Flow123d
JB_transport-112d700
|
Go to the documentation of this file.
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!");
208 time_unit_conversion_(time_unit_conversion)
227 index_(other.index_),
228 length_(other.length_),
230 time_unit_conversion_(other.time_unit_conversion_)
257 - 16*numeric_limits<double>::epsilon()*(1.0+max(abs(t1),abs(t0)));
286 out <<
"time: " << t_step.
end() <<
" dt: " << t_step.
length() << endl;
297 : timestep_output_(timestep_output)
318 input.
opt_val(
"dt_limits", limits_array);
330 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input)
346 }
catch(ExcTimeGovernorMessage &exc) {
354 : dt_limits_pos_(0), timestep_output_(false)
360 THROW(ExcTimeGovernorMessage() << EI_Message(
"Fixed time step smaller then machine precision. \n") );
382 : dt_limits_pos_(0), timestep_output_(false)
411 THROW(ExcTimeGovernorMessage()
412 << EI_Message(
"Start time has to be greater or equal to 0.0\n")
422 THROW(ExcTimeGovernorMessage() << EI_Message(
"End time must be greater than start time.\n") );
471 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' smaller than machine precision.\n") );
473 if (max_dt < min_dt) {
474 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' smaller than 'min_dt'.\n") );
477 bool first_step =
true;
478 if (dt_limits_list.
size())
491 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is lesser than start time of simulation "
495 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is in incorrect order "
500 WarningOut().fmt(
"Time {} define in 'dt_limits' table at address {} is greater than end time of simulation "
506 if (min == 0.0) min = min_dt;
508 if (max == 0.0) max = max_dt;
511 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' in 'dt_limits' smaller than machine precision.\n") );
514 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' in 'dt_limits' smaller than 'min_dt'.\n") );
611 THROW(ExcTimeGovernorMessage()
612 << EI_Message(
"Missing end time for making output grid required by key 'time_step' of the output stream.\n")
639 double full_step = fix_time_it->
time() -
t();
644 if (step_estimate ==
inf_time)
return step_estimate;
651 step_estimate = full_step / n_steps;
661 DebugOut().fmt(
"Time step estimate is below the lower constraint of time step. The difference is: {:.16f}.\n",
665 return step_estimate;
732 double prior_dt =
dt();
733 double new_upper_constraint = factor *
dt();
744 if (current_minus_new < 0)
746 THROW(ExcMessage() << EI_Message(
"Internal error."));
751 return dt() / prior_dt;
757 unsigned int back_idx;
759 back_idx =
static_cast<unsigned int>(-index-1);
761 back_idx =
static_cast<unsigned int>(
recent_steps_[0].index() - index);
764 THROW(ExcMissingTimeStep() << EI_Index(index) << EI_BackIndex(back_idx) << EI_HistorySize(
recent_steps_.size()));
774 #ifdef FLOW123D_DEBUG_MESSAGES
776 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}> "
777 "end_time: {} end_fixed_time: {} type: {:#x}\n",
781 MessageOut().fmt(
"Lower time step constraint [{}]: {} \nUpper time step constraint [{}]: {} \n",
786 "TG[{}]:{:06d} t:{:10.4f} dt:{:10.6f} dt_int<{:10.6f},{:10.6f}>\n",
818 static char buffer[1024];
819 sprintf(buffer,
"\n%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>\n",
821 return (out << buffer);
double read_coef(Input::Iterator< Input::Record > unit_it) const
unsigned long int bitmap_
void add_time_marks_grid(double step, TimeMark::Type mark_type=TimeMark::none_type) const
bool safe_compare(double t1, double t0) const
double read_unit_coef_from_input(const Input::Record &input) const
Reads the Unit record and computes the coef.
TimeMarks::iterator next(const TimeGovernor &tg, const TimeMark::Type &mask) const
TimeMarks::iterator current(const TimeStep &time_step, const TimeMark::Type &mask) const
TimeMark::Type new_mark_type()
double last_printed_timestep_
Store last printed time to YAML output, try multiplicity output of one time.
static Input::Type::Default get_input_default()
void set_permanent_constraint()
Sets permanent constraints for actual time step.
Basic time management class.
double end_time() const
End time.
unsigned int dt_limits_pos_
Index to actual position of DT limits.
std::string upper_constraint_message_
Description of the upper constraint.
std::shared_ptr< TimeUnitConversion > get_unit_conversion() const
Getter for time unit conversion object.
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time) const
double init_time_
Initial time.
double fixed_time_step_
Next fixed 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 equation_fixed_mark_type() const
int set_upper_constraint(double upper, std::string message)
Sets upper constraint for the next time step estimating.
double end_of_fixed_dt_interval_
End of interval if fixed time step.
static const unsigned int size_of_recent_steps_
std::shared_ptr< TimeUnitConversion > get_unit_conversion() const
Getter for time unit conversion object.
Dedicated class for storing path to input and output files.
boost::circular_buffer< TimeStep > recent_steps_
Circular buffer of recent time steps. Implicit size is 3.
double upper_constraint_
Upper constraint for the choice of the next time step.
static TimeMarks time_marks_
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
TimeMarks::iterator end(TimeMark::Type mask) const
Iterator for the end mimics container-like of TimeMarks.
std::string sprintf(CStringRef format, ArgList args)
double read_coef(Input::Iterator< Input::Record > unit_it) const
double convert_unit_from(std::string actual_unit) const
Convert and check user-defined unit.
double min_time_step_
Permanent lower limit for the time step.
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
bool steady_
True if the time governor is used for steady problem.
void open_stream(Stream &stream) const
int set_lower_constraint(double lower, std::string message)
Sets lower constraint for the next time step estimating.
std::string unit_string_
String representation of global unit of all time values within the equation.
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 last_lower_constraint_
Lower constraint used for choice of current time.
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 ...
bool is_end() const
Returns true if the actual time is greater than or equal to the end time.
std::string lower_constraint_message_
Description of the upper constraint.
double last_upper_constraint_
Upper constraint used for choice of current time.
bool timestep_output_
Special flag allows forbid output time steps during multiple initialization of TimeGovernor.
Class used for marking specified times at which some events occur.
bool limits_time_marks_
Allows add all times defined in dt_limits_table_ to list of TimeMarks.
static const double time_step_precision
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
double upper_constraint() const
double end_time_
End time of the simulation.
double reduce_timestep(double factor)
Force timestep reduction in particular in the case of failure of the non-linear solver.
Representation of one time step..
Basic time management functionality for unsteady (and steady) solvers (class Equation).
const TimeStep & step(int index=-1) const
Structure that stores one record of DT limit.
Class for representation SI units of Fields.
double read_coef(Input::Iterator< Input::Record > unit_it) const
static const Type every_type
Mark Type with all bits set.
double end_
End time point of the time step.
double coef_
Conversion coefficient of all time values within the equation.
double estimate_dt() const
Estimate choice of next time step according to actual setting of constraints.
TimeMark add(const TimeMark &mark)
static const Input::Type::Record & get_input_type()
void view(const char *name="") const
static const Input::Type::Record & get_input_type()
double lower_constraint_
Lower constraint for the choice of the next time step.
static const Type none_type
Mark Type with all bits unset.
TimeStep make_next(double new_length) 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.
std::vector< DtLimitRow > dt_limits_table_
Table of DT limits.
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
static TimeMarks & marks()
std::ofstream timesteps_output_
Handle for file for output time steps to YAML format.
#define WarningOut()
Macro defining 'warning' record of log.
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal) only for debug mode.
std::shared_ptr< TimeUnitConversion > time_unit_conversion_
Conversion unit of all time values within the equation.
static const double inf_time
Infinity time used for steady case.
TimeMark::Type equation_mark_type() const
double max_time_step_
Permanent upper limit for the time step.
static const double max_end_time
FilePath timesteps_output_file_
File path for timesteps_output_ stream.
bool is_current(const TimeMark::Type &mask) 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 time() const
Getter for the time of the TimeMark.
void add_time_marks(double time, double dt, double end_time, TimeMark::Type type)
double lower_constraint() const
#define DebugOut()
Macro defining 'debug' record of log.
void next_time()
Proceed to the next time according to current estimated time step.
bool time_step_changed_
Flag is set if the time step has been changed (lasts only one time step).
double fix_dt_until_mark()
Fixing time step until fixed time mark.
Iterator over TimeMark objects in TimeMarks object (database of TimeMark objects).
TimeMark::Type eq_mark_type_
TimeMark type of the equation.
ostream & operator<<(ostream &out, const TimeStep &t_step)
bool is_time_step_fixed_
Flag that is set when the fixed step is set (lasts only one time step).
#define MessageOut()
Macro defining 'message' record of log.