Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs
Rythmos_FirstOrderErrorStepControlStrategy_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_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_DEF_H
00030 #define Rythmos_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_DEF_H
00031 
00032 #include "Rythmos_FirstOrderErrorStepControlStrategy_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 FirstOrderErrorStepControlStrategy<Scalar>::initialStepSizeName_
00044 = "Initial Step Size";
00045 
00046 template<class Scalar>
00047 const double
00048 FirstOrderErrorStepControlStrategy<Scalar>::initialStepSizeDefault_
00049 = 1.0;
00050 
00051 
00052 template<class Scalar>
00053 const std::string
00054 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeName_
00055 = "Min Step Size";
00056 
00057 template<class Scalar>
00058 const double
00059 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeDefault_
00060 = std::numeric_limits<Scalar>::min();
00061 
00062 
00063 template<class Scalar>
00064 const std::string
00065 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeName_
00066 = "Max Step Size";
00067 
00068 template<class Scalar>
00069 const double
00070 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeDefault_
00071 = std::numeric_limits<Scalar>::max();
00072 
00073 
00074 template<class Scalar>
00075 const std::string
00076 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeIncreaseFactorName_
00077 = "Max Step Size Increase Factor";
00078 
00079 template<class Scalar>
00080 const double
00081 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeIncreaseFactorDefault_
00082 = 1.5;
00083 
00084 
00085 template<class Scalar>
00086 const std::string
00087 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeDecreaseFactorName_
00088 = "Min Step Size Decrease Factor";
00089 
00090 template<class Scalar>
00091 const double
00092 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeDecreaseFactorDefault_
00093 = 0.5;
00094 
00095 
00096 template<class Scalar>
00097 const std::string
00098 FirstOrderErrorStepControlStrategy<Scalar>::maxStepFailuresName_
00099 = "Maximum Number of Step Failures";
00100 
00101 template<class Scalar>
00102 const int
00103 FirstOrderErrorStepControlStrategy<Scalar>::maxStepFailuresDefault_
00104 = 100;
00105 
00106 
00107 template<class Scalar>
00108 const std::string
00109 FirstOrderErrorStepControlStrategy<Scalar>::errorRelativeToleranceName_
00110 = "Error Relative Tolerance";
00111 
00112 template<class Scalar>
00113 const double
00114 FirstOrderErrorStepControlStrategy<Scalar>::errorRelativeToleranceDefault_
00115 = 1.0e-06;
00116 
00117 
00118 template<class Scalar>
00119 const std::string
00120 FirstOrderErrorStepControlStrategy<Scalar>::errorAbsoluteToleranceName_
00121 = "Error Absolute Tolerance";
00122 
00123 template<class Scalar>
00124 const double
00125 FirstOrderErrorStepControlStrategy<Scalar>::errorAbsoluteToleranceDefault_
00126 = 1.0e-12;
00127 
00128 
00129 // Constructors
00130 
00131 template<class Scalar>
00132 void FirstOrderErrorStepControlStrategy<Scalar>::setStepControlState_(
00133   StepControlStrategyState newState)
00134 {
00135   if (stepControlState_ == UNINITIALIZED) {
00136     TEUCHOS_TEST_FOR_EXCEPT(newState != BEFORE_FIRST_STEP);
00137   } else if (stepControlState_ == BEFORE_FIRST_STEP) {
00138     TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
00139   } else if (stepControlState_ == MID_STEP) {
00140     TEUCHOS_TEST_FOR_EXCEPT(newState != AFTER_CORRECTION);
00141   } else if (stepControlState_ == AFTER_CORRECTION) {
00142     TEUCHOS_TEST_FOR_EXCEPT(newState != READY_FOR_NEXT_STEP);
00143   } else if (stepControlState_ == READY_FOR_NEXT_STEP) {
00144     TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
00145   }
00146   stepControlState_ = newState;
00147 }
00148 
00149 template<class Scalar>
00150 StepControlStrategyState FirstOrderErrorStepControlStrategy<Scalar>::getCurrentState()
00151 {
00152   return(stepControlState_);
00153 }
00154 
00155 template<class Scalar>
00156 FirstOrderErrorStepControlStrategy<Scalar>::FirstOrderErrorStepControlStrategy()
00157   : stepControlState_(UNINITIALIZED),
00158     initialStepSize_(initialStepSizeDefault_),
00159     stepSizeType_(STEP_TYPE_VARIABLE),
00160     minStepSize_(minStepSizeDefault_),
00161     maxStepSize_(maxStepSizeDefault_),
00162     maxStepSizeIncreaseFactor_(maxStepSizeIncreaseFactorDefault_),
00163     minStepSizeDecreaseFactor_(minStepSizeDecreaseFactorDefault_),
00164     numStepFailures_(0),
00165     maxStepFailures_(maxStepFailuresDefault_),
00166     maxOrder_(1),
00167     errorRelativeTolerance_(errorRelativeToleranceDefault_),
00168     errorAbsoluteTolerance_(errorAbsoluteToleranceDefault_),
00169     solveStatus_(0)
00170 {}
00171 
00172 template<class Scalar>
00173 void FirstOrderErrorStepControlStrategy<Scalar>::initialize(
00174   const StepperBase<Scalar>& stepper)
00175 {
00176   using Teuchos::as;
00177   typedef Teuchos::ScalarTraits<Scalar> ST;
00178   using Thyra::createMember;
00179 
00180   RCP<Teuchos::FancyOStream> out = this->getOStream();
00181   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00182   const bool doTrace = (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH));
00183   Teuchos::OSTab ostab(out,1,"initialize");
00184 
00185   if (doTrace) {
00186     *out << "\nEntering " << this->Teuchos::Describable::description()
00187          << "::initialize()...\n";
00188   }
00189 
00190   if (is_null(errWtVec_))
00191     errWtVec_ = createMember(stepper.get_x_space());
00192   setStepControlState_(BEFORE_FIRST_STEP);
00193 
00194   if (doTrace) {
00195     *out << "\nLeaving " << this->Teuchos::Describable::description()
00196          << "::initialize()...\n";
00197   }
00198 }
00199 
00200 template<class Scalar>
00201 void FirstOrderErrorStepControlStrategy<Scalar>::setRequestedStepSize(
00202   const StepperBase<Scalar>& stepper,
00203   const Scalar& stepSize,
00204   const StepSizeType& stepSizeType)
00205 {
00206   typedef Teuchos::ScalarTraits<Scalar> ST;
00207   TEUCHOS_TEST_FOR_EXCEPTION(
00208     !((stepControlState_ == UNINITIALIZED) ||
00209       (stepControlState_ == BEFORE_FIRST_STEP) ||
00210       (stepControlState_ == READY_FOR_NEXT_STEP) ||
00211       (stepControlState_ == MID_STEP)), std::logic_error,
00212      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00213      << ") for FirstOrderErrorStepControlStrategy<Scalar>::setRequestedStepSize()\n");
00214 
00215   TEUCHOS_TEST_FOR_EXCEPTION(
00216     ((stepSizeType == STEP_TYPE_FIXED) && (stepSize == ST::zero())),
00217     std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
00218     "but requested step size == 0!\n");
00219 
00220   TEUCHOS_TEST_FOR_EXCEPTION(
00221     ((stepSizeType == STEP_TYPE_FIXED) && (stepSize < minStepSize_)),
00222     std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
00223     "and (stepSize="<<stepSize<<") < (minStepSize="<<minStepSize_<<")!\n");
00224 
00225   TEUCHOS_TEST_FOR_EXCEPTION(
00226     ((stepSizeType == STEP_TYPE_FIXED) && (stepSize > maxStepSize_)),
00227     std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
00228     "and (stepSize="<<stepSize<<") > (maxStepSize="<<maxStepSize_<<")!\n");
00229 
00230   if (stepControlState_ == UNINITIALIZED) initialize(stepper);
00231   requestedStepSize_ = stepSize;
00232   stepSizeType_ = stepSizeType;
00233 }
00234 
00235 template<class Scalar>
00236 void FirstOrderErrorStepControlStrategy<Scalar>::nextStepSize(
00237   const StepperBase<Scalar>& stepper, Scalar* stepSize,
00238   StepSizeType* stepSizeType, int* order)
00239 {
00240   TEUCHOS_TEST_FOR_EXCEPTION(!((stepControlState_ == BEFORE_FIRST_STEP) ||
00241                                (stepControlState_ == MID_STEP) ||
00242                                (stepControlState_ == READY_FOR_NEXT_STEP) ),
00243                                std::logic_error,
00244      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00245      << ") for FirstOrderErrorStepControlStrategy<Scalar>::nextStepSize()\n");
00246 
00247   if (stepControlState_ == BEFORE_FIRST_STEP) {
00248     if (initialStepSize_ == initialStepSizeDefault_)
00249       initialStepSize_ = requestedStepSize_;
00250     nextStepSize_ = initialStepSize_;
00251   }
00252 
00253   stepSizeType_ = *stepSizeType;
00254   if (stepSizeType_ == STEP_TYPE_FIXED)
00255     currentStepSize_ = requestedStepSize_;
00256   else // STEP_TYPE_VARIABLE
00257     currentStepSize_ = nextStepSize_;
00258 
00259   // Limit the step size to the requested step size
00260   currentStepSize_ = std::min(requestedStepSize_, currentStepSize_);
00261 
00262   *stepSize = currentStepSize_;
00263   setStepControlState_(MID_STEP);
00264 }
00265 
00266 template<class Scalar>
00267 void FirstOrderErrorStepControlStrategy<Scalar>::setCorrection(
00268      const StepperBase<Scalar>& stepper
00269     ,const RCP<const Thyra::VectorBase<Scalar> >& soln
00270     ,const RCP<const Thyra::VectorBase<Scalar> >& dx
00271     ,int solveStatus)
00272 {
00273   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != MID_STEP, std::logic_error,
00274      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00275      << ") for FirstOrderErrorStepControlStrategy<Scalar>::setCorrection()\n");
00276   x_ = soln;
00277   dx_ = dx;
00278   solveStatus_ = solveStatus;
00279   setStepControlState_(AFTER_CORRECTION);
00280 }
00281 
00282 template<class Scalar>
00283 bool FirstOrderErrorStepControlStrategy<Scalar>::acceptStep(
00284   const StepperBase<Scalar>& stepper, Scalar* value)
00285 {
00286   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00287      std::logic_error,
00288      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00289      << ") for FirstOrderErrorStepControlStrategy<Scalar>::completeStep()\n");
00290 
00291   // Let's construct the weight here for now.  We will replace with it
00292   // with a errWtVecSet() in the future.
00293   Thyra::abs(*x_, Teuchos::ptrFromRef(*errWtVec_));
00294   Thyra::Vt_S(Teuchos::ptrFromRef(*errWtVec_), errorRelativeTolerance_);
00295   Thyra::Vp_S(Teuchos::ptrFromRef(*errWtVec_), errorAbsoluteTolerance_);
00296   reciprocal(*errWtVec_, Teuchos::ptrFromRef(*errWtVec_));
00297   typedef Teuchos::ScalarTraits<Scalar> ST;
00298   // We square w because of how weighted norm_2 is computed.
00299   Vt_StV(Teuchos::ptrFromRef(*errWtVec_), ST::one(), *errWtVec_);
00300   // divide by N to get RMS norm
00301   int N = x_->space()->dim();
00302   Vt_S(Teuchos::ptrFromRef(*errWtVec_), Teuchos::as<Scalar>(1.0/N));
00303   double wrms = norm_2(*errWtVec_,(*dx_));
00304   stepSizeFactor_ = sqrt(2.0/wrms);     // Factor for 1st order. See
00305                                         // Gresho and Sani, "Incompressible
00306                                         // Flow and the Finite Element Method",
00307                                         // Vol. 1, 1998, p. 268.
00308   bool return_status = true;
00309   // If the error is too large (stepSizeFactor_ too small) OR
00310   // the solve failed, reduce the step size and try again.
00311   if ( (stepSizeFactor_ < minStepSizeDecreaseFactor_) || solveStatus_ < 0 )
00312     return_status = false;
00313 
00314   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00315   if ( Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ||
00316        (return_status == false &&
00317         Teuchos::as<int>(verbLevel) != Teuchos::as<int>(Teuchos::VERB_NONE)) ) {
00318     RCP<Teuchos::FancyOStream> out = this->getOStream();
00319     Teuchos::OSTab ostab(out,1,"acceptStep");
00320     *out << "\n wrms                       = " << wrms << "\n"
00321          << " stepSizeFactor_            = " << stepSizeFactor_ << "\n"
00322          << " solveStatus_               = " << solveStatus_ << "\n"
00323          << " minStepSizeDecreaseFactor_ = " << minStepSizeDecreaseFactor_
00324          << "\n";
00325   }
00326 
00327   return(return_status);
00328 }
00329 
00330 template<class Scalar>
00331 AttemptedStepStatusFlag FirstOrderErrorStepControlStrategy<Scalar>::rejectStep(
00332   const StepperBase<Scalar>& stepper)
00333 {
00334   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00335      std::logic_error,
00336      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00337      << ") for FirstOrderErrorStepControlStrategy<Scalar>::completeStep()\n");
00338 
00339   setStepControlState_(READY_FOR_NEXT_STEP);
00340 
00341   using Teuchos::as;
00342 
00343   RCP<Teuchos::FancyOStream> out = this->getOStream();
00344   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00345   Teuchos::OSTab ostab(out,1,"rejectStep");
00346 
00347   numStepFailures_ ++;
00348   if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) )
00349     *out << "numStepFailures_ = " << numStepFailures_ << "\n";
00350   if (numStepFailures_ > maxStepFailures_) {
00351     *out << "Rythmos_FirstOrderErrorStepControlStrategy::rejectStep(...):  "
00352          << "Error: Too many step failures "
00353          << "(numStepFailures="<<numStepFailures_
00354          <<") > (maxStepFailures="<<maxStepFailures_<<")\n";
00355     return (REP_ERR_FAIL);
00356   }
00357 
00358   // Fail if we are running with fixed stepsize.
00359   if (stepSizeType_ == STEP_TYPE_FIXED) {
00360     if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) ) {
00361       *out << "Rythmos_FirstOrderErrorStepControl::rejectStep(...):  "
00362            << "Error:  Step failure with fixed step size.\n";
00363     }
00364     return (REP_ERR_FAIL);
00365   }
00366 
00367   nextStepSize_ = currentStepSize_*
00368                   std::max(stepSizeFactor_, minStepSizeDecreaseFactor_);
00369   nextStepSize_ = std::max(nextStepSize_, minStepSize_);
00370   nextStepSize_ = std::min(nextStepSize_, maxStepSize_);
00371 
00372   AttemptedStepStatusFlag return_status = PREDICT_AGAIN;
00373 
00374   if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) ) {
00375     *out << "Rythmos_FirstOrderErrorStepControl::rejectStep(...):  Step failure.\n"
00376          << "  Current step size is "<< currentStepSize_ <<".\n"
00377          << "  Reducing next step size to "<< nextStepSize_ <<".\n";
00378   }
00379 
00380   return(return_status);
00381 }
00382 
00383 template<class Scalar>
00384 void FirstOrderErrorStepControlStrategy<Scalar>::completeStep(
00385   const StepperBase<Scalar>& stepper)
00386 {
00387   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00388      std::logic_error,
00389      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00390      << ") for FirstOrderErrorStepControlStrategy<Scalar>::completeStep()\n");
00391 
00392   // Only update the time step if we are NOT running constant stepsize.
00393   if (stepSizeType_ == STEP_TYPE_VARIABLE) {
00394     // Only increase stepSize_ if no recent step failures.
00395     if (numStepFailures_ == 0) {
00396       nextStepSize_ *= std::max(minStepSizeDecreaseFactor_,
00397                          std::min(stepSizeFactor_, maxStepSizeIncreaseFactor_));
00398     } else {
00399       // Keep nextStepSize_ constant until we have no recent step failures.
00400       nextStepSize_ = currentStepSize_;
00401       numStepFailures_ = std::max(numStepFailures_-1,0);
00402     }
00403   }
00404   nextStepSize_ = std::max(nextStepSize_, minStepSize_);
00405   nextStepSize_ = std::min(nextStepSize_, maxStepSize_);
00406 
00407   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00408   if ( Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ) {
00409     RCP<Teuchos::FancyOStream> out = this->getOStream();
00410     Teuchos::OSTab ostab(out,1,"completeStep_");
00411     *out << "nextStepSize_    = " << nextStepSize_ << "\n";
00412     *out << "numStepFailures_ = " << numStepFailures_ << "\n";
00413   }
00414   setStepControlState_(READY_FOR_NEXT_STEP);
00415 }
00416 
00417 template<class Scalar>
00418 void FirstOrderErrorStepControlStrategy<Scalar>::describe(
00419   Teuchos::FancyOStream &out,
00420   const Teuchos::EVerbosityLevel verbLevel
00421   ) const
00422 {
00423 
00424   using Teuchos::as;
00425 
00426   if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
00427        (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)     )    ) {
00428     out << this->description() << "::describe" << "\n";
00429   }
00430   if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
00431     out << "requestedStepSize_ = " << requestedStepSize_ << "\n";
00432     out << "currentStepSize_   = " << currentStepSize_ << "\n";
00433     out << "nextStepSize_      = " << nextStepSize_ << "\n";
00434     out << "stepSizeType_      = " << stepSizeType_ << "\n";
00435     out << "numStepFailures_   = " << numStepFailures_ << "\n";
00436   }
00437 }
00438 
00439 template<class Scalar>
00440 void FirstOrderErrorStepControlStrategy<Scalar>::setParameterList(
00441   RCP<Teuchos::ParameterList> const& paramList)
00442 {
00443   using Teuchos::as;
00444   typedef Teuchos::ScalarTraits<Scalar> ST;
00445 
00446   TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
00447   paramList->validateParameters(*this->getValidParameters(),0);
00448   parameterList_ = paramList;
00449   Teuchos::readVerboseObjectSublist(&*parameterList_,this);
00450 
00451   initialStepSize_ = parameterList_->get(initialStepSizeName_,
00452                                          initialStepSizeDefault_);
00453   minStepSize_ = parameterList_->get(minStepSizeName_, minStepSizeDefault_);
00454   maxStepSize_ = parameterList_->get(maxStepSizeName_, maxStepSizeDefault_);
00455   TEUCHOS_TEST_FOR_EXCEPTION(
00456     !(minStepSize_ <= maxStepSize_), std::logic_error,
00457     "Error:  (minStepSize="<<minStepSize_
00458     <<") > (maxStepSize="<<maxStepSize_<<")\n");
00459   TEUCHOS_TEST_FOR_EXCEPTION(
00460     !((minStepSize_ <= initialStepSize_) && (initialStepSize_ <= maxStepSize_)),
00461     std::logic_error,
00462     "Error: Initial Step Size is not within min/max range.\n"
00463     << "  (minStepSize="<<minStepSize_
00464     <<") > (initialStepSize="<<initialStepSize_<<") or \n"
00465     << "  (maxStepSize="<<maxStepSize_
00466     <<") < (initialStepSize="<<initialStepSize_<<")\n");
00467 
00468   maxStepSizeIncreaseFactor_ =
00469     parameterList_->get(maxStepSizeIncreaseFactorName_,
00470                         maxStepSizeIncreaseFactorDefault_);
00471   TEUCHOS_TEST_FOR_EXCEPTION(
00472     !(maxStepSizeIncreaseFactor_ > 0.0), std::logic_error,
00473     "Error:  (maxStepSizeIncreaseFactor="
00474     <<maxStepSizeIncreaseFactor_<<") <= 0.0\n");
00475 
00476   minStepSizeDecreaseFactor_ =
00477     parameterList_->get(minStepSizeDecreaseFactorName_,
00478                         minStepSizeDecreaseFactorDefault_);
00479   TEUCHOS_TEST_FOR_EXCEPTION(
00480     !(minStepSizeDecreaseFactor_ > 0.0), std::logic_error,
00481     "Error:  (minStepSizeDecreaseFactor="
00482     <<minStepSizeDecreaseFactor_<<") <= 0.0\n");
00483 
00484   TEUCHOS_TEST_FOR_EXCEPTION(
00485     !(minStepSizeDecreaseFactor_ < maxStepSizeIncreaseFactor_),
00486     std::logic_error, "Error:  "
00487     "(minStepSizeDecreaseFactor="<<minStepSizeDecreaseFactor_<<") >="
00488     "(maxStepSizeIncreaseFactor="<<maxStepSizeIncreaseFactor_<<")\n");
00489 
00490   maxStepFailures_ = parameterList_->get(maxStepFailuresName_,
00491                                          maxStepFailuresDefault_);
00492   TEUCHOS_TEST_FOR_EXCEPTION(
00493     !(maxStepFailures_ >= 0), std::logic_error,
00494     "Error:  (maxStepFailures="<<maxStepFailures_<<") < 0\n");
00495 
00496   errorRelativeTolerance_ = parameterList_->get(errorRelativeToleranceName_,
00497                                                 errorRelativeToleranceDefault_);
00498   TEUCHOS_TEST_FOR_EXCEPTION(
00499     !(errorRelativeTolerance_ >= 0.0), std::logic_error,
00500     "Error:  (errorRelativeTolerance="<<errorRelativeTolerance_<<") < 0.0\n");
00501 
00502   errorAbsoluteTolerance_ = parameterList_->get(errorAbsoluteToleranceName_,
00503                                                 errorAbsoluteToleranceDefault_);
00504   TEUCHOS_TEST_FOR_EXCEPTION(
00505     !(errorAbsoluteTolerance_ >= 0.0), std::logic_error,
00506     "Error:  (errorAbsoluteTolerance="<<errorAbsoluteTolerance_<<") < 0.0\n");
00507 
00508   RCP<Teuchos::FancyOStream> out = this->getOStream();
00509   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00510   Teuchos::OSTab ostab(out,1,"setParameterList");
00511   out->precision(15);
00512 
00513   if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
00514     *out << "minStepSize_               = " << minStepSize_              <<"\n";
00515     *out << "maxStepSize_               = " << maxStepSize_              <<"\n";
00516     *out << "maxStepSizeIncreaseFactor_ = " << maxStepSizeIncreaseFactor_<<"\n";
00517     *out << "minStepSizeDecreaseFactor_ = " << minStepSizeDecreaseFactor_<<"\n";
00518     *out << "maxStepFailures_           = " << maxStepFailures_          <<"\n";
00519     *out << "errorRelativeTolerance_    = " << errorRelativeTolerance_   <<"\n";
00520     *out << "errorAbsoluteTolerance_    = " << errorAbsoluteTolerance_   <<"\n";
00521   }
00522 }
00523 
00524 template<class Scalar>
00525 RCP<const Teuchos::ParameterList>
00526 FirstOrderErrorStepControlStrategy<Scalar>::getValidParameters() const
00527 {
00528   static RCP<Teuchos::ParameterList> validPL;
00529   if (is_null(validPL)) {
00530     RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
00531 
00532     pl->set(initialStepSizeName_,initialStepSizeDefault_, "Initial step size.");
00533     pl->set(minStepSizeName_, minStepSizeDefault_, "Minimum step size.");
00534     pl->set(maxStepSizeName_, maxStepSizeDefault_, "Maximum step size.");
00535     pl->set(maxStepSizeIncreaseFactorName_, maxStepSizeIncreaseFactorDefault_,
00536       "The maximum factor to increase the step size after a successful step.");
00537     pl->set(minStepSizeDecreaseFactorName_, minStepSizeDecreaseFactorDefault_,
00538       "The minimum allowable factor to decrease the step size.  If the "
00539       "stepSizeFactor_ is below this, the current step is considered a "
00540       "failure and retried with `" + minStepSizeDecreaseFactorName_ +
00541       "' applied.");
00542     pl->set(maxStepFailuresName_, maxStepFailuresDefault_,
00543       "The maximum number of step failures before exiting with an error.  "
00544       "The number of failure steps are carried between successful steps.");
00545     pl->set(errorRelativeToleranceName_, errorRelativeToleranceDefault_,
00546       "The allowable relative change in the error (the difference between "
00547       "the solution at the end of the step and the predicted solution) for "
00548       "each step to pass.  The stepper solution status is also used to "
00549       "determine pass/fail.");
00550     pl->set(errorAbsoluteToleranceName_, errorAbsoluteToleranceDefault_,
00551       "The allowable absolute change in the error (the difference between "
00552       "the solution at the end of the step and the predicted solution) for "
00553       "each step to pass.  The stepper solution status is also used to "
00554       "determine pass/fail.");
00555 
00556     Teuchos::setupVerboseObjectSublist(&*pl);
00557     validPL = pl;
00558   }
00559   return (validPL);
00560 }
00561 
00562 template<class Scalar>
00563 RCP<Teuchos::ParameterList>
00564 FirstOrderErrorStepControlStrategy<Scalar>::unsetParameterList()
00565 {
00566   RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
00567   parameterList_ = Teuchos::null;
00568   return(temp_param_list);
00569 }
00570 
00571 template<class Scalar>
00572 RCP<Teuchos::ParameterList>
00573 FirstOrderErrorStepControlStrategy<Scalar>::getNonconstParameterList()
00574 {
00575   return(parameterList_);
00576 }
00577 
00578 template<class Scalar>
00579 void FirstOrderErrorStepControlStrategy<Scalar>::setStepControlData(
00580   const StepperBase<Scalar>& stepper)
00581 {
00582   if (stepControlState_ == UNINITIALIZED) initialize(stepper);
00583 }
00584 
00585 template<class Scalar>
00586 bool FirstOrderErrorStepControlStrategy<Scalar>::supportsCloning() const
00587 {
00588   return true;
00589 }
00590 
00591 
00592 template<class Scalar>
00593 RCP<StepControlStrategyBase<Scalar> >
00594 FirstOrderErrorStepControlStrategy<Scalar>::cloneStepControlStrategyAlgorithm() const
00595 {
00596   RCP<FirstOrderErrorStepControlStrategy<Scalar> >
00597     stepControl = rcp(new FirstOrderErrorStepControlStrategy<Scalar>());
00598 
00599   if (!is_null(parameterList_)) {
00600     stepControl->setParameterList(parameterList_);
00601   }
00602 
00603   return stepControl;
00604 }
00605 
00606 template<class Scalar>
00607 int FirstOrderErrorStepControlStrategy<Scalar>::getMaxOrder() const
00608 {
00609   TEUCHOS_TEST_FOR_EXCEPTION(
00610       stepControlState_ == UNINITIALIZED, std::logic_error,
00611       "Error, attempting to call getMaxOrder before initialization!\n"
00612       );
00613   return(maxOrder_);
00614 }
00615 
00616 //
00617 // Explicit Instantiation macro
00618 //
00619 // Must be expanded from within the Rythmos namespace!
00620 //
00621 
00622 #define RYTHMOS_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_INSTANT(SCALAR) \
00623   template class FirstOrderErrorStepControlStrategy< SCALAR >;
00624 
00625 
00626 } // namespace Rythmos
00627 #endif // Rythmos_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_DEF_H
 All Classes Functions Variables Typedefs