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   TEST_FOR_EXCEPT(is_null(paramList));
00139   paramList->validateParameters(*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 RCP<IntegrationControlStrategyBase<Scalar> >
00178 RampingIntegrationControlStrategy<Scalar>::cloneIntegrationControlStrategy() const
00179 {
00180   RCP<RampingIntegrationControlStrategy<Scalar> >
00181     integrCtrlStry = rampingIntegrationControlStrategy<Scalar>();
00182   const RCP<const ParameterList> paramList = this->getParameterList();
00183   if (!is_null(paramList))
00184     integrCtrlStry->setParameterList(Teuchos::parameterList(*paramList));
00185   integrCtrlStry->num_ramping_steps_ = this->num_ramping_steps_;
00186   integrCtrlStry->initial_dt_ = this->initial_dt_;
00187   integrCtrlStry->max_dt_ = this->max_dt_;
00188   integrCtrlStry->ramping_factor_ = this->ramping_factor_;
00189   integrCtrlStry->current_dt_ = this->current_dt_;
00190   return integrCtrlStry;
00191 }
00192 
00193 
00194 template<class Scalar>
00195 void
00196 RampingIntegrationControlStrategy<Scalar>::resetIntegrationControlStrategy(
00197   const TimeRange<Scalar> &integrationTimeDomain
00198   )
00199 {
00200   typedef Teuchos::ScalarTraits<Scalar> ST;
00201 #ifdef RYTHMOS_DEBUG
00202   TEUCHOS_ASSERT(integrationTimeDomain.length() > ST::zero());
00203 #endif
00204   integrationTimeDomain_ = integrationTimeDomain;
00205   if (max_dt_ < ST::zero()) {
00206     max_dt_ = integrationTimeDomain_.length();
00207   }
00208 
00209   current_dt_ = initial_dt_;
00210 }
00211 
00212 
00213 template<class Scalar>
00214 StepControlInfo<Scalar>
00215 RampingIntegrationControlStrategy<Scalar>::getNextStepControlInfo(
00216   const StepperBase<Scalar> &stepper,
00217   const StepControlInfo<Scalar> &stepCtrlInfoLast,
00218   const int timeStepIter
00219   )
00220 {
00221 
00222   typedef Teuchos::ScalarTraits<Scalar> ST;
00223 
00224 #ifdef RYTHMOS_DEBUG
00225   TEUCHOS_ASSERT(integrationTimeDomain_.length() > ST::zero());
00226 #endif
00227   
00228   StepControlInfo<Scalar> trialStepCtrlInfo;
00229   
00230   if (timeStepIter == 0)
00231     current_dt_ = initial_dt_;
00232   else
00233     current_dt_ *= ramping_factor_;
00234 
00235   if (timeStepIter < num_ramping_steps_) {
00236     trialStepCtrlInfo.stepType = STEP_TYPE_FIXED;
00237     trialStepCtrlInfo.stepSize = current_dt_;
00238   }
00239   else  {
00240     trialStepCtrlInfo.stepType = STEP_TYPE_VARIABLE;
00241     trialStepCtrlInfo.stepSize = max_dt_;
00242   }
00243 
00244   return trialStepCtrlInfo;
00245   
00246 }
00247 
00248 // 
00249 // Explicit Instantiation macro
00250 //
00251 // Must be expanded from within the Rythmos namespace!
00252 //
00253 
00254 #define RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_INSTANT(SCALAR) \
00255   \
00256   template class RampingIntegrationControlStrategy< SCALAR >; \
00257   \
00258   template RCP<RampingIntegrationControlStrategy< SCALAR > > \
00259   rampingIntegrationControlStrategy(); \
00260   \
00261   template RCP<RampingIntegrationControlStrategy< SCALAR > > \
00262   rampingIntegrationControlStrategy( const RCP<ParameterList> &paramList );
00263    
00264 
00265 } // namespace Rythmos
00266 
00267 
00268 #endif // RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
 All Classes Functions Variables Typedefs Friends