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_WrapperModelEvaluatorPairPartIMEX_Basic.hpp"
17 #include "Tempus_StepperIMEX_RK_Partition.hpp"
20 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
21 #include "../TestModels/VanDerPol_IMEXPart_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_IMEX_RK_VanDerPol.xml");
55 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
58 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
59 const bool useProductVector =
true;
66 const int numExplicitBlocks = 1;
67 const int parameterIndex = 4;
69 explicitModel, implicitModel,
70 numExplicitBlocks, parameterIndex));
75 stepper->setModel(model);
76 stepper->initialize();
80 ParameterList tscPL = pl->sublist(
"Default Integrator")
81 .sublist(
"Time Step Control");
82 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
83 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
84 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
85 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
86 timeStepControl->setInitTimeStep(dt);
87 timeStepControl->initialize();
90 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
91 stepper->getModel()->getNominalValues();
92 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
94 icState->setTime (timeStepControl->getInitTime());
95 icState->setIndex (timeStepControl->getInitIndex());
96 icState->setTimeStep(0.0);
97 icState->setOrder (stepper->getOrder());
108 RCP<Tempus::IntegratorBasic<double> > integrator =
109 Tempus::integratorBasic<double>();
110 integrator->setStepperWStepper(stepper);
111 integrator->setTimeStepControl(timeStepControl);
114 integrator->initialize();
118 bool integratorStatus = integrator->advanceTime();
119 TEST_ASSERT(integratorStatus)
123 double time = integrator->getTime();
124 double timeFinal =pl->sublist(
"Default Integrator")
125 .sublist(
"Time Step Control").get<
double>(
"Final Time");
126 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
129 RCP<Thyra::VectorBase<double> > x = integrator->getX();
132 std::cout <<
" Stepper = " << stepper->description() << std::endl;
133 std::cout <<
" =========================" << std::endl;
134 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
135 << get_ele(*(x ), 1) << std::endl;
136 std::cout <<
" =========================" << std::endl;
137 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
138 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
140 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
143 #ifdef TEST_VANDERPOL
148 std::vector<std::string> stepperTypes;
149 stepperTypes.push_back(
"Partitioned IMEX RK 1st order");
150 stepperTypes.push_back(
"Partitioned IMEX RK SSP2" );
151 stepperTypes.push_back(
"Partitioned IMEX RK ARS 233" );
152 stepperTypes.push_back(
"General Partitioned IMEX RK" );
154 std::vector<double> stepperOrders;
155 stepperOrders.push_back(1.07964);
156 stepperOrders.push_back(2.00408);
157 stepperOrders.push_back(2.70655);
158 stepperOrders.push_back(2.00211);
160 std::vector<double> stepperErrors;
161 stepperErrors.push_back(0.0046423);
162 stepperErrors.push_back(0.0154534);
163 stepperErrors.push_back(0.000298908);
164 stepperErrors.push_back(0.0071546);
166 std::vector<double> stepperInitDt;
167 stepperInitDt.push_back(0.0125);
168 stepperInitDt.push_back(0.05);
169 stepperInitDt.push_back(0.05);
170 stepperInitDt.push_back(0.05);
172 std::vector<std::string>::size_type m;
173 for(m = 0; m != stepperTypes.size(); m++) {
175 std::string stepperType = stepperTypes[m];
176 std::string stepperName = stepperTypes[m];
177 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
178 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
180 RCP<Tempus::IntegratorBasic<double> > integrator;
181 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
182 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
183 std::vector<double> StepSize;
184 std::vector<double> xErrorNorm;
185 std::vector<double> xDotErrorNorm;
187 const int nTimeStepSizes = 3;
188 double dt = stepperInitDt[m];
190 for (
int n=0; n<nTimeStepSizes; n++) {
193 RCP<ParameterList> pList =
194 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
197 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
198 const bool useProductVector =
true;
207 const int numExplicitBlocks = 1;
208 const int parameterIndex = 4;
211 explicitModel, implicitModel,
212 numExplicitBlocks, parameterIndex));
215 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
217 if (stepperType ==
"General Partitioned IMEX RK"){
219 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
221 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
225 if (n == nTimeStepSizes-1) dt /= 10.0;
229 pl->sublist(
"Default Integrator")
230 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
231 integrator = Tempus::integratorBasic<double>(pl, model);
234 bool integratorStatus = integrator->advanceTime();
235 TEST_ASSERT(integratorStatus)
238 time = integrator->getTime();
239 double timeFinal =pl->sublist(
"Default Integrator")
240 .sublist(
"Time Step Control").get<
double>(
"Final Time");
241 double tol = 100.0 * std::numeric_limits<double>::epsilon();
242 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
245 StepSize.push_back(dt);
246 auto solution = Thyra::createMember(model->get_x_space());
247 Thyra::copy(*(integrator->getX()),solution.ptr());
248 solutions.push_back(solution);
249 auto solutionDot = Thyra::createMember(model->get_x_space());
250 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
251 solutionsDot.push_back(solutionDot);
255 if ((n == 0) or (n == nTimeStepSizes-1)) {
256 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
257 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
259 integrator->getSolutionHistory();
266 double xDotSlope = 0.0;
267 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
271 solutions, xErrorNorm, xSlope,
272 solutionsDot, xDotErrorNorm, xDotSlope);
274 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
275 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
281 Teuchos::TimeMonitor::summarize();
283 #endif // TEST_VANDERPOL
van der Pol model formulated for the partitioned IMEX-RK.
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > solutionHistory)
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
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)
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
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...