35 #define MAX_END_TIME 5.0e+17 36 #define MAX_END_TIME_STR "5.0e+17" 48 return Tuple(
"TimeValue",
"A time with unit specification.")
50 "Numeric value of time." )
52 "Specify unit of an input time value.")
58 static const Tuple &dt_step =
59 Tuple(
"DtLimits",
"Time dependent changes in min_dt and max_dt limits.")
61 "The start time of dt step set.")
63 "Soft lower limit for the time step.")
65 "Whole time of the simulation if specified, infinity else.")
68 return Record(
"TimeGovernor",
69 "Setting of the simulation time (can be specific to one equation).\n" 70 "TimeGovernor allows to:\n" 71 " - define start time and end time of simulation\n" 72 " - define lower and upper limits of time steps\n" 73 " - direct fixed time marks of whole simulation\n" 74 " - set global time unit of equation (see 'common_time_unit' key)\n" 75 "Limits of time steps are defined by keys 'min_dt', 'max_dt', 'init_dt' and 'dt_limits'. Key " 76 "'init_dt' has the highest priority and allows set fix size of time steps. Pair of keys 'min_dt' " 77 "and 'max_dt' define interval of time steps. Both previous cases ('init_dt' or pair 'min_dt' " 78 "and 'max_dt') set global limits of whole simulation. In contrasts, 'dt_limits' allow set " 79 "time-dependent function of min_dt/max_dt. Used time steps of simulation can be printed to YAML " 80 "output file (see 'write_used_timesteps'.\n" 81 "Fixed time marks define exact values of time steps. They are defined in:\n" 82 " - start time and end time of simulation\n" 83 " - output times printed to output mesh file\n" 84 " - times defined in 'dt_limits' table (optional, see 'add_dt_limits_time_marks' key)")
87 "Start time of the simulation.")
89 "End time of the simulation. Default value is more then age of universe in seconds.")
91 "Initial guess for the time step.\n" 92 "Only useful for equations that use adaptive time stepping." 93 "If set to 0.0, the time step is determined in fully autonomous" 94 " way if the equation supports it.")
97 "Soft lower limit for the time step. Equation using adaptive time stepping can not" 98 "suggest smaller time step, but actual time step could be smaller in order to match " 99 "prescribed input or output times.")
102 "Hard upper limit for the time step. Actual length of the time step is also limited" 103 "by input and output times.")
105 "Allow to set a time dependent changes in min_dt and max_dt limits. This list is processed " 106 "at individual times overwriting previous setting of min_dt/max_dt. Limits equal to 0 are " 107 "ignored and replaced with min_dt/max_dt values.")
108 .
declare_key(
"add_dt_limits_time_marks",
Bool(),
Default(
"false"),
"Add all times defined in 'dt_limits' " 109 "table to list of fixed TimeMarks.")
111 "Write used time steps to given file in YAML format corresponding with format of 'dt_limits'.")
113 "Common time unit of equation. This unit will be used for all time inputs and outputs " 114 "within the equation. On inputs can be overwrite for every time definition.\n" 115 "Time units are used in following cases:\n" 116 "1) Time units of time value keys in: TimeGovernor, FieldDescriptors.\n" 117 " Global definition of unit can be overwrite for every declared time.\n" 118 "2) Time units in: \n" 119 " a) input fields: FieldInterpolatedP0, FieldFE and FieldTimeFunction\n" 120 " b) time steps definition of OutputTimeSet\n" 121 " Global definition can be overwrite by one unit value for every whole mesh data file or time function.\n" 122 "3) Time units in output files: Observe times, balance times, frame times of VTK and GMSH\n" 123 " Global definition can't be overwritten.\n" 135 : unit_string_(user_defined_unit)
149 double time = time_it->val<
double>(
"time");
151 if (time_it->opt_val<
string>(
"unit", time_unit)) {
154 return ( time *
coef_ );
157 ASSERT(default_time!=std::numeric_limits<double>::quiet_NaN()).error(
"Undefined default time!");
182 time_unit_conversion_(time_unit_conversion)
229 - 16*numeric_limits<double>::epsilon()*(1.0+max(abs(t1),abs(t0)));
253 out <<
"time: " << t_step.
end() <<
"step: " << t_step.
length() << endl;
264 : timestep_output_(timestep_output)
271 string common_unit_string=input.
val<
string>(
"common_time_unit");
284 input.
opt_val(
"dt_limits", limits_array);
296 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input)
312 }
catch(ExcTimeGovernorMessage &exc) {
326 THROW(ExcTimeGovernorMessage() << EI_Message(
"Fixed time step smaller then machine precision. \n") );
376 if (init_time < 0.0) {
377 THROW(ExcTimeGovernorMessage()
378 << EI_Message(
"Start time has to be greater or equal to 0.0\n")
387 if (end_time < init_time) {
388 THROW(ExcTimeGovernorMessage() << EI_Message(
"End time must be greater than start time.\n") );
437 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' smaller than machine precision.\n") );
439 if (max_dt < min_dt) {
440 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' smaller than 'min_dt'.\n") );
443 bool first_step =
true;
444 if (dt_limits_list.
size())
457 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is lesser than start time of simulation " 461 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is in incorrect order " 466 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is greater than end time of simulation " 472 if (min == 0.0) min = min_dt;
474 if (max == 0.0) max = max_dt;
477 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' in 'dt_limits' smaller than machine precision.\n") );
480 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' in 'dt_limits' smaller than 'min_dt'.\n") );
577 THROW(ExcTimeGovernorMessage()
578 << EI_Message(
"Missing end time for making output grid required by key 'time_step' of the output stream.\n")
605 double full_step = fix_time_it->
time() -
t();
610 if (step_estimate ==
inf_time)
return step_estimate;
617 step_estimate = full_step / n_steps;
627 DebugOut().fmt(
"Time step estimate is below the lower constraint of time step. The difference is: {:.16f}.\n",
631 return step_estimate;
698 double prior_dt =
dt();
699 double new_upper_constraint = factor *
dt();
710 if (current_minus_new < 0)
712 THROW(ExcMessage() << EI_Message(
"Internal error."));
717 return dt() / prior_dt;
723 unsigned int back_idx;
725 back_idx =
static_cast<unsigned int>(-index-1);
727 back_idx =
static_cast<unsigned int>(
recent_steps_[0].index() - index);
730 THROW(ExcMissingTimeStep() << EI_Index(index) << EI_BackIndex(back_idx) << EI_HistorySize(
recent_steps_.size()));
740 static char buffer[1024];
741 #ifdef FLOW123D_DEBUG_MESSAGES 743 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}> " 744 "end_time: {} end_fixed_time: {} type: {:#x}\n",
748 MessageOut().fmt(
"Lower time step constraint [{}]: {} \nUpper time step constraint [{}]: {} \n",
753 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}>\n",
790 static char buffer[1024];
791 sprintf(buffer,
"\n%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>\n",
793 return (out << buffer);
void add_time_marks(double time, double dt, double end_time, TimeMark::Type type)
double init_time_
Initial time.
TimeMarks::iterator next(const TimeGovernor &tg, const TimeMark::Type &mask) const
double lower_constraint_
Lower constraint for the choice of the next time step.
Iterator over TimeMark objects in TimeMarks object (database of TimeMark objects).
double end_time() const
End time.
double reduce_timestep(double factor)
Force timestep reduction in particular in the case of failure of the non-linear solver.
bool is_time_step_fixed_
Flag that is set when the fixed step is set (lasts only one time step).
double read_coef(Input::Iterator< std::string > unit_it) const
boost::circular_buffer< TimeStep > recent_steps_
Circular buffer of recent time steps. Implicit size is 3.
static TimeMarks time_marks_
std::ofstream timesteps_output_
Handle for file for output time steps to YAML format.
double upper_constraint() const
#define MessageOut()
Macro defining 'message' record of log.
double coef_
Conversion coefficient of all time values within the equation.
double end_time_
End time of the simulation.
double fix_dt_until_mark()
Fixing time step until fixed time mark.
double convert_unit_from(std::string actual_unit) const
Convert and check user-defined unit.
int set_lower_constraint(double lower, std::string message)
Sets lower constraint for the next time step estimating.
std::vector< DtLimitRow > dt_limits_table_
Table of DT limits.
bool is_end() const
Returns true if the actual time is greater than or equal to the end time.
void next_time()
Proceed to the next time according to current estimated time step.
double read_coef(Input::Iterator< std::string > unit_it) const
void set_permanent_constraint()
Sets permanent constraints for actual time step.
double read_coef(Input::Iterator< std::string > unit_it) const
bool is_current(const TimeMark::Type &mask) const
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
const TimeStep & step(int index=-1) const
unsigned int dt_limits_pos_
Index to actual position of DT limits.
static const double max_end_time
Basic time management functionality for unsteady (and steady) solvers (class Equation).
static const Type none_type
Mark Type with all bits unset.
static TimeMarks & marks()
Basic time management class.
static const Type every_type
Mark Type with all bits set.
double estimate_dt() const
Estimate choice of next time step according to actual setting of constraints.
void view(const char *name="") const
Structure that stores one record of DT limit.
bool time_step_changed_
Flag is set if the time step has been changed (lasts only one time step).
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.
void open_stream(Stream &stream) const
double upper_constraint_
Upper constraint for the choice of the next time step.
TimeGovernor(const Input::Record &input, TimeMark::Type fixed_time_mask=TimeMark::none_type, bool timestep_output=true)
Constructor for unsteady solvers.
TimeMark::Type eq_mark_type_
TimeMark type of the equation.
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())
void add_time_marks_grid(double step, TimeMark::Type mark_type=TimeMark::none_type) const
std::string sprintf(CStringRef format, ArgList args)
static const double time_step_precision
TimeMark::Type equation_fixed_mark_type() const
TimeMark::Type equation_mark_type() const
bool timestep_output_
Special flag allows forbid output time steps during multiple initialization of TimeGovernor.
static const unsigned int size_of_recent_steps_
TimeMark::Type new_mark_type()
double last_lower_constraint_
Lower constraint used for choice of current time.
double lower_constraint() const
unsigned int index_
Index of the step is index if the end time. Zero time step is artificial.
This class is a collection of time marks to manage various events occurring during simulation time...
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
double end_of_fixed_dt_interval_
End of interval if fixed time step.
bool steady_
True if the time governor is used for steady problem.
TimeStep make_next(double new_length) const
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
Dedicated class for storing path to input and output files.
TimeMark add(const TimeMark &mark)
double max_time_step_
Permanent upper limit for the time step.
int set_upper_constraint(double upper, std::string message)
Sets upper constraint for the next time step estimating.
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 ...
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time) const
std::string get_unit_string() const
FilePath timesteps_output_file_
File path for timesteps_output_ stream.
bool safe_compare(double t1, double t0) const
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
bool limits_time_marks_
Allows add all times defined in dt_limits_table_ to list of TimeMarks.
double last_printed_timestep_
Store last printed time to YAML output, try multiplicity output of one time.
std::string upper_constraint_message_
Description of the upper constraint.
double time() const
Getter for the time of the TimeMark.
TimeMarks::iterator end(TimeMark::Type mask) const
Iterator for the end mimics container-like of TimeMarks.
static const Input::Type::Record & get_input_type()
#define WarningOut()
Macro defining 'warning' record of log.
TimeMarks::iterator current(const TimeStep &time_step, const TimeMark::Type &mask) const
Class used for marking specified times at which some events occur.
std::string unit_string_
String representation of global unit of all time values within the equation.
#define OLD_ASSERT_LE(a, b)
unsigned long int bitmap_
Class for representation SI units of Fields.
double fixed_time_step_
Next fixed time step.
double last_upper_constraint_
Upper constraint used for choice of current time.
ostream & operator<<(ostream &out, const TimeStep &t_step)
#define DebugOut()
Macro defining 'debug' record of log.
static const double inf_time
Infinity time used for steady case.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Representation of one time step..
double end_
End time point of the time step.
std::string lower_constraint_message_
Description of the upper constraint.
double min_time_step_
Permanent lower limit for the time step.