13 #include "Teuchos_DefaultComm.hpp"
15 #include "Tempus_config.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperBDF2.hpp"
19 #include "../TestModels/VanDerPolModel.hpp"
20 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
27 namespace Tempus_Test {
29 using Teuchos::getParametersFromXmlFile;
33 using Teuchos::rcp_const_cast;
34 using Teuchos::sublist;
44 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
45 std::vector<double> StepSize;
46 std::vector<double> ErrorNorm;
50 getParametersFromXmlFile(
"Tempus_BDF2_VanDerPol.xml");
55 double dt = pl->
sublist(
"Demo Integrator")
57 .
get<
double>(
"Initial Time Step");
61 const int nTimeStepSizes = vdpm_pl->
get<
int>(
"Number of Time Step Sizes", 3);
65 for (
int n = 0; n < nTimeStepSizes; n++) {
71 if (n == nTimeStepSizes - 1) dt /= 10.0;
76 .
set(
"Initial Time Step", dt);
78 Tempus::createIntegratorBasic<double>(pl, model);
79 order = integrator->getStepper()->getOrder();
82 bool integratorStatus = integrator->advanceTime();
86 double time = integrator->getTime();
87 double timeFinal = pl->sublist(
"Demo Integrator")
88 .sublist(
"Time Step Control")
89 .
get<
double>(
"Final Time");
90 double tol = 100.0 * std::numeric_limits<double>::epsilon();
94 auto solution = Thyra::createMember(model->get_x_space());
95 Thyra::copy(*(integrator->getX()), solution.ptr());
96 solutions.push_back(solution);
97 StepSize.push_back(dt);
101 if ((n == 0) || (n == nTimeStepSizes - 1)) {
102 std::string fname =
"Tempus_BDF2_VanDerPol-Ref.dat";
103 if (n == 0) fname =
"Tempus_BDF2_VanDerPol.dat";
104 std::ofstream ftmp(fname);
106 integrator->getSolutionHistory();
107 int nStates = solutionHistory->getNumStates();
108 for (
int i = 0; i < nStates; i++) {
111 double ttime = solutionState->getTime();
112 ftmp << ttime <<
" " << get_ele(*x, 0) <<
" " << get_ele(*x, 1)
121 auto ref_solution = solutions[solutions.size() - 1];
122 std::vector<double> StepSizeCheck;
123 for (std::size_t i = 0; i < (solutions.size() - 1); ++i) {
124 auto tmp = solutions[i];
125 Thyra::Vp_StV(tmp.ptr(), -1.0, *ref_solution);
126 const double L2norm = Thyra::norm_2(*tmp);
127 StepSizeCheck.push_back(StepSize[i]);
128 ErrorNorm.push_back(L2norm);
131 if (nTimeStepSizes > 2) {
134 computeLinearRegressionLogLog<double>(StepSizeCheck, ErrorNorm);
135 out <<
" Stepper = BDF2" << std::endl;
136 out <<
" =========================" << std::endl;
137 out <<
" Expected order: " << order << std::endl;
138 out <<
" Observed order: " << slope << std::endl;
139 out <<
" =========================" << std::endl;
141 out <<
"\n\n ** Slope on BDF2 Method = " << slope <<
"\n"
147 std::ofstream ftmp(
"Tempus_BDF2_VanDerPol-Error.dat");
148 double error0 = 0.8 * ErrorNorm[0];
149 for (std::size_t n = 0; n < StepSizeCheck.size(); n++) {
150 ftmp << StepSizeCheck[n] <<
" " << ErrorNorm[n] <<
" "
151 << error0 * (pow(StepSize[n] / StepSize[0], order)) << std::endl;
T & get(const std::string &name, T def_value)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
van der Pol model problem for nonlinear electrical circuit.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Solution state for integrators and steppers.