9 #ifndef Tempus_StepperIMEX_RK_Partition_impl_hpp
10 #define Tempus_StepperIMEX_RK_Partition_impl_hpp
12 #include "Tempus_RKButcherTableauBuilder.hpp"
13 #include "Tempus_config.hpp"
15 #include "Tempus_WrapperModelEvaluatorPairPartIMEX_Basic.hpp"
16 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
17 #include "Thyra_VectorStdOps.hpp"
18 #include "NOX_Thyra.H"
24 template<
class Scalar>
class StepperFactory;
27 template<
class Scalar>
30 this->setTableaus(Teuchos::null,
"Partitioned IMEX RK SSP2");
31 this->setParameterList(Teuchos::null);
36 template<
class Scalar>
38 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
39 Teuchos::RCP<Teuchos::ParameterList> pList)
41 this->setTableaus(pList,
"Partitioned IMEX RK SSP2");
42 this->setParameterList(pList);
44 if (appModel == Teuchos::null) {
48 this->setModel(appModel);
54 template<
class Scalar>
56 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
57 std::string stepperType)
59 this->setTableaus(Teuchos::null, stepperType);
61 if (appModel == Teuchos::null) {
65 this->setModel(appModel);
71 template<
class Scalar>
73 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
74 std::string stepperType,
75 Teuchos::RCP<Teuchos::ParameterList> pList)
77 this->setTableaus(pList, stepperType);
78 this->setParameterList(pList);
80 if (appModel == Teuchos::null) {
84 this->setModel(appModel);
90 template<
class Scalar>
92 Teuchos::RCP<Teuchos::ParameterList> pList,
93 std::string stepperType)
95 if (stepperType ==
"") {
96 if (pList == Teuchos::null)
97 stepperType =
"Partitioned IMEX RK SSP2";
99 stepperType = pList->get<std::string>(
"Stepper Type",
100 "Partitioned IMEX RK SSP2");
103 if (stepperType ==
"Partitioned IMEX RK 1st order") {
106 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
107 pl->setName(
"IMEX-RK Explicit Stepper");
108 pl->set<std::string>(
"Stepper Type",
"General ERK");
111 Teuchos::RCP<Teuchos::ParameterList> tableauPL = Teuchos::parameterList();
112 tableauPL->set<std::string>(
"A",
"0.0 0.0; 1.0 0.0");
113 tableauPL->set<std::string>(
"b",
"1.0 0.0");
114 tableauPL->set<std::string>(
"c",
"0.0 1.0");
115 tableauPL->set<
int>(
"order", 1);
116 pl->set(
"Tableau", *tableauPL);
118 this->setExplicitTableau(
"General ERK", pl);
122 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
123 pl->setName(
"IMEX-RK Implicit Stepper");
124 pl->set<std::string>(
"Stepper Type",
"General DIRK");
125 pl->set(
"Solver Name",
"");
128 Teuchos::RCP<Teuchos::ParameterList> tableauPL = Teuchos::parameterList();
129 tableauPL->set<std::string>(
"A",
"0.0 0.0; 0.0 1.0");
130 tableauPL->set<std::string>(
"b",
"0.0 1.0");
131 tableauPL->set<std::string>(
"c",
"0.0 1.0");
132 tableauPL->set<
int>(
"order", 1);
133 pl->set(
"Tableau", *tableauPL);
135 this->setImplicitTableau(
"General DIRK", pl);
137 description_ = stepperType;
140 }
else if (stepperType ==
"Partitioned IMEX RK SSP2") {
141 typedef Teuchos::ScalarTraits<Scalar> ST;
143 this->setExplicitTableau(
"RK Explicit Trapezoidal", Teuchos::null);
146 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
147 pl->set<std::string>(
"Stepper Type",
"SDIRK 2 Stage 3rd order");
148 pl->set(
"Solver Name",
"");
149 const Scalar one = ST::one();
150 Scalar gamma = one - one/ST::squareroot(2*one);
151 pl->set<
double>(
"gamma",gamma);
152 this->setImplicitTableau(
"SDIRK 2 Stage 3rd order", pl);
154 description_ = stepperType;
156 }
else if (stepperType ==
"Partitioned IMEX RK ARS 233") {
157 using std::to_string;
158 typedef Teuchos::ScalarTraits<Scalar> ST;
159 const Scalar one = ST::one();
160 const Scalar gammaN = (3*one+ST::squareroot(3*one))/(6*one);
161 std::string gamma = to_string( gammaN);
162 std::string one_gamma = to_string(1.0- gammaN);
163 std::string one_2gamma = to_string(1.0-2.0*gammaN);
164 std::string two_2gamma = to_string(2.0-2.0*gammaN);
165 std::string gamma_one = to_string( gammaN-1.0);
168 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
169 pl->setName(
"IMEX-RK Explicit Stepper");
170 pl->set<std::string>(
"Stepper Type",
"General ERK");
173 Teuchos::RCP<Teuchos::ParameterList> tableauPL = Teuchos::parameterList();
174 tableauPL->set<std::string>(
"A",
175 "0.0 0.0 0.0; "+gamma+
" 0.0 0.0; "+gamma_one+
" "+two_2gamma+
" 0.0");
176 tableauPL->set<std::string>(
"b",
"0.0 0.5 0.5");
177 tableauPL->set<std::string>(
"c",
"0.0 "+gamma+
" "+one_gamma);
178 tableauPL->set<
int>(
"order", 2);
179 pl->set(
"Tableau", *tableauPL);
181 this->setExplicitTableau(
"General ERK", pl);
185 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
186 pl->setName(
"IMEX-RK Implicit Stepper");
187 pl->set<std::string>(
"Stepper Type",
"General DIRK");
188 pl->set(
"Solver Name",
"");
191 Teuchos::RCP<Teuchos::ParameterList> tableauPL = Teuchos::parameterList();
192 tableauPL->set<std::string>(
"A",
193 "0.0 0.0 0.0; 0.0 "+gamma+
" 0.0; 0.0 "+one_2gamma+
" "+gamma);
194 tableauPL->set<std::string>(
"b",
"0.0 0.5 0.5");
195 tableauPL->set<std::string>(
"c",
"0.0 "+gamma+
" "+one_gamma);
196 tableauPL->set<
int>(
"order", 3);
197 pl->set(
"Tableau", *tableauPL);
199 this->setImplicitTableau(
"General DIRK", pl);
201 description_ = stepperType;
204 }
else if (stepperType ==
"General Partitioned IMEX RK") {
205 Teuchos::RCP<Teuchos::ParameterList> explicitPL = Teuchos::rcp(
206 new Teuchos::ParameterList(pList->sublist(
"IMEX-RK Explicit Stepper")));
208 Teuchos::RCP<Teuchos::ParameterList> implicitPL = Teuchos::rcp(
209 new Teuchos::ParameterList(pList->sublist(
"IMEX-RK Implicit Stepper")));
212 this->setExplicitTableau(
"General ERK", explicitPL);
213 this->setImplicitTableau(
"General DIRK", implicitPL);
214 description_ = stepperType;
215 order_ = pList->get<
int>(
"overall order", 0);
218 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
219 "Error - Not a valid StepperIMEX_RK_Partition type! Stepper Type = "
220 << stepperType <<
"\n"
221 <<
" Current valid types are: " <<
"\n"
222 <<
" 'Partitioned IMEX RK 1st order'" <<
"\n"
223 <<
" 'Partitioned IMEX RK SSP2'" <<
"\n"
224 <<
" 'Partitioned IMEX RK ARS 233'" <<
"\n"
225 <<
" 'General Partitioned IMEX RK'" <<
"\n");
228 TEUCHOS_TEST_FOR_EXCEPTION(explicitTableau_==Teuchos::null,
230 "Error - StepperIMEX_RK_Partition - Explicit tableau is null!");
231 TEUCHOS_TEST_FOR_EXCEPTION(implicitTableau_==Teuchos::null,
233 "Error - StepperIMEX_RK_Partition - Implicit tableau is null!");
234 TEUCHOS_TEST_FOR_EXCEPTION(
235 explicitTableau_->numStages()!=implicitTableau_->numStages(),
237 "Error - StepperIMEX_RK_Partition - Number of stages do not match!\n"
238 <<
" Explicit tableau = " << explicitTableau_->description() <<
"\n"
239 <<
" number of stages = " << explicitTableau_->numStages() <<
"\n"
240 <<
" Implicit tableau = " << implicitTableau_->description() <<
"\n"
241 <<
" number of stages = " << implicitTableau_->numStages() <<
"\n");
245 template<
class Scalar>
247 std::string stepperType,
248 Teuchos::RCP<Teuchos::ParameterList> pList)
250 Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau =
251 createRKBT<Scalar>(stepperType,pList);
252 this->setExplicitTableau(explicitTableau);
256 template<
class Scalar>
260 TEUCHOS_TEST_FOR_EXCEPTION(explicitTableau->isImplicit() ==
true,
262 "Error - Received an implicit Tableau for setExplicitTableau()!\n" <<
263 " Tableau = " << explicitTableau->description() <<
"\n");
264 explicitTableau_ = explicitTableau;
268 template<
class Scalar>
270 std::string stepperType,
271 Teuchos::RCP<Teuchos::ParameterList> pList)
273 Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau =
274 createRKBT<Scalar>(stepperType,pList);
275 this->setImplicitTableau(implicitTableau);
279 template<
class Scalar>
283 TEUCHOS_TEST_FOR_EXCEPTION( implicitTableau->isDIRK() !=
true,
285 "Error - Did not receive a DIRK Tableau for setImplicitTableau()!\n" <<
286 " Tableau = " << implicitTableau->description() <<
"\n");
287 implicitTableau_ = implicitTableau;
290 template<
class Scalar>
292 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
295 using Teuchos::rcp_const_cast;
296 using Teuchos::rcp_dynamic_cast;
297 RCP<Thyra::ModelEvaluator<Scalar> > ncModel =
298 rcp_const_cast<Thyra::ModelEvaluator<Scalar> > (appModel);
299 RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> > modelPairIMEX =
301 TEUCHOS_TEST_FOR_EXCEPTION( modelPairIMEX == Teuchos::null, std::logic_error,
302 "Error - StepperIMEX_RK::setModel() was given a ModelEvaluator that\n"
303 " could not be cast to a WrapperModelEvaluatorPairPartIMEX_Basic!\n"
304 " From: " << appModel <<
"\n"
305 " To : " << modelPairIMEX <<
"\n"
306 " Likely have given the wrong ModelEvaluator to this Stepper.\n");
308 setModelPair(modelPairIMEX);
316 template<
class Scalar>
321 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
322 wrapperModelPairIMEX =
324 (this->wrapperModel_);
325 this->validExplicitODE (mePairIMEX->getExplicitModel());
326 this->validImplicitODE_DAE(mePairIMEX->getImplicitModel());
327 wrapperModelPairIMEX = mePairIMEX;
330 this->wrapperModel_ = wrapperModelPairIMEX;
338 template<
class Scalar>
340 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& explicitModel,
341 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& implicitModel)
343 this->validExplicitODE (explicitModel);
344 this->validImplicitODE_DAE(implicitModel);
345 this->wrapperModel_ = Teuchos::rcp(
347 explicitModel, implicitModel));
351 template<
class Scalar>
355 if (obs == Teuchos::null) {
357 if (this->stepperObserver_ == Teuchos::null) {
358 stepperIMEX_RKPartObserver_ =
360 this->stepperObserver_ =
362 (stepperIMEX_RKPartObserver_);
365 this->stepperObserver_ = obs;
366 stepperIMEX_RKPartObserver_ =
368 (this->stepperObserver_);
373 template<
class Scalar>
376 TEUCHOS_TEST_FOR_EXCEPTION(
377 (explicitTableau_ == Teuchos::null) || (implicitTableau_ == Teuchos::null),
379 "Error - Need to set the Butcher Tableaus, setTableaus(), before calling "
380 "StepperIMEX_RK_Partition::initialize()\n");
382 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
383 wrapperModelPairIMEX =
385 (this->wrapperModel_);
386 TEUCHOS_TEST_FOR_EXCEPTION( wrapperModelPairIMEX == Teuchos::null,
388 "Error - Need to set the model, setModel(), before calling "
389 "StepperIMEX_RK_Partition::initialize()\n");
391 this->setTableaus(this->stepperPL_);
392 this->setParameterList(this->stepperPL_);
397 const int numStages = explicitTableau_->numStages();
398 stageF_.resize(numStages);
399 stageGx_.resize(numStages);
400 for(
int i=0; i < numStages; i++) {
401 stageF_[i] = Thyra::createMember(wrapperModelPairIMEX->
402 getExplicitModel()->get_f_space());
403 stageGx_[i] = Thyra::createMember(wrapperModelPairIMEX->
404 getImplicitModel()->get_f_space());
405 assign(stageF_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
406 assign(stageGx_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
409 xTilde_ = Thyra::createMember(wrapperModelPairIMEX->
410 getImplicitModel()->get_x_space());
411 assign(xTilde_.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
415 template<
class Scalar>
423 TEUCHOS_TEST_FOR_EXCEPTION(numStates < 1, std::logic_error,
424 "Error - setInitialConditions() needs at least one SolutionState\n"
425 " to set the initial condition. Number of States = " << numStates);
428 RCP<Teuchos::FancyOStream> out = this->getOStream();
429 Teuchos::OSTab ostab(out,1,
"StepperIMEX_RK::setInitialConditions()");
430 *out <<
"Warning -- SolutionHistory has more than one state!\n"
431 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
434 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
435 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
438 auto inArgs = this->wrapperModel_->getNominalValues();
439 if (x == Teuchos::null) {
440 TEUCHOS_TEST_FOR_EXCEPTION( (x == Teuchos::null) &&
441 (inArgs.get_x() == Teuchos::null), std::logic_error,
442 "Error - setInitialConditions() needs the ICs from the SolutionHistory\n"
443 " or getNominalValues()!\n");
445 x = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x());
446 initialState->setX(x);
451 std::string icConsistency = this->getICConsistency();
452 TEUCHOS_TEST_FOR_EXCEPTION(icConsistency !=
"None", std::logic_error,
453 "Error - setInitialConditions() requested a consistency of '"
454 << icConsistency <<
"'.\n"
455 " But only 'None' is available for IMEX-RK!\n");
457 TEUCHOS_TEST_FOR_EXCEPTION( this->getUseFSAL(), std::logic_error,
458 "Error - The First-Step-As-Last (FSAL) principle is not "
459 <<
"available for IMEX-RK. Set useFSAL=false.\n");
463 template <
typename Scalar>
465 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> > & X,
466 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> > & Y,
467 Scalar time, Scalar stepSize, Scalar stageNumber,
468 const Teuchos::RCP<Thyra::VectorBase<Scalar> > & G)
const
470 typedef Thyra::ModelEvaluatorBase MEB;
471 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
472 wrapperModelPairIMEX =
474 (this->wrapperModel_);
475 MEB::InArgs<Scalar> inArgs = wrapperModelPairIMEX->
getInArgs();
477 inArgs.set_p(wrapperModelPairIMEX->getParameterIndex(), Y);
478 if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(time);
479 if (inArgs.supports(MEB::IN_ARG_step_size)) inArgs.set_step_size(stepSize);
480 if (inArgs.supports(MEB::IN_ARG_stage_number))
481 inArgs.set_stage_number(stageNumber);
488 if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(Teuchos::null);
490 MEB::OutArgs<Scalar> outArgs = wrapperModelPairIMEX->getOutArgs();
493 wrapperModelPairIMEX->getImplicitModel()->evalModel(inArgs,outArgs);
494 Thyra::Vt_S(G.ptr(), -1.0);
498 template <
typename Scalar>
500 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> > & Z,
501 Scalar time, Scalar stepSize, Scalar stageNumber,
502 const Teuchos::RCP<Thyra::VectorBase<Scalar> > & F)
const
504 typedef Thyra::ModelEvaluatorBase MEB;
506 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
507 wrapperModelPairIMEX =
509 (this->wrapperModel_);
510 MEB::InArgs<Scalar> inArgs =
513 if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(time);
514 if (inArgs.supports(MEB::IN_ARG_step_size)) inArgs.set_step_size(stepSize);
515 if (inArgs.supports(MEB::IN_ARG_stage_number))
516 inArgs.set_stage_number(stageNumber);
523 if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(Teuchos::null);
525 MEB::OutArgs<Scalar> outArgs =
526 wrapperModelPairIMEX->getExplicitModel()->createOutArgs();
529 wrapperModelPairIMEX->getExplicitModel()->evalModel(inArgs, outArgs);
530 Thyra::Vt_S(F.ptr(), -1.0);
534 template<
class Scalar>
539 using Teuchos::SerialDenseMatrix;
540 using Teuchos::SerialDenseVector;
542 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperIMEX_RK_Partition::takeStep()");
546 "Error - StepperIMEX_RK_Partition<Scalar>::takeStep(...)\n"
547 "Need at least two SolutionStates for IMEX_RK_Partition.\n"
549 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
550 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
553 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
554 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
555 const Scalar dt = workingState->getTimeStep();
556 const Scalar time = currentState->getTime();
558 const int numStages = explicitTableau_->numStages();
559 const SerialDenseMatrix<int,Scalar> & AHat = explicitTableau_->A();
560 const SerialDenseVector<int,Scalar> & bHat = explicitTableau_->b();
561 const SerialDenseVector<int,Scalar> & cHat = explicitTableau_->c();
562 const SerialDenseMatrix<int,Scalar> & A = implicitTableau_->A();
563 const SerialDenseVector<int,Scalar> & b = implicitTableau_->b();
564 const SerialDenseVector<int,Scalar> & c = implicitTableau_->c();
566 Teuchos::RCP<WrapperModelEvaluatorPairPartIMEX_Basic<Scalar> >
567 wrapperModelPairIMEX =
569 (this->wrapperModel_);
572 Thyra::SolveStatus<Scalar> sStatus;
573 stageZ_ = workingState->getX();
574 Thyra::assign(stageZ_.ptr(), *(currentState->getX()));
575 RCP<Thyra::VectorBase<Scalar> > stageY =
576 wrapperModelPairIMEX->getExplicitOnlyVector(stageZ_);
577 RCP<Thyra::VectorBase<Scalar> > stageX =
578 wrapperModelPairIMEX->getIMEXVector(stageZ_);
581 for (
int i = 0; i < numStages; ++i) {
582 if (!Teuchos::is_null(stepperIMEX_RKPartObserver_))
583 stepperIMEX_RKPartObserver_->observeBeginStage(
solutionHistory, *
this);
585 Thyra::assign(stageY.ptr(),
586 *(wrapperModelPairIMEX->getExplicitOnlyVector(currentState->getX())));
587 Thyra::assign(xTilde_.ptr(),
588 *(wrapperModelPairIMEX->getIMEXVector(currentState->getX())));
589 for (
int j = 0; j < i; ++j) {
590 if (AHat(i,j) != Teuchos::ScalarTraits<Scalar>::zero()) {
591 RCP<Thyra::VectorBase<Scalar> > stageFy =
592 wrapperModelPairIMEX->getExplicitOnlyVector(stageF_[j]);
593 RCP<Thyra::VectorBase<Scalar> > stageFx =
594 wrapperModelPairIMEX->getIMEXVector(stageF_[j]);
595 Thyra::Vp_StV(stageY.ptr(), -dt*AHat(i,j), *stageFy);
596 Thyra::Vp_StV(xTilde_.ptr(), -dt*AHat(i,j), *stageFx);
598 if (A (i,j) != Teuchos::ScalarTraits<Scalar>::zero())
599 Thyra::Vp_StV(xTilde_.ptr(), -dt*A (i,j), *(stageGx_[j]));
602 Scalar ts = time + c(i)*dt;
603 Scalar tHats = time + cHat(i)*dt;
604 if (A(i,i) == Teuchos::ScalarTraits<Scalar>::zero()) {
606 bool isNeeded =
false;
607 for (
int k=i+1; k<numStages; ++k)
if (A(k,i) != 0.0) isNeeded =
true;
608 if (b(i) != 0.0) isNeeded =
true;
609 if (isNeeded ==
false) {
611 assign(stageGx_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
613 Thyra::assign(stageX.ptr(), *xTilde_);
614 if (!Teuchos::is_null(stepperIMEX_RKPartObserver_))
615 stepperIMEX_RKPartObserver_->
617 evalImplicitModelExplicitly(stageX, stageY, ts, dt, i, stageGx_[i]);
621 const Scalar alpha = Scalar(1.0)/(dt*A(i,i));
622 const Scalar beta = Scalar(1.0);
625 RCP<TimeDerivative<Scalar> > timeDer =
627 alpha, xTilde_.getConst()));
630 typedef Thyra::ModelEvaluatorBase MEB;
633 wrapperModelPairIMEX->setUseImplicitModel(
true);
634 MEB::InArgs<Scalar> inArgs = wrapperModelPairIMEX->createInArgs();
635 MEB::OutArgs<Scalar> outArgs = wrapperModelPairIMEX->createOutArgs();
636 inArgs.set_x(stageX);
637 if (wrapperModelPairIMEX->getParameterIndex() >= 0)
638 inArgs.set_p(wrapperModelPairIMEX->getParameterIndex(), stageY);
639 if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(stageGx_[i]);
640 if (inArgs.supports(MEB::IN_ARG_t )) inArgs.set_t (ts);
641 if (inArgs.supports(MEB::IN_ARG_step_size)) inArgs.set_step_size(dt);
642 if (inArgs.supports(MEB::IN_ARG_alpha )) inArgs.set_alpha (alpha);
643 if (inArgs.supports(MEB::IN_ARG_beta )) inArgs.set_beta (beta);
644 if (inArgs.supports(MEB::IN_ARG_stage_number))
645 inArgs.set_stage_number(i);
647 wrapperModelPairIMEX->setForSolve(timeDer, inArgs, outArgs);
649 if (!Teuchos::is_null(stepperIMEX_RKPartObserver_))
650 stepperIMEX_RKPartObserver_->observeBeforeSolve(
solutionHistory, *
this);
652 this->solver_->setModel(wrapperModelPairIMEX);
653 sStatus = this->solveImplicitODE(stageX);
654 if (sStatus.solveStatus != Thyra::SOLVE_STATUS_CONVERGED) pass =
false;
656 wrapperModelPairIMEX->setUseImplicitModel(
false);
658 if (!Teuchos::is_null(stepperIMEX_RKPartObserver_))
659 stepperIMEX_RKPartObserver_->observeAfterSolve(
solutionHistory, *
this);
662 Thyra::V_StVpStV(stageGx_[i].ptr(), -alpha, *stageX, alpha, *xTilde_);
665 if (!Teuchos::is_null(stepperIMEX_RKPartObserver_))
666 stepperIMEX_RKPartObserver_->observeBeforeExplicit(
solutionHistory,*
this);
667 evalExplicitModel(stageZ_, tHats, dt, i, stageF_[i]);
668 if (!Teuchos::is_null(stepperIMEX_RKPartObserver_))
674 Thyra::assign((workingState->getX()).ptr(), *(currentState->getX()));
675 RCP<Thyra::VectorBase<Scalar> > Z = workingState->getX();
676 RCP<Thyra::VectorBase<Scalar> > X = wrapperModelPairIMEX->getIMEXVector(Z);
677 for (
int i=0; i < numStages; ++i) {
678 if (bHat(i) != Teuchos::ScalarTraits<Scalar>::zero())
679 Thyra::Vp_StV(Z.ptr(), -dt*bHat(i), *(stageF_[i]));
680 if (b (i) != Teuchos::ScalarTraits<Scalar>::zero())
681 Thyra::Vp_StV(X.ptr(), -dt*b (i), *(stageGx_[i]));
684 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
686 workingState->setOrder(this->getOrder());
698 template<
class Scalar>
699 Teuchos::RCP<Tempus::StepperState<Scalar> >
703 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
709 template<
class Scalar>
712 return(description_);
716 template<
class Scalar>
718 Teuchos::FancyOStream &out,
719 const Teuchos::EVerbosityLevel )
const
721 out << description() <<
"::describe:" << std::endl
722 <<
"wrapperModelPairIMEX = " << this->wrapperModel_->description()
727 template <
class Scalar>
729 const Teuchos::RCP<Teuchos::ParameterList> & pList)
731 if (pList == Teuchos::null) {
733 if (this->stepperPL_ == Teuchos::null) this->stepperPL_ = this->getDefaultParameters();
735 this->stepperPL_ = pList;
742 template<
class Scalar>
743 Teuchos::RCP<const Teuchos::ParameterList>
746 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
747 pl->setName(
"Default Stepper - Partitioned IMEX RK SSP2");
748 pl->set<std::string>(
"Stepper Type",
"Partitioned IMEX RK SSP2");
749 this->getValidParametersBasic(pl);
750 pl->set<
bool>(
"Initial Condition Consistency Check",
false);
751 pl->set<
bool> (
"Zero Initial Guess",
false);
752 pl->set<std::string>(
"Solver Name",
"",
753 "Name of ParameterList containing the solver specifications.");
758 template <
class Scalar>
759 Teuchos::RCP<Teuchos::ParameterList>
763 using Teuchos::ParameterList;
764 using Teuchos::rcp_const_cast;
766 RCP<ParameterList> pl =
767 rcp_const_cast<ParameterList>(this->getValidParameters());
769 pl->set<std::string>(
"Solver Name",
"Default Solver");
770 RCP<ParameterList> solverPL = this->defaultSolverParameters();
771 pl->set(
"Default Solver", *solverPL);
776 template <
class Scalar>
777 Teuchos::RCP<Teuchos::ParameterList>
780 return(this->stepperPL_);
784 template <
class Scalar>
785 Teuchos::RCP<Teuchos::ParameterList>
788 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
789 this->stepperPL_ = Teuchos::null;
795 #endif // Tempus_StepperIMEX_RK_Partition_impl_hpp
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
StepperIMEX_RK_Partition()
Default constructor.
virtual void setImplicitTableau(std::string stepperType, Teuchos::RCP< Teuchos::ParameterList > pList)
Set the implicit tableau from ParameterList.
virtual void setModelPair(const Teuchos::RCP< WrapperModelEvaluatorPairPartIMEX_Basic< Scalar > > &modelPair)
Create WrapperModelPairIMEX from user-supplied ModelEvaluator pair.
virtual std::string description() const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > getInArgs()
Get InArgs the wrapper ModelEvalutor.
virtual void initialize()
Initialize after setting member data.
void evalExplicitModel(const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &X, Scalar time, Scalar stepSize, Scalar stageNumber, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &F) const
StepperIMEX_RKPartObserver class for StepperIMEX_RK_Partition.
StepperState is a simple class to hold state information about the stepper.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Provide a StepperState to the SolutionState. This Stepper does not have any special state data...
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
void evalImplicitModelExplicitly(const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &X, const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &Y, Scalar time, Scalar stepSize, Scalar stageNumber, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &G) const
StepperObserver class for Stepper class.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
Time-derivative interface for Partitioned IMEX RK.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setTableaus(Teuchos::RCP< Teuchos::ParameterList > pList, std::string stepperType="")
Set both the explicit and implicit tableau from ParameterList.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getExplicitModel() const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual void initialize()
Initialize during construction and after changing input parameters.
virtual void setExplicitTableau(std::string stepperType, Teuchos::RCP< Teuchos::ParameterList > pList)
Set the explicit tableau from ParameterList.