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
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;
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;
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) &&
340 (desiredOrder <= maxOrder_)));
341 TEUCHOS_TEST_FOR_EXCEPT(!(desiredOrder <= usedOrder_+1));
342 currentOrder_ = desiredOrder;
343 if (numberOfSteps_ == 0) {
346 Vt_S(xHistory_[1].ptr(),hh_);
348 Vt_S(xHistory_[1].ptr(),hh_/hh_old);
351 this->updateCoeffs_();
367 Scalar coeff_x_dot = Scalar(-ST::one())*alpha_s_/hh_;
368 V_StVpStV( x_dot_base_.ptr(), ST::one(), *xpn0_, alpha_s_/hh_, *xn0_ );
369 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
370 *out <<
"model_ = " << std::endl;
371 model_->describe(*out,verbLevel);
372 *out <<
"basePoint_ = " << std::endl;
373 basePoint_.describe(*out,verbLevel);
374 *out <<
"coeff_x_dot = " << coeff_x_dot << std::endl;
375 *out <<
"x_dot_base_ = " << std::endl;
376 x_dot_base_->describe(*out,verbLevel);
377 *out <<
"time_+hh_ = " << time_+hh_ << std::endl;
378 *out <<
"xn0_ = " << std::endl;
379 xn0_->describe(*out,verbLevel);
381 neModel_.initializeSingleResidualModel(
383 coeff_x_dot, x_dot_base_,
384 ST::one(), Teuchos::null,
391 if (solver_->getModel().get() != &neModel_) {
392 solver_->setModel( Teuchos::rcpFromRef(neModel_) );
407 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
408 *out <<
"xn0 = " << std::endl;
409 xn0_->describe(*out,verbLevel);
410 *out <<
"ee = " << std::endl;
411 ee_->describe(*out,verbLevel);
413 nonlinearSolveStatus_ = solver_->solve( &*xn0_, NULL, &*ee_ );
414 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
415 *out <<
"xn0 = " << std::endl;
416 xn0_->describe(*out,verbLevel);
417 *out <<
"ee = " << std::endl;
418 ee_->describe(*out,verbLevel);
424 if (nonlinearSolveStatus_.solveStatus == Thyra::SOLVE_STATUS_CONVERGED) {
425 newtonConvergenceStatus_ = 0;
428 newtonConvergenceStatus_ = -1;
432 stepControl_->setCorrection(*
this,xn0_,ee_,newtonConvergenceStatus_);
433 bool stepPass = stepControl_->acceptStep(*
this,&LETvalue_);
435 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
436 *out <<
"xn0_ = " << std::endl;
437 xn0_->describe(*out,verbLevel);
438 *out <<
"xpn0_ = " << std::endl;
439 xpn0_->describe(*out,verbLevel);
440 *out <<
"ee_ = " << std::endl;
441 ee_->describe(*out,verbLevel);
442 for (
int i=0; i<std::max(2,maxOrder_); ++i) {
443 *out <<
"xHistory_[" << i <<
"] = " << std::endl;
444 xHistory_[i]->describe(*out,verbLevel);
450 stepLETStatus_ = STEP_LET_STATUS_FAILED;
451 status = stepControl_->rejectStep(*
this);
453 if (status == CONTINUE_ANYWAY) {
459 stepLETStatus_ = STEP_LET_STATUS_PASSED;
467 stepControl_->completeStep(*
this);
469 if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
471 <<
"\nLeaving " << this->Teuchos::Describable::description()
472 <<
"::takeStep("<<dt<<
","<<toString(stepType)<<
") ...\n";
479 template<
class Scalar>
486 typedef Teuchos::ScalarTraits<Scalar> ST;
488 if (!isInitialized_) {
489 stepStatus.
message =
"This stepper is uninitialized.";
490 stepStatus.
stepStatus = STEP_STATUS_UNINITIALIZED;
491 stepStatus.
stepSize = Scalar(-ST::one());
492 stepStatus.
order = -1;
493 stepStatus.
time = Scalar(-ST::one());
496 else if (numberOfSteps_ > 0) {
497 stepStatus.
stepStatus = STEP_STATUS_CONVERGED;
504 stepStatus.
order = usedOrder_;
505 stepStatus.
time = time_;
507 if(xHistory_.size() > 0)
510 stepStatus.
solution = Teuchos::null;
512 stepStatus.
residual = Teuchos::null;
522 template<
class Scalar>
523 RCP<const Thyra::VectorSpaceBase<Scalar> >
527 return ( !is_null(model_) ? model_->get_x_space() : Teuchos::null );
531 template<
class Scalar>
533 const Array<Scalar>& time_vec,
534 const Array<RCP<
const Thyra::VectorBase<Scalar> > >& x_vec,
535 const Array<RCP<
const Thyra::VectorBase<Scalar> > >& xdot_vec
538 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
539 "Error, addPoints is not implemented for ImplicitBDFStepper.\n");
543 template<
class Scalar>
546 if ( !isInitialized_ && haveInitialCondition_ )
547 return timeRange<Scalar>(time_,time_);
548 if ( !isInitialized_ && !haveInitialCondition_ )
549 return invalidTimeRange<Scalar>();
550 return timeRange<Scalar>(time_-usedStep_,time_);
554 template<
class Scalar>
556 const Array<Scalar>& time_vec
557 ,Array<RCP<
const Thyra::VectorBase<Scalar> > >* x_vec
558 ,Array<RCP<
const Thyra::VectorBase<Scalar> > >* xdot_vec
559 ,Array<ScalarMag>* accuracy_vec)
const 562 using Teuchos::constOptInArg;
565 typedef Teuchos::ScalarTraits<Scalar> ST;
566 typedef typename ST::magnitudeType mScalarMag;
568 TEUCHOS_ASSERT(haveInitialCondition_);
570 if ( (numberOfSteps_ == -1) &&
571 (time_vec.length() == 1) &&
572 (compareTimeValues<Scalar>(time_vec[0],time_)==0) ) {
573 defaultGetPoints<Scalar>(
574 time_, constOptInArg(*xn0_), constOptInArg(*xpn0_),
575 time_, constOptInArg(*xn0_), constOptInArg(*xpn0_),
576 time_vec, ptr(x_vec), ptr(xdot_vec), ptr(accuracy_vec),
581 TEUCHOS_ASSERT(isInitialized_);
582 RYTHMOS_FUNC_TIME_MONITOR(
"Rythmos::ImplicitBDFStepper::getPoints");
587 for (Teuchos::Ordinal i=0 ; i<time_vec.size() ; ++i) {
588 RCP<Thyra::VectorBase<Scalar> >
589 x_temp = createMember(xn0_->space());
590 RCP<Thyra::VectorBase<Scalar> >
591 xdot_temp = createMember(xn0_->space());
592 mScalarMag accuracy = -ST::zero();
593 interpolateSolution_(
594 time_vec[i], &*x_temp, &*xdot_temp,
595 accuracy_vec ? &accuracy : 0
598 x_vec->push_back(x_temp);
600 xdot_vec->push_back(xdot_temp);
602 accuracy_vec->push_back(accuracy);
604 if ( as<int>(this->getVerbLevel()) >= as<int>(Teuchos::VERB_HIGH) ) {
605 RCP<Teuchos::FancyOStream> out = this->getOStream();
606 Teuchos::OSTab ostab(out,1,
"getPoints");
607 *out <<
"Passing out the interpolated values:" << std::endl;
608 for (Teuchos::Ordinal i=0; i<time_vec.size() ; ++i) {
609 *out <<
"time_[" << i <<
"] = " << time_vec[i] << std::endl;
611 *out <<
"x_vec[" << i <<
"] = " << std::endl;
612 (*x_vec)[i]->describe(*out,this->getVerbLevel());
615 *out <<
"xdot_vec[" << i <<
"] = ";
616 if ( (*xdot_vec)[i] == Teuchos::null) {
617 *out <<
"Teuchos::null" << std::endl;
620 *out << std::endl << Teuchos::describe(*(*xdot_vec)[i],this->getVerbLevel());
624 *out <<
"accuracy[" << i <<
"] = " << (*accuracy_vec)[i] << std::endl;
630 template<
class Scalar>
633 TEUCHOS_ASSERT( time_vec != NULL );
635 if (!haveInitialCondition_) {
638 if (numberOfSteps_ > 0) {
639 time_vec->push_back(time_-usedStep_);
641 time_vec->push_back(time_);
645 template<
class Scalar>
648 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
649 "Error, removeNodes is not implemented for ImplicitBDFStepper.\n");
653 template<
class Scalar>
656 if (!isInitialized_) {
666 template<
class Scalar>
668 RCP<Teuchos::ParameterList>
const& paramList
671 TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
672 paramList->validateParameters(*this->getValidParameters(),0);
673 parameterList_ = paramList;
674 Teuchos::readVerboseObjectSublist(&*parameterList_,
this);
678 template<
class Scalar>
681 return(parameterList_);
685 template<
class Scalar>
686 RCP<Teuchos::ParameterList>
689 RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
690 parameterList_ = Teuchos::null;
691 return(temp_param_list);
695 template<
class Scalar>
696 RCP<const Teuchos::ParameterList>
699 static RCP<Teuchos::ParameterList> validPL;
700 if (is_null(validPL)) {
701 RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
703 pl->sublist(RythmosStepControlSettings_name);
704 Teuchos::setupVerboseObjectSublist(&*pl);
708 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
709 if (Teuchos::as<int>(verbLevel) == Teuchos::VERB_HIGH) {
710 RCP<Teuchos::FancyOStream> out = this->getOStream();
711 Teuchos::OSTab ostab(out,1,
"getValidParameters");
712 *out <<
"Setting up valid parameterlist." << std::endl;
713 validPL->print(*out);
724 template<
class Scalar>
727 std::ostringstream out;
728 out << this->Teuchos::Describable::description();
731 out <<
" (timeRange="<<timeRange<<
")";
733 out <<
" (This stepper is not initialized yet)";
739 template<
class Scalar>
741 Teuchos::FancyOStream &out,
742 const Teuchos::EVerbosityLevel verbLevel
748 if (!isInitialized_) {
749 out << this->description();
753 if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
754 (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) )
757 out << this->description() << std::endl;
758 out <<
"model_ = " << Teuchos::describe(*model_,verbLevel);
759 out <<
"solver_ = " << Teuchos::describe(*solver_,verbLevel);
760 out <<
"neModel_ = " << Teuchos::describe(neModel_,verbLevel);
762 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
763 out <<
"time_ = " << time_ << std::endl;
764 out <<
"hh_ = " << hh_ << std::endl;
765 out <<
"currentOrder_ = " << currentOrder_ << std::endl;
767 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH)) {
768 out <<
"xn0_ = " << Teuchos::describe(*xn0_,verbLevel);
769 out <<
"xpn0_ = " << Teuchos::describe(*xpn0_,verbLevel);
770 out <<
"x_dot_base_ = " << Teuchos::describe(*x_dot_base_,verbLevel);
771 for (
int i=0 ; i < std::max(2,maxOrder_) ; ++i) {
772 out <<
"xHistory_[" << i <<
"] = " 773 << Teuchos::describe(*xHistory_[i],verbLevel);
775 out <<
"ee_ = " << Teuchos::describe(*ee_,verbLevel);
790 template<
class Scalar>
793 typedef Teuchos::ScalarTraits<Scalar> ST;
794 const Scalar nan = ST::nan(), one = ST::one(), zero = ST::zero();
796 haveInitialCondition_ =
false;
797 isInitialized_ =
false;
807 stepLETStatus_ = STEP_LET_STATUS_UNKNOWN;
812 newtonConvergenceStatus_ = -1;
816 template<
class Scalar>
817 void ImplicitBDFStepper<Scalar>::obtainPredictor_()
821 typedef Teuchos::ScalarTraits<Scalar> ST;
823 if (!isInitialized_) {
827 RCP<Teuchos::FancyOStream> out = this->getOStream();
828 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
829 Teuchos::OSTab ostab(out,1,
"obtainPredictor_");
830 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
831 *out <<
"currentOrder_ = " << currentOrder_ << std::endl;
835 for (
int i=nscsco_;i<=currentOrder_;++i) {
836 Vt_S(xHistory_[i].ptr(),beta_[i]);
840 V_V(xn0_.ptr(),*xHistory_[0]);
841 V_S(xpn0_.ptr(),ST::zero());
842 for (
int i=1;i<=currentOrder_;++i) {
843 Vp_V(xn0_.ptr(),*xHistory_[i]);
844 Vp_StV(xpn0_.ptr(),gamma_[i],*xHistory_[i]);
846 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
847 *out <<
"xn0_ = " << std::endl;
848 xn0_->describe(*out,verbLevel);
849 *out <<
"xpn0_ = " << std::endl;
850 xpn0_->describe(*out,verbLevel);
855 template<
class Scalar>
856 void ImplicitBDFStepper<Scalar>::interpolateSolution_(
857 const Scalar& timepoint,
858 Thyra::VectorBase<Scalar>* x_ptr,
859 Thyra::VectorBase<Scalar>* xdot_ptr,
860 ScalarMag* accuracy_ptr
865 typedef Teuchos::ScalarTraits<Scalar> ST;
867 #ifdef HAVE_RYTHMOS_DEBUG 868 TEUCHOS_TEST_FOR_EXCEPTION(
869 !isInitialized_,std::logic_error,
870 "Error, attempting to call interpolateSolution before initialization!\n");
871 const TimeRange<Scalar> currTimeRange = this->getTimeRange();
872 TEUCHOS_TEST_FOR_EXCEPTION(
873 !currTimeRange.isInRange(timepoint), std::logic_error,
874 "Error, timepoint = " << timepoint <<
" is not in the time range " 875 << currTimeRange <<
"!" );
878 const Scalar tn = time_;
879 const int kused = usedOrder_;
883 if ( (kused == 0) || (timepoint == tn) ) {
888 Thyra::V_V(ptr(x_ptr),*xHistory_[0]);
889 Thyra::V_S(ptr(xdot_ptr),ST::zero());
892 const Scalar delt = timepoint - tn;
893 Scalar c = ST::one();
894 Scalar d = ST::zero();
895 Scalar gam = delt/psi_[0];
896 for (
int j=1 ; j <= kord ; ++j) {
897 d = d*gam + c/psi_[j-1];
899 gam = (delt + psi_[j-1])/psi_[j];
900 Thyra::Vp_StV(ptr(x_ptr),c,*xHistory_[j]);
901 Thyra::Vp_StV(ptr(xdot_ptr),d,*xHistory_[j]);
906 *accuracy_ptr = Teuchos::ScalarTraits<Scalar>::pow(usedStep_,kord);
912 template<
class Scalar>
913 void ImplicitBDFStepper<Scalar>::updateHistory_()
919 if (usedOrder_ < maxOrder_) {
920 assign( xHistory_[usedOrder_+1].ptr(), *ee_ );
923 Vp_V( xHistory_[usedOrder_].ptr(), *ee_ );
924 for (
int j=usedOrder_-1;j>=0;j--) {
925 Vp_V( xHistory_[j].ptr(), *xHistory_[j+1] );
927 RCP<Teuchos::FancyOStream> out = this->getOStream();
928 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
929 Teuchos::OSTab ostab(out,1,
"updateHistory_");
930 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
931 for (
int i=0;i<std::max(2,maxOrder_);++i) {
932 *out <<
"xHistory_[" << i <<
"] = " << std::endl;
933 xHistory_[i]->describe(*out,verbLevel);
940 template<
class Scalar>
941 void ImplicitBDFStepper<Scalar>::restoreHistory_()
945 typedef Teuchos::ScalarTraits<Scalar> ST;
948 for (
int i=nscsco_;i<=currentOrder_;++i) {
949 Vt_S( xHistory_[i].ptr(), ST::one()/beta_[i] );
951 for (
int i=1;i<=currentOrder_;++i) {
952 psi_[i-1] = psi_[i] - hh_;
954 RCP<Teuchos::FancyOStream> out = this->getOStream();
955 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
956 Teuchos::OSTab ostab(out,1,
"restoreHistory_");
957 if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
958 for (
int i=0;i<maxOrder_;++i) {
959 *out <<
"psi_[" << i <<
"] = " << psi_[i] << std::endl;
961 for (
int i=0;i<maxOrder_;++i) {
962 *out <<
"xHistory_[" << i <<
"] = " << std::endl;
963 xHistory_[i]->describe(*out,verbLevel);
970 template<
class Scalar>
971 void ImplicitBDFStepper<Scalar>::updateCoeffs_()
975 typedef Teuchos::ScalarTraits<Scalar> ST;
982 if ((hh_ != usedStep_) || (currentOrder_ != usedOrder_)) {
985 nscsco_ = std::min(nscsco_+1,usedOrder_+2);
986 if (currentOrder_+1 >= nscsco_) {
987 beta_[0] = ST::one();
988 alpha_[0] = ST::one();
990 gamma_[0] = ST::zero();
991 for (
int i=1;i<=currentOrder_;++i) {
992 Scalar temp2 = psi_[i-1];
994 beta_[i] = beta_[i-1]*psi_[i-1]/temp2;
996 alpha_[i] = hh_/temp1;
997 gamma_[i] = gamma_[i-1]+alpha_[i-1]/hh_;
999 psi_[currentOrder_] = temp1;
1001 alpha_s_ = ST::zero();
1002 for (
int i=0;i<currentOrder_;++i) {
1003 alpha_s_ = alpha_s_ - Scalar(ST::one()/(i+ST::one()));
1005 RCP<Teuchos::FancyOStream> out = this->getOStream();
1006 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1007 Teuchos::OSTab ostab(out,1,
"updateCoeffs_");
1008 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1009 for (
int i=0;i<=maxOrder_;++i) {
1010 *out <<
"alpha_[" << i <<
"] = " << alpha_[i] << std::endl;
1011 *out <<
"beta_[" << i <<
"] = " << beta_[i] << std::endl;
1012 *out <<
"gamma_[" << i <<
"] = " << gamma_[i] << std::endl;
1013 *out <<
"psi_[" << i <<
"] = " << psi_[i] << std::endl;
1014 *out <<
"alpha_s_ = " << alpha_s_ << std::endl;
1027 template<
class Scalar>
1028 void ImplicitBDFStepper<Scalar>::initialize_()
1032 typedef Teuchos::ScalarTraits<Scalar> ST;
1033 using Thyra::createMember;
1035 RCP<Teuchos::FancyOStream> out = this->getOStream();
1036 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1037 const bool doTrace = (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH));
1038 Teuchos::OSTab ostab(out,1,
"initialize_");
1042 <<
"\nEntering " << this->Teuchos::Describable::description()
1043 <<
"::initialize_()...\n";
1046 TEUCHOS_TEST_FOR_EXCEPT(model_ == Teuchos::null);
1047 TEUCHOS_TEST_FOR_EXCEPT(solver_ == Teuchos::null);
1048 TEUCHOS_ASSERT(haveInitialCondition_);
1051 if (parameterList_ == Teuchos::null) {
1052 RCP<Teuchos::ParameterList> emptyParameterList =
1053 Teuchos::rcp(
new Teuchos::ParameterList);
1054 this->setParameterList(emptyParameterList);
1058 if (stepControl_ == Teuchos::null) {
1059 RCP<ImplicitBDFStepperStepControl<Scalar> > implicitBDFStepperStepControl =
1060 Teuchos::rcp(
new ImplicitBDFStepperStepControl<Scalar>());
1061 RCP<Teuchos::ParameterList> stepControlPL =
1062 Teuchos::sublist(parameterList_, RythmosStepControlSettings_name);
1063 implicitBDFStepperStepControl->setParameterList(stepControlPL);
1064 this->setStepControlStrategy(implicitBDFStepperStepControl);
1066 stepControl_->initialize(*
this);
1068 maxOrder_ = stepControl_->getMaxOrder();
1069 TEUCHOS_TEST_FOR_EXCEPTION(
1070 !((1 <= maxOrder_) && (maxOrder_ <= 5)), std::logic_error,
1071 "Error, maxOrder returned from stepControl_->getMaxOrder() = " 1072 << maxOrder_ <<
" is outside range of [1,5]!\n");
1074 Scalar zero = ST::zero();
1090 for (
int i=0 ; i<=maxOrder_ ; ++i) {
1091 alpha_.push_back(zero);
1092 beta_.push_back(zero);
1093 gamma_.push_back(zero);
1094 psi_.push_back(zero);
1096 alpha_s_=Scalar(-ST::one());
1102 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1103 *out <<
"alpha_s_ = " << alpha_s_ << std::endl;
1104 for (
int i=0 ; i<=maxOrder_ ; ++i) {
1105 *out <<
"alpha_[" << i <<
"] = " << alpha_[i] << std::endl;
1106 *out <<
"beta_[" << i <<
"] = " << beta_[i] << std::endl;
1107 *out <<
"gamma_[" << i <<
"] = " << gamma_[i] << std::endl;
1108 *out <<
"psi_[" << i <<
"] = " << psi_[i] << std::endl;
1110 *out <<
"numberOfSteps_ = " << numberOfSteps_ << std::endl;
1115 for (
int i=2 ; i<=maxOrder_ ; ++i) {
1116 xHistory_.push_back(createMember(xn0_->space()));
1117 V_S(xHistory_[i].ptr(),zero);
1120 isInitialized_ =
true;
1124 <<
"\nLeaving " << this->Teuchos::Describable::description()
1125 <<
"::initialize_()...\n";
1131 template<
class Scalar>
1132 void ImplicitBDFStepper<Scalar>::completeStep_()
1136 typedef Teuchos::ScalarTraits<Scalar> ST;
1138 #ifdef HAVE_RYTHMOS_DEBUG 1139 TEUCHOS_TEST_FOR_EXCEPT(ST::isnaninf(hh_));
1145 usedOrder_ = currentOrder_;
1147 RCP<Teuchos::FancyOStream> out = this->getOStream();
1148 Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
1149 Teuchos::OSTab ostab(out,1,
"completeStep_");
1151 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
1152 *out <<
"numberOfSteps_ = " << numberOfSteps_ << std::endl;
1153 *out <<
"time_ = " << time_ << std::endl;
1162 template<
class Scalar>
1166 if (!isInitialized_) {
1169 stepControl_->setStepControlData(stepper);
1172 template<
class Scalar>
1175 return nonlinearSolveStatus_;
1184 #define RYTHMOS_IMPLICITBDF_STEPPER_INSTANT(SCALAR) \ 1186 template class ImplicitBDFStepper< SCALAR >; \ 1188 template RCP< ImplicitBDFStepper< SCALAR > > \ 1189 implicitBDFStepper(); \ 1191 template RCP< ImplicitBDFStepper< SCALAR > > \ 1192 implicitBDFStepper( \ 1193 const RCP<Thyra::ModelEvaluator< SCALAR > >& model, \ 1194 const RCP<Thyra::NonlinearSolverBase< SCALAR > >& solver, \ 1195 const RCP<Teuchos::ParameterList>& parameterList \ 1202 #endif //Rythmos_IMPLICITBDF_STEPPER_DEF_H 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
const StepStatus< Scalar > getStepStatus() const
RCP< StepperBase< Scalar > > cloneStepperAlgorithm() const
Creates copies of all internal data (including the parameter list) except the model which is assumed ...
Base strategy class for interpolation functionality.
Base class for defining stepper functionality.
void getNodes(Array< Scalar > *time_vec) const
RCP< Teuchos::ParameterList > getNonconstParameterList()
RCP< const StepControlStrategyBase< Scalar > > getStepControlStrategy() const
void setInitialCondition(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initialCondition)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setNonconstModel(const RCP< Thyra::ModelEvaluator< Scalar > > &model)
const Thyra::VectorBase< Scalar > & getxHistory(int index) const
const Thyra::SolveStatus< Scalar > & getNonlinearSolveStatus() const
Returns the Thyra::SolveStatus object from the last nonlinear solve.
ImplicitBDFStepper()
Constructors, intializers, Misc.
bool isImplicit() const
Overridden from StepperBase.
Thyra::ModelEvaluatorBase::InArgs< Scalar > getInitialCondition() const
RCP< const Teuchos::ParameterList > getValidParameters() const
The member functions in the StepControlStrategyBase move you between these states in the following fa...
RCP< const Thyra::VectorBase< Scalar > > residual
RCP< const Thyra::NonlinearSolverBase< Scalar > > getSolver() const
RCP< Thyra::NonlinearSolverBase< Scalar > > getNonconstSolver()
RCP< const Thyra::VectorBase< Scalar > > solutionDot
void setModel(const RCP< const Thyra::ModelEvaluator< Scalar > > &model)
bool supportsCloning() const
Returns true.
RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
Scalar takeStep(Scalar dt, StepSizeType flag)
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
EStepLETStatus stepLETStatus
TimeRange< Scalar > getTimeRange() const
RCP< const Thyra::VectorBase< Scalar > > solution
std::string description() const
void setStepControlData(const StepperBase< Scalar > &stepper)
RCP< StepControlStrategyBase< Scalar > > getNonconstStepControlStrategy()
void removeNodes(Array< Scalar > &time_vec)
RCP< Thyra::ModelEvaluator< Scalar > > getNonconstModel()
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)
void setSolver(const RCP< Thyra::NonlinearSolverBase< Scalar > > &solver)
RCP< Teuchos::ParameterList > unsetParameterList()
void setStepControlStrategy(const RCP< StepControlStrategyBase< Scalar > > &stepControlStrategy)