140 this->checkInitialized();
144 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperDIRK::takeStep()");
146 TEUCHOS_TEST_FOR_EXCEPTION(
147 solutionHistory->getNumStates() < 2, std::logic_error,
148 "Error - StepperDIRK<Scalar>::takeStep(...)\n"
149 <<
"Need at least two SolutionStates for DIRK.\n"
150 <<
" Number of States = " << solutionHistory->getNumStates()
151 <<
"\nTry setting in \"Solution History\" "
152 <<
"\"Storage Type\" = \"Undo\"\n"
153 <<
" or \"Storage Type\" = \"Static\" and "
154 <<
"\"Storage Limit\" = \"2\"\n");
156 RCP<SolutionState<Scalar> > currentState =
157 solutionHistory->getCurrentState();
158 RCP<SolutionState<Scalar> > workingState =
159 solutionHistory->getWorkingState();
160 const Scalar dt = workingState->getTimeStep();
161 const Scalar time = currentState->getTime();
163 const int numStages = this->tableau_->numStages();
164 Teuchos::SerialDenseMatrix<int, Scalar> A = this->tableau_->A();
165 Teuchos::SerialDenseVector<int, Scalar> b = this->tableau_->b();
166 Teuchos::SerialDenseVector<int, Scalar> c = this->tableau_->c();
169 if (this->getResetInitialGuess() && (!this->getZeroInitialGuess()))
170 Thyra::assign(workingState->getX().ptr(), *(currentState->getX()));
172 RCP<StepperDIRK<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
173 this->stepperRKAppAction_->execute(
174 solutionHistory, thisStepper,
179 Thyra::SolveStatus<Scalar> sStatus;
180 for (
int i = 0; i < numStages; ++i) {
181 this->setStageNumber(i);
183 Thyra::assign(xTilde_.ptr(), *(currentState->getX()));
184 for (
int j = 0; j < i; ++j) {
185 if (A(i, j) != Teuchos::ScalarTraits<Scalar>::zero()) {
186 Thyra::Vp_StV(xTilde_.ptr(), dt * A(i, j), *(stageXDot_[j]));
189 this->setStepperXDot(stageXDot_[i]);
191 this->stepperRKAppAction_->execute(
192 solutionHistory, thisStepper,
195 Scalar ts = time + c(i) * dt;
198 bool isNeeded =
false;
199 for (
int k = i + 1; k < numStages; ++k)
200 if (A(k, i) != 0.0) isNeeded =
true;
201 if (b(i) != 0.0) isNeeded =
true;
202 if (this->tableau_->isEmbedded() && this->getUseEmbedded() &&
203 this->tableau_->bstar()(i) != 0.0)
205 if (isNeeded ==
false) {
206 assign(stageXDot_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
208 else if (A(i, i) == Teuchos::ScalarTraits<Scalar>::zero()) {
210 if (i == 0 && this->getUseFSAL() &&
211 workingState->getNConsecutiveFailures() == 0) {
213 RCP<Thyra::VectorBase<Scalar> > tmp = stageXDot_[0];
214 stageXDot_[0] = stageXDot_.back();
215 stageXDot_.back() = tmp;
216 this->setStepperXDot(stageXDot_[0]);
220 typedef Thyra::ModelEvaluatorBase MEB;
221 MEB::InArgs<Scalar> inArgs = this->wrapperModel_->createInArgs();
222 MEB::OutArgs<Scalar> outArgs = this->wrapperModel_->createOutArgs();
223 inArgs.set_x(xTilde_);
224 if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(ts);
225 if (inArgs.supports(MEB::IN_ARG_x_dot))
226 inArgs.set_x_dot(Teuchos::null);
227 outArgs.set_f(stageXDot_[i]);
229 this->wrapperModel_->getAppModel()->evalModel(inArgs, outArgs);
234 const Scalar alpha = 1.0 / (dt * A(i, i));
235 const Scalar beta = 1.0;
238 Teuchos::RCP<TimeDerivative<Scalar> > timeDer = Teuchos::rcp(
244 this->stepperRKAppAction_->execute(
245 solutionHistory, thisStepper,
249 this->solveImplicitODE(workingState->getX(), stageXDot_[i], ts, p);
251 if (sStatus.solveStatus != Thyra::SOLVE_STATUS_CONVERGED) pass =
false;
253 this->stepperRKAppAction_->execute(
254 solutionHistory, thisStepper,
257 timeDer->compute(workingState->getX(), stageXDot_[i]);
259 this->stepperRKAppAction_->execute(
260 solutionHistory, thisStepper,
262 this->stepperRKAppAction_->execute(
263 solutionHistory, thisStepper,
267 this->setStageNumber(-1);
270 Thyra::assign((workingState->getX()).ptr(), *(currentState->getX()));
271 for (
int i = 0; i < numStages; ++i) {
272 if (b(i) != Teuchos::ScalarTraits<Scalar>::zero()) {
273 Thyra::Vp_StV((workingState->getX()).ptr(), dt * b(i),
278 if (this->tableau_->isEmbedded() && this->getUseEmbedded()) {
279 const Scalar tolRel = workingState->getTolRel();
280 const Scalar tolAbs = workingState->getTolAbs();
283 this->stepperErrorNormCalculator_->setRelativeTolerance(tolRel);
284 this->stepperErrorNormCalculator_->setAbsoluteTolerance(tolAbs);
288 Teuchos::SerialDenseVector<int, Scalar> errWght = b;
289 errWght -= this->tableau_->bstar();
293 assign(this->ee_.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
294 for (
int i = 0; i < numStages; ++i) {
295 if (errWght(i) != Teuchos::ScalarTraits<Scalar>::zero()) {
296 Thyra::Vp_StV(this->ee_.ptr(), dt * errWght(i), *(stageXDot_[i]));
300 Scalar err = this->stepperErrorNormCalculator_->computeWRMSNorm(
301 currentState->getX(), workingState->getX(), this->ee_);
302 workingState->setErrorRel(err);
305 if (std::isinf(err) || std::isnan(err) || err > Teuchos::as<Scalar>(1.0))
314 workingState->setOrder(this->getOrder());
315 workingState->computeNorms(currentState);
316 this->stepperRKAppAction_->execute(
317 solutionHistory, thisStepper,