105 std::string stepperType,
109 if (stepperType ==
"") stepperType =
"Partitioned IMEX RK SSP2";
111 if (stepperType ==
"Partitioned IMEX RK 1st order") {
114 typedef Teuchos::ScalarTraits<Scalar> ST;
116 Teuchos::SerialDenseMatrix<int,Scalar> A(NumStages,NumStages);
117 Teuchos::SerialDenseVector<int,Scalar> b(NumStages);
118 Teuchos::SerialDenseVector<int,Scalar> c(NumStages);
119 const Scalar one = ST::one();
120 const Scalar zero = ST::zero();
123 A(0,0) = zero; A(0,1) = zero;
124 A(1,0) = one; A(1,1) = zero;
127 b(0) = one; b(1) = zero;
130 c(0) = zero; c(1) = one;
135 "Explicit Tableau - Partitioned IMEX RK 1st order",
136 A,b,c,order,order,order));
137 expTableau->setTVD(
true);
138 expTableau->setTVDCoeff(2.0);
144 typedef Teuchos::ScalarTraits<Scalar> ST;
146 const Scalar sspcoef = std::numeric_limits<Scalar>::max();
147 Teuchos::SerialDenseMatrix<int,Scalar> A(NumStages,NumStages);
148 Teuchos::SerialDenseVector<int,Scalar> b(NumStages);
149 Teuchos::SerialDenseVector<int,Scalar> c(NumStages);
150 const Scalar one = ST::one();
151 const Scalar zero = ST::zero();
154 A(0,0) = zero; A(0,1) = zero;
155 A(1,0) = zero; A(1,1) = one;
158 b(0) = zero; b(1) = one;
161 c(0) = zero; c(1) = one;
166 "Implicit Tableau - Partitioned IMEX RK 1st order",
167 A,b,c,order,order,order));
168 impTableau->setTVD(
true);
169 impTableau->setTVDCoeff(sspcoef);
177 }
else if (stepperType ==
"Partitioned IMEX RK SSP2") {
184 stepperSDIRK->setGammaType(
"2nd Order L-stable");
191 }
else if (stepperType ==
"Partitioned IMEX RK ARS 233") {
192 typedef Teuchos::ScalarTraits<Scalar> ST;
194 Teuchos::SerialDenseMatrix<int,Scalar> A(NumStages,NumStages);
195 Teuchos::SerialDenseVector<int,Scalar> b(NumStages);
196 Teuchos::SerialDenseVector<int,Scalar> c(NumStages);
197 const Scalar one = ST::one();
198 const Scalar zero = ST::zero();
199 const Scalar onehalf = ST::one()/(2*ST::one());
200 const Scalar gamma = (3*one+ST::squareroot(3*one))/(6*one);
204 A(0,0) = zero; A(0,1) = zero; A(0,2) = zero;
205 A(1,0) = gamma; A(1,1) = zero; A(1,2) = zero;
206 A(2,0) = (gamma-1.0); A(2,1) = (2.0-2.0*gamma); A(2,2) = zero;
209 b(0) = zero; b(1) = onehalf; b(2) = onehalf;
212 c(0) = zero; c(1) = gamma; c(2) = one-gamma;
217 "Explicit Tableau - Partitioned IMEX RK ARS 233",
218 A,b,c,order,order,order));
225 A(0,0) = zero; A(0,1) = zero; A(0,2) = zero;
226 A(1,0) = zero; A(1,1) = gamma; A(1,2) = zero;
227 A(2,0) = zero; A(2,1) = (1.0-2.0*gamma); A(2,2) = gamma;
230 b(0) = zero; b(1) = onehalf; b(2) = onehalf;
233 c(0) = zero; c(1) = gamma; c(2) = one-gamma;
238 "Implicit Tableau - Partitioned IMEX RK ARS 233",
239 A,b,c,order,order,order));
247 }
else if (stepperType ==
"General Partitioned IMEX RK") {
249 if ( explicitTableau == Teuchos::null ) {
257 if ( implicitTableau == Teuchos::null ) {
260 stepperSDIRK->setGammaType(
"2nd Order L-stable");
271 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
272 "Error - Not a valid StepperIMEX_RK_Partition type! Stepper Type = "
273 << stepperType <<
"\n"
274 <<
" Current valid types are: " <<
"\n"
275 <<
" 'Partitioned IMEX RK 1st order'" <<
"\n"
276 <<
" 'Partitioned IMEX RK SSP2'" <<
"\n"
277 <<
" 'Partitioned IMEX RK ARS 233'" <<
"\n"
278 <<
" 'General Partitioned IMEX RK'" <<
"\n");
283 "Error - StepperIMEX_RK_Partition - Explicit tableau is null!");
286 "Error - StepperIMEX_RK_Partition - Implicit tableau is null!");
287 TEUCHOS_TEST_FOR_EXCEPTION(
290 "Error - StepperIMEX_RK_Partition - Number of stages do not match!\n"
304 Teuchos::RCP<Teuchos::ParameterList> pl,
305 std::string stepperType)
308 if (stepperType ==
"") {
309 if (pl == Teuchos::null)
310 stepperType =
"Partitioned IMEX RK SSP2";
312 stepperType = pl->get<std::string>(
"Stepper Type",
"Partitioned IMEX RK SSP2");
315 if (stepperType !=
"General Partitioned IMEX RK") {
318 if (pl != Teuchos::null) {
319 Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau;
320 Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau;
321 if (pl->isSublist(
"IMEX-RK Explicit Stepper")) {
322 RCP<Teuchos::ParameterList> explicitPL = Teuchos::rcp(
323 new Teuchos::ParameterList(pl->sublist(
"IMEX-RK Explicit Stepper")));
325 auto stepperTemp = sf->createStepper(explicitPL, Teuchos::null);
326 auto stepperERK = Teuchos::rcp_dynamic_cast<StepperExplicitRK<Scalar> > (
328 TEUCHOS_TEST_FOR_EXCEPTION(stepperERK == Teuchos::null, std::logic_error,
329 "Error - The explicit component of a general partitioned IMEX RK stepper was not specified as an ExplicitRK stepper");
330 explicitTableau = stepperERK->getTableau();
333 if (pl->isSublist(
"IMEX-RK Implicit Stepper")) {
334 RCP<Teuchos::ParameterList> implicitPL = Teuchos::rcp(
335 new Teuchos::ParameterList(pl->sublist(
"IMEX-RK Implicit Stepper")));
337 auto stepperTemp = sf->createStepper(implicitPL, Teuchos::null);
338 auto stepperDIRK = Teuchos::rcp_dynamic_cast<StepperDIRK<Scalar> > (
340 TEUCHOS_TEST_FOR_EXCEPTION(stepperDIRK == Teuchos::null, std::logic_error,
341 "Error - The implicit component of a general partitioned IMEX RK stepper was not specified as an DIRK stepper");
342 implicitTableau = stepperDIRK->getTableau();
345 TEUCHOS_TEST_FOR_EXCEPTION(
346 !(explicitTableau!=Teuchos::null && implicitTableau!=Teuchos::null), std::logic_error,
347 "Error - A parameter list was used to setup a general partitioned IMEX RK stepper, but did not "
348 "specify both an explicit and an implicit tableau!\n");
350 this->
setTableaus(stepperType, explicitTableau, implicitTableau);
352 this->
setOrder(pl->get<
int>(
"overall order", 1));
491 int numStates = solutionHistory->getNumStates();
493 TEUCHOS_TEST_FOR_EXCEPTION(numStates < 1, std::logic_error,
494 "Error - setInitialConditions() needs at least one SolutionState\n"
495 " to set the initial condition. Number of States = " << numStates);
498 RCP<Teuchos::FancyOStream> out = this->getOStream();
499 Teuchos::OSTab ostab(out,1,
"StepperIMEX_RK::setInitialConditions()");
500 *out <<
"Warning -- SolutionHistory has more than one state!\n"
501 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
504 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
505 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
509 if (x == Teuchos::null) {
510 TEUCHOS_TEST_FOR_EXCEPTION( (x == Teuchos::null) &&
511 (inArgs.get_x() == Teuchos::null), std::logic_error,
512 "Error - setInitialConditions() needs the ICs from the SolutionHistory\n"
513 " or getNominalValues()!\n");
515 x = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x());
516 initialState->setX(x);
522 TEUCHOS_TEST_FOR_EXCEPTION(icConsistency !=
"None", std::logic_error,
523 "Error - setInitialConditions() requested a consistency of '"
524 << icConsistency <<
"'.\n"
525 " But only 'None' is available for IMEX-RK!\n");
527 TEUCHOS_TEST_FOR_EXCEPTION( this->
getUseFSAL(), std::logic_error,
528 "Error - The First-Same-As-Last (FSAL) principle is not "
529 <<
"available for IMEX-RK. Set useFSAL=false.\n");
537 Scalar time, Scalar stepSize, Scalar stageNumber,
540 typedef Thyra::ModelEvaluatorBase MEB;
541 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
542 wrapperModelPairIMEX =
543 Teuchos::rcp_dynamic_cast<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
545 MEB::InArgs<Scalar> inArgs = wrapperModelPairIMEX->getInArgs();
547 inArgs.set_p(wrapperModelPairIMEX->getParameterIndex(), Y);
548 if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(time);
549 if (inArgs.supports(MEB::IN_ARG_step_size)) inArgs.set_step_size(stepSize);
550 if (inArgs.supports(MEB::IN_ARG_stage_number))
551 inArgs.set_stage_number(stageNumber);
558 if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(Teuchos::null);
560 MEB::OutArgs<Scalar> outArgs = wrapperModelPairIMEX->getOutArgs();
563 wrapperModelPairIMEX->getImplicitModel()->evalModel(inArgs,outArgs);
564 Thyra::Vt_S(G.ptr(), -1.0);
571 Scalar time, Scalar stepSize, Scalar stageNumber,
574 typedef Thyra::ModelEvaluatorBase MEB;
576 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
577 wrapperModelPairIMEX =
578 Teuchos::rcp_dynamic_cast<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
580 MEB::InArgs<Scalar> inArgs =
581 wrapperModelPairIMEX->getExplicitModel()->createInArgs();
583 if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(time);
584 if (inArgs.supports(MEB::IN_ARG_step_size)) inArgs.set_step_size(stepSize);
585 if (inArgs.supports(MEB::IN_ARG_stage_number))
586 inArgs.set_stage_number(stageNumber);
593 if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(Teuchos::null);
595 MEB::OutArgs<Scalar> outArgs =
596 wrapperModelPairIMEX->getExplicitModel()->createOutArgs();
599 wrapperModelPairIMEX->getExplicitModel()->evalModel(inArgs, outArgs);
600 Thyra::Vt_S(F.ptr(), -1.0);
611 using Teuchos::SerialDenseMatrix;
612 using Teuchos::SerialDenseVector;
614 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperIMEX_RK_Partition::takeStep()");
616 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
618 "Error - StepperIMEX_RK_Partition<Scalar>::takeStep(...)\n"
619 "Need at least two SolutionStates for IMEX_RK_Partition.\n"
620 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
621 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
622 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
624 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
625 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
626 const Scalar dt = workingState->getTimeStep();
627 const Scalar time = currentState->getTime();
637 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
638 wrapperModelPairIMEX =
639 Teuchos::rcp_dynamic_cast<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
643 Thyra::assign(workingState->getX().ptr(), *(currentState->getX()));
644 RCP<Thyra::VectorBase<Scalar> > stageY =
645 wrapperModelPairIMEX->getExplicitOnlyVector(workingState->getX());
646 RCP<Thyra::VectorBase<Scalar> > stageX =
647 wrapperModelPairIMEX->getIMEXVector(workingState->getX());
649 RCP<StepperIMEX_RK_Partition<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
654 for (
int i = 0; i < numStages; ++i) {
657 Thyra::assign(stageY.ptr(),
658 *(wrapperModelPairIMEX->getExplicitOnlyVector(currentState->getX())));
660 *(wrapperModelPairIMEX->getIMEXVector(currentState->getX())));
661 for (
int j = 0; j < i; ++j) {
662 if (AHat(i,j) != Teuchos::ScalarTraits<Scalar>::zero()) {
663 RCP<Thyra::VectorBase<Scalar> > stageFy =
664 wrapperModelPairIMEX->getExplicitOnlyVector(
stageF_[j]);
665 RCP<Thyra::VectorBase<Scalar> > stageFx =
666 wrapperModelPairIMEX->getIMEXVector(
stageF_[j]);
667 Thyra::Vp_StV(stageY.ptr(), -dt*AHat(i,j), *stageFy);
668 Thyra::Vp_StV(
xTilde_.ptr(), -dt*AHat(i,j), *stageFx);
670 if (A (i,j) != Teuchos::ScalarTraits<Scalar>::zero())
677 Scalar ts = time + c(i)*dt;
678 Scalar tHats = time + cHat(i)*dt;
679 if (A(i,i) == Teuchos::ScalarTraits<Scalar>::zero()) {
681 bool isNeeded =
false;
682 for (
int k=i+1; k<numStages; ++k)
if (A(k,i) != 0.0) isNeeded =
true;
683 if (b(i) != 0.0) isNeeded =
true;
684 if (isNeeded ==
false) {
686 assign(
stageGx_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
688 Thyra::assign(stageX.ptr(), *
xTilde_);
693 const Scalar alpha = Scalar(1.0)/(dt*A(i,i));
694 const Scalar beta = Scalar(1.0);
697 RCP<TimeDerivative<Scalar> > timeDer =
707 wrapperModelPairIMEX->setUseImplicitModel(
true);
708 this->
solver_->setModel(wrapperModelPairIMEX);
710 Thyra::SolveStatus<Scalar> sStatus;
711 if (wrapperModelPairIMEX->getParameterIndex() >= 0)
713 stageY, wrapperModelPairIMEX->getParameterIndex());
717 if (sStatus.solveStatus != Thyra::SOLVE_STATUS_CONVERGED) pass =
false;
719 wrapperModelPairIMEX->setUseImplicitModel(
false);
737 Thyra::assign((workingState->getX()).ptr(), *(currentState->getX()));
738 RCP<Thyra::VectorBase<Scalar> > Z = workingState->getX();
739 RCP<Thyra::VectorBase<Scalar> > X = wrapperModelPairIMEX->getIMEXVector(Z);
740 for (
int i=0; i < numStages; ++i) {
741 if (bHat(i) != Teuchos::ScalarTraits<Scalar>::zero())
742 Thyra::Vp_StV(Z.ptr(), -dt*bHat(i), *(
stageF_[i]));
743 if (b (i) != Teuchos::ScalarTraits<Scalar>::zero())
744 Thyra::Vp_StV(X.ptr(), -dt*b (i), *(
stageGx_[i]));
747 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
749 workingState->setOrder(this->
getOrder());
750 workingState->computeNorms(currentState);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...