29 #ifndef Rythmos_IMPLICITBDF_STEPPER_DEF_H
30 #define Rythmos_IMPLICITBDF_STEPPER_DEF_H
32 #include "Rythmos_ImplicitBDFStepper_decl.hpp"
33 #include "Rythmos_StepperHelpers.hpp"
34 #include "Rythmos_ImplicitBDFStepperStepControl.hpp"
42 template<
class Scalar>
43 RCP<ImplicitBDFStepper<Scalar> > implicitBDFStepper() {
44 RCP<ImplicitBDFStepper<Scalar> >
45 stepper = rcp(
new ImplicitBDFStepper<Scalar>() );
49 template<
class Scalar>
50 RCP<ImplicitBDFStepper<Scalar> > implicitBDFStepper(
51 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
52 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
55 RCP<ImplicitBDFStepper<Scalar> >
56 stepper = Teuchos::rcp(
new ImplicitBDFStepper<Scalar>(model, solver));
60 template<
class Scalar>
61 RCP<ImplicitBDFStepper<Scalar> > implicitBDFStepper(
62 const RCP<Thyra::ModelEvaluator<Scalar> >& model,
63 const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
64 const RCP<Teuchos::ParameterList>& parameterList
67 RCP<ImplicitBDFStepper<Scalar> >
68 stepper = Teuchos::rcp(
new ImplicitBDFStepper<Scalar>(model,
77 template<
class Scalar>
80 this->defaultInitializeAll_();
81 haveInitialCondition_ =
false;
86 template<
class Scalar>
88 const RCP<Thyra::ModelEvaluator<Scalar> >& model
89 ,
const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
90 ,
const RCP<Teuchos::ParameterList>& parameterList
93 this->defaultInitializeAll_();
94 this->setParameterList(parameterList);
98 haveInitialCondition_ =
false;
103 template<
class Scalar>
105 const RCP<Thyra::ModelEvaluator<Scalar> >& model
106 ,
const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
109 this->defaultInitializeAll_();
113 haveInitialCondition_ =
false;
114 isInitialized_=
false;
117 template<
class Scalar>
118 const Thyra::VectorBase<Scalar>&
121 TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
122 "Error, attempting to call getxHistory before initialization!\n");
123 TEUCHOS_TEST_FOR_EXCEPT( !(( 0 <= index ) && ( index <= maxOrder_ )) );
124 TEUCHOS_TEST_FOR_EXCEPT( !( index <= usedOrder_+1 ) );
125 return(*(xHistory_[index]));
128 template<
class Scalar>
131 TEUCHOS_TEST_FOR_EXCEPTION(stepControl == Teuchos::null,std::logic_error,
"Error, stepControl == Teuchos::null!\n");
132 stepControl_ = stepControl;
135 template<
class Scalar>
138 return(stepControl_);
141 template<
class Scalar>
144 return(stepControl_);
151 template<
class Scalar>
154 TEUCHOS_TEST_FOR_EXCEPT(solver == Teuchos::null)
159 template<
class Scalar>
160 RCP<Thyra::NonlinearSolverBase<Scalar> >
167 template<
class Scalar>
168 RCP<const Thyra::NonlinearSolverBase<Scalar> >
178 template<
class Scalar>
184 template<
class Scalar>
191 template<
class Scalar>
192 RCP<StepperBase<Scalar> >
199 RCP<ImplicitBDFStepper<Scalar> >
202 if (!is_null(model_))
203 stepper->setModel(model_);
205 if (!is_null(solver_))
206 stepper->setSolver(solver_->cloneNonlinearSolver().assert_not_null());
208 if (!is_null(parameterList_))
209 stepper->setParameterList(Teuchos::parameterList(*parameterList_));
211 if (!is_null(stepControl_)) {
212 if (stepControl_->supportsCloning())
213 stepper->setStepControlStrategy(
214 stepControl_->cloneStepControlStrategyAlgorithm().assert_not_null());
227 template<
class Scalar>
229 const RCP<
const Thyra::ModelEvaluator<Scalar> >& model
232 typedef Teuchos::ScalarTraits<Scalar> ST;
233 TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
234 assertValidModel( *
this, *model );
238 template<
class Scalar>
240 const RCP<Thyra::ModelEvaluator<Scalar> >& model
243 this->setModel(model);
247 template<
class Scalar>
248 RCP<const Thyra::ModelEvaluator<Scalar> >
255 template<
class Scalar>
256 RCP<Thyra::ModelEvaluator<Scalar> >
259 return Teuchos::null;
263 template<
class Scalar>
265 const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
268 typedef Teuchos::ScalarTraits<Scalar> ST;
269 typedef Thyra::ModelEvaluatorBase MEB;
270 TEUCHOS_TEST_FOR_EXCEPT(is_null(initialCondition.get_x()));
271 TEUCHOS_TEST_FOR_EXCEPT(is_null(initialCondition.get_x_dot()));
272 basePoint_ = initialCondition;
273 xn0_ = initialCondition.get_x()->clone_v();
274 xpn0_ = initialCondition.get_x_dot()->clone_v();
275 time_ = initialCondition.get_t();
277 x_dot_base_ = createMember(xpn0_->space());
278 V_S(x_dot_base_.ptr(),ST::zero());
279 ee_ = createMember(xn0_->space());
280 V_S(ee_.ptr(),ST::zero());
283 xHistory_.push_back(xn0_->clone_v());
284 xHistory_.push_back(xpn0_->clone_v());
286 haveInitialCondition_ =
true;
287 if (isInitialized_) {
293 template<
class Scalar>
294 Thyra::ModelEvaluatorBase::InArgs<Scalar>
301 template<
class Scalar>
305 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos::ImplicitBDFStepper::takeStep");
308 using Teuchos::incrVerbLevel;
309 typedef Teuchos::ScalarTraits<Scalar> ST;
310 typedef typename Thyra::ModelEvaluatorBase::InArgs<Scalar>::ScalarMag TScalarMag;
311 typedef Thyra::NonlinearSolverBase<Scalar> NSB;
312 typedef Teuchos::VerboseObjectTempState<NSB> VOTSNSB;
314 RCP<Teuchos::FancyOStream> out = this->getOStream();
315 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
316 Teuchos::OSTab ostab(out,1,
"takeStep");
317 VOTSNSB solver_outputTempState(solver_,out,incrVerbLevel(verbLevel,-1));
319 if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
321 <<
"\nEntering " << this->Teuchos::Describable::description()
322 <<
"::takeStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
325 if (!isInitialized_) {
329 stepControl_->setOStream(out);
330 stepControl_->setVerbLevel(verbLevel);
331 stepControl_->setRequestedStepSize(*
this,dt,stepType);
333 AttemptedStepStatusFlag status;
338 stepControl_->nextStepSize(*
this,&hh_,&stepType,&desiredOrder);
339 TEUCHOS_TEST_FOR_EXCEPT(!((1 <= desiredOrder) && (desiredOrder <= maxOrder_)));
340 TEUCHOS_TEST_FOR_EXCEPT(!(desiredOrder <= usedOrder_+1));
341 currentOrder_ = desiredOrder;
342 if (numberOfSteps_ == 0) {
345 Vt_S(xHistory_[1].ptr(),hh_);
347 Vt_S(xHistory_[1].ptr(),hh_/hh_old);
350 this->updateCoeffs_();
365 Scalar coeff_x_dot = Scalar(-ST::one())*alpha_s_/hh_;
366 V_StVpStV( x_dot_base_.ptr(), ST::one(), *xpn0_, alpha_s_/hh_, *xn0_ );
367 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
368 *out <<
"model_ = " << std::endl;
369 model_->describe(*out,verbLevel);
370 *out <<
"basePoint_ = " << std::endl;
371 basePoint_.describe(*out,verbLevel);
372 *out <<
"coeff_x_dot = " << coeff_x_dot << std::endl;
373 *out <<
"x_dot_base_ = " << std::endl;
374 x_dot_base_->describe(*out,verbLevel);
375 *out <<
"time_+hh_ = " << time_+hh_ << std::endl;
376 *out <<
"xn0_ = " << std::endl;
377 xn0_->describe(*out,verbLevel);
379 neModel_.initializeSingleResidualModel(
381 coeff_x_dot, x_dot_base_,
382 ST::one(), Teuchos::null,
389 if (solver_->getModel().get() != &neModel_) {
390 solver_->setModel( Teuchos::rcpFromRef(neModel_) );
399 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
400 *out <<
"xn0 = " << std::endl;
401 xn0_->describe(*out,verbLevel);
402 *out <<
"ee = " << std::endl;
403 ee_->describe(*out,verbLevel);
405 Thyra::SolveStatus<Scalar> nonlinearSolveStatus = solver_->solve( &*xn0_, NULL, &*ee_ );
406 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
407 *out <<
"xn0 = " << std::endl;
408 xn0_->describe(*out,verbLevel);
409 *out <<
"ee = " << std::endl;
410 ee_->describe(*out,verbLevel);
416 if (nonlinearSolveStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED) {
417 newtonConvergenceStatus_ = 0;
420 newtonConvergenceStatus_ = -1;
424 stepControl_->setCorrection(*
this,xn0_,ee_,newtonConvergenceStatus_);
425 bool stepPass = stepControl_->acceptStep(*
this,&LETvalue_);
427 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
428 *out <<
"xn0_ = " << std::endl;
429 xn0_->describe(*out,verbLevel);
430 *out <<
"xpn0_ = " << std::endl;
431 xpn0_->describe(*out,verbLevel);
432 *out <<
"ee_ = " << std::endl;
433 ee_->describe(*out,verbLevel);
434 for (
int i=0; i<std::max(2,maxOrder_); ++i) {
435 *out <<
"xHistory_[" << i <<
"] = " << std::endl;
436 xHistory_[i]->describe(*out,verbLevel);
442 stepLETStatus_ = STEP_LET_STATUS_FAILED;
443 status = stepControl_->rejectStep(*
this);
445 if (status == CONTINUE_ANYWAY) {
451 stepLETStatus_ = STEP_LET_STATUS_PASSED;
458 stepControl_->completeStep(*
this);
460 if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
462 <<
"\nLeaving " << this->Teuchos::Describable::description()
463 <<
"::takeStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
471 template<
class Scalar>
478 typedef Teuchos::ScalarTraits<Scalar> ST;
480 if (!isInitialized_) {
481 stepStatus.
message =
"This stepper is uninitialized.";
482 stepStatus.
stepStatus = STEP_STATUS_UNINITIALIZED;
483 stepStatus.
stepSize = Scalar(-ST::one());
484 stepStatus.
order = -1;
485 stepStatus.
time = Scalar(-ST::one());
489 if (numberOfSteps_ > 0) {
490 stepStatus.
stepStatus = STEP_STATUS_CONVERGED;
496 stepStatus.
order = usedOrder_;
497 stepStatus.
time = time_;
501 stepStatus.
residual = Teuchos::null;
511 template<
class Scalar>
512 RCP<const Thyra::VectorSpaceBase<Scalar> >
516 return ( !is_null(model_) ? model_->get_x_space() : Teuchos::null );
520 template<
class Scalar>
522 const Array<Scalar>& time_vec,
523 const Array<RCP<
const Thyra::VectorBase<Scalar> > >& x_vec,
524 const Array<RCP<
const Thyra::VectorBase<Scalar> > >& xdot_vec
527 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
528 "Error, addPoints is not implemented for ImplicitBDFStepper.\n");
532 template<
class Scalar>
535 if ( !isInitialized_ && haveInitialCondition_ )
536 return timeRange<Scalar>(time_,time_);
537 if ( !isInitialized_ && !haveInitialCondition_ )
538 return invalidTimeRange<Scalar>();
539 return timeRange<Scalar>(time_-usedStep_,time_);
543 template<
class Scalar>
545 const Array<Scalar>& time_vec
546 ,Array<RCP<
const Thyra::VectorBase<Scalar> > >* x_vec
547 ,Array<RCP<
const Thyra::VectorBase<Scalar> > >* xdot_vec
548 ,Array<ScalarMag>* accuracy_vec)
const
551 using Teuchos::constOptInArg;
554 typedef Teuchos::ScalarTraits<Scalar> ST;
555 typedef typename ST::magnitudeType mScalarMag;
557 TEUCHOS_ASSERT(haveInitialCondition_);
559 if ( (numberOfSteps_ == -1) &&
560 (time_vec.length() == 1) &&
561 (compareTimeValues<Scalar>(time_vec[0],time_)==0) ) {
562 defaultGetPoints<Scalar>(
563 time_, constOptInArg(*xn0_), constOptInArg(*xpn0_),
564 time_, constOptInArg(*xn0_), constOptInArg(*xpn0_),
565 time_vec, ptr(x_vec), ptr(xdot_vec), ptr(accuracy_vec),
566 Ptr<InterpolatorBase<Scalar> >(null)
570 TEUCHOS_ASSERT(isInitialized_);
571 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos::ImplicitBDFStepper::getPoints");
576 for (Teuchos::Ordinal i=0 ; i<time_vec.size() ; ++i) {
577 RCP<Thyra::VectorBase<Scalar> >
578 x_temp = createMember(xn0_->space());
579 RCP<Thyra::VectorBase<Scalar> >
580 xdot_temp = createMember(xn0_->space());
581 mScalarMag accuracy = -ST::zero();
582 interpolateSolution_(
583 time_vec[i], &*x_temp, &*xdot_temp,
584 accuracy_vec ? &accuracy : 0
587 x_vec->push_back(x_temp);
589 xdot_vec->push_back(xdot_temp);
591 accuracy_vec->push_back(accuracy);
593 if ( as<int>(this->getVerbLevel()) >= as<int>(Teuchos::VERB_HIGH) ) {
594 RCP<Teuchos::FancyOStream> out = this->getOStream();
595 Teuchos::OSTab ostab(out,1,
"getPoints");
596 *out <<
"Passing out the interpolated values:" << std::endl;
597 for (Teuchos::Ordinal i=0; i<time_vec.size() ; ++i) {
598 *out <<
"time_[" << i <<
"] = " << time_vec[i] << std::endl;
600 *out <<
"x_vec[" << i <<
"] = " << std::endl;
601 (*x_vec)[i]->describe(*out,this->getVerbLevel());
604 *out <<
"xdot_vec[" << i <<
"] = ";
605 if ( (*xdot_vec)[i] == Teuchos::null) {
606 *out <<
"Teuchos::null" << std::endl;
609 *out << std::endl << Teuchos::describe(*(*xdot_vec)[i],this->getVerbLevel());
613 *out <<
"accuracy[" << i <<
"] = " << (*accuracy_vec)[i] << std::endl;
619 template<
class Scalar>
622 TEUCHOS_ASSERT( time_vec != NULL );
624 if (!haveInitialCondition_) {
627 if (numberOfSteps_ > 0) {
628 time_vec->push_back(time_-usedStep_);
630 time_vec->push_back(time_);
634 template<
class Scalar>
637 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
638 "Error, removeNodes is not implemented for ImplicitBDFStepper.\n");
642 template<
class Scalar>
645 if (!isInitialized_) {
655 template<
class Scalar>
657 RCP<Teuchos::ParameterList>
const& paramList
660 TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
661 paramList->validateParameters(*this->getValidParameters(),0);
662 parameterList_ = paramList;
663 Teuchos::readVerboseObjectSublist(&*parameterList_,
this);
667 template<
class Scalar>
670 return(parameterList_);
674 template<
class Scalar>
675 RCP<Teuchos::ParameterList>
678 RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
679 parameterList_ = Teuchos::null;
680 return(temp_param_list);
684 template<
class Scalar>
685 RCP<const Teuchos::ParameterList>
689 static RCP<Teuchos::ParameterList> validPL;
691 if (is_null(validPL)) {
693 RCP<Teuchos::ParameterList>
694 pl = Teuchos::parameterList();
696 pl->sublist(RythmosStepControlSettings_name);
698 Teuchos::setupVerboseObjectSublist(&*pl);
704 RCP<Teuchos::FancyOStream> out = this->getOStream();
705 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
706 Teuchos::OSTab ostab(out,1,
"getValidParameters");
707 if (Teuchos::as<int>(verbLevel) == Teuchos::VERB_HIGH) {
708 *out <<
"Setting up valid parameterlist." << std::endl;
709 validPL->print(*out);
720 template<
class Scalar>
723 std::ostringstream out;
724 out << this->Teuchos::Describable::description();
727 out <<
" (timeRange="<<timeRange<<
")";
729 out <<
" (This stepper is not initialized yet)";
735 template<
class Scalar>
737 Teuchos::FancyOStream &out,
738 const Teuchos::EVerbosityLevel verbLevel
744 if (!isInitialized_) {
745 out << this->description();
749 if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
750 (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) )
753 out << this->description() << std::endl;
754 out <<
"model_ = " << Teuchos::describe(*model_,verbLevel);
755 out <<
"solver_ = " << Teuchos::describe(*solver_,verbLevel);
756 out <<
"neModel_ = " << Teuchos::describe(neModel_,verbLevel);
758 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
759 out <<
"time_ = " << time_ << std::endl;
760 out <<
"hh_ = " << hh_ << std::endl;
761 out <<
"currentOrder_ = " << currentOrder_ << std::endl;
763 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH)) {
764 out <<
"xn0_ = " << Teuchos::describe(*xn0_,verbLevel);
765 out <<
"xpn0_ = " << Teuchos::describe(*xpn0_,verbLevel);
766 out <<
"x_dot_base_ = " << Teuchos::describe(*x_dot_base_,verbLevel);
767 for (
int i=0 ; i < std::max(2,maxOrder_) ; ++i) {
768 out <<
"xHistory_[" << i <<
"] = "
769 << Teuchos::describe(*xHistory_[i],verbLevel);
771 out <<
"ee_ = " << Teuchos::describe(*ee_,verbLevel);
786 template<
class Scalar>
789 typedef Teuchos::ScalarTraits<Scalar> ST;
790 const Scalar nan = ST::nan(), one = ST::one(), zero = ST::zero();
792 haveInitialCondition_ =
false;
793 isInitialized_ =
false;
803 stepLETStatus_ = STEP_LET_STATUS_UNKNOWN;
808 newtonConvergenceStatus_ = -1;
812 template<
class Scalar>
813 void ImplicitBDFStepper<Scalar>::obtainPredictor_()
817 typedef Teuchos::ScalarTraits<Scalar> ST;
819 if (!isInitialized_) {
823 RCP<Teuchos::FancyOStream> out = this->getOStream();
824 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
825 Teuchos::OSTab ostab(out,1,
"obtainPredictor_");
826 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
827 *out <<
"currentOrder_ = " << currentOrder_ << std::endl;
831 for (
int i=nscsco_;i<=currentOrder_;++i) {
832 Vt_S(xHistory_[i].ptr(),beta_[i]);
836 V_V(xn0_.ptr(),*xHistory_[0]);
837 V_S(xpn0_.ptr(),ST::zero());
838 for (
int i=1;i<=currentOrder_;++i) {
839 Vp_V(xn0_.ptr(),*xHistory_[i]);
840 Vp_StV(xpn0_.ptr(),gamma_[i],*xHistory_[i]);
842 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
843 *out <<
"xn0_ = " << std::endl;
844 xn0_->describe(*out,verbLevel);
845 *out <<
"xpn0_ = " << std::endl;
846 xpn0_->describe(*out,verbLevel);
851 template<
class Scalar>
852 void ImplicitBDFStepper<Scalar>::interpolateSolution_(
853 const Scalar& timepoint,
854 Thyra::VectorBase<Scalar>* x_ptr,
855 Thyra::VectorBase<Scalar>* xdot_ptr,
856 ScalarMag* accuracy_ptr
860 typedef std::numeric_limits<Scalar> NL;
861 typedef Teuchos::ScalarTraits<Scalar> ST;
863 #ifdef HAVE_RYTHMOS_DEBUG
864 TEUCHOS_TEST_FOR_EXCEPTION(
865 !isInitialized_,std::logic_error,
866 "Error, attempting to call interpolateSolution before initialization!\n");
867 const TimeRange<Scalar> currTimeRange = this->getTimeRange();
868 TEUCHOS_TEST_FOR_EXCEPTION(
869 !currTimeRange.isInRange(timepoint), std::logic_error,
870 "Error, timepoint = " << timepoint <<
" is not in the time range "
871 << currTimeRange <<
"!" );
874 const Scalar tn = time_;
875 const int kused = usedOrder_;
879 if ( (kused == 0) || (timepoint == tn) ) {
884 Thyra::V_V(ptr(x_ptr),*xHistory_[0]);
885 Thyra::V_S(ptr(xdot_ptr),ST::zero());
888 const Scalar delt = timepoint - tn;
889 Scalar c = ST::one();
890 Scalar d = ST::zero();
891 Scalar gam = delt/psi_[0];
892 for (
int j=1 ; j <= kord ; ++j) {
893 d = d*gam + c/psi_[j-1];
895 gam = (delt + psi_[j-1])/psi_[j];
896 Thyra::Vp_StV(ptr(x_ptr),c,*xHistory_[j]);
897 Thyra::Vp_StV(ptr(xdot_ptr),d,*xHistory_[j]);
902 *accuracy_ptr = Teuchos::ScalarTraits<Scalar>::pow(usedStep_,kord);
908 template<
class Scalar>
909 void ImplicitBDFStepper<Scalar>::updateHistory_()
915 if (usedOrder_ < maxOrder_) {
916 assign( xHistory_[usedOrder_+1].ptr(), *ee_ );
919 Vp_V( xHistory_[usedOrder_].ptr(), *ee_ );
920 for (
int j=usedOrder_-1;j>=0;j--) {
921 Vp_V( xHistory_[j].ptr(), *xHistory_[j+1] );
923 RCP<Teuchos::FancyOStream> out = this->getOStream();
924 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
925 Teuchos::OSTab ostab(out,1,
"updateHistory_");
926 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
927 for (
int i=0;i<std::max(2,maxOrder_);++i) {
928 *out <<
"xHistory_[" << i <<
"] = " << std::endl;
929 xHistory_[i]->describe(*out,verbLevel);
936 template<
class Scalar>
937 void ImplicitBDFStepper<Scalar>::restoreHistory_()
941 typedef Teuchos::ScalarTraits<Scalar> ST;
944 for (
int i=nscsco_;i<=currentOrder_;++i) {
945 Vt_S( xHistory_[i].ptr(), ST::one()/beta_[i] );
947 for (
int i=1;i<=currentOrder_;++i) {
948 psi_[i-1] = psi_[i] - hh_;
950 RCP<Teuchos::FancyOStream> out = this->getOStream();
951 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
952 Teuchos::OSTab ostab(out,1,
"restoreHistory_");
953 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
954 for (
int i=0;i<maxOrder_;++i) {
955 *out <<
"psi_[" << i <<
"] = " << psi_[i] << std::endl;
957 for (
int i=0;i<maxOrder_;++i) {
958 *out <<
"xHistory_[" << i <<
"] = " << std::endl;
959 xHistory_[i]->describe(*out,verbLevel);
966 template<
class Scalar>
967 void ImplicitBDFStepper<Scalar>::updateCoeffs_()
971 typedef Teuchos::ScalarTraits<Scalar> ST;
978 if ((hh_ != usedStep_) || (currentOrder_ != usedOrder_)) {
981 nscsco_ = std::min(nscsco_+1,usedOrder_+2);
982 if (currentOrder_+1 >= nscsco_) {
983 beta_[0] = ST::one();
984 alpha_[0] = ST::one();
986 gamma_[0] = ST::zero();
987 for (
int i=1;i<=currentOrder_;++i) {
988 Scalar temp2 = psi_[i-1];
990 beta_[i] = beta_[i-1]*psi_[i-1]/temp2;
992 alpha_[i] = hh_/temp1;
993 gamma_[i] = gamma_[i-1]+alpha_[i-1]/hh_;
995 psi_[currentOrder_] = temp1;
997 alpha_s_ = ST::zero();
998 for (
int i=0;i<currentOrder_;++i) {
999 alpha_s_ = alpha_s_ - Scalar(ST::one()/(i+ST::one()));
1001 RCP<Teuchos::FancyOStream> out = this->getOStream();
1002 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1003 Teuchos::OSTab ostab(out,1,
"updateCoeffs_");
1004 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1005 for (
int i=0;i<=maxOrder_;++i) {
1006 *out <<
"alpha_[" << i <<
"] = " << alpha_[i] << std::endl;
1007 *out <<
"beta_[" << i <<
"] = " << beta_[i] << std::endl;
1008 *out <<
"gamma_[" << i <<
"] = " << gamma_[i] << std::endl;
1009 *out <<
"psi_[" << i <<
"] = " << psi_[i] << std::endl;
1010 *out <<
"alpha_s_ = " << alpha_s_ << std::endl;
1023 template<
class Scalar>
1024 void ImplicitBDFStepper<Scalar>::initialize_()
1028 typedef Teuchos::ScalarTraits<Scalar> ST;
1029 using Thyra::createMember;
1031 RCP<Teuchos::FancyOStream> out = this->getOStream();
1032 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1033 const bool doTrace = (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH));
1034 Teuchos::OSTab ostab(out,1,
"initialize_");
1038 <<
"\nEntering " << this->Teuchos::Describable::description()
1039 <<
"::initialize_()...\n";
1042 TEUCHOS_TEST_FOR_EXCEPT(model_ == Teuchos::null);
1043 TEUCHOS_TEST_FOR_EXCEPT(solver_ == Teuchos::null);
1044 TEUCHOS_ASSERT(haveInitialCondition_);
1047 if (parameterList_ == Teuchos::null) {
1048 RCP<Teuchos::ParameterList> emptyParameterList = Teuchos::rcp(
new Teuchos::ParameterList);
1049 this->setParameterList(emptyParameterList);
1053 if (stepControl_ == Teuchos::null) {
1054 RCP<ImplicitBDFStepperStepControl<Scalar> > implicitBDFStepperStepControl =
1055 Teuchos::rcp(
new ImplicitBDFStepperStepControl<Scalar>());
1056 RCP<Teuchos::ParameterList> stepControlPL =
1057 Teuchos::sublist(parameterList_, RythmosStepControlSettings_name);
1058 implicitBDFStepperStepControl->setParameterList(stepControlPL);
1059 this->setStepControlStrategy(implicitBDFStepperStepControl);
1061 stepControl_->initialize(*
this);
1063 maxOrder_ = stepControl_->getMaxOrder();
1064 TEUCHOS_TEST_FOR_EXCEPTION(
1065 !((1 <= maxOrder_) && (maxOrder_ <= 5)), std::logic_error,
1066 "Error, maxOrder returned from stepControl_->getMaxOrder() = " << maxOrder_ <<
" is outside range of [1,5]!\n"
1069 Scalar zero = ST::zero();
1083 for (
int i=0 ; i<=maxOrder_ ; ++i) {
1084 alpha_.push_back(zero);
1085 beta_.push_back(zero);
1086 gamma_.push_back(zero);
1087 psi_.push_back(zero);
1089 alpha_s_=Scalar(-ST::one());
1094 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1095 *out <<
"alpha_s_ = " << alpha_s_ << std::endl;
1096 for (
int i=0 ; i<=maxOrder_ ; ++i) {
1097 *out <<
"alpha_[" << i <<
"] = " << alpha_[i] << std::endl;
1098 *out <<
"beta_[" << i <<
"] = " << beta_[i] << std::endl;
1099 *out <<
"gamma_[" << i <<
"] = " << gamma_[i] << std::endl;
1100 *out <<
"psi_[" << i <<
"] = " << psi_[i] << std::endl;
1102 *out <<
"numberOfSteps_ = " << numberOfSteps_ << std::endl;
1107 for (
int i=2 ; i<=maxOrder_ ; ++i) {
1108 xHistory_.push_back(createMember(xn0_->space()));
1109 V_S(xHistory_[i].ptr(),zero);
1112 isInitialized_ =
true;
1116 <<
"\nLeaving " << this->Teuchos::Describable::description()
1117 <<
"::initialize_()...\n";
1123 template<
class Scalar>
1124 void ImplicitBDFStepper<Scalar>::completeStep_()
1128 typedef Teuchos::ScalarTraits<Scalar> ST;
1130 #ifdef HAVE_RYTHMOS_DEBUG
1131 TEUCHOS_TEST_FOR_EXCEPT(ST::isnaninf(hh_));
1137 usedOrder_ = currentOrder_;
1139 RCP<Teuchos::FancyOStream> out = this->getOStream();
1140 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1141 Teuchos::OSTab ostab(out,1,
"completeStep_");
1143 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1144 *out <<
"numberOfSteps_ = " << numberOfSteps_ << std::endl;
1145 *out <<
"time_ = " << time_ << std::endl;
1154 template<
class Scalar>
1157 if (!isInitialized_) {
1160 stepControl_->setStepControlData(stepper);
1169 #define RYTHMOS_IMPLICITBDF_STEPPER_INSTANT(SCALAR) \
1171 template class ImplicitBDFStepper< SCALAR >; \
1173 template RCP< ImplicitBDFStepper< SCALAR > > \
1174 implicitBDFStepper(); \
1176 template RCP< ImplicitBDFStepper< SCALAR > > \
1177 implicitBDFStepper( \
1178 const RCP<Thyra::ModelEvaluator< SCALAR > >& model, \
1179 const RCP<Thyra::NonlinearSolverBase< SCALAR > >& solver, \
1180 const RCP<Teuchos::ParameterList>& parameterList \
1187 #endif //Rythmos_IMPLICITBDF_STEPPER_DEF_H
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
bool isImplicit() const
Overridden from StepperBase.
Base class for defining stepper functionality.
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< Teuchos::ParameterList > getNonconstParameterList()
RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
void setInitialCondition(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initialCondition)
void setNonconstModel(const RCP< Thyra::ModelEvaluator< Scalar > > &model)
RCP< StepperBase< Scalar > > cloneStepperAlgorithm() const
Creates copies of all internal data (including the parameter list) except the model which is assumed ...
RCP< const StepControlStrategyBase< Scalar > > getStepControlStrategy() const
ImplicitBDFStepper()
Constructors, intializers, Misc.
std::string description() const
TimeRange< Scalar > getTimeRange() const
The member functions in the StepControlStrategyBase move you between these states in the following fa...
RCP< const Thyra::VectorBase< Scalar > > residual
RCP< Thyra::NonlinearSolverBase< Scalar > > getNonconstSolver()
RCP< const Thyra::VectorBase< Scalar > > solutionDot
Thyra::ModelEvaluatorBase::InArgs< Scalar > getInitialCondition() const
void setModel(const RCP< const Thyra::ModelEvaluator< Scalar > > &model)
RCP< const Thyra::NonlinearSolverBase< Scalar > > getSolver() const
void getNodes(Array< Scalar > *time_vec) const
Scalar takeStep(Scalar dt, StepSizeType flag)
bool supportsCloning() const
Returns true.
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
EStepLETStatus stepLETStatus
RCP< const Thyra::VectorBase< Scalar > > solution
void setStepControlData(const StepperBase< Scalar > &stepper)
RCP< StepControlStrategyBase< Scalar > > getNonconstStepControlStrategy()
void removeNodes(Array< Scalar > &time_vec)
RCP< Thyra::ModelEvaluator< Scalar > > getNonconstModel()
RCP< const Teuchos::ParameterList > getValidParameters() const
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< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
const StepStatus< Scalar > getStepStatus() const
void setSolver(const RCP< Thyra::NonlinearSolverBase< Scalar > > &solver)
RCP< Teuchos::ParameterList > unsetParameterList()
void setStepControlStrategy(const RCP< StepControlStrategyBase< Scalar > > &stepControlStrategy)
const Thyra::VectorBase< Scalar > & getxHistory(int index) const