Flow123d  jenkins-Flow123d-windows-release-multijob-285
output_time.hh
Go to the documentation of this file.
1 /*
2  * output_time.hh
3  *
4  * Created on: Mar 12, 2014
5  * Author: jb
6  */
7 
8 #ifndef OUTPUT_TIME_HH_
9 #define OUTPUT_TIME_HH_
10 
11 #include <vector>
12 #include <string>
13 #include <fstream>
14 #include "input/accessors.hh"
15 
16 class OutputDataBase;
17 class Mesh;
18 class FieldCommon; // in fact not necessary, output_data_by_field() can use directly name as parameter
19 template <int spacedim, class Value>
20 class Field;
21 template <int spacedim, class Value>
22 class MultiField;
23 class TimeGovernor;
24 
25 /**
26  * \brief The class for outputting data during time.
27  *
28  * This class is descendant of Output class. This class is used for outputting
29  * data varying in time. Own output to specific file formats is done at other
30  * places to. See output_vtk.cc and output_msh.cc.
31  */
32 class OutputTime {
33 
34 public:
35  /// Default constructor. Only for testing.
36  OutputTime();
37 
38 
39  /**
40  * \brief Constructor of OutputTime object. It opens base file for writing.
41  *
42  * \param[in] in_rec The reference on the input record
43  */
44  OutputTime(const Input::Record &in_rec);
45 
46  /**
47  * \brief Destructor of OutputTime. It doesn't do anything, because all
48  * necessary destructors will be called in destructor of Output
49  */
50  virtual ~OutputTime();
51 
52  /**
53  * \brief The specification of output stream
54  *
55  * \return This variable defines record for output stream
56  */
58 
59  /**
60  * \brief The specification of output file format
61  */
63 
64  /**
65  * Types of reference data
66  */
67  static const unsigned int N_DISCRETE_SPACES = 3;
69  NODE_DATA = 0,
72  };
73 
74  /**
75  * \brief This method delete all object instances of class OutputTime stored
76  * in output_streams vector
77  */
78  //static void destroy_all(void);
79 
80  /**
81  * \brief This method tries to create new instance of OutputTime according
82  * record in configuration file.
83  */
84  static OutputTime* create_output_stream(const Input::Record &in_rec);
85 
86  /**
87  * \brief Generic method for registering output data stored in MultiField
88  *
89  * @param ref_type Type of output (element, node, corner data).
90  * @param multi_field The actual field for output.
91  */
92  template<int spacedim, class Value>
93  void register_data(const DiscreteSpace type,
94  MultiField<spacedim, Value> &multi_field);
95 
96  /**
97  * \brief Generic method for registering of output data stored in Field
98  *
99  * @param ref_type Type of output (element, node, corner data).
100  * @param field The actual field for output.
101  */
102  template<int spacedim, class Value>
103  void register_data(const DiscreteSpace ref_type,
104  Field<spacedim, Value> &field);
105 
106  /**
107  * Write all data registered as a new time frame.
108  */
109  void write_time_frame();
110 
111  /**
112  * \brief Registers names of output fields that can be written using this stream.
113  * @param in_array Array of admissible fields (array of selections).
114  */
115  void add_admissible_field_names(const Input::Array &in_array);
116 
117  /**
118  * \brief Clear data for output computed by method @p compute_field_data.
119  */
120  void clear_data(void);
121 
122  /**
123  * Add time marks matching given @p tg.output_mark_type as well as general output type
124  * TimeMarks::type_output(). The time marks denotes times when output should be performed according
125  * to the input record of the output stream, namely keys: time_step, time_list, and include_input_times.
126  */
127  void mark_output_times(const TimeGovernor &tg);
128 
129  /**
130  * Declaration of new exception info used in following exception
131  */
132  TYPEDEF_ERR_INFO(EI_FieldName, std::string);
133 
134  /**
135  * Declaration of exception
136  */
137  DECLARE_EXCEPTION(ExcOutputVariableVector, << "Can not output field " << EI_FieldName::qval
138  << " returning variable size vectors. Try convert to MultiField.\n");
139 
140  /**
141  * Record for current output stream
142  */
144 
145 protected:
146 
147  /**
148  * Interpolate given @p field into output discrete @p space and store the values
149  * into private storage for postponed output.
150  */
151  template<int spacedim, class Value>
153 
154  /**
155  * Change main filename to have prescribed extension.
156  */
157  void fix_main_file_extension(std::string extension);
158 
159 
160  /**
161  * \brief Virtual method for writing data to output file
162  */
163  virtual int write_data(void) = 0;
164 
165  /**
166  * Cached MPI rank of process (is tested in methods)
167  */
168  int rank;
169 
170  /**
171  * Map field name to its OutputData object.
172  */
173  typedef std::shared_ptr<OutputDataBase> OutputDataPtr;
175 
176  /**
177  * Registered output data. Single map for every value of DiscreteSpace
178  * corresponding to nodes, elements and corners.
179  */
180  OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES];
181 
182  /**
183  * Current step
184  */
186 
187  /**
188  * The newest time of registered data
189  */
190  double time;
191 
192  /**
193  * The last time, when data was wrote to this stream
194  */
195  double write_time;
196 
197  /**
198  * Maps names of output fields required by user to their indices in
199  * output_data_vec_.
200  */
201  typedef unsigned int DiscreteSpaceFlags;
203 
204  /**
205  * Record for current output stream
206  */
208 
209  /**
210  * Base output stream
211  */
212  ofstream _base_file;
213 
214  /**
215  * Name of base output file
216  */
218 
219  /**
220  * Cached pointer at mesh used by this output stream
221  */
223 };
224 
225 
226 #endif /* OUTPUT_TIME_HH_ */
double time
Definition: output_time.hh:190
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:47
Mesh * _mesh
Definition: output_time.hh:222
Common parent class for templated OutputData.
static Input::Type::AbstractRecord input_format_type
The specification of output file format.
Definition: output_time.hh:62
Input::Record input_record_
Definition: output_time.hh:207
Accessor to input data conforming to declared Array.
Definition: accessors.hh:558
void fix_main_file_extension(std::string extension)
Definition: output_time.cc:110
static Input::Type::Record input_type
The specification of output stream.
Definition: output_time.hh:57
TYPEDEF_ERR_INFO(EI_FieldName, std::string)
DECLARE_EXCEPTION(ExcOutputVariableVector,<< "Can not output field "<< EI_FieldName::qval<< " returning variable size vectors. Try convert to MultiField.\n")
void add_admissible_field_names(const Input::Array &in_array)
Registers names of output fields that can be written using this stream.
Definition: output_time.cc:165
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:52
void register_data(const DiscreteSpace type, MultiField< spacedim, Value > &multi_field)
Generic method for registering output data stored in MultiField.
Definition: mesh.h:109
OutputTime()
Default constructor. Only for testing.
Definition: output_time.cc:66
Basic time management functionality for unsteady (and steady) solvers (class Equation).
std::map< std::string, DiscreteSpaceFlags > output_names
Definition: output_time.hh:202
unsigned int DiscreteSpaceFlags
Definition: output_time.hh:201
static OutputTime * create_output_stream(const Input::Record &in_rec)
This method delete all object instances of class OutputTime stored in output_streams vector...
Definition: output_time.cc:141
int current_step
Definition: output_time.hh:185
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
Class for declaration of polymorphic Record.
Definition: type_record.hh:487
static const unsigned int N_DISCRETE_SPACES
Definition: output_time.hh:67
Input::AbstractRecord format_record_
Definition: output_time.hh:143
virtual ~OutputTime()
Destructor of OutputTime. It doesn't do anything, because all necessary destructors will be called in...
Definition: output_time.cc:91
void clear_data(void)
Clear data for output computed by method compute_field_data.
Definition: output_time.cc:237
ofstream _base_file
Definition: output_time.hh:212
The class for outputting data during time.
Definition: output_time.hh:32
void mark_output_times(const TimeGovernor &tg)
Definition: output_time.cc:182
void compute_field_data(DiscreteSpace type, Field< spacedim, Value > &field)
string _base_filename
Definition: output_time.hh:217
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:448
void write_time_frame()
Definition: output_time.cc:215
virtual int write_data(void)=0
Virtual method for writing data to output file.
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
Definition: output_time.hh:180
std::shared_ptr< OutputDataBase > OutputDataPtr
Definition: output_time.hh:173
Record type proxy class.
Definition: type_record.hh:169
double write_time
Definition: output_time.hh:195
std::vector< OutputDataPtr > OutputDataFieldVec
Definition: output_time.hh:174
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:45