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_WrapperModelEvaluatorPairPartIMEX_Basic.hpp"
17 #include "Tempus_StepperIMEX_RK_Partition.hpp"
20 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
21 #include "../TestModels/VanDerPol_IMEXPart_ImplicitModel.hpp"
22 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
30 using Teuchos::ParameterList;
31 using Teuchos::sublist;
32 using Teuchos::getParametersFromXmlFile;
39 #define TEST_CONSTRUCTING_FROM_DEFAULTS
40 #define TEST_VANDERPOL
43 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS
51 RCP<ParameterList> pList =
52 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
53 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
56 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
57 const bool useProductVector =
true;
58 RCP<VanDerPol_IMEX_ExplicitModel<double> > explicitModel =
63 RCP<VanDerPol_IMEXPart_ImplicitModel<double> > implicitModel =
67 const int numExplicitBlocks = 1;
68 const int parameterIndex = 4;
69 RCP<Tempus::WrapperModelEvaluatorPairPartIMEX_Basic<double> > model =
72 explicitModel, implicitModel,
73 numExplicitBlocks, parameterIndex));
77 RCP<Tempus::StepperIMEX_RK_Partition<double> > stepper =
81 RCP<Tempus::TimeStepControl<double> > timeStepControl =
83 ParameterList tscPL = pl->sublist(
"Default Integrator")
84 .sublist(
"Time Step Control");
85 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
86 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
87 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
88 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
89 timeStepControl->setInitTimeStep(dt);
90 timeStepControl->initialize();
93 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
94 stepper->getModel()->getNominalValues();
95 RCP<Thyra::VectorBase<double> > icSolution =
96 Teuchos::rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
97 RCP<Tempus::SolutionState<double> > icState =
99 icState->setTime (timeStepControl->getInitTime());
100 icState->setIndex (timeStepControl->getInitIndex());
101 icState->setTimeStep(0.0);
102 icState->setOrder (stepper->getOrder());
114 RCP<Tempus::IntegratorBasic<double> > integrator =
115 Tempus::integratorBasic<double>();
116 integrator->setStepperWStepper(stepper);
117 integrator->setTimeStepControl(timeStepControl);
120 integrator->initialize();
124 bool integratorStatus = integrator->advanceTime();
125 TEST_ASSERT(integratorStatus)
129 double time = integrator->getTime();
130 double timeFinal =pl->sublist(
"Default Integrator")
131 .sublist(
"Time Step Control").get<
double>(
"Final Time");
132 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
135 RCP<Thyra::VectorBase<double> > x = integrator->getX();
138 std::cout <<
" Stepper = " << stepper->description() << std::endl;
139 std::cout <<
" =========================" << std::endl;
140 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
141 << get_ele(*(x ), 1) << std::endl;
142 std::cout <<
" =========================" << std::endl;
143 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
144 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
146 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
149 #ifdef TEST_VANDERPOL
154 std::vector<std::string> stepperTypes;
155 stepperTypes.push_back(
"Partitioned IMEX RK 1st order");
156 stepperTypes.push_back(
"Partitioned IMEX RK SSP2" );
157 stepperTypes.push_back(
"Partitioned IMEX RK ARS 233" );
158 stepperTypes.push_back(
"General Partitioned IMEX RK" );
160 std::vector<double> stepperOrders;
161 stepperOrders.push_back(1.07964);
162 stepperOrders.push_back(2.00408);
163 stepperOrders.push_back(2.70655);
164 stepperOrders.push_back(2.00211);
166 std::vector<double> stepperErrors;
167 stepperErrors.push_back(0.0046423);
168 stepperErrors.push_back(0.0154534);
169 stepperErrors.push_back(0.000298908);
170 stepperErrors.push_back(0.0071546);
172 std::vector<double> stepperInitDt;
173 stepperInitDt.push_back(0.0125);
174 stepperInitDt.push_back(0.05);
175 stepperInitDt.push_back(0.05);
176 stepperInitDt.push_back(0.05);
178 std::vector<std::string>::size_type m;
179 for(m = 0; m != stepperTypes.size(); m++) {
181 std::string stepperType = stepperTypes[m];
182 std::string stepperName = stepperTypes[m];
183 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
184 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
186 RCP<Tempus::IntegratorBasic<double> > integrator;
187 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
188 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
189 std::vector<double> StepSize;
190 std::vector<double> xErrorNorm;
191 std::vector<double> xDotErrorNorm;
193 const int nTimeStepSizes = 3;
194 double dt = stepperInitDt[m];
196 for (
int n=0; n<nTimeStepSizes; n++) {
199 RCP<ParameterList> pList =
200 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
203 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
204 const bool useProductVector =
true;
205 RCP<VanDerPol_IMEX_ExplicitModel<double> > explicitModel =
210 RCP<VanDerPol_IMEXPart_ImplicitModel<double> > implicitModel =
214 const int numExplicitBlocks = 1;
215 const int parameterIndex = 4;
216 RCP<Tempus::WrapperModelEvaluatorPairPartIMEX_Basic<double> > model =
219 explicitModel, implicitModel,
220 numExplicitBlocks, parameterIndex));
223 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
225 if (stepperType ==
"General Partitioned IMEX RK"){
227 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
229 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
233 if (n == nTimeStepSizes-1) dt /= 10.0;
237 pl->sublist(
"Default Integrator")
238 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
239 integrator = Tempus::integratorBasic<double>(pl, model);
242 bool integratorStatus = integrator->advanceTime();
243 TEST_ASSERT(integratorStatus)
246 time = integrator->getTime();
247 double timeFinal =pl->sublist(
"Default Integrator")
248 .sublist(
"Time Step Control").get<
double>(
"Final Time");
249 double tol = 100.0 * std::numeric_limits<double>::epsilon();
250 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
253 StepSize.push_back(dt);
254 auto solution = Thyra::createMember(model->get_x_space());
255 Thyra::copy(*(integrator->getX()),solution.ptr());
256 solutions.push_back(solution);
257 auto solutionDot = Thyra::createMember(model->get_x_space());
258 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
259 solutionsDot.push_back(solutionDot);
263 if ((n == 0) or (n == nTimeStepSizes-1)) {
264 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
265 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
267 integrator->getSolutionHistory();
274 double xDotSlope = 0.0;
275 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
279 solutions, xErrorNorm, xSlope,
280 solutionsDot, xDotErrorNorm, xDotSlope);
282 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
283 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
289 Teuchos::TimeMonitor::summarize();
291 #endif // TEST_VANDERPOL