|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_InterpolatorAcceptingObjectBase.hpp" 00034 #include "Rythmos_SingleResidualModelEvaluator.hpp" 00035 #include "Rythmos_MomentoBase.hpp" 00036 00037 #include "Thyra_VectorBase.hpp" 00038 #include "Thyra_ModelEvaluator.hpp" 00039 #include "Thyra_NonlinearSolverBase.hpp" 00040 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp" 00041 00042 00043 namespace Rythmos { 00044 00045 00050 template<class Scalar> 00051 class BackwardEulerStepperMomento : 00052 virtual public MomentoBase<Scalar>, 00053 virtual public Teuchos::ParameterListAcceptorDefaultBase 00054 { 00055 public: 00056 BackwardEulerStepperMomento() {} 00057 virtual ~BackwardEulerStepperMomento() {} 00058 00059 RCP<MomentoBase<Scalar> > clone() const 00060 { 00061 RCP<BackwardEulerStepperMomento<Scalar> > m = rcp(new BackwardEulerStepperMomento<Scalar>()); 00062 m->set_scaled_x_old(scaled_x_old_); 00063 m->set_x_dot_old(x_dot_old_); 00064 m->set_x(x_); 00065 m->set_x_dot(x_dot_); 00066 m->set_t(t_); 00067 m->set_t_old(t_old_); 00068 m->set_dt(dt_); 00069 m->set_numSteps(numSteps_); 00070 m->set_isInitialized(isInitialized_); 00071 m->set_haveInitialCondition(haveInitialCondition_); 00072 m->set_parameterList(parameterList_); 00073 m->set_basePoint(basePoint_); 00074 m->set_neModel(neModel_); 00075 m->set_interpolator(interpolator_); 00076 if (!Teuchos::is_null(this->getMyParamList())) { 00077 m->setParameterList(Teuchos::parameterList(*(this->getMyParamList()))); 00078 } 00079 // How do I copy the VerboseObject data? 00080 // 07/10/09 tscoffe: Its not set up in Teuchos to do this yet 00081 return m; 00082 } 00083 00084 void serialize( 00085 const StateSerializerStrategy<Scalar>& stateSerializer, 00086 std::ostream& oStream 00087 ) const 00088 { } 00089 00090 void deSerialize( 00091 const StateSerializerStrategy<Scalar>& stateSerializer, 00092 std::istream& iStream 00093 ) 00094 { } 00095 00096 void set_scaled_x_old(const RCP<const VectorBase<Scalar> >& scaled_x_old ) 00097 { 00098 scaled_x_old_ = Teuchos::null; 00099 if (!Teuchos::is_null(scaled_x_old)) { 00100 scaled_x_old_ = scaled_x_old->clone_v(); 00101 } 00102 } 00103 RCP<VectorBase<Scalar> > get_scaled_x_old() const 00104 { return scaled_x_old_; } 00105 00106 void set_x_dot_old(const RCP<const VectorBase<Scalar> >& x_dot_old ) 00107 { 00108 x_dot_old_ = Teuchos::null; 00109 if (!Teuchos::is_null(x_dot_old)) { 00110 x_dot_old_ = x_dot_old->clone_v(); 00111 } 00112 } 00113 RCP<VectorBase<Scalar> > get_x_dot_old() const 00114 { return x_dot_old_; } 00115 00116 void set_x(const RCP<const VectorBase<Scalar> >& x ) 00117 { 00118 x_ = Teuchos::null; 00119 if (!Teuchos::is_null(x)) { 00120 x_ = x->clone_v(); 00121 } 00122 } 00123 RCP<VectorBase<Scalar> > get_x() const 00124 { return x_; } 00125 00126 void set_x_dot(const RCP<const VectorBase<Scalar> >& x_dot ) 00127 { 00128 x_dot_ = Teuchos::null; 00129 if (!Teuchos::is_null(x_dot)) { 00130 x_dot_ = x_dot->clone_v(); 00131 } 00132 } 00133 RCP<VectorBase<Scalar> > get_x_dot() const 00134 { return x_dot_; } 00135 00136 void set_t(const Scalar & t) 00137 { t_ = t; } 00138 Scalar get_t() const 00139 { return t_; } 00140 00141 void set_t_old(const Scalar & t_old) 00142 { t_old_ = t_old; } 00143 Scalar get_t_old() const 00144 { return t_old_; } 00145 00146 void set_dt(const Scalar & dt) 00147 { dt_ = dt; } 00148 Scalar get_dt() const 00149 { return dt_; } 00150 00151 void set_numSteps(const int & numSteps) 00152 { numSteps_ = numSteps; } 00153 int get_numSteps() const 00154 { return numSteps_; } 00155 00156 void set_isInitialized(const bool & isInitialized) 00157 { isInitialized_ = isInitialized; } 00158 bool get_isInitialized() const 00159 { return isInitialized_; } 00160 00161 void set_haveInitialCondition(const bool & haveInitialCondition) 00162 { haveInitialCondition_ = haveInitialCondition; } 00163 bool get_haveInitialCondition() const 00164 { return haveInitialCondition_; } 00165 00166 void set_parameterList(const RCP<const ParameterList>& pl) 00167 { 00168 parameterList_ = Teuchos::null; 00169 if (!Teuchos::is_null(pl)) { 00170 parameterList_ = Teuchos::parameterList(*pl); 00171 } 00172 } 00173 RCP<ParameterList> get_parameterList() const 00174 { return parameterList_; } 00175 00176 void set_basePoint(Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint) 00177 { basePoint_ = basePoint; }; 00178 Thyra::ModelEvaluatorBase::InArgs<Scalar> get_basePoint() const 00179 { return basePoint_; } 00180 00181 void set_neModel(const RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >& neModel) 00182 { 00183 neModel_ = Teuchos::null; 00184 if (!Teuchos::is_null(neModel)) { 00185 neModel_ = Teuchos::rcp(new Rythmos::SingleResidualModelEvaluator<Scalar>); 00186 } 00187 } 00188 RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > get_neModel() const 00189 { return neModel_; } 00190 00191 void set_interpolator(const RCP<InterpolatorBase<Scalar> >& interpolator) 00192 { 00193 interpolator_ = Teuchos::null; 00194 if (!Teuchos::is_null(interpolator)) { 00195 TEUCHOS_ASSERT(interpolator->supportsCloning()); 00196 interpolator_ = interpolator->cloneInterpolator(); 00197 } 00198 } 00199 RCP<InterpolatorBase<Scalar> > get_interpolator() const 00200 { return interpolator_; } 00201 00202 void setParameterList(const RCP<ParameterList>& paramList) 00203 { this->setMyParamList(paramList); } 00204 RCP<const ParameterList> getValidParameters() const 00205 { return Teuchos::null; } 00206 00207 private: 00208 RCP<Thyra::VectorBase<Scalar> > scaled_x_old_; 00209 RCP<Thyra::VectorBase<Scalar> > x_dot_old_; 00210 RCP<Thyra::VectorBase<Scalar> > x_; 00211 RCP<Thyra::VectorBase<Scalar> > x_dot_; 00212 Scalar t_; 00213 Scalar t_old_; 00214 Scalar dt_; 00215 int numSteps_; 00216 bool isInitialized_; 00217 bool haveInitialCondition_; 00218 RCP<Teuchos::ParameterList> parameterList_; 00219 Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_; 00220 RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_; 00221 RCP<InterpolatorBase<Scalar> > interpolator_; 00222 00223 }; 00224 00225 00236 template<class Scalar> 00237 class BackwardEulerStepper : 00238 virtual public SolverAcceptingStepperBase<Scalar>, 00239 virtual public InterpolatorAcceptingObjectBase<Scalar> 00240 { 00241 public: 00242 00244 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag; 00245 00248 00250 BackwardEulerStepper(); 00251 00253 BackwardEulerStepper( 00254 const RCP<Thyra::ModelEvaluator<Scalar> >& model, 00255 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver 00256 ); 00257 00259 00262 00264 void setInterpolator(const RCP<InterpolatorBase<Scalar> >& interpolator); 00265 00267 RCP<InterpolatorBase<Scalar> > getNonconstInterpolator(); 00268 00270 RCP<const InterpolatorBase<Scalar> > getInterpolator() const; 00271 00273 RCP<InterpolatorBase<Scalar> > unSetInterpolator(); 00274 00276 00279 00281 void setSolver( 00282 const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver 00283 ); 00284 00286 RCP<Thyra::NonlinearSolverBase<Scalar> > 00287 getNonconstSolver(); 00288 00290 RCP<const Thyra::NonlinearSolverBase<Scalar> > 00291 getSolver() const; 00292 00294 00297 00299 bool supportsCloning() const; 00300 00308 RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const; 00309 00311 bool isImplicit() const; 00312 00314 void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> >& model); 00315 00317 void setNonconstModel(const RCP<Thyra::ModelEvaluator<Scalar> >& model); 00318 00320 RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const; 00321 00323 RCP<Thyra::ModelEvaluator<Scalar> > getNonconstModel(); 00324 00326 void setInitialCondition( 00327 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition 00328 ); 00329 00331 Thyra::ModelEvaluatorBase::InArgs<Scalar> getInitialCondition() const; 00332 00334 Scalar takeStep(Scalar dt, StepSizeType flag); 00335 00337 const StepStatus<Scalar> getStepStatus() const; 00338 00340 00343 00345 RCP<const Thyra::VectorSpaceBase<Scalar> > 00346 get_x_space() const; 00347 00349 void addPoints( 00350 const Array<Scalar>& time_vec, 00351 const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec, 00352 const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec 00353 ); 00354 00356 TimeRange<Scalar> getTimeRange() const; 00357 00359 void getPoints( 00360 const Array<Scalar>& time_vec, 00361 Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec, 00362 Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec, 00363 Array<ScalarMag>* accuracy_vec 00364 ) const; 00365 00367 void getNodes(Array<Scalar>* time_vec) const; 00368 00370 void removeNodes(Array<Scalar>& time_vec); 00371 00373 int getOrder() const; 00374 00376 00379 00381 void setParameterList(RCP<Teuchos::ParameterList> const& paramList); 00382 00384 RCP<Teuchos::ParameterList> getNonconstParameterList(); 00385 00387 RCP<Teuchos::ParameterList> unsetParameterList(); 00388 00390 RCP<const Teuchos::ParameterList> getValidParameters() const; 00391 00393 00396 00398 void describe( 00399 Teuchos::FancyOStream &out, 00400 const Teuchos::EVerbosityLevel verbLevel 00401 ) const; 00402 00404 00407 00411 RCP<const MomentoBase<Scalar> > getMomento() const; 00412 00415 void setMomento( 00416 const Ptr<const MomentoBase<Scalar> >& momentoPtr, 00417 const RCP<Thyra::ModelEvaluator<Scalar> >& model, 00418 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver 00419 ); 00420 00422 00423 00424 private: 00425 00426 // /////////////////////// 00427 // Private date members 00428 00429 bool isInitialized_; 00430 bool haveInitialCondition_; 00431 RCP<const Thyra::ModelEvaluator<Scalar> > model_; 00432 RCP<Thyra::NonlinearSolverBase<Scalar> > solver_; 00433 RCP<Thyra::VectorBase<Scalar> > scaled_x_old_; 00434 RCP<Thyra::VectorBase<Scalar> > x_dot_old_; 00435 00436 Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_; 00437 RCP<Thyra::VectorBase<Scalar> > x_; 00438 RCP<Thyra::VectorBase<Scalar> > x_dot_; 00439 Scalar t_; 00440 Scalar t_old_; 00441 00442 Scalar dt_; 00443 int numSteps_; 00444 00445 RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_; 00446 00447 RCP<Teuchos::ParameterList> parameterList_; 00448 00449 RCP<InterpolatorBase<Scalar> > interpolator_; 00450 00451 00452 // ////////////////////////// 00453 // Private member functions 00454 00455 void defaultInitializeAll_(); 00456 void initialize(); 00457 void checkConsistentState_(); 00458 00459 }; 00460 00461 00466 template<class Scalar> 00467 RCP<BackwardEulerStepper<Scalar> > 00468 backwardEulerStepper(); 00469 00470 00475 template<class Scalar> 00476 RCP<BackwardEulerStepper<Scalar> > 00477 backwardEulerStepper( 00478 const RCP<Thyra::ModelEvaluator<Scalar> >& model, 00479 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver 00480 ); 00481 00482 00483 } // namespace Rythmos 00484 00485 00486 #endif //Rythmos_BACKWARD_EULER_STEPPER_DECL_H
1.7.6.1