29 #ifndef Rythmos_BACKWARD_EULER_STEPPER_DEF_H
30 #define Rythmos_BACKWARD_EULER_STEPPER_DEF_H
32 #include "Rythmos_BackwardEulerStepper_decl.hpp"
33 #include "Rythmos_DataStore.hpp"
34 #include "Rythmos_LinearInterpolator.hpp"
35 #include "Rythmos_InterpolatorBaseHelpers.hpp"
36 #include "Rythmos_StepperHelpers.hpp"
37 #include "Rythmos_FixedStepControlStrategy.hpp"
38 #include "Rythmos_SimpleStepControlStrategy.hpp"
39 #include "Rythmos_FirstOrderErrorStepControlStrategy.hpp"
41 #include "Thyra_ModelEvaluatorHelpers.hpp"
42 #include "Thyra_AssertOp.hpp"
43 #include "Thyra_TestingTools.hpp"
45 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
46 #include "Teuchos_as.hpp"
51 template<
class Scalar>
52 RCP<BackwardEulerStepper<Scalar> >
54 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
55 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
61 template<
class Scalar>
62 RCP<BackwardEulerStepper<Scalar> >
63 backwardEulerStepper()
76 template<
class Scalar>
79 typedef Teuchos::ScalarTraits<Scalar> ST;
80 this->defaultInitializeAll_();
86 template<
class Scalar>
88 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
89 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
92 typedef Teuchos::ScalarTraits<Scalar> ST;
93 this->defaultInitializeAll_();
100 template<
class Scalar>
103 typedef Teuchos::ScalarTraits<Scalar> ST;
104 isInitialized_ =
false;
105 haveInitialCondition_ =
false;
106 model_ = Teuchos::null;
107 solver_ = Teuchos::null;
108 x_old_ = Teuchos::null;
109 scaled_x_old_ = Teuchos::null;
110 x_dot_old_ = Teuchos::null;
113 x_dot_ = Teuchos::null;
119 neModel_ = Teuchos::null;
120 parameterList_ = Teuchos::null;
121 interpolator_ = Teuchos::null;
122 stepControl_ = Teuchos::null;
123 newtonConvergenceStatus_ = -1;
128 template<
class Scalar>
133 #ifdef HAVE_RYTHMOS_DEBUG
134 TEUCHOS_TEST_FOR_EXCEPT(is_null(interpolator));
136 interpolator_ = interpolator;
137 isInitialized_ =
false;
140 template<
class Scalar>
141 RCP<InterpolatorBase<Scalar> >
144 return interpolator_;
147 template<
class Scalar>
148 RCP<const InterpolatorBase<Scalar> >
151 return interpolator_;
154 template<
class Scalar>
155 RCP<InterpolatorBase<Scalar> >
158 RCP<InterpolatorBase<Scalar> > temp_interpolator = interpolator_;
159 interpolator_ = Teuchos::null;
161 return temp_interpolator;
168 template<
class Scalar>
170 const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver
175 TEUCHOS_TEST_FOR_EXCEPTION(solver == Teuchos::null, std::logic_error,
176 "Error! Thyra::NonlinearSolverBase RCP passed in through "
177 "BackwardEulerStepper::setSolver is null!");
179 RCP<Teuchos::FancyOStream> out = this->getOStream();
180 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
181 Teuchos::OSTab ostab(out,1,
"BES::setSolver");
182 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
183 *out <<
"solver = " << solver->description() << std::endl;
188 isInitialized_ =
false;
193 template<
class Scalar>
194 RCP<Thyra::NonlinearSolverBase<Scalar> >
201 template<
class Scalar>
202 RCP<const Thyra::NonlinearSolverBase<Scalar> >
212 template<
class Scalar>
219 template<
class Scalar>
220 RCP<StepperBase<Scalar> >
223 RCP<BackwardEulerStepper<Scalar> >
225 stepper->isInitialized_ = isInitialized_;
226 stepper->model_ = model_;
227 if (!is_null(solver_))
228 stepper->solver_ = solver_->cloneNonlinearSolver().assert_not_null();
230 stepper->x_ = x_->clone_v().assert_not_null();
231 if (!is_null(scaled_x_old_))
232 stepper->scaled_x_old_ = scaled_x_old_->clone_v().assert_not_null();
234 stepper->t_old_ = t_old_;
236 stepper->numSteps_ = numSteps_;
237 if (!is_null(neModel_))
240 if (!is_null(parameterList_))
241 stepper->parameterList_ = parameterList(*parameterList_);
242 if (!is_null(interpolator_))
243 stepper->interpolator_
244 = interpolator_->cloneInterpolator().assert_not_null();
245 if (!is_null(stepControl_)) {
246 if (stepControl_->supportsCloning())
247 stepper->setStepControlStrategy(
248 stepControl_->cloneStepControlStrategyAlgorithm().assert_not_null());
253 template<
class Scalar>
259 template<
class Scalar>
261 const RCP<
const Thyra::ModelEvaluator<Scalar> >& model)
265 TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
266 assertValidModel( *
this, *model );
268 RCP<Teuchos::FancyOStream> out = this->getOStream();
269 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
270 Teuchos::OSTab ostab(out,1,
"BES::setModel");
271 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
272 *out <<
"model = " << model->description() << std::endl;
277 template<
class Scalar>
279 const RCP<Thyra::ModelEvaluator<Scalar> >& model
282 this->setModel(model);
285 template<
class Scalar>
286 RCP<const Thyra::ModelEvaluator<Scalar> >
293 template<
class Scalar>
294 RCP<Thyra::ModelEvaluator<Scalar> >
297 return Teuchos::null;
301 template<
class Scalar>
303 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition)
306 typedef Teuchos::ScalarTraits<Scalar> ST;
309 basePoint_ = initialCondition;
312 RCP<const Thyra::VectorBase<Scalar> > x_init = initialCondition.get_x();
313 TEUCHOS_TEST_FOR_EXCEPTION(
314 is_null(x_init), std::logic_error,
315 "Error, if the client passes in an intial condition to "
316 "setInitialCondition(...), then x can not be null!" );
317 x_ = x_init->clone_v();
320 RCP<const Thyra::VectorBase<Scalar> >
321 x_dot_init = initialCondition.get_x_dot();
322 if (!is_null(x_dot_init)) {
323 x_dot_ = x_dot_init->clone_v();
326 x_dot_ = createMember(x_->space());
327 V_S(x_dot_.ptr(),ST::zero());
331 if (is_null(dx_)) dx_ = createMember(x_->space());
332 V_S(dx_.ptr(), ST::zero());
335 t_ = initialCondition.get_t();
339 if (is_null(x_old_)) x_old_ = createMember(x_->space());
340 x_old_ = x_init->clone_v();
341 scaled_x_old_ = x_->clone_v();
344 if (is_null(x_dot_old_)) x_dot_old_ = createMember(x_->space());
345 x_dot_old_ = x_dot_->clone_v();
347 haveInitialCondition_ =
true;
351 template<
class Scalar>
352 Thyra::ModelEvaluatorBase::InArgs<Scalar>
358 template<
class Scalar>
362 TEUCHOS_TEST_FOR_EXCEPTION(stepControl == Teuchos::null,std::logic_error,
363 "Error, stepControl == Teuchos::null!\n");
364 stepControl_ = stepControl;
367 template<
class Scalar>
368 RCP<StepControlStrategyBase<Scalar> >
371 return(stepControl_);
374 template<
class Scalar>
375 RCP<const StepControlStrategyBase<Scalar> >
378 return(stepControl_);
381 template<
class Scalar>
383 StepSizeType stepSizeType)
387 using Teuchos::incrVerbLevel;
388 typedef Teuchos::ScalarTraits<Scalar> ST;
389 typedef Thyra::NonlinearSolverBase<Scalar> NSB;
390 typedef Teuchos::VerboseObjectTempState<NSB> VOTSNSB;
392 RCP<Teuchos::FancyOStream> out = this->getOStream();
393 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
394 Teuchos::OSTab ostab(out,1,
"BES::takeStep");
395 VOTSNSB solver_outputTempState(solver_,out,incrVerbLevel(verbLevel,-1));
397 if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
398 *out <<
"\nEntering "
399 << Teuchos::TypeNameTraits<BackwardEulerStepper<Scalar> >::name()
400 <<
"::takeStep("<<dt<<
","<<toString(stepSizeType)<<
") ...\n";
405 if(!neModel_.get()) {
411 if (dt <= ST::zero()) {
412 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) )
413 *out <<
"\nThe arguments to takeStep are not valid for "
414 <<
"BackwardEulerStepper at this time.\n"
415 <<
" dt = " << dt <<
"\n"
416 <<
"BackwardEulerStepper requires positive dt.\n" << std::endl;
417 return(Scalar(-ST::one()));
419 if ((stepSizeType == STEP_TYPE_VARIABLE) && (stepControl_ == Teuchos::null)) {
420 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) )
421 *out <<
"\nFor 'variable' time stepping (step size adjustable by "
422 <<
"BackwardEulerStepper), BackwardEulerStepper requires "
423 <<
"Step-Control Strategy.\n"
424 <<
" stepType = " << toString(stepSizeType) <<
"\n" << std::endl;
425 return(Scalar(-ST::one()));
428 stepControl_->setRequestedStepSize(*
this,dt_,stepSizeType);
429 AttemptedStepStatusFlag status;
430 bool stepPass =
false;
433 stepControl_->nextStepSize(*
this,&dt_,&stepSizeType,NULL);
434 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
435 *out <<
"\nrequested dt = " << dt
436 <<
"\ncurrent dt = " << dt_ <<
"\n";
443 V_StV( scaled_x_old_.ptr(), Scalar(-ST::one()/dt_), *x_old_ );
445 neModel_->initializeSingleResidualModel(
447 Scalar(ST::one()/dt_), scaled_x_old_,
448 ST::one(), Teuchos::null,
452 if( solver_->getModel().get() != neModel_.get() ) {
453 solver_->setModel(neModel_);
462 if ( as<int>(verbLevel) > as<int>(Teuchos::VERB_LOW) ) {
463 *out <<
"\nSolving the implicit backward-Euler timestep equation ...\n";
466 Thyra::SolveStatus<Scalar> neSolveStatus =
467 solver_->solve(&*x_, NULL, &*dx_);
474 if ( as<int>(verbLevel) > as<int>(Teuchos::VERB_LOW) ) {
475 *out <<
"\nOutput status of nonlinear solve:\n" << neSolveStatus;
483 if (neSolveStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED) {
484 newtonConvergenceStatus_ = 0;
487 newtonConvergenceStatus_ = -1;
490 stepControl_->setCorrection(*
this,x_,dx_,newtonConvergenceStatus_);
492 stepPass = stepControl_->acceptStep(*
this,NULL);
495 status = stepControl_->rejectStep(*
this);
497 if (status != PREDICT_AGAIN)
507 V_V( x_dot_old_.ptr(), *x_dot_ );
509 V_StVpStV( x_dot_.ptr(), Scalar(ST::one()/dt_), *x_,
510 Scalar(-ST::one()/dt_), *x_old_ );
511 V_V( x_old_.ptr(), *x_ );
514 stepControl_->completeStep(*
this);
517 dt_ = Scalar(-ST::one());
520 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
521 *out <<
"\nt_old_ = " << t_old_ << std::endl;
522 *out <<
"\nt_ = " << t_ << std::endl;
525 #ifdef HAVE_RYTHMOS_DEBUG
528 if ( includesVerbLevel(verbLevel,Teuchos::VERB_LOW) )
529 *out <<
"\nChecking to make sure that solution and "
530 <<
"the interpolated solution are the same! ...\n";
534 typedef ScalarTraits<ScalarMag> SMT;
536 Teuchos::OSTab tab(out);
540 RCP<const Thyra::VectorBase<Scalar> >
544 Array<Scalar> time_vec = Teuchos::tuple(stepStatus.
time);
545 Array<RCP<const Thyra::VectorBase<Scalar> > > x_vec, xdot_vec;
546 this->getPoints(time_vec,&x_vec,&xdot_vec,0);
548 RCP<const Thyra::VectorBase<Scalar> >
550 xdot_interp = xdot_vec[0];
552 TEUCHOS_TEST_FOR_EXCEPT(
553 !Thyra::testRelNormDiffErr(
554 "x", *x,
"x_interp", *x_interp,
555 "2*epsilon",
ScalarMag(100.0*SMT::eps()),
556 "2*epsilon",
ScalarMag(100.0*SMT::eps()),
557 includesVerbLevel(verbLevel,Teuchos::VERB_HIGH) ? out.get() : 0
561 TEUCHOS_TEST_FOR_EXCEPT(
562 !Thyra::testRelNormDiffErr(
563 "xdot", *xdot,
"xdot_interp", *xdot_interp,
564 "2*epsilon",
ScalarMag(100.0*SMT::eps()),
565 "2*epsilon",
ScalarMag(100.0*SMT::eps()),
566 includesVerbLevel(verbLevel,Teuchos::VERB_HIGH) ? out.get() : 0
575 #endif // HAVE_RYTHMOS_DEBUG
577 if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
579 << Teuchos::TypeNameTraits<BackwardEulerStepper<Scalar> >::name()
580 <<
"::takeStep("<<dt_<<
","<<toString(stepSizeType)<<
") ...\n";
587 template<
class Scalar>
595 if (!isInitialized_) {
596 stepStatus.
stepStatus = STEP_STATUS_UNINITIALIZED;
598 else if (numSteps_ > 0) {
599 stepStatus.
stepStatus = STEP_STATUS_CONVERGED;
604 stepStatus.
order = 1;
605 stepStatus.
time = t_;
617 template<
class Scalar>
618 RCP<const Thyra::VectorSpaceBase<Scalar> >
621 return ( !is_null(model_) ? model_->get_x_space() : Teuchos::null );
625 template<
class Scalar>
627 const Array<Scalar>& time_vec,
628 const Array<RCP<
const Thyra::VectorBase<Scalar> > >& x_vec,
629 const Array<RCP<
const Thyra::VectorBase<Scalar> > >&
633 typedef Teuchos::ScalarTraits<Scalar> ST;
638 #ifdef HAVE_RYTHMOS_DEBUG
639 TEUCHOS_TEST_FOR_EXCEPTION(
640 time_vec.size() == 0, std::logic_error,
641 "Error, addPoints called with an empty time_vec array!\n");
642 #endif // HAVE_RYTHMOS_DEBUG
644 RCP<Teuchos::FancyOStream> out = this->getOStream();
645 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
646 Teuchos::OSTab ostab(out,1,
"BES::setPoints");
648 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
649 *out <<
"time_vec = " << std::endl;
650 for (
int i=0 ; i<Teuchos::as<int>(time_vec.size()) ; ++i) {
651 *out <<
"time_vec[" << i <<
"] = " << time_vec[i] << std::endl;
654 else if (time_vec.size() == 1) {
658 Thyra::V_V(x_.ptr(),*x_vec[n]);
659 Thyra::V_V(scaled_x_old_.ptr(),*x_);
662 int n = time_vec.size()-1;
663 int nm1 = time_vec.size()-2;
665 t_old_ = time_vec[nm1];
666 Thyra::V_V(x_.ptr(),*x_vec[n]);
667 Scalar dt = t_ - t_old_;
668 Thyra::V_StV(scaled_x_old_.ptr(),Scalar(-ST::one()/dt),*x_vec[nm1]);
673 template<
class Scalar>
676 if ( !isInitialized_ && haveInitialCondition_ )
677 return timeRange<Scalar>(t_,t_);
678 if ( !isInitialized_ && !haveInitialCondition_ )
679 return invalidTimeRange<Scalar>();
680 return timeRange<Scalar>(t_old_,t_);
684 template<
class Scalar>
686 const Array<Scalar>& time_vec,
687 Array<RCP<
const Thyra::VectorBase<Scalar> > >* x_vec,
688 Array<RCP<
const Thyra::VectorBase<Scalar> > >* xdot_vec,
689 Array<ScalarMag>* accuracy_vec
692 typedef Teuchos::ScalarTraits<Scalar> ST;
693 using Teuchos::constOptInArg;
695 #ifdef HAVE_RYTHMOS_DEBUG
696 TEUCHOS_ASSERT(haveInitialCondition_);
697 #endif // HAVE_RYTHMOS_DEBUG
698 RCP<Thyra::VectorBase<Scalar> > x_temp = x_;
699 if (compareTimeValues(t_old_,t_)!=0) {
700 Scalar dt = t_ - t_old_;
701 x_temp = scaled_x_old_->clone_v();
702 Thyra::Vt_S(x_temp.ptr(),Scalar(-ST::one()*dt));
704 defaultGetPoints<Scalar>(
705 t_old_, constOptInArg(*x_temp), constOptInArg(*x_dot_old_),
706 t_, constOptInArg(*x_), constOptInArg(*x_dot_),
707 time_vec, ptr(x_vec), ptr(xdot_vec), ptr(accuracy_vec),
708 ptr(interpolator_.get())
812 template<
class Scalar>
817 TEUCHOS_ASSERT( time_vec != NULL );
821 if (!haveInitialCondition_) {
825 time_vec->push_back(t_old_);
828 time_vec->push_back(t_);
831 RCP<Teuchos::FancyOStream> out = this->getOStream();
832 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
833 Teuchos::OSTab ostab(out,1,
"BES::getNodes");
834 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
835 *out << this->description() << std::endl;
836 for (
int i=0 ; i<Teuchos::as<int>(time_vec->size()) ; ++i) {
837 *out <<
"time_vec[" << i <<
"] = " << (*time_vec)[i] << std::endl;
843 template<
class Scalar>
848 RCP<Teuchos::FancyOStream> out = this->getOStream();
849 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
850 Teuchos::OSTab ostab(out,1,
"BES::removeNodes");
851 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
852 *out <<
"time_vec = " << std::endl;
853 for (
int i=0 ; i<Teuchos::as<int>(time_vec.size()) ; ++i) {
854 *out <<
"time_vec[" << i <<
"] = " << time_vec[i] << std::endl;
857 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Error, removeNodes is not implemented for BackwardEulerStepper at this time.\n");
865 template<
class Scalar>
875 template <
class Scalar>
877 RCP<Teuchos::ParameterList>
const& paramList
880 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
881 paramList->validateParametersAndSetDefaults(*this->getValidParameters());
882 parameterList_ = paramList;
883 Teuchos::readVerboseObjectSublist(&*parameterList_,
this);
887 template <
class Scalar>
888 RCP<Teuchos::ParameterList>
891 return(parameterList_);
895 template <
class Scalar>
896 RCP<Teuchos::ParameterList>
899 RCP<Teuchos::ParameterList>
900 temp_param_list = parameterList_;
901 parameterList_ = Teuchos::null;
902 return(temp_param_list);
906 template<
class Scalar>
907 RCP<const Teuchos::ParameterList>
910 using Teuchos::ParameterList;
911 static RCP<const ParameterList> validPL;
912 if (is_null(validPL)) {
913 RCP<ParameterList> pl = Teuchos::parameterList();
915 pl->sublist(RythmosStepControlSettings_name);
916 Teuchos::setupVerboseObjectSublist(&*pl);
926 template<
class Scalar>
928 Teuchos::FancyOStream &out,
929 const Teuchos::EVerbosityLevel verbLevel
933 Teuchos::OSTab tab(out);
934 if (!isInitialized_) {
935 out << this->description() <<
" : This stepper is not initialized yet"
940 as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT)
942 as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)
945 out << this->description() <<
"::describe:" << std::endl;
946 out <<
"model = " << model_->description() << std::endl;
947 out <<
"solver = " << solver_->description() << std::endl;
948 if (neModel_ == Teuchos::null) {
949 out <<
"neModel = Teuchos::null" << std::endl;
951 out <<
"neModel = " << neModel_->description() << std::endl;
954 else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
955 out <<
"t_ = " << t_ << std::endl;
956 out <<
"t_old_ = " << t_old_ << std::endl;
958 else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_MEDIUM)) {
960 else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH)) {
961 out <<
"model_ = " << std::endl;
962 model_->describe(out,verbLevel);
963 out <<
"solver_ = " << std::endl;
964 solver_->describe(out,verbLevel);
965 if (neModel_ == Teuchos::null) {
966 out <<
"neModel = Teuchos::null" << std::endl;
968 out <<
"neModel = " << std::endl;
969 neModel_->describe(out,verbLevel);
971 out <<
"x_ = " << std::endl;
972 x_->describe(out,verbLevel);
973 out <<
"scaled_x_old_ = " << std::endl;
974 scaled_x_old_->describe(out,verbLevel);
982 template <
class Scalar>
986 if (isInitialized_)
return;
988 TEUCHOS_TEST_FOR_EXCEPT(is_null(model_));
989 TEUCHOS_TEST_FOR_EXCEPT(is_null(solver_));
990 TEUCHOS_TEST_FOR_EXCEPT(!haveInitialCondition_);
993 if (parameterList_ == Teuchos::null) {
994 RCP<Teuchos::ParameterList> emptyParameterList =
995 Teuchos::rcp(
new Teuchos::ParameterList);
996 this->setParameterList(emptyParameterList);
1000 if (stepControl_ == Teuchos::null) {
1001 RCP<StepControlStrategyBase<Scalar> > stepControlStrategy =
1002 Teuchos::rcp(
new FixedStepControlStrategy<Scalar>());
1003 RCP<Teuchos::ParameterList> stepControlPL =
1004 Teuchos::sublist(parameterList_, RythmosStepControlSettings_name);
1006 stepControlStrategy->setParameterList(stepControlPL);
1007 this->setStepControlStrategy(stepControlStrategy);
1009 stepControl_->initialize(*
this);
1010 stepControl_->setOStream(this->getOStream());
1011 stepControl_->setVerbLevel(this->getVerbLevel());
1015 #ifdef HAVE_RYTHMOS_DEBUG
1016 THYRA_ASSERT_VEC_SPACES(
1017 "Rythmos::BackwardEulerStepper::initialize_(...)",
1018 *x_->space(), *model_->get_x_space() );
1019 #endif // HAVE_RYTHMOS_DEBUG
1021 if ( is_null(interpolator_) ) {
1024 interpolator_ = linearInterpolator<Scalar>();
1028 isInitialized_ =
true;
1032 template<
class Scalar>
1033 RCP<const MomentoBase<Scalar> >
1036 RCP<BackwardEulerStepperMomento<Scalar> > momento =
1038 momento->set_scaled_x_old(scaled_x_old_);
1039 momento->set_x_old(x_old_);
1040 momento->set_x_dot_old(x_dot_old_);
1042 momento->set_x_dot(x_dot_);
1043 momento->set_dx(dx_);
1045 momento->set_t_old(t_old_);
1046 momento->set_dt(dt_);
1047 momento->set_numSteps(numSteps_);
1048 momento->set_newtonConvergenceStatus(newtonConvergenceStatus_);
1049 momento->set_isInitialized(isInitialized_);
1050 momento->set_haveInitialCondition(haveInitialCondition_);
1051 momento->set_parameterList(parameterList_);
1052 momento->set_basePoint(basePoint_);
1053 momento->set_neModel(neModel_);
1054 momento->set_interpolator(interpolator_);
1055 momento->set_stepControl(stepControl_);
1059 template<
class Scalar>
1062 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
1063 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
1066 Ptr<const BackwardEulerStepperMomento<Scalar> > beMomentoPtr =
1072 scaled_x_old_ = beMomento.get_scaled_x_old();
1073 x_old_ = beMomento.get_x_old();
1074 x_dot_old_ = beMomento.get_x_dot_old();
1075 x_ = beMomento.get_x();
1076 x_dot_ = beMomento.get_x_dot();
1077 dx_ = beMomento.get_dx();
1078 t_ = beMomento.get_t();
1079 t_old_ = beMomento.get_t_old();
1080 dt_ = beMomento.get_dt();
1081 numSteps_ = beMomento.get_numSteps();
1082 newtonConvergenceStatus_ = beMomento.get_newtonConvergenceStatus();
1083 isInitialized_ = beMomento.get_isInitialized();
1084 haveInitialCondition_ = beMomento.get_haveInitialCondition();
1085 parameterList_ = beMomento.get_parameterList();
1086 basePoint_ = beMomento.get_basePoint();
1087 neModel_ = beMomento.get_neModel();
1088 interpolator_ = beMomento.get_interpolator();
1089 stepControl_ = beMomento.get_stepControl();
1090 this->checkConsistentState_();
1093 template<
class Scalar>
1096 if (isInitialized_) {
1097 TEUCHOS_ASSERT( !Teuchos::is_null(model_) );
1098 TEUCHOS_ASSERT( !Teuchos::is_null(solver_) );
1099 TEUCHOS_ASSERT( haveInitialCondition_ );
1100 TEUCHOS_ASSERT( !Teuchos::is_null(interpolator_) );
1101 TEUCHOS_ASSERT( !Teuchos::is_null(stepControl_) );
1103 if (haveInitialCondition_) {
1105 typedef Teuchos::ScalarTraits<Scalar> ST;
1106 TEUCHOS_ASSERT( !ST::isnaninf(t_) );
1107 TEUCHOS_ASSERT( !ST::isnaninf(t_old_) );
1108 TEUCHOS_ASSERT( !Teuchos::is_null(scaled_x_old_) );
1109 TEUCHOS_ASSERT( !Teuchos::is_null(x_dot_old_) );
1110 TEUCHOS_ASSERT( !Teuchos::is_null(x_) );
1111 TEUCHOS_ASSERT( !Teuchos::is_null(x_dot_) );
1112 TEUCHOS_ASSERT( !Teuchos::is_null(x_old_) );
1113 TEUCHOS_ASSERT( !Teuchos::is_null(dx_) );
1114 TEUCHOS_ASSERT( t_ >= basePoint_.get_t() );
1115 TEUCHOS_ASSERT( t_old_ >= basePoint_.get_t() );
1117 if (numSteps_ > 0) {
1118 TEUCHOS_ASSERT(isInitialized_);
1122 template<
class Scalar>
1123 void BackwardEulerStepper<Scalar>::obtainPredictor_()
1128 if (!isInitialized_)
return;
1130 RCP<Teuchos::FancyOStream> out = this->getOStream();
1131 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1132 Teuchos::OSTab ostab(out,1,
"obtainPredictor_");
1134 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1135 *out <<
"Before predictor x_ = " << std::endl;
1136 x_->describe(*out,verbLevel);
1140 V_StVpV(x_.ptr(), dt_, *x_dot_old_, *x_old_);
1142 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1143 *out <<
"After predictor x_ = " << std::endl;
1144 x_->describe(*out,verbLevel);
1154 #define RYTHMOS_BACKWARD_EULER_STEPPER_INSTANT(SCALAR) \
1156 template class BackwardEulerStepper< SCALAR >; \
1158 template RCP< BackwardEulerStepper< SCALAR > > \
1159 backwardEulerStepper( \
1160 const RCP<Thyra::ModelEvaluator< SCALAR > >& model, \
1161 const RCP<Thyra::NonlinearSolverBase< SCALAR > >& solver \
1163 template RCP< BackwardEulerStepper< SCALAR > > \
1164 backwardEulerStepper();
1171 #endif //Rythmos_BACKWARD_EULER_STEPPER_DEF_H
Simple concrete stepper subclass implementing an implicit backward Euler method.
bool supportsCloning() const
Returns true.
Base strategy class for interpolation functionality.
RCP< const InterpolatorBase< Scalar > > getInterpolator() const
void setSolver(const RCP< Thyra::NonlinearSolverBase< Scalar > > &solver)
void setStepControlStrategy(const RCP< StepControlStrategyBase< Scalar > > &stepControlStrategy)
void getNodes(Array< Scalar > *time_vec) const
RCP< Teuchos::ParameterList > unsetParameterList()
void setInitialCondition(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initialCondition)
void setModel(const RCP< const Thyra::ModelEvaluator< Scalar > > &model)
void removeNodes(Array< Scalar > &time_vec)
Scalar takeStep(Scalar dt, StepSizeType flag)
void addPoints(const Array< Scalar > &time_vec, const Array< RCP< const Thyra::VectorBase< Scalar > > > &x_vec, const Array< RCP< const Thyra::VectorBase< Scalar > > > &xdot_vec)
RCP< Teuchos::ParameterList > getNonconstParameterList()
RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
RCP< StepControlStrategyBase< Scalar > > getNonconstStepControlStrategy()
The member functions in the StepControlStrategyBase move you between these states in the following fa...
void setNonconstModel(const RCP< Thyra::ModelEvaluator< Scalar > > &model)
RCP< InterpolatorBase< Scalar > > unSetInterpolator()
Thyra::ModelEvaluatorBase::InArgs< Scalar > getInitialCondition() const
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
void getPoints(const Array< Scalar > &time_vec, Array< RCP< const Thyra::VectorBase< Scalar > > > *x_vec, Array< RCP< const Thyra::VectorBase< Scalar > > > *xdot_vec, Array< ScalarMag > *accuracy_vec) const
RCP< const Thyra::VectorBase< Scalar > > solutionDot
void setMomento(const Ptr< const MomentoBase< Scalar > > &momentoPtr, const RCP< Thyra::ModelEvaluator< Scalar > > &model, const RCP< Thyra::NonlinearSolverBase< Scalar > > &solver)
Set momento object for use in restarts.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Concrete momento class for the BackwardEulerStepper.
RCP< Thyra::NonlinearSolverBase< Scalar > > getNonconstSolver()
RCP< const MomentoBase< Scalar > > getMomento() const
Get momento object for use in restarts.
Decorator subclass for a steady-state version of a DAE for single-residual time stepper methods...
RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
RCP< const StepControlStrategyBase< Scalar > > getStepControlStrategy() const
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< StepperBase< Scalar > > cloneStepperAlgorithm() const
Creates copies of all internal data (including the parameter list) except the model which is assumed ...
const StepStatus< Scalar > getStepStatus() const
RCP< const Thyra::VectorBase< Scalar > > solution
RCP< const Thyra::NonlinearSolverBase< Scalar > > getSolver() const
RCP< InterpolatorBase< Scalar > > getNonconstInterpolator()
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
RCP< Thyra::ModelEvaluator< Scalar > > getNonconstModel()
Base class for a momento object.
void setInterpolator(const RCP< InterpolatorBase< Scalar > > &interpolator)
TimeRange< Scalar > getTimeRange() const