13 #include "Teuchos_DefaultComm.hpp"
15 #include "Thyra_MultiVectorStdOps.hpp"
17 #include "Tempus_config.hpp"
18 #include "Tempus_IntegratorBasic.hpp"
19 #include "Tempus_StepperBackwardEuler.hpp"
21 #include "../TestModels/SinCosModel.hpp"
22 #include "../TestModels/VanDerPolModel.hpp"
23 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
30 namespace Tempus_Test {
32 using Teuchos::getParametersFromXmlFile;
36 using Teuchos::rcp_const_cast;
37 using Teuchos::sublist;
49 getParametersFromXmlFile(
"Tempus_BackwardEuler_SinCos.xml");
58 Tempus::createIntegratorBasic<double>(pl, model);
61 bool integratorStatus = integrator->advanceTime();
66 integrator->getSolutionHistory();
82 Thyra::createMember(model->get_x_space());
85 Thyra::createMember(model->get_f_space());
92 const int num_p = p->range()->dim();
94 Thyra::createMembers(model->get_f_space(), num_p);
96 Thyra::createMembers(model->get_f_space(), num_p);
100 Thyra::createMembers(model->get_x_space(), num_p);
102 Thyra::createMembers(model->get_x_space(), num_p);
103 std::vector<double> nrms(num_p);
107 const int n = solutionHistory->getNumStates();
108 for (
int i = 1; i < n; ++i) {
113 x[0] = state->getX();
114 x[1] = prev_state->getX();
115 t[0] = state->getTime();
116 t[1] = prev_state->getTime();
119 const double dt = t[0] - t[1];
120 Thyra::V_StVpStV(x_dot.
ptr(), 1.0 / dt, *(x[0]), -1.0 / dt, *(x[1]));
124 MEB::InArgs<double> in_args = model->createInArgs();
125 MEB::OutArgs<double> out_args = model->createOutArgs();
127 in_args.set_x_dot(x_dot);
131 const double tol = 1.0e-14;
134 opt_stepper->computeStepResidual(*f, x, t, *p, 0);
136 model->evalModel(in_args, out_args);
137 out_args.set_f(Teuchos::null);
138 Thyra::V_VmV(f.ptr(), *f, *f2);
139 err = Thyra::norm(*f);
144 opt_stepper->computeStepJacobian(*dfdx, x, t, *p, 0, 0);
145 out_args.set_W_op(dfdx2);
146 in_args.set_alpha(1.0 / dt);
147 in_args.set_beta(1.0);
148 model->evalModel(in_args, out_args);
149 out_args.set_W_op(Teuchos::null);
150 Thyra::V_VmV(dfdx_mv.
ptr(), *dfdx_mv, *dfdx_mv2);
151 Thyra::norms(*dfdx_mv, Teuchos::arrayViewFromVector(nrms));
153 for (
auto nrm : nrms) err += nrm;
158 opt_stepper->computeStepJacobian(*dfdx, x, t, *p, 0, 1);
159 out_args.set_W_op(dfdx2);
160 in_args.set_alpha(-1.0 / dt);
161 in_args.set_beta(0.0);
162 model->evalModel(in_args, out_args);
163 out_args.set_W_op(Teuchos::null);
164 Thyra::V_VmV(dfdx_mv.
ptr(), *dfdx_mv, *dfdx_mv2);
165 Thyra::norms(*dfdx_mv, Teuchos::arrayViewFromVector(nrms));
167 for (
auto nrm : nrms) err += nrm;
171 opt_stepper->computeStepParamDeriv(*dfdp, x, t, *p, 0);
173 0, MEB::Derivative<double>(dfdp2, MEB::DERIV_MV_JACOBIAN_FORM));
174 model->evalModel(in_args, out_args);
175 out_args.set_DfDp(0, MEB::Derivative<double>());
176 Thyra::V_VmV(dfdp.
ptr(), *dfdp, *dfdp2);
177 Thyra::norms(*dfdp, Teuchos::arrayViewFromVector(nrms));
179 for (
auto nrm : nrms) err += nrm;
183 opt_stepper->computeStepSolver(*W, x, t, *p, 0);
185 in_args.set_alpha(1.0 / dt);
186 in_args.set_beta(1.0);
187 model->evalModel(in_args, out_args);
188 out_args.set_W(Teuchos::null);
192 Thyra::V_VmV(tmp.
ptr(), *tmp, *tmp2);
193 Thyra::norms(*tmp, Teuchos::arrayViewFromVector(nrms));
195 for (
auto nrm : nrms) err += nrm;
#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...
Stepper interface to support full-space optimization.
#define TEST_EQUALITY(v1, v2)
Solution state for integrators and steppers.