Rythmos - Transient Integration for Differential Equations Version of the Day
Rythmos_BackwardEulerStepper_decl.hpp
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 namespace Rythmos {
00043 
00048 template<class Scalar>
00049   class BackwardEulerStepperMomento :
00050     virtual public MomentoBase<Scalar>,
00051     virtual public Teuchos::ParameterListAcceptorDefaultBase
00052 {
00053   public:
00054     BackwardEulerStepperMomento() {}
00055     virtual ~BackwardEulerStepperMomento() {}
00056 
00057     RCP<MomentoBase<Scalar> > clone() const
00058     {
00059       RCP<BackwardEulerStepperMomento<Scalar> > m = rcp(new BackwardEulerStepperMomento<Scalar>());
00060       m->set_scaled_x_old(scaled_x_old_);
00061       m->set_x_dot_old(x_dot_old_);
00062       m->set_x(x_);
00063       m->set_x_dot(x_dot_);
00064       m->set_t(t_);
00065       m->set_t_old(t_old_);
00066       m->set_dt(dt_);
00067       m->set_numSteps(numSteps_);
00068       m->set_isInitialized(isInitialized_);
00069       m->set_haveInitialCondition(haveInitialCondition_);
00070       m->set_parameterList(parameterList_);
00071       m->set_basePoint(basePoint_);
00072       m->set_neModel(neModel_);
00073       m->set_interpolator(interpolator_);
00074       if (!Teuchos::is_null(this->getMyParamList())) {
00075         m->setParameterList(Teuchos::parameterList(*(this->getMyParamList())));
00076       }
00077       // How do I copy the VerboseObject data?  
00078       // 07/10/09 tscoffe:  Its not set up in Teuchos to do this yet
00079       return m;
00080     }
00081 
00082     void serialize(
00083         const StateSerializerStrategy<Scalar>& stateSerializer,
00084         std::ostream& oStream
00085         ) const
00086     { }
00087 
00088     void deSerialize(
00089         const StateSerializerStrategy<Scalar>& stateSerializer,
00090         std::istream& iStream
00091         )
00092     { }
00093 
00094     void set_scaled_x_old(const RCP<const VectorBase<Scalar> >& scaled_x_old )
00095     { 
00096       scaled_x_old_ = Teuchos::null;
00097       if (!Teuchos::is_null(scaled_x_old)) {
00098         scaled_x_old_ = scaled_x_old->clone_v(); 
00099       }
00100     }
00101     RCP<VectorBase<Scalar> > get_scaled_x_old() const
00102     { return scaled_x_old_; }
00103 
00104     void set_x_dot_old(const RCP<const VectorBase<Scalar> >& x_dot_old )
00105     { 
00106       x_dot_old_ = Teuchos::null;
00107       if (!Teuchos::is_null(x_dot_old)) {
00108         x_dot_old_ = x_dot_old->clone_v(); 
00109       }
00110     }
00111     RCP<VectorBase<Scalar> > get_x_dot_old() const
00112     { return x_dot_old_; }
00113 
00114     void set_x(const RCP<const VectorBase<Scalar> >& x )
00115     { 
00116       x_ = Teuchos::null;
00117       if (!Teuchos::is_null(x)) {
00118         x_ = x->clone_v(); 
00119       }
00120     }
00121     RCP<VectorBase<Scalar> > get_x() const
00122     { return x_; }
00123 
00124     void set_x_dot(const RCP<const VectorBase<Scalar> >& x_dot )
00125     { 
00126       x_dot_ = Teuchos::null;
00127       if (!Teuchos::is_null(x_dot)) {
00128         x_dot_ = x_dot->clone_v(); 
00129       }
00130     }
00131     RCP<VectorBase<Scalar> > get_x_dot() const
00132     { return x_dot_; }
00133 
00134     void set_t(const Scalar & t)
00135     { t_ = t; }
00136     Scalar get_t() const
00137     { return t_; }
00138 
00139     void set_t_old(const Scalar & t_old)
00140     { t_old_ = t_old; }
00141     Scalar get_t_old() const
00142     { return t_old_; }
00143 
00144     void set_dt(const Scalar & dt)
00145     { dt_ = dt; }
00146     Scalar get_dt() const
00147     { return dt_; }
00148 
00149     void set_numSteps(const int & numSteps)
00150     { numSteps_ = numSteps; }
00151     int get_numSteps() const
00152     { return numSteps_; }
00153 
00154     void set_isInitialized(const bool & isInitialized)
00155     { isInitialized_ = isInitialized; }
00156     bool get_isInitialized() const
00157     { return isInitialized_; }
00158 
00159     void set_haveInitialCondition(const bool & haveInitialCondition)
00160     { haveInitialCondition_ = haveInitialCondition; }
00161     bool get_haveInitialCondition() const
00162     { return haveInitialCondition_; }
00163 
00164     void set_parameterList(const RCP<const ParameterList>& pl)
00165     { 
00166       parameterList_ = Teuchos::null;
00167       if (!Teuchos::is_null(pl)) {
00168         parameterList_ = Teuchos::parameterList(*pl); 
00169       }
00170     }
00171     RCP<ParameterList> get_parameterList() const
00172     { return parameterList_; }
00173 
00174     void set_basePoint(Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint)
00175     { basePoint_ = basePoint; };
00176     Thyra::ModelEvaluatorBase::InArgs<Scalar> get_basePoint() const
00177     { return basePoint_; }
00178 
00179     void set_neModel(const RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >& neModel)
00180     { 
00181       neModel_ = Teuchos::null;
00182       if (!Teuchos::is_null(neModel)) {
00183         neModel_ = Teuchos::rcp(new Rythmos::SingleResidualModelEvaluator<Scalar>);
00184       }
00185     }
00186     RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > get_neModel() const
00187     { return neModel_; }
00188 
00189     void set_interpolator(const RCP<InterpolatorBase<Scalar> >& interpolator)
00190     {
00191       interpolator_ = Teuchos::null;
00192       if (!Teuchos::is_null(interpolator)) {
00193         TEUCHOS_ASSERT(interpolator->supportsCloning());
00194         interpolator_ = interpolator->cloneInterpolator();
00195       }
00196     }
00197     RCP<InterpolatorBase<Scalar> > get_interpolator() const
00198     { return interpolator_; }
00199 
00200     void setParameterList(const RCP<ParameterList>& paramList)
00201     { this->setMyParamList(paramList); }
00202     RCP<const ParameterList> getValidParameters() const
00203     { return Teuchos::null; }
00204 
00205   private:
00206     RCP<Thyra::VectorBase<Scalar> > scaled_x_old_;
00207     RCP<Thyra::VectorBase<Scalar> > x_dot_old_;
00208     RCP<Thyra::VectorBase<Scalar> > x_;
00209     RCP<Thyra::VectorBase<Scalar> > x_dot_;
00210     Scalar t_;
00211     Scalar t_old_;
00212     Scalar dt_;
00213     int numSteps_;
00214     bool isInitialized_;
00215     bool haveInitialCondition_;
00216     RCP<Teuchos::ParameterList> parameterList_;
00217     Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
00218     RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >  neModel_; 
00219     RCP<InterpolatorBase<Scalar> > interpolator_;
00220 
00221 };
00222 
00223 
00234 template<class Scalar>
00235 class BackwardEulerStepper : 
00236   virtual public SolverAcceptingStepperBase<Scalar>,
00237   virtual public InterpolatorAcceptingObjectBase<Scalar>
00238 {
00239 public:
00240   
00242   typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00243   
00246 
00248   BackwardEulerStepper();
00249   
00251   BackwardEulerStepper(
00252     const RCP<Thyra::ModelEvaluator<Scalar> >& model,
00253     const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
00254     );
00255 
00257   
00260   
00262   void setInterpolator(const RCP<InterpolatorBase<Scalar> >& interpolator);
00263 
00265   RCP<InterpolatorBase<Scalar> > getNonconstInterpolator();
00266 
00268   RCP<const InterpolatorBase<Scalar> > getInterpolator() const;
00269   
00271   RCP<InterpolatorBase<Scalar> > unSetInterpolator();
00272 
00274 
00277 
00279   void setSolver(
00280     const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver
00281     );
00282 
00284   RCP<Thyra::NonlinearSolverBase<Scalar> >
00285   getNonconstSolver();
00286 
00288   RCP<const Thyra::NonlinearSolverBase<Scalar> >
00289   getSolver() const;
00290 
00292 
00295  
00297   bool supportsCloning() const;
00298 
00306   RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const;
00307 
00309   bool isImplicit() const;
00310 
00312   void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> >& model);
00313 
00315   void setNonconstModel(const RCP<Thyra::ModelEvaluator<Scalar> >& model);
00316   
00318   RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const;
00319 
00321   RCP<Thyra::ModelEvaluator<Scalar> > getNonconstModel();
00322 
00324   void setInitialCondition(
00325     const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
00326     );
00327 
00329   Thyra::ModelEvaluatorBase::InArgs<Scalar> getInitialCondition() const;
00330 
00332   Scalar takeStep(Scalar dt, StepSizeType flag);
00333   
00335   const StepStatus<Scalar> getStepStatus() const;
00336   
00338 
00341 
00343   RCP<const Thyra::VectorSpaceBase<Scalar> >
00344   get_x_space() const;
00345 
00347   void addPoints(
00348     const Array<Scalar>& time_vec,
00349     const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec,
00350     const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec
00351     );
00352   
00354   TimeRange<Scalar> getTimeRange() const;
00355   
00357   void getPoints(
00358     const Array<Scalar>& time_vec,
00359     Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec,
00360     Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec,
00361     Array<ScalarMag>* accuracy_vec
00362     ) const;
00363   
00365   void getNodes(Array<Scalar>* time_vec) const;
00366   
00368   void removeNodes(Array<Scalar>& time_vec);
00369 
00371   int getOrder() const;
00372 
00374   
00377 
00379   void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
00380   
00382   RCP<Teuchos::ParameterList> getNonconstParameterList();
00383   
00385   RCP<Teuchos::ParameterList> unsetParameterList();
00386   
00388   RCP<const Teuchos::ParameterList> getValidParameters() const;
00389  
00391 
00394   
00396   void describe(
00397     Teuchos::FancyOStream  &out,
00398     const Teuchos::EVerbosityLevel verbLevel
00399     ) const;
00400 
00402   
00406   RCP<const MomentoBase<Scalar> > getMomento() const;
00407 
00411   void setMomento(
00412       const Ptr<const MomentoBase<Scalar> >& momentoPtr,
00413       const RCP<Thyra::ModelEvaluator<Scalar> >& model,
00414       const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
00415       );
00416 
00417 
00418 private:
00419 
00420   // ///////////////////////
00421   // Private date members
00422 
00423   bool isInitialized_;
00424   bool haveInitialCondition_;
00425   RCP<const Thyra::ModelEvaluator<Scalar> > model_;
00426   RCP<Thyra::NonlinearSolverBase<Scalar> > solver_;
00427   RCP<Thyra::VectorBase<Scalar> > scaled_x_old_;
00428   RCP<Thyra::VectorBase<Scalar> > x_dot_old_;
00429 
00430   Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
00431   RCP<Thyra::VectorBase<Scalar> > x_;
00432   RCP<Thyra::VectorBase<Scalar> > x_dot_;
00433   Scalar t_;
00434   Scalar t_old_;
00435 
00436   Scalar dt_;
00437   int numSteps_;
00438 
00439   RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >  neModel_;
00440 
00441   RCP<Teuchos::ParameterList> parameterList_;
00442 
00443   RCP<InterpolatorBase<Scalar> > interpolator_;
00444 
00445 
00446   // //////////////////////////
00447   // Private member functions
00448 
00449   void defaultInitializeAll_();
00450   void initialize();
00451   void checkConsistentState_();
00452 
00453 };
00454 
00459 template<class Scalar>
00460 RCP<BackwardEulerStepper<Scalar> >
00461 backwardEulerStepper(
00462     const RCP<Thyra::ModelEvaluator<Scalar> >& model,
00463     const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
00464     );
00465 
00466 template<class Scalar>
00467 RCP<BackwardEulerStepper<Scalar> >
00468 backwardEulerStepper();
00469 
00470 
00471 } // namespace Rythmos
00472 
00473 #endif //Rythmos_BACKWARD_EULER_STEPPER_DECL_H
 All Classes Functions Variables Typedefs Friends