13 #include "Teuchos_DefaultComm.hpp"
15 #include "Tempus_config.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperBDF2.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;
53 double dt = pList->
sublist(
"Tempus")
56 .
get<
double>(
"Initial Time Step");
61 const int nTimeStepSizes = scm_pl->
get<
int>(
"Number of Time Step Sizes", 7);
62 std::string output_file_string =
63 scm_pl->
get<std::string>(
"Output File Name",
"Tempus_BDF2_SinCos");
64 std::string output_file_name = output_file_string +
".dat";
65 std::string ref_out_file_name = output_file_string +
"-Ref.dat";
66 std::string err_out_file_name = output_file_string +
"-Error.dat";
68 for (
int n = 0; n < nTimeStepSizes; n++) {
75 getParametersFromXmlFile(
"Tempus_BDF2_SinCos.xml");
77 pl->
sublist(
"Default Integrator")
79 .
set(
"Initial Time Step", dt);
80 integrator = Tempus::createIntegratorBasic<double>(pl, model);
87 model->getNominalValues().get_x()->clone_v();
88 integrator->initializeSolutionHistory(0.0, x0);
91 bool integratorStatus = integrator->advanceTime();
95 time = integrator->getTime();
96 double timeFinal = pl->sublist(
"Default Integrator")
97 .sublist(
"Time Step Control")
98 .
get<
double>(
"Final Time");
104 integrator->getSolutionHistory();
108 for (
int i = 0; i < solutionHistory->getNumStates(); i++) {
109 double time_i = (*solutionHistory)[i]->getTime();
112 model->getExactSolution(time_i).get_x()),
114 model->getExactSolution(time_i).get_x_dot()));
115 state->setTime((*solutionHistory)[i]->getTime());
116 solnHistExact->addState(state);
122 StepSize.push_back(dt);
123 auto solution = Thyra::createMember(model->get_x_space());
124 Thyra::copy(*(integrator->getX()), solution.ptr());
125 solutions.push_back(solution);
126 auto solutionDot = Thyra::createMember(model->get_x_space());
127 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
128 solutionsDot.push_back(solutionDot);
129 if (n == nTimeStepSizes - 1) {
130 StepSize.push_back(0.0);
131 auto solutionExact = Thyra::createMember(model->get_x_space());
132 Thyra::copy(*(model->getExactSolution(time).get_x()),
133 solutionExact.ptr());
134 solutions.push_back(solutionExact);
135 auto solutionDotExact = Thyra::createMember(model->get_x_space());
136 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
137 solutionDotExact.ptr());
138 solutionsDot.push_back(solutionDotExact);
143 if (nTimeStepSizes > 1) {
145 double xDotSlope = 0.0;
146 std::vector<double> xErrorNorm;
147 std::vector<double> xDotErrorNorm;
149 double order = stepper->getOrder();
150 writeOrderError(err_out_file_name, stepper, StepSize, solutions, xErrorNorm,
151 xSlope, solutionsDot, 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.
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)
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.