48 using namespace Input::Type;
55 "Setting of the simulation time. (can be specific to one equation)")
58 "Start time of the simulation.")
60 "End time of the simulation.")
62 "Initial guess for the time step.\n"
63 "The time step is fixed if the hard time step limits are not set.\n"
64 "If set to 0.0, the time step is determined in fully autonomous way if the equation supports it.")
66 "Hard lower limit for the time step.")
68 "Hard upper limit for the time step.");
82 if (input.
opt_val<
double>(
"end_time", end_time_))
88 init_common(input.
val<
double>(
"init_dt"),
89 input.
val<
double>(
"start_time"),
94 set_permanent_constraint(
95 input.
val<
double>(
"min_dt", min_time_step_),
96 input.
val<
double>(
"max_dt", max_time_step_)
98 }
catch(ExcTimeGovernorMessage &exc) {
117 init_common(0.0, init_time, inf_time, eq_mark_type);
128 if (init_time < 0.0) {
129 THROW(ExcTimeGovernorMessage()
130 << EI_Message(
"Start time has to be greater or equal to 0.0\n")
135 init_time_ = time_ = init_time;
136 last_time_ = -inf_time;
137 last_time_step_ = inf_time;
140 if (end_time < init_time) {
141 THROW(ExcTimeGovernorMessage() << EI_Message(
"End time must be greater than start time.\n") );
144 end_time_ = end_time;
148 fixed_time_step_=0.0;
149 is_time_step_fixed_=
false;
150 time_step_changed_=
true;
151 end_of_fixed_dt_interval_ = time_;
153 min_time_step_=lower_constraint_=time_step_lower_bound;
154 if (end_time_ == inf_time) {
155 max_time_step_=upper_constraint_=inf_time;
157 max_time_step_=upper_constraint_= end_time - time_;
160 time_step_=max_time_step_;
163 if (dt < time_step_lower_bound)
164 xprintf(
UsrErr,
"Fixed time step small then machine precision. \n");
167 is_time_step_fixed_=
true;
168 time_step_changed_=
true;
169 end_of_fixed_dt_interval_ = inf_time;
171 upper_constraint_=max_time_step_=dt;
172 lower_constraint_=min_time_step_=dt;
179 time_marks_->add(
TimeMark(time_, equation_fixed_mark_type()) );
180 if (end_time_ != inf_time)
181 time_marks_->add(
TimeMark(end_time_, equation_fixed_mark_type()) );
191 if (min_dt < time_step_lower_bound) {
192 THROW(ExcTimeGovernorMessage() << EI_Message(
"'min_dt' smaller then machine precision.\n") );
194 if (max_dt < min_dt) {
195 THROW(ExcTimeGovernorMessage() << EI_Message(
"'max_dt' smaller then 'min_dt'.\n") );
198 lower_constraint_ = min_time_step_ = max(min_dt, time_step_lower_bound);
199 upper_constraint_ = max_time_step_ = min(max_dt, end_time_-time_);
211 if (upper_constraint_ < upper)
217 if (lower_constraint_ <= upper)
220 upper_constraint_ = upper;
224 if (lower_constraint_ > upper)
235 if (upper_constraint_ < lower)
241 if (min_time_step_ <= lower)
244 lower_constraint_ = lower;
248 if (min_time_step_ > lower)
261 if (end_time() == inf_time) {
262 THROW(ExcTimeGovernorMessage()
263 << EI_Message(
"Missing end time for make output grid required by key 'time_step' of the output stream.\n")
267 marks().add_time_marks(init_time_, step, end_time(), mark_type | eq_mark_type_);
269 marks().add(
TimeMark(init_time_, mark_type | eq_mark_type_));
270 marks().add(
TimeMark(end_time(), mark_type | eq_mark_type_));
276 if (time_ == inf_time || is_end())
return 0.0;
277 if (time_marks_ == NULL)
return inf_time;
283 if (this->lt(end_of_fixed_dt_interval_))
return fixed_time_step_;
288 double full_step = fix_time_it->
time() - time_;
290 double step_estimate = min(full_step, upper_constraint_);
291 step_estimate = max(step_estimate, lower_constraint_);
293 if (step_estimate == inf_time)
return step_estimate;
297 int n_steps = ceil( full_step / step_estimate );
302 int n_floor_steps = floor(full_step / step_estimate);
303 if ( abs(full_step / step_estimate - n_floor_steps) < round_n_steps_precision) n_steps = n_floor_steps;
305 step_estimate = full_step / n_steps;
310 if (step_estimate < lower_constraint_)
311 xprintf(
Warn,
"Time step estimate is below the lower constraint of time step. The difference is: %.16f.\n",
312 lower_constraint_ - step_estimate);
325 return step_estimate;
333 if (time_ == inf_time || is_end())
return;
346 if (this->lt(end_of_fixed_dt_interval_)) {
350 if (end_of_fixed_dt_interval_ < inf_time) {
351 fixed_time_step_ = (end_of_fixed_dt_interval_-time_) / round( (end_of_fixed_dt_interval_-time_) / fixed_time_step_ );
354 last_time_step_ = time_step_;
355 time_step_ = fixed_time_step_;
358 if (is_time_step_fixed_)
360 is_time_step_fixed_ =
false;
363 time_step_changed_ = (last_time_step_ != time_step_);
366 time_step_changed_ =
false;
371 last_time_step_ = time_step_;
372 time_step_ = estimate_dt();
373 time_step_changed_= (last_time_step_ != time_step_);
380 upper_constraint_ = min(end_time_ - time_, max_time_step_);
381 lower_constraint_ = min_time_step_;
393 xprintf(
Msg,
"\nTG[%s]:%06d t:%10.4f dt:%10.6f dt_int<%10.6f,%10.6f>",
394 name, time_level_, time_, time_step_, lower_constraint_, upper_constraint_ );
395 #ifdef DEBUG_MESSAGES
396 xprintf(
Msg,
" end_time: %f end_fixed_time: %f type: 0x%x\n" , end_time_, end_of_fixed_dt_interval_, eq_mark_type_);