13 #include "Teuchos_DefaultComm.hpp"
15 #include "Tempus_config.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperBackwardEuler.hpp"
19 #include "../TestModels/SinCosModel.hpp"
20 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
27 namespace Tempus_Test {
29 using Teuchos::getParametersFromXmlFile;
33 using Teuchos::rcp_const_cast;
34 using Teuchos::sublist;
45 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
46 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
47 std::vector<double> StepSize;
48 std::vector<double> xErrorNorm;
49 std::vector<double> xDotErrorNorm;
50 const int nTimeStepSizes = 7;
53 for (
int n = 0; n < nTimeStepSizes; n++) {
56 getParametersFromXmlFile(
"Tempus_BackwardEuler_SinCos.xml");
71 pl->
sublist(
"Default Integrator")
73 .
set(
"Initial Time Step", dt);
74 integrator = Tempus::createIntegratorBasic<double>(pl, model);
81 model->getNominalValues().get_x()->clone_v();
82 integrator->initializeSolutionHistory(0.0, x0);
85 bool integratorStatus = integrator->advanceTime();
89 time = integrator->getTime();
90 double timeFinal = pl->sublist(
"Default Integrator")
91 .sublist(
"Time Step Control")
92 .
get<
double>(
"Final Time");
98 integrator->getSolutionHistory();
99 writeSolution(
"Tempus_BackwardEuler_SinCos.dat", solutionHistory);
102 for (
int i = 0; i < solutionHistory->getNumStates(); i++) {
103 double time_i = (*solutionHistory)[i]->getTime();
106 model->getExactSolution(time_i).get_x()),
108 model->getExactSolution(time_i).get_x_dot()));
109 state->setTime((*solutionHistory)[i]->getTime());
110 solnHistExact->addState(state);
112 writeSolution(
"Tempus_BackwardEuler_SinCos-Ref.dat", solnHistExact);
116 StepSize.push_back(dt);
117 auto solution = Thyra::createMember(model->get_x_space());
118 Thyra::copy(*(integrator->getX()), solution.ptr());
119 solutions.push_back(solution);
120 auto solutionDot = Thyra::createMember(model->get_x_space());
121 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
122 solutionsDot.push_back(solutionDot);
123 if (n == nTimeStepSizes - 1) {
124 StepSize.push_back(0.0);
125 auto solutionExact = Thyra::createMember(model->get_x_space());
126 Thyra::copy(*(model->getExactSolution(time).get_x()),
127 solutionExact.ptr());
128 solutions.push_back(solutionExact);
129 auto solutionDotExact = Thyra::createMember(model->get_x_space());
130 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
131 solutionDotExact.ptr());
132 solutionsDot.push_back(solutionDotExact);
138 double xDotSlope = 0.0;
140 double order = stepper->getOrder();
141 writeOrderError(
"Tempus_BackwardEuler_SinCos-Error.dat", stepper, StepSize,
142 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.
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)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
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)
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)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Solution state for integrators and steppers.