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_WrapperModelEvaluatorPairIMEX_Basic.hpp"
17 #include "Tempus_StepperIMEX_RK.hpp"
19 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
20 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
26 namespace Tempus_Test {
30 using Teuchos::rcp_const_cast;
31 using Teuchos::ParameterList;
32 using Teuchos::sublist;
33 using Teuchos::getParametersFromXmlFile;
47 RCP<ParameterList> pList =
48 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
49 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
52 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
60 explicitModel, implicitModel));
65 stepper->setModel(model);
66 stepper->initialize();
70 ParameterList tscPL = pl->sublist(
"Default Integrator")
71 .sublist(
"Time Step Control");
72 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
73 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
74 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
75 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
76 timeStepControl->setInitTimeStep(dt);
77 timeStepControl->initialize();
80 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
81 stepper->getModel()->getNominalValues();
82 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
84 icState->setTime (timeStepControl->getInitTime());
85 icState->setIndex (timeStepControl->getInitIndex());
86 icState->setTimeStep(0.0);
87 icState->setOrder (stepper->getOrder());
92 solutionHistory->setName(
"Forward States");
94 solutionHistory->setStorageLimit(2);
95 solutionHistory->addState(icState);
98 RCP<Tempus::IntegratorBasic<double> > integrator =
99 Tempus::integratorBasic<double>();
100 integrator->setStepperWStepper(stepper);
101 integrator->setTimeStepControl(timeStepControl);
102 integrator->setSolutionHistory(solutionHistory);
103 integrator->initialize();
107 bool integratorStatus = integrator->advanceTime();
108 TEST_ASSERT(integratorStatus)
112 double time = integrator->getTime();
113 double timeFinal =pl->sublist(
"Default Integrator")
114 .sublist(
"Time Step Control").get<
double>(
"Final Time");
115 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
118 RCP<Thyra::VectorBase<double> > x = integrator->getX();
121 std::cout <<
" Stepper = " << stepper->description() << std::endl;
122 std::cout <<
" =========================" << std::endl;
123 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
124 << get_ele(*(x ), 1) << std::endl;
125 std::cout <<
" =========================" << std::endl;
126 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
127 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
135 std::vector<std::string> stepperTypes;
136 stepperTypes.push_back(
"IMEX RK 1st order");
137 stepperTypes.push_back(
"SSP1_111" );
138 stepperTypes.push_back(
"IMEX RK SSP2" );
139 stepperTypes.push_back(
"SSP2_222" );
140 stepperTypes.push_back(
"IMEX RK ARS 233" );
141 stepperTypes.push_back(
"General IMEX RK" );
142 stepperTypes.push_back(
"IMEX RK SSP3" );
144 std::vector<double> stepperOrders;
145 stepperOrders.push_back(1.07964);
146 stepperOrders.push_back(1.07964);
147 stepperOrders.push_back(2.00408);
148 stepperOrders.push_back(2.76941);
149 stepperOrders.push_back(2.70655);
150 stepperOrders.push_back(2.00211);
151 stepperOrders.push_back(2.00211);
153 std::vector<double> stepperErrors;
154 stepperErrors.push_back(0.0046423);
155 stepperErrors.push_back(0.103569);
156 stepperErrors.push_back(0.0154534);
157 stepperErrors.push_back(0.000533759);
158 stepperErrors.push_back(0.000298908);
159 stepperErrors.push_back(0.0071546);
160 stepperErrors.push_back(0.0151202);
162 std::vector<double> stepperInitDt;
163 stepperInitDt.push_back(0.0125);
164 stepperInitDt.push_back(0.0125);
165 stepperInitDt.push_back(0.05);
166 stepperInitDt.push_back(0.05);
167 stepperInitDt.push_back(0.05);
168 stepperInitDt.push_back(0.05);
169 stepperInitDt.push_back(0.05);
171 TEUCHOS_ASSERT( stepperTypes.size() == stepperOrders.size() );
172 TEUCHOS_ASSERT( stepperTypes.size() == stepperErrors.size() );
173 TEUCHOS_ASSERT( stepperTypes.size() == stepperInitDt.size() );
175 std::vector<std::string>::size_type m;
176 for(m = 0; m != stepperTypes.size(); m++) {
178 std::string stepperType = stepperTypes[m];
179 std::string stepperName = stepperTypes[m];
180 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
181 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
183 RCP<Tempus::IntegratorBasic<double> > integrator;
184 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
185 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
186 std::vector<double> StepSize;
187 std::vector<double> xErrorNorm;
188 std::vector<double> xDotErrorNorm;
190 const int nTimeStepSizes = 3;
191 double dt = stepperInitDt[m];
193 for (
int n=0; n<nTimeStepSizes; n++) {
196 RCP<ParameterList> pList =
197 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
200 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
208 explicitModel, implicitModel));
211 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
212 if (stepperType ==
"General IMEX RK"){
214 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
216 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
220 if (n == nTimeStepSizes-1) dt /= 10.0;
224 pl->sublist(
"Default Integrator")
225 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
226 integrator = Tempus::integratorBasic<double>(pl, model);
229 bool integratorStatus = integrator->advanceTime();
230 TEST_ASSERT(integratorStatus)
233 time = integrator->getTime();
234 double timeFinal =pl->sublist(
"Default Integrator")
235 .sublist(
"Time Step Control").get<
double>(
"Final Time");
236 double tol = 100.0 * std::numeric_limits<double>::epsilon();
237 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
240 StepSize.push_back(dt);
241 auto solution = Thyra::createMember(model->get_x_space());
242 Thyra::copy(*(integrator->getX()),solution.ptr());
243 solutions.push_back(solution);
244 auto solutionDot = Thyra::createMember(model->get_x_space());
245 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
246 solutionsDot.push_back(solutionDot);
250 if ((n == 0) or (n == nTimeStepSizes-1)) {
251 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
252 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
253 RCP<const SolutionHistory<double> > solutionHistory =
254 integrator->getSolutionHistory();
261 double xDotSlope = 0.0;
262 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
266 solutions, xErrorNorm, xSlope,
267 solutionsDot, xDotErrorNorm, xDotSlope);
269 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
270 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
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.
van der Pol model formulated for IMEX-RK.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
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)
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
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...