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"
17 #include "Tempus_StepperOperatorSplit.hpp"
18 #include "Tempus_StepperForwardEuler.hpp"
19 #include "Tempus_StepperBackwardEuler.hpp"
21 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
22 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
23 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
28 namespace Tempus_Test {
32 using Teuchos::rcp_const_cast;
33 using Teuchos::ParameterList;
34 using Teuchos::sublist;
35 using Teuchos::getParametersFromXmlFile;
42 #define TEST_CONSTRUCTING_FROM_DEFAULTS
43 #define TEST_VANDERPOL
46 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS
54 RCP<ParameterList> pList =
55 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
56 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
59 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
69 RCP<Tempus::StepperFactory<double> > sf =
73 sf->createStepperForwardEuler(explicitModel, Teuchos::null);
76 sf->createStepperBackwardEuler(implicitModel, Teuchos::null);
78 stepper->addStepper(subStepper1);
79 stepper->addStepper(subStepper2);
80 stepper->initialize();
85 ParameterList tscPL = pl->sublist(
"Demo Integrator")
86 .sublist(
"Time Step Control");
87 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
88 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
89 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
90 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
91 timeStepControl->setInitTimeStep(dt);
92 timeStepControl->initialize();
95 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
96 stepper->getModel()->getNominalValues();
97 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
98 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
100 icState->setTime (timeStepControl->getInitTime());
101 icState->setIndex (timeStepControl->getInitIndex());
102 icState->setTimeStep(0.0);
103 icState->setOrder (stepper->getOrder());
114 RCP<Tempus::IntegratorBasic<double> > integrator =
115 Tempus::integratorBasic<double>();
116 integrator->setStepperWStepper(stepper);
117 integrator->setTimeStepControl(timeStepControl);
120 integrator->initialize();
124 bool integratorStatus = integrator->advanceTime();
125 TEST_ASSERT(integratorStatus)
129 double time = integrator->getTime();
130 double timeFinal =pl->sublist(
"Demo Integrator")
131 .sublist(
"Time Step Control").get<
double>(
"Final Time");
132 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
135 RCP<Thyra::VectorBase<double> > x = integrator->getX();
138 std::cout <<
" Stepper = " << stepper->description() << std::endl;
139 std::cout <<
" =========================" << std::endl;
140 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
141 << get_ele(*(x ), 1) << std::endl;
142 std::cout <<
" =========================" << std::endl;
143 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), -2.223910, 1.0e-4);
144 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.565441, 1.0e-4);
146 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
149 #ifdef TEST_VANDERPOL
154 RCP<Tempus::IntegratorBasic<double> > integrator;
155 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
156 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
157 std::vector<double> StepSize;
158 std::vector<double> xErrorNorm;
159 std::vector<double> xDotErrorNorm;
160 const int nTimeStepSizes = 4;
163 for (
int n=0; n<nTimeStepSizes; n++) {
166 RCP<ParameterList> pList =
167 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
170 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
177 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
178 models.push_back(explicitModel);
179 models.push_back(implicitModel);
183 if (n == nTimeStepSizes-1) dt /= 10.0;
186 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
187 pl->sublist(
"Demo Integrator")
188 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
189 integrator = Tempus::integratorBasic<double>(pl, models);
192 bool integratorStatus = integrator->advanceTime();
193 TEST_ASSERT(integratorStatus)
196 time = integrator->getTime();
197 double timeFinal =pl->sublist(
"Demo Integrator")
198 .sublist(
"Time Step Control").get<
double>(
"Final Time");
199 double tol = 100.0 * std::numeric_limits<double>::epsilon();
200 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
203 StepSize.push_back(dt);
204 auto solution = Thyra::createMember(implicitModel->get_x_space());
205 Thyra::copy(*(integrator->getX()),solution.ptr());
206 solutions.push_back(solution);
207 auto solutionDot = Thyra::createMember(implicitModel->get_x_space());
208 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
209 solutionsDot.push_back(solutionDot);
213 if ((n == 0) or (n == nTimeStepSizes-1)) {
214 std::string fname =
"Tempus_OperatorSplit_VanDerPol-Ref.dat";
215 if (n == 0) fname =
"Tempus_OperatorSplit_VanDerPol.dat";
217 integrator->getSolutionHistory();
225 double xDotSlope = 0.0;
226 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
227 double order = stepper->getOrder();
230 solutions, xErrorNorm, xSlope,
231 solutionsDot, xDotErrorNorm, xDotSlope);
233 TEST_FLOATING_EQUALITY( xSlope, order, 0.05 );
234 TEST_FLOATING_EQUALITY( xDotSlope, order, 0.05 );
235 TEST_FLOATING_EQUALITY( xErrorNorm[0], 1.27294, 1.0e-4 );
236 TEST_FLOATING_EQUALITY( xDotErrorNorm[0], 12.7102, 1.0e-4 );
238 Teuchos::TimeMonitor::summarize();
240 #endif // TEST_VANDERPOL
van der Pol model formulated for IMEX-RK.
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.
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...