9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
13 #include "Thyra_VectorStdOps.hpp"
15 #include "Tempus_IntegratorBasic.hpp"
16 #include "Tempus_StepperOperatorSplit.hpp"
17 #include "Tempus_StepperForwardEuler.hpp"
18 #include "Tempus_StepperBackwardEuler.hpp"
20 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
21 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
22 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
27 namespace Tempus_Test {
31 using Teuchos::rcp_const_cast;
32 using Teuchos::ParameterList;
33 using Teuchos::sublist;
34 using Teuchos::getParametersFromXmlFile;
41 #define TEST_CONSTRUCTING_FROM_DEFAULTS
42 #define TEST_VANDERPOL
45 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS
53 RCP<ParameterList> pList =
54 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
55 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
58 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
71 stepper->addStepper(subStepper1);
72 stepper->addStepper(subStepper2);
73 stepper->initialize();
78 ParameterList tscPL = pl->sublist(
"Demo Integrator")
79 .sublist(
"Time Step Control");
80 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
81 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
82 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
83 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
84 timeStepControl->setInitTimeStep(dt);
85 timeStepControl->initialize();
88 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
89 stepper->getModel()->getNominalValues();
90 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
92 icState->setTime (timeStepControl->getInitTime());
93 icState->setIndex (timeStepControl->getInitIndex());
94 icState->setTimeStep(0.0);
95 icState->setOrder (stepper->getOrder());
106 RCP<Tempus::IntegratorBasic<double> > integrator =
107 Tempus::integratorBasic<double>();
108 integrator->setStepperWStepper(stepper);
109 integrator->setTimeStepControl(timeStepControl);
112 integrator->initialize();
116 bool integratorStatus = integrator->advanceTime();
117 TEST_ASSERT(integratorStatus)
121 double time = integrator->getTime();
122 double timeFinal =pl->sublist(
"Demo Integrator")
123 .sublist(
"Time Step Control").get<
double>(
"Final Time");
124 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
127 RCP<Thyra::VectorBase<double> > x = integrator->getX();
130 std::cout <<
" Stepper = " << stepper->description() << std::endl;
131 std::cout <<
" =========================" << std::endl;
132 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
133 << get_ele(*(x ), 1) << std::endl;
134 std::cout <<
" =========================" << std::endl;
135 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), -2.223910, 1.0e-4);
136 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.565441, 1.0e-4);
138 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
141 #ifdef TEST_VANDERPOL
146 RCP<Tempus::IntegratorBasic<double> > integrator;
147 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
148 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
149 std::vector<double> StepSize;
150 std::vector<double> xErrorNorm;
151 std::vector<double> xDotErrorNorm;
152 const int nTimeStepSizes = 4;
155 for (
int n=0; n<nTimeStepSizes; n++) {
158 RCP<ParameterList> pList =
159 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
162 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
169 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
170 models.push_back(explicitModel);
171 models.push_back(implicitModel);
175 if (n == nTimeStepSizes-1) dt /= 10.0;
178 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
179 pl->sublist(
"Demo Integrator")
180 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
181 integrator = Tempus::integratorBasic<double>(pl, models);
184 bool integratorStatus = integrator->advanceTime();
185 TEST_ASSERT(integratorStatus)
188 time = integrator->getTime();
189 double timeFinal =pl->sublist(
"Demo Integrator")
190 .sublist(
"Time Step Control").get<
double>(
"Final Time");
191 double tol = 100.0 * std::numeric_limits<double>::epsilon();
192 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
195 StepSize.push_back(dt);
196 auto solution = Thyra::createMember(implicitModel->get_x_space());
197 Thyra::copy(*(integrator->getX()),solution.ptr());
198 solutions.push_back(solution);
199 auto solutionDot = Thyra::createMember(implicitModel->get_x_space());
200 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
201 solutionsDot.push_back(solutionDot);
205 if ((n == 0) or (n == nTimeStepSizes-1)) {
206 std::string fname =
"Tempus_OperatorSplit_VanDerPol-Ref.dat";
207 if (n == 0) fname =
"Tempus_OperatorSplit_VanDerPol.dat";
209 integrator->getSolutionHistory();
217 double xDotSlope = 0.0;
218 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
219 double order = stepper->getOrder();
222 solutions, xErrorNorm, xSlope,
223 solutionsDot, xDotErrorNorm, xDotSlope);
225 TEST_FLOATING_EQUALITY( xSlope, order, 0.05 );
226 TEST_FLOATING_EQUALITY( xDotSlope, order, 0.05 );
227 TEST_FLOATING_EQUALITY( xErrorNorm[0], 1.27294, 1.0e-4 );
228 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 12.7102, 1.0e-4 );
230 Teuchos::TimeMonitor::summarize();
232 #endif // TEST_VANDERPOL
van der Pol model formulated for IMEX-RK.
Forward Euler time stepper.
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > solutionHistory)
OperatorSplit stepper loops through the Stepper list.
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.
Backward Euler time stepper.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
van der Pol model formulated for IMEX.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...