|
Rythmos - Transient Integration for Differential Equations
Version of the Day
|
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 00030 #ifndef RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_DEF_HPP 00031 #define RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_DEF_HPP 00032 00033 #include "Rythmos_SimpleIntegrationControlStrategy_decl.hpp" 00034 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 00035 00036 00037 namespace Rythmos { 00038 00039 00040 template<class Scalar> 00041 RCP<SimpleIntegrationControlStrategy<Scalar> > 00042 simpleIntegrationControlStrategy() 00043 { 00044 RCP<SimpleIntegrationControlStrategy<Scalar> > 00045 integrationControl = Teuchos::rcp(new SimpleIntegrationControlStrategy<Scalar>()); 00046 return integrationControl; 00047 } 00048 00049 00050 template<class Scalar> 00051 RCP<SimpleIntegrationControlStrategy<Scalar> > 00052 simpleIntegrationControlStrategy( const RCP<ParameterList> ¶mList ) 00053 { 00054 RCP<SimpleIntegrationControlStrategy<Scalar> > 00055 integrationControl = Teuchos::rcp(new SimpleIntegrationControlStrategy<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 SimpleIntegrationControlStrategy<Scalar>::takeVariableSteps_name_ 00072 = "Take Variable Steps"; 00073 00074 template<class Scalar> 00075 const bool 00076 SimpleIntegrationControlStrategy<Scalar>::takeVariableSteps_default_ 00077 = true; 00078 00079 00080 template<class Scalar> 00081 const std::string 00082 SimpleIntegrationControlStrategy<Scalar>::max_dt_name_ 00083 = "Max dt"; 00084 00085 template<class Scalar> 00086 const double 00087 SimpleIntegrationControlStrategy<Scalar>::max_dt_default_ 00088 = std::numeric_limits<Scalar>::max(); 00089 00090 00091 template<class Scalar> 00092 const std::string 00093 SimpleIntegrationControlStrategy<Scalar>::numTimeSteps_name_ 00094 = "Number of Time Steps"; 00095 00096 template<class Scalar> 00097 const int 00098 SimpleIntegrationControlStrategy<Scalar>::numTimeSteps_default_ 00099 = -1; 00100 00101 00102 template<class Scalar> 00103 const std::string 00104 SimpleIntegrationControlStrategy<Scalar>::fixed_dt_name_ 00105 = "Fixed dt"; 00106 00107 template<class Scalar> 00108 const double 00109 SimpleIntegrationControlStrategy<Scalar>::fixed_dt_default_ 00110 = -1.0; 00111 00112 00113 // Constructors/Initializers 00114 00115 00116 template<class Scalar> 00117 SimpleIntegrationControlStrategy<Scalar>::SimpleIntegrationControlStrategy() 00118 :takeVariableSteps_(takeVariableSteps_default_), 00119 max_dt_(max_dt_default_), 00120 numTimeSteps_(numTimeSteps_default_), 00121 fixed_dt_(fixed_dt_default_) 00122 {} 00123 00124 00125 // Overridden from ParameterListAcceptor 00126 00127 00128 template<class Scalar> 00129 void SimpleIntegrationControlStrategy<Scalar>::setParameterList( 00130 RCP<ParameterList> const& paramList 00131 ) 00132 { 00133 using Teuchos::as; 00134 using Teuchos::get; 00135 typedef Teuchos::ScalarTraits<Scalar> ST; 00136 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList)); 00137 paramList->validateParameters(*getValidParameters()); 00138 this->setMyParamList(paramList); 00139 takeVariableSteps_ = paramList->get( 00140 takeVariableSteps_name_, takeVariableSteps_ ); 00141 if (!takeVariableSteps_) { 00142 numTimeSteps_ = paramList->get(numTimeSteps_name_,numTimeSteps_); 00143 fixed_dt_ = paramList->get(fixed_dt_name_,fixed_dt_default_); 00144 TEUCHOS_TEST_FOR_EXCEPTION( 00145 numTimeSteps_ < 0 && fixed_dt_ <= ST::zero(), std::logic_error, 00146 "Error, when taking fixed steps, the user must set the parameters " 00147 "\""<<numTimeSteps_name_<<"\" > 0 or \""<<fixed_dt_name_<<"\" > 0.0!" ); 00148 } 00149 else { 00150 max_dt_ = paramList->get(max_dt_name_,max_dt_); 00151 } 00152 Teuchos::readVerboseObjectSublist(&*paramList,this); 00153 } 00154 00155 00156 template<class Scalar> 00157 RCP<const ParameterList> 00158 SimpleIntegrationControlStrategy<Scalar>::getValidParameters() const 00159 { 00160 static RCP<const ParameterList> validPL; 00161 if (is_null(validPL) ) { 00162 RCP<ParameterList> pl = Teuchos::parameterList(); 00163 pl->set( 00164 takeVariableSteps_name_, takeVariableSteps_default_, 00165 "Take variable time steps or fixed time steps.\n" 00166 "If set to false, then the parameter \"" + fixed_dt_name_ + "\"\n" 00167 "or \"" + numTimeSteps_name_ + "\" must be set!" 00168 ); 00169 pl->set( 00170 max_dt_name_, max_dt_default_, 00171 "Gives the max size of the variable time steps. This is only read and used if\n" 00172 "\"" + takeVariableSteps_name_ + "\" is set to true." 00173 ); 00174 pl->set( 00175 numTimeSteps_name_, numTimeSteps_default_, 00176 "Gives the number of fixed time steps. The actual step size gets computed\n" 00177 "on the fly given the size of the time domain.\n" 00178 "This is only read and used if \"" + takeVariableSteps_name_ + "\" is set to false\n" 00179 "and \"" + fixed_dt_name_ + "\" is set to < 0.0." 00180 ); 00181 pl->set( 00182 fixed_dt_name_, fixed_dt_default_, 00183 "Gives the size of the fixed time steps. This is only read and used if\n" 00184 "\"" + takeVariableSteps_name_ + "\" is set to false." 00185 ); 00186 Teuchos::setupVerboseObjectSublist(&*pl); 00187 validPL = pl; 00188 } 00189 return validPL; 00190 } 00191 00192 00193 // Overridden from IntegrationControlStrategyBase 00194 00195 00196 template<class Scalar> 00197 RCP<IntegrationControlStrategyBase<Scalar> > 00198 SimpleIntegrationControlStrategy<Scalar>::cloneIntegrationControlStrategy() const 00199 { 00200 RCP<SimpleIntegrationControlStrategy<Scalar> > 00201 integrCtrlStry = simpleIntegrationControlStrategy<Scalar>(); 00202 const RCP<const ParameterList> paramList = this->getParameterList(); 00203 if (!is_null(paramList)) 00204 integrCtrlStry->setParameterList(Teuchos::parameterList(*paramList)); 00205 integrCtrlStry->takeVariableSteps_ = takeVariableSteps_; 00206 integrCtrlStry->max_dt_ = max_dt_; 00207 integrCtrlStry->numTimeSteps_ = numTimeSteps_; 00208 integrCtrlStry->fixed_dt_ = fixed_dt_; 00209 return integrCtrlStry; 00210 } 00211 00212 00213 template<class Scalar> 00214 void 00215 SimpleIntegrationControlStrategy<Scalar>::resetIntegrationControlStrategy( 00216 const TimeRange<Scalar> &integrationTimeDomain 00217 ) 00218 { 00219 typedef Teuchos::ScalarTraits<Scalar> ST; 00220 #ifdef HAVE_RYTHMOS_DEBUG 00221 TEUCHOS_ASSERT(integrationTimeDomain.length() >= ST::zero()); 00222 #endif 00223 integrationTimeDomain_ = integrationTimeDomain; 00224 if (takeVariableSteps_) { 00225 if (max_dt_ < ST::zero()) { 00226 max_dt_ = integrationTimeDomain_.length(); 00227 } 00228 } 00229 else { 00230 if (fixed_dt_ < ST::zero()) { 00231 #ifdef HAVE_RYTHMOS_DEBUG 00232 TEUCHOS_ASSERT(numTimeSteps_ > 0); 00233 #endif 00234 fixed_dt_ = integrationTimeDomain_.length()/numTimeSteps_; 00235 } 00236 } 00237 } 00238 00239 00240 template<class Scalar> 00241 StepControlInfo<Scalar> 00242 SimpleIntegrationControlStrategy<Scalar>::getNextStepControlInfo( 00243 const StepperBase<Scalar> &stepper, 00244 const StepControlInfo<Scalar> &stepCtrlInfoLast, 00245 const int timeStepIter 00246 ) 00247 { 00248 00249 typedef Teuchos::ScalarTraits<Scalar> ST; 00250 00251 #ifdef HAVE_RYTHMOS_DEBUG 00252 TEUCHOS_ASSERT(integrationTimeDomain_.length() >= ST::zero()); 00253 #endif 00254 00255 StepControlInfo<Scalar> trialStepCtrlInfo; 00256 00257 if (takeVariableSteps_) { 00258 trialStepCtrlInfo.stepType = STEP_TYPE_VARIABLE; 00259 trialStepCtrlInfo.stepSize = max_dt_; 00260 } 00261 else { 00262 trialStepCtrlInfo.stepType = STEP_TYPE_FIXED; 00263 trialStepCtrlInfo.stepSize = fixed_dt_; 00264 } 00265 00266 return trialStepCtrlInfo; 00267 00268 } 00269 00270 // 00271 // Explicit Instantiation macro 00272 // 00273 // Must be expanded from within the Rythmos namespace! 00274 // 00275 00276 #define RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_INSTANT(SCALAR) \ 00277 \ 00278 template class SimpleIntegrationControlStrategy< SCALAR >; \ 00279 \ 00280 template RCP<SimpleIntegrationControlStrategy< SCALAR > > \ 00281 simpleIntegrationControlStrategy(); \ 00282 \ 00283 template RCP<SimpleIntegrationControlStrategy< SCALAR > > \ 00284 simpleIntegrationControlStrategy( const RCP<ParameterList> ¶mList ); 00285 00286 00287 } // namespace Rythmos 00288 00289 00290 #endif // RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
1.7.6.1