14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperFactory.hpp"
18 #include "Tempus_StepperOperatorSplit.hpp"
19 #include "Tempus_StepperForwardEuler.hpp"
20 #include "Tempus_StepperBackwardEuler.hpp"
22 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
23 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
24 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
29 namespace Tempus_Test {
31 using Teuchos::getParametersFromXmlFile;
35 using Teuchos::rcp_const_cast;
36 using Teuchos::sublist;
50 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
70 stepper->addStepper(subStepper1);
71 stepper->addStepper(subStepper2);
72 stepper->initialize();
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 auto inArgsIC = stepper->getModel()->getNominalValues();
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);
104 Tempus::createIntegratorBasic<double>();
105 integrator->setStepper(stepper);
106 integrator->setTimeStepControl(timeStepControl);
107 integrator->setSolutionHistory(solutionHistory);
109 integrator->initialize();
112 bool integratorStatus = integrator->advanceTime();
116 double time = integrator->getTime();
117 double timeFinal = pl->
sublist(
"Demo Integrator")
119 .
get<
double>(
"Final Time");
126 out <<
" Stepper = " << stepper->description() << std::endl;
127 out <<
" =========================" << std::endl;
128 out <<
" Computed solution: " << get_ele(*(x), 0) <<
" "
129 << get_ele(*(x), 1) << std::endl;
130 out <<
" =========================" << std::endl;
131 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), -2.223910, 1.0e-4);
132 TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.565441, 1.0e-4);
140 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
141 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
142 std::vector<double> StepSize;
143 std::vector<double> xErrorNorm;
144 std::vector<double> xDotErrorNorm;
145 const int nTimeStepSizes = 4;
148 for (
int n = 0; n < nTimeStepSizes; n++) {
151 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
161 std::vector<RCP<const Thyra::ModelEvaluator<double>>> models;
162 models.push_back(explicitModel);
163 models.push_back(implicitModel);
167 if (n == nTimeStepSizes - 1) dt /= 10.0;
173 .
set(
"Initial Time Step", dt);
174 integrator = Tempus::createIntegratorBasic<double>(pl, models);
177 bool integratorStatus = integrator->advanceTime();
181 time = integrator->getTime();
182 double timeFinal = pl->sublist(
"Demo Integrator")
183 .sublist(
"Time Step Control")
184 .
get<
double>(
"Final Time");
185 double tol = 100.0 * std::numeric_limits<double>::epsilon();
189 StepSize.push_back(dt);
190 auto solution = Thyra::createMember(implicitModel->get_x_space());
191 Thyra::copy(*(integrator->getX()), solution.ptr());
192 solutions.push_back(solution);
193 auto solutionDot = Thyra::createMember(implicitModel->get_x_space());
194 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
195 solutionsDot.push_back(solutionDot);
199 if ((n == 0) || (n == nTimeStepSizes - 1)) {
200 std::string fname =
"Tempus_OperatorSplit_VanDerPol-Ref.dat";
201 if (n == 0) fname =
"Tempus_OperatorSplit_VanDerPol.dat";
203 integrator->getSolutionHistory();
211 double xDotSlope = 0.0;
213 double order = stepper->getOrder();
214 writeOrderError(
"Tempus_OperatorSplit_VanDerPol-Error.dat", stepper, StepSize,
215 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
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.
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)
OperatorSplit stepper loops through the Stepper list.
Teuchos::RCP< StepperForwardEuler< Scalar > > createStepperForwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
Teuchos::RCP< StepperBackwardEuler< Scalar > > createStepperBackwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
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.