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: Time Integration and Sensitivity Analysis Package
4//
5// Copyright 2017 NTESS and the Tempus contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8//@HEADER
9
10#ifndef Tempus_StepperLeapfrog_impl_hpp
11#define Tempus_StepperLeapfrog_impl_hpp
12
13#include "Thyra_VectorStdOps.hpp"
14
16
17namespace Tempus {
18
19template <class Scalar>
21{
22 this->setStepperName("Leapfrog");
23 this->setStepperType("Leapfrog");
24 this->setUseFSAL(false);
25 this->setICConsistency("Consistent");
26 this->setICConsistencyCheck(false);
27
28 this->setAppAction(Teuchos::null);
29}
30
31template <class Scalar>
33 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
34 bool useFSAL, std::string ICConsistency, bool ICConsistencyCheck,
35 const Teuchos::RCP<StepperLeapfrogAppAction<Scalar> >& stepperLFAppAction)
36{
37 this->setStepperName("Leapfrog");
38 this->setStepperType("Leapfrog");
39 this->setUseFSAL(useFSAL);
40 this->setICConsistency(ICConsistency);
41 this->setICConsistencyCheck(ICConsistencyCheck);
42 this->setAppAction(stepperLFAppAction);
43 if (appModel != Teuchos::null) {
44 this->setModel(appModel);
45 this->initialize();
46 }
47}
48
49template <class Scalar>
51 Teuchos::RCP<StepperLeapfrogAppAction<Scalar> > appAction)
52{
53 if (appAction == Teuchos::null) {
54 // Create default appAction
55 stepperLFAppAction_ =
57 }
58 else {
59 stepperLFAppAction_ = appAction;
60 }
61}
62
63template <class Scalar>
65 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
66{
67 using Teuchos::RCP;
68
69 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
70
71 // Check if we need Stepper storage for xDotDot
72 if (initialState->getXDotDot() == Teuchos::null)
73 this->setStepperXDotDot(initialState->getX()->clone_v());
74 else
75 this->setStepperXDotDot(initialState->getXDotDot());
76
78
79 if (this->getUseFSAL()) {
80 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
81 Teuchos::OSTab ostab(out, 1, "StepperLeapfrog::setInitialConditions()");
82 *out << "Warning -- The First-Same-As-Last (FSAL) principle is not "
83 << "used with Leapfrog because of the algorithm's prescribed "
84 << "order of solution update. The default is to set useFSAL=false, "
85 << "however useFSAL=true will also work but have no affect "
86 << "(i.e., no-op).\n"
87 << std::endl;
88 }
89}
90
91template <class Scalar>
93 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
94{
95 this->checkInitialized();
96
97 using Teuchos::RCP;
98
99 TEMPUS_FUNC_TIME_MONITOR("Tempus::StepperLeapfrog::takeStep()");
100 {
101 TEUCHOS_TEST_FOR_EXCEPTION(
102 solutionHistory->getNumStates() < 2, std::logic_error,
103 "Error - StepperLeapfrog<Scalar>::takeStep(...)\n"
104 << "Need at least two SolutionStates for Leapfrog.\n"
105 << " Number of States = " << solutionHistory->getNumStates()
106 << "\nTry setting in \"Solution History\" \"Storage Type\" = "
107 << "\"Undo\"\n"
108 << " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
109 << "\"2\"\n");
110
111 RCP<SolutionState<Scalar> > currentState =
112 solutionHistory->getCurrentState();
113 RCP<SolutionState<Scalar> > workingState =
114 solutionHistory->getWorkingState();
115 const Scalar time = currentState->getTime();
116 const Scalar dt = workingState->getTimeStep();
117
118 RCP<StepperLeapfrog<Scalar> > thisStepper = Teuchos::rcpFromRef(*this);
119
120 stepperLFAppAction_->execute(
121 solutionHistory, thisStepper,
123
124 // Perform half-step startup if working state is synced
125 // (i.e., xDot and x are at the same time level).
126 if (workingState->getIsSynced() == true) {
127 // Half-step startup: xDot_{n+1/2} = xDot_n + 0.5*dt*xDotDot_n
128 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
129 *(currentState->getXDot()), 0.5 * dt,
130 *(currentState->getXDotDot()));
131 }
132 stepperLFAppAction_->execute(
133 solutionHistory, thisStepper,
135 // x_{n+1} = x_n + dt*xDot_{n+1/2}
136 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
137 *(currentState->getX()), dt, *(workingState->getXDot()));
138
139 stepperLFAppAction_->execute(
140 solutionHistory, thisStepper,
142 Scalar>::ACTION_LOCATION::BEFORE_EXPLICIT_EVAL);
143 auto p = Teuchos::rcp(new ExplicitODEParameters<Scalar>(dt));
144
145 // Evaluate xDotDot = f(x,t).
146 this->evaluateExplicitODE(workingState->getXDotDot(), workingState->getX(),
147 Teuchos::null, time + dt, p);
148 stepperLFAppAction_->execute(
149 solutionHistory, thisStepper,
151 if (workingState->getOutput() == true) {
152 // Half-step sync: xDot_{n+1} = xDot_{n+1/2} + 0.5*dt*xDotDot_{n+1}
153 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
154 *(workingState->getXDot()), 0.5 * dt,
155 *(workingState->getXDotDot()));
156 workingState->setIsSynced(true);
157 }
158 else {
159 // Full leapfrog step: xDot_{n+3/2} = xDot_{n+1/2} + dt*xDotDot_{n+1}
160 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
161 *(workingState->getXDot()), dt,
162 *(workingState->getXDotDot()));
163 workingState->setIsSynced(false);
164 }
165
166 workingState->setSolutionStatus(Status::PASSED);
167 workingState->setOrder(this->getOrder());
168 workingState->computeNorms(currentState);
169
170 stepperLFAppAction_->execute(
171 solutionHistory, thisStepper,
173 }
174 return;
175}
176
183template <class Scalar>
184Teuchos::RCP<Tempus::StepperState<Scalar> >
186{
187 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
188 rcp(new StepperState<Scalar>(this->getStepperType()));
189 return stepperState;
190}
191
192template <class Scalar>
194 Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const
195{
196 out.setOutputToRootOnly(0);
197 out << std::endl;
198 Stepper<Scalar>::describe(out, verbLevel);
199 StepperExplicit<Scalar>::describe(out, verbLevel);
200
201 out << "--- StepperLeapfrog ---\n";
202 out << " stepperLFAppAction_ = " << stepperLFAppAction_
203 << std::endl;
204 out << "-----------------------" << std::endl;
205}
206
207template <class Scalar>
208bool StepperLeapfrog<Scalar>::isValidSetup(Teuchos::FancyOStream& out) const
209{
210 out.setOutputToRootOnly(0);
211 bool isValidSetup = true;
212
213 if (!Stepper<Scalar>::isValidSetup(out)) isValidSetup = false;
214 if (!StepperExplicit<Scalar>::isValidSetup(out)) isValidSetup = false;
215 if (stepperLFAppAction_ == Teuchos::null) {
216 isValidSetup = false;
217 out << "The Leapfrog AppAction is not set!\n";
218 }
219
220 return isValidSetup;
221}
222
223// Nonmember constructor - ModelEvaluator and ParameterList
224// ------------------------------------------------------------------------
225template <class Scalar>
226Teuchos::RCP<StepperLeapfrog<Scalar> > createStepperLeapfrog(
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} // namespace Tempus
242#endif // Tempus_StepperLeapfrog_impl_hpp
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Thyra Base interface for implicit time steppers.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Application Action for StepperLeapfrog.
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)
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.
Thyra Base interface for time steppers.
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.