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" 39 #define TEST_PARAMETERLIST 40 #define TEST_CONSTRUCTING_FROM_DEFAULTS 42 #define TEST_SINCOS_ADAPT 44 #define TEST_VANDERPOL 49 using Teuchos::ParameterList;
50 using Teuchos::sublist;
51 using Teuchos::getParametersFromXmlFile;
58 #ifdef TEST_PARAMETERLIST 64 RCP<ParameterList> pList =
65 getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
68 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
69 RCP<SinCosModel<double> > model =
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);
81 stepperPL->remove(
"Start Up Stepper Name");
82 stepperPL->remove(
"Default Start Up Stepper");
83 RCP<ParameterList> defaultPL =
84 integrator->getStepper()->getDefaultParameters();
85 TEST_ASSERT(haveSameValues(*stepperPL, *defaultPL,
true))
90 RCP<Tempus::IntegratorBasic<double> > integrator =
91 Tempus::integratorBasic<double>(model,
"BDF2");
93 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Default Stepper",
true);
94 RCP<ParameterList> defaultPL =
95 integrator->getStepper()->getDefaultParameters();
100 TEST_ASSERT(haveSameValues(*stepperPL, *defaultPL,
true))
103 #endif // TEST_PARAMETERLIST 106 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS 114 RCP<ParameterList> pList =
115 getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
116 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
119 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
121 RCP<SinCosModel<double> > model =
125 RCP<Tempus::StepperBDF2<double> > stepper =
137 RCP<Tempus::TimeStepControl<double> > timeStepControl =
139 ParameterList tscPL = pl->sublist(
"Default Integrator")
140 .sublist(
"Time Step Control");
141 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
142 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
143 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
144 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
145 timeStepControl->setInitTimeStep(dt);
146 timeStepControl->initialize();
149 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
150 stepper->getModel()->getNominalValues();
151 RCP<Thyra::VectorBase<double> > icSolution =
152 Teuchos::rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
153 RCP<Tempus::SolutionState<double> > icState =
155 icState->setTime (timeStepControl->getInitTime());
156 icState->setIndex (timeStepControl->getInitIndex());
157 icState->setTimeStep(0.0);
158 icState->setOrder (stepper->getOrder());
170 RCP<Tempus::IntegratorBasic<double> > integrator =
171 Tempus::integratorBasic<double>();
172 integrator->setStepperWStepper(stepper);
173 integrator->setTimeStepControl(timeStepControl);
176 integrator->initialize();
180 bool integratorStatus = integrator->advanceTime();
181 TEST_ASSERT(integratorStatus)
185 double time = integrator->getTime();
186 double timeFinal =pl->sublist(
"Default Integrator")
187 .sublist(
"Time Step Control").get<
double>(
"Final Time");
188 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
191 RCP<Thyra::VectorBase<double> > x = integrator->getX();
192 RCP<const Thyra::VectorBase<double> > x_exact =
193 model->getExactSolution(time).get_x();
196 RCP<Thyra::VectorBase<double> > xdiff = x->clone_v();
197 Thyra::V_StVpStV(xdiff.ptr(), 1.0, *x_exact, -1.0, *(x));
200 std::cout <<
" Stepper = BDF2" << std::endl;
201 std::cout <<
" =========================" << std::endl;
202 std::cout <<
" Exact solution : " << get_ele(*(x_exact), 0) <<
" " 203 << get_ele(*(x_exact), 1) << std::endl;
204 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" " 205 << get_ele(*(x ), 1) << std::endl;
206 std::cout <<
" Difference : " << get_ele(*(xdiff ), 0) <<
" " 207 << get_ele(*(xdiff ), 1) << std::endl;
208 std::cout <<
" =========================" << std::endl;
209 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 0.839732, 1.0e-4 );
210 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.542663, 1.0e-4 );
212 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS 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;
226 RCP<ParameterList> pList = getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
229 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
230 double dt = pl->sublist(
"Default Integrator")
231 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
235 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
236 const int nTimeStepSizes = scm_pl->get<
int>(
"Number of Time Step Sizes", 7);
237 std::string output_file_string =
238 scm_pl->get<std::string>(
"Output File Name",
"Tempus_BDF2_SinCos");
239 std::string output_file_name = output_file_string +
".dat";
240 std::string ref_out_file_name = output_file_string +
"-Ref.dat";
241 std::string err_out_file_name = output_file_string +
"-Error.dat";
243 for (
int n=0; n<nTimeStepSizes; n++) {
249 RCP<SinCosModel<double> > model =
255 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
256 pl->sublist(
"Default Integrator")
257 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
258 integrator = Tempus::integratorBasic<double>(pl, model);
264 RCP<Thyra::VectorBase<double> > x0 =
265 model->getNominalValues().get_x()->clone_v();
266 integrator->setInitialState(0.0, x0);
269 bool integratorStatus = integrator->advanceTime();
270 TEST_ASSERT(integratorStatus)
273 time = integrator->getTime();
274 double timeFinal =pl->sublist(
"Default Integrator")
275 .sublist(
"Time Step Control").get<
double>(
"Final Time");
276 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
281 integrator->getSolutionHistory();
284 RCP<Tempus::SolutionHistory<double> > solnHistExact =
287 double time = (*solutionHistory)[i]->getTime();
288 RCP<Tempus::SolutionState<double> > state =
290 model->getExactSolution(time).get_x(),
291 model->getExactSolution(time).get_x_dot()));
293 solnHistExact->addState(state);
299 StepSize.push_back(dt);
300 auto solution = Thyra::createMember(model->get_x_space());
301 Thyra::copy(*(integrator->getX()),solution.ptr());
302 solutions.push_back(solution);
303 auto solutionDot = Thyra::createMember(model->get_x_space());
304 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
305 solutionsDot.push_back(solutionDot);
306 if (n == nTimeStepSizes-1) {
307 StepSize.push_back(0.0);
308 auto solution = Thyra::createMember(model->get_x_space());
309 Thyra::copy(*(model->getExactSolution(time).get_x()),solution.ptr());
310 solutions.push_back(solution);
311 auto solutionDot = Thyra::createMember(model->get_x_space());
312 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
314 solutionsDot.push_back(solutionDot);
319 if (nTimeStepSizes > 1) {
321 double xDotSlope = 0.0;
322 std::vector<double> xErrorNorm;
323 std::vector<double> xDotErrorNorm;
324 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
325 double order = stepper->getOrder();
328 solutions, xErrorNorm, xSlope,
329 solutionsDot, xDotErrorNorm, xDotSlope);
331 TEST_FLOATING_EQUALITY( xSlope, order, 0.01 );
332 TEST_FLOATING_EQUALITY( xDotSlope, order, 0.01 );
333 TEST_FLOATING_EQUALITY( xErrorNorm[0], 5.13425e-05, 1.0e-4 );
334 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 5.13425e-05, 1.0e-4 );
337 Teuchos::TimeMonitor::summarize();
339 #endif // TEST_SINCOS 342 #ifdef TEST_SINCOS_ADAPT 347 RCP<Tempus::IntegratorBasic<double> > integrator;
348 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
349 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
350 std::vector<double> StepSize;
353 RCP<ParameterList> pList =
354 getParametersFromXmlFile(
"Tempus_BDF2_SinCos_AdaptDt.xml");
356 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
357 double dt = pl->sublist(
"Default Integrator")
358 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
362 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
363 const int nTimeStepSizes = scm_pl->get<
int>(
"Number of Time Step Sizes", 7);
364 std::string output_file_string =
365 scm_pl->get<std::string>(
"Output File Name",
"Tempus_BDF2_SinCos");
366 std::string output_file_name = output_file_string +
".dat";
367 std::string err_out_file_name = output_file_string +
"-Error.dat";
369 for (
int n=0; n<nTimeStepSizes; n++) {
375 RCP<SinCosModel<double> > model =
381 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
382 pl->sublist(
"Default Integrator")
383 .sublist(
"Time Step Control").set(
"Initial Time Step", dt/4.0);
386 pl->sublist(
"Default Integrator")
387 .sublist(
"Time Step Control").set(
"Maximum Time Step", dt);
389 pl->sublist(
"Default Integrator")
390 .sublist(
"Time Step Control").set(
"Minimum Time Step", dt/4.0);
392 pl->sublist(
"Default Integrator")
393 .sublist(
"Time Step Control")
394 .sublist(
"Time Step Control Strategy")
396 .set(
"Minimum Value Monitoring Function", dt*0.99);
397 integrator = Tempus::integratorBasic<double>(pl, model);
403 RCP<Thyra::VectorBase<double> > x0 =
404 model->getNominalValues().get_x()->clone_v();
405 integrator->setInitialState(0.0, x0);
408 bool integratorStatus = integrator->advanceTime();
409 TEST_ASSERT(integratorStatus)
412 time = integrator->getTime();
413 double timeFinal =pl->sublist(
"Default Integrator")
414 .sublist(
"Time Step Control").get<
double>(
"Final Time");
415 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
418 RCP<Thyra::VectorBase<double> > x = integrator->getX();
419 RCP<const Thyra::VectorBase<double> > x_exact =
420 model->getExactSolution(time).get_x();
424 std::ofstream ftmp(output_file_name);
426 FILE *gold_file = fopen(
"Tempus_BDF2_SinCos_AdaptDt_gold.dat",
"r");
428 integrator->getSolutionHistory();
429 RCP<const Thyra::VectorBase<double> > x_exact_plot;
431 char time_gold_char[100];
432 fgets(time_gold_char, 100, gold_file);
434 sscanf(time_gold_char,
"%lf", &time_gold);
435 RCP<const SolutionState<double> > solutionState = (*solutionHistory)[i];
436 double time = solutionState->getTime();
438 TEST_FLOATING_EQUALITY( time, time_gold, 1.0e-5 );
439 RCP<const Thyra::VectorBase<double> > x_plot = solutionState->getX();
440 x_exact_plot = model->getExactSolution(time).get_x();
442 << get_ele(*(x_plot), 0) <<
" " 443 << get_ele(*(x_plot), 1) <<
" " 444 << get_ele(*(x_exact_plot), 0) <<
" " 445 << get_ele(*(x_exact_plot), 1) << std::endl;
451 StepSize.push_back(dt);
452 auto solution = Thyra::createMember(model->get_x_space());
453 Thyra::copy(*(integrator->getX()),solution.ptr());
454 solutions.push_back(solution);
455 auto solutionDot = Thyra::createMember(model->get_x_space());
456 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
457 solutionsDot.push_back(solutionDot);
458 if (n == nTimeStepSizes-1) {
459 StepSize.push_back(0.0);
460 auto solution = Thyra::createMember(model->get_x_space());
461 Thyra::copy(*(model->getExactSolution(time).get_x()),solution.ptr());
462 solutions.push_back(solution);
463 auto solutionDot = Thyra::createMember(model->get_x_space());
464 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
466 solutionsDot.push_back(solutionDot);
471 if (nTimeStepSizes > 1) {
473 double xDotSlope = 0.0;
474 std::vector<double> xErrorNorm;
475 std::vector<double> xDotErrorNorm;
476 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
480 solutions, xErrorNorm, xSlope,
481 solutionsDot, xDotErrorNorm, xDotSlope);
483 TEST_FLOATING_EQUALITY( xSlope, 1.95089, 0.01 );
484 TEST_FLOATING_EQUALITY( xDotSlope, 1.95089, 0.01 );
485 TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.000197325, 1.0e-4 );
486 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 0.000197325, 1.0e-4 );
489 Teuchos::TimeMonitor::summarize();
491 #endif // TEST_SINCOS_ADAPT 500 RCP<Epetra_Comm> comm;
501 #ifdef Tempus_ENABLE_MPI 502 comm = Teuchos::rcp(
new Epetra_MpiComm(MPI_COMM_WORLD));
504 comm = Teuchos::rcp(
new Epetra_SerialComm);
507 RCP<Tempus::IntegratorBasic<double> > integrator;
508 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
509 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
510 std::vector<double> StepSize;
513 RCP<ParameterList> pList =
514 getParametersFromXmlFile(
"Tempus_BDF2_CDR.xml");
517 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
518 double dt = pl->sublist(
"Demo Integrator")
519 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
521 RCP<ParameterList> model_pl = sublist(pList,
"CDR Model",
true);
523 const int nTimeStepSizes = model_pl->get<
int>(
"Number of Time Step Sizes", 5);
525 for (
int n=0; n<nTimeStepSizes; n++) {
528 const int num_elements = model_pl->get<
int>(
"num elements");
529 const double left_end = model_pl->get<
double>(
"left end");
530 const double right_end = model_pl->get<
double>(
"right end");
531 const double a_convection = model_pl->get<
double>(
"a (convection)");
532 const double k_source = model_pl->get<
double>(
"k (source)");
534 RCP<Tempus_Test::CDR_Model<double>> model =
543 ::Stratimikos::DefaultLinearSolverBuilder builder;
545 Teuchos::RCP<Teuchos::ParameterList> p =
546 Teuchos::rcp(
new Teuchos::ParameterList);
547 p->set(
"Linear Solver Type",
"Belos");
548 p->set(
"Preconditioner Type",
"None");
549 builder.setParameterList(p);
551 Teuchos::RCP< ::Thyra::LinearOpWithSolveFactoryBase<double> >
552 lowsFactory = builder.createLinearSolveStrategy(
"");
554 model->set_W_factory(lowsFactory);
560 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
561 pl->sublist(
"Demo Integrator")
562 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
563 integrator = Tempus::integratorBasic<double>(pl, model);
566 bool integratorStatus = integrator->advanceTime();
567 TEST_ASSERT(integratorStatus)
570 double time = integrator->getTime();
571 double timeFinal =pl->sublist(
"Demo Integrator")
572 .sublist(
"Time Step Control").get<
double>(
"Final Time");
573 double tol = 100.0 * std::numeric_limits<double>::epsilon();
574 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
577 StepSize.push_back(dt);
578 auto solution = Thyra::createMember(model->get_x_space());
579 Thyra::copy(*(integrator->getX()),solution.ptr());
580 solutions.push_back(solution);
581 auto solutionDot = Thyra::createMember(model->get_x_space());
582 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
583 solutionsDot.push_back(solutionDot);
587 if ((n == nTimeStepSizes-1) && (comm->NumProc() == 1)) {
588 std::ofstream ftmp(
"Tempus_BDF2_CDR.dat");
589 ftmp <<
"TITLE=\"BDF2 Solution to CDR\"\n" 590 <<
"VARIABLES=\"z\",\"T\"\n";
591 const double dx = std::fabs(left_end-right_end) /
592 static_cast<double>(num_elements);
594 integrator->getSolutionHistory();
596 for (
int i=0; i<nStates; i++) {
597 RCP<const SolutionState<double> > solutionState = (*solutionHistory)[i];
598 RCP<const Thyra::VectorBase<double> > x = solutionState->getX();
599 double ttime = solutionState->getTime();
600 ftmp <<
"ZONE T=\"Time="<<ttime<<
"\", I=" 601 <<num_elements+1<<
", F=BLOCK\n";
602 for (
int j = 0; j < num_elements+1; j++) {
603 const double x_coord = left_end +
static_cast<double>(j) * dx;
604 ftmp << x_coord <<
" ";
607 for (
int j=0; j<num_elements+1; j++) ftmp << get_ele(*x, j) <<
" ";
615 if (nTimeStepSizes > 2) {
617 double xDotSlope = 0.0;
618 std::vector<double> xErrorNorm;
619 std::vector<double> xDotErrorNorm;
620 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
621 double order = stepper->getOrder();
624 solutions, xErrorNorm, xSlope,
625 solutionsDot, xDotErrorNorm, xDotSlope);
626 TEST_FLOATING_EQUALITY( xSlope, order, 0.35 );
627 TEST_COMPARE(xSlope, >, 0.95);
628 TEST_FLOATING_EQUALITY( xDotSlope, order, 0.35 );
629 TEST_COMPARE(xDotSlope, >, 0.95);
631 TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.0145747, 1.0e-4 );
632 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 0.0563621, 1.0e-4 );
637 if (comm->NumProc() == 1) {
638 RCP<ParameterList> pList =
639 getParametersFromXmlFile(
"Tempus_BDF2_CDR.xml");
640 RCP<ParameterList> model_pl = sublist(pList,
"CDR Model",
true);
641 const int num_elements = model_pl->get<
int>(
"num elements");
642 const double left_end = model_pl->get<
double>(
"left end");
643 const double right_end = model_pl->get<
double>(
"right end");
645 const Thyra::VectorBase<double>& x = *(solutions[solutions.size()-1]);
647 std::ofstream ftmp(
"Tempus_BDF2_CDR-Solution.dat");
648 for (
int n = 0; n < num_elements+1; n++) {
649 const double dx = std::fabs(left_end-right_end) /
650 static_cast<double>(num_elements);
651 const double x_coord = left_end +
static_cast<double>(n) * dx;
652 ftmp << x_coord <<
" " << Thyra::get_ele(x,n) << std::endl;
657 Teuchos::TimeMonitor::summarize();
662 #ifdef TEST_VANDERPOL 667 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
668 std::vector<double> StepSize;
669 std::vector<double> ErrorNorm;
672 RCP<ParameterList> pList =
673 getParametersFromXmlFile(
"Tempus_BDF2_VanDerPol.xml");
676 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
677 double dt = pl->sublist(
"Demo Integrator")
678 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
681 RCP<ParameterList> vdpm_pl = sublist(pList,
"VanDerPolModel",
true);
682 const int nTimeStepSizes = vdpm_pl->get<
int>(
"Number of Time Step Sizes", 3);
686 for (
int n=0; n<nTimeStepSizes; n++) {
689 RCP<VanDerPolModel<double> > model =
694 if (n == nTimeStepSizes-1) dt /= 10.0;
697 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
698 pl->sublist(
"Demo Integrator")
699 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
700 RCP<Tempus::IntegratorBasic<double> > integrator =
701 Tempus::integratorBasic<double>(pl, model);
702 order = integrator->getStepper()->getOrder();
705 bool integratorStatus = integrator->advanceTime();
706 TEST_ASSERT(integratorStatus)
709 double time = integrator->getTime();
710 double timeFinal =pl->sublist(
"Demo Integrator")
711 .sublist(
"Time Step Control").get<
double>(
"Final Time");
712 double tol = 100.0 * std::numeric_limits<double>::epsilon();
713 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
716 auto solution = Thyra::createMember(model->get_x_space());
717 Thyra::copy(*(integrator->getX()),solution.ptr());
718 solutions.push_back(solution);
719 StepSize.push_back(dt);
723 if ((n == 0) or (n == nTimeStepSizes-1)) {
724 std::string fname =
"Tempus_BDF2_VanDerPol-Ref.dat";
725 if (n == 0) fname =
"Tempus_BDF2_VanDerPol.dat";
726 std::ofstream ftmp(fname);
728 integrator->getSolutionHistory();
730 for (
int i=0; i<nStates; i++) {
731 RCP<const SolutionState<double> > solutionState = (*solutionHistory)[i];
732 RCP<const Thyra::VectorBase<double> > x = solutionState->getX();
733 double ttime = solutionState->getTime();
734 ftmp << ttime <<
" " << get_ele(*x, 0) <<
" " << get_ele(*x, 1)
743 auto ref_solution = solutions[solutions.size()-1];
744 std::vector<double> StepSizeCheck;
745 for (std::size_t i=0; i < (solutions.size()-1); ++i) {
746 auto tmp = solutions[i];
747 Thyra::Vp_StV(tmp.ptr(), -1.0, *ref_solution);
748 const double L2norm = Thyra::norm_2(*tmp);
749 StepSizeCheck.push_back(StepSize[i]);
750 ErrorNorm.push_back(L2norm);
753 if (nTimeStepSizes > 2) {
755 double slope = computeLinearRegressionLogLog<double>(StepSizeCheck,ErrorNorm);
756 std::cout <<
" Stepper = BDF2" << std::endl;
757 std::cout <<
" =========================" << std::endl;
758 std::cout <<
" Expected order: " << order << std::endl;
759 std::cout <<
" Observed order: " << slope << std::endl;
760 std::cout <<
" =========================" << std::endl;
761 TEST_FLOATING_EQUALITY( slope, order, 0.10 );
762 out <<
"\n\n ** Slope on BDF2 Method = " << slope
763 <<
"\n" << std::endl;
768 std::ofstream ftmp(
"Tempus_BDF2_VanDerPol-Error.dat");
769 double error0 = 0.8*ErrorNorm[0];
770 for (std::size_t n = 0; n < StepSizeCheck.size(); n++) {
771 ftmp << StepSizeCheck[n] <<
" " << ErrorNorm[n] <<
" " 772 << error0*(pow(StepSize[n]/StepSize[0],order)) << std::endl;
777 Teuchos::TimeMonitor::summarize();
779 #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