Flow123d  release_3.0.0-968-gc87a28e79
output_time_set.cc
Go to the documentation of this file.
1 /*
2  * output_time_set.cc
3  *
4  * Created on: Jul 11, 2016
5  * Author: jb
6  */
7 
8 #include "tools/time_marks.hh"
9 #include "input/input_type.hh"
10 #include "input/accessors.hh"
11 #include "io/output_time_set.hh"
12 #include "tools/time_governor.hh"
13 
14 namespace IT = Input::Type;
15 
16 
18 {
19  static const IT::Record &time_grid =
20  IT::Record("TimeGrid", "Equally spaced grid of time points.")
21  .allow_auto_conversion("begin")
22  .declare_key("begin", IT::Double(0.0),
23  IT::Default::read_time("The initial time of the associated equation."),
24  "The start time of the grid.")
26  "The step of the grid. If not specified, the grid consists of the single time given by the `begin` key.")
27  .declare_key("end", IT::Double(0.0),
28  IT::Default::read_time("The end time of the simulation."),
29  "The time greater or equal to the last time in the grid.")
30  .declare_key("time_unit", IT::String(), IT::Default::read_time("Common unit of TimeGovernor."),
31  "Definition of unit of all defined times (begin, step and end time).")
32  .close();
33  return IT::Array(time_grid);
34 }
35 
36 
38 {
39  read_from_input(in_array, tg, tg.equation_fixed_mark_type());
40 }
41 
43 {
44  double initial_time = tg.init_time();
45  double simulation_end_time = tg.end_time();
46 
47  for(auto it =in_array.begin<Input::Record>(); it != in_array.end(); ++it) {
48  double time_unit_coef = tg.read_coef(it->find<string>("time_unit"));
49  double t_begin = it->val<double>("begin", initial_time) * time_unit_coef;
50  double t_end = it->val<double>("end", simulation_end_time) * time_unit_coef;
51  double t_step;
52  if (! it->opt_val("step", t_step) ) {
53  t_end = t_begin;
54  t_step = 1.0;
55  } else {
56  t_step *= time_unit_coef;
57  }
58  if ( t_begin > t_end) {
59  WarningOut().fmt("Ignoring output time grid. Time begin {} > time end {}. {}",
60  t_begin, t_end, it->address_string());
61  continue;
62  }
63  if ( t_step < 2*numeric_limits<double>::epsilon()) {
64  WarningOut().fmt("Ignoring output time grid. Time step {} < two times machine epsilon {}. {}",
65  t_step, 2*numeric_limits<double>::epsilon(),it->address_string());
66  continue;
67  }
68 
69  this->add(t_begin, t_step, t_end, mark_type);
70  }
71 }
72 
73 
75  return times_.find( mark.time() ) != times_.end();
76 }
77 
78 
79 void OutputTimeSet::add(double time, TimeMark::Type mark_type)
80 {
81  TimeMark::Type output_mark_type = mark_type | TimeGovernor::marks().type_output();
82  auto mark = TimeMark(time, output_mark_type);
83  double mark_time = TimeGovernor::marks().add(mark).time();
84  times_.insert( mark_time );
85 }
86 
87 
88 
89 void OutputTimeSet::add(double begin, double step, double end, TimeMark::Type mark_type)
90 {
91  //DebugOut().fmt("set add: {} {} {} {}\n", begin, step, end, mark_type);
92  ASSERT_GE( step, 2*numeric_limits<double>::epsilon());
93  ASSERT_LE( begin, end);
95  TimeMark::Type output_mark_type = mark_type | TimeGovernor::marks().type_output();
96 
97  double n_steps_dbl=((end - begin) / step + TimeGovernor::time_step_precision);
98  if (n_steps_dbl > 1.0e+6) {
99  WarningOut().fmt("Output step: {} to small, fixing number of output steps to 1e6.", step);
100  n_steps_dbl=1e6;
101  step = (end - begin)/n_steps_dbl;
102  }
103  unsigned int n_steps = (unsigned int)n_steps_dbl;
104  for(unsigned int i = 0; i <= n_steps; i++) {
105  auto mark = TimeMark(begin + i * step, output_mark_type);
106  double time = TimeGovernor::marks().add(mark).time();
107  times_.insert( time );
108  //DebugOut().fmt("add time: {} size: {}\n", time, times_.size());
109  }
110 }
time_governor.hh
Basic time management class.
TimeGovernor::end_time
double end_time() const
End time.
Definition: time_governor.hh:568
TimeGovernor::equation_fixed_mark_type
TimeMark::Type equation_fixed_mark_type() const
Definition: time_governor.hh:458
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
OutputTimeSet::add
void add(double begin, TimeMark::Type mark_type)
Definition: output_time_set.cc:79
Input::Type::Default::read_time
static Default read_time(const std::string &description)
The factory function to make an default value that will be specified at the time when a key will be r...
Definition: type_record.hh:97
OutputTimeSet::contains
bool contains(TimeMark mark) const
Definition: output_time_set.cc:74
Input::Array::begin
Iterator< ValueType > begin() const
Definition: accessors_impl.hh:145
TimeMark
Class used for marking specified times at which some events occur.
Definition: time_marks.hh:45
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
TimeGovernor::time_step_precision
static const double time_step_precision
Definition: time_governor.hh:627
Input::Type::Record::allow_auto_conversion
virtual Record & allow_auto_conversion(const string &from_key)
Allows shorter input of the Record providing only value of the from_key given as the parameter.
Definition: type_record.cc:132
accessors.hh
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:294
TimeMark::Type
Definition: time_marks.hh:60
Input::Type::Record::declare_key
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:501
output_time_set.hh
TimeMarks::add
TimeMark add(const TimeMark &mark)
Definition: time_marks.cc:81
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:303
OutputTimeSet::read_from_input
void read_from_input(Input::Array in_array, const TimeGovernor &tg)
Definition: output_time_set.cc:37
Input::Type
Definition: balance.hh:38
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
input_type.hh
OutputTimeSet::get_input_type
static const Input::Type::Array get_input_type()
Definition: output_time_set.cc:17
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
TimeGovernor::marks
static TimeMarks & marks()
Definition: time_governor.hh:315
Input::Type::String
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
ASSERT_GE
#define ASSERT_GE(a, b)
Definition of comparative assert macro (Greater or Equal)
Definition: asserts.hh:319
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:246
ASSERT_LE
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal)
Definition: asserts.hh:303
TimeGovernor::inf_time
static const double inf_time
Infinity time used for steady case.
Definition: time_governor.hh:621
TimeGovernor::read_coef
double read_coef(Input::Iterator< std::string > unit_it) const
Definition: time_governor.cc:773
time_marks.hh
OutputTimeSet::times_
std::set< double > times_
Definition: output_time_set.hh:51
TimeMark::time
double time() const
Getter for the time of the TimeMark.
Definition: time_marks.hh:115
TimeMarks::type_output
TimeMark::Type type_output()
Definition: time_marks.hh:239
Input::Type::Default::optional
static Default optional()
The factory function to make an empty default value which is optional.
Definition: type_record.hh:124
TimeGovernor::init_time
double init_time() const
Definition: time_governor.hh:513
Input::Array::end
IteratorBase end() const
Definition: accessors_impl.hh:157