9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
14 #include "Tempus_config.hpp"
15 #include "Tempus_IntegratorBasic.hpp"
16 #include "Tempus_StepperBDF2.hpp"
18 #include "../TestModels/SinCosModel.hpp"
19 #include "../TestModels/CDR_Model.hpp"
20 #include "../TestModels/VanDerPolModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
23 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
24 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
26 #ifdef Tempus_ENABLE_MPI
27 #include "Epetra_MpiComm.h"
29 #include "Epetra_SerialComm.h"
38 #define TEST_PARAMETERLIST
39 #define TEST_CONSTRUCTING_FROM_DEFAULTS
41 #define TEST_SINCOS_ADAPT
43 #define TEST_VANDERPOL
45 namespace Tempus_Test {
49 using Teuchos::rcp_const_cast;
50 using Teuchos::ParameterList;
51 using Teuchos::sublist;
52 using Teuchos::getParametersFromXmlFile;
59 #ifdef TEST_PARAMETERLIST
65 RCP<ParameterList> pList =
66 getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
69 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
72 RCP<ParameterList> tempusPL = sublist(pList,
"Tempus",
true);
76 RCP<Tempus::IntegratorBasic<double> > integrator =
77 Tempus::integratorBasic<double>(tempusPL, model);
79 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Default Stepper",
true);
80 RCP<const ParameterList> defaultPL =
81 integrator->getStepper()->getValidParameters();
82 bool pass = haveSameValues(*stepperPL, *defaultPL,
true);
84 std::cout << std::endl;
85 std::cout <<
"stepperPL -------------- \n" << *stepperPL << std::endl;
86 std::cout <<
"defaultPL -------------- \n" << *defaultPL << std::endl;
93 RCP<Tempus::IntegratorBasic<double> > integrator =
94 Tempus::integratorBasic<double>(model,
"BDF2");
96 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Default Stepper",
true);
97 RCP<const ParameterList> defaultPL =
98 integrator->getStepper()->getValidParameters();
100 bool pass = haveSameValues(*stepperPL, *defaultPL,
true);
102 std::cout << std::endl;
103 std::cout <<
"stepperPL -------------- \n" << *stepperPL << std::endl;
104 std::cout <<
"defaultPL -------------- \n" << *defaultPL << std::endl;
109 #endif // TEST_PARAMETERLIST
112 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS
120 RCP<ParameterList> pList =
121 getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
122 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
125 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
131 stepper->setModel(model);
132 stepper->setSolver();
133 stepper->setStartUpStepper();
134 stepper->initialize();
138 ParameterList tscPL = pl->sublist(
"Default Integrator")
139 .sublist(
"Time Step Control");
140 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
141 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
142 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
143 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
144 timeStepControl->setInitTimeStep(dt);
145 timeStepControl->initialize();
148 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
149 stepper->getModel()->getNominalValues();
150 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
152 icState->setTime (timeStepControl->getInitTime());
153 icState->setIndex (timeStepControl->getInitIndex());
154 icState->setTimeStep(0.0);
155 icState->setOrder (stepper->getOrder());
166 RCP<Tempus::IntegratorBasic<double> > integrator =
167 Tempus::integratorBasic<double>();
168 integrator->setStepperWStepper(stepper);
169 integrator->setTimeStepControl(timeStepControl);
172 integrator->initialize();
176 bool integratorStatus = integrator->advanceTime();
177 TEST_ASSERT(integratorStatus)
181 double time = integrator->getTime();
182 double timeFinal =pl->sublist(
"Default Integrator")
183 .sublist(
"Time Step Control").get<
double>(
"Final Time");
184 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
187 RCP<Thyra::VectorBase<double> > x = integrator->getX();
188 RCP<const Thyra::VectorBase<double> > x_exact =
189 model->getExactSolution(time).get_x();
192 RCP<Thyra::VectorBase<double> > xdiff = x->clone_v();
193 Thyra::V_StVpStV(xdiff.ptr(), 1.0, *x_exact, -1.0, *(x));
196 std::cout <<
" Stepper = BDF2" << std::endl;
197 std::cout <<
" =========================" << std::endl;
198 std::cout <<
" Exact solution : " << get_ele(*(x_exact), 0) <<
" "
199 << get_ele(*(x_exact), 1) << std::endl;
200 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
201 << get_ele(*(x ), 1) << std::endl;
202 std::cout <<
" Difference : " << get_ele(*(xdiff ), 0) <<
" "
203 << get_ele(*(xdiff ), 1) << std::endl;
204 std::cout <<
" =========================" << std::endl;
205 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 0.839732, 1.0e-4 );
206 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.542663, 1.0e-4 );
208 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
216 RCP<Tempus::IntegratorBasic<double> > integrator;
217 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
218 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
219 std::vector<double> StepSize;
222 RCP<ParameterList> pList = getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
225 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
226 double dt = pl->sublist(
"Default Integrator")
227 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
231 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
232 const int nTimeStepSizes = scm_pl->get<
int>(
"Number of Time Step Sizes", 7);
233 std::string output_file_string =
234 scm_pl->get<std::string>(
"Output File Name",
"Tempus_BDF2_SinCos");
235 std::string output_file_name = output_file_string +
".dat";
236 std::string ref_out_file_name = output_file_string +
"-Ref.dat";
237 std::string err_out_file_name = output_file_string +
"-Error.dat";
239 for (
int n=0; n<nTimeStepSizes; n++) {
250 pl->sublist(
"Default Integrator")
251 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
252 integrator = Tempus::integratorBasic<double>(pl, model);
258 RCP<Thyra::VectorBase<double> > x0 =
259 model->getNominalValues().get_x()->clone_v();
260 integrator->initializeSolutionHistory(0.0, x0);
263 bool integratorStatus = integrator->advanceTime();
264 TEST_ASSERT(integratorStatus)
267 time = integrator->getTime();
268 double timeFinal =pl->sublist(
"Default Integrator")
269 .sublist(
"Time Step Control").get<
double>(
"Final Time");
270 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
275 integrator->getSolutionHistory();
279 for (
int i=0; i<solutionHistory->getNumStates(); i++) {
280 double time_i = (*solutionHistory)[i]->getTime();
282 model->getExactSolution(time_i).get_x(),
283 model->getExactSolution(time_i).get_x_dot()));
284 state->setTime((*solutionHistory)[i]->getTime());
285 solnHistExact->addState(state);
291 StepSize.push_back(dt);
292 auto solution = Thyra::createMember(model->get_x_space());
293 Thyra::copy(*(integrator->getX()),solution.ptr());
294 solutions.push_back(solution);
295 auto solutionDot = Thyra::createMember(model->get_x_space());
296 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
297 solutionsDot.push_back(solutionDot);
298 if (n == nTimeStepSizes-1) {
299 StepSize.push_back(0.0);
300 auto solutionExact = Thyra::createMember(model->get_x_space());
301 Thyra::copy(*(model->getExactSolution(time).get_x()),solutionExact.ptr());
302 solutions.push_back(solutionExact);
303 auto solutionDotExact = Thyra::createMember(model->get_x_space());
304 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
305 solutionDotExact.ptr());
306 solutionsDot.push_back(solutionDotExact);
311 if (nTimeStepSizes > 1) {
313 double xDotSlope = 0.0;
314 std::vector<double> xErrorNorm;
315 std::vector<double> xDotErrorNorm;
316 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
317 double order = stepper->getOrder();
320 solutions, xErrorNorm, xSlope,
321 solutionsDot, xDotErrorNorm, xDotSlope);
323 TEST_FLOATING_EQUALITY( xSlope, order, 0.01 );
324 TEST_FLOATING_EQUALITY( xDotSlope, order, 0.01 );
325 TEST_FLOATING_EQUALITY( xErrorNorm[0], 5.13425e-05, 1.0e-4 );
326 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 5.13425e-05, 1.0e-4 );
329 Teuchos::TimeMonitor::summarize();
331 #endif // TEST_SINCOS
334 #ifdef TEST_SINCOS_ADAPT
339 RCP<Tempus::IntegratorBasic<double> > integrator;
340 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
341 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
342 std::vector<double> StepSize;
345 RCP<ParameterList> pList =
346 getParametersFromXmlFile(
"Tempus_BDF2_SinCos_AdaptDt.xml");
348 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
349 double dt = pl->sublist(
"Default Integrator")
350 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
354 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
355 const int nTimeStepSizes = scm_pl->get<
int>(
"Number of Time Step Sizes", 7);
356 std::string output_file_string =
357 scm_pl->get<std::string>(
"Output File Name",
"Tempus_BDF2_SinCos");
358 std::string output_file_name = output_file_string +
".dat";
359 std::string err_out_file_name = output_file_string +
"-Error.dat";
361 for (
int n=0; n<nTimeStepSizes; n++) {
372 pl->sublist(
"Default Integrator")
373 .sublist(
"Time Step Control").set(
"Initial Time Step", dt/4.0);
376 pl->sublist(
"Default Integrator")
377 .sublist(
"Time Step Control").set(
"Maximum Time Step", dt);
379 pl->sublist(
"Default Integrator")
380 .sublist(
"Time Step Control").set(
"Minimum Time Step", dt/4.0);
382 pl->sublist(
"Default Integrator")
383 .sublist(
"Time Step Control")
384 .sublist(
"Time Step Control Strategy")
386 .set(
"Minimum Value Monitoring Function", dt*0.99);
387 integrator = Tempus::integratorBasic<double>(pl, model);
393 RCP<Thyra::VectorBase<double> > x0 =
394 model->getNominalValues().get_x()->clone_v();
395 integrator->initializeSolutionHistory(0.0, x0);
398 bool integratorStatus = integrator->advanceTime();
399 TEST_ASSERT(integratorStatus)
402 time = integrator->getTime();
403 double timeFinal =pl->sublist(
"Default Integrator")
404 .sublist(
"Time Step Control").get<
double>(
"Final Time");
405 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
408 RCP<Thyra::VectorBase<double> > x = integrator->getX();
409 RCP<const Thyra::VectorBase<double> > x_exact =
410 model->getExactSolution(time).get_x();
414 std::ofstream ftmp(output_file_name);
416 FILE *gold_file = fopen(
"Tempus_BDF2_SinCos_AdaptDt_gold.dat",
"r");
418 integrator->getSolutionHistory();
419 RCP<const Thyra::VectorBase<double> > x_exact_plot;
420 for (
int i=0; i<solutionHistory->getNumStates(); i++) {
421 char time_gold_char[100];
422 fgets(time_gold_char, 100, gold_file);
424 sscanf(time_gold_char,
"%lf", &time_gold);
425 RCP<const SolutionState<double> > solutionState = (*solutionHistory)[i];
426 double time_i = solutionState->getTime();
428 TEST_FLOATING_EQUALITY( time_i, time_gold, 1.0e-5 );
429 RCP<const Thyra::VectorBase<double> > x_plot = solutionState->getX();
430 x_exact_plot = model->getExactSolution(time_i).get_x();
431 ftmp << time_i <<
" "
432 << get_ele(*(x_plot), 0) <<
" "
433 << get_ele(*(x_plot), 1) <<
" "
434 << get_ele(*(x_exact_plot), 0) <<
" "
435 << get_ele(*(x_exact_plot), 1) << std::endl;
441 StepSize.push_back(dt);
442 auto solution = Thyra::createMember(model->get_x_space());
443 Thyra::copy(*(integrator->getX()),solution.ptr());
444 solutions.push_back(solution);
445 auto solutionDot = Thyra::createMember(model->get_x_space());
446 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
447 solutionsDot.push_back(solutionDot);
448 if (n == nTimeStepSizes-1) {
449 StepSize.push_back(0.0);
450 auto solutionExact = Thyra::createMember(model->get_x_space());
451 Thyra::copy(*(model->getExactSolution(time).get_x()),solutionExact.ptr());
452 solutions.push_back(solutionExact);
453 auto solutionDotExact = Thyra::createMember(model->get_x_space());
454 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
455 solutionDotExact.ptr());
456 solutionsDot.push_back(solutionDotExact);
461 if (nTimeStepSizes > 1) {
463 double xDotSlope = 0.0;
464 std::vector<double> xErrorNorm;
465 std::vector<double> xDotErrorNorm;
466 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
470 solutions, xErrorNorm, xSlope,
471 solutionsDot, xDotErrorNorm, xDotSlope);
473 TEST_FLOATING_EQUALITY( xSlope, 1.95089, 0.01 );
474 TEST_FLOATING_EQUALITY( xDotSlope, 1.95089, 0.01 );
475 TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.000197325, 1.0e-4 );
476 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 0.000197325, 1.0e-4 );
479 Teuchos::TimeMonitor::summarize();
481 #endif // TEST_SINCOS_ADAPT
490 RCP<Epetra_Comm> comm;
491 #ifdef Tempus_ENABLE_MPI
492 comm = rcp(
new Epetra_MpiComm(MPI_COMM_WORLD));
494 comm = rcp(
new Epetra_SerialComm);
497 RCP<Tempus::IntegratorBasic<double> > integrator;
498 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
499 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
500 std::vector<double> StepSize;
503 RCP<ParameterList> pList =
504 getParametersFromXmlFile(
"Tempus_BDF2_CDR.xml");
507 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
508 double dt = pl->sublist(
"Demo Integrator")
509 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
511 RCP<ParameterList> model_pl = sublist(pList,
"CDR Model",
true);
513 const int nTimeStepSizes = model_pl->get<
int>(
"Number of Time Step Sizes", 5);
515 for (
int n=0; n<nTimeStepSizes; n++) {
518 const int num_elements = model_pl->get<
int>(
"num elements");
519 const double left_end = model_pl->get<
double>(
"left end");
520 const double right_end = model_pl->get<
double>(
"right end");
521 const double a_convection = model_pl->get<
double>(
"a (convection)");
522 const double k_source = model_pl->get<
double>(
"k (source)");
532 ::Stratimikos::DefaultLinearSolverBuilder builder;
534 auto p = rcp(
new ParameterList);
535 p->set(
"Linear Solver Type",
"Belos");
536 p->set(
"Preconditioner Type",
"None");
537 builder.setParameterList(p);
539 RCP< ::Thyra::LinearOpWithSolveFactoryBase<double> >
540 lowsFactory = builder.createLinearSolveStrategy(
"");
542 model->set_W_factory(lowsFactory);
548 pl->sublist(
"Demo Integrator")
549 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
550 integrator = Tempus::integratorBasic<double>(pl, model);
553 bool integratorStatus = integrator->advanceTime();
554 TEST_ASSERT(integratorStatus)
557 double time = integrator->getTime();
558 double timeFinal =pl->sublist(
"Demo Integrator")
559 .sublist(
"Time Step Control").get<
double>(
"Final Time");
560 double tol = 100.0 * std::numeric_limits<double>::epsilon();
561 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
564 StepSize.push_back(dt);
565 auto solution = Thyra::createMember(model->get_x_space());
566 Thyra::copy(*(integrator->getX()),solution.ptr());
567 solutions.push_back(solution);
568 auto solutionDot = Thyra::createMember(model->get_x_space());
569 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
570 solutionsDot.push_back(solutionDot);
574 if ((n == nTimeStepSizes-1) && (comm->NumProc() == 1)) {
575 std::ofstream ftmp(
"Tempus_BDF2_CDR.dat");
576 ftmp <<
"TITLE=\"BDF2 Solution to CDR\"\n"
577 <<
"VARIABLES=\"z\",\"T\"\n";
578 const double dx = std::fabs(left_end-right_end) /
579 static_cast<double>(num_elements);
581 integrator->getSolutionHistory();
582 int nStates = solutionHistory->getNumStates();
583 for (
int i=0; i<nStates; i++) {
584 RCP<const SolutionState<double> > solutionState = (*solutionHistory)[i];
585 RCP<const Thyra::VectorBase<double> > x = solutionState->getX();
586 double ttime = solutionState->getTime();
587 ftmp <<
"ZONE T=\"Time="<<ttime<<
"\", I="
588 <<num_elements+1<<
", F=BLOCK\n";
589 for (
int j = 0; j < num_elements+1; j++) {
590 const double x_coord = left_end +
static_cast<double>(j) * dx;
591 ftmp << x_coord <<
" ";
594 for (
int j=0; j<num_elements+1; j++) ftmp << get_ele(*x, j) <<
" ";
602 if (nTimeStepSizes > 2) {
604 double xDotSlope = 0.0;
605 std::vector<double> xErrorNorm;
606 std::vector<double> xDotErrorNorm;
607 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
608 double order = stepper->getOrder();
611 solutions, xErrorNorm, xSlope,
612 solutionsDot, xDotErrorNorm, xDotSlope);
613 TEST_FLOATING_EQUALITY( xSlope, order, 0.35 );
614 TEST_COMPARE(xSlope, >, 0.95);
615 TEST_FLOATING_EQUALITY( xDotSlope, order, 0.35 );
616 TEST_COMPARE(xDotSlope, >, 0.95);
618 TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.0145747, 1.0e-4 );
619 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 0.0563621, 1.0e-4 );
624 if (comm->NumProc() == 1) {
625 RCP<ParameterList> pListCDR =
626 getParametersFromXmlFile(
"Tempus_BDF2_CDR.xml");
627 RCP<ParameterList> model_pl_CDR = sublist(pListCDR,
"CDR Model",
true);
628 const int num_elements = model_pl_CDR->get<
int>(
"num elements");
629 const double left_end = model_pl_CDR->get<
double>(
"left end");
630 const double right_end = model_pl_CDR->get<
double>(
"right end");
632 const Thyra::VectorBase<double>& x = *(solutions[solutions.size()-1]);
634 std::ofstream ftmp(
"Tempus_BDF2_CDR-Solution.dat");
635 for (
int n = 0; n < num_elements+1; n++) {
636 const double dx = std::fabs(left_end-right_end) /
637 static_cast<double>(num_elements);
638 const double x_coord = left_end +
static_cast<double>(n) * dx;
639 ftmp << x_coord <<
" " << Thyra::get_ele(x,n) << std::endl;
644 Teuchos::TimeMonitor::summarize();
649 #ifdef TEST_VANDERPOL
654 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
655 std::vector<double> StepSize;
656 std::vector<double> ErrorNorm;
659 RCP<ParameterList> pList =
660 getParametersFromXmlFile(
"Tempus_BDF2_VanDerPol.xml");
663 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
664 double dt = pl->sublist(
"Demo Integrator")
665 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
668 RCP<ParameterList> vdpm_pl = sublist(pList,
"VanDerPolModel",
true);
669 const int nTimeStepSizes = vdpm_pl->get<
int>(
"Number of Time Step Sizes", 3);
673 for (
int n=0; n<nTimeStepSizes; n++) {
680 if (n == nTimeStepSizes-1) dt /= 10.0;
683 pl->sublist(
"Demo Integrator")
684 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
685 RCP<Tempus::IntegratorBasic<double> > integrator =
686 Tempus::integratorBasic<double>(pl, model);
687 order = integrator->getStepper()->getOrder();
690 bool integratorStatus = integrator->advanceTime();
691 TEST_ASSERT(integratorStatus)
694 double time = integrator->getTime();
695 double timeFinal =pl->sublist(
"Demo Integrator")
696 .sublist(
"Time Step Control").get<
double>(
"Final Time");
697 double tol = 100.0 * std::numeric_limits<double>::epsilon();
698 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
701 auto solution = Thyra::createMember(model->get_x_space());
702 Thyra::copy(*(integrator->getX()),solution.ptr());
703 solutions.push_back(solution);
704 StepSize.push_back(dt);
708 if ((n == 0) or (n == nTimeStepSizes-1)) {
709 std::string fname =
"Tempus_BDF2_VanDerPol-Ref.dat";
710 if (n == 0) fname =
"Tempus_BDF2_VanDerPol.dat";
711 std::ofstream ftmp(fname);
713 integrator->getSolutionHistory();
714 int nStates = solutionHistory->getNumStates();
715 for (
int i=0; i<nStates; i++) {
716 RCP<const SolutionState<double> > solutionState = (*solutionHistory)[i];
717 RCP<const Thyra::VectorBase<double> > x = solutionState->getX();
718 double ttime = solutionState->getTime();
719 ftmp << ttime <<
" " << get_ele(*x, 0) <<
" " << get_ele(*x, 1)
728 auto ref_solution = solutions[solutions.size()-1];
729 std::vector<double> StepSizeCheck;
730 for (std::size_t i=0; i < (solutions.size()-1); ++i) {
731 auto tmp = solutions[i];
732 Thyra::Vp_StV(tmp.ptr(), -1.0, *ref_solution);
733 const double L2norm = Thyra::norm_2(*tmp);
734 StepSizeCheck.push_back(StepSize[i]);
735 ErrorNorm.push_back(L2norm);
738 if (nTimeStepSizes > 2) {
740 double slope = computeLinearRegressionLogLog<double>(StepSizeCheck,ErrorNorm);
741 std::cout <<
" Stepper = BDF2" << std::endl;
742 std::cout <<
" =========================" << std::endl;
743 std::cout <<
" Expected order: " << order << std::endl;
744 std::cout <<
" Observed order: " << slope << std::endl;
745 std::cout <<
" =========================" << std::endl;
746 TEST_FLOATING_EQUALITY( slope, order, 0.10 );
747 out <<
"\n\n ** Slope on BDF2 Method = " << slope
748 <<
"\n" << std::endl;
753 std::ofstream ftmp(
"Tempus_BDF2_VanDerPol-Error.dat");
754 double error0 = 0.8*ErrorNorm[0];
755 for (std::size_t n = 0; n < StepSizeCheck.size(); n++) {
756 ftmp << StepSizeCheck[n] <<
" " << ErrorNorm[n] <<
" "
757 << error0*(pow(StepSize[n]/StepSize[0],order)) << std::endl;
762 Teuchos::TimeMonitor::summarize();
764 #endif // TEST_VANDERPOL
BDF2 (Backward-Difference-Formula-2) time stepper.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
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 problem for nonlinear electrical circuit.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
1D CGFEM model for convection/diffusion/reaction