Flow123d  3.9.0-895a22dee
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")
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.")
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  .close();
31  return IT::Array(time_grid);
32 }
33 
34 
36 {
37  read_from_input(in_array, tg, tg.equation_fixed_mark_type());
38 }
39 
41 {
42  double initial_time = tg.init_time();
43  double simulation_end_time = tg.end_time();
44 
45  for(auto it =in_array.begin<Input::Record>(); it != in_array.end(); ++it) {
46  double t_begin = tg.read_time(it->find<Input::Tuple>("begin"), initial_time);
47  double t_end = tg.read_time(it->find<Input::Tuple>("end"), simulation_end_time);
48  Input::Tuple step;
49  double t_step;
50  if (! it->opt_val("step", step) ) {
51  t_end = t_begin;
52  t_step = tg.get_coef();
53  } else {
54  t_step = tg.read_time(it->find<Input::Tuple>("step"));
55  }
56  if ( t_begin > t_end) {
57  WarningOut().fmt("Ignoring output time grid. Time begin {} > time end {}. {}",
58  t_begin, t_end, it->address_string());
59  continue;
60  }
61  if ( t_step < 2*numeric_limits<double>::epsilon()) {
62  WarningOut().fmt("Ignoring output time grid. Time step {} < two times machine epsilon {}. {}",
63  t_step, 2*numeric_limits<double>::epsilon(),it->address_string());
64  continue;
65  }
66 
67  this->add(t_begin, t_step, t_end, mark_type);
68  }
69 }
70 
71 
73  return times_.find( mark.time() ) != times_.end();
74 }
75 
76 
77 void OutputTimeSet::add(double time, TimeMark::Type mark_type)
78 {
79  TimeMark::Type output_mark_type = mark_type | TimeGovernor::marks().type_output();
80  auto mark = TimeMark(time, output_mark_type);
81  double mark_time = TimeGovernor::marks().add(mark).time();
82  times_.insert( mark_time );
83 }
84 
85 
86 
87 void OutputTimeSet::add(double begin, double step, double end, TimeMark::Type mark_type)
88 {
89  //DebugOut().fmt("set add: {} {} {} {}\n", begin, step, end, mark_type);
90  ASSERT_GE( step, 2*numeric_limits<double>::epsilon());
91  ASSERT_LE( begin, end);
93  TimeMark::Type output_mark_type = mark_type | TimeGovernor::marks().type_output();
94 
95  double n_steps_dbl=((end - begin) / step + TimeGovernor::time_step_precision);
96  if (n_steps_dbl > 1.0e+6) {
97  WarningOut().fmt("Output step: {} to small, fixing number of output steps to 1e6.", step);
98  n_steps_dbl=1e6;
99  step = (end - begin)/n_steps_dbl;
100  }
101  unsigned int n_steps = (unsigned int)n_steps_dbl;
102  for(unsigned int i = 0; i <= n_steps; i++) {
103  auto mark = TimeMark(begin + i * step, output_mark_type);
104  double time = TimeGovernor::marks().add(mark).time();
105  times_.insert( time );
106  //DebugOut().fmt("add time: {} size: {}\n", time, times_.size());
107  }
108 }
time_governor.hh
Basic time management class.
TimeGovernor::end_time
double end_time() const
End time.
Definition: time_governor.hh:591
TimeGovernor::equation_fixed_mark_type
TimeMark::Type equation_fixed_mark_type() const
Definition: time_governor.hh:481
OutputTimeSet::add
void add(double begin, TimeMark::Type mark_type)
Definition: output_time_set.cc:77
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:72
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:651
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:133
accessors.hh
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:317
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:503
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:304
OutputTimeSet::read_from_input
void read_from_input(Input::Array in_array, const TimeGovernor &tg)
Definition: output_time_set.cc:35
Input::Type
Definition: balance.hh:41
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
TimeGovernor::read_time
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
Definition: time_governor.cc:793
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
TimeGovernor::marks
static TimeMarks & marks()
Definition: time_governor.hh:338
ASSERT_GE
#define ASSERT_GE(a, b)
Definition of comparative assert macro (Greater or Equal) only for debug mode.
Definition: asserts.hh:325
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
TimeGovernor::get_coef
double get_coef() const
Definition: time_governor.cc:805
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
Input::Tuple
Accessor to the data with type Type::Tuple.
Definition: accessors.hh:411
ASSERT_LE
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal) only for debug mode.
Definition: asserts.hh:309
TimeGovernor::inf_time
static const double inf_time
Infinity time used for steady case.
Definition: time_governor.hh:645
TimeGovernor::get_input_time_type
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())
Definition: time_governor.cc:47
time_marks.hh
OutputTimeSet::times_
std::set< double > times_
Definition: output_time_set.hh:52
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:536
Input::Array::end
IteratorBase end() const
Definition: accessors_impl.hh:157