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);
77 stepper->initialize();
81 ParameterList tscPL = pl->sublist(
"Default Integrator")
82 .sublist(
"Time Step Control");
83 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
84 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
85 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
86 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
87 timeStepControl->setInitTimeStep(dt);
88 timeStepControl->initialize();
91 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
92 stepper->getModel()->getNominalValues();
93 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
95 icState->setTime (timeStepControl->getInitTime());
96 icState->setIndex (timeStepControl->getInitIndex());
97 icState->setTimeStep(0.0);
98 icState->setOrder (stepper->getOrder());
109 RCP<Tempus::IntegratorBasic<double> > integrator =
110 Tempus::integratorBasic<double>();
111 integrator->setStepperWStepper(stepper);
112 integrator->setTimeStepControl(timeStepControl);
115 integrator->initialize();
119 bool integratorStatus = integrator->advanceTime();
120 TEST_ASSERT(integratorStatus)
124 double time = integrator->getTime();
125 double timeFinal =pl->sublist(
"Default Integrator")
126 .sublist(
"Time Step Control").get<
double>(
"Final Time");
127 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
130 RCP<Thyra::VectorBase<double> > x = integrator->getX();
133 std::cout <<
" Stepper = " << stepper->description() << std::endl;
134 std::cout <<
" =========================" << std::endl;
135 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
136 << get_ele(*(x ), 1) << std::endl;
137 std::cout <<
" =========================" << std::endl;
138 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
139 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
141 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS
144 #ifdef TEST_VANDERPOL
149 std::vector<std::string> stepperTypes;
150 stepperTypes.push_back(
"Partitioned IMEX RK 1st order");
151 stepperTypes.push_back(
"Partitioned IMEX RK SSP2" );
152 stepperTypes.push_back(
"Partitioned IMEX RK ARS 233" );
153 stepperTypes.push_back(
"General Partitioned IMEX RK" );
155 std::vector<double> stepperOrders;
156 stepperOrders.push_back(1.07964);
157 stepperOrders.push_back(2.00408);
158 stepperOrders.push_back(2.70655);
159 stepperOrders.push_back(2.00211);
161 std::vector<double> stepperErrors;
162 stepperErrors.push_back(0.0046423);
163 stepperErrors.push_back(0.0154534);
164 stepperErrors.push_back(0.000298908);
165 stepperErrors.push_back(0.0071546);
167 std::vector<double> stepperInitDt;
168 stepperInitDt.push_back(0.0125);
169 stepperInitDt.push_back(0.05);
170 stepperInitDt.push_back(0.05);
171 stepperInitDt.push_back(0.05);
173 std::vector<std::string>::size_type m;
174 for(m = 0; m != stepperTypes.size(); m++) {
176 std::string stepperType = stepperTypes[m];
177 std::string stepperName = stepperTypes[m];
178 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
179 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
181 RCP<Tempus::IntegratorBasic<double> > integrator;
182 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
183 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
184 std::vector<double> StepSize;
185 std::vector<double> xErrorNorm;
186 std::vector<double> xDotErrorNorm;
188 const int nTimeStepSizes = 3;
189 double dt = stepperInitDt[m];
191 for (
int n=0; n<nTimeStepSizes; n++) {
194 RCP<ParameterList> pList =
195 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
198 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
199 const bool useProductVector =
true;
208 const int numExplicitBlocks = 1;
209 const int parameterIndex = 4;
212 explicitModel, implicitModel,
213 numExplicitBlocks, parameterIndex));
216 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
218 if (stepperType ==
"General Partitioned IMEX RK"){
220 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
222 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
226 if (n == nTimeStepSizes-1) dt /= 10.0;
230 pl->sublist(
"Default Integrator")
231 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
232 integrator = Tempus::integratorBasic<double>(pl, model);
235 bool integratorStatus = integrator->advanceTime();
236 TEST_ASSERT(integratorStatus)
239 time = integrator->getTime();
240 double timeFinal =pl->sublist(
"Default Integrator")
241 .sublist(
"Time Step Control").get<
double>(
"Final Time");
242 double tol = 100.0 * std::numeric_limits<double>::epsilon();
243 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
246 StepSize.push_back(dt);
247 auto solution = Thyra::createMember(model->get_x_space());
248 Thyra::copy(*(integrator->getX()),solution.ptr());
249 solutions.push_back(solution);
250 auto solutionDot = Thyra::createMember(model->get_x_space());
251 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
252 solutionsDot.push_back(solutionDot);
256 if ((n == 0) or (n == nTimeStepSizes-1)) {
257 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
258 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
260 integrator->getSolutionHistory();
267 double xDotSlope = 0.0;
268 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
272 solutions, xErrorNorm, xSlope,
273 solutionsDot, xDotErrorNorm, xDotSlope);
275 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
276 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
282 Teuchos::TimeMonitor::summarize();
284 #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...