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<const 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> >
00266     getNonconstInterpolator();
00267 
00269   RCP<const InterpolatorBase<Scalar> >
00270     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   RCP<const Thyra::ModelEvaluator<Scalar> >
00318   getModel() const;
00319 
00321   void setInitialCondition(
00322     const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
00323     );
00324 
00326   Scalar takeStep(Scalar dt, StepSizeType flag);
00327   
00329   const StepStatus<Scalar> getStepStatus() const;
00330   
00332 
00335 
00337   RCP<const Thyra::VectorSpaceBase<Scalar> >
00338   get_x_space() const;
00339 
00341   void addPoints(
00342     const Array<Scalar>& time_vec,
00343     const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec,
00344     const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec
00345     );
00346   
00348   TimeRange<Scalar> getTimeRange() const;
00349   
00351   void getPoints(
00352     const Array<Scalar>& time_vec,
00353     Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec,
00354     Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec,
00355     Array<ScalarMag>* accuracy_vec
00356     ) const;
00357   
00359   void getNodes(Array<Scalar>* time_vec) const;
00360   
00362   void removeNodes(Array<Scalar>& time_vec);
00363 
00365   int getOrder() const;
00366 
00368   
00371 
00373   void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
00374   
00376   RCP<Teuchos::ParameterList> getNonconstParameterList();
00377   
00379   RCP<Teuchos::ParameterList> unsetParameterList();
00380   
00382   RCP<const Teuchos::ParameterList> getValidParameters() const;
00383  
00385 
00388   
00390   void describe(
00391     Teuchos::FancyOStream  &out,
00392     const Teuchos::EVerbosityLevel verbLevel
00393     ) const;
00394 
00396   
00400   RCP<const MomentoBase<Scalar> > getMomento() const;
00401 
00405   void setMomento(
00406       const Ptr<const MomentoBase<Scalar> >& momentoPtr,
00407       const RCP<const Thyra::ModelEvaluator<Scalar> >& model,
00408       const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
00409       );
00410 
00411 
00412 private:
00413 
00414   // ///////////////////////
00415   // Private date members
00416 
00417   bool isInitialized_;
00418   bool haveInitialCondition_;
00419   RCP<const Thyra::ModelEvaluator<Scalar> > model_;
00420   RCP<Thyra::NonlinearSolverBase<Scalar> > solver_;
00421   RCP<Thyra::VectorBase<Scalar> > scaled_x_old_;
00422   RCP<Thyra::VectorBase<Scalar> > x_dot_old_;
00423 
00424   Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
00425   RCP<Thyra::VectorBase<Scalar> > x_;
00426   RCP<Thyra::VectorBase<Scalar> > x_dot_;
00427   Scalar t_;
00428   Scalar t_old_;
00429 
00430   Scalar dt_;
00431   int numSteps_;
00432 
00433   RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >  neModel_;
00434 
00435   RCP<Teuchos::ParameterList> parameterList_;
00436 
00437   RCP<InterpolatorBase<Scalar> > interpolator_;
00438 
00439 
00440   // //////////////////////////
00441   // Private member functions
00442 
00443   void defaultInitializeAll_();
00444   void initialize();
00445   void checkConsistentState_();
00446 
00447 };
00448 
00453 template<class Scalar>
00454 RCP<BackwardEulerStepper<Scalar> >
00455 backwardEulerStepper(
00456     const RCP<const Thyra::ModelEvaluator<Scalar> > &model,
00457     const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver
00458     );
00459 
00460 template<class Scalar>
00461 RCP<BackwardEulerStepper<Scalar> >
00462 backwardEulerStepper();
00463 
00464 
00465 } // namespace Rythmos
00466 
00467 #endif //Rythmos_BACKWARD_EULER_STEPPER_DECL_H

Generated on Wed May 12 21:25:42 2010 for Rythmos - Transient Integration for Differential Equations by  doxygen 1.4.7