Flow123d  JS_before_hm-1576-g4d0b70e
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 }
Iterator< ValueType > begin() const
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
double end_time() const
End time.
#define ASSERT_GE(a, b)
Definition of comparative assert macro (Greater or Equal)
Definition: asserts.hh:320
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:304
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:304
Basic time management class.
Class for declaration of inputs sequences.
Definition: type_base.hh:339
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:133
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())
static const double time_step_precision
TimeMark::Type equation_fixed_mark_type() const
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
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
double read_time(Input::Iterator< Input::Tuple > time_it, double default_time=std::numeric_limits< double >::quiet_NaN()) const
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:270
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
Accessor to the data with type Type::Tuple.
Definition: accessors.hh:411
double get_coef() const
static const double inf_time
Infinity time used for steady case.
void add(double begin, TimeMark::Type mark_type)