9 #ifndef Tempus_StepperTrapezoidal_impl_hpp
10 #define Tempus_StepperTrapezoidal_impl_hpp
12 #include "Tempus_config.hpp"
14 #include "Tempus_WrapperModelEvaluatorBasic.hpp"
15 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
16 #include "NOX_Thyra.H"
22 template<
class Scalar>
class StepperFactory;
25 template<
class Scalar>
28 this->setStepperType(
"Trapezoidal Method");
29 this->setUseFSAL( this->getUseFSALDefault());
30 this->setICConsistency( this->getICConsistencyDefault());
31 this->setICConsistencyCheck( this->getICConsistencyCheckDefault());
32 this->setZeroInitialGuess(
false);
35 this->setDefaultSolver();
39 template<
class Scalar>
41 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
43 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
45 std::string ICConsistency,
46 bool ICConsistencyCheck,
47 bool zeroInitialGuess)
50 this->setStepperType(
"Trapezoidal Method");
51 this->setUseFSAL( useFSAL);
52 this->setICConsistency( ICConsistency);
53 this->setICConsistencyCheck( ICConsistencyCheck);
54 this->setZeroInitialGuess( zeroInitialGuess);
56 this->setObserver(obs);
57 this->setSolver(solver);
59 if (appModel != Teuchos::null) {
60 this->setModel(appModel);
66 template<
class Scalar>
70 if (obs == Teuchos::null) {
72 if (this->stepperObserver_ == Teuchos::null) {
73 stepperTrapObserver_ =
75 this->stepperObserver_ =
77 (stepperTrapObserver_,
true);
80 this->stepperObserver_ = obs;
81 stepperTrapObserver_ =
83 (this->stepperObserver_,
true);
86 this->isInitialized_ =
false;
90 template<
class Scalar>
96 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
99 if (initialState->getXDot() == Teuchos::null)
100 this->setStepperXDot(initialState->getX()->clone_v());
104 TEUCHOS_TEST_FOR_EXCEPTION( !(this->getUseFSAL()), std::logic_error,
105 "Error - The First-Step-As-Last (FSAL) principle is required\n"
106 " for the Trapezoidal Stepper (i.e., useFSAL=true)!\n");
117 template<
class Scalar>
121 this->checkInitialized();
125 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperTrapezoidal::takeStep()");
127 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
129 "Error - StepperTrapezoidal<Scalar>::takeStep(...)\n"
130 "Need at least two SolutionStates for Trapezoidal.\n"
131 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
132 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
133 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
135 this->stepperObserver_->observeBeginTakeStep(solutionHistory, *
this);
136 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
137 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
139 RCP<const Thyra::VectorBase<Scalar> > xOld = currentState->getX();
140 RCP<const Thyra::VectorBase<Scalar> > xDotOld = currentState->getXDot();
141 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
142 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
144 const Scalar time = workingState->getTime();
145 const Scalar dt = workingState->getTimeStep();
146 const Scalar alpha = getAlpha(dt);
147 const Scalar beta = getBeta (dt);
150 Teuchos::RCP<TimeDerivative<Scalar> > timeDer =
152 alpha, xOld, xDotOld));
155 timeDer, dt, alpha, beta));
157 stepperTrapObserver_->observeBeforeSolve(solutionHistory, *
this);
159 const Thyra::SolveStatus<Scalar> sStatus =
160 this->solveImplicitODE(x, xDot, time, p);
162 stepperTrapObserver_->observeAfterSolve(solutionHistory, *
this);
164 if (workingState->getXDot() != Teuchos::null)
165 timeDer->compute(x, xDot);
167 workingState->setSolutionStatus(sStatus);
168 workingState->setOrder(this->getOrder());
169 workingState->computeNorms(currentState);
170 this->stepperObserver_->observeEndTakeStep(solutionHistory, *
this);
182 template<
class Scalar>
183 Teuchos::RCP<Tempus::StepperState<Scalar> >
187 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
193 template<
class Scalar>
195 Teuchos::FancyOStream &out,
196 const Teuchos::EVerbosityLevel verbLevel)
const
202 out <<
"--- StepperTrapezoidal ---\n";
203 out <<
" stepperTrapObserver_ = " << stepperTrapObserver_ << std::endl;
204 out <<
"--------------------------" << std::endl;
208 template<
class Scalar>
211 bool isValidSetup =
true;
216 if (stepperTrapObserver_ == Teuchos::null) {
217 isValidSetup =
false;
218 out <<
"The Trapezoidal observer is not set!\n";
225 template<
class Scalar>
226 Teuchos::RCP<const Teuchos::ParameterList>
229 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
231 pl->set<
bool> (
"Use FSAL", this->getUseFSALDefault());
232 pl->set<std::string>(
"Initial Condition Consistency",
233 this->getICConsistencyDefault());
234 pl->set<std::string>(
"Solver Name",
"Default Solver");
235 pl->set<
bool> (
"Zero Initial Guess",
false);
237 pl->set(
"Default Solver", *solverPL);
244 #endif // Tempus_StepperTrapezoidal_impl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
StepperTrapezoidal()
Default constructor.
Thyra Base interface for time steppers.
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.
Thyra Base interface for implicit time steppers.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
StepperTrapezoidalObserver class for StepperTrapezoidal.
StepperObserver class for Stepper class.
Time-derivative interface for Trapezoidal method.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.