14 #include "Tempus_config.hpp"
15 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperFactory.hpp"
18 #include "Tempus_StepperNewmarkImplicitAForm.hpp"
19 #include "Tempus_StepperNewmarkImplicitDForm.hpp"
21 #include "../TestModels/HarmonicOscillatorModel.hpp"
22 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
29 namespace Tempus_Test {
31 using Teuchos::getParametersFromXmlFile;
34 using Teuchos::rcp_const_cast;
35 using Teuchos::rcp_dynamic_cast;
36 using Teuchos::sublist;
46 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
47 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
48 std::vector<double> StepSize;
49 std::vector<double> xErrorNorm;
50 std::vector<double> xDotErrorNorm;
51 const int nTimeStepSizes = 9;
56 getParametersFromXmlFile(
"Tempus_Test_NewmarkExplicitAForm_SinCos.xml");
66 stepperPL->
remove(
"Zero Initial Guess");
71 double dt = pl->
sublist(
"Default Integrator")
73 .
get<
double>(
"Initial Time Step");
76 for (
int n = 0; n < nTimeStepSizes; n++) {
79 out <<
"\n \n time step #" << n <<
" (out of " << nTimeStepSizes - 1
80 <<
"), dt = " << dt <<
"\n";
81 pl->
sublist(
"Default Integrator")
83 .
set(
"Initial Time Step", dt);
84 integrator = Tempus::createIntegratorBasic<double>(pl, model);
87 bool integratorStatus = integrator->advanceTime();
91 time = integrator->getTime();
92 double timeFinal = pl->sublist(
"Default Integrator")
93 .sublist(
"Time Step Control")
94 .
get<
double>(
"Final Time");
100 integrator->getSolutionHistory();
106 for (
int i = 0; i < solutionHistory->getNumStates(); i++) {
107 double time_i = (*solutionHistory)[i]->getTime();
110 model->getExactSolution(time_i).get_x()),
112 model->getExactSolution(time_i).get_x_dot()));
113 state->setTime((*solutionHistory)[i]->getTime());
114 solnHistExact->addState(state);
116 writeSolution(
"Tempus_Test_NewmarkExplicitAForm_SinCos-Ref.dat",
121 StepSize.push_back(dt);
122 auto solution = Thyra::createMember(model->get_x_space());
123 Thyra::copy(*(integrator->getX()), solution.ptr());
124 solutions.push_back(solution);
125 auto solutionDot = Thyra::createMember(model->get_x_space());
126 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
127 solutionsDot.push_back(solutionDot);
128 if (n == nTimeStepSizes - 1) {
129 StepSize.push_back(0.0);
130 auto solutionExact = Thyra::createMember(model->get_x_space());
131 Thyra::copy(*(model->getExactSolution(time).get_x()),
132 solutionExact.ptr());
133 solutions.push_back(solutionExact);
134 auto solutionDotExact = Thyra::createMember(model->get_x_space());
135 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
136 solutionDotExact.ptr());
137 solutionsDot.push_back(solutionDotExact);
143 double xDotSlope = 0.0;
145 double order = stepper->getOrder();
146 writeOrderError(
"Tempus_Test_NewmarkExplicitAForm_SinCos-Error.dat", stepper,
147 StepSize, solutions, xErrorNorm, xSlope, solutionsDot,
148 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)
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)
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
bool remove(std::string const &name, bool throwIfNotExists=true)
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.