33 using namespace Input::Type;
40 return Record(
"TimeGovernor",
41 "Setting of the simulation time. (can be specific to one equation)")
44 "Start time of the simulation.")
46 "End time of the simulation.")
48 "Initial guess for the time step.\n"
49 "Only useful for equations that use adaptive time stepping."
50 "If set to 0.0, the time step is determined in fully autonomous"
51 " way if the equation supports it.")
54 "Soft lower limit for the time step. Equation using adaptive time stepping can not"
55 "suggest smaller time step, but actual time step could be smaller in order to match "
56 "prescribed input or output times.")
59 "Hard upper limit for the time step. Actual length of the time step is also limited"
60 "by input and output times.")
85 length_(other.length_),
118 out <<
"time: " << t_step.
end() <<
"step: " << t_step.
length() << endl;
138 double init_dt=input.
val<
double>(
"init_dt");
149 }
catch(ExcTimeGovernorMessage &exc) {
161 THROW(ExcTimeGovernorMessage() << EI_Message(
"Fixed time step smaller then machine precision. \n") );
194 if (init_time < 0.0) {
195 THROW(ExcTimeGovernorMessage()
196 << EI_Message(
"Start time has to be greater or equal to 0.0\n")
205 if (end_time < init_time) {
206 THROW(ExcTimeGovernorMessage() << EI_Message(
"End time must be greater than start time.\n") );
259 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' smaller then machine precision.\n") );
261 if (max_dt < min_dt) {
262 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' smaller then 'min_dt'.\n") );
335 THROW(ExcTimeGovernorMessage()
336 << EI_Message(
"Missing end time for making output grid required by key 'time_step' of the output stream.\n")
363 double full_step = fix_time_it->
time() -
t();
368 if (step_estimate ==
inf_time)
return step_estimate;
375 step_estimate = full_step / n_steps;
385 static char buffer[1024];
386 sprintf(buffer,
"Time step estimate is below the lower constraint of time step. The difference is: %.16f.\n",
391 return step_estimate;
446 double prior_dt =
dt();
447 double new_upper_constraint = factor *
dt();
458 if (current_minus_new < 0)
460 THROW(ExcMessage() << EI_Message(
"Internal error."));
465 return dt() / prior_dt;
471 unsigned int back_idx;
473 back_idx =
static_cast<unsigned int>(-index-1);
475 back_idx =
static_cast<unsigned int>(
recent_steps_[0].index() - index);
478 THROW(ExcMissingTimeStep() << EI_Index(index) << EI_BackIndex(back_idx) << EI_HistorySize(
recent_steps_.size()));
488 static char buffer[1024];
489 #ifdef FLOW123D_DEBUG_MESSAGES
490 sprintf(buffer,
"TG[%s]:%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f> end_time: %f end_fixed_time: %f type: 0x%x\n",
493 sprintf(buffer,
"TG[%s]:%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>\n",
497 MessageOut().fmt(
"Lower time step constraint [{}]: {} \nUpper time step constraint [{}]: {} \n",
507 static char buffer[1024];
508 sprintf(buffer,
"\n%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>\n",
510 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).
boost::circular_buffer< TimeStep > recent_steps_
Circular buffer of recent time steps. Implicit size is 3.
static TimeMarks time_marks_
double upper_constraint() const
TimeGovernor(const Input::Record &input, TimeMark::Type fixed_time_mask=TimeMark::none_type)
Constructor for unsteady solvers.
#define MessageOut()
Macro defining 'message' record of log.
double end_time_
End time of the simulation.
double fix_dt_until_mark()
Fixing time step until fixed time mark.
int set_lower_constraint(double lower, std::string message)
Sets lower constraint for the next time step estimating.
void set_permanent_constraint(double min_dt, double max_dt)
Sets permanent constraints for time step.
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.
bool is_current(const TimeMark::Type &mask) const
const TimeStep & step(int index=-1) const
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.
double estimate_dt() const
Estimate choice of next time step according to actual setting of constraints.
void view(const char *name="") const
bool time_step_changed_
Flag is set if the time step has been changed (lasts only one time step).
double upper_constraint_
Upper constraint for the choice of the next time step.
TimeMark::Type eq_mark_type_
TimeMark type of the equation.
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
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 end_of_fixed_dt_interval_
End of interval if fixed time step.
bool steady_
True if the time governor is used for steady problem.
STREAM & operator<<(STREAM &s, UpdateFlags u)
TimeStep make_next(double new_length) const
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 ...
bool safe_compare(double t1, double t0) const
std::string upper_constraint_message_
Description of the upper constraint.
double time() const
Getter for the time of the TimeMark.
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.
TimeMarks::iterator end(TimeMark::Type mask=TimeMark::every_type) const
Iterator for the end mimics container-like of TimeMarks.
#define OLD_ASSERT_LE(a, b)
double fixed_time_step_
Next fixed time step.
double last_upper_constraint_
Upper constraint used for choice of current time.
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.