44 RCP<Tempus::IntegratorBasic<double>> integrator;
45 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
46 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
47 std::vector<double> StepSize;
50 RCP<ParameterList> pList =
51 getParametersFromXmlFile(
"Tempus_BDF2_SinCos_AdaptDt.xml");
54 double dt = pList->sublist(
"Tempus")
55 .sublist(
"Default Integrator")
56 .sublist(
"Time Step Control")
57 .get<
double>(
"Initial Time Step");
61 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
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++) {
73 RCP<ParameterList> tempusPL =
74 getParametersFromXmlFile(
"Tempus_BDF2_SinCos_AdaptDt.xml");
75 RCP<ParameterList> pl = sublist(tempusPL,
"Tempus",
true);
78 pl->sublist(
"Default Integrator")
79 .sublist(
"Time Step Control")
80 .set(
"Initial Time Step", dt / 4.0);
83 pl->sublist(
"Default Integrator")
84 .sublist(
"Time Step Control")
85 .set(
"Maximum Time Step", dt);
87 pl->sublist(
"Default Integrator")
88 .sublist(
"Time Step Control")
89 .set(
"Minimum Time Step", dt / 4.0);
91 pl->sublist(
"Default Integrator")
92 .sublist(
"Time Step Control")
93 .sublist(
"Time Step Control Strategy")
94 .set(
"Minimum Value Monitoring Function", dt * 0.99);
95 integrator = Tempus::createIntegratorBasic<double>(pl, model);
101 RCP<Thyra::VectorBase<double>> x0 =
102 model->getNominalValues().get_x()->clone_v();
103 integrator->initializeSolutionHistory(0.0, x0);
106 bool integratorStatus = integrator->advanceTime();
107 TEST_ASSERT(integratorStatus)
110 time = integrator->getTime();
111 double timeFinal = pl->sublist(
"Default Integrator")
112 .sublist(
"Time Step Control")
113 .get<
double>(
"Final Time");
114 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
117 RCP<Thyra::VectorBase<double>> x = integrator->getX();
118 RCP<const Thyra::VectorBase<double>> x_exact =
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");
126 RCP<const SolutionHistory<double>> solutionHistory =
127 integrator->getSolutionHistory();
128 RCP<const Thyra::VectorBase<double>> x_exact_plot;
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);
134 RCP<const SolutionState<double>> solutionState = (*solutionHistory)[i];
135 double time_i = solutionState->getTime();
138 TEST_FLOATING_EQUALITY(time_i, time_gold, 1.0e-5);
139 RCP<const Thyra::VectorBase<double>> x_plot = solutionState->getX();
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;
175 RCP<Tempus::Stepper<double>> stepper = integrator->getStepper();
178 solutions, xErrorNorm, xSlope, solutionsDot, xDotErrorNorm,
181 TEST_FLOATING_EQUALITY(xSlope, 1.932, 0.01);
182 TEST_FLOATING_EQUALITY(xDotSlope, 1.932, 0.01);
183 TEST_FLOATING_EQUALITY(xErrorNorm[0], 0.000192591, 1.0e-4);
184 TEST_FLOATING_EQUALITY(xDotErrorNorm[0], 0.000192591, 1.0e-4);
187 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)