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_FORWARDEULER_STEPPER_DECL_H 00030 #define Rythmos_FORWARDEULER_STEPPER_DECL_H 00031 00032 #include "Rythmos_StepperBase.hpp" 00033 #include "Rythmos_Types.hpp" 00034 #include "Thyra_ModelEvaluator.hpp" 00035 #include "Rythmos_MomentoBase.hpp" 00036 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp" 00037 #include "Rythmos_StateSerializerStrategy.hpp" 00038 00039 namespace Rythmos { 00040 00045 /* 00046 template<class Scalar> 00047 class ForwardEulerStepperMomento : 00048 virtual public MomentoBase<Scalar>, 00049 virtual public Teuchos::ParameterListAcceptorDefaultBase 00050 { 00051 public: 00052 ForwardEulerStepperMomento() {} 00053 virtual ~ForwardEulerStepperMomento() {} 00054 00055 void serialize( 00056 const StateSerializerStrategy<Scalar>& stateSerializer, 00057 std::ostream& oStream 00058 ) const 00059 { 00060 using Teuchos::is_null; 00061 TEUCHOS_ASSERT( !is_null(model_) ); 00062 if (is_null(solution_vector_)) { 00063 solution_vector_ = Thyra::createMember(model_->get_x_space()); 00064 } 00065 if (is_null(residual_vector_)) { 00066 residual_vector_ = Thyra::createMember(model_->get_f_space()); 00067 } 00068 if (is_null(solution_vector_old_)) { 00069 solution_vector_old_ = Thyra::createMember(model_->get_x_space()); 00070 } 00071 stateSerializer.serializeVectorBase(*solution_vector_,oStream); 00072 stateSerializer.serializeVectorBase(*residual_vector_,oStream); 00073 stateSerializer.serializeVectorBase(*solution_vector_old_,oStream); 00074 stateSerializer.serializeScalar(t_,oStream); 00075 stateSerializer.serializeScalar(t_old_,oStream); 00076 stateSerializer.serializeScalar(dt_,oStream); 00077 stateSerializer.serializeInt(numSteps_,oStream); 00078 stateSerializer.serializeBool(isInitialized_,oStream); 00079 stateSerializer.serializeBool(haveInitialCondition_,oStream); 00080 RCP<ParameterList> pl = parameterList_; 00081 if (Teuchos::is_null(pl)) { 00082 pl = Teuchos::parameterList(); 00083 } 00084 stateSerializer.serializeParameterList(*pl,oStream); 00085 } 00086 00087 void deSerialize( 00088 const StateSerializerStrategy<Scalar>& stateSerializer, 00089 std::istream& iStream 00090 ) 00091 { 00092 using Teuchos::outArg; 00093 using Teuchos::is_null; 00094 TEUCHOS_ASSERT( !is_null(model_) ); 00095 if (is_null(solution_vector_)) { 00096 solution_vector_ = Thyra::createMember(*model_->get_x_space()); 00097 } 00098 if (is_null(residual_vector_)) { 00099 residual_vector_ = Thyra::createMember(*model_->get_f_space()); 00100 } 00101 if (is_null(solution_vector_old_)) { 00102 solution_vector_old_ = Thyra::createMember(*model_->get_x_space()); 00103 } 00104 stateSerializer.deSerializeVectorBase(outArg(*solution_vector_),iStream); 00105 stateSerializer.deSerializeVectorBase(outArg(*residual_vector_),iStream); 00106 stateSerializer.deSerializeVectorBase(outArg(*solution_vector_old_),iStream); 00107 stateSerializer.deSerializeScalar(outArg(t_),iStream); 00108 stateSerializer.deSerializeScalar(outArg(t_old_),iStream); 00109 stateSerializer.deSerializeScalar(outArg(dt_),iStream); 00110 stateSerializer.deSerializeInt(outArg(numSteps_),iStream); 00111 stateSerializer.deSerializeBool(outArg(isInitialized_),iStream); 00112 stateSerializer.deSerializeBool(outArg(haveInitialCondition_),iStream); 00113 if (is_null(parameterList_)) { 00114 parameterList_ = Teuchos::parameterList(); 00115 } 00116 stateSerializer.deSerializeParameterList(outArg(*parameterList_),iStream); 00117 } 00118 00119 RCP<MomentoBase<Scalar> > clone() const 00120 { 00121 RCP<ForwardEulerStepperMomento<Scalar> > m = rcp(new ForwardEulerStepperMomento<Scalar>()); 00122 m->set_solution_vector(solution_vector_); 00123 m->set_residual_vector(residual_vector_); 00124 m->set_solution_vector_old(solution_vector_old_); 00125 m->set_t(t_); 00126 m->set_t_old(t_old_); 00127 m->set_dt(dt_); 00128 m->set_numSteps(numSteps_); 00129 m->set_isInitialized(isInitialized_); 00130 m->set_haveInitialCondition(haveInitialCondition_); 00131 m->set_parameterList(parameterList_); 00132 if (!Teuchos::is_null(this->getMyParamList())) { 00133 m->setParameterList(Teuchos::parameterList(*(this->getMyParamList()))); 00134 } 00135 m->setModel(model_); 00136 m->setBasePoint(basePoint_); 00137 // How do I copy the VerboseObject data? 00138 // 07/10/09 tscoffe: Its not set up in Teuchos to do this yet 00139 return m; 00140 } 00141 00142 void set_solution_vector(const RCP<const VectorBase<Scalar> >& solution_vector ) 00143 { 00144 solution_vector_ = Teuchos::null; 00145 if (!Teuchos::is_null(solution_vector)) { 00146 solution_vector_ = solution_vector->clone_v(); 00147 } 00148 } 00149 RCP<VectorBase<Scalar> > get_solution_vector() const 00150 { return solution_vector_; } 00151 00152 void set_residual_vector(const RCP<const VectorBase<Scalar> >& residual_vector ) 00153 { 00154 residual_vector_ = Teuchos::null; 00155 if (!Teuchos::is_null(residual_vector)) { 00156 residual_vector_ = residual_vector->clone_v(); 00157 } 00158 } 00159 RCP<VectorBase<Scalar> > get_residual_vector() const 00160 { return residual_vector_; } 00161 00162 void set_solution_vector_old(const RCP<const VectorBase<Scalar> >& solution_vector_old ) 00163 { 00164 solution_vector_old_ = Teuchos::null; 00165 if (!Teuchos::is_null(solution_vector_old)) { 00166 solution_vector_old_ = solution_vector_old->clone_v(); 00167 } 00168 } 00169 RCP<VectorBase<Scalar> > get_solution_vector_old() const 00170 { return solution_vector_old_; } 00171 00172 void set_t(const Scalar & t) 00173 { t_ = t; } 00174 Scalar get_t() const 00175 { return t_; } 00176 00177 void set_t_old(const Scalar & t_old) 00178 { t_old_ = t_old; } 00179 Scalar get_t_old() const 00180 { return t_old_; } 00181 00182 void set_dt(const Scalar & dt) 00183 { dt_ = dt; } 00184 Scalar get_dt() const 00185 { return dt_; } 00186 00187 void set_numSteps(const int & numSteps) 00188 { numSteps_ = numSteps; } 00189 int get_numSteps() const 00190 { return numSteps_; } 00191 00192 void set_isInitialized(const bool & isInitialized) 00193 { isInitialized_ = isInitialized; } 00194 bool get_isInitialized() const 00195 { return isInitialized_; } 00196 00197 void set_haveInitialCondition(const bool & haveInitialCondition) 00198 { haveInitialCondition_ = haveInitialCondition; } 00199 bool get_haveInitialCondition() const 00200 { return haveInitialCondition_; } 00201 00202 void set_parameterList(const RCP<const ParameterList>& pl) 00203 { 00204 parameterList_ = Teuchos::null; 00205 if (!Teuchos::is_null(pl)) { 00206 parameterList_ = Teuchos::parameterList(*pl); 00207 } 00208 } 00209 RCP<ParameterList> get_parameterList() const 00210 { return parameterList_; } 00211 00212 void setParameterList(const RCP<ParameterList>& paramList) 00213 { this->setMyParamList(paramList); } 00214 RCP<const ParameterList> getValidParameters() const 00215 { return Teuchos::null; } 00216 00217 void set_model(const RCP<const Thyra::ModelEvaluator<Scalar> >& model) 00218 { model_ = model; } 00219 RCP<const Thyra::ModelEvaluator<Scalar> > get_model() const 00220 { return model_; } 00221 00222 void set_basePoint(const RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> >& basePoint) 00223 { basePoint_ = basePoint; } 00224 RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > get_basePoint() const 00225 { return basePoint_; } 00226 00227 private: 00228 RCP<Thyra::VectorBase<Scalar> > solution_vector_; 00229 RCP<Thyra::VectorBase<Scalar> > residual_vector_; 00230 RCP<Thyra::VectorBase<Scalar> > solution_vector_old_; 00231 Scalar t_; 00232 Scalar t_old_; 00233 Scalar dt_; 00234 int numSteps_; 00235 bool isInitialized_; 00236 bool haveInitialCondition_; 00237 RCP<ParameterList> parameterList_; 00238 00239 // Objects that must be set prior to serialization and deSerialization: 00240 RCP<const Thyra::ModelEvaluator<Scalar> > model_; 00241 // Objects that must be set prior to calling ForwardEulerStepper::setMomento: 00242 RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > basePoint_; 00243 }; 00244 */ 00245 template<class Scalar> 00246 class ForwardEulerStepperMomento : 00247 virtual public MomentoBase<Scalar>, 00248 virtual public Teuchos::ParameterListAcceptorDefaultBase 00249 { 00250 public: 00251 ForwardEulerStepperMomento(); 00252 virtual ~ForwardEulerStepperMomento(); 00253 00254 void serialize( 00255 const StateSerializerStrategy<Scalar>& stateSerializer, 00256 std::ostream& oStream 00257 ) const; 00258 00259 void deSerialize( 00260 const StateSerializerStrategy<Scalar>& stateSerializer, 00261 std::istream& iStream 00262 ); 00263 00264 RCP<MomentoBase<Scalar> > clone() const; 00265 00266 void set_solution_vector(const RCP<const VectorBase<Scalar> >& solution_vector ); 00267 RCP<VectorBase<Scalar> > get_solution_vector() const; 00268 00269 void set_residual_vector(const RCP<const VectorBase<Scalar> >& residual_vector ); 00270 RCP<VectorBase<Scalar> > get_residual_vector() const; 00271 00272 void set_solution_vector_old(const RCP<const VectorBase<Scalar> >& solution_vector_old ); 00273 RCP<VectorBase<Scalar> > get_solution_vector_old() const; 00274 00275 void set_t(const Scalar & t); 00276 Scalar get_t() const; 00277 00278 void set_t_old(const Scalar & t_old); 00279 Scalar get_t_old() const; 00280 00281 void set_dt(const Scalar & dt); 00282 Scalar get_dt() const; 00283 00284 void set_numSteps(const int & numSteps); 00285 int get_numSteps() const; 00286 00287 void set_isInitialized(const bool & isInitialized); 00288 bool get_isInitialized() const; 00289 00290 void set_haveInitialCondition(const bool & haveInitialCondition); 00291 bool get_haveInitialCondition() const; 00292 00293 void set_parameterList(const RCP<const ParameterList>& pl); 00294 RCP<ParameterList> get_parameterList() const; 00295 00296 void setParameterList(const RCP<ParameterList>& paramList); 00297 RCP<const ParameterList> getValidParameters() const; 00298 00299 void set_model(const RCP<const Thyra::ModelEvaluator<Scalar> >& model); 00300 RCP<const Thyra::ModelEvaluator<Scalar> > get_model() const; 00301 00302 void set_basePoint(const RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> >& basePoint); 00303 RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > get_basePoint() const; 00304 00305 private: 00306 RCP<Thyra::VectorBase<Scalar> > solution_vector_; 00307 RCP<Thyra::VectorBase<Scalar> > residual_vector_; 00308 RCP<Thyra::VectorBase<Scalar> > solution_vector_old_; 00309 Scalar t_; 00310 Scalar t_old_; 00311 Scalar dt_; 00312 int numSteps_; 00313 bool isInitialized_; 00314 bool haveInitialCondition_; 00315 RCP<ParameterList> parameterList_; 00316 00317 // Objects that must be set prior to serialization and deSerialization: 00318 RCP<const Thyra::ModelEvaluator<Scalar> > model_; 00319 // Objects that must be set prior to calling ForwardEulerStepper::setMomento: 00320 RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > basePoint_; 00321 }; 00322 00323 00325 template<class Scalar> 00326 class ForwardEulerStepper : virtual public StepperBase<Scalar> 00327 { 00328 public: 00329 00330 typedef Teuchos::ScalarTraits<Scalar> ST; 00331 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag; 00332 00334 ForwardEulerStepper(); 00335 00337 bool supportsCloning() const; 00338 00340 RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const; 00341 00343 void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> > &model); 00344 00346 RCP<const Thyra::ModelEvaluator<Scalar> > 00347 getModel() const; 00348 00350 void setInitialCondition( 00351 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition 00352 ); 00353 00355 RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const; 00356 00358 ~ForwardEulerStepper(); 00359 00361 Scalar takeStep(Scalar dt, StepSizeType flag); 00362 00364 const StepStatus<Scalar> getStepStatus() const; 00365 00367 std::string description() const; 00368 00370 void describe( 00371 Teuchos::FancyOStream &out, 00372 const Teuchos::EVerbosityLevel verbLevel 00373 ) const; 00374 00377 void addPoints( 00378 const Array<Scalar>& time_vec 00379 ,const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec 00380 ,const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec 00381 ); 00382 00384 void getPoints( 00385 const Array<Scalar>& time_vec 00386 ,Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec 00387 ,Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec 00388 ,Array<ScalarMag>* accuracy_vec 00389 ) const; 00390 00392 void setRange( 00393 const TimeRange<Scalar>& range, 00394 const InterpolationBufferBase<Scalar> & IB 00395 ); 00396 00398 TimeRange<Scalar> getTimeRange() const; 00399 00401 void getNodes(Array<Scalar>* time_vec) const; 00402 00404 void removeNodes(Array<Scalar>& time_vec); 00405 00407 int getOrder() const; 00408 00410 00411 void setParameterList(RCP<Teuchos::ParameterList> const& paramList); 00412 00414 RCP<Teuchos::ParameterList> getNonconstParameterList(); 00415 00417 RCP<Teuchos::ParameterList> unsetParameterList(); 00418 00420 RCP<const Teuchos::ParameterList> getValidParameters() const; 00421 00425 RCP<const MomentoBase<Scalar> > getMomento() const; 00426 00430 void setMomento( const Ptr<const MomentoBase<Scalar> >& momentoPtr ); 00431 00432 private: 00433 00434 RCP<const Thyra::ModelEvaluator<Scalar> > model_; 00435 RCP<Thyra::VectorBase<Scalar> > solution_vector_; 00436 RCP<Thyra::VectorBase<Scalar> > residual_vector_; 00437 Scalar t_; 00438 Scalar dt_; 00439 Scalar t_old_; 00440 RCP<Thyra::VectorBase<Scalar> > solution_vector_old_; 00441 Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_; 00442 int numSteps_; 00443 bool haveInitialCondition_; 00444 00445 RCP<Teuchos::ParameterList> parameterList_; 00446 bool isInitialized_; 00447 00448 // Private member functions: 00449 void defaultInitializAll_(); 00450 void initialize_(); 00451 void checkConsistentState_(); 00452 00453 }; 00454 00455 // Nonmember constructor 00456 template<class Scalar> 00457 RCP<ForwardEulerStepper<Scalar> > forwardEulerStepper(); 00458 00459 // Nonmember constructor 00460 template<class Scalar> 00461 RCP<ForwardEulerStepper<Scalar> > forwardEulerStepper(const RCP<const Thyra::ModelEvaluator<Scalar> > &model); 00462 00463 } // namespace Rythmos 00464 00465 #endif //Rythmos_FORWARDEULER_STEPPER_DECL_H
1.4.7