13 #include "Thyra_VectorStdOps.hpp"
15 #include "Tempus_IntegratorBasic.hpp"
19 #include "../TestModels/SinCosModel.hpp"
20 #include "../TestModels/VanDerPolModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
26 namespace Tempus_Test {
28 using Teuchos::getParametersFromXmlFile;
31 using Teuchos::sublist;
41 std::vector<double> StepSize;
42 std::vector<double> ErrorNorm;
43 const int nTimeStepSizes = 7;
46 for (
int n = 0; n < nTimeStepSizes; n++) {
49 getParametersFromXmlFile(
"Tempus_PhysicsState_SinCos.xml");
67 .
set(
"Initial Time Step", dt);
69 Tempus::createIntegratorBasic<double>(pl, model);
75 integrator->setStepper(physicsStepper);
76 order = integrator->getStepper()->getOrder();
83 model->getNominalValues().get_x()->clone_v();
84 integrator->initializeSolutionHistory(0.0, x0);
90 integrator->getSolutionHistory()->getCurrentState()->setPhysicsState(pSC);
93 bool integratorStatus = integrator->advanceTime();
98 integrator->getSolutionHistory()->getCurrentState()->getPhysicsState();
105 double time = integrator->getTime();
106 double timeFinal = pl->sublist(
"Demo Integrator")
107 .sublist(
"Time Step Control")
108 .
get<
double>(
"Final Time");
114 model->getExactSolution(time).get_x();
118 std::ofstream ftmp(
"Tempus_ForwardEuler_SinCos.dat");
120 integrator->getSolutionHistory();
122 for (
int i = 0; i < solutionHistory->getNumStates(); i++) {
124 double time_i = solutionState->getTime();
126 x_exact_plot = model->getExactSolution(time_i).get_x();
127 ftmp << time_i <<
" " << Thyra::get_ele(*(x_plot), 0) <<
" "
128 << Thyra::get_ele(*(x_plot), 1) <<
" "
129 << Thyra::get_ele(*(x_exact_plot), 0) <<
" "
130 << Thyra::get_ele(*(x_exact_plot), 1) << std::endl;
137 Thyra::V_StVpStV(xdiff.
ptr(), 1.0, *x_exact, -1.0, *(x));
138 StepSize.push_back(dt);
139 const double L2norm = Thyra::norm_2(*xdiff);
140 ErrorNorm.push_back(L2norm);
144 double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
145 out <<
" Stepper = ForwardEuler" << std::endl;
146 out <<
" =========================" << std::endl;
147 out <<
" Expected order: " << order << std::endl;
148 out <<
" Observed order: " << slope << std::endl;
149 out <<
" =========================" << std::endl;
153 std::ofstream ftmp(
"Tempus_ForwardEuler_SinCos-Error.dat");
154 double error0 = 0.8 * ErrorNorm[0];
155 for (
int n = 0; n < nTimeStepSizes; n++) {
156 ftmp << StepSize[n] <<
" " << ErrorNorm[n] <<
" "
157 << error0 * (pow(StepSize[n] / StepSize[0], order)) << std::endl;
This is a Forward Euler time stepper to test the PhysicsState.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
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...
PhysicsStateCounter is a simple PhysicsState that counts steps.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define TEST_EQUALITY(v1, v2)
Solution state for integrators and steppers.