Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_SimpleIntegrationControlStrategy_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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 
30 #ifndef RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
31 #define RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
32 
33 #include "Rythmos_SimpleIntegrationControlStrategy_decl.hpp"
34 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
35 
36 
37 namespace Rythmos {
38 
39 
40 template<class Scalar>
41 RCP<SimpleIntegrationControlStrategy<Scalar> >
42 simpleIntegrationControlStrategy()
43 {
44  RCP<SimpleIntegrationControlStrategy<Scalar> >
45  integrationControl = Teuchos::rcp(new SimpleIntegrationControlStrategy<Scalar>());
46  return integrationControl;
47 }
48 
49 
50 template<class Scalar>
51 RCP<SimpleIntegrationControlStrategy<Scalar> >
52 simpleIntegrationControlStrategy( const RCP<ParameterList> &paramList )
53 {
54  RCP<SimpleIntegrationControlStrategy<Scalar> >
55  integrationControl = Teuchos::rcp(new SimpleIntegrationControlStrategy<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 = "Take Variable Steps";
73 
74 template<class Scalar>
75 const bool
77 = true;
78 
79 
80 template<class Scalar>
81 const std::string
83 = "Max dt";
84 
85 template<class Scalar>
86 const double
88 = std::numeric_limits<Scalar>::max();
89 
90 
91 template<class Scalar>
92 const std::string
94 = "Number of Time Steps";
95 
96 template<class Scalar>
97 const int
99 = -1;
100 
101 
102 template<class Scalar>
103 const std::string
105 = "Fixed dt";
106 
107 template<class Scalar>
108 const double
110 = -1.0;
111 
112 
113 // Constructors/Initializers
114 
115 
116 template<class Scalar>
118  :takeVariableSteps_(takeVariableSteps_default_),
119  max_dt_(max_dt_default_),
120  numTimeSteps_(numTimeSteps_default_),
121  fixed_dt_(fixed_dt_default_)
122 {}
123 
124 
125 // Overridden from ParameterListAcceptor
126 
127 
128 template<class Scalar>
130  RCP<ParameterList> const& paramList
131  )
132 {
133  using Teuchos::as;
134  using Teuchos::get;
135  typedef Teuchos::ScalarTraits<Scalar> ST;
136  TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
137  paramList->validateParameters(*getValidParameters());
138  this->setMyParamList(paramList);
139  takeVariableSteps_ = paramList->get(
140  takeVariableSteps_name_, takeVariableSteps_ );
141  if (!takeVariableSteps_) {
142  numTimeSteps_ = paramList->get(numTimeSteps_name_,numTimeSteps_);
143  fixed_dt_ = paramList->get(fixed_dt_name_,fixed_dt_default_);
144  TEUCHOS_TEST_FOR_EXCEPTION(
145  numTimeSteps_ < 0 && fixed_dt_ <= ST::zero(), std::logic_error,
146  "Error, when taking fixed steps, the user must set the parameters "
147  "\""<<numTimeSteps_name_<<"\" > 0 or \""<<fixed_dt_name_<<"\" > 0.0!" );
148  }
149  else {
150  max_dt_ = paramList->get(max_dt_name_,max_dt_);
151  }
152  Teuchos::readVerboseObjectSublist(&*paramList,this);
153 }
154 
155 
156 template<class Scalar>
157 RCP<const ParameterList>
159 {
160  static RCP<const ParameterList> validPL;
161  if (is_null(validPL) ) {
162  RCP<ParameterList> pl = Teuchos::parameterList();
163  pl->set(
164  takeVariableSteps_name_, takeVariableSteps_default_,
165  "Take variable time steps or fixed time steps.\n"
166  "If set to false, then the parameter \"" + fixed_dt_name_ + "\"\n"
167  "or \"" + numTimeSteps_name_ + "\" must be set!"
168  );
169  pl->set(
170  max_dt_name_, max_dt_default_,
171  "Gives the max size of the variable time steps. This is only read and used if\n"
172  "\"" + takeVariableSteps_name_ + "\" is set to true."
173  );
174  pl->set(
175  numTimeSteps_name_, numTimeSteps_default_,
176  "Gives the number of fixed time steps. The actual step size gets computed\n"
177  "on the fly given the size of the time domain.\n"
178  "This is only read and used if \"" + takeVariableSteps_name_ + "\" is set to false\n"
179  "and \"" + fixed_dt_name_ + "\" is set to < 0.0."
180  );
181  pl->set(
182  fixed_dt_name_, fixed_dt_default_,
183  "Gives the size of the fixed time steps. This is only read and used if\n"
184  "\"" + takeVariableSteps_name_ + "\" is set to false."
185  );
186  Teuchos::setupVerboseObjectSublist(&*pl);
187  validPL = pl;
188  }
189  return validPL;
190 }
191 
192 
193 // Overridden from IntegrationControlStrategyBase
194 
195 
196 template<class Scalar>
197 RCP<IntegrationControlStrategyBase<Scalar> >
199 {
200  RCP<SimpleIntegrationControlStrategy<Scalar> >
201  integrCtrlStry = simpleIntegrationControlStrategy<Scalar>();
202  const RCP<const ParameterList> paramList = this->getParameterList();
203  if (!is_null(paramList))
204  integrCtrlStry->setParameterList(Teuchos::parameterList(*paramList));
205  integrCtrlStry->takeVariableSteps_ = takeVariableSteps_;
206  integrCtrlStry->max_dt_ = max_dt_;
207  integrCtrlStry->numTimeSteps_ = numTimeSteps_;
208  integrCtrlStry->fixed_dt_ = fixed_dt_;
209  return integrCtrlStry;
210 }
211 
212 
213 template<class Scalar>
214 void
216  const TimeRange<Scalar> &integrationTimeDomain
217  )
218 {
219  typedef Teuchos::ScalarTraits<Scalar> ST;
220 #ifdef HAVE_RYTHMOS_DEBUG
221  TEUCHOS_ASSERT(integrationTimeDomain.length() >= ST::zero());
222 #endif
223  integrationTimeDomain_ = integrationTimeDomain;
224  if (takeVariableSteps_) {
225  if (max_dt_ < ST::zero()) {
226  max_dt_ = integrationTimeDomain_.length();
227  }
228  }
229  else {
230  if (fixed_dt_ < ST::zero()) {
231 #ifdef HAVE_RYTHMOS_DEBUG
232  TEUCHOS_ASSERT(numTimeSteps_ > 0);
233 #endif
234  fixed_dt_ = integrationTimeDomain_.length()/numTimeSteps_;
235  }
236  }
237 }
238 
239 
240 template<class Scalar>
243  const StepperBase<Scalar> &/* stepper */,
244  const StepControlInfo<Scalar> &/* stepCtrlInfoLast */,
245  const int /* timeStepIter */
246  )
247 {
248 
249 #ifdef HAVE_RYTHMOS_DEBUG
250  typedef Teuchos::ScalarTraits<Scalar> ST;
251  TEUCHOS_ASSERT(integrationTimeDomain_.length() >= ST::zero());
252 #endif
253 
254  StepControlInfo<Scalar> trialStepCtrlInfo;
255 
256  if (takeVariableSteps_) {
257  trialStepCtrlInfo.stepType = STEP_TYPE_VARIABLE;
258  trialStepCtrlInfo.stepSize = max_dt_;
259  }
260  else {
261  trialStepCtrlInfo.stepType = STEP_TYPE_FIXED;
262  trialStepCtrlInfo.stepSize = fixed_dt_;
263  }
264 
265  return trialStepCtrlInfo;
266 
267 }
268 
269 //
270 // Explicit Instantiation macro
271 //
272 // Must be expanded from within the Rythmos namespace!
273 //
274 
275 #define RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_INSTANT(SCALAR) \
276  \
277  template class SimpleIntegrationControlStrategy< SCALAR >; \
278  \
279  template RCP<SimpleIntegrationControlStrategy< SCALAR > > \
280  simpleIntegrationControlStrategy(); \
281  \
282  template RCP<SimpleIntegrationControlStrategy< SCALAR > > \
283  simpleIntegrationControlStrategy( const RCP<ParameterList> &paramList );
284 
285 
286 } // namespace Rythmos
287 
288 
289 #endif // RYTHMOS_SIMPLE_INTEGRATION_CONTROL_STRATEGY_DEF_HPP
StepControlInfo< Scalar > getNextStepControlInfo(const StepperBase< Scalar > &stepper, const StepControlInfo< Scalar > &stepCtrlInfoLast, const int timeStepIter)
Base class for defining stepper functionality.
RCP< IntegrationControlStrategyBase< Scalar > > cloneIntegrationControlStrategy() const
Overridden from IntegrationControlStrategyBase.
Simple struct to aggregate integration/stepper control information.
Base class for strategy objects that control integration by selecting step sizes for a stepper...
StepSizeType stepType
The type of time step.
void resetIntegrationControlStrategy(const TimeRange< Scalar > &integrationTimeDomain)