Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs
Rythmos_SimpleStepControlStrategy_def.hpp
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //                           Rythmos Package
00005 //                 Copyright (2006) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00023 // USA
00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 #ifndef Rythmos_SIMPLE_STEP_CONTROL_STRATEGY_DEF_H
00030 #define Rythmos_SIMPLE_STEP_CONTROL_STRATEGY_DEF_H
00031 
00032 #include "Rythmos_SimpleStepControlStrategy_decl.hpp"
00033 #include "Thyra_VectorStdOps.hpp"
00034 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
00035 
00036 namespace Rythmos {
00037 
00038 // Static members
00039 
00040 
00041 template<class Scalar>
00042 const std::string
00043 SimpleStepControlStrategy<Scalar>::initialStepSizeName_
00044 = "Initial Step Size";
00045 
00046 template<class Scalar>
00047 const double
00048 SimpleStepControlStrategy<Scalar>::initialStepSizeDefault_
00049 = std::numeric_limits<Scalar>::min();
00050 
00051 
00052 template<class Scalar>
00053 const std::string
00054 SimpleStepControlStrategy<Scalar>::minStepSizeName_
00055 = "Min Step Size";
00056 
00057 template<class Scalar>
00058 const double
00059 SimpleStepControlStrategy<Scalar>::minStepSizeDefault_
00060 = std::numeric_limits<Scalar>::min();
00061 
00062 
00063 template<class Scalar>
00064 const std::string
00065 SimpleStepControlStrategy<Scalar>::maxStepSizeName_
00066 = "Max Step Size";
00067 
00068 template<class Scalar>
00069 const double
00070 SimpleStepControlStrategy<Scalar>::maxStepSizeDefault_
00071 = std::numeric_limits<Scalar>::max();
00072 
00073 
00074 template<class Scalar>
00075 const std::string
00076 SimpleStepControlStrategy<Scalar>::stepSizeDecreaseFactorName_
00077 = "Step Size Decrease Factor";
00078 
00079 template<class Scalar>
00080 const double
00081 SimpleStepControlStrategy<Scalar>::stepSizeDecreaseFactorDefault_
00082 = 0.5;
00083 
00084 
00085 template<class Scalar>
00086 const std::string
00087 SimpleStepControlStrategy<Scalar>::stepSizeIncreaseFactorName_
00088 = "Step Size Increase Factor";
00089 
00090 template<class Scalar>
00091 const double
00092 SimpleStepControlStrategy<Scalar>::stepSizeIncreaseFactorDefault_
00093 = 1.5;
00094 
00095 
00096 template<class Scalar>
00097 const std::string
00098 SimpleStepControlStrategy<Scalar>::maxStepFailuresName_
00099 = "Maximum Number of Step Failures";
00100 
00101 template<class Scalar>
00102 const int
00103 SimpleStepControlStrategy<Scalar>::maxStepFailuresDefault_
00104 = 100;
00105 
00106 
00107 template<class Scalar>
00108 const std::string
00109 SimpleStepControlStrategy<Scalar>::dxRelativeToleranceName_
00110 = "Solution Change Relative Tolerance";
00111 
00112 template<class Scalar>
00113 const double
00114 SimpleStepControlStrategy<Scalar>::dxRelativeToleranceDefault_
00115 = 1.0e-06;
00116 
00117 
00118 template<class Scalar>
00119 const std::string
00120 SimpleStepControlStrategy<Scalar>::dxAbsoluteToleranceName_
00121 = "Solution Change Absolute Tolerance";
00122 
00123 template<class Scalar>
00124 const double
00125 SimpleStepControlStrategy<Scalar>::dxAbsoluteToleranceDefault_
00126 = 1.0e-12;
00127 
00128 
00129 // Constructors
00130 
00131 template<class Scalar>
00132 void SimpleStepControlStrategy<Scalar>::setStepControlState_(StepControlStrategyState newState)
00133 {
00134   if (stepControlState_ == UNINITIALIZED) {
00135     TEUCHOS_TEST_FOR_EXCEPT(newState != BEFORE_FIRST_STEP);
00136   } else if (stepControlState_ == BEFORE_FIRST_STEP) {
00137     TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
00138   } else if (stepControlState_ == MID_STEP) {
00139     TEUCHOS_TEST_FOR_EXCEPT(newState != AFTER_CORRECTION);
00140   } else if (stepControlState_ == AFTER_CORRECTION) {
00141     TEUCHOS_TEST_FOR_EXCEPT(newState != READY_FOR_NEXT_STEP);
00142   } else if (stepControlState_ == READY_FOR_NEXT_STEP) {
00143     TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
00144   }
00145   stepControlState_ = newState;
00146 }
00147 
00148 template<class Scalar>
00149 StepControlStrategyState SimpleStepControlStrategy<Scalar>::getCurrentState()
00150 {
00151   return(stepControlState_);
00152 }
00153 
00154 template<class Scalar>
00155 SimpleStepControlStrategy<Scalar>::SimpleStepControlStrategy()
00156   : stepControlState_(UNINITIALIZED),
00157     initialStepSize_(initialStepSizeDefault_),
00158     stepSizeType_(STEP_TYPE_VARIABLE),
00159     minStepSize_(minStepSizeDefault_),
00160     maxStepSize_(maxStepSizeDefault_),
00161     stepSizeIncreaseFactor_(stepSizeIncreaseFactorDefault_),
00162     stepSizeDecreaseFactor_(stepSizeDecreaseFactorDefault_),
00163     numStepFailures_(0),
00164     maxStepFailures_(maxStepFailuresDefault_),
00165     maxOrder_(1),
00166     dxRelativeTolerance_(dxRelativeToleranceDefault_),
00167     dxAbsoluteTolerance_(dxAbsoluteToleranceDefault_),
00168     solveStatus_(0)
00169 {}
00170 
00171 template<class Scalar>
00172 void SimpleStepControlStrategy<Scalar>::initialize(
00173   const StepperBase<Scalar>& stepper)
00174 {
00175   using Teuchos::as;
00176   typedef Teuchos::ScalarTraits<Scalar> ST;
00177   using Thyra::createMember;
00178 
00179   RCP<Teuchos::FancyOStream> out = this->getOStream();
00180   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00181   const bool doTrace = (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH));
00182   Teuchos::OSTab ostab(out,1,"initialize");
00183 
00184   if (doTrace) {
00185     *out << "\nEntering " << this->Teuchos::Describable::description()
00186          << "::initialize()...\n";
00187   }
00188 
00189   setStepControlState_(BEFORE_FIRST_STEP);
00190 
00191   if (doTrace) {
00192     *out << "\nLeaving " << this->Teuchos::Describable::description()
00193          << "::initialize()...\n";
00194   }
00195 }
00196 
00197 template<class Scalar>
00198 void SimpleStepControlStrategy<Scalar>::setRequestedStepSize(
00199   const StepperBase<Scalar>& stepper,
00200   const Scalar& stepSize,
00201   const StepSizeType& stepSizeType)
00202 {
00203   typedef Teuchos::ScalarTraits<Scalar> ST;
00204   TEUCHOS_TEST_FOR_EXCEPTION(
00205     !((stepControlState_ == UNINITIALIZED) ||
00206       (stepControlState_ == BEFORE_FIRST_STEP) ||
00207       (stepControlState_ == READY_FOR_NEXT_STEP) ||
00208       (stepControlState_ == MID_STEP)), std::logic_error,
00209      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00210      << ") for SimpleStepControlStrategy<Scalar>::setRequestedStepSize()\n");
00211 
00212   TEUCHOS_TEST_FOR_EXCEPTION(
00213     ((stepSizeType == STEP_TYPE_FIXED) && (stepSize == ST::zero())),
00214     std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
00215     "but requested step size == 0!\n");
00216 
00217   TEUCHOS_TEST_FOR_EXCEPTION(
00218     ((stepSizeType == STEP_TYPE_FIXED) && (stepSize < minStepSize_)),
00219     std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
00220     "and (stepSize="<<stepSize<<") < (minStepSize="<<minStepSize_<<")!\n");
00221 
00222   TEUCHOS_TEST_FOR_EXCEPTION(
00223     ((stepSizeType == STEP_TYPE_FIXED) && (stepSize > maxStepSize_)),
00224     std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
00225     "and (stepSize="<<stepSize<<") > (maxStepSize="<<maxStepSize_<<")!\n");
00226 
00227   if (stepControlState_ == UNINITIALIZED) initialize(stepper);
00228   requestedStepSize_ = stepSize;
00229   stepSizeType_ = stepSizeType;
00230 }
00231 
00232 template<class Scalar>
00233 void SimpleStepControlStrategy<Scalar>::nextStepSize(
00234   const StepperBase<Scalar>& stepper, Scalar* stepSize,
00235   StepSizeType* stepSizeType, int* order)
00236 {
00237   TEUCHOS_TEST_FOR_EXCEPTION(!((stepControlState_ == BEFORE_FIRST_STEP) ||
00238                                (stepControlState_ == MID_STEP) ||
00239                                (stepControlState_ == READY_FOR_NEXT_STEP) ),
00240                                std::logic_error,
00241      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00242      << ") for SimpleStepControlStrategy<Scalar>::nextStepSize()\n");
00243 
00244   if (stepControlState_ == BEFORE_FIRST_STEP) {
00245     if (initialStepSize_ == initialStepSizeDefault_)
00246       initialStepSize_ = requestedStepSize_;
00247     nextStepSize_ = initialStepSize_;
00248   }
00249 
00250   stepSizeType_ = *stepSizeType;
00251   if (stepSizeType_ == STEP_TYPE_FIXED)
00252     currentStepSize_ = requestedStepSize_;
00253   else // STEP_TYPE_VARIABLE
00254     currentStepSize_ = nextStepSize_;
00255 
00256   // Limit the step size to the requested step size
00257   currentStepSize_ = std::min(requestedStepSize_, currentStepSize_);
00258 
00259   *stepSize = currentStepSize_;
00260   setStepControlState_(MID_STEP);
00261 }
00262 
00263 template<class Scalar>
00264 void SimpleStepControlStrategy<Scalar>::setCorrection(
00265      const StepperBase<Scalar>& stepper
00266     ,const RCP<const Thyra::VectorBase<Scalar> >& soln
00267     ,const RCP<const Thyra::VectorBase<Scalar> >& dx
00268     ,int solveStatus)
00269 {
00270   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != MID_STEP, std::logic_error,
00271      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00272      << ") for SimpleStepControlStrategy<Scalar>::setCorrection()\n");
00273   x_ = soln;
00274   dx_ = dx;
00275   solveStatus_ = solveStatus;
00276   setStepControlState_(AFTER_CORRECTION);
00277 }
00278 
00279 template<class Scalar>
00280 bool SimpleStepControlStrategy<Scalar>::acceptStep(
00281   const StepperBase<Scalar>& stepper, Scalar* value)
00282 {
00283   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00284      std::logic_error,
00285      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00286      << ") for SimpleStepControlStrategy<Scalar>::completeStep()\n");
00287 
00288   if (solveStatus_ < 0 )
00289     return false;
00290 
00291   bool return_status = true;
00292   Scalar maxAbs_x  = std::max(Thyra::max(*x_),-Thyra::min(*x_));
00293   Scalar maxAbs_dx = std::max(Thyra::max(*dx_),-Thyra::min(*dx_));
00294   Scalar dx_tolerance = dxRelativeTolerance_ * maxAbs_x + dxAbsoluteTolerance_;
00295   if (maxAbs_dx > dx_tolerance) return_status = false;
00296 
00297   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00298   if ( Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ) {
00299     RCP<Teuchos::FancyOStream> out = this->getOStream();
00300     Teuchos::OSTab ostab(out,1,"acceptStep");
00301     *out << " max |*x_|    = " << maxAbs_x << "\n"
00302          << " dx_tolerance = " << dx_tolerance << "\n"
00303          << " max |*dx_|   = " << maxAbs_dx << "\n";
00304   }
00305 
00306   return(return_status);
00307 }
00308 
00309 template<class Scalar>
00310 AttemptedStepStatusFlag SimpleStepControlStrategy<Scalar>::rejectStep(
00311   const StepperBase<Scalar>& stepper)
00312 {
00313   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00314      std::logic_error,
00315      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00316      << ") for SimpleStepControlStrategy<Scalar>::completeStep()\n");
00317 
00318   setStepControlState_(READY_FOR_NEXT_STEP);
00319 
00320   using Teuchos::as;
00321 
00322   RCP<Teuchos::FancyOStream> out = this->getOStream();
00323   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00324   Teuchos::OSTab ostab(out,1,"rejectStep");
00325 
00326   numStepFailures_ ++;
00327   if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) )
00328     *out << "numStepFailures_ = " << numStepFailures_ << "\n";
00329   if (numStepFailures_ > maxStepFailures_) {
00330     *out << "Rythmos_SimpleStepControlStrategy::rejectStep(...):  "
00331          << "Error: Too many step failures "
00332          << "(numStepFailures="<<numStepFailures_
00333          <<") > (maxStepFailures="<<maxStepFailures_<<")\n";
00334     return (REP_ERR_FAIL);
00335   }
00336 
00337   // Only update the time step if we are NOT running constant stepsize.
00338   if (stepSizeType_ == STEP_TYPE_VARIABLE) {
00339     nextStepSize_ *= stepSizeDecreaseFactor_;
00340     if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) ) {
00341       *out << "Rythmos_SimpleStepControl::rejectStep(...):  "
00342            << "  Step failure.  Reducing step size to "<< nextStepSize_ <<".\n";
00343     }
00344   } else {  // STEP_TYPE_FIXED
00345     if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) ) {
00346       *out << "Rythmos_SimpleStepControl::rejectStep(...):  "
00347            << "Error:  Step failure with fixed step size.\n";
00348     }
00349     return (REP_ERR_FAIL);
00350   }
00351 
00352   nextStepSize_ = std::max(nextStepSize_, minStepSize_);
00353   nextStepSize_ = std::min(nextStepSize_, maxStepSize_);
00354 
00355   AttemptedStepStatusFlag return_status = PREDICT_AGAIN;
00356 
00357   if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
00358     *out << "nextStepSize_ = " << nextStepSize_ << "\n";
00359   }
00360 
00361   return(return_status);
00362 }
00363 
00364 template<class Scalar>
00365 void SimpleStepControlStrategy<Scalar>::completeStep(
00366   const StepperBase<Scalar>& stepper)
00367 {
00368   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00369      std::logic_error,
00370      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00371      << ") for SimpleStepControlStrategy<Scalar>::completeStep()\n");
00372 
00373   // Only update the time step if we are NOT running constant stepsize.
00374   if (stepSizeType_ == STEP_TYPE_VARIABLE) {
00375     // Only increase stepSize_ if no recent step failures.
00376     if (numStepFailures_ == 0) {
00377       nextStepSize_ *= stepSizeIncreaseFactor_;
00378     } else {
00379       // Keep nextStepSize_ constant until we have no recent step failures.
00380       nextStepSize_ = currentStepSize_;
00381       numStepFailures_ = std::max(numStepFailures_-1,0);
00382     }
00383   }
00384   nextStepSize_ = std::max(nextStepSize_, minStepSize_);
00385   nextStepSize_ = std::min(nextStepSize_, maxStepSize_);
00386 
00387   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00388   if ( Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ) {
00389     RCP<Teuchos::FancyOStream> out = this->getOStream();
00390     Teuchos::OSTab ostab(out,1,"completeStep_");
00391     *out << "nextStepSize_    = " << nextStepSize_ << "\n";
00392     *out << "numStepFailures_ = " << numStepFailures_ << "\n";
00393   }
00394   setStepControlState_(READY_FOR_NEXT_STEP);
00395 }
00396 
00397 template<class Scalar>
00398 void SimpleStepControlStrategy<Scalar>::describe(
00399   Teuchos::FancyOStream &out,
00400   const Teuchos::EVerbosityLevel verbLevel
00401   ) const
00402 {
00403 
00404   using Teuchos::as;
00405 
00406   if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
00407        (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)     )    ) {
00408     out << this->description() << "::describe" << "\n";
00409   }
00410   if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
00411     out << "requestedStepSize_ = " << requestedStepSize_ << "\n";
00412     out << "currentStepSize_   = " << currentStepSize_ << "\n";
00413     out << "nextStepSize_      = " << nextStepSize_ << "\n";
00414     out << "stepSizeType_      = " << stepSizeType_ << "\n";
00415     out << "numStepFailures_   = " << numStepFailures_ << "\n";
00416   }
00417 }
00418 
00419 template<class Scalar>
00420 void SimpleStepControlStrategy<Scalar>::setParameterList(
00421   RCP<Teuchos::ParameterList> const& paramList)
00422 {
00423   using Teuchos::as;
00424   typedef Teuchos::ScalarTraits<Scalar> ST;
00425 
00426   TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
00427   paramList->validateParameters(*this->getValidParameters(),0);
00428   parameterList_ = paramList;
00429   Teuchos::readVerboseObjectSublist(&*parameterList_,this);
00430 
00431   initialStepSize_ = parameterList_->get(initialStepSizeName_,
00432                                          initialStepSizeDefault_);
00433   minStepSize_ = parameterList_->get(minStepSizeName_, minStepSizeDefault_);
00434   maxStepSize_ = parameterList_->get(maxStepSizeName_, maxStepSizeDefault_);
00435   TEUCHOS_TEST_FOR_EXCEPTION(
00436     !(minStepSize_ <= maxStepSize_), std::logic_error,
00437     "Error:  (minStepSize="<<minStepSize_
00438     <<") > (maxStepSize="<<maxStepSize_<<")\n");
00439   TEUCHOS_TEST_FOR_EXCEPTION(
00440     !((minStepSize_ <= initialStepSize_) && (initialStepSize_ <= maxStepSize_)),
00441     std::logic_error,
00442     "Error: Initial Step Size is not within min/max range.\n"
00443     << "  (minStepSize="<<minStepSize_
00444     <<") > (initialStepSize="<<initialStepSize_<<") or \n"
00445     << "  (maxStepSize="<<maxStepSize_
00446     <<") < (initialStepSize="<<initialStepSize_<<")\n");
00447 
00448   stepSizeIncreaseFactor_ = parameterList_->get(stepSizeIncreaseFactorName_,
00449                                                 stepSizeIncreaseFactorDefault_);
00450   TEUCHOS_TEST_FOR_EXCEPTION(
00451     !(stepSizeIncreaseFactor_ > 0.0), std::logic_error,
00452     "Error:  (stepSizeIncreaseFactor="<<stepSizeIncreaseFactor_<<") <= 0.0\n");
00453 
00454   stepSizeDecreaseFactor_ = parameterList_->get(stepSizeDecreaseFactorName_,
00455                                                 stepSizeDecreaseFactorDefault_);
00456   TEUCHOS_TEST_FOR_EXCEPTION(
00457     !(stepSizeDecreaseFactor_ > 0.0), std::logic_error,
00458     "Error:  (stepSizeDecreaseFactor="<<stepSizeDecreaseFactor_<<") <= 0.0\n");
00459 
00460   maxStepFailures_ = parameterList_->get(maxStepFailuresName_,
00461                                          maxStepFailuresDefault_);
00462   TEUCHOS_TEST_FOR_EXCEPTION(
00463     !(maxStepFailures_ >= 0), std::logic_error,
00464     "Error:  (maxStepFailures="<<maxStepFailures_<<") < 0\n");
00465 
00466   dxRelativeTolerance_ = parameterList_->get(dxRelativeToleranceName_,
00467                                              dxRelativeToleranceDefault_);
00468   TEUCHOS_TEST_FOR_EXCEPTION(
00469     !(dxRelativeTolerance_ >= 0.0), std::logic_error,
00470     "Error:  (dxRelativeTolerance="<<dxRelativeTolerance_<<") < 0.0\n");
00471 
00472   dxAbsoluteTolerance_ = parameterList_->get(dxAbsoluteToleranceName_,
00473                                              dxAbsoluteToleranceDefault_);
00474   TEUCHOS_TEST_FOR_EXCEPTION(
00475     !(dxAbsoluteTolerance_ >= 0.0), std::logic_error,
00476     "Error:  (dxAbsoluteTolerance="<<dxAbsoluteTolerance_<<") < 0.0\n");
00477 
00478   RCP<Teuchos::FancyOStream> out = this->getOStream();
00479   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00480   Teuchos::OSTab ostab(out,1,"setParameterList");
00481   out->precision(15);
00482 
00483   if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
00484     *out << "minStepSize_            = " << minStepSize_           << "\n";
00485     *out << "maxStepSize_            = " << maxStepSize_           << "\n";
00486     *out << "stepSizeIncreaseFactor_ = " << stepSizeIncreaseFactor_<< "\n";
00487     *out << "stepSizeDecreaseFactor_ = " << stepSizeDecreaseFactor_<< "\n";
00488     *out << "maxStepFailures_        = " << maxStepFailures_       << "\n";
00489     *out << "dxRelativeTolerance_    = " << dxRelativeTolerance_   << "\n";
00490     *out << "dxAbsoluteTolerance_    = " << dxAbsoluteTolerance_   << "\n";
00491   }
00492 }
00493 
00494 template<class Scalar>
00495 RCP<const Teuchos::ParameterList>
00496 SimpleStepControlStrategy<Scalar>::getValidParameters() const
00497 {
00498   static RCP<Teuchos::ParameterList> validPL;
00499   if (is_null(validPL)) {
00500     RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
00501 
00502     pl->set(initialStepSizeName_,initialStepSizeDefault_, "Initial step size.");
00503     pl->set(minStepSizeName_, minStepSizeDefault_, "Minimum step size.");
00504     pl->set(maxStepSizeName_, maxStepSizeDefault_, "Maximum step size.");
00505     pl->set(stepSizeIncreaseFactorName_, stepSizeIncreaseFactorDefault_,
00506       "Factor used to increase the step size after a successful step.");
00507     pl->set(stepSizeDecreaseFactorName_, stepSizeDecreaseFactorDefault_,
00508       "Factor used to decrease the step size after a step failure.");
00509     pl->set(maxStepFailuresName_, maxStepFailuresDefault_,
00510       "The maximum number of step failures before exiting with an error.  "
00511       "The number of failure steps are carried between successful steps.");
00512     pl->set(dxRelativeToleranceName_, dxRelativeToleranceDefault_,
00513       "The allowable relative change in the solution for each step to "
00514       "pass.  The stepper solution status is also used to determine "
00515       "pass/fail.");
00516     pl->set(dxAbsoluteToleranceName_, dxAbsoluteToleranceDefault_,
00517       "The allowable absolute change in the solution for each step to "
00518       "pass.  The stepper solution status is also used to determine "
00519       "pass/fail.");
00520 
00521     Teuchos::setupVerboseObjectSublist(&*pl);
00522     validPL = pl;
00523   }
00524   return (validPL);
00525 }
00526 
00527 template<class Scalar>
00528 RCP<Teuchos::ParameterList>
00529 SimpleStepControlStrategy<Scalar>::unsetParameterList()
00530 {
00531   RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
00532   parameterList_ = Teuchos::null;
00533   return(temp_param_list);
00534 }
00535 
00536 template<class Scalar>
00537 RCP<Teuchos::ParameterList>
00538 SimpleStepControlStrategy<Scalar>::getNonconstParameterList()
00539 {
00540   return(parameterList_);
00541 }
00542 
00543 template<class Scalar>
00544 void SimpleStepControlStrategy<Scalar>::setStepControlData(const StepperBase<Scalar>& stepper)
00545 {
00546   if (stepControlState_ == UNINITIALIZED) initialize(stepper);
00547 }
00548 
00549 template<class Scalar>
00550 bool SimpleStepControlStrategy<Scalar>::supportsCloning() const
00551 {
00552   return true;
00553 }
00554 
00555 
00556 template<class Scalar>
00557 RCP<StepControlStrategyBase<Scalar> >
00558 SimpleStepControlStrategy<Scalar>::cloneStepControlStrategyAlgorithm() const
00559 {
00560 
00561   RCP<SimpleStepControlStrategy<Scalar> >
00562     stepControl = rcp(new SimpleStepControlStrategy<Scalar>());
00563 
00564   if (!is_null(parameterList_)) {
00565     stepControl->setParameterList(parameterList_);
00566   }
00567 
00568   return stepControl;
00569 }
00570 
00571 template<class Scalar>
00572 int SimpleStepControlStrategy<Scalar>::getMaxOrder() const
00573 {
00574   TEUCHOS_TEST_FOR_EXCEPTION(
00575       stepControlState_ == UNINITIALIZED, std::logic_error,
00576       "Error, attempting to call getMaxOrder before initialization!\n"
00577       );
00578   return(maxOrder_);
00579 }
00580 
00581 //
00582 // Explicit Instantiation macro
00583 //
00584 // Must be expanded from within the Rythmos namespace!
00585 //
00586 
00587 #define RYTHMOS_SIMPLE_STEP_CONTROL_STRATEGY_INSTANT(SCALAR) \
00588   template class SimpleStepControlStrategy< SCALAR >;
00589 
00590 
00591 } // namespace Rythmos
00592 #endif // Rythmos_SIMPLE_STEP_CONTROL_STRATEGY_DEF_H
 All Classes Functions Variables Typedefs