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;
51 getParametersFromXmlFile(
"Tempus_BDF2_SinCos_AdaptDt.xml");
54 double dt = pList->
sublist(
"Tempus")
57 .
get<
double>(
"Initial Time Step");
62 const int nTimeStepSizes = scm_pl->
get<
int>(
"Number of Time Step Sizes", 7);
63 std::string output_file_string =
64 scm_pl->
get<std::string>(
"Output File Name",
"Tempus_BDF2_SinCos");
65 std::string output_file_name = output_file_string +
".dat";
66 std::string err_out_file_name = output_file_string +
"-Error.dat";
68 for (
int n = 0; n < nTimeStepSizes; n++) {
74 getParametersFromXmlFile(
"Tempus_BDF2_SinCos_AdaptDt.xml");
78 pl->
sublist(
"Default Integrator")
80 .
set(
"Initial Time Step", dt / 4.0);
83 pl->
sublist(
"Default Integrator")
85 .
set(
"Maximum Time Step", dt);
87 pl->
sublist(
"Default Integrator")
89 .
set(
"Minimum Time Step", dt / 4.0);
91 pl->
sublist(
"Default Integrator")
93 .
sublist(
"Time Step Control Strategy")
94 .
set(
"Minimum Value Monitoring Function", dt * 0.99);
95 integrator = Tempus::createIntegratorBasic<double>(pl, model);
102 model->getNominalValues().get_x()->clone_v();
103 integrator->initializeSolutionHistory(0.0, x0);
106 bool integratorStatus = integrator->advanceTime();
110 time = integrator->getTime();
111 double timeFinal = pl->sublist(
"Default Integrator")
112 .sublist(
"Time Step Control")
113 .
get<
double>(
"Final Time");
119 model->getExactSolution(time).get_x();
123 std::ofstream ftmp(output_file_name);
125 FILE *gold_file = fopen(
"Tempus_BDF2_SinCos_AdaptDt_gold.dat",
"r");
127 integrator->getSolutionHistory();
129 for (
int i = 0; i < solutionHistory->getNumStates(); i++) {
130 char time_gold_char[100];
131 fgets(time_gold_char, 100, gold_file);
133 sscanf(time_gold_char,
"%lf", &time_gold);
135 double time_i = solutionState->getTime();
138 TEST_FLOATING_EQUALITY(time_i, time_gold, 1.0e-5);
140 x_exact_plot = model->getExactSolution(time_i).get_x();
141 ftmp << time_i <<
" " << get_ele(*(x_plot), 0) <<
" "
142 << get_ele(*(x_plot), 1) <<
" " << get_ele(*(x_exact_plot), 0)
143 <<
" " << get_ele(*(x_exact_plot), 1) << std::endl;
149 StepSize.push_back(dt);
150 auto solution = Thyra::createMember(model->get_x_space());
151 Thyra::copy(*(integrator->getX()), solution.ptr());
152 solutions.push_back(solution);
153 auto solutionDot = Thyra::createMember(model->get_x_space());
154 Thyra::copy(*(integrator->getXDot()), solutionDot.ptr());
155 solutionsDot.push_back(solutionDot);
156 if (n == nTimeStepSizes - 1) {
157 StepSize.push_back(0.0);
158 auto solutionExact = Thyra::createMember(model->get_x_space());
159 Thyra::copy(*(model->getExactSolution(time).get_x()),
160 solutionExact.ptr());
161 solutions.push_back(solutionExact);
162 auto solutionDotExact = Thyra::createMember(model->get_x_space());
163 Thyra::copy(*(model->getExactSolution(time).get_x_dot()),
164 solutionDotExact.ptr());
165 solutionsDot.push_back(solutionDotExact);
170 if (nTimeStepSizes > 1) {
172 double xDotSlope = 0.0;
173 std::vector<double> xErrorNorm;
174 std::vector<double> xDotErrorNorm;
178 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
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...
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.