OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timestep_control.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 // $Id: timestep_control.h 1348 2013-08-16 00:45:07Z secanell $
3 //
4 // Copyright (C) 2006, 2007 by Guido Kanschat
5 //
6 // This file is subject to QPL and may not be distributed
7 // without copyright and license information. Please refer
8 // to the file deal.II/doc/license.html for the text and
9 // further information on this license.
10 //
11 //---------------------------------------------------------------------------
12 
13 #ifndef __deal2__appframe__timestep_control_h
14 #define __deal2__appframe__timestep_control_h
15 
16 #include <base/subscriptor.h>
17 #include <base/smartpointer.h>
18 #include <lac/vector_memory.h>
19 #include <cstdio>
20 
21 
22 using namespace dealii;
23 
24 namespace dealii
25 {
26  class ParameterHandler;
27 }
28 
29 namespace AppFrame
30 {
37 class TimestepControl : public Subscriptor
38 {
39  public:
48  enum Strategy
49  {
61 
87  inner_residual
88  };
89 
94  TimestepControl (double start = 0.,
95  double final = 1.,
96  double tolerance = 1.e-2,
97  double start_step = 1.e-2,
98  double print_step = -1.,
99  bool autonomous = false);
100 
101  static void declare_parameters (ParameterHandler& param);
102  void parse_parameters (ParameterHandler& param);
103 
107  double start () const;
115  double final () const;
120  double tolerance () const;
125  double step () const;
129  double now () const;
137  double next (const double indicator);
138 
145  bool autonomous () const;
146 
150  void start (double);
154  void final (double);
158  void tolerance (double);
162  void strategy (Strategy);
163 
169  void start_step (double);
170 
175  void max_step (double);
176 
180  void autonomous (bool);
181 
188  void restart ();
193  bool print ();
197  void file_name_format (const char*);
198  const char* file_name_format ();
199  private:
200 
201  double start_val;
202  double final_val;
206  double max_step_val;
207  double min_step_val;
215  double step_val;
217 
218  double now_val;
219  double print_step;
221 
222  char format[30];
223 };
224 
225 
226 inline double
227 TimestepControl::start () const
228 {
229  return start_val;
230 }
231 
232 
233 inline double
234 TimestepControl::final () const
235 {
236  return final_val;
237 }
238 
239 
240 inline double
241 TimestepControl::step () const
242 {
243  return current_step_val;
244 }
245 
246 
247 inline double
248 TimestepControl::tolerance () const
249 {
250  return tolerance_val;
251 }
252 
253 
254 inline double
255 TimestepControl::now () const
256 {
257  return now_val;
258 }
259 
260 
261 inline void
262 TimestepControl::start (double t)
263 {
264  start_val = t;
265 }
266 
267 
268 inline void
269 TimestepControl::final (double t)
270 {
271  final_val = t;
272 }
273 
274 
275 inline void
276 TimestepControl::tolerance (double t)
277 {
278  tolerance_val = t;
279 }
280 
281 
282 inline void
283 TimestepControl::strategy (Strategy t)
284 {
285  strategy_val = t;
286 }
287 
288 
289 inline void
290 TimestepControl::start_step (double t)
291 {
292  start_step_val = t;
293 }
294 
295 
296 inline void
297 TimestepControl::max_step (double t)
298 {
299  max_step_val = t;
300 }
301 
302 
303 inline void
304 TimestepControl::restart ()
305 {
306  now_val = start_val;
307  step_val = (strategy_val == uniform)
308  ? tolerance_val
309  : start_step_val;
310  current_step_val = step_val;
311  if (print_step > 0.)
312  next_print_val = now_val + print_step;
313  else
314  next_print_val = now_val - 1.;
315 }
316 
317 
318 inline void
319 TimestepControl::file_name_format (const char* fmt)
320 {
321  strcpy(format, fmt);
322 }
323 
324 
325 inline const char*
326 TimestepControl::file_name_format ()
327 {
328  return format;
329 }
330 
331 
332 inline bool
333 TimestepControl::autonomous () const
334 {
335  return is_autonomous;
336 }
337 
338 
339 inline void
340 TimestepControl::autonomous (bool b)
341 {
342  is_autonomous = b;
343 }
344 
345 }
346 
347 #endif