9 #ifndef Tempus_StepperBDF2_impl_hpp 
   10 #define Tempus_StepperBDF2_impl_hpp 
   12 #include "Tempus_config.hpp" 
   14 #include "Tempus_WrapperModelEvaluatorBasic.hpp" 
   15 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 
   16 #include "NOX_Thyra.H" 
   22 template<
class Scalar> 
class StepperFactory;
 
   25 template<
class Scalar>
 
   28   this->setStepperType(        
"BDF2");
 
   29   this->setUseFSAL(            this->getUseFSALDefault());
 
   30   this->setICConsistency(      this->getICConsistencyDefault());
 
   31   this->setICConsistencyCheck( this->getICConsistencyCheckDefault());
 
   32   this->setZeroInitialGuess(   
false);
 
   35   this->setDefaultSolver();
 
   36   this->setStartUpStepper(
"DIRK 1 Stage Theta Method");
 
   40 template<
class Scalar>
 
   42   const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
 
   44   const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
 
   47   std::string ICConsistency,
 
   48   bool ICConsistencyCheck,
 
   49   bool zeroInitialGuess)
 
   52   this->setStepperType(        
"BDF2");
 
   53   this->setUseFSAL(            useFSAL);
 
   54   this->setICConsistency(      ICConsistency);
 
   55   this->setICConsistencyCheck( ICConsistencyCheck);
 
   56   this->setZeroInitialGuess(   zeroInitialGuess);
 
   58   this->setObserver(obs);
 
   59   this->setSolver(solver);
 
   60   this->setStartUpStepper(startUpStepper);
 
   62   if (appModel != Teuchos::null) {
 
   63     this->setModel(appModel);
 
   69 template<
class Scalar>
 
   71   const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
 
   74   if (startUpStepper_->getModel() == Teuchos::null) {
 
   75     startUpStepper_->setModel(appModel);
 
   76     startUpStepper_->initialize();
 
   79   this->isInitialized_ = 
false;
 
   84 template<
class Scalar>
 
   89   if (this->wrapperModel_ != Teuchos::null &&
 
   90       this->wrapperModel_->getAppModel() != Teuchos::null) {
 
   92       sf->createStepper(startupStepperType, this->wrapperModel_->getAppModel());
 
   94     startUpStepper_ = sf->createStepper(startupStepperType);
 
   97   this->isInitialized_ = 
false;
 
  102 template<
class Scalar>
 
  106   startUpStepper_ = startUpStepper;
 
  108   if (this->wrapperModel_ != Teuchos::null) {
 
  109     TEUCHOS_TEST_FOR_EXCEPTION(
 
  110       this->wrapperModel_->getAppModel() == Teuchos::null, std::logic_error,
 
  111       "Error - Can not set the startUpStepper to Teuchos::null.\n");
 
  113     if (startUpStepper->getModel() == Teuchos::null  &&
 
  114         this->wrapperModel_->getAppModel() != Teuchos::null) {
 
  115       startUpStepper_->setModel(this->wrapperModel_->getAppModel());
 
  116       startUpStepper_->initialize();
 
  120   this->isInitialized_ = 
false;
 
  124 template<
class Scalar>
 
  128   if (this->stepperObserver_ == Teuchos::null)
 
  129     this->stepperObserver_  =
 
  132   if (obs == Teuchos::null) {
 
  133     if (stepperBDF2Observer_ == Teuchos::null)
 
  135     if (this->stepperObserver_->getSize() == 0)
 
  136       this->stepperObserver_->addObserver(stepperBDF2Observer_);
 
  138     stepperBDF2Observer_ =
 
  140     this->stepperObserver_->addObserver(stepperBDF2Observer_);
 
  143   this->isInitialized_ = 
false;
 
  147 template<
class Scalar>
 
  154 template<
class Scalar>
 
  160   RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
 
  163   if (initialState->getXDot() == Teuchos::null)
 
  164     this->setStepperXDot(initialState->getX()->clone_v());
 
  170 template<
class Scalar>
 
  174   this->checkInitialized();
 
  178   TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperBDF2::takeStep()");
 
  180     int numStates = solutionHistory->getNumStates();
 
  182     RCP<Thyra::VectorBase<Scalar> > xOld;
 
  183     RCP<Thyra::VectorBase<Scalar> > xOldOld;
 
  188       computeStartUp(solutionHistory);
 
  191     TEUCHOS_TEST_FOR_EXCEPTION( (numStates < 3), std::logic_error,
 
  192       "Error in Tempus::StepperBDF2::takeStep(): numStates after \n" 
  193         << 
"startup stepper must be at least 3, whereas numStates = " 
  194         << numStates <<
"!\n" << 
"If running with Storage Type = Static, " 
  195         << 
"make sure Storage Limit > 2.\n");
 
  202     RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
 
  203     RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
 
  205     RCP<Thyra::VectorBase<Scalar> > x    = workingState->getX();
 
  206     RCP<Thyra::VectorBase<Scalar> > xDot = this->getStepperXDot(workingState);
 
  209     const Scalar time  = workingState->getTime();
 
  210     const Scalar dt    = workingState->getTimeStep();
 
  211     const Scalar dtOld = currentState->getTimeStep();
 
  213     xOld    = solutionHistory->getStateTimeIndexNM1()->getX();
 
  214     xOldOld = solutionHistory->getStateTimeIndexNM2()->getX();
 
  215     order_ = Scalar(2.0);
 
  218     Teuchos::RCP<TimeDerivative<Scalar> > timeDer =
 
  221     const Scalar alpha = getAlpha(dt, dtOld);
 
  222     const Scalar beta  = getBeta (dt);
 
  225       timeDer, dt, alpha, beta));
 
  227     if (!Teuchos::is_null(stepperBDF2Observer_))
 
  228       stepperBDF2Observer_->observeBeforeSolve(solutionHistory, *
this);
 
  230     const Thyra::SolveStatus<Scalar> sStatus =
 
  231       this->solveImplicitODE(x, xDot, time, p);
 
  233     if (!Teuchos::is_null(stepperBDF2Observer_))
 
  234       stepperBDF2Observer_->observeAfterSolve(solutionHistory, *
this);
 
  236     if (workingState->getXDot() != Teuchos::null)
 
  237       timeDer->compute(x, xDot);
 
  239     workingState->setSolutionStatus(sStatus);  
 
  240     workingState->setOrder(getOrder());
 
  241     workingState->computeNorms(currentState);
 
  247 template<
class Scalar>
 
  251   Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
 
  252   Teuchos::OSTab ostab(out,1,
"StepperBDF2::computeStartUp()");
 
  253   *out << 
"Warning -- Taking a startup step for BDF2 using '" 
  254        << startUpStepper_->getStepperType()<<
"'!" << std::endl;
 
  257   startUpStepper_->takeStep(solutionHistory);
 
  259   order_ = startUpStepper_->getOrder();
 
  268 template<
class Scalar>
 
  269 Teuchos::RCP<Tempus::StepperState<Scalar> >
 
  273   Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
 
  279 template<
class Scalar>
 
  281   Teuchos::FancyOStream               &out,
 
  282   const Teuchos::EVerbosityLevel      verbLevel )
 const 
  288   out << 
"--- StepperBDF2 ---\n";
 
  289   if (startUpStepper_ != Teuchos::null) {
 
  290     out << 
"  startup stepper type             = " 
  291         << startUpStepper_->description() << std::endl;
 
  293   out << 
"  startUpStepper_                  = " 
  294       << startUpStepper_ << std::endl;
 
  295   out << 
"  startUpStepper_->isInitialized() = " 
  297   out << 
"  stepperBDF2Observer_             = " 
  298       << stepperBDF2Observer_ << std::endl;
 
  299   out << 
"  order_                           = " << order_ << std::endl;
 
  300   out << 
"-------------------" << std::endl;
 
  304 template<
class Scalar>
 
  307   bool isValidSetup = 
true;
 
  312   if ( !this->startUpStepper_->isInitialized() ) {
 
  313     isValidSetup = 
false;
 
  314     out << 
"The startup stepper is not initialized!\n";
 
  317   if (stepperBDF2Observer_ == Teuchos::null) {
 
  318     isValidSetup = 
false;
 
  319     out << 
"The BDF2 observer is not set!\n";
 
  326 template<
class Scalar>
 
  327 Teuchos::RCP<const Teuchos::ParameterList>
 
  330   Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
 
  332   pl->set<
bool>(
"Initial Condition Consistency Check",
 
  333                 this->getICConsistencyCheckDefault());
 
  334   pl->set<std::string>(
"Solver Name", 
"Default Solver");
 
  335   pl->set<
bool>(
"Zero Initial Guess", 
false);
 
  336   pl->set<std::string>(
"Start Up Stepper Type", 
"DIRK 1 Stage Theta Method");
 
  338   pl->set(
"Default Solver", *solverPL);
 
  345 #endif // Tempus_StepperBDF2_impl_hpp 
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent. 
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent. 
Time-derivative interface for BDF2. 
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState. 
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer. 
const std::string toString(const Status status)
Convert Status to string. 
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const 
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers. 
virtual void initialize()
Initialize after construction and changing input parameters. 
virtual void computeStartUp(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Compute the first time step given the supplied startup stepper. 
Thyra Base interface for time steppers. 
This observer is a composite observer,. 
StepperState is a simple class to hold state information about the stepper. 
Thyra Base interface for implicit time steppers. 
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const 
StepperObserver class for Stepper class. 
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual bool isValidSetup(Teuchos::FancyOStream &out) const 
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const 
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const 
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful. 
void setStartUpStepper(std::string startupStepperType)
Set the stepper to use in first step. 
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers. 
virtual void initialize()
Initialize during construction and after changing input parameters. 
StepperBDF2()
Default constructor. 
StepperBDF2Observer class for StepperBDF2.