Flow123d  3.9.0-127d9ed9b
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 
230  /**
231  * Temporary hack allows switched of using of FParser in FieldFormula.
232  *
233  * Flag is set to false default and can be set to true before call set_time in equation.
234  */
235  mutable bool use_fparser_;
236 private:
237 
238  /* Returns true if t1-t0 > delta. Where delta is choosen
239  * related to the current time step and magnitude of t1, t0.
240  */
241  bool safe_compare(double t1, double t0) const;
242 
243  /// Index of the step is index if the end time. Zero time step is artificial.
244  unsigned int index_;
245  /// Length of the time step. Theoretically @p end minus end of the previous time step.
246  /// However may be slightly different due to rounding errors.
247  double length_;
248  /// End time point of the time step.
249  double end_;
250  /// Conversion unit of all time values within the equation.
251  std::shared_ptr<TimeUnitConversion> time_unit_conversion_;
252 };
253 
254 std::ostream& operator<<(std::ostream& out, const TimeStep& t_step);
255 
256 
257 
258 /**
259  * @brief
260  * Basic time management functionality for unsteady (and steady) solvers (class Equation).
261  *
262  * <h2> Common features and unsteady time governor (TG) </h2>
263  *
264  * This class provides algorithm for selecting next time step, and information about current time step frame.
265  * Step estimating is constrained by several bounds (permanent maximal and minimal time step, upper
266  * and lower constraint of time step). The permanent constraints are set in the constructor from the input
267  * record so that user can set the time step constraints for the whole simulation.
268  * Function set_dt_limits() should be used only in very specific cases and possibly right after
269  * the constructor before using other functions of TG.
270  *
271  * Choice of the very next time step can be constrained using functions set_upper_constraint()
272  * and set_lower_constraint().
273  * Lower and upper constraints are set equal to permanent ones in the constructor and can only
274  * become stricter. If one tries to set these constraints outside the interval of the previous constraints,
275  * nothing is changed and a specified value is returned. Upper and lower constraints are reset in function
276  * next_time() to the permanent constraints.
277  *
278  * The later one can be called multiple times with various constraint values and we use the minimum of them.
279  * Function next_time() choose the next time step in such a way that it meets actual constraints and
280  * a uniform discrete time grid with this step hits the nearest fixed time in lowest possible number of steps.
281  *
282  * The fixed times are time marks of TimeMarks object passed at construction time with particular mask.
283  *
284  * There is just one set of time marks for the whole problem. Therefore TimeMarks object is static and is shared umong
285  * all the equations and time governors. Each equation creates its own specific time mark type.
286  *
287  * Information provided by TG includes:
288  * - actual time, last time, end time
289  * - actual time step
290  * - number of the time level
291  * - end of interval with fixed time step
292  * - time comparison
293  * - static pointer to time marks
294  *
295  * <h2> Steady time governor</h2>
296  *
297  * Steady TG can be constructed by default constructor (initial time is zero) or by
298  * constructor with initial time as parameter. End time and time step are set to infinity.
299  * One can check if the time governor is steady by calling is_steady().
300  * Calling estimate_dt() will return infinity.
301  *
302  * Setting constraints have no consequences. Calling fix_dt_until_mark() will only return zero
303  * and will not do anything.
304  *
305  * The steady TG works in two states. At first the time is set to initial and time level
306  * is equal zero. To use steady TG properly one should call next_time() after the computation
307  * of steady problem is done. Current time is then set to infinity, time level is set to 1 and
308  * calling estimate_dt() will return zero.
309  *
310  * Note: For example class TransportNothing (which computes really nothing) uses also steady TG but
311  * it calls next_time() immediately after TG's construction. This means that the 'computation'of transport
312  * is done.
313  *
314  *
315  */
316 
318 {
319 public:
320 
321  DECLARE_INPUT_EXCEPTION(ExcTimeGovernorMessage, << EI_Message::val);
322  TYPEDEF_ERR_INFO( EI_Index, int);
323  TYPEDEF_ERR_INFO( EI_BackIndex, unsigned int);
324  TYPEDEF_ERR_INFO( EI_HistorySize, unsigned int);
325  DECLARE_EXCEPTION(ExcMissingTimeStep,
326  << "Time step index: " << EI_Index::val
327  << ", history index: " << EI_BackIndex::val
328  << " out of history of size: " << EI_HistorySize::val);
329 
330  static const Input::Type::Record & get_input_type();
331 
332  static const Input::Type::Tuple & get_input_time_type(double lower_bound= -std::numeric_limits<double>::max(),
333  double upper_bound=std::numeric_limits<double>::max());
334 
335  /**
336  * Getter for time marks.
337  */
338  static inline TimeMarks &marks()
339  {return time_marks_;}
340 
341  /**
342  * @brief Constructor for unsteady solvers.
343  *
344  * @param input accessor to input data
345  * @param fixed_time_mask TimeMark mask used to select fixed time marks from all the time marks.
346  * @param timestep_output enable/forbid output of time steps to YAML file
347  * This value is bitwise added to the default one defined in TimeMarks::type_fixed_time().
348  *
349  */
350  TimeGovernor(const Input::Record &input,
351  TimeMark::Type fixed_time_mask = TimeMark::none_type,
352  bool timestep_output = true);
353 
354  /**
355  * @brief Default constructor - steady time governor.
356  *
357  * OBSOLETE.
358  *
359  * We can have "zero step" steady problem (no computation, e.g. EquationNothing) and one step steady problem
360  * (e.g. steady water flow).
361  *
362  * Time is set to zero, time step and end time to infinity.
363  *
364  * First call of next_time() pushes the actual time to infinity.
365  *
366  * However, you have to use full constructor for the "steady problem" that has time-variable input data.
367  *
368  * Has a private pointer to static TimeMarks and can access them by marks().
369  */
370  explicit TimeGovernor(double init_time=0.0,
371  TimeMark::Type fixed_time_mask = TimeMark::none_type);
372 
373  /**
374  * The aim of this constuctor is simple way to make a time governor without Input interface.
375  *
376  * TODO: Partially tested as part of field test. Needs its own unit test.
377  */
378  TimeGovernor(double init_time, double dt);
379 
380  /**
381  * Destructor.
382  */
383  ~TimeGovernor();
384 
385  /**
386  * Returns true if the time governor was set from default values
387  */
388  bool is_default() {
389  return (end_time_ == max_end_time)
391  }
392 
393  /**
394  * @brief Sets dt limits for time dependent DT limits in simulation.
395  *
396  * This function should not be normally used. These values are to be set in constructor
397  * from the input record or by default.
398  * @param min_dt is the minimal value allowed for time step
399  * @param max_dt is the maximal value allowed for time step
400  * @param dt_limits_list list of time dependent values of minimal and maximal value allowed for time step
401  */
402  void set_dt_limits( double min_dt, double max_dt, Input::Array dt_limits_list);
403 
404  /**
405  * @brief Sets upper constraint for the next time step estimating.
406  *
407  * This function can only make the constraint stricter. Upper constraint is reset to @p max_dt after the next_time() call.
408  * The return value mimics result of the comparison: current constraint compared to @param upper.
409  * @param message describes the origin of the constraint
410  * In particular the return values is:
411  * - -1: Current upper constraint is less then the @param upper. No change happen.
412  * - 0: Current constraint interval contains the @param upper. The upper constraint is set.
413  * - +1: Current lower constraint is greater then the @param upper. No change happen.
414  */
415  int set_upper_constraint(double upper, std::string message);
416 
417  /**
418  * @brief Sets lower constraint for the next time step estimating.
419  *
420  * This function can only make the constraint stricter. Lower constraint is reset to @p min_dt after the next_time() call.
421  * The return value mimics result of the comparison: current constraint compared to @param upper.
422  * In particular the return values is:
423  * - -1: Current upper constraint is less then the @param lower. No change happen.
424  * - 0: Current constraint interval contains the @param lower. The lower constraint is set.
425  * - +1: Current upper constraint is greater then the @param lower. No change happen.
426  */
427  /**
428  * @brief Sets lower constraint for the next time step estimating.
429  * @param lower is the lower constraint for time step
430  * @param message describes the origin of the constraint
431  * @return -1, 0 or 1 according to the success.
432  * @see set_upper_constrain().
433  */
434  int set_lower_constraint(double lower, std::string message);
435 
436  /**
437  * @brief Fixing time step until fixed time mark.
438  *
439  * Fix time step until first fixed time mark. When called inside an already fixed interval,
440  * it overwrites previous setting.
441  * @return actual end of fixed time step.
442  */
443  double fix_dt_until_mark();
444 
445  /**
446  * @brief Proceed to the next time according to current estimated time step.
447  *
448  * The timestep constraints are relaxed to the permanent constraints.
449  */
450  void next_time();
451 
452  /**
453  * @brief Force timestep reduction in particular in the case of failure of the non-linear solver.
454  *
455  * Calling this method also force immediate end of the fixed timestep interval.
456  * Returns true reduce factor used. It is larger then given factor if we hit the lower timestep constraint.
457  *
458  * TODO: How to keep constraints active for the last next_time call.
459  */
460  double reduce_timestep(double factor);
461 
462  /**
463  * Returns reference to required time step in the recent history.
464  * Without parameter the actual time step is returned.
465  * Use negative indices to get recent time steps: step(-1) the actual step, step(-2) the last one.
466  * Use positive index to get time step by its index: step(0) the first time step.
467  * However only limited number of last time steps is stored.
468  * If the time step is not accessible any more, we throw an exception ExcMissingTimeStep.
469  */
470  const TimeStep &step(int index=-1) const;
471 
472  /**
473  * Specific time mark of the equation owning the time governor.
474  */
476  { return eq_mark_type_;}
477 
478  /**
479  * Specific time mark of the fixed times of the equation owning the time governor.
480  */
482  { return eq_mark_type_ | marks().type_fixed_time(); }
483 
484  /**
485  * Add sequence of time marks starting from the initial time up to the end time with given @p step.
486  * Time marks type combines given mark_type (none by default) and native mark type of the time governor.
487  */
488  void add_time_marks_grid(double step, TimeMark::Type mark_type= TimeMark::none_type) const;
489 
490  /**
491  * Simpler interface to TimeMarks::is_current().
492  */
493  bool is_current(const TimeMark::Type &mask) const;
494 
495 
496  /**
497  * Simpler interface to TimeMarks::next().
498  */
499  inline TimeMarks::iterator next(const TimeMark::Type &mask) const
500  {return time_marks_.next(*this, mask);}
501 
502  /**
503  * Simpler interface to TimeMarks::last().
504  */
505  inline TimeMarks::iterator last(const TimeMark::Type &mask) const
506  {return time_marks_.last(*this, mask);}
507 
508  /**
509  * Getter for upper constrain.
510  */
511  inline double upper_constraint() const
512  {return upper_constraint_;}
513 
514  /**
515  * Returns lower constraint.
516  */
517  inline double lower_constraint() const
518  {return lower_constraint_;}
519 
520  /**
521  * End of interval with currently fixed time step. Can be changed by next call of method fix_dt_until_mark.
522  */
523  inline double end_of_fixed_dt() const
524  {return end_of_fixed_dt_interval_;}
525 
526  /**
527  * Getter for dt_changed. Returns whether the time step has been changed.
528  */
529  inline bool is_changed_dt() const
530  {return time_step_changed_;}
531 
532 
533  /**
534  * Initial time getter.
535  */
536  inline double init_time() const
537  {return this->init_time_;}
538 
539  /**
540  * End of actual time interval; i.e. where the solution is computed.
541  */
542  inline double t() const
543  {return step().end();}
544 
545  /**
546  * Previous time step.
547  */
548  inline double last_dt() const
549  {if (step().index() >0) return step(-2).length();
550  else return inf_time;
551  }
552 
553  /**
554  * Previous time.
555  */
556  inline double last_t() const
557  {if (step().index() >0) return step(-2).end();
558  else return step().end() - step().length();
559  }
560 
561 
562  /**
563  * Length of actual time interval; i.e. the actual time step.
564  */
565  inline double dt() const
566  {return step().length();}
567 
568  /**
569  * @brief Estimate choice of next time step according to actual setting of constraints.
570  *
571  * Precedence of constraints:
572  *
573  * -# meet next fixed time (always satisfied)
574  * -# permanent upper constraint (always satisfied)
575  * -# upper constraint (always satisfied)
576  * -# lower constraint (satisfied if not in conflict with 1.)
577  * -# permanent lower constraint (satisfied if 4.)
578  * -# else writes the difference between lower constraint and estimated time step
579  * -# If there are more then one step to the next fixed time, try to
580  * use the last time step if it is nearly the same.
581  */
582  double estimate_dt() const;
583 
584  /**
585  * Estimate next time.
586  */
587  inline double estimate_time() const
588  {return t()+estimate_dt();}
589 
590  /// End time.
591  inline double end_time() const
592  { return end_time_; }
593 
594  /// Returns true if the actual time is greater than or equal to the end time.
595  inline bool is_end() const
596  { return (this->step().ge(end_time_) || t() == inf_time); }
597 
598  /// Returns true if the time governor is used for steady problem.
599  inline bool is_steady() const
600  { return steady_; }
601 
602 
603 
604  /**
605  * Returns the time level.
606  */
607  inline int tlevel() const
608  {return step().index();}
609 
610  /**
611  * Prints output of TimeGovernor.
612  * @param name is the name of time governor that you want to show up in output (just for your convenience)
613  *
614  */
615  void view(const char *name="") const;
616 
617  /**
618  * Read and return time value multiplied by coefficient of given unit or global coefficient of equation
619  * stored in time_unit_conversion_. If time Tuple is not defined (e. g. Tuple is optional key) return
620  * default_time value.
621  * Shortcut for time_unit_conversion_ function.
622  */
623  double read_time(Input::Iterator<Input::Tuple> time_it, double default_time=std::numeric_limits<double>::quiet_NaN()) const;
624 
625  /**
626  * Read and return time unit coefficient given in unit_it or global coefficient of equation stored
627  * in time_unit_conversion_, if iterator is not defined.
628  * Shortcut for time_unit_conversion_ function.
629  */
630  double read_coef(Input::Iterator<Input::Record> unit_it) const;
631 
632  /**
633  * Return global time unit coefficient of equation.
634  * Shortcut for time_unit_conversion_ function.
635  */
636  double get_coef() const;
637 
638  /// Getter for time unit conversion object.
639  std::shared_ptr<TimeUnitConversion> get_unit_conversion() const;
640 
641  // Maximal tiem of simulation. More then age of the universe in seconds.
642  static const double max_end_time;
643 
644  /// Infinity time used for steady case.
645  static const double inf_time;
646 
647  /**
648  * Rounding precision for computing time_step.
649  * Used as technical lower bound for the time step.
650  */
651  static const double time_step_precision;
652 
653 private:
654 
655  /// Structure that stores one record of DT limit.
656  struct DtLimitRow {
657 
658  DtLimitRow(double t, double min, double max)
659  : time(t),
660  min_dt(min),
661  max_dt(max)
662  {};
663 
664  double time; ///< time of DT limits record
665  double min_dt; ///< min DT limit
666  double max_dt; ///< max DT limit
667  };
668 
669  /**
670  * \brief Common part of the constructors. Set most important parameters, check they are valid and set default values to other.
671  *
672  * Set main parameters to given values.
673  * Check they are correct.
674  * Set soft and permanent constrains to the same, the least restricting values.
675  * Set time marks for the start time and end time (if finite).
676  */
677  void init_common(double init_time, double end_time, TimeMark::Type type);
678 
679  /**
680  * \brief Sets permanent constraints for actual time step.
681  */
683 
684  /**
685  * Size of the time step buffer, i.e. recent_time_steps_.
686  */
687  static const unsigned int size_of_recent_steps_ = 3;
688 
689  /// Circular buffer of recent time steps. Implicit size is 3.
690  boost::circular_buffer<TimeStep> recent_steps_;
691  /// Initial time.
692  double init_time_;
693  /// End of interval if fixed time step.
695  /// End time of the simulation.
696  double end_time_;
697 
698  /// Next fixed time step.
700  /// Flag that is set when the fixed step is set (lasts only one time step).
702  /// Flag is set if the time step has been changed (lasts only one time step).
704 
705  /// Description of the upper constraint.
707  /// Description of the upper constraint.
709  /// Upper constraint for the choice of the next time step.
711  /// Lower constraint for the choice of the next time step.
713  /// Permanent upper limit for the time step.
715  /// Permanent lower limit for the time step.
717 
718  /// Upper constraint used for choice of current time.
720  /// Lower constraint used for choice of current time.
722 
723  /**
724  * When the next time is chosen we need only the lowest fix time. Therefore we use
725  * minimum priority queue of doubles based on the vector container.
726  * This is one global set of time marks for the whole problem and is shared among all equations.
727  * Therefore this object is static constant pointer.
728  */
730 
731  /// TimeMark type of the equation.
733 
734  /// True if the time governor is used for steady problem.
735  bool steady_;
736 
737  /// Conversion unit of all time values within the equation.
738  std::shared_ptr<TimeUnitConversion> time_unit_conversion_;
739 
740  /// Table of DT limits
742 
743  /// Index to actual position of DT limits
744  unsigned int dt_limits_pos_;
745 
746  /// File path for timesteps_output_ stream.
748 
749  /// Handle for file for output time steps to YAML format.
750  std::ofstream timesteps_output_;
751 
752  /// Store last printed time to YAML output, try multiplicity output of one time
754 
755  /// Special flag allows forbid output time steps during multiple initialization of TimeGovernor
757 
758  /// Allows add all times defined in dt_limits_table_ to list of TimeMarks
760 
761  friend TimeMarks;
762 };
763 
764 /**
765  * \brief Stream output operator for TimeGovernor.
766  *
767  * Currently for debugging purposes.
768  * In the future it should be customized for use in combination with
769  * streams for various log targets.
770  *
771  */
772 std::ostream& operator<<(std::ostream& out, const TimeGovernor& tg);
773 
774 
775 
776 #endif /* TIME_HH_ */
TimeGovernor::DtLimitRow::max_dt
double max_dt
max DT limit
Definition: time_governor.hh:666
TimeStep::read_coef
double read_coef(Input::Iterator< Input::Record > unit_it) const
Definition: time_governor.cc:268
TimeStep::get_coef
double get_coef() const
Definition: time_governor.cc:274
TimeGovernor::add_time_marks_grid
void add_time_marks_grid(double step, TimeMark::Type mark_type=TimeMark::none_type) const
Definition: time_governor.cc:608
TimeStep::safe_compare
bool safe_compare(double t1, double t0) const
Definition: time_governor.cc:254
TimeGovernor::DECLARE_INPUT_EXCEPTION
DECLARE_INPUT_EXCEPTION(ExcTimeGovernorMessage,<< EI_Message::val)
TimeUnitConversion::read_unit_coef_from_input
double read_unit_coef_from_input(const Input::Record &input) const
Reads the Unit record and computes the coef.
Definition: time_governor.cc:153
TimeMarks::next
TimeMarks::iterator next(const TimeGovernor &tg, const TimeMark::Type &mask) const
Definition: time_marks.cc:149
TimeGovernor::DECLARE_EXCEPTION
DECLARE_EXCEPTION(ExcMissingTimeStep,<< "Time step index: "<< EI_Index::val<< ", history index: "<< EI_BackIndex::val<< " out of history of size: "<< EI_HistorySize::val)
TimeStep::le
bool le(double other_time) const
Definition: time_governor.hh:185
TimeGovernor::DtLimitRow::DtLimitRow
DtLimitRow(double t, double min, double max)
Definition: time_governor.hh:658
TimeGovernor::~TimeGovernor
~TimeGovernor()
Definition: time_governor.cc:398
TimeGovernor::dt
double dt() const
Definition: time_governor.hh:565
operator<<
std::ostream & operator<<(std::ostream &out, const TimeStep &t_step)
Definition: time_governor.cc:285
TimeGovernor::last_printed_timestep_
double last_printed_timestep_
Store last printed time to YAML output, try multiplicity output of one time.
Definition: time_governor.hh:753
TimeUnitConversion::get_input_default
static Input::Type::Default get_input_default()
Definition: time_governor.hh:66
TimeGovernor::set_permanent_constraint
void set_permanent_constraint()
Sets permanent constraints for actual time step.
Definition: time_governor.cc:539
TimeGovernor::end_time
double end_time() const
End time.
Definition: time_governor.hh:591
TimeGovernor::dt_limits_pos_
unsigned int dt_limits_pos_
Index to actual position of DT limits.
Definition: time_governor.hh:744
TimeGovernor::upper_constraint_message_
std::string upper_constraint_message_
Description of the upper constraint.
Definition: time_governor.hh:706
TimeGovernor::get_unit_conversion
std::shared_ptr< TimeUnitConversion > get_unit_conversion() const
Getter for time unit conversion object.
Definition: time_governor.cc:810
TimeUnitConversion::read_time
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time) const
Definition: time_governor.cc:169
TimeGovernor::init_time_
double init_time_
Initial time.
Definition: time_governor.hh:692
Input
Abstract linear system class.
Definition: balance.hh:40
TimeMarks::last
TimeMarks::iterator last(const TimeStep &time_step, const TimeMark::Type &mask) const
Definition: time_marks.cc:165
TimeGovernor::fixed_time_step_
double fixed_time_step_
Next fixed time step.
Definition: time_governor.hh:699
TimeGovernor::TimeGovernor
TimeGovernor(const Input::Record &input, TimeMark::Type fixed_time_mask=TimeMark::none_type, bool timestep_output=true)
Constructor for unsteady solvers.
Definition: time_governor.cc:296
TimeGovernor::equation_fixed_mark_type
TimeMark::Type equation_fixed_mark_type() const
Definition: time_governor.hh:481
file_path.hh
TimeGovernor::set_upper_constraint
int set_upper_constraint(double upper, std::string message)
Sets upper constraint for the next time step estimating.
Definition: time_governor.cc:555
TimeGovernor::estimate_time
double estimate_time() const
Definition: time_governor.hh:587
TimeGovernor::end_of_fixed_dt_interval_
double end_of_fixed_dt_interval_
End of interval if fixed time step.
Definition: time_governor.hh:694
TimeGovernor::size_of_recent_steps_
static const unsigned int size_of_recent_steps_
Definition: time_governor.hh:687
TimeStep::get_unit_conversion
std::shared_ptr< TimeUnitConversion > get_unit_conversion() const
Getter for time unit conversion object.
Definition: time_governor.cc:280
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
TimeGovernor::recent_steps_
boost::circular_buffer< TimeStep > recent_steps_
Circular buffer of recent time steps. Implicit size is 3.
Definition: time_governor.hh:690
TimeGovernor::upper_constraint_
double upper_constraint_
Upper constraint for the choice of the next time step.
Definition: time_governor.hh:710
TimeGovernor::time_marks_
static TimeMarks time_marks_
Definition: time_governor.hh:729
TimeUnitConversion::get_coef
double get_coef() const
Definition: time_governor.hh:87
std::vector
Definition: doxy_dummy_defs.hh:7
Input::Type::Default::read_time
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
TimeStep::gt
bool gt(double other_time) const
Definition: time_governor.hh:167
system.hh
TimeGovernor::read_coef
double read_coef(Input::Iterator< Input::Record > unit_it) const
Definition: time_governor.cc:799
Input::Type::Tuple
Tuple type proxy class.
Definition: type_tuple.hh:45
TimeStep::lt
bool lt(double other_time) const
Definition: time_governor.hh:179
TimeGovernor::min_time_step_
double min_time_step_
Permanent lower limit for the time step.
Definition: time_governor.hh:716
TimeStep::read_time
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
Definition: time_governor.cc:262
TimeGovernor::steady_
bool steady_
True if the time governor is used for steady problem.
Definition: time_governor.hh:735
TimeStep::use_fparser_
bool use_fparser_
Definition: time_governor.hh:235
TimeMarks::type_fixed_time
TimeMark::Type type_fixed_time()
Definition: time_marks.hh:234
TimeUnitConversion
Helper class storing unit conversion coefficient and functionality for conversion of units.
Definition: time_governor.hh:58
exceptions.hh
type_record.hh
TimeGovernor::set_lower_constraint
int set_lower_constraint(double lower, std::string message)
Sets lower constraint for the next time step estimating.
Definition: time_governor.cc:576
TimeUnitConversion::unit_string_
std::string unit_string_
String representation of global unit of all time values within the equation.
Definition: time_governor.hh:107
TimeGovernor::set_dt_limits
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.
Definition: time_governor.cc:465
TimeGovernor::last_lower_constraint_
double last_lower_constraint_
Lower constraint used for choice of current time.
Definition: time_governor.hh:721
TimeGovernor::init_common
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 ...
Definition: time_governor.cc:407
Input::Iterator
Definition: accessors.hh:143
TimeUnitConversion::TimeUnitConversion
TimeUnitConversion()
Definition: time_governor.cc:144
TimeGovernor::is_end
bool is_end() const
Returns true if the actual time is greater than or equal to the end time.
Definition: time_governor.hh:595
TimeGovernor::lower_constraint_message_
std::string lower_constraint_message_
Description of the upper constraint.
Definition: time_governor.hh:708
TimeGovernor::last_upper_constraint_
double last_upper_constraint_
Upper constraint used for choice of current time.
Definition: time_governor.hh:719
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
TimeStep::length_
double length_
Definition: time_governor.hh:247
TimeStep::operator==
bool operator==(const TimeStep &other)
Definition: time_governor.hh:224
TimeGovernor::timestep_output_
bool timestep_output_
Special flag allows forbid output time steps during multiple initialization of TimeGovernor.
Definition: time_governor.hh:756
TimeGovernor::is_steady
bool is_steady() const
Returns true if the time governor is used for steady problem.
Definition: time_governor.hh:599
TimeStep::end
double end() const
Definition: time_governor.hh:161
TimeGovernor::limits_time_marks_
bool limits_time_marks_
Allows add all times defined in dt_limits_table_ to list of TimeMarks.
Definition: time_governor.hh:759
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
TimeGovernor::time_step_precision
static const double time_step_precision
Definition: time_governor.hh:651
TimeStep::time_unit_conversion_
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
Definition: time_governor.hh:251
TimeGovernor::tlevel
int tlevel() const
Definition: time_governor.hh:607
TimeGovernor::upper_constraint
double upper_constraint() const
Definition: time_governor.hh:511
TimeGovernor::end_time_
double end_time_
End time of the simulation.
Definition: time_governor.hh:696
TimeGovernor::reduce_timestep
double reduce_timestep(double factor)
Force timestep reduction in particular in the case of failure of the non-linear solver.
Definition: time_governor.cc:731
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:317
TimeGovernor::step
const TimeStep & step(int index=-1) const
Definition: time_governor.cc:756
TimeMark::Type
Definition: time_marks.hh:60
TimeGovernor::DtLimitRow
Structure that stores one record of DT limit.
Definition: time_governor.hh:656
TimeUnitConversion::read_coef
double read_coef(Input::Iterator< Input::Record > unit_it) const
Definition: time_governor.cc:189
TimeGovernor::next
TimeMarks::iterator next(const TimeMark::Type &mask) const
Definition: time_governor.hh:499
TimeGovernor::last_t
double last_t() const
Definition: time_governor.hh:556
input_exception.hh
TimeStep::end_
double end_
End time point of the time step.
Definition: time_governor.hh:249
TimeUnitConversion::coef_
double coef_
Conversion coefficient of all time values within the equation.
Definition: time_governor.hh:104
TimeGovernor::estimate_dt
double estimate_dt() const
Estimate choice of next time step according to actual setting of constraints.
Definition: time_governor.cc:631
TimeGovernor::get_input_type
static const Input::Type::Record & get_input_type()
Definition: time_governor.cc:63
TimeGovernor::view
void view(const char *name="") const
Definition: time_governor.cc:772
TimeGovernor::end_of_fixed_dt
double end_of_fixed_dt() const
Definition: time_governor.hh:523
TimeGovernor::lower_constraint_
double lower_constraint_
Lower constraint for the choice of the next time step.
Definition: time_governor.hh:712
exc_common.hh
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
TimeMark::none_type
static const Type none_type
Mark Type with all bits unset.
Definition: time_marks.hh:95
TimeStep::make_next
TimeStep make_next(double new_length) const
Definition: time_governor.cc:235
TimeStep::eq
bool eq(double other_time) const
Definition: time_governor.hh:191
TimeStep::index_
unsigned int index_
Index of the step is index if the end time. Zero time step is artificial.
Definition: time_governor.hh:244
TimeMarks
This class is a collection of time marks to manage various events occurring during simulation time.
Definition: time_marks.hh:206
TimeGovernor::DtLimitRow::min_dt
double min_dt
min DT limit
Definition: time_governor.hh:665
TimeGovernor::dt_limits_table_
std::vector< DtLimitRow > dt_limits_table_
Table of DT limits.
Definition: time_governor.hh:741
TimeGovernor::read_time
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
Definition: time_governor.cc:793
TimeGovernor::marks
static TimeMarks & marks()
Definition: time_governor.hh:338
TimeGovernor::timesteps_output_
std::ofstream timesteps_output_
Handle for file for output time steps to YAML format.
Definition: time_governor.hh:750
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
global_defs.h
Global macros to enhance readability and debugging, general constants.
TimeGovernor::get_coef
double get_coef() const
Definition: time_governor.cc:805
TimeGovernor::TimeMarks
friend TimeMarks
Definition: time_governor.hh:761
TimeGovernor::DtLimitRow::time
double time
time of DT limits record
Definition: time_governor.hh:662
TimeGovernor::time_unit_conversion_
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
Definition: time_governor.hh:738
accessors_forward.hh
TimeGovernor::is_default
bool is_default()
Definition: time_governor.hh:388
TimeGovernor::inf_time
static const double inf_time
Infinity time used for steady case.
Definition: time_governor.hh:645
TimeStep::TimeStep
TimeStep()
Definition: time_governor.cc:213
TimeGovernor::equation_mark_type
TimeMark::Type equation_mark_type() const
Definition: time_governor.hh:475
TimeGovernor::last
TimeMarks::iterator last(const TimeMark::Type &mask) const
Definition: time_governor.hh:505
TimeGovernor::max_time_step_
double max_time_step_
Permanent upper limit for the time step.
Definition: time_governor.hh:714
TimeGovernor::max_end_time
static const double max_end_time
Definition: time_governor.hh:642
TimeGovernor::timesteps_output_file_
FilePath timesteps_output_file_
File path for timesteps_output_ stream.
Definition: time_governor.hh:747
TimeGovernor::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_Index, int)
TimeGovernor::is_changed_dt
bool is_changed_dt() const
Definition: time_governor.hh:529
TimeGovernor::is_current
bool is_current(const TimeMark::Type &mask) const
Definition: time_governor.cc:623
TimeGovernor::get_input_time_type
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())
Definition: time_governor.cc:47
time_marks.hh
TimeStep::contains
bool contains(double other_time) const
Definition: time_governor.hh:194
TimeStep::index
unsigned int index() const
Definition: time_governor.hh:159
TimeStep::ge
bool ge(double other_time) const
Definition: time_governor.hh:173
TimeGovernor::lower_constraint
double lower_constraint() const
Definition: time_governor.hh:517
TimeGovernor::next_time
void next_time()
Proceed to the next time according to current estimated time step.
Definition: time_governor.cc:670
TimeStep::length
double length() const
Definition: time_governor.hh:160
TimeGovernor::time_step_changed_
bool time_step_changed_
Flag is set if the time step has been changed (lasts only one time step).
Definition: time_governor.hh:703
TimeGovernor::fix_dt_until_mark
double fix_dt_until_mark()
Fixing time step until fixed time mark.
Definition: time_governor.cc:597
TimeGovernor::init_time
double init_time() const
Definition: time_governor.hh:536
TimeMarksIterator
Iterator over TimeMark objects in TimeMarks object (database of TimeMark objects).
Definition: time_marks.hh:351
TimeGovernor::eq_mark_type_
TimeMark::Type eq_mark_type_
TimeMark type of the equation.
Definition: time_governor.hh:732
TimeGovernor::last_dt
double last_dt() const
Definition: time_governor.hh:548
TimeGovernor::is_time_step_fixed_
bool is_time_step_fixed_
Flag that is set when the fixed step is set (lasts only one time step).
Definition: time_governor.hh:701
TimeUnitConversion::get_unit_string
std::string get_unit_string() const
Definition: time_governor.hh:94
TimeGovernor::t
double t() const
Definition: time_governor.hh:542