93 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
98 model->getNominalValues().get_x()->clone_v());
99 solState->setIndex (0);
100 solState->setTime (0.0);
101 solState->setTimeStep(0.0);
103 RCP<Thyra::VectorBase<double> > xDot_n =
104 model->getNominalValues().get_x_dot()->clone_v();
107 auto solHistory = Tempus::createSolutionHistoryState<double>(solState);
110 double finalTime = 2.0;
111 int nTimeSteps = 2000;
112 const double constDT = finalTime/nTimeSteps;
116 cout << std::setw(8) <<
"index"
117 << std::setw(10) <<
"time"
118 << std::setw(12) <<
"x_0"
119 << std::setw(12) <<
"x_1" << endl;
121 auto currentState = solHistory->getCurrentState();
122 cout << std::setw(8) << currentState->getIndex()
123 << std::setw(10) << std::setprecision(3) << currentState->getTime()
124 << std::setw(12) << std::setprecision(4) << Thyra::get_ele(*(currentState->getX()), 0)
125 << std::setw(12) << std::setprecision(4) << Thyra::get_ele(*(currentState->getX()), 1)
130 solHistory->getCurrentTime() < finalTime &&
131 solHistory->getCurrentIndex() < nTimeSteps ) {
134 solHistory->initWorkingState();
135 currentState = solHistory->getCurrentState();
136 auto workingState = solHistory->getWorkingState();
137 RCP<Thyra::VectorBase<double> > x_n = currentState->getX();
138 RCP<Thyra::VectorBase<double> > x_np1 = workingState->getX();
141 int index = workingState->getIndex();
143 double time = index*dt;
144 workingState->setTime(time);
145 workingState->setTimeStep(dt);
149 auto inArgs = model->createInArgs();
150 auto outArgs = model->createOutArgs();
153 inArgs.set_x_dot(Teuchos::null);
154 outArgs.set_f(xDot_n);
157 model->evalModel(inArgs, outArgs);
160 Thyra::V_VpStV(x_np1.ptr(), *x_n, dt, *xDot_n);
163 if ( std::isnan(Thyra::norm(*x_np1)) ) {
169 solHistory->promoteWorkingState();
172 if (solHistory->getCurrentState()->getIndex() % 100 == 0) {
173 currentState = solHistory->getCurrentState();
174 cout << std::setw(8) << currentState->getIndex()
175 << std::setw(10) << std::setprecision(3) << currentState->getTime()
176 << std::setw(12) << std::setprecision(4) << Thyra::get_ele(*(currentState->getX()), 0)
177 << std::setw(12) << std::setprecision(4) << Thyra::get_ele(*(currentState->getX()), 1)
183 auto finalState = solHistory->getCurrentState();
187 if (passed && regressionPassed) success =
true;
189 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
192 cout <<
"\nEnd Result: Test Passed!" << std::endl;
194 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x.