54 RCP<ParameterList> pList =
55 getParametersFromXmlFile(
"Tempus_Subcycling_SinCos.xml");
62 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
65 RCP<ParameterList> tempusPL = sublist(pList,
"Tempus",
true);
69 RCP<Tempus::IntegratorBasic<double>> integrator =
70 Tempus::createIntegratorBasic<double>(tempusPL, model);
72 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Demo Stepper",
true);
73 RCP<const ParameterList> defaultPL =
74 integrator->getStepper()->getValidParameters();
76 bool pass = haveSameValuesSorted(*stepperPL, *defaultPL,
true);
79 out <<
"stepperPL -------------- \n"
80 << *stepperPL << std::endl;
81 out <<
"defaultPL -------------- \n"
82 << *defaultPL << std::endl;
89 RCP<Tempus::IntegratorBasic<double>> integrator =
90 Tempus::createIntegratorBasic<double>(model,
91 std::string(
"Forward Euler"));
93 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Demo Stepper",
true);
94 RCP<const ParameterList> defaultPL =
95 integrator->getStepper()->getValidParameters();
97 bool pass = haveSameValuesSorted(*stepperPL, *defaultPL,
true);
100 out <<
"stepperPL -------------- \n"
101 << *stepperPL << std::endl;
102 out <<
"defaultPL -------------- \n"
103 << *defaultPL << std::endl;
117 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double>>(model);
122 stepper->setSubcyclingStepper(stepperFE);
124 stepper->setSubcyclingMinTimeStep(0.1);
125 stepper->setSubcyclingInitTimeStep(0.1);
126 stepper->setSubcyclingMaxTimeStep(0.1);
127 stepper->setSubcyclingMaxFailures(10);
128 stepper->setSubcyclingMaxConsecFailures(5);
129 stepper->setSubcyclingScreenOutputIndexInterval(1);
130 stepper->setSubcyclingIntegratorObserver(
132 stepper->setSubcyclingPrintDtChanges(
true);
137 stepper->setSubcyclingTimeStepControlStrategy(subStrategy);
141 timeStepControl->setInitIndex(0);
142 timeStepControl->setFinalIndex(10);
143 timeStepControl->setInitTime(0.0);
144 timeStepControl->setFinalTime(1.0);
145 timeStepControl->setInitTimeStep(dt);
149 strategy->initialize();
150 timeStepControl->setTimeStepControlStrategy(strategy);
152 timeStepControl->initialize();
155 auto inArgsIC = stepper->getModel()->getNominalValues();
156 auto icSolution = rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x());
158 icState->setTime(timeStepControl->getInitTime());
159 icState->setIndex(timeStepControl->getInitIndex());
160 icState->setTimeStep(0.0);
165 solutionHistory->setName(
"Forward States");
167 solutionHistory->setStorageLimit(2);
168 solutionHistory->addState(icState);
171 stepper->setInitialConditions(solutionHistory);
172 stepper->initialize();
175 RCP<Tempus::IntegratorBasic<double>> integrator =
176 Tempus::createIntegratorBasic<double>();
177 integrator->setStepper(stepper);
178 integrator->setTimeStepControl(timeStepControl);
179 integrator->setSolutionHistory(solutionHistory);
180 integrator->setScreenOutputIndexInterval(1);
182 integrator->initialize();
185 bool integratorStatus = integrator->advanceTime();
186 TEST_ASSERT(integratorStatus)
189 double time = integrator->getTime();
190 double timeFinal = 1.0;
191 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
194 RCP<Thyra::VectorBase<double>> x = integrator->getX();
195 RCP<const Thyra::VectorBase<double>> x_exact =
196 model->getExactSolution(time).get_x();
199 RCP<Thyra::VectorBase<double>> xdiff = x->clone_v();
200 Thyra::V_StVpStV(xdiff.ptr(), 1.0, *x_exact, -1.0, *(x));
203 out <<
" Stepper = " << stepper->description() << std::endl;
204 out <<
" =========================" << std::endl;
205 out <<
" Exact solution : " << get_ele(*(x_exact), 0) <<
" "
206 << get_ele(*(x_exact), 1) << std::endl;
207 out <<
" Computed solution: " << get_ele(*(x), 0) <<
" "
208 << get_ele(*(x), 1) << std::endl;
209 out <<
" Difference : " << get_ele(*(xdiff), 0) <<
" "
210 << get_ele(*(xdiff), 1) << std::endl;
211 out <<
" =========================" << std::endl;
212 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 0.882508, 1.0e-4);
213 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.570790, 1.0e-4);
220 RCP<Tempus::IntegratorBasic<double>> integrator;
221 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
222 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
223 std::vector<double> StepSize;
228 const int nTimeStepSizes = 2;
229 std::string output_file_string =
"Tempus_Subcycling_SinCos";
230 std::string output_file_name = output_file_string +
".dat";
231 std::string err_out_file_name = output_file_string +
"-Error.dat";
233 for (
int n = 0; n < nTimeStepSizes; n++) {
238 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double>>(model);
243 stepper->setSubcyclingStepper(stepperFE);
245 stepper->setSubcyclingMinTimeStep(dt / 10.0);
246 stepper->setSubcyclingInitTimeStep(dt / 10.0);
247 stepper->setSubcyclingMaxTimeStep(dt);
248 stepper->setSubcyclingMaxFailures(10);
249 stepper->setSubcyclingMaxConsecFailures(5);
250 stepper->setSubcyclingScreenOutputIndexInterval(1);
257 strategy->setMinEta(0.02);
258 strategy->setMaxEta(0.04);
259 strategy->initialize();
260 stepper->setSubcyclingTimeStepControlStrategy(strategy);
264 timeStepControl->setInitIndex(0);
265 timeStepControl->setInitTime(0.0);
266 timeStepControl->setFinalTime(1.0);
267 timeStepControl->setMinTimeStep(dt);
268 timeStepControl->setInitTimeStep(dt);
269 timeStepControl->setMaxTimeStep(dt);
270 timeStepControl->initialize();
273 auto inArgsIC = stepper->getModel()->getNominalValues();
275 rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x());
277 icState->setTime(timeStepControl->getInitTime());
278 icState->setIndex(timeStepControl->getInitIndex());
279 icState->setTimeStep(0.0);
284 solutionHistory->setName(
"Forward States");
286 solutionHistory->setStorageLimit(2);
287 solutionHistory->addState(icState);
290 stepper->setInitialConditions(solutionHistory);
291 stepper->initialize();
294 integrator = Tempus::createIntegratorBasic<double>();
295 integrator->setStepper(stepper);
296 integrator->setTimeStepControl(timeStepControl);
297 integrator->setSolutionHistory(solutionHistory);
298 integrator->setScreenOutputIndexInterval(10);
300 integrator->initialize();
303 bool integratorStatus = integrator->advanceTime();
304 TEST_ASSERT(integratorStatus)
307 time = integrator->getTime();
308 double timeFinal = 1.0;
309 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
312 RCP<Thyra::VectorBase<double>> x = integrator->getX();
313 RCP<const Thyra::VectorBase<double>> x_exact =
314 model->getExactSolution(time).get_x();
345 StepSize.push_back(dt);
346 auto solution = Thyra::createMember(model->get_x_space());
347 Thyra::copy(*(integrator->getX()), solution.ptr());
348 solutions.push_back(solution);
349 if (n == nTimeStepSizes - 1) {
350 StepSize.push_back(0.0);
351 auto solutionExact = Thyra::createMember(model->get_x_space());
352 Thyra::copy(*(model->getExactSolution(time).get_x()),
353 solutionExact.ptr());
354 solutions.push_back(solutionExact);
359 if (nTimeStepSizes > 1) {
361 double xDotSlope = 0.0;
362 std::vector<double> xErrorNorm;
363 std::vector<double> xDotErrorNorm;
364 RCP<Tempus::Stepper<double>> stepper = integrator->getStepper();
367 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
370 TEST_FLOATING_EQUALITY(xSlope, 1.00137, 0.01);
372 TEST_FLOATING_EQUALITY(xErrorNorm[0], 0.00387948, 1.0e-4);
376 Teuchos::TimeMonitor::summarize();
383 RCP<Tempus::IntegratorBasic<double>> integrator;
384 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
385 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
386 std::vector<double> StepSize;
387 std::vector<double> xErrorNorm;
388 std::vector<double> xDotErrorNorm;
389 const int nTimeStepSizes = 4;
392 for (
int n = 0; n < nTimeStepSizes; n++) {
395 if (n == nTimeStepSizes - 1) dt /= 10.0;
399 auto pl = Teuchos::rcp_const_cast<Teuchos::ParameterList>(
400 tmpModel->getValidParameters());
401 pl->set(
"Coeff epsilon", 0.1);
402 RCP<const Thyra::ModelEvaluator<double>> explicitModel =
404 RCP<const Thyra::ModelEvaluator<double>> implicitModel =
413 stepperFE->setUseFSAL(
false);
414 stepperFE->initialize();
415 stepperSC->setSubcyclingStepper(stepperFE);
417 stepperSC->setSubcyclingMinTimeStep(0.00001);
418 stepperSC->setSubcyclingInitTimeStep(dt / 10.0);
419 stepperSC->setSubcyclingMaxTimeStep(dt / 10.0);
420 stepperSC->setSubcyclingMaxFailures(10);
421 stepperSC->setSubcyclingMaxConsecFailures(5);
422 stepperSC->setSubcyclingScreenOutputIndexInterval(1);
428 strategySC->setMinEta(0.000001);
429 strategySC->setMaxEta(0.01);
430 strategySC->initialize();
431 stepperSC->setSubcyclingTimeStepControlStrategy(strategySC);
439 stepper->addStepper(stepperSC);
440 stepper->addStepper(stepperBE);
444 timeStepControl->setInitIndex(0);
445 timeStepControl->setInitTime(0.0);
447 timeStepControl->setFinalTime(2.0);
448 timeStepControl->setMinTimeStep(0.000001);
449 timeStepControl->setInitTimeStep(dt);
450 timeStepControl->setMaxTimeStep(dt);
462 timeStepControl->initialize();
465 auto inArgsIC = stepper->getModel()->getNominalValues();
466 auto icX = rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x());
468 rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x_dot());
470 icState->setTime(timeStepControl->getInitTime());
471 icState->setIndex(timeStepControl->getInitIndex());
472 icState->setTimeStep(0.0);
473 icState->setOrder(stepper->getOrder());
478 solutionHistory->setName(
"Forward States");
481 solutionHistory->setStorageLimit(3);
482 solutionHistory->addState(icState);
485 stepperSC->setInitialConditions(solutionHistory);
486 stepper->initialize();
489 integrator = Tempus::createIntegratorBasic<double>();
490 integrator->setStepper(stepper);
491 integrator->setTimeStepControl(timeStepControl);
492 integrator->setSolutionHistory(solutionHistory);
493 integrator->setScreenOutputIndexInterval(10);
495 integrator->initialize();
498 bool integratorStatus = integrator->advanceTime();
499 TEST_ASSERT(integratorStatus)
502 time = integrator->getTime();
503 double timeFinal = 2.0;
504 double tol = 100.0 * std::numeric_limits<double>::epsilon();
505 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
508 StepSize.push_back(dt);
509 auto solution = Thyra::createMember(implicitModel->get_x_space());
510 Thyra::copy(*(integrator->getX()), solution.ptr());
511 solutions.push_back(solution);
512 auto solutionDot = Thyra::createMember(implicitModel->get_x_space());
513 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
514 solutionsDot.push_back(solutionDot);
518 if ((n == 0) || (n == nTimeStepSizes - 1)) {
519 std::string fname =
"Tempus_Subcycling_VanDerPol-Ref.dat";
520 if (n == 0) fname =
"Tempus_Subcycling_VanDerPol.dat";
528 double xDotSlope = 0.0;
529 RCP<Tempus::Stepper<double>> stepper = integrator->getStepper();
531 writeOrderError(
"Tempus_Subcycling_VanDerPol-Error.dat", stepper, StepSize,
532 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
535 TEST_FLOATING_EQUALITY(xSlope, 1.25708, 0.05);
536 TEST_FLOATING_EQUALITY(xDotSlope, 1.20230, 0.05);
537 TEST_FLOATING_EQUALITY(xErrorNorm[0], 0.37156, 1.0e-4);
538 TEST_FLOATING_EQUALITY(xDotErrorNorm[0], 3.11651, 1.0e-4);
540 Teuchos::TimeMonitor::summarize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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)