Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs
Rythmos_FixedStepControlStrategy_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_FIXED_STEP_CONTROL_STRATEGY_DEF_H
00030 #define Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H
00031 
00032 #include "Rythmos_FixedStepControlStrategy_decl.hpp"
00033 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
00034 
00035 namespace Rythmos {
00036 
00037 
00038 // Constructors
00039 
00040 template<class Scalar>
00041 void FixedStepControlStrategy<Scalar>::setStepControlState_(
00042   StepControlStrategyState newState)
00043 {
00044   if (stepControlState_ == UNINITIALIZED) {
00045     TEUCHOS_TEST_FOR_EXCEPTION(newState != BEFORE_FIRST_STEP, std::logic_error,
00046                                "newState = " << toString(newState) << "\n");
00047   } else if (stepControlState_ == BEFORE_FIRST_STEP) {
00048     TEUCHOS_TEST_FOR_EXCEPTION(newState != MID_STEP, std::logic_error,
00049                                "newState = " << toString(newState) << "\n");
00050   } else if (stepControlState_ == MID_STEP) {
00051     TEUCHOS_TEST_FOR_EXCEPTION(newState != AFTER_CORRECTION, std::logic_error,
00052                                "newState = " << toString(newState) << "\n");
00053   } else if (stepControlState_ == AFTER_CORRECTION) {
00054     TEUCHOS_TEST_FOR_EXCEPTION(newState != READY_FOR_NEXT_STEP,std::logic_error,
00055                                "newState = " << toString(newState) << "\n");
00056   } else if (stepControlState_ == READY_FOR_NEXT_STEP) {
00057     TEUCHOS_TEST_FOR_EXCEPTION(newState != MID_STEP, std::logic_error,
00058                                "newState = " << toString(newState) << "\n");
00059   }
00060   stepControlState_ = newState;
00061 }
00062 
00063 template<class Scalar>
00064 StepControlStrategyState FixedStepControlStrategy<Scalar>::getCurrentState()
00065 {
00066   return(stepControlState_);
00067 }
00068 
00069 template<class Scalar>
00070 FixedStepControlStrategy<Scalar>::FixedStepControlStrategy()
00071   : stepControlState_(UNINITIALIZED)
00072 {}
00073 
00074 template<class Scalar>
00075 void FixedStepControlStrategy<Scalar>::initialize(
00076   const StepperBase<Scalar>& stepper)
00077 {
00078   stepControlState_ = UNINITIALIZED;
00079   // Any other initialization goes here.
00080   setStepControlState_(BEFORE_FIRST_STEP);
00081 }
00082 
00083 template<class Scalar>
00084 void FixedStepControlStrategy<Scalar>::setRequestedStepSize(
00085   const StepperBase<Scalar>& stepper,
00086   const Scalar& stepSize,
00087   const StepSizeType& stepSizeType)
00088 {
00089   typedef Teuchos::ScalarTraits<Scalar> ST;
00090   TEUCHOS_TEST_FOR_EXCEPTION(
00091     !((stepControlState_ == UNINITIALIZED) ||
00092       (stepControlState_ == BEFORE_FIRST_STEP) ||
00093       (stepControlState_ == READY_FOR_NEXT_STEP) ||
00094       (stepControlState_ == MID_STEP)), std::logic_error,
00095      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00096      << ") for FixedStepControlStrategy<Scalar>::setRequestedStepSize()\n");
00097 
00098   TEUCHOS_TEST_FOR_EXCEPTION(
00099     (stepSizeType != STEP_TYPE_FIXED),
00100     std::logic_error, "Error, step size type != STEP_TYPE_FIXED "
00101     "for FixedStepControlStrategy!\n");
00102 
00103   if (stepControlState_ == UNINITIALIZED) setStepControlData(stepper);
00104 }
00105 
00106 template<class Scalar>
00107 void FixedStepControlStrategy<Scalar>::nextStepSize(
00108   const StepperBase<Scalar>& stepper, Scalar* stepSize,
00109   StepSizeType* stepSizeType, int* order)
00110 {
00111   TEUCHOS_TEST_FOR_EXCEPTION(!((stepControlState_ == BEFORE_FIRST_STEP) ||
00112                                (stepControlState_ == MID_STEP) ||
00113                                (stepControlState_ == READY_FOR_NEXT_STEP) ),
00114                                std::logic_error,
00115      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00116      << ") for FixedStepControlStrategy<Scalar>::nextStepSize()\n");
00117 
00118   setStepControlState_(MID_STEP);
00119 }
00120 
00121 template<class Scalar>
00122 void FixedStepControlStrategy<Scalar>::setCorrection(
00123      const StepperBase<Scalar>& stepper
00124     ,const RCP<const Thyra::VectorBase<Scalar> >& soln
00125     ,const RCP<const Thyra::VectorBase<Scalar> >& dx
00126     ,int solveStatus)
00127 {
00128   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != MID_STEP, std::logic_error,
00129      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00130      << ") for FixedStepControlStrategy<Scalar>::setCorrection()\n");
00131   setStepControlState_(AFTER_CORRECTION);
00132 }
00133 
00134 template<class Scalar>
00135 bool FixedStepControlStrategy<Scalar>::acceptStep(
00136   const StepperBase<Scalar>& stepper, Scalar* value)
00137 {
00138   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00139      std::logic_error,
00140      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00141      << ") for FixedStepControlStrategy<Scalar>::completeStep()\n");
00142 
00143   return true;
00144 }
00145 
00146 template<class Scalar>
00147 AttemptedStepStatusFlag FixedStepControlStrategy<Scalar>::rejectStep(
00148   const StepperBase<Scalar>& stepper)
00149 {
00150   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00151      std::logic_error,
00152      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00153      << ") for FixedStepControlStrategy<Scalar>::completeStep()\n");
00154 
00155   setStepControlState_(READY_FOR_NEXT_STEP);
00156 
00157   return (REP_ERR_FAIL);
00158 }
00159 
00160 template<class Scalar>
00161 void FixedStepControlStrategy<Scalar>::completeStep(
00162   const StepperBase<Scalar>& stepper)
00163 {
00164   TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
00165      std::logic_error,
00166      "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
00167      << ") for FixedStepControlStrategy<Scalar>::completeStep()\n");
00168 
00169   setStepControlState_(READY_FOR_NEXT_STEP);
00170 }
00171 
00172 template<class Scalar>
00173 void FixedStepControlStrategy<Scalar>::describe(
00174   Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
00175 {
00176   using Teuchos::as;
00177   if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
00178        (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)     )    ) {
00179     out << this->description() << "::describe" << "\n";
00180   }
00181 }
00182 
00183 template<class Scalar>
00184 void FixedStepControlStrategy<Scalar>::setParameterList(
00185   RCP<Teuchos::ParameterList> const& paramList)
00186 {
00187   typedef Teuchos::ScalarTraits<Scalar> ST;
00188   TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
00189   paramList->validateParameters(*getValidParameters());
00190 }
00191 
00192 template<class Scalar>
00193 RCP<const Teuchos::ParameterList>
00194 FixedStepControlStrategy<Scalar>::getValidParameters() const
00195 {
00196   static RCP<Teuchos::ParameterList> validPL;
00197   if (is_null(validPL)) {
00198     RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
00199     Teuchos::setupVerboseObjectSublist(&*pl);
00200     validPL = pl;
00201   }
00202 
00203   return (validPL);
00204 }
00205 
00206 template<class Scalar>
00207 RCP<Teuchos::ParameterList>
00208 FixedStepControlStrategy<Scalar>::unsetParameterList()
00209 {
00210   RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
00211   parameterList_ = Teuchos::null;
00212   return(temp_param_list);
00213 }
00214 
00215 template<class Scalar>
00216 RCP<Teuchos::ParameterList>
00217 FixedStepControlStrategy<Scalar>::getNonconstParameterList()
00218 {
00219   return(parameterList_);
00220 }
00221 
00222 template<class Scalar>
00223 void FixedStepControlStrategy<Scalar>::setStepControlData(
00224   const StepperBase<Scalar>& stepper)
00225 {
00226   if (stepControlState_ == UNINITIALIZED) initialize(stepper);
00227 }
00228 
00229 template<class Scalar>
00230 bool FixedStepControlStrategy<Scalar>::supportsCloning() const
00231 {
00232   return true;
00233 }
00234 
00235 
00236 template<class Scalar>
00237 RCP<StepControlStrategyBase<Scalar> >
00238 FixedStepControlStrategy<Scalar>::cloneStepControlStrategyAlgorithm() const
00239 {
00240 
00241   RCP<FixedStepControlStrategy<Scalar> >
00242     stepControl = rcp(new FixedStepControlStrategy<Scalar>());
00243 
00244   if (!is_null(parameterList_))
00245     stepControl->setParameterList(parameterList_);
00246 
00247   return stepControl;
00248 }
00249 
00250 template<class Scalar>
00251 int FixedStepControlStrategy<Scalar>::getMaxOrder() const
00252 {
00253   TEUCHOS_TEST_FOR_EXCEPTION(
00254       stepControlState_ == UNINITIALIZED, std::logic_error,
00255       "Error, attempting to call getMaxOrder before initialization!\n"
00256       );
00257   return(0);
00258 }
00259 
00260 //
00261 // Explicit Instantiation macro
00262 //
00263 // Must be expanded from within the Rythmos namespace!
00264 //
00265 
00266 #define RYTHMOS_FIXED_STEP_CONTROL_STRATEGY_INSTANT(SCALAR) \
00267   template class FixedStepControlStrategy< SCALAR >;
00268 
00269 
00270 } // namespace Rythmos
00271 #endif // Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H
 All Classes Functions Variables Typedefs