Flow123d  DF_patch_fe_data_tables-b828b90
time_governor.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file time_governor.hh
15  * @brief Basic time management class.
16  * @author Jan Brezina
17  */
18 
19 #ifndef TIME_HH_
20 #define TIME_HH_
21 
22 #include <limits>
23 #include <cmath>
24 #include <algorithm>
25 #include <fstream>
26 #include <boost/circular_buffer.hpp>
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "system/global_defs.h"
32 #include "system/system.hh"
33 #include "system/file_path.hh"
35 #include "input/input_exception.hh"
36 #include "input/type_record.hh"
37 #include "system/exc_common.hh"
38 #include "system/exceptions.hh"
39 #include "tools/time_marks.hh"
40 
41 namespace Input {
42  class Record;
43  class Tuple;
44  template<class T> class Iterator;
45  namespace Type {
46  class Tuple;
47  }
48 }
49 
50 
51 
52 /**
53  * @brief Helper class storing unit conversion coefficient and functionality for conversion of units.
54  *
55  * This class has created one instance for each TimeGovernor object. This object is shared with all
56  * TimeSteps.
57  */
59 public:
60  // Default constructor
62 
63  // Constructor from the Unit input record
64  TimeUnitConversion(const Input::Record &input);
65 
67  {
68  return Input::Type::Default::read_time("Common time unit of the equation's Time Governor.\n"
69  "See the key 'common_time_unit'.");
70  }
71 
72  /**
73  * Read and return time value multiplied by coefficient of given unit or global coefficient of equation
74  * stored in coeff_. If time Tuple is not defined (e. g. Tuple is optional key) return default_time value.
75  */
76  double read_time(Input::Iterator<Input::Tuple> time_it, double default_time) const;
77 
78  /**
79  * Read and return time unit coefficient given in unit_it or global coefficient of equation stored
80  * in coeff_, if iterator is not defined.
81  */
82  double read_coef(Input::Iterator<Input::Record> unit_it) const;
83 
84  /**
85  * Return global time unit coefficient of equation stored in coeff_.
86  */
87  inline double get_coef() const {
88  return coef_;
89  }
90 
91  /**
92  * Return string representation of global time unit.
93  */
94  inline std::string get_unit_string() const {
95  return unit_string_;
96  }
97 
98 protected:
99 
100  /// Reads the Unit record and computes the coef
101  double read_unit_coef_from_input(const Input::Record &input) const;
102 
103  /// Conversion coefficient of all time values within the equation.
104  double coef_;
105 
106  /// String representation of global unit of all time values within the equation.
107  std::string unit_string_;
108 
109 };
110 
111 
112 
113 /**
114  * @brief Representation of one time step.\
115  *
116  * Time step consists of the time step @p length() and from time step @end() time.
117  * More over we store the index of the time step within it time governor.
118  *
119  * The reason to store both the end time and the length of the time step is to allow
120  * safe comparisons of the time with safety margin small relative to the
121  * time step length.
122  */
123 class TimeStep {
124 public:
125  /**
126  * Constructor of the zero time step.
127  */
128  TimeStep(double init_time, std::shared_ptr<TimeUnitConversion> time_unit_conversion = std::make_shared<TimeUnitConversion>());
129 
130  /**
131  * Default constructor.
132  * Creates undefined time step.
133  */
134  TimeStep();
135 
136  /**
137  * Copy constructor.
138  */
139  TimeStep(const TimeStep &other);
140 
141  /**
142  * Create subsequent time step.
143  */
144  TimeStep make_next(double new_length) const;
145 
146  /**
147  * Create subsequent time step, with the @end_time
148  * explicitly specified. This allow slight discrepancy to
149  * overcome rounding errors in the case of fixed time step.
150  * Otherwise using small fixed time step, we may miss long term fixed
151  * goal time.
152  *
153  */
154  TimeStep make_next(double new_lenght, double end_time) const;
155 
156  /**
157  * Getters.
158  */
159  unsigned int index() const {return index_;}
160  double length() const { return length_;}
161  double end() const { return end_;}
162  /**
163  * Performs rounding safe comparison time > other_time, i.e. time is strictly greater than given parameter
164  * other_time with precision relative to the magnitude of the numbers time step.
165  * TODO: introduce type TimeDouble with overloaded comparison operators, use it consistently in TimeMarks.
166  */
167  inline bool gt(double other_time) const
168  { return ! safe_compare(other_time, end());}
169 
170  /**
171  * Performs rounding safe comparison time >= other_time See @fn gt
172  */
173  inline bool ge(double other_time) const
174  { return safe_compare(end(), other_time); }
175 
176  /**
177  * Performs rounding safe comparison time < other_time. See @fn gt
178  */
179  inline bool lt(double other_time) const
180  { return ! safe_compare(end(), other_time); }
181 
182  /**
183  * Performs rounding safe comparison time <= other_time. See @fn gt
184  */
185  inline bool le(double other_time) const
186  { return safe_compare(other_time, end()); }
187 
188  /**
189  * Performs rounding safe comparison time (step) == other_time. See @fn gt
190  */
191  inline bool eq(double other_time) const
192  { return this->le(other_time) && this->ge(other_time); }
193 
194  inline bool contains(double other_time) const
195  { return this->ge(other_time) && this->lt(other_time + length_); }
196 
197  /**
198  * Read and return time value multiplied by coefficient of given unit or global coefficient of equation
199  * stored in time_unit_conversion_. If time Tuple is not defined (e. g. Tuple is optional key) return
200  * default_time value.
201  * Shortcut for time_unit_conversion_ function.
202  */
203  double read_time(Input::Iterator<Input::Tuple> time_it, double default_time=std::numeric_limits<double>::quiet_NaN()) const;
204 
205  /**
206  * Read and return time unit coefficient given in unit_it or global coefficient of equation stored
207  * in time_unit_conversion_, if iterator is not defined.
208  * Shortcut for time_unit_conversion_ function.
209  */
210  double read_coef(Input::Iterator<Input::Record> unit_it) const;
211 
212  /**
213  * Return global time unit coefficient of equation.
214  * Shortcut for time_unit_conversion_ function.
215  */
216  double get_coef() const;
217 
218  /// Getter for time unit conversion object.
219  std::shared_ptr<TimeUnitConversion> get_unit_conversion() const;
220 
221  /**
222  * Returns true if two time steps are exactly the same.
223  */
224  bool operator==(const TimeStep & other)
225  { return (index_ == other.index_)
226  && (length_ == other.length_)
227  && (end_ == other.end_);
228  }
229 private:
230 
231  /* Returns true if t1-t0 > delta. Where delta is choosen
232  * related to the current time step and magnitude of t1, t0.
233  */
234  bool safe_compare(double t1, double t0) const;
235 
236  /// Index of the step is index if the end time. Zero time step is artificial.
237  unsigned int index_;
238  /// Length of the time step. Theoretically @p end minus end of the previous time step.
239  /// However may be slightly different due to rounding errors.
240  double length_;
241  /// End time point of the time step.
242  double end_;
243  /// Conversion unit of all time values within the equation.
244  std::shared_ptr<TimeUnitConversion> time_unit_conversion_;
245 };
246 
247 std::ostream& operator<<(std::ostream& out, const TimeStep& t_step);
248 
249 
250 
251 /**
252  * @brief
253  * Basic time management functionality for unsteady (and steady) solvers (class Equation).
254  *
255  * <h2> Common features and unsteady time governor (TG) </h2>
256  *
257  * This class provides algorithm for selecting next time step, and information about current time step frame.
258  * Step estimating is constrained by several bounds (permanent maximal and minimal time step, upper
259  * and lower constraint of time step). The permanent constraints are set in the constructor from the input
260  * record so that user can set the time step constraints for the whole simulation.
261  * Function set_dt_limits() should be used only in very specific cases and possibly right after
262  * the constructor before using other functions of TG.
263  *
264  * Choice of the very next time step can be constrained using functions set_upper_constraint()
265  * and set_lower_constraint().
266  * Lower and upper constraints are set equal to permanent ones in the constructor and can only
267  * become stricter. If one tries to set these constraints outside the interval of the previous constraints,
268  * nothing is changed and a specified value is returned. Upper and lower constraints are reset in function
269  * next_time() to the permanent constraints.
270  *
271  * The later one can be called multiple times with various constraint values and we use the minimum of them.
272  * Function next_time() choose the next time step in such a way that it meets actual constraints and
273  * a uniform discrete time grid with this step hits the nearest fixed time in lowest possible number of steps.
274  *
275  * The fixed times are time marks of TimeMarks object passed at construction time with particular mask.
276  *
277  * There is just one set of time marks for the whole problem. Therefore TimeMarks object is static and is shared umong
278  * all the equations and time governors. Each equation creates its own specific time mark type.
279  *
280  * Information provided by TG includes:
281  * - actual time, last time, end time
282  * - actual time step
283  * - number of the time level
284  * - end of interval with fixed time step
285  * - time comparison
286  * - static pointer to time marks
287  *
288  * <h2> Steady time governor</h2>
289  *
290  * Steady TG can be constructed by default constructor (initial time is zero) or by
291  * constructor with initial time as parameter. End time and time step are set to infinity.
292  * One can check if the time governor is steady by calling is_steady().
293  * Calling estimate_dt() will return infinity.
294  *
295  * Setting constraints have no consequences. Calling fix_dt_until_mark() will only return zero
296  * and will not do anything.
297  *
298  * The steady TG works in two states. At first the time is set to initial and time level
299  * is equal zero. To use steady TG properly one should call next_time() after the computation
300  * of steady problem is done. Current time is then set to infinity, time level is set to 1 and
301  * calling estimate_dt() will return zero.
302  *
303  * Note: For example class TransportNothing (which computes really nothing) uses also steady TG but
304  * it calls next_time() immediately after TG's construction. This means that the 'computation'of transport
305  * is done.
306  *
307  *
308  */
309 
311 {
312 public:
313 
314  DECLARE_INPUT_EXCEPTION(ExcTimeGovernorMessage, << EI_Message::val);
315  TYPEDEF_ERR_INFO( EI_Index, int);
316  TYPEDEF_ERR_INFO( EI_BackIndex, unsigned int);
317  TYPEDEF_ERR_INFO( EI_HistorySize, unsigned int);
318  DECLARE_EXCEPTION(ExcMissingTimeStep,
319  << "Time step index: " << EI_Index::val
320  << ", history index: " << EI_BackIndex::val
321  << " out of history of size: " << EI_HistorySize::val);
322 
323  static const Input::Type::Record & get_input_type();
324 
325  static const Input::Type::Tuple & get_input_time_type(double lower_bound= -std::numeric_limits<double>::max(),
326  double upper_bound=std::numeric_limits<double>::max());
327 
328  /**
329  * Getter for time marks.
330  */
331  static inline TimeMarks &marks()
332  {return time_marks_;}
333 
334  /**
335  * @brief Constructor for unsteady solvers.
336  *
337  * @param input accessor to input data
338  * @param fixed_time_mask TimeMark mask used to select fixed time marks from all the time marks.
339  * @param timestep_output enable/forbid output of time steps to YAML file
340  * This value is bitwise added to the default one defined in TimeMarks::type_fixed_time().
341  *
342  */
343  TimeGovernor(const Input::Record &input,
344  TimeMark::Type fixed_time_mask = TimeMark::none_type,
345  bool timestep_output = true);
346 
347  /**
348  * @brief Default constructor - steady time governor.
349  *
350  * OBSOLETE.
351  *
352  * We can have "zero step" steady problem (no computation, e.g. EquationNothing) and one step steady problem
353  * (e.g. steady water flow).
354  *
355  * Time is set to zero, time step and end time to infinity.
356  *
357  * First call of next_time() pushes the actual time to infinity.
358  *
359  * However, you have to use full constructor for the "steady problem" that has time-variable input data.
360  *
361  * Has a private pointer to static TimeMarks and can access them by marks().
362  */
363  explicit TimeGovernor(double init_time=0.0,
364  TimeMark::Type fixed_time_mask = TimeMark::none_type);
365 
366  /**
367  * The aim of this constuctor is simple way to make a time governor without Input interface.
368  *
369  * TODO: Partially tested as part of field test. Needs its own unit test.
370  */
371  TimeGovernor(double init_time, double dt);
372 
373  /**
374  * Destructor.
375  */
376  ~TimeGovernor();
377 
378  /**
379  * Returns true if the time governor was set from default values
380  */
381  bool is_default() {
382  return (end_time_ == max_end_time)
384  }
385 
386  /**
387  * @brief Sets dt limits for time dependent DT limits in simulation.
388  *
389  * This function should not be normally used. These values are to be set in constructor
390  * from the input record or by default.
391  * @param min_dt is the minimal value allowed for time step
392  * @param max_dt is the maximal value allowed for time step
393  * @param dt_limits_list list of time dependent values of minimal and maximal value allowed for time step
394  */
395  void set_dt_limits( double min_dt, double max_dt, Input::Array dt_limits_list);
396 
397  /**
398  * @brief Sets upper constraint for the next time step estimating.
399  *
400  * This function can only make the constraint stricter. Upper constraint is reset to @p max_dt after the next_time() call.
401  * The return value mimics result of the comparison: current constraint compared to @param upper.
402  * @param message describes the origin of the constraint
403  * In particular the return values is:
404  * - -1: Current upper constraint is less then the @param upper. No change happen.
405  * - 0: Current constraint interval contains the @param upper. The upper constraint is set.
406  * - +1: Current lower constraint is greater then the @param upper. No change happen.
407  */
408  int set_upper_constraint(double upper, std::string message);
409 
410  /**
411  * @brief Sets lower constraint for the next time step estimating.
412  *
413  * This function can only make the constraint stricter. Lower constraint is reset to @p min_dt after the next_time() call.
414  * The return value mimics result of the comparison: current constraint compared to @param upper.
415  * In particular the return values is:
416  * - -1: Current upper constraint is less then the @param lower. No change happen.
417  * - 0: Current constraint interval contains the @param lower. The lower constraint is set.
418  * - +1: Current upper constraint is greater then the @param lower. No change happen.
419  */
420  /**
421  * @brief Sets lower constraint for the next time step estimating.
422  * @param lower is the lower constraint for time step
423  * @param message describes the origin of the constraint
424  * @return -1, 0 or 1 according to the success.
425  * @see set_upper_constrain().
426  */
427  int set_lower_constraint(double lower, std::string message);
428 
429  /**
430  * @brief Fixing time step until fixed time mark.
431  *
432  * Fix time step until first fixed time mark. When called inside an already fixed interval,
433  * it overwrites previous setting.
434  * @return actual end of fixed time step.
435  */
436  double fix_dt_until_mark();
437 
438  /**
439  * @brief Proceed to the next time according to current estimated time step.
440  *
441  * The timestep constraints are relaxed to the permanent constraints.
442  */
443  void next_time();
444 
445  /**
446  * @brief Force timestep reduction in particular in the case of failure of the non-linear solver.
447  *
448  * Calling this method also force immediate end of the fixed timestep interval.
449  * Returns true reduce factor used. It is larger then given factor if we hit the lower timestep constraint.
450  *
451  * TODO: How to keep constraints active for the last next_time call.
452  */
453  double reduce_timestep(double factor);
454 
455  /**
456  * Returns reference to required time step in the recent history.
457  * Without parameter the actual time step is returned.
458  * Use negative indices to get recent time steps: step(-1) the actual step, step(-2) the last one.
459  * Use positive index to get time step by its index: step(0) the first time step.
460  * However only limited number of last time steps is stored.
461  * If the time step is not accessible any more, we throw an exception ExcMissingTimeStep.
462  */
463  const TimeStep &step(int index=-1) const;
464 
465  /**
466  * Specific time mark of the equation owning the time governor.
467  */
469  { return eq_mark_type_;}
470 
471  /**
472  * Specific time mark of the fixed times of the equation owning the time governor.
473  */
475  { return eq_mark_type_ | marks().type_fixed_time(); }
476 
477  /**
478  * Add sequence of time marks starting from the initial time up to the end time with given @p step.
479  * Time marks type combines given mark_type (none by default) and native mark type of the time governor.
480  */
481  void add_time_marks_grid(double step, TimeMark::Type mark_type= TimeMark::none_type) const;
482 
483  /**
484  * Simpler interface to TimeMarks::is_current().
485  */
486  bool is_current(const TimeMark::Type &mask) const;
487 
488 
489  /**
490  * Simpler interface to TimeMarks::next().
491  */
492  inline TimeMarks::iterator next(const TimeMark::Type &mask) const
493  {return time_marks_.next(*this, mask);}
494 
495  /**
496  * Simpler interface to TimeMarks::last().
497  */
498  inline TimeMarks::iterator last(const TimeMark::Type &mask) const
499  {return time_marks_.last(*this, mask);}
500 
501  /**
502  * Getter for upper constrain.
503  */
504  inline double upper_constraint() const
505  {return upper_constraint_;}
506 
507  /**
508  * Returns lower constraint.
509  */
510  inline double lower_constraint() const
511  {return lower_constraint_;}
512 
513  /**
514  * End of interval with currently fixed time step. Can be changed by next call of method fix_dt_until_mark.
515  */
516  inline double end_of_fixed_dt() const
517  {return end_of_fixed_dt_interval_;}
518 
519  /**
520  * Getter for dt_changed. Returns whether the time step has been changed.
521  */
522  inline bool is_changed_dt() const
523  {return time_step_changed_;}
524 
525 
526  /**
527  * Initial time getter.
528  */
529  inline double init_time() const
530  {return this->init_time_;}
531 
532  /**
533  * End of actual time interval; i.e. where the solution is computed.
534  */
535  inline double t() const
536  {return step().end();}
537 
538  /**
539  * Previous time step.
540  */
541  inline double last_dt() const
542  {if (step().index() >0) return step(-2).length();
543  else return inf_time;
544  }
545 
546  /**
547  * Previous time.
548  */
549  inline double last_t() const
550  {if (step().index() >0) return step(-2).end();
551  else return step().end() - step().length();
552  }
553 
554 
555  /**
556  * Length of actual time interval; i.e. the actual time step.
557  */
558  inline double dt() const
559  {return step().length();}
560 
561  /**
562  * @brief Estimate choice of next time step according to actual setting of constraints.
563  *
564  * Precedence of constraints:
565  *
566  * -# meet next fixed time (always satisfied)
567  * -# permanent upper constraint (always satisfied)
568  * -# upper constraint (always satisfied)
569  * -# lower constraint (satisfied if not in conflict with 1.)
570  * -# permanent lower constraint (satisfied if 4.)
571  * -# else writes the difference between lower constraint and estimated time step
572  * -# If there are more then one step to the next fixed time, try to
573  * use the last time step if it is nearly the same.
574  */
575  double estimate_dt() const;
576 
577  /**
578  * Estimate next time.
579  */
580  inline double estimate_time() const
581  {return t()+estimate_dt();}
582 
583  /// End time.
584  inline double end_time() const
585  { return end_time_; }
586 
587  /// Returns true if the actual time is greater than or equal to the end time.
588  inline bool is_end() const
589  { return (this->step().ge(end_time_) || t() == inf_time); }
590 
591  /// Returns true if the time governor is used for steady problem.
592  inline bool is_steady() const
593  { return steady_; }
594 
595 
596 
597  /**
598  * Returns the time level.
599  */
600  inline int tlevel() const
601  {return step().index();}
602 
603  /**
604  * Prints output of TimeGovernor.
605  * @param name is the name of time governor that you want to show up in output (just for your convenience)
606  *
607  */
608  void view(const char *name="") const;
609 
610  /**
611  * Read and return time value multiplied by coefficient of given unit or global coefficient of equation
612  * stored in time_unit_conversion_. If time Tuple is not defined (e. g. Tuple is optional key) return
613  * default_time value.
614  * Shortcut for time_unit_conversion_ function.
615  */
616  double read_time(Input::Iterator<Input::Tuple> time_it, double default_time=std::numeric_limits<double>::quiet_NaN()) const;
617 
618  /**
619  * Read and return time unit coefficient given in unit_it or global coefficient of equation stored
620  * in time_unit_conversion_, if iterator is not defined.
621  * Shortcut for time_unit_conversion_ function.
622  */
623  double read_coef(Input::Iterator<Input::Record> unit_it) const;
624 
625  /**
626  * Return global time unit coefficient of equation.
627  * Shortcut for time_unit_conversion_ function.
628  */
629  double get_coef() const;
630 
631  /// Getter for time unit conversion object.
632  std::shared_ptr<TimeUnitConversion> get_unit_conversion() const;
633 
634  // Maximal tiem of simulation. More then age of the universe in seconds.
635  static const double max_end_time;
636 
637  /// Infinity time used for steady case.
638  static const double inf_time;
639 
640  /**
641  * Rounding precision for computing time_step.
642  * Used as technical lower bound for the time step.
643  */
644  static const double time_step_precision;
645 
646 private:
647 
648  /// Structure that stores one record of DT limit.
649  struct DtLimitRow {
650 
651  DtLimitRow(double t, double min, double max)
652  : time(t),
653  min_dt(min),
654  max_dt(max)
655  {};
656 
657  double time; ///< time of DT limits record
658  double min_dt; ///< min DT limit
659  double max_dt; ///< max DT limit
660  };
661 
662  /**
663  * \brief Common part of the constructors. Set most important parameters, check they are valid and set default values to other.
664  *
665  * Set main parameters to given values.
666  * Check they are correct.
667  * Set soft and permanent constrains to the same, the least restricting values.
668  * Set time marks for the start time and end time (if finite).
669  */
670  void init_common(double init_time, double end_time, TimeMark::Type type);
671 
672  /**
673  * \brief Sets permanent constraints for actual time step.
674  */
676 
677  /**
678  * Size of the time step buffer, i.e. recent_time_steps_.
679  */
680  static const unsigned int size_of_recent_steps_ = 3;
681 
682  /// Circular buffer of recent time steps. Implicit size is 3.
683  boost::circular_buffer<TimeStep> recent_steps_;
684  /// Initial time.
685  double init_time_;
686  /// End of interval if fixed time step.
688  /// End time of the simulation.
689  double end_time_;
690 
691  /// Next fixed time step.
693  /// Flag that is set when the fixed step is set (lasts only one time step).
695  /// Flag is set if the time step has been changed (lasts only one time step).
697 
698  /// Description of the upper constraint.
700  /// Description of the upper constraint.
702  /// Upper constraint for the choice of the next time step.
704  /// Lower constraint for the choice of the next time step.
706  /// Permanent upper limit for the time step.
708  /// Permanent lower limit for the time step.
710 
711  /// Upper constraint used for choice of current time.
713  /// Lower constraint used for choice of current time.
715 
716  /**
717  * When the next time is chosen we need only the lowest fix time. Therefore we use
718  * minimum priority queue of doubles based on the vector container.
719  * This is one global set of time marks for the whole problem and is shared among all equations.
720  * Therefore this object is static constant pointer.
721  */
723 
724  /// TimeMark type of the equation.
726 
727  /// True if the time governor is used for steady problem.
728  bool steady_;
729 
730  /// Conversion unit of all time values within the equation.
731  std::shared_ptr<TimeUnitConversion> time_unit_conversion_;
732 
733  /// Table of DT limits
735 
736  /// Index to actual position of DT limits
737  unsigned int dt_limits_pos_;
738 
739  /// File path for timesteps_output_ stream.
741 
742  /// Handle for file for output time steps to YAML format.
743  std::ofstream timesteps_output_;
744 
745  /// Store last printed time to YAML output, try multiplicity output of one time
747 
748  /// Special flag allows forbid output time steps during multiple initialization of TimeGovernor
750 
751  /// Allows add all times defined in dt_limits_table_ to list of TimeMarks
753 
754  friend TimeMarks;
755 };
756 
757 /**
758  * \brief Stream output operator for TimeGovernor.
759  *
760  * Currently for debugging purposes.
761  * In the future it should be customized for use in combination with
762  * streams for various log targets.
763  *
764  */
765 std::ostream& operator<<(std::ostream& out, const TimeGovernor& tg);
766 
767 
768 
769 #endif /* TIME_HH_ */
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
static Default read_time(const std::string &description)
The factory function to make an default value that will be specified at the time when a key will be r...
Definition: type_record.hh:97
Record type proxy class.
Definition: type_record.hh:182
Tuple type proxy class.
Definition: type_tuple.hh:45
Basic time management functionality for unsteady (and steady) solvers (class Equation).
TimeMark::Type equation_fixed_mark_type() const
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
bool time_step_changed_
Flag is set if the time step has been changed (lasts only one time step).
std::shared_ptr< TimeUnitConversion > get_unit_conversion() const
Getter for time unit conversion object.
double reduce_timestep(double factor)
Force timestep reduction in particular in the case of failure of the non-linear solver.
double lower_constraint() const
std::ofstream timesteps_output_
Handle for file for output time steps to YAML format.
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
void add_time_marks_grid(double step, TimeMark::Type mark_type=TimeMark::none_type) const
void set_dt_limits(double min_dt, double max_dt, Input::Array dt_limits_list)
Sets dt limits for time dependent DT limits in simulation.
TYPEDEF_ERR_INFO(EI_Index, int)
double min_time_step_
Permanent lower limit for the time step.
double last_upper_constraint_
Upper constraint used for choice of current time.
double dt() const
static const Input::Type::Tuple & get_input_time_type(double lower_bound=-std::numeric_limits< double >::max(), double upper_bound=std::numeric_limits< double >::max())
double end_time_
End time of the simulation.
bool steady_
True if the time governor is used for steady problem.
TimeMarks::iterator next(const TimeMark::Type &mask) const
FilePath timesteps_output_file_
File path for timesteps_output_ stream.
bool limits_time_marks_
Allows add all times defined in dt_limits_table_ to list of TimeMarks.
double lower_constraint_
Lower constraint for the choice of the next time step.
DECLARE_INPUT_EXCEPTION(ExcTimeGovernorMessage,<< EI_Message::val)
double get_coef() const
static const unsigned int size_of_recent_steps_
double end_of_fixed_dt_interval_
End of interval if fixed time step.
double t() const
static const Input::Type::Record & get_input_type()
std::string upper_constraint_message_
Description of the upper constraint.
int set_lower_constraint(double lower, std::string message)
Sets lower constraint for the next time step estimating.
std::string lower_constraint_message_
Description of the upper constraint.
TYPEDEF_ERR_INFO(EI_BackIndex, unsigned int)
TimeMark::Type eq_mark_type_
TimeMark type of the equation.
std::vector< DtLimitRow > dt_limits_table_
Table of DT limits.
double upper_constraint_
Upper constraint for the choice of the next time step.
bool is_end() const
Returns true if the actual time is greater than or equal to the end time.
int set_upper_constraint(double upper, std::string message)
Sets upper constraint for the next time step estimating.
double fixed_time_step_
Next fixed time step.
double last_t() const
double upper_constraint() const
bool is_changed_dt() const
double read_coef(Input::Iterator< Input::Record > unit_it) const
static TimeMarks time_marks_
void view(const char *name="") const
boost::circular_buffer< TimeStep > recent_steps_
Circular buffer of recent time steps. Implicit size is 3.
double end_time() const
End time.
double last_dt() const
bool is_time_step_fixed_
Flag that is set when the fixed step is set (lasts only one time step).
DECLARE_EXCEPTION(ExcMissingTimeStep,<< "Time step index: "<< EI_Index::val<< ", history index: "<< EI_BackIndex::val<< " out of history of size: "<< EI_HistorySize::val)
double last_lower_constraint_
Lower constraint used for choice of current time.
double estimate_dt() const
Estimate choice of next time step according to actual setting of constraints.
static const double time_step_precision
TimeGovernor(const Input::Record &input, TimeMark::Type fixed_time_mask=TimeMark::none_type, bool timestep_output=true)
Constructor for unsteady solvers.
static const double max_end_time
void set_permanent_constraint()
Sets permanent constraints for actual time step.
TimeMarks::iterator last(const TimeMark::Type &mask) const
TimeMark::Type equation_mark_type() const
double last_printed_timestep_
Store last printed time to YAML output, try multiplicity output of one time.
double estimate_time() const
double init_time() const
double fix_dt_until_mark()
Fixing time step until fixed time mark.
double init_time_
Initial time.
bool timestep_output_
Special flag allows forbid output time steps during multiple initialization of TimeGovernor.
bool is_current(const TimeMark::Type &mask) const
const TimeStep & step(int index=-1) const
TYPEDEF_ERR_INFO(EI_HistorySize, unsigned int)
static const double inf_time
Infinity time used for steady case.
static TimeMarks & marks()
double end_of_fixed_dt() const
unsigned int dt_limits_pos_
Index to actual position of DT limits.
double max_time_step_
Permanent upper limit for the time step.
bool is_steady() const
Returns true if the time governor is used for steady problem.
int tlevel() const
void init_common(double init_time, double end_time, TimeMark::Type type)
Common part of the constructors. Set most important parameters, check they are valid and set default ...
void next_time()
Proceed to the next time according to current estimated time step.
static const Type none_type
Mark Type with all bits unset.
Definition: time_marks.hh:95
Iterator over TimeMark objects in TimeMarks object (database of TimeMark objects).
Definition: time_marks.hh:351
This class is a collection of time marks to manage various events occurring during simulation time.
Definition: time_marks.hh:206
TimeMarks::iterator last(const TimeStep &time_step, const TimeMark::Type &mask) const
Definition: time_marks.cc:165
TimeMark::Type type_fixed_time()
Definition: time_marks.hh:234
TimeMarks::iterator next(const TimeGovernor &tg, const TimeMark::Type &mask) const
Definition: time_marks.cc:149
Representation of one time step..
bool eq(double other_time) const
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
double end() const
bool operator==(const TimeStep &other)
bool ge(double other_time) const
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
bool gt(double other_time) const
TimeStep make_next(double new_length) const
double end_
End time point of the time step.
bool le(double other_time) const
double read_coef(Input::Iterator< Input::Record > unit_it) const
bool lt(double other_time) const
bool contains(double other_time) const
double length() const
std::shared_ptr< TimeUnitConversion > get_unit_conversion() const
Getter for time unit conversion object.
bool safe_compare(double t1, double t0) const
unsigned int index_
Index of the step is index if the end time. Zero time step is artificial.
double get_coef() const
unsigned int index() const
double length_
Helper class storing unit conversion coefficient and functionality for conversion of units.
double read_unit_coef_from_input(const Input::Record &input) const
Reads the Unit record and computes the coef.
double coef_
Conversion coefficient of all time values within the equation.
double get_coef() const
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time) const
double read_coef(Input::Iterator< Input::Record > unit_it) const
std::string unit_string_
String representation of global unit of all time values within the equation.
std::string get_unit_string() const
static Input::Type::Default get_input_default()
Global macros to enhance readability and debugging, general constants.
Abstract linear system class.
Definition: balance.hh:40
Structure that stores one record of DT limit.
double max_dt
max DT limit
double time
time of DT limits record
DtLimitRow(double t, double min, double max)
double min_dt
min DT limit
std::ostream & operator<<(std::ostream &out, const TimeStep &t_step)