14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_WrapperModelEvaluatorPairIMEX_Basic.hpp"
18 #include "Tempus_StepperIMEX_RK.hpp"
20 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
21 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
22 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
27 namespace Tempus_Test {
29 using Teuchos::getParametersFromXmlFile;
33 using Teuchos::rcp_const_cast;
34 using Teuchos::sublist;
48 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
60 explicitModel, implicitModel));
64 stepper->setModel(model);
65 stepper->initialize();
71 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
72 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
73 timeStepControl->setFinalTime(tscPL.
get<
double>(
"Final Time"));
74 timeStepControl->setInitTimeStep(dt);
75 timeStepControl->initialize();
78 auto inArgsIC = model->getNominalValues();
81 icState->setTime(timeStepControl->getInitTime());
82 icState->setIndex(timeStepControl->getInitIndex());
83 icState->setTimeStep(0.0);
84 icState->setOrder(stepper->getOrder());
89 solutionHistory->setName(
"Forward States");
91 solutionHistory->setStorageLimit(2);
92 solutionHistory->addState(icState);
96 Tempus::createIntegratorBasic<double>();
97 integrator->setStepper(stepper);
98 integrator->setTimeStepControl(timeStepControl);
99 integrator->setSolutionHistory(solutionHistory);
100 integrator->initialize();
103 bool integratorStatus = integrator->advanceTime();
107 double time = integrator->getTime();
108 double timeFinal = pl->
sublist(
"Default Integrator")
110 .
get<
double>(
"Final Time");
117 out <<
" Stepper = " << stepper->description() << std::endl;
118 out <<
" =========================" << std::endl;
119 out <<
" Computed solution: " << get_ele(*(x), 0) <<
" "
120 << get_ele(*(x), 1) << std::endl;
121 out <<
" =========================" << std::endl;
122 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4);
123 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4);
130 std::vector<std::string> stepperTypes;
131 stepperTypes.push_back(
"IMEX RK 1st order");
132 stepperTypes.push_back(
"SSP1_111");
133 stepperTypes.push_back(
"IMEX RK SSP2");
134 stepperTypes.push_back(
"SSP2_222");
135 stepperTypes.push_back(
"IMEX RK ARS 233");
136 stepperTypes.push_back(
"General IMEX RK");
137 stepperTypes.push_back(
"IMEX RK SSP3");
139 std::vector<double> stepperOrders;
140 stepperOrders.push_back(1.07964);
141 stepperOrders.push_back(1.07964);
142 stepperOrders.push_back(2.00408);
143 stepperOrders.push_back(2.76941);
144 stepperOrders.push_back(2.70655);
145 stepperOrders.push_back(2.00211);
146 stepperOrders.push_back(2.00211);
148 std::vector<double> stepperErrors;
149 stepperErrors.push_back(0.0046423);
150 stepperErrors.push_back(0.103569);
151 stepperErrors.push_back(0.0154534);
152 stepperErrors.push_back(0.000533759);
153 stepperErrors.push_back(0.000298908);
154 stepperErrors.push_back(0.0071546);
155 stepperErrors.push_back(0.0151202);
157 std::vector<double> stepperInitDt;
158 stepperInitDt.push_back(0.0125);
159 stepperInitDt.push_back(0.0125);
160 stepperInitDt.push_back(0.05);
161 stepperInitDt.push_back(0.05);
162 stepperInitDt.push_back(0.05);
163 stepperInitDt.push_back(0.05);
164 stepperInitDt.push_back(0.05);
170 std::vector<std::string>::size_type m;
171 for (m = 0; m != stepperTypes.size(); m++) {
172 std::string stepperType = stepperTypes[m];
173 std::string stepperName = stepperTypes[m];
174 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
175 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
178 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
179 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
180 std::vector<double> StepSize;
181 std::vector<double> xErrorNorm;
182 std::vector<double> xDotErrorNorm;
184 const int nTimeStepSizes = 3;
185 double dt = stepperInitDt[m];
187 for (
int n = 0; n < nTimeStepSizes; n++) {
190 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
203 explicitModel, implicitModel));
207 if (stepperType ==
"General IMEX RK") {
209 pl->
sublist(
"Default Integrator")
210 .
set(
"Stepper Name",
"General IMEX RK");
213 pl->
sublist(
"Default Stepper").
set(
"Stepper Type", stepperType);
217 if (n == nTimeStepSizes - 1)
223 pl->
sublist(
"Default Integrator")
225 .
set(
"Initial Time Step", dt);
226 integrator = Tempus::createIntegratorBasic<double>(pl, model);
229 bool integratorStatus = integrator->advanceTime();
233 time = integrator->getTime();
234 double timeFinal = pl->sublist(
"Default Integrator")
235 .sublist(
"Time Step Control")
236 .get<
double>(
"Final Time");
237 double tol = 100.0 * std::numeric_limits<double>::epsilon();
241 StepSize.push_back(dt);
242 auto solution = Thyra::createMember(model->get_x_space());
243 Thyra::copy(*(integrator->getX()), solution.ptr());
244 solutions.push_back(solution);
245 auto solutionDot = Thyra::createMember(model->get_x_space());
246 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
247 solutionsDot.push_back(solutionDot);
251 if ((n == 0) || (n == nTimeStepSizes - 1)) {
252 std::string fname =
"Tempus_" + stepperName +
"_VanDerPol-Ref.dat";
253 if (n == 0) fname =
"Tempus_" + stepperName +
"_VanDerPol.dat";
255 integrator->getSolutionHistory();
262 double xDotSlope = 0.0;
267 solutionsDot.clear();
269 writeOrderError(
"Tempus_" + stepperName +
"_VanDerPol-Error.dat", stepper,
270 StepSize, solutions, xErrorNorm, xSlope, solutionsDot,
271 xDotErrorNorm, xDotSlope, out);
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x.
van der Pol model formulated for IMEX-RK.
T & get(const std::string &name, T def_value)
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
void writeOrderError(const std::string filename, Teuchos::RCP< Tempus::Stepper< Scalar >> stepper, std::vector< Scalar > &StepSize, std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar >>> &solutions, std::vector< Scalar > &xErrorNorm, Scalar &xSlope, std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar >>> &solutionsDot, std::vector< Scalar > &xDotErrorNorm, Scalar &xDotSlope, std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar >>> &solutionsDotDot, std::vector< Scalar > &xDotDotErrorNorm, Scalar &xDotDotSlope, Teuchos::FancyOStream &out)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar >> solutionHistory)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
van der Pol model formulated for IMEX.
#define TEUCHOS_ASSERT(assertion_test)
Solution state for integrators and steppers.