Flow123d  jenkins-Flow123d-windows32-release-multijob-51
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 
15 //#include <mpi.h>
16 
17 #include "mesh/mesh.h"
18 #include "input/accessors.hh"
19 
20 
21 
22 class OutputDataBase;
23 class FieldCommon; // in fact not necessary, output_data_by_field() can use directly name as parameter
24 template <int spacedim, class Value>
25 class Field;
26 template <int spacedim, class Value>
27 class MultiField;
28 
29 
30 /**
31  * \brief The class for outputing data during time.
32  *
33  * This class is descendant of Output class. This class is used for outputing
34  * data varying in time. Own output to specific file formats is done at other
35  * places to. See output_vtk.cc and output_msh.cc.
36  */
37 class OutputTime {
38 
39 public:
40  TYPEDEF_ERR_INFO(EI_FieldName, std::string);
41  DECLARE_EXCEPTION(ExcOutputVariableVector, << "Can not output field " << EI_FieldName::qval
42  << " returning variable size vectors. Try convert to MultiField.\n");
43  /**
44  * Types of reference data
45  */
47  NODE_DATA = 0,
50  };
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  * \brief Try to find output stream from a key in record.
66  */
67  //static OutputTime *output_stream_by_key_name(const Input::Record &in_rec, const string key_name);
68 
69  /**
70  * \brief Try to find output stream with this name
71  */
72  //static OutputTime *output_stream_by_name(string name);
73 
74  /**
75  * \brief Does OutputStream with same name and filename exist?
76  *
77  * When this record is already created, then it returns pointer at
78  * corresponding OutputTime. When this record doesn't exist, then
79  * it create new OutputTime object and it puts this object to the
80  * array of OutputTime pointers
81  *
82  * \param[in] in_rec The reference at the input record
83  */
84  //static OutputTime *output_stream(const Input::Record &in_rec);
85 
86  /**
87  * \brief This method delete all object instances of class OutputTime stored
88  * in output_streams vector
89  */
90  static void destroy_all(void);
91 
92  /**
93  * \brief This method write all registered data to output streams
94  */
95  //static void write_all_data(void);
96 
97 
98 
99  /**
100  *
101  */
102  static OutputTime* create_output_stream(const Input::Record &in_rec);
103 
104  /**
105  * Declaration of exceptions
106  */
107  //TYPEDEF_ERR_INFO(EI_StreamName, const string);
108  //DECLARE_INPUT_EXCEPTION( ExcStreamName, << "Not valid stream name " << EI_StreamName::qval << "\n");
109 
110  /**
111  * \brief Constructor of OutputTime object. It opens base file for writing.
112  *
113  * \param[in] in_rec The reference on the input record
114  */
115  OutputTime(const Input::Record &in_rec);
116 
117  /**
118  * \brief Destructor of OutputTime. It doesn't do anything, because all
119  * necessary destructors will be called in destructor of Output
120  */
121  virtual ~OutputTime();
122 
123  /**
124  * \brief Generic method for registering output data stored in MultiField
125  *
126  * @param ref_type Type of output (element, node, corner data).
127  * @param multi_field The actual field for output.
128  */
129  template<int spacedim, class Value>
130  void register_data(const DiscreteSpace type,
131  MultiField<spacedim, Value> &multi_field);
132 
133 
134  /**
135  * \brief Generic method for registering of output data stored in Field
136  *
137  * @param ref_type Type of output (element, node, corner data).
138  * @param field The actual field for output.
139  */
140  template<int spacedim, class Value>
141  void register_data(const DiscreteSpace ref_type,
142  Field<spacedim, Value> &field);
143 
144  /**
145  * Write all data registered as a new time frame.
146  */
147  void write_time_frame();
148 
149  /**
150  * \brief Registers names of output fields that can be written using this stream.
151  * @param in_array Array of admissible fields (array of selections).
152  * @param in_sel Temporary - selection with field names.
153  */
154  void add_admissible_field_names(const Input::Array &in_array, const Input::Type::Selection &in_sel);
155 
156  /**
157  * \brief Clear data for output computed by method @p compute_field_data.
158  */
159  void clear_data(void);
160 
161  /**
162  * Add time marks matching given @p tgoutput_mark_type as well as general output type
163  * TimeMarks::type_output(). The time marks denotes times when output should be performed according
164  * to the input record of the output stream, namely keys: time_step, time_list, and include_input_times.
165  */
166  void mark_output_times(const TimeGovernor &tg);
167 
168 
169 private:
170  ofstream *base_file; ///< Base output stream
171  string *_base_filename; ///< Name of base output file
172  string *data_filename; ///< Name of data output file
173  ofstream *data_file; ///< Data output stream (could be same as base_file)
175 
176 protected:
177 
178 
179  /**
180  * Enumeration of file formats supported by Flow123d
181  */
182  typedef enum OutFileFormat {
183  NONE = 0,
184  GMSH = 1,
185  VTK = 2,
186  } OutFileFormat;
187 
188  /**
189  * Interpolate given @p field into output discrete @p space and store the values
190  * into private storage for postponed output.
191  */
192  template<int spacedim, class Value>
194 
195 
196  /**
197  * \brief This method returns pointer at existing data, when corresponding
198  * output data exists or it creates new one.
199  */
200  OutputDataBase *output_data_by_field_name(const string &field_name, DiscreteSpace ref_type);
201 
202  /**
203  * \brief This method set current time for registered data array/vector
204  */
205  void set_data_time(void *data, double time);
206 
207 
208  /**
209  *
210  */
211  virtual int write_data(void) = 0;
212 
213  /**
214  *
215  */
216  virtual int write_head(void) = 0 ;
217 
218  /**
219  *
220  */
221  virtual int write_tail(void) = 0;
222 
223  string *base_filename() { return this->_base_filename; };
224 
225  ofstream& get_base_file(void) { return *base_file; };
226 
227  ofstream& get_data_file(void) { return *data_file; };
228 
229  string& get_data_filename(void) { return *data_filename; };
230 
231  Mesh *get_mesh(void) { return mesh; };
232 
233  unsigned int get_corner_count(void) {
234  unsigned int li, count = 0;
235  FOR_ELEMENTS(this->mesh, ele) {
236  FOR_ELEMENT_NODES(ele, li) {
237  count++;
238  }
239  }
240  return count;
241  }
242 
243  void set_data_file(ofstream *_data_file) { data_file = _data_file; };
244 
245 
246 
247  // Protected setters for descendant
248  void set_mesh(Mesh *_mesh) { mesh = _mesh; };
249 
250  void set_base_file(ofstream *_base_file) { this->base_file = _base_file; };
251 
252 
253 
254 
255  /**
256  * \brief Vector of pointers at OutputTime
257  */
259 
260  /// MPI rank of process (is tested in methods)
261  int rank;
262 
264  //OutputFormat *output_format;
265  //string name; ///< Name of output stream
266 
270 
271 
272  int current_step; ///< Current step
273 
274  double time; ///< The newest time of registered data
275 
276  double write_time; ///< The last time, when data was wrote to this stream
277 
278  map<string,bool> output_names; ///< Map of names of output fields. True means that field will be saved.
279 
281 };
282 
283 
284 
285 
286 #endif /* OUTPUT_TIME_HH_ */
double time
The newest time of registered data.
Definition: output_time.hh:274
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:45
Common parent class for templated OutputData.
static Input::Type::AbstractRecord input_format_type
The specification of output file format.
Definition: output_time.hh:62
#define FOR_ELEMENT_NODES(i, j)
Definition: elements.h:150
Input::Record input_record_
Definition: output_time.hh:280
ofstream * base_file
Base output stream.
Definition: output_time.hh:170
Accessor to input data conforming to declared Array.
Definition: accessors.hh:521
static Input::Type::Record input_type
The specification of output stream.
Definition: output_time.hh:57
TYPEDEF_ERR_INFO(EI_FieldName, std::string)
void set_data_file(ofstream *_data_file)
Definition: output_time.hh:243
DECLARE_EXCEPTION(ExcOutputVariableVector,<< "Can not output field "<< EI_FieldName::qval<< " returning variable size vectors. Try convert to MultiField.\n")
#define FOR_ELEMENTS(_mesh_, __i)
Definition: mesh.h:357
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:48
void set_base_file(ofstream *_base_file)
Definition: output_time.hh:250
ofstream & get_data_file(void)
Definition: output_time.hh:227
void register_data(const DiscreteSpace type, MultiField< spacedim, Value > &multi_field)
Generic method for registering output data stored in MultiField.
Definition: output.h:243
???
Definition: mesh.h:108
OutputTime(const Input::Record &in_rec)
Constructor of OutputTime object. It opens base file for writing.
Definition: output.cc:248
Basic time management functionality for unsteady (and steady) solvers (class Equation).
string * data_filename
Name of data output file.
Definition: output_time.hh:172
vector< OutputDataBase * > node_data
Definition: output_time.hh:267
static void destroy_all(void)
Try to find output stream from a key in record.
Definition: output.cc:121
Mesh * get_mesh(void)
Definition: output_time.hh:231
static OutputTime * create_output_stream(const Input::Record &in_rec)
This method write all registered data to output streams.
Definition: output.cc:171
string * _base_filename
Name of base output file.
Definition: output_time.hh:171
void compute_field_data(DiscreteSpace space, Field< spacedim, Value > &field)
Definition: output.h:280
static std::vector< OutputTime * > output_streams
Vector of pointers at OutputTime.
Definition: output_time.hh:250
void set_mesh(Mesh *_mesh)
Definition: output_time.hh:248
int current_step
Current step.
Definition: output_time.hh:272
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
OutputDataBase * output_data_by_field_name(const string &field_name, DiscreteSpace ref_type)
This method returns pointer at existing data, when corresponding output data exists or it creates new...
Definition: output.cc:94
vector< OutputDataBase * > elem_data
Definition: output_time.hh:269
Class for declaration of polymorphic Record.
Definition: type_record.hh:463
map< string, bool > output_names
Map of names of output fields. True means that field will be saved.
Definition: output_time.hh:278
int rank
MPI rank of process (is tested in methods)
Definition: output_time.hh:261
void set_data_time(void *data, double time)
This method set current time for registered data array/vector.
virtual ~OutputTime()
Destructor of OutputTime. It doesn't do anything, because all necessary destructors will be called in...
Definition: output.cc:310
void clear_data(void)
Clear data for output computed by method compute_field_data.
Definition: output.cc:428
string * base_filename()
Definition: output_time.hh:223
ofstream * data_file
Data output stream (could be same as base_file)
Definition: output_time.hh:173
The class for outputing data during time.
Definition: output_time.hh:37
void mark_output_times(const TimeGovernor &tg)
Definition: output.cc:331
OutFileFormat file_format
Definition: output_time.hh:263
void write_time_frame()
Definition: output.cc:362
virtual int write_tail(void)=0
virtual int write_data(void)=0
Mesh * mesh
Definition: output_time.hh:174
void add_admissible_field_names(const Input::Array &in_array, const Input::Type::Selection &in_sel)
Registers names of output fields that can be written using this stream.
Definition: output.cc:231
string & get_data_filename(void)
Definition: output_time.hh:229
virtual int write_head(void)=0
Record type proxy class.
Definition: type_record.hh:161
double write_time
The last time, when data was wrote to this stream.
Definition: output_time.hh:276
unsigned int get_corner_count(void)
Definition: output_time.hh:233
Class for representation of a vector of fields of the same physical quantity.
Definition: field.hh:309
Template for classes storing finite set of named values.
ofstream & get_base_file(void)
Definition: output_time.hh:225
vector< OutputDataBase * > corner_data
Definition: output_time.hh:268