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 "Time axis settings of the simulation.\n" 70 "The settings is specific to a particular equation.\n" 71 "TimeGovernor allows to:\n" 72 " - define start time and end time of simulation\n" 73 " - define lower and upper limits of time steps\n" 74 " - direct fixed time marks of whole simulation\n" 75 " - set global time unit of equation (see 'common_time_unit' key)\n" 76 "Limits of time steps are defined by keys 'min_dt', 'max_dt', 'init_dt' and 'dt_limits'. Key " 77 "'init_dt' has the highest priority and allows set fix size of time steps. Pair of keys 'min_dt' " 78 "and 'max_dt' define interval of time steps. Both previous cases ('init_dt' or pair 'min_dt' " 79 "and 'max_dt') set global limits of whole simulation. In contrasts, 'dt_limits' allow set " 80 "time-dependent function of min_dt/max_dt. Used time steps of simulation can be printed to YAML " 81 "output file (see 'write_used_timesteps'.\n" 82 "Fixed time marks define exact values of time steps. They are defined in:\n" 83 " - start time and end time of simulation\n" 84 " - output times printed to output mesh file\n" 85 " - times defined in 'dt_limits' table (optional, see 'add_dt_limits_time_marks' key)")
88 "Start time of the simulation.")
90 "End time of the simulation.\n" 91 "The default value is higher than the age of the Universe (given in seconds).")
93 "Initial guess for the time step.\n" 94 "It applies to equations that use an adaptive time stepping. " 95 "If set to 0.0, the time step is determined in fully autonomous " 96 "way, assuming the equation supports it.")
99 "Soft lower limit for the time step.\n" 100 "Equation using an adaptive time stepping cannot suggest smaller time step. " 101 "The actual time step can only decrease below the limit in order to match " 102 "the prescribed input or output times.")
105 "Hard upper limit for the time step.\n" 106 "The actual time step can only increase above the limit in order to match " 107 "the prescribed input or output times.")
109 "Allow to set a time dependent changes in ``min_dt`` and ``max_dt`` limits. This list is processed " 110 "at individual times overwriting previous values of ``min_dt``/``max_dt``. Limits equal to 0 are " 111 "ignored and replaced with ``min_dt``/``max_dt`` values.")
112 .
declare_key(
"add_dt_limits_time_marks",
Bool(),
Default(
"false"),
"Add all times defined in ``dt_limits`` " 113 "table to the list of fixed TimeMarks.")
115 "Write used time steps to the given file in YAML format corresponding with the format of ``dt_limits``.")
117 "Common time unit of the equation.\nThis unit will be used for all time inputs and outputs " 118 "within the equation. Individually, the common time unit can be overwritten for every declared time.\n" 119 "Time units are used in the following cases:\n" 120 "1) Time units of time value keys in: TimeGovernor, FieldDescriptors.\n" 121 " The common time unit can be overwritten for every declared time.\n" 122 "2) Time units in: \n" 123 " a) input fields: FieldFE and FieldTimeFunction\n" 124 " b) time steps definition of OutputTimeSet\n" 125 " Common time unit can be overwritten by one unit value for every whole mesh data file or time function.\n" 126 "3) Time units in output files: observation times, balance times, frame times of VTK and GMSH\n" 127 " Common time unit cannot be overwritten in these cases." 139 : unit_string_(user_defined_unit)
153 double time = time_it->val<
double>(
"time");
155 if (time_it->opt_val<
string>(
"unit", time_unit)) {
158 return ( time *
coef_ );
161 ASSERT(default_time!=std::numeric_limits<double>::quiet_NaN()).error(
"Undefined default time!");
186 time_unit_conversion_(time_unit_conversion)
233 - 16*numeric_limits<double>::epsilon()*(1.0+max(abs(t1),abs(t0)));
257 out <<
"time: " << t_step.
end() <<
"step: " << t_step.
length() << endl;
268 : timestep_output_(timestep_output)
275 string common_unit_string=input.
val<
string>(
"common_time_unit");
288 input.
opt_val(
"dt_limits", limits_array);
300 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input)
316 }
catch(ExcTimeGovernorMessage &exc) {
330 THROW(ExcTimeGovernorMessage() << EI_Message(
"Fixed time step smaller then machine precision. \n") );
380 if (init_time < 0.0) {
381 THROW(ExcTimeGovernorMessage()
382 << EI_Message(
"Start time has to be greater or equal to 0.0\n")
391 if (end_time < init_time) {
392 THROW(ExcTimeGovernorMessage() << EI_Message(
"End time must be greater than start time.\n") );
441 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' smaller than machine precision.\n") );
443 if (max_dt < min_dt) {
444 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' smaller than 'min_dt'.\n") );
447 bool first_step =
true;
448 if (dt_limits_list.
size())
461 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is lesser than start time of simulation " 465 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is in incorrect order " 470 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is greater than end time of simulation " 476 if (min == 0.0) min = min_dt;
478 if (max == 0.0) max = max_dt;
481 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' in 'dt_limits' smaller than machine precision.\n") );
484 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' in 'dt_limits' smaller than 'min_dt'.\n") );
581 THROW(ExcTimeGovernorMessage()
582 << EI_Message(
"Missing end time for making output grid required by key 'time_step' of the output stream.\n")
609 double full_step = fix_time_it->
time() -
t();
614 if (step_estimate ==
inf_time)
return step_estimate;
621 step_estimate = full_step / n_steps;
631 DebugOut().fmt(
"Time step estimate is below the lower constraint of time step. The difference is: {:.16f}.\n",
635 return step_estimate;
702 double prior_dt =
dt();
703 double new_upper_constraint = factor *
dt();
714 if (current_minus_new < 0)
716 THROW(ExcMessage() << EI_Message(
"Internal error."));
721 return dt() / prior_dt;
727 unsigned int back_idx;
729 back_idx =
static_cast<unsigned int>(-index-1);
731 back_idx =
static_cast<unsigned int>(
recent_steps_[0].index() - index);
734 THROW(ExcMissingTimeStep() << EI_Index(index) << EI_BackIndex(back_idx) << EI_HistorySize(
recent_steps_.size()));
744 static char buffer[1024];
745 #ifdef FLOW123D_DEBUG_MESSAGES 747 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}> " 748 "end_time: {} end_fixed_time: {} type: {:#x}\n",
752 MessageOut().fmt(
"Lower time step constraint [{}]: {} \nUpper time step constraint [{}]: {} \n",
757 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}>\n",
794 static char buffer[1024];
795 sprintf(buffer,
"\n%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>\n",
797 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.