10 #ifndef Tempus_StepperTrapezoidal_impl_hpp
11 #define Tempus_StepperTrapezoidal_impl_hpp
14 #include "Tempus_WrapperModelEvaluatorBasic.hpp"
18 template <
class Scalar>
21 this->setStepperName(
"Trapezoidal Method");
22 this->setStepperType(
"Trapezoidal Method");
23 this->setUseFSAL(
true);
24 this->setICConsistency(
"Consistent");
25 this->setICConsistencyCheck(
false);
26 this->setZeroInitialGuess(
false);
28 this->setAppAction(Teuchos::null);
29 this->setDefaultSolver();
32 template <
class Scalar>
36 bool useFSAL, std::string ICConsistency,
bool ICConsistencyCheck,
37 bool zeroInitialGuess,
41 this->setStepperName(
"Trapezoidal Method");
42 this->setStepperType(
"Trapezoidal Method");
43 this->setUseFSAL(useFSAL);
44 this->setICConsistency(ICConsistency);
45 this->setICConsistencyCheck(ICConsistencyCheck);
46 this->setZeroInitialGuess(zeroInitialGuess);
48 this->setAppAction(stepperTrapAppAction);
49 this->setSolver(solver);
51 if (appModel != Teuchos::null) {
52 this->setModel(appModel);
57 template <
class Scalar>
61 if (appAction == Teuchos::null) {
63 stepperTrapAppAction_ =
67 stepperTrapAppAction_ = appAction;
69 this->isInitialized_ =
false;
72 template <
class Scalar>
78 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
81 if (initialState->getXDot() == Teuchos::null)
82 this->setStepperXDot(initialState->getX()->clone_v());
84 this->setStepperXDot(initialState->getXDot());
89 !(this->getUseFSAL()), std::logic_error,
90 "Error - The First-Same-As-Last (FSAL) principle is required\n"
91 " for the Trapezoidal Stepper (i.e., useFSAL=true)!\n");
101 template <
class Scalar>
105 this->checkInitialized();
109 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperTrapezoidal::takeStep()");
112 solutionHistory->getNumStates() < 2, std::logic_error,
113 "Error - StepperTrapezoidal<Scalar>::takeStep(...)\n"
114 <<
"Need at least two SolutionStates for Trapezoidal.\n"
115 <<
" Number of States = " << solutionHistory->getNumStates()
116 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
118 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
120 RCP<StepperTrapezoidal<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
121 stepperTrapAppAction_->execute(
122 solutionHistory, thisStepper,
125 RCP<SolutionState<Scalar> > workingState =
126 solutionHistory->getWorkingState();
127 RCP<SolutionState<Scalar> > currentState =
128 solutionHistory->getCurrentState();
130 RCP<const Thyra::VectorBase<Scalar> > xOld = currentState->getX();
131 RCP<const Thyra::VectorBase<Scalar> > xDotOld = currentState->getXDot();
132 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
133 if (workingState->getXDot() != Teuchos::null)
134 this->setStepperXDot(workingState->getXDot());
135 RCP<Thyra::VectorBase<Scalar> > xDot = this->getStepperXDot();
137 const Scalar time = workingState->getTime();
138 const Scalar dt = workingState->getTimeStep();
139 const Scalar alpha = getAlpha(dt);
140 const Scalar beta = getBeta(dt);
148 stepperTrapAppAction_->execute(
149 solutionHistory, thisStepper,
153 this->solveImplicitODE(x, xDot, time, p);
154 stepperTrapAppAction_->execute(
155 solutionHistory, thisStepper,
158 if (workingState->getXDot() != Teuchos::null) timeDer->compute(x, xDot);
160 workingState->setSolutionStatus(sStatus);
161 workingState->setOrder(this->getOrder());
162 workingState->computeNorms(currentState);
163 stepperTrapAppAction_->execute(
164 solutionHistory, thisStepper,
176 template <
class Scalar>
185 template <
class Scalar>
194 out <<
"--- StepperTrapezoidal ---\n";
195 out <<
" stepperTrapAppAction_ = " << stepperTrapAppAction_ << std::endl;
196 out <<
"--------------------------" << std::endl;
199 template <
class Scalar>
203 bool isValidSetup =
true;
208 if (stepperTrapAppAction_ == Teuchos::null) {
209 isValidSetup =
false;
210 out <<
"The Trapezoidal AppAction is not set!\n";
218 template <
class Scalar>
224 stepper->setStepperImplicitValues(pl);
226 if (model != Teuchos::null) {
227 stepper->setModel(model);
228 stepper->initialize();
235 #endif // Tempus_StepperTrapezoidal_impl_hpp
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
Trapezoidal method time stepper.
Default modifier for StepperTrapezoidal.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
StepperTrapezoidal()
Default constructor.
Thyra Base interface for time steppers.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) override
Set the initial conditions and make them consistent.
Teuchos::RCP< StepperTrapezoidal< Scalar > > createStepperTrapezoidal(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
StepperState is a simple class to hold state information about the stepper.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Thyra Base interface for implicit time steppers.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Application Action for StepperTrapezoidal.
virtual void setAppAction(Teuchos::RCP< StepperTrapezoidalAppAction< Scalar > > appAction)
Time-derivative interface for Trapezoidal method.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.