14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_WrapperModelEvaluatorPairPartIMEX_Basic.hpp"
18 #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 {
29 using Teuchos::getParametersFromXmlFile;
33 using Teuchos::rcp_const_cast;
34 using Teuchos::sublist;
48 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
53 const bool useProductVector =
true;
62 const int numExplicitBlocks = 1;
63 const int parameterIndex = 4;
65 explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
69 stepper->setModel(model);
70 stepper->initialize();
76 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
77 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
78 timeStepControl->setFinalTime(tscPL.
get<
double>(
"Final Time"));
79 timeStepControl->setInitTimeStep(dt);
80 timeStepControl->initialize();
83 auto inArgsIC = model->getNominalValues();
86 icState->setTime(timeStepControl->getInitTime());
87 icState->setIndex(timeStepControl->getInitIndex());
88 icState->setTimeStep(0.0);
89 icState->setOrder(stepper->getOrder());
94 solutionHistory->setName(
"Forward States");
96 solutionHistory->setStorageLimit(2);
97 solutionHistory->addState(icState);
101 Tempus::createIntegratorBasic<double>();
102 integrator->setStepper(stepper);
103 integrator->setTimeStepControl(timeStepControl);
104 integrator->setSolutionHistory(solutionHistory);
106 integrator->initialize();
109 bool integratorStatus = integrator->advanceTime();
113 double time = integrator->getTime();
114 double timeFinal = pl->
sublist(
"Default Integrator")
116 .
get<
double>(
"Final Time");
123 out <<
" Stepper = " << stepper->description() << std::endl;
124 out <<
" =========================" << std::endl;
125 out <<
" Computed solution: " << get_ele(*(x), 0) <<
" "
126 << get_ele(*(x), 1) << std::endl;
127 out <<
" =========================" << std::endl;
128 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4);
129 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4);
136 std::vector<std::string> stepperTypes;
137 stepperTypes.push_back(
"Partitioned IMEX RK 1st order");
138 stepperTypes.push_back(
"Partitioned IMEX RK SSP2");
139 stepperTypes.push_back(
"Partitioned IMEX RK ARS 233");
140 stepperTypes.push_back(
"General Partitioned IMEX RK");
142 std::vector<double> stepperOrders;
143 stepperOrders.push_back(1.07964);
144 stepperOrders.push_back(2.00408);
145 stepperOrders.push_back(2.70655);
146 stepperOrders.push_back(2.00211);
148 std::vector<double> stepperErrors;
149 stepperErrors.push_back(0.0046423);
150 stepperErrors.push_back(0.0154534);
151 stepperErrors.push_back(0.000298908);
152 stepperErrors.push_back(0.0071546);
154 std::vector<double> stepperInitDt;
155 stepperInitDt.push_back(0.0125);
156 stepperInitDt.push_back(0.05);
157 stepperInitDt.push_back(0.05);
158 stepperInitDt.push_back(0.05);
160 std::vector<std::string>::size_type m;
161 for (m = 0; m != stepperTypes.size(); m++) {
162 std::string stepperType = stepperTypes[m];
163 std::string stepperName = stepperTypes[m];
164 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
165 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
168 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
169 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
170 std::vector<double> StepSize;
171 std::vector<double> xErrorNorm;
172 std::vector<double> xDotErrorNorm;
174 const int nTimeStepSizes = 3;
175 double dt = stepperInitDt[m];
177 for (
int n = 0; n < nTimeStepSizes; n++) {
180 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
184 const bool useProductVector =
true;
185 auto explicitModel =
rcp(
193 const int numExplicitBlocks = 1;
194 const int parameterIndex = 4;
197 explicitModel, implicitModel, numExplicitBlocks, parameterIndex));
202 if (stepperType ==
"General Partitioned IMEX RK") {
204 pl->
sublist(
"Default Integrator")
205 .
set(
"Stepper Name",
"General IMEX RK");
208 pl->
sublist(
"Default Stepper").
set(
"Stepper Type", stepperType);
212 if (n == nTimeStepSizes - 1)
218 pl->
sublist(
"Default Integrator")
220 .
set(
"Initial Time Step", dt);
221 integrator = Tempus::createIntegratorBasic<double>(pl, model);
224 bool integratorStatus = integrator->advanceTime();
228 time = integrator->getTime();
229 double timeFinal = pl->sublist(
"Default Integrator")
230 .sublist(
"Time Step Control")
231 .get<
double>(
"Final Time");
232 double tol = 100.0 * std::numeric_limits<double>::epsilon();
236 StepSize.push_back(dt);
237 auto solution = Thyra::createMember(model->get_x_space());
238 Thyra::copy(*(integrator->getX()), solution.ptr());
239 solutions.push_back(solution);
240 auto solutionDot = Thyra::createMember(model->get_x_space());
241 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
242 solutionsDot.push_back(solutionDot);
246 if ((n == 0) || (n == nTimeStepSizes - 1)) {
247 std::string fname =
"Tempus_" + stepperName +
"_VanDerPol-Ref.dat";
248 if (n == 0) fname =
"Tempus_" + stepperName +
"_VanDerPol.dat";
250 integrator->getSolutionHistory();
257 double xDotSlope = 0.0;
262 solutionsDot.clear();
264 writeOrderError(
"Tempus_" + stepperName +
"_VanDerPol-Error.dat", stepper,
265 StepSize, solutions, xErrorNorm, xSlope, solutionsDot,
266 xDotErrorNorm, xDotSlope, out);
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 the partitioned IMEX-RK.
T & get(const std::string &name, T def_value)
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::FancyOStream &out)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
void writeSolution(const std::string filename, Teuchos::RCP< const Tempus::SolutionHistory< Scalar >> solutionHistory)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
van der Pol model formulated for IMEX.
Solution state for integrators and steppers.