Rythmos - Transient Integration for Differential Equations Version of the Day
Rythmos_RampingIntegrationControlStrategy_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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 
00030 #ifndef RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
00031 #define RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
00032 
00033 #include "Rythmos_RampingIntegrationControlStrategy_decl.hpp"
00034 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
00035 
00036 
00037 namespace Rythmos {
00038 
00039 
00040 template<class Scalar> 
00041 RCP<RampingIntegrationControlStrategy<Scalar> >
00042 rampingIntegrationControlStrategy()
00043 {
00044   RCP<RampingIntegrationControlStrategy<Scalar> >
00045     integrationControl = Teuchos::rcp(new RampingIntegrationControlStrategy<Scalar>());
00046   return integrationControl;
00047 }
00048 
00049 
00050 template<class Scalar> 
00051 RCP<RampingIntegrationControlStrategy<Scalar> >
00052 rampingIntegrationControlStrategy( const RCP<ParameterList> &paramList )
00053 {
00054   RCP<RampingIntegrationControlStrategy<Scalar> >
00055     integrationControl = Teuchos::rcp(new RampingIntegrationControlStrategy<Scalar>());
00056   integrationControl->setParameterList(paramList);
00057   return integrationControl;
00058 }
00059 
00060 
00061 //
00062 // Implementation
00063 //
00064 
00065 
00066 // Static members
00067 
00068 
00069 template<class Scalar> 
00070 const std::string
00071 RampingIntegrationControlStrategy<Scalar>::num_ramping_steps_name_
00072 = "Number of Ramping Steps";
00073 
00074 template<class Scalar> 
00075 const int
00076 RampingIntegrationControlStrategy<Scalar>::num_ramping_steps_default_
00077 = 6;
00078 
00079 
00080 template<class Scalar> 
00081 const std::string
00082 RampingIntegrationControlStrategy<Scalar>::initial_dt_name_
00083 = "Initial dt";
00084 
00085 template<class Scalar> 
00086 const double
00087 RampingIntegrationControlStrategy<Scalar>::initial_dt_default_
00088 = -1.0;
00089 
00090 
00091 template<class Scalar> 
00092 const std::string
00093 RampingIntegrationControlStrategy<Scalar>::max_dt_name_
00094 = "Max dt";
00095 
00096 template<class Scalar> 
00097 const double
00098 RampingIntegrationControlStrategy<Scalar>::max_dt_default_
00099 = std::numeric_limits<Scalar>::max();
00100 
00101 
00102 template<class Scalar> 
00103 const std::string
00104 RampingIntegrationControlStrategy<Scalar>::ramping_factor_name_
00105 = "Ramping Factor";
00106 
00107 template<class Scalar> 
00108 const double
00109 RampingIntegrationControlStrategy<Scalar>::ramping_factor_default_
00110 = 1.0;
00111 
00112 
00113 
00114 // Constructors/Initializers
00115 
00116 
00117 template<class Scalar>
00118 RampingIntegrationControlStrategy<Scalar>::RampingIntegrationControlStrategy() :
00119   num_ramping_steps_(num_ramping_steps_default_),
00120   initial_dt_(initial_dt_default_),
00121   max_dt_(max_dt_default_),
00122   ramping_factor_(ramping_factor_default_),
00123   current_dt_(-1.0)
00124 {}
00125 
00126 
00127 // Overridden from ParameterListAcceptor
00128 
00129 
00130 template<class Scalar> 
00131 void RampingIntegrationControlStrategy<Scalar>::setParameterList(
00132   RCP<ParameterList> const& paramList
00133   )
00134 {
00135   using Teuchos::as;
00136   using Teuchos::get;
00137   typedef Teuchos::ScalarTraits<Scalar> ST;
00138   TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
00139   paramList->validateParametersAndSetDefaults(*getValidParameters());
00140   this->setMyParamList(paramList);
00141 
00142   num_ramping_steps_ = paramList->get<int>(num_ramping_steps_name_);
00143   initial_dt_ = paramList->get<double>(initial_dt_name_);
00144   max_dt_ = paramList->get<double>(max_dt_name_);
00145   ramping_factor_ = paramList->get<double>(ramping_factor_name_);
00146 
00147   Teuchos::readVerboseObjectSublist(&*paramList,this);
00148 }
00149 
00150 
00151 template<class Scalar> 
00152 RCP<const ParameterList>
00153 RampingIntegrationControlStrategy<Scalar>::getValidParameters() const
00154 {
00155   static RCP<const ParameterList> validPL;
00156   if (is_null(validPL) ) {
00157     RCP<ParameterList> pl = Teuchos::parameterList();
00158     pl->set(num_ramping_steps_name_, num_ramping_steps_default_,
00159       "Number of ramping steps to take before handing control to variable stepper.");
00160     pl->set(initial_dt_name_, initial_dt_default_,
00161       "Initial teim step.");
00162     pl->set(max_dt_name_, max_dt_default_,
00163       "Maximum time step.");
00164     pl->set(ramping_factor_name_, ramping_factor_default_,
00165       "Time step growth factor used during ramping phase.dt_{n+1} = (ramping factor) * dt_n");
00166     Teuchos::setupVerboseObjectSublist(&*pl);
00167     validPL = pl;
00168   }
00169   return validPL;
00170 }
00171 
00172 
00173 // Overridden from IntegrationControlStrategyBase
00174 
00175 
00176 template<class Scalar>
00177 bool RampingIntegrationControlStrategy<Scalar>::handlesFailedTimeSteps() const
00178 {
00179   return true;
00180 }
00181 
00182 
00183 template<class Scalar>
00184 RCP<IntegrationControlStrategyBase<Scalar> >
00185 RampingIntegrationControlStrategy<Scalar>::cloneIntegrationControlStrategy() const
00186 {
00187   RCP<RampingIntegrationControlStrategy<Scalar> >
00188     integrCtrlStry = rampingIntegrationControlStrategy<Scalar>();
00189   const RCP<const ParameterList> paramList = this->getParameterList();
00190   if (!is_null(paramList))
00191     integrCtrlStry->setParameterList(Teuchos::parameterList(*paramList));
00192   integrCtrlStry->num_ramping_steps_ = this->num_ramping_steps_;
00193   integrCtrlStry->initial_dt_ = this->initial_dt_;
00194   integrCtrlStry->max_dt_ = this->max_dt_;
00195   integrCtrlStry->ramping_factor_ = this->ramping_factor_;
00196   integrCtrlStry->current_dt_ = this->current_dt_;
00197   return integrCtrlStry;
00198 }
00199 
00200 
00201 template<class Scalar>
00202 void
00203 RampingIntegrationControlStrategy<Scalar>::resetIntegrationControlStrategy(
00204   const TimeRange<Scalar> &integrationTimeDomain
00205   )
00206 {
00207   typedef Teuchos::ScalarTraits<Scalar> ST;
00208 #ifdef HAVE_RYTHMOS_DEBUG
00209   TEUCHOS_ASSERT(integrationTimeDomain.length() > ST::zero());
00210 #endif
00211   integrationTimeDomain_ = integrationTimeDomain;
00212   if (max_dt_ < ST::zero()) {
00213     max_dt_ = integrationTimeDomain_.length();
00214   }
00215 
00216   current_dt_ = initial_dt_;
00217 }
00218 
00219 
00220 template<class Scalar>
00221 StepControlInfo<Scalar>
00222 RampingIntegrationControlStrategy<Scalar>::getNextStepControlInfo(
00223   const StepperBase<Scalar> &stepper,
00224   const StepControlInfo<Scalar> &stepCtrlInfoLast,
00225   const int timeStepIter
00226   )
00227 {
00228 
00229   typedef Teuchos::ScalarTraits<Scalar> ST;
00230 
00231 #ifdef HAVE_RYTHMOS_DEBUG
00232   TEUCHOS_ASSERT(integrationTimeDomain_.length() > ST::zero());
00233 #endif
00234   
00235   StepControlInfo<Scalar> trialStepCtrlInfo;
00236   
00237   if (timeStepIter == 0)
00238     current_dt_ = initial_dt_;
00239   else
00240     current_dt_ *= ramping_factor_;
00241 
00242   if (timeStepIter < num_ramping_steps_) {
00243     trialStepCtrlInfo.stepType = STEP_TYPE_FIXED;
00244     trialStepCtrlInfo.stepSize = current_dt_;
00245   }
00246   else  {
00247     trialStepCtrlInfo.stepType = STEP_TYPE_VARIABLE;
00248     trialStepCtrlInfo.stepSize = max_dt_;
00249   }
00250 
00251   return trialStepCtrlInfo;
00252   
00253 }
00254 
00255 
00256 template<class Scalar>
00257 bool RampingIntegrationControlStrategy<Scalar>::resetForFailedTimeStep(
00258   const StepperBase<Scalar> &stepper,
00259   const StepControlInfo<Scalar> &stepCtrlInfoLast,
00260   const int timeStepIter,
00261   const StepControlInfo<Scalar> &stepCtrlInfo
00262   )
00263 {
00264   // \todo Implement more control over this in the PL
00265   current_dt_ /= ramping_factor_;
00266   // \todo Put in a max number of attempted time steps (otherwise infinite
00267   // loop)
00268   return true;
00269 }
00270 
00271 
00272 // 
00273 // Explicit Instantiation macro
00274 //
00275 // Must be expanded from within the Rythmos namespace!
00276 //
00277 
00278 #define RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_INSTANT(SCALAR) \
00279   \
00280   template class RampingIntegrationControlStrategy< SCALAR >; \
00281   \
00282   template RCP<RampingIntegrationControlStrategy< SCALAR > > \
00283   rampingIntegrationControlStrategy(); \
00284   \
00285   template RCP<RampingIntegrationControlStrategy< SCALAR > > \
00286   rampingIntegrationControlStrategy( const RCP<ParameterList> &paramList );
00287    
00288 
00289 } // namespace Rythmos
00290 
00291 
00292 #endif // RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
 All Classes Functions Variables Typedefs Friends