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);
38 template<
class Scalar>
40 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
42 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
44 std::string ICConsistency,
45 bool ICConsistencyCheck,
46 bool zeroInitialGuess)
49 this->setStepperType(
"Trapezoidal Method");
50 this->setUseFSAL( useFSAL);
51 this->setICConsistency( ICConsistency);
52 this->setICConsistencyCheck( ICConsistencyCheck);
53 this->setZeroInitialGuess( zeroInitialGuess);
55 this->setObserver(obs);
57 if (appModel != Teuchos::null) {
58 this->setModel(appModel);
59 this->setSolver(solver);
65 template<
class Scalar>
69 if (obs == Teuchos::null) {
71 if (this->stepperObserver_ == Teuchos::null) {
72 stepperTrapObserver_ =
74 this->stepperObserver_ =
76 (stepperTrapObserver_,
true);
79 this->stepperObserver_ = obs;
80 stepperTrapObserver_ =
82 (this->stepperObserver_,
true);
87 template<
class Scalar>
90 TEUCHOS_TEST_FOR_EXCEPTION(
91 this->wrapperModel_ == Teuchos::null, std::logic_error,
92 "Error - Need to set the model, setModel(), before calling "
93 "StepperTrapezoidal::initialize()\n");
97 template<
class Scalar>
103 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
106 if (initialState->getXDot() == Teuchos::null)
107 this->setStepperXDot(initialState->getX()->clone_v());
111 TEUCHOS_TEST_FOR_EXCEPTION( !(this->getUseFSAL()), std::logic_error,
112 "Error - The First-Step-As-Last (FSAL) principle is required\n"
113 " for the Trapezoidal Stepper (i.e., useFSAL=true)!\n");
124 template<
class Scalar>
130 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperTrapezoidal::takeStep()");
134 "Error - StepperTrapezoidal<Scalar>::takeStep(...)\n"
135 "Need at least two SolutionStates for Trapezoidal.\n"
137 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
138 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
141 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
142 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
144 RCP<const Thyra::VectorBase<Scalar> > xOld = currentState->getX();
145 RCP<const Thyra::VectorBase<Scalar> > xDotOld = currentState->getXDot();
146 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
147 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
149 const Scalar time = workingState->getTime();
150 const Scalar dt = workingState->getTimeStep();
151 const Scalar alpha = getAlpha(dt);
152 const Scalar beta = getBeta (dt);
155 Teuchos::RCP<TimeDerivative<Scalar> > timeDer =
157 alpha, xOld, xDotOld));
160 timeDer, dt, alpha, beta));
164 const Thyra::SolveStatus<Scalar> sStatus =
165 this->solveImplicitODE(x, xDot, time, p);
169 if (workingState->getXDot() != Teuchos::null)
170 timeDer->compute(x, xDot);
172 workingState->setSolutionStatus(sStatus);
173 workingState->setOrder(this->getOrder());
186 template<
class Scalar>
187 Teuchos::RCP<Tempus::StepperState<Scalar> >
191 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
197 template<
class Scalar>
199 Teuchos::FancyOStream &out,
200 const Teuchos::EVerbosityLevel )
const
202 out << this->getStepperType() <<
"::describe:" << std::endl
203 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
207 template<
class Scalar>
208 Teuchos::RCP<const Teuchos::ParameterList>
211 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
213 pl->set<
bool> (
"Use FSAL", this->getUseFSALDefault());
214 pl->set<std::string>(
"Initial Condition Consistency",
215 this->getICConsistencyDefault());
216 pl->set<std::string>(
"Solver Name",
"Default Solver");
217 pl->set<
bool> (
"Zero Initial Guess",
false);
219 pl->set(
"Default Solver", *solverPL);
226 #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.
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.
StepperTrapezoidalObserver class for StepperTrapezoidal.
virtual void initialize()
Initialize during construction and after changing input parameters.
StepperObserver class for Stepper class.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
Time-derivative interface for Trapezoidal method.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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.