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" 29 using Teuchos::ParameterList;
30 using Teuchos::sublist;
31 using Teuchos::getParametersFromXmlFile;
38 #define TEST_CONSTRUCTING_FROM_DEFAULTS 39 #define TEST_VANDERPOL 42 #ifdef TEST_CONSTRUCTING_FROM_DEFAULTS 50 RCP<ParameterList> pList =
51 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
52 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
55 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
56 RCP<VanDerPol_IMEX_ExplicitModel<double> > explicitModel =
60 RCP<VanDerPol_IMEX_ImplicitModel<double> > implicitModel =
64 RCP<Tempus::WrapperModelEvaluatorPairIMEX_Basic<double> > model =
66 explicitModel, implicitModel));
70 RCP<Tempus::StepperIMEX_RK<double> > stepper =
74 RCP<Tempus::TimeStepControl<double> > timeStepControl =
76 ParameterList tscPL = pl->sublist(
"Default Integrator")
77 .sublist(
"Time Step Control");
78 timeStepControl->setStepType (tscPL.get<std::string>(
"Integrator Step Type"));
79 timeStepControl->setInitIndex(tscPL.get<
int> (
"Initial Time Index"));
80 timeStepControl->setInitTime (tscPL.get<
double>(
"Initial Time"));
81 timeStepControl->setFinalTime(tscPL.get<
double>(
"Final Time"));
82 timeStepControl->setInitTimeStep(dt);
83 timeStepControl->initialize();
86 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
87 stepper->getModel()->getNominalValues();
88 RCP<Thyra::VectorBase<double> > icSolution =
89 Teuchos::rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
90 RCP<Tempus::SolutionState<double> > icState =
92 icState->setTime (timeStepControl->getInitTime());
93 icState->setIndex (timeStepControl->getInitIndex());
94 icState->setTimeStep(0.0);
95 icState->setOrder (stepper->getOrder());
107 RCP<Tempus::IntegratorBasic<double> > integrator =
108 Tempus::integratorBasic<double>();
109 integrator->setStepperWStepper(stepper);
110 integrator->setTimeStepControl(timeStepControl);
113 integrator->initialize();
117 bool integratorStatus = integrator->advanceTime();
118 TEST_ASSERT(integratorStatus)
122 double time = integrator->getTime();
123 double timeFinal =pl->sublist(
"Default Integrator")
124 .sublist(
"Time Step Control").get<
double>(
"Final Time");
125 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
128 RCP<Thyra::VectorBase<double> > x = integrator->getX();
131 std::cout <<
" Stepper = " << stepper->description() << std::endl;
132 std::cout <<
" =========================" << std::endl;
133 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" " 134 << get_ele(*(x ), 1) << std::endl;
135 std::cout <<
" =========================" << std::endl;
136 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
137 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
139 #endif // TEST_CONSTRUCTING_FROM_DEFAULTS 142 #ifdef TEST_VANDERPOL 147 std::vector<std::string> stepperTypes;
148 stepperTypes.push_back(
"IMEX RK 1st order");
149 stepperTypes.push_back(
"IMEX RK SSP2" );
150 stepperTypes.push_back(
"IMEX RK ARS 233" );
151 stepperTypes.push_back(
"General IMEX RK" );
153 std::vector<double> stepperOrders;
154 stepperOrders.push_back(1.07964);
155 stepperOrders.push_back(2.00408);
156 stepperOrders.push_back(2.70655);
157 stepperOrders.push_back(2.00211);
159 std::vector<double> stepperErrors;
160 stepperErrors.push_back(0.0046423);
161 stepperErrors.push_back(0.0154534);
162 stepperErrors.push_back(0.000298908);
163 stepperErrors.push_back(0.0071546);
165 std::vector<double> stepperInitDt;
166 stepperInitDt.push_back(0.0125);
167 stepperInitDt.push_back(0.05);
168 stepperInitDt.push_back(0.05);
169 stepperInitDt.push_back(0.05);
171 std::vector<std::string>::size_type m;
172 for(m = 0; m != stepperTypes.size(); m++) {
174 std::string stepperType = stepperTypes[m];
175 std::string stepperName = stepperTypes[m];
176 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
177 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
179 RCP<Tempus::IntegratorBasic<double> > integrator;
180 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
181 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
182 std::vector<double> StepSize;
183 std::vector<double> xErrorNorm;
184 std::vector<double> xDotErrorNorm;
186 const int nTimeStepSizes = 3;
187 double dt = stepperInitDt[m];
189 for (
int n=0; n<nTimeStepSizes; n++) {
192 RCP<ParameterList> pList =
193 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
196 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
197 RCP<VanDerPol_IMEX_ExplicitModel<double> > explicitModel =
201 RCP<VanDerPol_IMEX_ImplicitModel<double> > implicitModel =
205 RCP<Tempus::WrapperModelEvaluatorPairIMEX_Basic<double> > model =
207 explicitModel, implicitModel));
210 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
211 if (stepperType ==
"General IMEX RK"){
213 pl->sublist(
"Default Integrator").set(
"Stepper Name",
"General IMEX RK");
215 pl->sublist(
"Default Stepper").set(
"Stepper Type", stepperType);
219 if (n == nTimeStepSizes-1) dt /= 10.0;
223 pl->sublist(
"Default Integrator")
224 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
225 integrator = Tempus::integratorBasic<double>(pl, model);
228 bool integratorStatus = integrator->advanceTime();
229 TEST_ASSERT(integratorStatus)
232 time = integrator->getTime();
233 double timeFinal =pl->sublist(
"Default Integrator")
234 .sublist(
"Time Step Control").get<
double>(
"Final Time");
235 double tol = 100.0 * std::numeric_limits<double>::epsilon();
236 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
239 StepSize.push_back(dt);
240 auto solution = Thyra::createMember(model->get_x_space());
241 Thyra::copy(*(integrator->getX()),solution.ptr());
242 solutions.push_back(solution);
243 auto solutionDot = Thyra::createMember(model->get_x_space());
244 Thyra::copy(*(integrator->getXdot()),solutionDot.ptr());
245 solutionsDot.push_back(solutionDot);
249 if ((n == 0) or (n == nTimeStepSizes-1)) {
250 std::string fname =
"Tempus_"+stepperName+
"_VanDerPol-Ref.dat";
251 if (n == 0) fname =
"Tempus_"+stepperName+
"_VanDerPol.dat";
253 integrator->getSolutionHistory();
260 double xDotSlope = 0.0;
261 RCP<Tempus::Stepper<double> > stepper = integrator->getStepper();
265 solutions, xErrorNorm, xSlope,
266 solutionsDot, xDotErrorNorm, xDotSlope);
268 TEST_FLOATING_EQUALITY( xSlope, stepperOrders[m], 0.02 );
269 TEST_FLOATING_EQUALITY( xErrorNorm[0], stepperErrors[m], 1.0e-4 );
277 #endif // TEST_VANDERPOL 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...
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...