46 RCP<ParameterList> pList =
47 getParametersFromXmlFile(
"Tempus_Trapezoidal_SinCos.xml");
50 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
53 RCP<ParameterList> tempusPL = sublist(pList,
"Tempus",
true);
57 RCP<Tempus::IntegratorBasic<double>> integrator =
58 Tempus::createIntegratorBasic<double>(tempusPL, model);
60 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Default Stepper",
true);
62 RCP<const ParameterList> defaultPL =
63 integrator->getStepper()->getValidParameters();
64 bool pass = haveSameValuesSorted(*stepperPL, *defaultPL,
true);
67 out <<
"stepperPL -------------- \n"
68 << *stepperPL << std::endl;
69 out <<
"defaultPL -------------- \n"
70 << *defaultPL << std::endl;
77 RCP<Tempus::IntegratorBasic<double>> integrator =
78 Tempus::createIntegratorBasic<double>(
79 model, std::string(
"Trapezoidal Method"));
81 RCP<ParameterList> stepperPL = sublist(tempusPL,
"Default Stepper",
true);
82 RCP<const ParameterList> defaultPL =
83 integrator->getStepper()->getValidParameters();
85 bool pass = haveSameValuesSorted(*stepperPL, *defaultPL,
true);
88 out <<
"stepperPL -------------- \n"
89 << *stepperPL << std::endl;
90 out <<
"defaultPL -------------- \n"
91 << *defaultPL << std::endl;
102 std::vector<std::string> options;
103 options.push_back(
"Default Parameters");
104 options.push_back(
"ICConsistency and Check");
106 for (
const auto& option : options) {
108 RCP<ParameterList> pList =
109 getParametersFromXmlFile(
"Tempus_Trapezoidal_SinCos.xml");
110 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
113 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
132 stepper->setModel(model);
133 if (option ==
"ICConsistency and Check") {
134 stepper->setICConsistency(
"Consistent");
135 stepper->setICConsistencyCheck(
true);
137 stepper->initialize();
141 ParameterList tscPL =
142 pl->sublist(
"Default Integrator").sublist(
"Time Step Control");
143 timeStepControl->setInitIndex(tscPL.get<
int>(
"Initial Time Index"));
144 timeStepControl->setInitTime(tscPL.get<
double>(
"Initial Time"));
145 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
146 timeStepControl->setInitTimeStep(dt);
147 timeStepControl->initialize();
150 auto inArgsIC = model->getNominalValues();
151 auto icSoln = rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x());
153 rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x_dot());
155 icState->setTime(timeStepControl->getInitTime());
156 icState->setIndex(timeStepControl->getInitIndex());
157 icState->setTimeStep(0.0);
158 icState->setOrder(stepper->getOrder());
163 solutionHistory->setName(
"Forward States");
165 solutionHistory->setStorageLimit(2);
166 solutionHistory->addState(icState);
169 RCP<Tempus::IntegratorBasic<double>> integrator =
170 Tempus::createIntegratorBasic<double>();
171 integrator->setStepper(stepper);
172 integrator->setTimeStepControl(timeStepControl);
173 integrator->setSolutionHistory(solutionHistory);
175 integrator->initialize();
178 bool integratorStatus = integrator->advanceTime();
179 TEST_ASSERT(integratorStatus)
182 double time = integrator->getTime();
183 double timeFinal = pl->sublist(
"Default Integrator")
184 .sublist(
"Time Step Control")
185 .get<
double>(
"Final Time");
186 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
189 RCP<Thyra::VectorBase<double>> x = integrator->getX();
190 RCP<const Thyra::VectorBase<double>> x_exact =
191 model->getExactSolution(time).get_x();
194 RCP<Thyra::VectorBase<double>> xdiff = x->clone_v();
195 Thyra::V_StVpStV(xdiff.ptr(), 1.0, *x_exact, -1.0, *(x));
198 out <<
" Stepper = " << stepper->description() <<
"\n with "
199 << option << std::endl;
200 out <<
" =========================" << std::endl;
201 out <<
" Exact solution : " << get_ele(*(x_exact), 0) <<
" "
202 << get_ele(*(x_exact), 1) << std::endl;
203 out <<
" Computed solution: " << get_ele(*(x), 0) <<
" "
204 << get_ele(*(x), 1) << std::endl;
205 out <<
" Difference : " << get_ele(*(xdiff), 0) <<
" "
206 << get_ele(*(xdiff), 1) << std::endl;
207 out <<
" =========================" << std::endl;
208 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 0.841021, 1.0e-4);
209 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.541002, 1.0e-4);
217 RCP<Tempus::IntegratorBasic<double>> integrator;
218 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
219 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
220 std::vector<double> StepSize;
221 std::vector<double> xErrorNorm;
222 std::vector<double> xDotErrorNorm;
223 const int nTimeStepSizes = 7;
226 for (
int n = 0; n < nTimeStepSizes; n++) {
228 RCP<ParameterList> pList =
229 getParametersFromXmlFile(
"Tempus_Trapezoidal_SinCos.xml");
236 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
243 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
244 pl->sublist(
"Default Integrator")
245 .sublist(
"Time Step Control")
246 .set(
"Initial Time Step", dt);
247 integrator = Tempus::createIntegratorBasic<double>(pl, model);
254 RCP<Thyra::VectorBase<double>> x0 =
255 model->getNominalValues().get_x()->clone_v();
256 RCP<Thyra::VectorBase<double>> xdot0 =
257 model->getNominalValues().get_x_dot()->clone_v();
258 integrator->initializeSolutionHistory(0.0, x0, xdot0);
262 bool integratorStatus = integrator->advanceTime();
263 TEST_ASSERT(integratorStatus)
266 time = integrator->getTime();
267 double timeFinal = pl->sublist(
"Default Integrator")
268 .sublist(
"Time Step Control")
269 .get<
double>(
"Final Time");
270 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
274 RCP<const SolutionHistory<double>> solutionHistory =
275 integrator->getSolutionHistory();
276 writeSolution(
"Tempus_Trapezoidal_SinCos.dat", solutionHistory);
279 for (
int i = 0; i < solutionHistory->getNumStates(); i++) {
280 double time_i = (*solutionHistory)[i]->getTime();
283 model->getExactSolution(time_i).get_x()),
285 model->getExactSolution(time_i).get_x_dot()));
286 state->setTime((*solutionHistory)[i]->getTime());
287 solnHistExact->addState(state);
289 writeSolution(
"Tempus_Trapezoidal_SinCos-Ref.dat", solnHistExact);
293 StepSize.push_back(dt);
294 auto solution = Thyra::createMember(model->get_x_space());
295 Thyra::copy(*(integrator->getX()), solution.ptr());
296 solutions.push_back(solution);
297 auto solutionDot = Thyra::createMember(model->get_x_space());
298 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
299 solutionsDot.push_back(solutionDot);
300 if (n == nTimeStepSizes - 1) {
301 StepSize.push_back(0.0);
302 auto solutionExact = Thyra::createMember(model->get_x_space());
303 Thyra::copy(*(model->getExactSolution(time).get_x()),
304 solutionExact.ptr());
305 solutions.push_back(solutionExact);
306 auto solutionDotExact = Thyra::createMember(model->get_x_space());
307 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
308 solutionDotExact.ptr());
309 solutionsDot.push_back(solutionDotExact);
314 double xDotSlope = 0.0;
315 RCP<Tempus::Stepper<double>> stepper = integrator->getStepper();
316 double order = stepper->getOrder();
317 writeOrderError(
"Tempus_Trapezoidal_SinCos-Error.dat", stepper, StepSize,
318 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
321 TEST_FLOATING_EQUALITY(xSlope, order, 0.01);
322 TEST_FLOATING_EQUALITY(xErrorNorm[0], 0.000832086, 1.0e-4);
323 TEST_FLOATING_EQUALITY(xDotSlope, order, 0.01);
324 TEST_FLOATING_EQUALITY(xDotErrorNorm[0], 0.000832086, 1.0e-4);
326 Teuchos::TimeMonitor::summarize();
333 RCP<Tempus::IntegratorBasic<double>> integrator;
334 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
335 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
336 std::vector<double> StepSize;
337 std::vector<double> xErrorNorm;
338 std::vector<double> xDotErrorNorm;
339 const int nTimeStepSizes = 4;
342 for (
int n = 0; n < nTimeStepSizes; n++) {
344 RCP<ParameterList> pList =
345 getParametersFromXmlFile(
"Tempus_Trapezoidal_VanDerPol.xml");
348 RCP<ParameterList> vdpm_pl = sublist(pList,
"VanDerPolModel",
true);
353 if (n == nTimeStepSizes - 1) dt /= 10.0;
356 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
357 pl->sublist(
"Demo Integrator")
358 .sublist(
"Time Step Control")
359 .set(
"Initial Time Step", dt);
360 integrator = Tempus::createIntegratorBasic<double>(pl, model);
363 bool integratorStatus = integrator->advanceTime();
364 TEST_ASSERT(integratorStatus)
367 time = integrator->getTime();
368 double timeFinal = pl->sublist(
"Demo Integrator")
369 .sublist(
"Time Step Control")
370 .get<
double>(
"Final Time");
371 double tol = 100.0 * std::numeric_limits<double>::epsilon();
372 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
375 StepSize.push_back(dt);
376 auto solution = Thyra::createMember(model->get_x_space());
377 Thyra::copy(*(integrator->getX()), solution.ptr());
378 solutions.push_back(solution);
379 auto solutionDot = Thyra::createMember(model->get_x_space());
380 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
381 solutionsDot.push_back(solutionDot);
385 if ((n == 0) || (n == nTimeStepSizes - 1)) {
386 std::string fname =
"Tempus_Trapezoidal_VanDerPol-Ref.dat";
387 if (n == 0) fname =
"Tempus_Trapezoidal_VanDerPol.dat";
388 RCP<const SolutionHistory<double>> solutionHistory =
389 integrator->getSolutionHistory();
395 double xDotSlope = 0.0;
396 RCP<Tempus::Stepper<double>> stepper = integrator->getStepper();
397 double order = stepper->getOrder();
398 writeOrderError(
"Tempus_Trapezoidal_VanDerPol-Error.dat", stepper, StepSize,
399 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
402 TEST_FLOATING_EQUALITY(xSlope, order, 0.10);
403 TEST_FLOATING_EQUALITY(xDotSlope, order, 0.10);
404 TEST_FLOATING_EQUALITY(xErrorNorm[0], 0.00085855, 1.0e-4);
405 TEST_FLOATING_EQUALITY(xDotErrorNorm[0], 0.00120695, 1.0e-4);
407 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)