Rythmos - Transient Integration for Differential Equations  Version of the Day
Rythmos_RampingIntegrationControlStrategy_def.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 
30 #ifndef RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
31 #define RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
32 
33 #include "Rythmos_RampingIntegrationControlStrategy_decl.hpp"
34 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
35 
36 
37 namespace Rythmos {
38 
39 
40 template<class Scalar>
41 RCP<RampingIntegrationControlStrategy<Scalar> >
42 rampingIntegrationControlStrategy()
43 {
44  RCP<RampingIntegrationControlStrategy<Scalar> >
45  integrationControl = Teuchos::rcp(new RampingIntegrationControlStrategy<Scalar>());
46  return integrationControl;
47 }
48 
49 
50 template<class Scalar>
51 RCP<RampingIntegrationControlStrategy<Scalar> >
52 rampingIntegrationControlStrategy( const RCP<ParameterList> &paramList )
53 {
54  RCP<RampingIntegrationControlStrategy<Scalar> >
55  integrationControl = Teuchos::rcp(new RampingIntegrationControlStrategy<Scalar>());
56  integrationControl->setParameterList(paramList);
57  return integrationControl;
58 }
59 
60 
61 //
62 // Implementation
63 //
64 
65 
66 // Static members
67 
68 
69 template<class Scalar>
70 const std::string
72 = "Number of Ramping Steps";
73 
74 template<class Scalar>
75 const int
77 = 6;
78 
79 
80 template<class Scalar>
81 const std::string
83 = "Initial dt";
84 
85 template<class Scalar>
86 const double
88 = -1.0;
89 
90 
91 template<class Scalar>
92 const std::string
94 = "Max dt";
95 
96 template<class Scalar>
97 const double
99 = std::numeric_limits<Scalar>::max();
100 
101 
102 template<class Scalar>
103 const std::string
105 = "Ramping Factor";
106 
107 template<class Scalar>
108 const double
110 = 1.0;
111 
112 
113 
114 // Constructors/Initializers
115 
116 
117 template<class Scalar>
119  num_ramping_steps_(num_ramping_steps_default_),
120  initial_dt_(initial_dt_default_),
121  max_dt_(max_dt_default_),
122  ramping_factor_(ramping_factor_default_),
123  current_dt_(-1.0)
124 {}
125 
126 
127 // Overridden from ParameterListAcceptor
128 
129 
130 template<class Scalar>
132  RCP<ParameterList> const& paramList
133  )
134 {
135  using Teuchos::as;
136  using Teuchos::get;
137  typedef Teuchos::ScalarTraits<Scalar> ST;
138  TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
139  paramList->validateParametersAndSetDefaults(*getValidParameters());
140  this->setMyParamList(paramList);
141 
142  num_ramping_steps_ = paramList->get<int>(num_ramping_steps_name_);
143  initial_dt_ = paramList->get<double>(initial_dt_name_);
144  max_dt_ = paramList->get<double>(max_dt_name_);
145  ramping_factor_ = paramList->get<double>(ramping_factor_name_);
146 
147  Teuchos::readVerboseObjectSublist(&*paramList,this);
148 }
149 
150 
151 template<class Scalar>
152 RCP<const ParameterList>
154 {
155  static RCP<const ParameterList> validPL;
156  if (is_null(validPL) ) {
157  RCP<ParameterList> pl = Teuchos::parameterList();
158  pl->set(num_ramping_steps_name_, num_ramping_steps_default_,
159  "Number of ramping steps to take before handing control to variable stepper.");
160  pl->set(initial_dt_name_, initial_dt_default_,
161  "Initial teim step.");
162  pl->set(max_dt_name_, max_dt_default_,
163  "Maximum time step.");
164  pl->set(ramping_factor_name_, ramping_factor_default_,
165  "Time step growth factor used during ramping phase.dt_{n+1} = (ramping factor) * dt_n");
166  Teuchos::setupVerboseObjectSublist(&*pl);
167  validPL = pl;
168  }
169  return validPL;
170 }
171 
172 
173 // Overridden from IntegrationControlStrategyBase
174 
175 
176 template<class Scalar>
178 {
179  return true;
180 }
181 
182 
183 template<class Scalar>
184 RCP<IntegrationControlStrategyBase<Scalar> >
186 {
187  RCP<RampingIntegrationControlStrategy<Scalar> >
188  integrCtrlStry = rampingIntegrationControlStrategy<Scalar>();
189  const RCP<const ParameterList> paramList = this->getParameterList();
190  if (!is_null(paramList))
191  integrCtrlStry->setParameterList(Teuchos::parameterList(*paramList));
192  integrCtrlStry->num_ramping_steps_ = this->num_ramping_steps_;
193  integrCtrlStry->initial_dt_ = this->initial_dt_;
194  integrCtrlStry->max_dt_ = this->max_dt_;
195  integrCtrlStry->ramping_factor_ = this->ramping_factor_;
196  integrCtrlStry->current_dt_ = this->current_dt_;
197  return integrCtrlStry;
198 }
199 
200 
201 template<class Scalar>
202 void
204  const TimeRange<Scalar> &integrationTimeDomain
205  )
206 {
207  typedef Teuchos::ScalarTraits<Scalar> ST;
208 #ifdef HAVE_RYTHMOS_DEBUG
209  TEUCHOS_ASSERT(integrationTimeDomain.length() > ST::zero());
210 #endif
211  integrationTimeDomain_ = integrationTimeDomain;
212  if (max_dt_ < ST::zero()) {
213  max_dt_ = integrationTimeDomain_.length();
214  }
215 
216  current_dt_ = initial_dt_;
217 }
218 
219 
220 template<class Scalar>
223  const StepperBase<Scalar> &stepper,
224  const StepControlInfo<Scalar> &stepCtrlInfoLast,
225  const int timeStepIter
226  )
227 {
228 
229  typedef Teuchos::ScalarTraits<Scalar> ST;
230 
231 #ifdef HAVE_RYTHMOS_DEBUG
232  TEUCHOS_ASSERT(integrationTimeDomain_.length() > ST::zero());
233 #endif
234 
235  StepControlInfo<Scalar> trialStepCtrlInfo;
236 
237  if (timeStepIter == 0)
238  current_dt_ = initial_dt_;
239  else
240  current_dt_ *= ramping_factor_;
241 
242  if (timeStepIter < num_ramping_steps_) {
243  trialStepCtrlInfo.stepType = STEP_TYPE_FIXED;
244  trialStepCtrlInfo.stepSize = current_dt_;
245  }
246  else {
247  trialStepCtrlInfo.stepType = STEP_TYPE_VARIABLE;
248  trialStepCtrlInfo.stepSize = max_dt_;
249  }
250 
251  return trialStepCtrlInfo;
252 
253 }
254 
255 
256 template<class Scalar>
258  const StepperBase<Scalar> &stepper,
259  const StepControlInfo<Scalar> &stepCtrlInfoLast,
260  const int timeStepIter,
261  const StepControlInfo<Scalar> &stepCtrlInfo
262  )
263 {
264  // \todo Implement more control over this in the PL
265  current_dt_ /= ramping_factor_;
266  // \todo Put in a max number of attempted time steps (otherwise infinite
267  // loop)
268  return true;
269 }
270 
271 
272 //
273 // Explicit Instantiation macro
274 //
275 // Must be expanded from within the Rythmos namespace!
276 //
277 
278 #define RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_INSTANT(SCALAR) \
279  \
280  template class RampingIntegrationControlStrategy< SCALAR >; \
281  \
282  template RCP<RampingIntegrationControlStrategy< SCALAR > > \
283  rampingIntegrationControlStrategy(); \
284  \
285  template RCP<RampingIntegrationControlStrategy< SCALAR > > \
286  rampingIntegrationControlStrategy( const RCP<ParameterList> &paramList );
287 
288 
289 } // namespace Rythmos
290 
291 
292 #endif // RYTHMOS_RAMPING_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
void resetIntegrationControlStrategy(const TimeRange< Scalar > &integrationTimeDomain)
Base class for defining stepper functionality.
Simple strict to aggregate integration/stepper control information.
bool handlesFailedTimeSteps() const
Overridden from IntegrationControlStrategyBase.
bool resetForFailedTimeStep(const StepperBase< Scalar > &stepper, const StepControlInfo< Scalar > &stepCtrlInfoLast, const int timeStepIter, const StepControlInfo< Scalar > &stepCtrlInfo)
Controls inital ramping at a fixed or incrementing time step size.
RCP< IntegrationControlStrategyBase< Scalar > > cloneIntegrationControlStrategy() const
StepControlInfo< Scalar > getNextStepControlInfo(const StepperBase< Scalar > &stepper, const StepControlInfo< Scalar > &stepCtrlInfoLast, const int timeStepIter)