|
Rythmos - Transient Integration for Differential Equations
Version of the Day
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // Rythmos Package 00005 // Copyright (2006) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 // USA 00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 00029 #ifndef Rythmos_BACKWARD_EULER_STEPPER_DECL_H 00030 #define Rythmos_BACKWARD_EULER_STEPPER_DECL_H 00031 00032 #include "Rythmos_SolverAcceptingStepperBase.hpp" 00033 #include "Rythmos_StepControlStrategyAcceptingStepperBase.hpp" 00034 #include "Rythmos_InterpolatorAcceptingObjectBase.hpp" 00035 #include "Rythmos_SingleResidualModelEvaluator.hpp" 00036 #include "Rythmos_MomentoBase.hpp" 00037 00038 #include "Thyra_VectorBase.hpp" 00039 #include "Thyra_ModelEvaluator.hpp" 00040 #include "Thyra_NonlinearSolverBase.hpp" 00041 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp" 00042 00043 00044 namespace Rythmos { 00045 00046 00052 template<class Scalar> 00053 class BackwardEulerStepperMomento : 00054 virtual public MomentoBase<Scalar>, 00055 virtual public Teuchos::ParameterListAcceptorDefaultBase 00056 { 00057 public: 00058 BackwardEulerStepperMomento() {} 00059 virtual ~BackwardEulerStepperMomento() {} 00060 00061 RCP<MomentoBase<Scalar> > clone() const 00062 { 00063 RCP<BackwardEulerStepperMomento<Scalar> > m = 00064 rcp(new BackwardEulerStepperMomento<Scalar>()); 00065 m->set_scaled_x_old(scaled_x_old_); 00066 m->set_x_dot_old(x_dot_old_); 00067 m->set_x(x_); 00068 m->set_x_old(x_old_); 00069 m->set_x_dot(x_dot_); 00070 m->set_dx(dx_); 00071 m->set_t(t_); 00072 m->set_t_old(t_old_); 00073 m->set_dt(dt_); 00074 m->set_numSteps(numSteps_); 00075 m->set_isInitialized(isInitialized_); 00076 m->set_haveInitialCondition(haveInitialCondition_); 00077 m->set_parameterList(parameterList_); 00078 m->set_basePoint(basePoint_); 00079 m->set_neModel(neModel_); 00080 m->set_interpolator(interpolator_); 00081 m->set_stepControl(stepControl_); 00082 if (!Teuchos::is_null(this->getMyParamList())) { 00083 m->setParameterList(Teuchos::parameterList(*(this->getMyParamList()))); 00084 } 00085 // How do I copy the VerboseObject data? 00086 // 07/10/09 tscoffe: Its not set up in Teuchos to do this yet 00087 return m; 00088 } 00089 00090 void serialize( 00091 const StateSerializerStrategy<Scalar>& stateSerializer, 00092 std::ostream& oStream 00093 ) const 00094 { } 00095 00096 void deSerialize( 00097 const StateSerializerStrategy<Scalar>& stateSerializer, 00098 std::istream& iStream 00099 ) 00100 { } 00101 00102 void set_scaled_x_old(const RCP<const VectorBase<Scalar> >& scaled_x_old ) 00103 { 00104 scaled_x_old_ = Teuchos::null; 00105 if (!Teuchos::is_null(scaled_x_old)) { 00106 scaled_x_old_ = scaled_x_old->clone_v(); 00107 } 00108 } 00109 RCP<VectorBase<Scalar> > get_scaled_x_old() const 00110 { return scaled_x_old_; } 00111 00112 void set_x_dot_old(const RCP<const VectorBase<Scalar> >& x_dot_old ) 00113 { 00114 x_dot_old_ = Teuchos::null; 00115 if (!Teuchos::is_null(x_dot_old)) { 00116 x_dot_old_ = x_dot_old->clone_v(); 00117 } 00118 } 00119 RCP<VectorBase<Scalar> > get_x_dot_old() const 00120 { return x_dot_old_; } 00121 00122 void set_x_old(const RCP<const VectorBase<Scalar> >& x_old ) 00123 { 00124 x_old_ = Teuchos::null; 00125 if (!Teuchos::is_null(x_old)) { 00126 x_old_ = x_old->clone_v(); 00127 } 00128 } 00129 RCP<VectorBase<Scalar> > get_x_old() const 00130 { return x_old_; } 00131 00132 void set_x(const RCP<const VectorBase<Scalar> >& x ) 00133 { 00134 x_ = Teuchos::null; 00135 if (!Teuchos::is_null(x)) { 00136 x_ = x->clone_v(); 00137 } 00138 } 00139 RCP<VectorBase<Scalar> > get_x() const 00140 { return x_; } 00141 00142 void set_dx(const RCP<const VectorBase<Scalar> >& dx ) 00143 { 00144 dx_ = Teuchos::null; 00145 if (!Teuchos::is_null(dx)) { 00146 dx_ = dx->clone_v(); 00147 } 00148 } 00149 RCP<VectorBase<Scalar> > get_dx() const 00150 { return dx_; } 00151 00152 void set_x_dot(const RCP<const VectorBase<Scalar> >& x_dot ) 00153 { 00154 x_dot_ = Teuchos::null; 00155 if (!Teuchos::is_null(x_dot)) { 00156 x_dot_ = x_dot->clone_v(); 00157 } 00158 } 00159 RCP<VectorBase<Scalar> > get_x_dot() const 00160 { return x_dot_; } 00161 00162 void set_t(const Scalar & t) 00163 { t_ = t; } 00164 Scalar get_t() const 00165 { return t_; } 00166 00167 void set_t_old(const Scalar & t_old) 00168 { t_old_ = t_old; } 00169 Scalar get_t_old() const 00170 { return t_old_; } 00171 00172 void set_dt(const Scalar & dt) 00173 { dt_ = dt; } 00174 Scalar get_dt() const 00175 { return dt_; } 00176 00177 void set_numSteps(const int & numSteps) 00178 { numSteps_ = numSteps; } 00179 int get_numSteps() const 00180 { return numSteps_; } 00181 00182 void set_newtonConvergenceStatus(const int & newtonConvergenceStatus) 00183 { newtonConvergenceStatus_ = newtonConvergenceStatus; } 00184 int get_newtonConvergenceStatus() const 00185 { return newtonConvergenceStatus_; } 00186 00187 void set_isInitialized(const bool & isInitialized) 00188 { isInitialized_ = isInitialized; } 00189 bool get_isInitialized() const 00190 { return isInitialized_; } 00191 00192 void set_haveInitialCondition(const bool & haveInitialCondition) 00193 { haveInitialCondition_ = haveInitialCondition; } 00194 bool get_haveInitialCondition() const 00195 { return haveInitialCondition_; } 00196 00197 void set_parameterList(const RCP<const ParameterList>& pl) 00198 { 00199 parameterList_ = Teuchos::null; 00200 if (!Teuchos::is_null(pl)) { 00201 parameterList_ = Teuchos::parameterList(*pl); 00202 } 00203 } 00204 RCP<ParameterList> get_parameterList() const 00205 { return parameterList_; } 00206 00207 void set_basePoint(Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint) 00208 { basePoint_ = basePoint; }; 00209 Thyra::ModelEvaluatorBase::InArgs<Scalar> get_basePoint() const 00210 { return basePoint_; } 00211 00212 void set_neModel(const RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >& neModel) 00213 { 00214 neModel_ = Teuchos::null; 00215 if (!Teuchos::is_null(neModel)) { 00216 neModel_ = Teuchos::rcp(new Rythmos::SingleResidualModelEvaluator<Scalar>); 00217 } 00218 } 00219 RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > get_neModel() const 00220 { return neModel_; } 00221 00222 void set_interpolator(const RCP<InterpolatorBase<Scalar> >& interpolator) 00223 { 00224 interpolator_ = Teuchos::null; 00225 if (!Teuchos::is_null(interpolator)) { 00226 TEUCHOS_ASSERT(interpolator->supportsCloning()); 00227 interpolator_ = interpolator->cloneInterpolator(); 00228 } 00229 } 00230 RCP<InterpolatorBase<Scalar> > get_interpolator() const 00231 { return interpolator_; } 00232 00233 void set_stepControl(const RCP<StepControlStrategyBase<Scalar> >& stepControl) 00234 { 00235 stepControl_ = Teuchos::null; 00236 if (!Teuchos::is_null(stepControl)) { 00237 TEUCHOS_ASSERT(stepControl->supportsCloning()); 00238 stepControl_ = stepControl->cloneStepControlStrategyAlgorithm(); 00239 } 00240 } 00241 RCP<StepControlStrategyBase<Scalar> > get_stepControl() const 00242 { return stepControl_; } 00243 00244 void setParameterList(const RCP<ParameterList>& paramList) 00245 { this->setMyParamList(paramList); } 00246 RCP<const ParameterList> getValidParameters() const 00247 { return Teuchos::null; } 00248 00249 private: 00250 RCP<Thyra::VectorBase<Scalar> > scaled_x_old_; 00251 RCP<Thyra::VectorBase<Scalar> > x_old_; 00252 RCP<Thyra::VectorBase<Scalar> > x_dot_old_; 00253 RCP<Thyra::VectorBase<Scalar> > x_; 00254 RCP<Thyra::VectorBase<Scalar> > x_dot_; 00255 RCP<Thyra::VectorBase<Scalar> > dx_; 00256 Scalar t_; 00257 Scalar t_old_; 00258 Scalar dt_; 00259 int numSteps_; 00260 int newtonConvergenceStatus_; 00261 bool isInitialized_; 00262 bool haveInitialCondition_; 00263 RCP<Teuchos::ParameterList> parameterList_; 00264 Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_; 00265 RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_; 00266 RCP<InterpolatorBase<Scalar> > interpolator_; 00267 RCP<StepControlStrategyBase<Scalar> > stepControl_; 00268 00269 }; 00270 00271 00282 template<class Scalar> 00283 class BackwardEulerStepper : 00284 virtual public SolverAcceptingStepperBase<Scalar>, 00285 virtual public StepControlStrategyAcceptingStepperBase<Scalar>, 00286 virtual public InterpolatorAcceptingObjectBase<Scalar> 00287 { 00288 public: 00289 00291 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag; 00292 00295 00297 BackwardEulerStepper(); 00298 00300 BackwardEulerStepper( 00301 const RCP<Thyra::ModelEvaluator<Scalar> >& model, 00302 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver 00303 ); 00304 00306 00309 00311 void setInterpolator(const RCP<InterpolatorBase<Scalar> >& interpolator); 00312 00314 RCP<InterpolatorBase<Scalar> > getNonconstInterpolator(); 00315 00317 RCP<const InterpolatorBase<Scalar> > getInterpolator() const; 00318 00320 RCP<InterpolatorBase<Scalar> > unSetInterpolator(); 00321 00323 00326 00328 void setStepControlStrategy( 00329 const RCP<StepControlStrategyBase<Scalar> >& stepControlStrategy 00330 ); 00331 00333 RCP<StepControlStrategyBase<Scalar> > 00334 getNonconstStepControlStrategy(); 00335 00337 RCP<const StepControlStrategyBase<Scalar> > 00338 getStepControlStrategy() const; 00339 00341 00344 00346 void setSolver( 00347 const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver 00348 ); 00349 00351 RCP<Thyra::NonlinearSolverBase<Scalar> > 00352 getNonconstSolver(); 00353 00355 RCP<const Thyra::NonlinearSolverBase<Scalar> > 00356 getSolver() const; 00357 00359 00362 00364 bool supportsCloning() const; 00365 00373 RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const; 00374 00376 bool isImplicit() const; 00377 00379 void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> >& model); 00380 00382 void setNonconstModel(const RCP<Thyra::ModelEvaluator<Scalar> >& model); 00383 00385 RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const; 00386 00388 RCP<Thyra::ModelEvaluator<Scalar> > getNonconstModel(); 00389 00391 void setInitialCondition( 00392 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition 00393 ); 00394 00396 Thyra::ModelEvaluatorBase::InArgs<Scalar> getInitialCondition() const; 00397 00399 Scalar takeStep(Scalar dt, StepSizeType flag); 00400 00402 const StepStatus<Scalar> getStepStatus() const; 00403 00405 00408 00410 RCP<const Thyra::VectorSpaceBase<Scalar> > 00411 get_x_space() const; 00412 00414 void addPoints( 00415 const Array<Scalar>& time_vec, 00416 const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec, 00417 const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec 00418 ); 00419 00421 TimeRange<Scalar> getTimeRange() const; 00422 00424 void getPoints( 00425 const Array<Scalar>& time_vec, 00426 Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec, 00427 Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec, 00428 Array<ScalarMag>* accuracy_vec 00429 ) const; 00430 00432 void getNodes(Array<Scalar>* time_vec) const; 00433 00435 void removeNodes(Array<Scalar>& time_vec); 00436 00438 int getOrder() const; 00439 00441 00444 00446 void setParameterList(RCP<Teuchos::ParameterList> const& paramList); 00447 00449 RCP<Teuchos::ParameterList> getNonconstParameterList(); 00450 00452 RCP<Teuchos::ParameterList> unsetParameterList(); 00453 00455 RCP<const Teuchos::ParameterList> getValidParameters() const; 00456 00458 00461 00463 void describe( 00464 Teuchos::FancyOStream &out, 00465 const Teuchos::EVerbosityLevel verbLevel 00466 ) const; 00467 00469 00472 00476 RCP<const MomentoBase<Scalar> > getMomento() const; 00477 00480 void setMomento( 00481 const Ptr<const MomentoBase<Scalar> >& momentoPtr, 00482 const RCP<Thyra::ModelEvaluator<Scalar> >& model, 00483 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver 00484 ); 00485 00487 00488 00489 private: 00490 00491 // /////////////////////// 00492 // Private date members 00493 00494 bool isInitialized_; 00495 bool haveInitialCondition_; 00496 RCP<const Thyra::ModelEvaluator<Scalar> > model_; 00497 RCP<Thyra::NonlinearSolverBase<Scalar> > solver_; 00498 RCP<Thyra::VectorBase<Scalar> > x_old_; 00499 RCP<Thyra::VectorBase<Scalar> > scaled_x_old_; 00500 RCP<Thyra::VectorBase<Scalar> > x_dot_old_; 00501 00502 Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_; 00503 RCP<Thyra::VectorBase<Scalar> > x_; 00504 RCP<Thyra::VectorBase<Scalar> > x_dot_; 00505 RCP<Thyra::VectorBase<Scalar> > dx_; 00506 Scalar t_; 00507 Scalar t_old_; 00508 00509 Scalar dt_; 00510 int numSteps_; 00511 00512 RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_; 00513 00514 RCP<Teuchos::ParameterList> parameterList_; 00515 00516 RCP<InterpolatorBase<Scalar> > interpolator_; 00517 RCP<StepControlStrategyBase<Scalar> > stepControl_; 00518 00519 int newtonConvergenceStatus_; 00520 00521 00522 // ////////////////////////// 00523 // Private member functions 00524 00525 void defaultInitializeAll_(); 00526 void initialize_(); 00527 void checkConsistentState_(); 00528 void obtainPredictor_(); 00529 00530 }; 00531 00532 00537 template<class Scalar> 00538 RCP<BackwardEulerStepper<Scalar> > 00539 backwardEulerStepper(); 00540 00541 00546 template<class Scalar> 00547 RCP<BackwardEulerStepper<Scalar> > 00548 backwardEulerStepper( 00549 const RCP<Thyra::ModelEvaluator<Scalar> >& model, 00550 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver 00551 ); 00552 00553 00554 } // namespace Rythmos 00555 00556 00557 #endif //Rythmos_BACKWARD_EULER_STEPPER_DECL_H
1.7.6.1