Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Tempus_StepperLeapfrog_impl.hpp
Go to the documentation of this file.
1// @HEADER
2// ****************************************************************************
3// Tempus: Copyright (2017) Sandia Corporation
4//
5// Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6// ****************************************************************************
7// @HEADER
8
9#ifndef Tempus_StepperLeapfrog_impl_hpp
10#define Tempus_StepperLeapfrog_impl_hpp
11
12#include "Thyra_VectorStdOps.hpp"
13
15
16
17namespace Tempus {
18
19
20template<class Scalar>
22{
23 this->setStepperName( "Leapfrog");
24 this->setStepperType( "Leapfrog");
25 this->setUseFSAL( false);
26 this->setICConsistency( "Consistent");
27 this->setICConsistencyCheck( false);
28
29 this->setAppAction(Teuchos::null);
30}
31
32template<class Scalar>
34 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
35 bool useFSAL,
36 std::string ICConsistency,
37 bool ICConsistencyCheck,
38 const Teuchos::RCP<StepperLeapfrogAppAction<Scalar> >& stepperLFAppAction)
39 {
40 this->setStepperName( "Leapfrog");
41 this->setStepperType( "Leapfrog");
42 this->setUseFSAL( useFSAL);
43 this->setICConsistency( ICConsistency);
44 this->setICConsistencyCheck( ICConsistencyCheck);
45 this->setAppAction(stepperLFAppAction);
46 if (appModel != Teuchos::null) {
47
48 this->setModel(appModel);
49 this->initialize();
50 }
51 }
52
53
54template<class Scalar>
56 Teuchos::RCP<StepperLeapfrogAppAction<Scalar> > appAction)
57 {
58 if (appAction == Teuchos::null) {
59 // Create default appAction
62 }
63 else {
64 stepperLFAppAction_ = appAction;
65 }
66}
67
68
69template<class Scalar>
71 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
72{
73 using Teuchos::RCP;
74
75 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
76
77 // Check if we need Stepper storage for xDotDot
78 if (initialState->getXDotDot() == Teuchos::null)
79 this->setStepperXDotDot(initialState->getX()->clone_v());
80 else
81 this->setStepperXDotDot(initialState->getXDotDot());
82
84
85 if (this->getUseFSAL()) {
86 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
87 Teuchos::OSTab ostab(out,1,"StepperLeapfrog::setInitialConditions()");
88 *out << "Warning -- The First-Same-As-Last (FSAL) principle is not "
89 << "used with Leapfrog because of the algorithm's prescribed "
90 << "order of solution update. The default is to set useFSAL=false, "
91 << "however useFSAL=true will also work but have no affect "
92 << "(i.e., no-op).\n" << std::endl;
93 }
94}
95
96template<class Scalar>
98 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
99{
100 this->checkInitialized();
101
102 using Teuchos::RCP;
103
104 TEMPUS_FUNC_TIME_MONITOR("Tempus::StepperLeapfrog::takeStep()");
105 {
106 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
107 std::logic_error,
108 "Error - StepperLeapfrog<Scalar>::takeStep(...)\n"
109 "Need at least two SolutionStates for Leapfrog.\n"
110 " Number of States = " << solutionHistory->getNumStates() << "\n"
111 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
112 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
113
114 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
115 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
116 const Scalar time = currentState->getTime();
117 const Scalar dt = workingState->getTimeStep();
118
119
120 RCP<StepperLeapfrog<Scalar> > thisStepper = Teuchos::rcpFromRef(*this);
121
122 stepperLFAppAction_->execute(solutionHistory, thisStepper,
124
125 // Perform half-step startup if working state is synced
126 // (i.e., xDot and x are at the same time level).
127 if (workingState->getIsSynced() == true) {
128 // Half-step startup: xDot_{n+1/2} = xDot_n + 0.5*dt*xDotDot_n
129 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
130 *(currentState->getXDot()),0.5*dt,*(currentState->getXDotDot()));
131 }
132 stepperLFAppAction_->execute(solutionHistory, thisStepper,
134 // x_{n+1} = x_n + dt*xDot_{n+1/2}
135 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
136 *(currentState->getX()),dt,*(workingState->getXDot()));
137
138 stepperLFAppAction_->execute(solutionHistory, thisStepper,
140 auto p = Teuchos::rcp(new ExplicitODEParameters<Scalar>(dt));
141
142 // Evaluate xDotDot = f(x,t).
143 this->evaluateExplicitODE(workingState->getXDotDot(),
144 workingState->getX(),
145 Teuchos::null, time+dt, p);
146 stepperLFAppAction_->execute(solutionHistory, thisStepper,
148 if (workingState->getOutput() == true) {
149 // Half-step sync: xDot_{n+1} = xDot_{n+1/2} + 0.5*dt*xDotDot_{n+1}
150 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
151 *(workingState->getXDot()),0.5*dt,*(workingState->getXDotDot()));
152 workingState->setIsSynced(true);
153 } else {
154 // Full leapfrog step: xDot_{n+3/2} = xDot_{n+1/2} + dt*xDotDot_{n+1}
155 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
156 *(workingState->getXDot()),dt,*(workingState->getXDotDot()));
157 workingState->setIsSynced(false);
158 }
159
160 workingState->setSolutionStatus(Status::PASSED);
161 workingState->setOrder(this->getOrder());
162 workingState->computeNorms(currentState);
163
164 stepperLFAppAction_->execute(solutionHistory, thisStepper,
166 }
167 return;
168}
169
170
177template<class Scalar>
178Teuchos::RCP<Tempus::StepperState<Scalar> > StepperLeapfrog<Scalar>::
180{
181 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
182 rcp(new StepperState<Scalar>(this->getStepperType()));
183 return stepperState;
184}
185
186
187template<class Scalar>
189 Teuchos::FancyOStream &out,
190 const Teuchos::EVerbosityLevel verbLevel) const
191{
192 out.setOutputToRootOnly(0);
193 out << std::endl;
194 Stepper<Scalar>::describe(out, verbLevel);
195 StepperExplicit<Scalar>::describe(out, verbLevel);
196
197 out << "--- StepperLeapfrog ---\n";
198 out << " stepperLFAppAction_ = "
199 << stepperLFAppAction_ << std::endl;
200 out << "-----------------------" << std::endl;
201}
202
203
204template<class Scalar>
205bool StepperLeapfrog<Scalar>::isValidSetup(Teuchos::FancyOStream & out) const
206{
207 out.setOutputToRootOnly(0);
208 bool isValidSetup = true;
209
210 if ( !Stepper<Scalar>::isValidSetup(out) ) isValidSetup = false;
212 if (stepperLFAppAction_ == Teuchos::null) {
213 isValidSetup = false;
214 out << "The Leapfrog AppAction is not set!\n";
215 }
216
217
218 return isValidSetup;
219}
220
221
222// Nonmember constructor - ModelEvaluator and ParameterList
223// ------------------------------------------------------------------------
224template<class Scalar>
225Teuchos::RCP<StepperLeapfrog<Scalar> >
227 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
228 Teuchos::RCP<Teuchos::ParameterList> pl)
229{
230 auto stepper = Teuchos::rcp(new StepperLeapfrog<Scalar>());
231 stepper->setStepperExplicitValues(pl);
232
233 if (model != Teuchos::null) {
234 stepper->setModel(model);
235 stepper->initialize();
236 }
237
238 return stepper;
239}
240
241
242} // namespace Tempus
243#endif // Tempus_StepperLeapfrog_impl_hpp
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void evaluateExplicitODE(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDot, Teuchos::RCP< const Thyra::VectorBase< Scalar > > x, const Scalar time, const Teuchos::RCP< ExplicitODEParameters< Scalar > > &p)
Evaluate xDot = f(x,t).
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Set model.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Application Action for StepperLeapfrog.
@ BEFORE_EXPLICIT_EVAL
Before the explicit ME evaluation.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
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.
virtual void setAppAction(Teuchos::RCP< StepperLeapfrogAppAction< Scalar > > appAction)
Teuchos::RCP< StepperLeapfrogAppAction< Scalar > > stepperLFAppAction_
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
StepperState is a simple class to hold state information about the stepper.
void setICConsistencyCheck(bool c)
virtual void setStepperXDotDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDotDot)
Set x for Stepper storage.
void setStepperName(std::string s)
Set the stepper name.
virtual void initialize()
Initialize after construction and changing input parameters.
std::string getStepperType() const
Get the stepper type. The stepper type is used as an identifier for the stepper, and can only be set ...
virtual void setUseFSAL(bool a)
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void checkInitialized()
Check initialization, and error out on failure.
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< StepperLeapfrog< Scalar > > createStepperLeapfrog(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.