49 RCP<ParameterList> pList =
50 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
51 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
54 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
55 RCP<const Thyra::ModelEvaluator<double>> explicitModel =
59 RCP<const Thyra::ModelEvaluator<double>> implicitModel =
70 stepper->addStepper(subStepper1);
71 stepper->addStepper(subStepper2);
72 stepper->initialize();
77 pl->sublist(
"Demo Integrator").sublist(
"Time Step Control");
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();
86 auto icX = rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x());
87 auto icXDot = rcp_const_cast<Thyra::VectorBase<double>>(inArgsIC.get_x_dot());
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);
103 RCP<Tempus::IntegratorBasic<double>> integrator =
104 Tempus::createIntegratorBasic<double>();
105 integrator->setStepper(stepper);
106 integrator->setTimeStepControl(timeStepControl);
107 integrator->setSolutionHistory(solutionHistory);
109 integrator->initialize();
112 bool integratorStatus = integrator->advanceTime();
113 TEST_ASSERT(integratorStatus)
116 double time = integrator->getTime();
117 double timeFinal = pl->sublist(
"Demo Integrator")
118 .sublist(
"Time Step Control")
119 .get<
double>(
"Final Time");
120 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
123 RCP<Thyra::VectorBase<double>> x = integrator->getX();
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);
139 RCP<Tempus::IntegratorBasic<double>> integrator;
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++) {
150 RCP<ParameterList> pList =
151 getParametersFromXmlFile(
"Tempus_OperatorSplit_VanDerPol.xml");
154 RCP<ParameterList> vdpmPL = sublist(pList,
"VanDerPolModel",
true);
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;
170 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
171 pl->sublist(
"Demo Integrator")
172 .sublist(
"Time Step Control")
173 .set(
"Initial Time Step", dt);
174 integrator = Tempus::createIntegratorBasic<double>(pl, models);
177 bool integratorStatus = integrator->advanceTime();
178 TEST_ASSERT(integratorStatus)
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();
186 TEST_FLOATING_EQUALITY(time, timeFinal, tol);
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";
202 RCP<const SolutionHistory<double>> solutionHistory =
203 integrator->getSolutionHistory();
211 double xDotSlope = 0.0;
212 RCP<Tempus::Stepper<double>> stepper = integrator->getStepper();
213 double order = stepper->getOrder();
214 writeOrderError(
"Tempus_OperatorSplit_VanDerPol-Error.dat", stepper, StepSize,
215 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
218 TEST_FLOATING_EQUALITY(xSlope, order, 0.05);
219 TEST_FLOATING_EQUALITY(xDotSlope, order, 0.05);
220 TEST_FLOATING_EQUALITY(xErrorNorm[0], 1.27294, 1.0e-4);
221 TEST_FLOATING_EQUALITY(xDotErrorNorm[0], 12.7102, 1.0e-4);
223 Teuchos::TimeMonitor::summarize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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)
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.