Flow123d  release_2.2.0-19-g1279b7e
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), IT::Default::read_time("The initial time of the associated equation."),
23  "The start time of the grid.")
25  "The step of the grid. If not specified, the grid consists only of the start time.")
26  .declare_key("end", IT::Double(0.0), IT::Default::read_time("The end time of the simulation."),
27  "The time greater or equal to the last time in the grid.")
28  .close();
29  return IT::Array(time_grid);
30 }
31 
32 
34 {
35  read_from_input(in_array, tg, tg.equation_fixed_mark_type());
36 }
37 
39 {
40  double initial_time = tg.init_time();
41  double simulation_end_time = tg.end_time();
42 
43  for(auto it =in_array.begin<Input::Record>(); it != in_array.end(); ++it) {
44  double t_begin = it->val<double>("begin", initial_time);
45  double t_end = it->val<double>("end", simulation_end_time );
46  double t_step;
47  if (! it->opt_val("step", t_step) ) {
48  t_end = t_begin;
49  t_step = 1.0;
50  }
51  if ( t_begin > t_end) {
52  WarningOut().fmt("Ignoring output time grid. Time begin {} > time end {}. {}",
53  t_begin, t_end, it->address_string());
54  continue;
55  }
56  if ( t_step < 2*numeric_limits<double>::epsilon()) {
57  WarningOut().fmt("Ignoring output time grid. Time step {} < two times machine epsilon {}. {}",
58  t_step, 2*numeric_limits<double>::epsilon(),it->address_string());
59  continue;
60  }
61 
62  this->add(t_begin, t_step, t_end, mark_type);
63  }
64 }
65 
66 
68  return times_.find( mark.time() ) != times_.end();
69 }
70 
71 
72 void OutputTimeSet::add(double time, TimeMark::Type mark_type)
73 {
74  TimeMark::Type output_mark_type = mark_type | TimeGovernor::marks().type_output();
75  auto mark = TimeMark(time, output_mark_type);
76  double mark_time = TimeGovernor::marks().add(mark).time();
77  times_.insert( mark_time );
78 }
79 
80 
81 
82 void OutputTimeSet::add(double begin, double step, double end, TimeMark::Type mark_type)
83 {
84  //DebugOut().fmt("set add: {} {} {} {}\n", begin, step, end, mark_type);
86  ASSERT_LE( begin, end);
88  TimeMark::Type output_mark_type = mark_type | TimeGovernor::marks().type_output();
89 
90  double n_steps_dbl=((end - begin) / step + TimeGovernor::time_step_precision);
91  if (n_steps_dbl > 1.0e+6) {
92  WarningOut().fmt("Output step: {} to small, fixing number of output steps to 1e6.", step);
93  n_steps_dbl=1e6;
94  step = (end - begin)/n_steps_dbl;
95  }
96  unsigned int n_steps = (unsigned int)n_steps_dbl;
97  for(unsigned int i = 0; i <= n_steps; i++) {
98  auto mark = TimeMark(begin + i * step, output_mark_type);
99  double time = TimeGovernor::marks().add(mark).time();
100  times_.insert( time );
101  //DebugOut().fmt("add time: {} size: {}\n", time, times_.size());
102  }
103 }
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
TimeMark::Type type_output()
Definition: time_marks.hh:230
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:345
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:540
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:490
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
const double epsilon
Definition: mathfce.h:23
static const Input::Type::Array get_input_type()
double time() const
Getter for the time of the TimeMark.
Definition: time_marks.hh:106
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:236
Class used for marking specified times at which some events occur.
Definition: time_marks.hh:36
Record type proxy class.
Definition: type_record.hh:182
static const double inf_time
Infinity time used for steady case.
void add(double begin, TimeMark::Type mark_type)