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;
33 using Teuchos::sublist;
34 using Teuchos::getParametersFromXmlFile;
49 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
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();
77 timeStepControl->setInitIndex(tscPL.
get<
int> (
"Initial Time Index"));
78 timeStepControl->setInitTime (tscPL.
get<
double>(
"Initial Time"));
79 timeStepControl->setFinalTime(tscPL.
get<
double>(
"Final Time"));
80 timeStepControl->setInitTimeStep(dt);
81 timeStepControl->initialize();
84 auto inArgsIC = model->getNominalValues();
87 icState->setTime (timeStepControl->getInitTime());
88 icState->setIndex (timeStepControl->getInitIndex());
89 icState->setTimeStep(0.0);
90 icState->setOrder (stepper->getOrder());
95 solutionHistory->setName(
"Forward States");
97 solutionHistory->setStorageLimit(2);
98 solutionHistory->addState(icState);
102 Tempus::createIntegratorBasic<double>();
103 integrator->setStepper(stepper);
104 integrator->setTimeStepControl(timeStepControl);
105 integrator->setSolutionHistory(solutionHistory);
107 integrator->initialize();
111 bool integratorStatus = integrator->advanceTime();
116 double time = integrator->getTime();
117 double timeFinal =pl->
sublist(
"Default Integrator")
118 .
sublist(
"Time Step Control").
get<
double>(
"Final Time");
125 std::cout <<
" Stepper = " << stepper->description() << std::endl;
126 std::cout <<
" =========================" << std::endl;
127 std::cout <<
" Computed solution: " << get_ele(*(x ), 0) <<
" "
128 << get_ele(*(x ), 1) << std::endl;
129 std::cout <<
" =========================" << std::endl;
130 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 1.810210, 1.0e-4 );
131 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), -0.754602, 1.0e-4 );
139 std::vector<std::string> stepperTypes;
140 stepperTypes.push_back(
"Partitioned IMEX RK 1st order");
141 stepperTypes.push_back(
"Partitioned IMEX RK SSP2" );
142 stepperTypes.push_back(
"Partitioned IMEX RK ARS 233" );
143 stepperTypes.push_back(
"General Partitioned IMEX RK" );
145 std::vector<double> stepperOrders;
146 stepperOrders.push_back(1.07964);
147 stepperOrders.push_back(2.00408);
148 stepperOrders.push_back(2.70655);
149 stepperOrders.push_back(2.00211);
151 std::vector<double> stepperErrors;
152 stepperErrors.push_back(0.0046423);
153 stepperErrors.push_back(0.0154534);
154 stepperErrors.push_back(0.000298908);
155 stepperErrors.push_back(0.0071546);
157 std::vector<double> stepperInitDt;
158 stepperInitDt.push_back(0.0125);
159 stepperInitDt.push_back(0.05);
160 stepperInitDt.push_back(0.05);
161 stepperInitDt.push_back(0.05);
163 std::vector<std::string>::size_type m;
164 for(m = 0; m != stepperTypes.size(); m++) {
166 std::string stepperType = stepperTypes[m];
167 std::string stepperName = stepperTypes[m];
168 std::replace(stepperName.begin(), stepperName.end(),
' ',
'_');
169 std::replace(stepperName.begin(), stepperName.end(),
'/',
'.');
172 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
173 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
174 std::vector<double> StepSize;
175 std::vector<double> xErrorNorm;
176 std::vector<double> xDotErrorNorm;
178 const int nTimeStepSizes = 3;
179 double dt = stepperInitDt[m];
181 for (
int n=0; n<nTimeStepSizes; n++) {
185 getParametersFromXmlFile(
"Tempus_IMEX_RK_VanDerPol.xml");
189 const bool useProductVector =
true;
198 const int numExplicitBlocks = 1;
199 const int parameterIndex = 4;
202 explicitModel, implicitModel,
203 numExplicitBlocks, parameterIndex));
208 if (stepperType ==
"General Partitioned IMEX RK"){
210 pl->
sublist(
"Default Integrator").
set(
"Stepper Name",
"General IMEX RK");
212 pl->
sublist(
"Default Stepper").
set(
"Stepper Type", stepperType);
216 if (n == nTimeStepSizes-1) dt /= 10.0;
220 pl->
sublist(
"Default Integrator")
221 .
sublist(
"Time Step Control").
set(
"Initial Time Step", dt);
222 integrator = Tempus::createIntegratorBasic<double>(pl, model);
225 bool integratorStatus = integrator->advanceTime();
229 time = integrator->getTime();
230 double timeFinal =pl->sublist(
"Default Integrator")
231 .sublist(
"Time Step Control").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 solutions, xErrorNorm, xSlope,
263 solutionsDot, xDotErrorNorm, xDotSlope);
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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
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)
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. SolutionState contains the metadata for solutions and th...