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->setParameterList(Teuchos::null);
33 template<
class Scalar>
35 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
36 Teuchos::RCP<Teuchos::ParameterList> pList)
38 this->setParameterList(pList);
40 if (appModel == Teuchos::null) {
44 this->setModel(appModel);
50 template<
class Scalar>
54 if (obs == Teuchos::null) {
56 if (this->stepperObserver_ == Teuchos::null) {
57 stepperTrapObserver_ =
59 this->stepperObserver_ =
61 (stepperTrapObserver_);
64 this->stepperObserver_ = obs;
65 stepperTrapObserver_ =
67 (this->stepperObserver_);
72 template<
class Scalar>
75 TEUCHOS_TEST_FOR_EXCEPTION(
76 this->wrapperModel_ == Teuchos::null, std::logic_error,
77 "Error - Need to set the model, setModel(), before calling "
78 "StepperTrapezoidal::initialize()\n");
80 this->setParameterList(this->stepperPL_);
86 template<
class Scalar>
92 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
95 if (initialState->getXDot() == Teuchos::null)
96 this->setStepperXDot(initialState->getX()->clone_v());
100 TEUCHOS_TEST_FOR_EXCEPTION( !(this->getUseFSAL()), std::logic_error,
101 "Error - The First-Step-As-Last (FSAL) principle is required\n"
102 " for the Trapezoidal Stepper (i.e., useFSAL=true)!\n");
113 template<
class Scalar>
119 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperTrapezoidal::takeStep()");
123 "Error - StepperTrapezoidal<Scalar>::takeStep(...)\n"
124 "Need at least two SolutionStates for Trapezoidal.\n"
126 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
127 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
130 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
131 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
133 RCP<const Thyra::VectorBase<Scalar> > xOld = currentState->getX();
134 RCP<const Thyra::VectorBase<Scalar> > xDotOld = currentState->getXDot();
135 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
136 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
138 const Scalar time = workingState->getTime();
139 const Scalar dt = workingState->getTimeStep();
140 const Scalar alpha = getAlpha(dt);
141 const Scalar beta = getBeta (dt);
145 Teuchos::RCP<TimeDerivative<Scalar> > timeDer =
147 alpha, xOld, xDotOld));
150 typedef Thyra::ModelEvaluatorBase MEB;
151 MEB::InArgs<Scalar> inArgs = this->wrapperModel_->getInArgs();
152 MEB::OutArgs<Scalar> outArgs = this->wrapperModel_->getOutArgs();
154 if (inArgs.supports(MEB::IN_ARG_x_dot )) inArgs.set_x_dot (xDot);
155 if (inArgs.supports(MEB::IN_ARG_t )) inArgs.set_t (time);
156 if (inArgs.supports(MEB::IN_ARG_step_size)) inArgs.set_step_size(dt);
157 if (inArgs.supports(MEB::IN_ARG_alpha )) inArgs.set_alpha (alpha);
158 if (inArgs.supports(MEB::IN_ARG_beta )) inArgs.set_beta (beta);
160 this->wrapperModel_->setForSolve(timeDer, inArgs, outArgs);
164 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(x);
168 if (workingState->getXDot() != Teuchos::null)
169 timeDer->compute(x, xDot);
171 workingState->setSolutionStatus(sStatus);
172 workingState->setOrder(this->getOrder());
185 template<
class Scalar>
186 Teuchos::RCP<Tempus::StepperState<Scalar> >
190 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
196 template<
class Scalar>
199 std::string name =
"Trapezoidal Method";
204 template<
class Scalar>
206 Teuchos::FancyOStream &out,
207 const Teuchos::EVerbosityLevel )
const
209 out << description() <<
"::describe:" << std::endl
210 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
214 template <
class Scalar>
216 Teuchos::RCP<Teuchos::ParameterList>
const& pList)
218 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
219 if (pList == Teuchos::null) {
221 if (stepperPL == Teuchos::null) stepperPL = this->getDefaultParameters();
225 if (!(stepperPL->isParameter(
"Solver Name"))) {
226 stepperPL->set<std::string>(
"Solver Name",
"Default Solver");
227 Teuchos::RCP<Teuchos::ParameterList> solverPL =
228 this->defaultSolverParameters();
229 stepperPL->set(
"Default Solver", *solverPL);
234 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
235 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"Trapezoidal Method",
237 "Error - Stepper Type is not 'Trapezoidal Method'!\n"
238 <<
" Stepper Type = "<<stepperPL->get<std::string>(
"Stepper Type")<<
"\n");
240 this->stepperPL_ = stepperPL;
244 template<
class Scalar>
245 Teuchos::RCP<const Teuchos::ParameterList>
248 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
249 pl->setName(
"Default Stepper - " + this->description());
250 pl->set<std::string>(
"Stepper Type", this->description());
251 this->getValidParametersBasic(pl);
252 pl->set<
bool> (
"Use FSAL",
true);
253 pl->set<std::string>(
"Initial Condition Consistency",
"Consistent");
254 pl->set<
bool> (
"Zero Initial Guess",
false);
255 pl->set<std::string>(
"Solver Name",
"",
256 "Name of ParameterList containing the solver specifications.");
262 template<
class Scalar>
263 Teuchos::RCP<Teuchos::ParameterList>
267 using Teuchos::ParameterList;
268 using Teuchos::rcp_const_cast;
270 RCP<ParameterList> pl =
271 rcp_const_cast<ParameterList>(this->getValidParameters());
273 pl->set<std::string>(
"Solver Name",
"Default Solver");
274 RCP<ParameterList> solverPL = this->defaultSolverParameters();
275 pl->set(
"Default Solver", *solverPL);
281 template <
class Scalar>
282 Teuchos::RCP<Teuchos::ParameterList>
285 return(this->stepperPL_);
289 template <
class Scalar>
290 Teuchos::RCP<Teuchos::ParameterList>
293 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
294 this->stepperPL_ = Teuchos::null;
300 #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.
virtual std::string description() const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
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
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
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
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()