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::StepperForwardEuler<Scalar>
27 {
28 public:
29 
30  /// Constructor
32  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
33  Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null)
34  : Tempus::StepperForwardEuler<Scalar>(appModel, pList) {}
35 
36  /// Take the specified timestep, dt, and return true if successful.
37  virtual void takeStep(
39 {
40  using Teuchos::RCP;
41 
42  TEMPUS_FUNC_TIME_MONITOR("Tempus::StepperForwardEuler::takeStep()");
43  {
44  this->stepperFEObserver_->observeBeginTakeStep(solutionHistory, *this);
45  RCP<Tempus::SolutionState<Scalar> > currentState =
46  solutionHistory->getCurrentState();
47 
48  typedef Thyra::ModelEvaluatorBase MEB;
49  this->inArgs_.set_x(currentState->getX());
50  if (this->inArgs_.supports(MEB::IN_ARG_t))
51  this->inArgs_.set_t(currentState->getTime());
52 
53  // For model evaluators whose state function f(x, x_dot, t) describes
54  // an implicit ODE, and which accept an optional x_dot input argument,
55  // make sure the latter is set to null in order to request the evaluation
56  // of a state function corresponding to the explicit ODE formulation
57  // x_dot = f(x, t)
58  if (this->inArgs_.supports(MEB::IN_ARG_x_dot))
59  this->inArgs_.set_x_dot(Teuchos::null);
60  this->outArgs_.set_f(currentState->getXDot());
61 
62  this->stepperFEObserver_->observeBeforeExplicit(solutionHistory, *this);
63 
64  this->appModel_->evalModel(this->inArgs_,this->outArgs_);
65 
66  // Forward Euler update, x = x + dt*xdot
67  RCP<Tempus::SolutionState<Scalar> > workingState =
68  solutionHistory->getWorkingState();
69  const Scalar dt = workingState->getTimeStep();
70  Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
71  *(currentState->getX()),dt,*(currentState->getXDot()));
72 
73  RCP<PhysicsStateCounter<Scalar> > pSC =
74  Teuchos::rcp_dynamic_cast<PhysicsStateCounter<Scalar> >
75  (workingState->getPhysicsState());
76  int counter = pSC->getCounter();
77  counter++;
78  pSC->setCounter(counter);
79 
80  workingState->setSolutionStatus(Tempus::Status::PASSED);
81  workingState->setOrder(this->getOrder());
82  this->stepperFEObserver_->observeEndTakeStep(solutionHistory, *this);
83  }
84  return;
85 }
86 
87 };
88 
89 } // namespace Tempus_Test
90 
91 #endif // Tempus_PhysicsStateTest_StepperForwardEuler_hpp
This is a Forward Euler time stepper to test the PhysicsState.
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > appModel_
Explicit ODE ModelEvaluator.
virtual int getCounter() const
Return counter of PhysicsStateCounter.
PhysicsStateTest_StepperForwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel, Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Constructor.
Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs_
virtual void takeStep(const Teuchos::RCP< Tempus::SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
Teuchos::RCP< StepperForwardEulerObserver< Scalar > > stepperFEObserver_
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
PhysicsStateCounter is a simple PhysicsState that counts steps.
Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs_