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"
31 using Teuchos::rcp_const_cast;
32 using Teuchos::ParameterList;
33 using Teuchos::sublist;
34 using Teuchos::getParametersFromXmlFile;
48 RCP<ParameterList> pList =
49 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
50 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
53 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
54 const bool useProductVector =
true;
61 const int numExplicitBlocks = 1;
62 const int parameterIndex = 4;
64 explicitModel, implicitModel,
65 numExplicitBlocks, parameterIndex));
70 stepper->setModel(model);
71 stepper->initialize();
75 ParameterList tscPL = pl->sublist(
"Default Integrator")
76 .sublist(
"Time Step Control");
77 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
78 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
79 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
80 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
81 timeStepControl->setInitTimeStep(dt);
82 timeStepControl->initialize();
85 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
86 stepper->getModel()->getNominalValues();
87 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
89 icState->setTime (timeStepControl->getInitTime());
90 icState->setIndex (timeStepControl->getInitIndex());
91 icState->setTimeStep(0.0);
92 icState->setOrder (stepper->getOrder());
97 solutionHistory->setName(
"Forward States");
99 solutionHistory->setStorageLimit(2);
100 solutionHistory->addState(icState);
103 RCP<Tempus::IntegratorBasic<double> > integrator =
104 Tempus::integratorBasic<double>();
105 integrator->setStepperWStepper(stepper);
106 integrator->setTimeStepControl(timeStepControl);
107 integrator->setSolutionHistory(solutionHistory);
109 integrator->initialize();
113 bool integratorStatus = integrator->advanceTime();
114 TEST_ASSERT(integratorStatus)
118 double time = integrator->getTime();
119 double timeFinal =pl->sublist(
"Default Integrator")
120 .sublist(
"Time Step Control").get<
double>(
"Final Time");
121 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
124 RCP<Thyra::VectorBase<double> > x = integrator->getX();
127 std::cout <<
" Stepper = " << stepper->description() << std::endl;
128 std::cout <<
" =========================" << std::endl;
129 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
130 << get_ele(*(x ), 1) << std::endl;
131 std::cout <<
" =========================" << std::endl;
132 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
133 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
141 std::vector<std::string> stepperTypes;
142 stepperTypes.push_back(
"Partitioned IMEX RK 1st order");
143 stepperTypes.push_back(
"Partitioned IMEX RK SSP2" );
144 stepperTypes.push_back(
"Partitioned IMEX RK ARS 233" );
145 stepperTypes.push_back(
"General Partitioned IMEX RK" );
147 std::vector<double> stepperOrders;
148 stepperOrders.push_back(1.07964);
149 stepperOrders.push_back(2.00408);
150 stepperOrders.push_back(2.70655);
151 stepperOrders.push_back(2.00211);
153 std::vector<double> stepperErrors;
154 stepperErrors.push_back(0.0046423);
155 stepperErrors.push_back(0.0154534);
156 stepperErrors.push_back(0.000298908);
157 stepperErrors.push_back(0.0071546);
159 std::vector<double> stepperInitDt;
160 stepperInitDt.push_back(0.0125);
161 stepperInitDt.push_back(0.05);
162 stepperInitDt.push_back(0.05);
163 stepperInitDt.push_back(0.05);
165 std::vector<std::string>::size_type m;
166 for(m = 0; m != stepperTypes.size(); m++) {
168 std::string stepperType = stepperTypes[m];
169 std::string stepperName = stepperTypes[m];
170 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
171 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
173 RCP<Tempus::IntegratorBasic<double> > integrator;
174 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
175 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
176 std::vector<double> StepSize;
177 std::vector<double> xErrorNorm;
178 std::vector<double> xDotErrorNorm;
180 const int nTimeStepSizes = 3;
181 double dt = stepperInitDt[m];
183 for (
int n=0; n<nTimeStepSizes; n++) {
186 RCP<ParameterList> pList =
187 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
190 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
191 const bool useProductVector =
true;
200 const int numExplicitBlocks = 1;
201 const int parameterIndex = 4;
204 explicitModel, implicitModel,
205 numExplicitBlocks, parameterIndex));
208 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
210 if (stepperType ==
"General Partitioned IMEX RK"){
212 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
214 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
218 if (n == nTimeStepSizes-1) dt /= 10.0;
222 pl->sublist(
"Default Integrator")
223 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
224 integrator = Tempus::integratorBasic<double>(pl, model);
227 bool integratorStatus = integrator->advanceTime();
228 TEST_ASSERT(integratorStatus)
231 time = integrator->getTime();
232 double timeFinal =pl->sublist(
"Default Integrator")
233 .sublist(
"Time Step Control").get<
double>(
"Final Time");
234 double tol = 100.0 * std::numeric_limits<double>::epsilon();
235 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
238 StepSize.push_back(dt);
239 auto solution = Thyra::createMember(model->get_x_space());
240 Thyra::copy(*(integrator->getX()),solution.ptr());
241 solutions.push_back(solution);
242 auto solutionDot = Thyra::createMember(model->get_x_space());
243 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
244 solutionsDot.push_back(solutionDot);
248 if ((n == 0) or (n == nTimeStepSizes-1)) {
249 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
250 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
251 RCP<const SolutionHistory<double> > solutionHistory =
252 integrator->getSolutionHistory();
259 double xDotSlope = 0.0;
260 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
264 solutions, xErrorNorm, xSlope,
265 solutionsDot, xDotErrorNorm, xDotSlope);
267 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
268 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
274 Teuchos::TimeMonitor::summarize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
van der Pol model formulated for the partitioned IMEX-RK.
van der Pol model formulated for IMEX.
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > solutionHistory)
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)
@ STORAGE_TYPE_STATIC
Keep a fix number of states.
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x.