Flow123d
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 FieldCommonBase; // 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_ */