9 #ifndef Tempus_StepperTrapezoidal_impl_hpp
10 #define Tempus_StepperTrapezoidal_impl_hpp
13 #include "Tempus_WrapperModelEvaluatorBasic.hpp"
17 template <
class Scalar>
20 this->setStepperName(
"Trapezoidal Method");
21 this->setStepperType(
"Trapezoidal Method");
22 this->setUseFSAL(
true);
23 this->setICConsistency(
"Consistent");
24 this->setICConsistencyCheck(
false);
25 this->setZeroInitialGuess(
false);
27 this->setAppAction(Teuchos::null);
28 this->setDefaultSolver();
31 template <
class Scalar>
35 bool useFSAL, std::string ICConsistency,
bool ICConsistencyCheck,
36 bool zeroInitialGuess,
40 this->setStepperName(
"Trapezoidal Method");
41 this->setStepperType(
"Trapezoidal Method");
42 this->setUseFSAL(useFSAL);
43 this->setICConsistency(ICConsistency);
44 this->setICConsistencyCheck(ICConsistencyCheck);
45 this->setZeroInitialGuess(zeroInitialGuess);
47 this->setAppAction(stepperTrapAppAction);
48 this->setSolver(solver);
50 if (appModel != Teuchos::null) {
51 this->setModel(appModel);
56 template <
class Scalar>
60 if (appAction == Teuchos::null) {
62 stepperTrapAppAction_ =
66 stepperTrapAppAction_ = appAction;
68 this->isInitialized_ =
false;
71 template <
class Scalar>
77 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
80 if (initialState->getXDot() == Teuchos::null)
81 this->setStepperXDot(initialState->getX()->clone_v());
83 this->setStepperXDot(initialState->getXDot());
88 !(this->getUseFSAL()), std::logic_error,
89 "Error - The First-Same-As-Last (FSAL) principle is required\n"
90 " for the Trapezoidal Stepper (i.e., useFSAL=true)!\n");
100 template <
class Scalar>
104 this->checkInitialized();
108 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperTrapezoidal::takeStep()");
111 solutionHistory->getNumStates() < 2, std::logic_error,
112 "Error - StepperTrapezoidal<Scalar>::takeStep(...)\n"
113 <<
"Need at least two SolutionStates for Trapezoidal.\n"
114 <<
" Number of States = " << solutionHistory->getNumStates()
115 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
117 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
119 RCP<StepperTrapezoidal<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
120 stepperTrapAppAction_->execute(
121 solutionHistory, thisStepper,
124 RCP<SolutionState<Scalar> > workingState =
125 solutionHistory->getWorkingState();
126 RCP<SolutionState<Scalar> > currentState =
127 solutionHistory->getCurrentState();
129 RCP<const Thyra::VectorBase<Scalar> > xOld = currentState->getX();
130 RCP<const Thyra::VectorBase<Scalar> > xDotOld = currentState->getXDot();
131 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
132 if (workingState->getXDot() != Teuchos::null)
133 this->setStepperXDot(workingState->getXDot());
134 RCP<Thyra::VectorBase<Scalar> > xDot = this->getStepperXDot();
136 const Scalar time = workingState->getTime();
137 const Scalar dt = workingState->getTimeStep();
138 const Scalar alpha = getAlpha(dt);
139 const Scalar beta = getBeta(dt);
147 stepperTrapAppAction_->execute(
148 solutionHistory, thisStepper,
152 this->solveImplicitODE(x, xDot, time, p);
153 stepperTrapAppAction_->execute(
154 solutionHistory, thisStepper,
157 if (workingState->getXDot() != Teuchos::null) timeDer->compute(x, xDot);
159 workingState->setSolutionStatus(sStatus);
160 workingState->setOrder(this->getOrder());
161 workingState->computeNorms(currentState);
162 stepperTrapAppAction_->execute(
163 solutionHistory, thisStepper,
175 template <
class Scalar>
184 template <
class Scalar>
193 out <<
"--- StepperTrapezoidal ---\n";
194 out <<
" stepperTrapAppAction_ = " << stepperTrapAppAction_ << std::endl;
195 out <<
"--------------------------" << std::endl;
198 template <
class Scalar>
202 bool isValidSetup =
true;
207 if (stepperTrapAppAction_ == Teuchos::null) {
208 isValidSetup =
false;
209 out <<
"The Trapezoidal AppAction is not set!\n";
217 template <
class Scalar>
223 stepper->setStepperImplicitValues(pl);
225 if (model != Teuchos::null) {
226 stepper->setModel(model);
227 stepper->initialize();
234 #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.