Flow123d  release_3.0.0-890-gfc7e296
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 }
Iterator< ValueType > begin() const
Accessor to input data conforming to declared Array.
Definition: accessors.hh:567
double end_time() const
End time.
#define ASSERT_GE(a, b)
Definition of comparative assert macro (Greater or Equal)
Definition: asserts.hh:319
double read_coef(Input::Iterator< std::string > unit_it) const
TimeMark::Type type_output()
Definition: time_marks.hh:239
void read_from_input(Input::Array in_array, const TimeGovernor &tg)
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal)
Definition: asserts.hh:303
bool contains(TimeMark mark) const
Basic time management functionality for unsteady (and steady) solvers (class Equation).
static TimeMarks & marks()
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:303
Basic time management class.
Class for declaration of inputs sequences.
Definition: type_base.hh:346
IteratorBase end() const
std::set< double > times_
static Default optional()
The factory function to make an empty default value which is optional.
Definition: type_record.hh:124
double init_time() const
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
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:541
static const double time_step_precision
TimeMark::Type equation_fixed_mark_type() const
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
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
TimeMark add(const TimeMark &mark)
Definition: time_marks.cc:81
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
static const Input::Type::Array get_input_type()
double time() const
Getter for the time of the TimeMark.
Definition: time_marks.hh:115
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:246
Class used for marking specified times at which some events occur.
Definition: time_marks.hh:45
Record type proxy class.
Definition: type_record.hh:182
Class for declaration of the input data that are in string format.
Definition: type_base.hh:589
static const double inf_time
Infinity time used for steady case.
void add(double begin, TimeMark::Type mark_type)