Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_PhysicsStateTest_StepperForwardEuler.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_PhysicsStateTest_StepperForwardEuler_hpp
10 #define Tempus_PhysicsStateTest_StepperForwardEuler_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_StepperForwardEuler.hpp"
15 
16 
17 namespace Tempus_Test {
18 
19 /** \brief This is a Forward Euler time stepper to test the PhysicsState.
20  *
21  * It is derived from StepperForwardEuler, and simply increments
22  * a physics counter.
23  */
24 template<class Scalar>
26  : virtual public Tempus::StepperExplicit<Scalar>
27 {
28 public:
29 
30  /// Constructor
32  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel)
33  {
34  this->setStepperType( this->description());
35  this->setUseFSAL( this->getUseFSALDefault());
38 
39  this->setModel(appModel);
40  }
41 
42  void setObserver(Teuchos::RCP<Tempus::StepperObserver<Scalar> > /*obs*/) {}
43  virtual Teuchos::RCP<Tempus::StepperObserver<Scalar> > getObserver() const
44  { return Teuchos::null; }
45  void initialize() {}
46  Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState()
47  { return Teuchos::null; }
48  Scalar getOrder() const {return 1.0;}
49  Scalar getOrderMin() const {return 1.0;}
50  Scalar getOrderMax() const {return 1.0;}
52 
53  /// Take the specified timestep, dt, and return true if successful.
54  virtual void takeStep(
55  const Teuchos::RCP<Tempus::SolutionHistory<Scalar> >& solutionHistory)
56 {
57  using Teuchos::RCP;
58 
59  TEMPUS_FUNC_TIME_MONITOR("Tempus::StepperPhysicsStateTest::takeStep()");
60  {
61  RCP<Tempus::SolutionState<Scalar> > currentState =
62  solutionHistory->getCurrentState();
63 
64  typedef Thyra::ModelEvaluatorBase MEB;
65  this->inArgs_.set_x(currentState->getX());
66  if (this->inArgs_.supports(MEB::IN_ARG_t))
67  this->inArgs_.set_t(currentState->getTime());
68 
69  // For model evaluators whose state function f(x, x_dot, t) describes
70  // an implicit ODE, and which accept an optional x_dot input argument,
71  // make sure the latter is set to null in order to request the evaluation
72  // of a state function corresponding to the explicit ODE formulation
73  // x_dot = f(x, t)
74  if (this->inArgs_.supports(MEB::IN_ARG_x_dot))
75  this->inArgs_.set_x_dot(Teuchos::null);
76  this->outArgs_.set_f(currentState->getXDot());
77 
78  this->appModel_->evalModel(this->inArgs_,this->outArgs_);
79 
80  // Forward Euler update, x = x + dt*xdot
81  RCP<Tempus::SolutionState<Scalar> > workingState =
82  solutionHistory->getWorkingState();
83  const Scalar dt = workingState->getTimeStep();
84  Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
85  *(currentState->getX()),dt,*(currentState->getXDot()));
86 
87  RCP<PhysicsStateCounter<Scalar> > pSC =
88  Teuchos::rcp_dynamic_cast<PhysicsStateCounter<Scalar> >
89  (workingState->getPhysicsState());
90  int counter = pSC->getCounter();
91  counter++;
92  pSC->setCounter(counter);
93 
94  workingState->setSolutionStatus(Tempus::Status::PASSED);
95  workingState->setOrder(this->getOrder());
96  }
97  return;
98 }
99 
100 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const
101 {
102  return Teuchos::null;
103 }
104 
105 };
106 
107 } // namespace Tempus_Test
108 
109 #endif // Tempus_PhysicsStateTest_StepperForwardEuler_hpp
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > appModel_
Explicit ODE ModelEvaluator.
This is a Forward Euler time stepper to test the PhysicsState.
virtual void takeStep(const Teuchos::RCP< Tempus::SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual int getCounter() const
Return counter of PhysicsStateCounter.
Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
virtual bool getICConsistencyCheckDefault() const
virtual std::string getICConsistencyDefault() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual std::string description() const
void setICConsistencyCheck(bool c)
StepperObserver class for Stepper class.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
PhysicsStateCounter is a simple PhysicsState that counts steps.
Stepper integrates first-order ODEs.
void initialize()
Initialize after construction and changing input parameters.
virtual bool getUseFSALDefault() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs_
Thyra Base interface for implicit time steppers.
void setStepperType(std::string s)
StepperPhysicsStateTest(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Constructor.
void setObserver(Teuchos::RCP< Tempus::StepperObserver< Scalar > >)
Set Observer.
void setICConsistency(std::string s)
virtual Teuchos::RCP< Tempus::StepperObserver< Scalar > > getObserver() const
Get Observer.