36 #define MAX_END_TIME 5.0e+17
37 #define MAX_END_TIME_STR "5.0e+17"
49 return Tuple(
"TimeValue",
"A time with optional unit specification.")
53 "Predefined units include: `s` seconds, `min` minutes, `h` hours, `d` days, `y` years.\n"
54 "The default time unit is set from the equation's time governor, see the key `common_time_unit`"
55 "in the equation's time record.\n\n"
56 "User can benefit from the Unit Convertor funcionality and create different time units.\n"
57 "Year length example considering leap years (Gregorian calendar): `year; year = 365.2425*d`.\n"
58 "Miliseconds example : `milisec; milisec = 0.001*s`.")
64 static const Tuple &dt_step =
65 Tuple(
"DtLimits",
"Time dependent changes in min_dt and max_dt limits.")
67 "The start time of dt step set.")
69 "Soft lower limit for the time step.")
71 "Whole time of the simulation if specified, infinity else.")
74 return Record(
"TimeGovernor",
75 "Time axis settings of the simulation.\n"
76 "The settings is specific to a particular equation.\n"
77 "TimeGovernor allows to:\n"
78 " - define start time and end time of simulation\n"
79 " - define lower and upper limits of time steps\n"
80 " - direct fixed time marks of whole simulation\n"
81 " - set global time unit of equation (see 'common_time_unit' key)\n"
82 "Limits of time steps are defined by keys 'min_dt', 'max_dt', 'init_dt' and 'dt_limits'. Key "
83 "'init_dt' has the highest priority and allows set fix size of time steps. Pair of keys 'min_dt' "
84 "and 'max_dt' define interval of time steps. Both previous cases ('init_dt' or pair 'min_dt' "
85 "and 'max_dt') set global limits of whole simulation. In contrasts, 'dt_limits' allow set "
86 "time-dependent function of min_dt/max_dt. Used time steps of simulation can be printed to YAML "
87 "output file (see 'write_used_timesteps'.\n"
88 "Fixed time marks define exact values of time steps. They are defined in:\n"
89 " - start time and end time of simulation\n"
90 " - output times printed to output mesh file\n"
91 " - times defined in 'dt_limits' table (optional, see 'add_dt_limits_time_marks' key)")
94 "Start time of the simulation.")
96 "End time of the simulation.\n"
97 "The default value is higher than the age of the Universe (given in seconds).")
99 "Initial guess for the time step.\n"
100 "It applies to equations that use an adaptive time stepping. "
101 "If set to 0.0, the time step is determined in fully autonomous "
102 "way, assuming the equation supports it.")
105 "Soft lower limit for the time step.\n"
106 "Equation using an adaptive time stepping cannot suggest smaller time step. "
107 "The actual time step can only decrease below the limit in order to match "
108 "the prescribed input or output times.")
111 "Hard upper limit for the time step.\n"
112 "The actual time step can only increase above the limit in order to match "
113 "the prescribed input or output times.")
115 "Allow to set a time dependent changes in ``min_dt`` and ``max_dt`` limits. This list is processed "
116 "at individual times overwriting previous values of ``min_dt``/``max_dt``. Limits equal to 0 are "
117 "ignored and replaced with ``min_dt``/``max_dt`` values.")
118 .
declare_key(
"add_dt_limits_time_marks",
Bool(),
Default(
"false"),
"Add all times defined in ``dt_limits`` "
119 "table to the list of fixed TimeMarks.")
121 "Write used time steps to the given file in YAML format corresponding with the format of ``dt_limits``.")
123 "Common time unit of the equation.\nThis unit will be used for all time inputs and outputs "
124 "within the equation. Individually, the common time unit can be overwritten for every declared time.\n"
125 "Time units are used in the following cases:\n"
126 "1) Time units of time value keys in: TimeGovernor, FieldDescriptors.\n"
127 " The common time unit can be overwritten for every declared time.\n"
128 "2) Time units in: \n"
129 " a) input fields: FieldFE and FieldTimeFunction\n"
130 " b) time steps definition of OutputTimeSet\n"
131 " Common time unit can be overwritten by one unit value for every whole mesh data file or time function.\n"
132 "3) Time units in output files: observation times, balance times, frame times of VTK and GMSH\n"
133 " Common time unit cannot be overwritten in these cases."
145 : coef_(1.0), unit_string_(
"s") {}
155 std::string unit_str = input.
val<std::string>(
"unit_formula");
158 }
catch (ExcInvalidUnit &e) {
161 }
catch (ExcNoncorrespondingUnit &e) {
171 double time = time_it->val<
double>(
"time");
174 if ( time_it->opt_val(
"unit", unit_record) ) {
176 return ( time * unit_coef );
179 return ( time *
coef_ );
182 ASSERT(default_time!=std::numeric_limits<double>::quiet_NaN()).error(
"Undefined default time!");
207 time_unit_conversion_(time_unit_conversion)
224 index_(other.index_),
225 length_(other.length_),
227 time_unit_conversion_(other.time_unit_conversion_)
254 - 16*numeric_limits<double>::epsilon()*(1.0+max(abs(t1),abs(t0)));
283 out <<
"time: " << t_step.
end() <<
" dt: " << t_step.
length() << endl;
294 : timestep_output_(timestep_output)
315 input.
opt_val(
"dt_limits", limits_array);
327 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input)
343 }
catch(ExcTimeGovernorMessage &exc) {
351 : dt_limits_pos_(0), timestep_output_(false)
357 THROW(ExcTimeGovernorMessage() << EI_Message(
"Fixed time step smaller then machine precision. \n") );
379 : dt_limits_pos_(0), timestep_output_(false)
408 THROW(ExcTimeGovernorMessage()
409 << EI_Message(
"Start time has to be greater or equal to 0.0\n")
419 THROW(ExcTimeGovernorMessage() << EI_Message(
"End time must be greater than start time.\n") );
468 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' smaller than machine precision.\n") );
470 if (max_dt < min_dt) {
471 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' smaller than 'min_dt'.\n") );
474 bool first_step =
true;
475 if (dt_limits_list.
size())
488 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is lesser than start time of simulation "
492 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is in incorrect order "
497 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is greater than end time of simulation "
503 if (min == 0.0) min = min_dt;
505 if (max == 0.0) max = max_dt;
508 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' in 'dt_limits' smaller than machine precision.\n") );
511 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' in 'dt_limits' smaller than 'min_dt'.\n") );
608 THROW(ExcTimeGovernorMessage()
609 << EI_Message(
"Missing end time for making output grid required by key 'time_step' of the output stream.\n")
636 double full_step = fix_time_it->
time() -
t();
641 if (step_estimate ==
inf_time)
return step_estimate;
648 step_estimate = full_step / n_steps;
658 DebugOut().fmt(
"Time step estimate is below the lower constraint of time step. The difference is: {:.16f}.\n",
662 return step_estimate;
729 double prior_dt =
dt();
730 double new_upper_constraint = factor *
dt();
741 if (current_minus_new < 0)
743 THROW(ExcMessage() << EI_Message(
"Internal error."));
748 return dt() / prior_dt;
754 unsigned int back_idx;
756 back_idx =
static_cast<unsigned int>(-index-1);
758 back_idx =
static_cast<unsigned int>(
recent_steps_[0].index() - index);
761 THROW(ExcMissingTimeStep() << EI_Index(index) << EI_BackIndex(back_idx) << EI_HistorySize(
recent_steps_.size()));
771 #ifdef FLOW123D_DEBUG_MESSAGES
773 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}> "
774 "end_time: {} end_fixed_time: {} type: {:#x}\n",
778 MessageOut().fmt(
"Lower time step constraint [{}]: {} \nUpper time step constraint [{}]: {} \n",
783 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}>\n",
815 static char buffer[1024];
816 sprintf(buffer,
"\n%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>\n",
818 return (out << buffer);
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal) only for debug mode.
Dedicated class for storing path to input and output files.
void open_stream(Stream &stream) const
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.
double min_time_step_
Permanent lower limit for the time step.
double last_upper_constraint_
Upper constraint used for choice of current time.
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.
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.
static const unsigned int size_of_recent_steps_
double end_of_fixed_dt_interval_
End of interval if fixed time step.
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.
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 upper_constraint() 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.
bool is_time_step_fixed_
Flag that is set when the fixed step is set (lasts only one time step).
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.
TimeMark::Type equation_mark_type() const
double last_printed_timestep_
Store last printed time to YAML output, try multiplicity output of one time.
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
static const double inf_time
Infinity time used for steady case.
static TimeMarks & marks()
unsigned int dt_limits_pos_
Index to actual position of DT limits.
double max_time_step_
Permanent upper limit for the time step.
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.
Class used for marking specified times at which some events occur.
static const Type every_type
Mark Type with all bits set.
double time() const
Getter for the time of the TimeMark.
static const Type none_type
Mark Type with all bits unset.
Iterator over TimeMark objects in TimeMarks object (database of TimeMark objects).
This class is a collection of time marks to manage various events occurring during simulation time.
void add_time_marks(double time, double dt, double end_time, TimeMark::Type type)
TimeMarks::iterator end(TimeMark::Type mask) const
Iterator for the end mimics container-like of TimeMarks.
TimeMarks::iterator current(const TimeStep &time_step, const TimeMark::Type &mask) const
TimeMark::Type new_mark_type()
TimeMark add(const TimeMark &mark)
TimeMarks::iterator next(const TimeGovernor &tg, const TimeMark::Type &mask) const
Representation of one time step..
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
TimeStep make_next(double new_length) const
double end_
End time point of the time step.
double read_coef(Input::Iterator< Input::Record > unit_it) 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 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 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.
static Input::Type::Default get_input_default()
static const Input::Type::Record & get_input_type()
Class for representation SI units of Fields.
double convert_unit_from(std::string actual_unit) const
Convert and check user-defined unit.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
#define WarningOut()
Macro defining 'warning' record of log.
#define MessageOut()
Macro defining 'message' record of log.
#define DebugOut()
Macro defining 'debug' record of log.
std::string sprintf(CStringRef format, ArgList args)
Structure that stores one record of DT limit.
unsigned long int bitmap_
ostream & operator<<(ostream &out, const TimeStep &t_step)
Basic time management class.