Rythmos_ForwardEulerStepper.hpp

Go to the documentation of this file.
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_H
00030 #define Rythmos_FORWARDEULER_STEPPER_H
00031 
00032 #include "Rythmos_Stepper.hpp"
00033 #include "Teuchos_RefCountPtr.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 #include "Thyra_ModelEvaluator.hpp"
00036 #include "Thyra_ModelEvaluatorHelpers.hpp"
00037 
00038 namespace Rythmos {
00039 
00041 template<class Scalar>
00042 class ForwardEulerStepper : virtual public Stepper<Scalar>
00043 {
00044   public:
00045 
00046     typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00047     
00049     ForwardEulerStepper();
00050     ForwardEulerStepper(const Teuchos::RefCountPtr<const Thyra::ModelEvaluator<Scalar> > &model);
00051     
00053     ~ForwardEulerStepper();
00054 
00056     Scalar TakeStep(Scalar dt);
00057    
00059     Scalar TakeStep();
00060 
00062     Teuchos::RefCountPtr<const Thyra::VectorBase<Scalar> > get_solution() const;
00063 
00065     Teuchos::RefCountPtr<const Thyra::VectorBase<Scalar> > get_residual() const;
00066     
00068     std::string description() const;
00069 
00071     std::ostream& describe(
00072       std::ostream                &out
00073       ,const Teuchos::EVerbosityLevel      verbLevel
00074       ,const std::string          leadingIndent
00075       ,const std::string          indentSpacer
00076       ) const;
00077     
00080     bool SetPoints(
00081       const std::vector<Scalar>& time_list
00082       ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& x_list
00083       ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& xdot_list);
00084     
00086     bool GetPoints(
00087       const std::vector<Scalar>& time_list
00088       ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* x_list
00089       ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* xdot_list
00090       ,std::vector<ScalarMag>* accuracy_list) const;
00091 
00093     bool SetRange(
00094       const Scalar& time_lower
00095       ,const Scalar& time_upper
00096       ,const InterpolationBuffer<Scalar> & IB);
00097 
00099     bool GetNodes(std::vector<Scalar>* time_list) const;
00100 
00102     bool RemoveNodes(std::vector<Scalar>& time_list) const;
00103 
00105     int GetOrder() const;
00106 
00107 
00108 
00109   private:
00110 
00111     Teuchos::RefCountPtr<const Thyra::ModelEvaluator<Scalar> > model_;
00112     Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > solution_vector_;
00113     Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > residual_vector_;
00114     Scalar t_;
00115 
00116 };
00117 
00118 template<class Scalar>
00119 ForwardEulerStepper<Scalar>::ForwardEulerStepper(const Teuchos::RefCountPtr<const Thyra::ModelEvaluator<Scalar> > &model)
00120 {
00121   typedef Teuchos::ScalarTraits<Scalar> ST;
00122   model_ = model;
00123   t_ = ST::zero();
00124   solution_vector_ = model_->getNominalValues().get_x()->clone_v();
00125   residual_vector_ = Thyra::createMember(model_->get_f_space());
00126 }
00127 
00128 template<class Scalar>
00129 ForwardEulerStepper<Scalar>::ForwardEulerStepper()
00130 {
00131 }
00132 
00133 template<class Scalar>
00134 ForwardEulerStepper<Scalar>::~ForwardEulerStepper()
00135 {
00136 }
00137 
00138 template<class Scalar>
00139 Scalar ForwardEulerStepper<Scalar>::TakeStep()
00140 {
00141   // print something out about this method not supporting automatic variable step-size
00142   typedef Teuchos::ScalarTraits<Scalar> ST;
00143   return(-ST::one());
00144 }
00145 
00146 template<class Scalar>
00147 Scalar ForwardEulerStepper<Scalar>::TakeStep(Scalar dt)
00148 {
00149 /*
00150   Thyra::ModelEvaluatorBase::InArgs<Scalar>   inArgs  = model_->createInArgs();
00151   Thyra::ModelEvaluatorBase::OutArgs<Scalar>  outArgs = model_->createOutArgs();
00152 
00153   inArgs.set_x(solution_vector_);
00154   inArgs.set_t(t_+dt);
00155 
00156   outArgs.set_f(residual_vector_);
00157 
00158   model_->evalModel(inArgs,outArgs);
00159 */
00160   Thyra::eval_f<Scalar>(*model_,*solution_vector_,t_+dt,&*residual_vector_);
00161 
00162   // solution_vector = solution_vector + dt*residual_vector
00163   Thyra::Vp_StV(&*solution_vector_,dt,*residual_vector_); 
00164   t_ += dt;
00165 
00166   return(dt);
00167 }
00168 
00169 template<class Scalar>
00170 Teuchos::RefCountPtr<const Thyra::VectorBase<Scalar> > ForwardEulerStepper<Scalar>::get_solution() const
00171 {
00172   return(solution_vector_);
00173 }
00174 
00175 template<class Scalar>
00176 Teuchos::RefCountPtr<const Thyra::VectorBase<Scalar> > ForwardEulerStepper<Scalar>::get_residual() const
00177 {
00178   return(residual_vector_);
00179 }
00180 
00181 template<class Scalar>
00182 std::string ForwardEulerStepper<Scalar>::description() const
00183 {
00184   std::string name = "Rythmos::ForwardEulerStepper";
00185   return(name);
00186 }
00187 
00188 template<class Scalar>
00189 std::ostream& ForwardEulerStepper<Scalar>::describe(
00190       std::ostream                &out
00191       ,const Teuchos::EVerbosityLevel      verbLevel
00192       ,const std::string          leadingIndent
00193       ,const std::string          indentSpacer
00194       ) const
00195 {
00196   if (verbLevel == Teuchos::VERB_EXTREME)
00197   {
00198     out << description() << "::describe" << std::endl;
00199     out << "model_ = " << std::endl;
00200     out << model_->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00201     out << "solution_vector_ = " << std::endl;
00202     out << solution_vector_->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00203     out << "residual_vector_ = " << std::endl;
00204     out << residual_vector_->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00205   }
00206   return(out);
00207 }
00208 
00209 template<class Scalar>
00210 bool ForwardEulerStepper<Scalar>::SetPoints(
00211     const std::vector<Scalar>& time_list
00212     ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& x_list
00213     ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& xdot_list)
00214 {
00215   return(false);
00216 }
00217 
00218 template<class Scalar>
00219 bool ForwardEulerStepper<Scalar>::GetPoints(
00220     const std::vector<Scalar>& time_list
00221     ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* x_list
00222     ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* xdot_list
00223     ,std::vector<ScalarMag>* accuracy_list) const
00224 {
00225   return(false);
00226 }
00227 
00228 template<class Scalar>
00229 bool ForwardEulerStepper<Scalar>::SetRange(
00230     const Scalar& time_lower
00231     ,const Scalar& time_upper
00232     ,const InterpolationBuffer<Scalar>& IB)
00233 {
00234   return(false);
00235 }
00236 
00237 template<class Scalar>
00238 bool ForwardEulerStepper<Scalar>::GetNodes(std::vector<Scalar>* time_list) const
00239 {
00240   return(false);
00241 }
00242 
00243 template<class Scalar>
00244 bool ForwardEulerStepper<Scalar>::RemoveNodes(std::vector<Scalar>& time_list) const
00245 {
00246   return(false);
00247 }
00248 
00249 template<class Scalar>
00250 int ForwardEulerStepper<Scalar>::GetOrder() const
00251 {
00252   return(1);
00253 }
00254 
00255 
00256 } // namespace Rythmos
00257 
00258 #endif //Rythmos_FORWARDEULER_STEPPER_H

Generated on Thu Sep 18 12:30:05 2008 for Rythmos - Transient Integration for Differential Equations by doxygen 1.3.9.1