79int main(
int argc,
char *argv[])
85 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
90 model->getNominalValues().get_x()->clone_v());
91 solState->setIndex (0);
92 solState->setTime (0.0);
93 solState->setTimeStep(0.0);
95 RCP<Thyra::VectorBase<double> > xDot_n =
96 model->getNominalValues().get_x_dot()->clone_v();
99 auto solHistory = Tempus::createSolutionHistoryState<double>(solState);
102 double finalTime = 2.0;
103 int nTimeSteps = 2000;
104 const double constDT = finalTime/nTimeSteps;
108 solHistory->getCurrentState()->getTime() < finalTime &&
109 solHistory->getCurrentState()->getIndex() < nTimeSteps) {
112 solHistory->initWorkingState();
113 auto currentState = solHistory->getCurrentState();
114 auto workingState = solHistory->getWorkingState();
115 RCP<Thyra::VectorBase<double> > x_n = currentState->getX();
116 RCP<Thyra::VectorBase<double> > x_np1 = workingState->getX();
119 int index = workingState->getIndex();
121 double time = index*dt;
122 workingState->setTime(time);
123 workingState->setTimeStep(dt);
127 auto inArgs = model->createInArgs();
128 auto outArgs = model->createOutArgs();
131 inArgs.set_x_dot(Teuchos::null);
132 outArgs.set_f(xDot_n);
135 model->evalModel(inArgs, outArgs);
138 Thyra::V_VpStV(x_np1.ptr(), *x_n, dt, *xDot_n);
141 if ( std::isnan(Thyra::norm(*x_np1)) ) {
147 solHistory->promoteWorkingState();
150 if (solHistory->getCurrentState()->getIndex() % 100 == 0) {
151 currentState = solHistory->getCurrentState();
152 cout << currentState->getIndex() <<
" " << currentState->getTime()
153 <<
" " << Thyra::get_ele(*(currentState->getX()), 0)
154 <<
" " << Thyra::get_ele(*(currentState->getX()), 1) << endl;
159 auto finalState = solHistory->getCurrentState();
160 RCP<Thyra::VectorBase<double> > x_n = finalState->getX();
161 RCP<Thyra::VectorBase<double> > x_regress = x_n->clone_v();
163 Thyra::DetachedVectorView<double> x_regress_view(*x_regress);
164 x_regress_view[0] = -1.59496108218721311;
165 x_regress_view[1] = 0.96359412806611255;
168 RCP<Thyra::VectorBase<double> > x_error = x_n->clone_v();
169 Thyra::V_VmV(x_error.ptr(), *x_n, *x_regress);
170 double x_L2norm_error = Thyra::norm_2(*x_error );
171 double x_L2norm_regress = Thyra::norm_2(*x_regress);
173 cout <<
"Relative L2 Norm of the error (regression) = "
174 << x_L2norm_error/x_L2norm_regress << endl;
175 if ( x_L2norm_error > 1.0e-08*x_L2norm_regress) {
177 cout <<
"FAILED regression constraint!" << endl;
181 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
184 cout <<
"\nEnd Result: Test Passed!" << std::endl;
186 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
int main(int argc, char *argv[])