9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
13 #include "Thyra_VectorStdOps.hpp"
15 #include "Tempus_IntegratorBasic.hpp"
16 #include "Tempus_WrapperModelEvaluatorPairIMEX_Basic.hpp"
17 #include "Tempus_StepperIMEX_RK.hpp"
19 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
20 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
26 namespace Tempus_Test {
30 using Teuchos::rcp_const_cast;
31 using Teuchos::ParameterList;
32 using Teuchos::sublist;
33 using Teuchos::getParametersFromXmlFile;
40 #define TEST_CONSTRUCTING_FROM_DEFAULTS
41 #define TEST_VANDERPOL
44 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS
52 RCP<ParameterList> pList =
53 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
54 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
57 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
65 explicitModel, implicitModel));
70 stepper->setModel(model);
72 stepper->initialize();
76 ParameterList tscPL = pl->sublist(
"Default Integrator")
77 .sublist(
"Time Step Control");
78 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
79 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
80 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
81 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
82 timeStepControl->setInitTimeStep(dt);
83 timeStepControl->initialize();
86 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
87 stepper->getModel()->getNominalValues();
88 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
90 icState->setTime (timeStepControl->getInitTime());
91 icState->setIndex (timeStepControl->getInitIndex());
92 icState->setTimeStep(0.0);
93 icState->setOrder (stepper->getOrder());
104 RCP<Tempus::IntegratorBasic<double> > integrator =
105 Tempus::integratorBasic<double>();
106 integrator->setStepperWStepper(stepper);
107 integrator->setTimeStepControl(timeStepControl);
110 integrator->initialize();
114 bool integratorStatus = integrator->advanceTime();
115 TEST_ASSERT(integratorStatus)
119 double time = integrator->getTime();
120 double timeFinal =pl->sublist(
"Default Integrator")
121 .sublist(
"Time Step Control").get<
double>(
"Final Time");
122 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
125 RCP<Thyra::VectorBase<double> > x = integrator->getX();
128 std::cout <<
" Stepper = " << stepper->description() << std::endl;
129 std::cout <<
" =========================" << std::endl;
130 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
131 << get_ele(*(x ), 1) << std::endl;
132 std::cout <<
" =========================" << std::endl;
133 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
134 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
136 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
139 #ifdef TEST_VANDERPOL
144 std::vector<std::string> stepperTypes;
145 stepperTypes.push_back(
"IMEX RK 1st order");
146 stepperTypes.push_back(
"IMEX RK SSP2" );
147 stepperTypes.push_back(
"IMEX RK ARS 233" );
148 stepperTypes.push_back(
"General IMEX RK" );
150 std::vector<double> stepperOrders;
151 stepperOrders.push_back(1.07964);
152 stepperOrders.push_back(2.00408);
153 stepperOrders.push_back(2.70655);
154 stepperOrders.push_back(2.00211);
156 std::vector<double> stepperErrors;
157 stepperErrors.push_back(0.0046423);
158 stepperErrors.push_back(0.0154534);
159 stepperErrors.push_back(0.000298908);
160 stepperErrors.push_back(0.0071546);
162 std::vector<double> stepperInitDt;
163 stepperInitDt.push_back(0.0125);
164 stepperInitDt.push_back(0.05);
165 stepperInitDt.push_back(0.05);
166 stepperInitDt.push_back(0.05);
168 std::vector<std::string>::size_type m;
169 for(m = 0; m != stepperTypes.size(); m++) {
171 std::string stepperType = stepperTypes[m];
172 std::string stepperName = stepperTypes[m];
173 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
174 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
176 RCP<Tempus::IntegratorBasic<double> > integrator;
177 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
178 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
179 std::vector<double> StepSize;
180 std::vector<double> xErrorNorm;
181 std::vector<double> xDotErrorNorm;
183 const int nTimeStepSizes = 3;
184 double dt = stepperInitDt[m];
186 for (
int n=0; n<nTimeStepSizes; n++) {
189 RCP<ParameterList> pList =
190 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
193 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
201 explicitModel, implicitModel));
204 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
205 if (stepperType ==
"General IMEX RK"){
207 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
209 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
213 if (n == nTimeStepSizes-1) dt /= 10.0;
217 pl->sublist(
"Default Integrator")
218 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
219 integrator = Tempus::integratorBasic<double>(pl, model);
222 bool integratorStatus = integrator->advanceTime();
223 TEST_ASSERT(integratorStatus)
226 time = integrator->getTime();
227 double timeFinal =pl->sublist(
"Default Integrator")
228 .sublist(
"Time Step Control").get<
double>(
"Final Time");
229 double tol = 100.0 * std::numeric_limits<double>::epsilon();
230 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
233 StepSize.push_back(dt);
234 auto solution = Thyra::createMember(model->get_x_space());
235 Thyra::copy(*(integrator->getX()),solution.ptr());
236 solutions.push_back(solution);
237 auto solutionDot = Thyra::createMember(model->get_x_space());
238 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
239 solutionsDot.push_back(solutionDot);
243 if ((n == 0) or (n == nTimeStepSizes-1)) {
244 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
245 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
247 integrator->getSolutionHistory();
254 double xDotSlope = 0.0;
255 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
259 solutions, xErrorNorm, xSlope,
260 solutionsDot, xDotErrorNorm, xDotSlope);
262 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
263 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
271 #endif // TEST_VANDERPOL
van der Pol model formulated for IMEX-RK.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > solutionHistory)
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_UNIT_TEST(BackwardEuler, SinCos_ASA)
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
van der Pol model formulated for IMEX.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...