Flow123d  release_2.2.0-914-gf1a3a4f
output_time.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file output_time.hh
15  * @brief
16  */
17 
18 #ifndef OUTPUT_TIME_HH_
19 #define OUTPUT_TIME_HH_
20 
21 #include <vector>
22 #include <string>
23 #include <fstream>
24 #include "input/accessors.hh"
25 #include "io/element_data_cache.hh"
26 
27 class FilePath;
28 class Observe;
30 class Mesh;
31 class TimeGovernor;
32 class OutputMeshBase;
33 class OutputMesh;
35 
36 
37 /**
38  * \brief The class for outputting data during time.
39  *
40  * This class is descendant of Output class. This class is used for outputting
41  * data varying in time. Own output to specific file formats is done at other
42  * places to. See output_vtk.cc and output_msh.cc.
43  */
44 class OutputTime {
45 
46 public:
47  /// Default constructor. Only for testing.
48  OutputTime();
49 
50 
51  /**
52  * \brief Constructor of OutputTime object. It opens base file for writing.
53  *
54  * \param[in] equation_name The name of equation, used for forming output file name.
55  * \param[in] in_rec The reference on the input record
56  */
57  virtual void init_from_input(const std::string &equation_name, const Input::Record &in_rec);
58 
59  /**
60  * Common method to set scientific format and precision for output of floating point values to ASCII streams.
61  */
62  void set_stream_precision(std::ofstream &stream);
63 
64  /**
65  * \brief Destructor of OutputTime. It doesn't do anything, because all
66  * necessary destructors will be called in destructor of Output
67  */
68  virtual ~OutputTime();
69 
70  /**
71  * Return the input array for the output time set of the output stream.
72  */
74 
75  /**
76  * Return the input record for the output mesh of the output stream.
77  */
79 
80  /**
81  * \brief The specification of output stream
82  *
83  * \return This variable defines record for output stream
84  */
85  static const Input::Type::Record & get_input_type();
86 
87  /**
88  * \brief The specification of output file format
89  */
91 
92  /**
93  * Types of reference data
94  *
95  * NATIVE_DATA represents output of FieldFE in our own format, Paraview ignores this format.
96  */
97  static const unsigned int N_DISCRETE_SPACES = 4;
99  NODE_DATA = 0,
105  };
106 
107  /**
108  * Maps names of output fields required by user to their indices in
109  * output_data_vec_.
110  */
111  typedef unsigned int DiscreteSpaceFlags;
112 
113  /**
114  * Map field name to its OutputData object.
115  */
116  typedef std::shared_ptr<ElementDataCacheBase> OutputDataPtr;
118 
119  /// pair of field name and shape (= Scalar 1, Vector 3, Tensor 9)
120  typedef std::pair< std::string, unsigned int > FieldInterpolationData;
122 
123  /**
124  * \brief This method delete all object instances of class OutputTime stored
125  * in output_streams vector
126  */
127  //static void destroy_all(void);
128 
129  /**
130  * \brief This method tries to create new instance of OutputTime according
131  * record in configuration file.
132  */
133  static std::shared_ptr<OutputTime> create_output_stream(const std::string &equation_name, const Input::Record &in_rec);
134 
135  /**
136  * Write all data registered as a new time frame.
137  */
138  void write_time_frame();
139 
140  /**
141  * Getter of the observe object.
142  */
143  std::shared_ptr<Observe> observe(Mesh *mesh);
144 
145  /**
146  * \brief Clear data for output computed by method @p compute_field_data.
147  */
148  void clear_data(void);
149 
150  /**
151  * Return if shared pointer to output data caches are created.
152  */
154  return (bool)(nodes_);
155  }
156 
157  /// Return auxiliary flag enable_refinement_.
158  inline bool enable_refinement() {
159  return enable_refinement_;
160  }
161 
162  /**
163  * Set shared pointers of output data caches.
164  *
165  * Set shared pointer of \p output_mesh_ (temporary solution).
166  */
167  virtual void set_output_data_caches(std::shared_ptr<OutputMeshBase> mesh_ptr);
168 
169  /**
170  * Get shared pointer of \p output_mesh_.
171  */
172  std::shared_ptr<OutputMeshBase> get_output_mesh_ptr();
173 
174  /**
175  * Update the last time is actual \p time is less than \p field_time
176  */
177  void update_time(double field_time);
178 
179  /**
180  * Prepare data for computing field values.
181  *
182  * Method:
183  * - compute discontinuous mesh if CORNER_DATA is calculated
184  * - find and return ElementDataCache of given field_name, create its if doesn't exist
185  *
186  * @param field_name Quantity name of founding ElementDataCache
187  * @param space_type Output discrete space
188  * @param n_rows Count of rows of data cache (used only if new cache is created)
189  * @param n_cols Count of columns of data cache (used only if new cache is created)
190  * @param size Size of data cache (used only if new cache is created and only for native data)
191  */
192  template <typename T>
193  ElementDataCache<T> & prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols);
194 
195  /**
196  * Return base output parameters (rank and parallel) which determine if the output is performed
197  */
198  inline void get_output_params(bool &parallel, int &rank) {
199  parallel = this->parallel_;
200  rank = this->rank;
201  }
202 
203  /// Complete information about dummy fields, method has effect only for GMSH output.
204  virtual void add_dummy_fields();
205 
206 
207 protected:
208 
209  /**
210  * Change main filename to have prescribed extension.
211  */
212  void fix_main_file_extension(std::string extension);
213 
214 
215  /**
216  * \brief Return unique value current step for parallel or serial output.
217  *
218  * Respect value of \p parallel_ flag:
219  * - for serial output return actual value of \p current_step
220  * - for parallel output take unique value with account rank and number of processes
221  */
223 
224 
225  /**
226  * \brief Virtual method for writing data to output file
227  */
228  virtual int write_data(void) = 0;
229 
230  /**
231  * Cached MPI rank of process (is tested in methods)
232  */
233  int rank;
234 
235  /**
236  * Cached MPI number of processes (is tested in methods)
237  */
238  int n_proc;
239 
240  /**
241  * Registered output data. Single map for every value of DiscreteSpace
242  * corresponding to nodes, elements and corners.
243  */
244  OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES];
245 
246  /**
247  * Current step
248  */
250 
251  /**
252  * The newest time of registered data
253  */
254  double time;
255 
256  /**
257  * The last time, when data was wrote to this stream
258  */
259  double write_time;
260 
261  /**
262  * Record for current output stream
263  */
265 
266  /**
267  * Base output stream
268  */
269  ofstream _base_file;
270 
271  /**
272  * Name of base output file
273  */
275 
276  /**
277  * Name of the equation owning the output stream. Usually the balance equation.
278  * Used for forming default output file name and the name of observe output file.
279  */
280  std::string equation_name_;
281 
282  /**
283  * Number of decimal digits used for output of double values.
284  */
286 
287  /// Output mesh.
288  std::shared_ptr<OutputMeshBase> output_mesh_;
289 
290  std::shared_ptr<Observe> observe_;
291 
292  /// Auxiliary flag for refinement enabling, due to gmsh format.
294 
295  /// Parallel or serial version of file format (parallel has effect only for VTK)
296  bool parallel_;
297 
298  /// Vector of node coordinates. [spacedim x n_nodes]
299  std::shared_ptr<ElementDataCache<double>> nodes_;
300  /// Vector maps the nodes to their coordinates in vector @p nodes_.
301  std::shared_ptr<ElementDataCache<unsigned int>> connectivity_;
302  /// Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
303  std::shared_ptr<ElementDataCache<unsigned int>> offsets_;
304 
305 };
306 
307 
308 #endif /* OUTPUT_TIME_HH_ */
Class represents output mesh with continuous elements.
Definition: output_mesh.hh:172
ElementDataCache< T > & prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols)
virtual void set_output_data_caches(std::shared_ptr< OutputMeshBase > mesh_ptr)
Definition: output_time.cc:129
double time
Definition: output_time.hh:254
Input::Record input_record_
Definition: output_time.hh:264
Base class for Output mesh.
Definition: output_mesh.hh:67
void fix_main_file_extension(std::string extension)
Definition: output_time.cc:149
static std::shared_ptr< OutputTime > create_output_stream(const std::string &equation_name, const Input::Record &in_rec)
This method delete all object instances of class OutputTime stored in output_streams vector...
Definition: output_time.cc:183
std::shared_ptr< ElementDataCache< unsigned int > > connectivity_
Vector maps the nodes to their coordinates in vector nodes_.
Definition: output_time.hh:301
std::shared_ptr< OutputMeshBase > output_mesh_
Output mesh.
Definition: output_time.hh:288
static const Input::Type::Record & get_input_type()
The specification of output stream.
Definition: output_time.cc:37
std::shared_ptr< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
Definition: output_time.hh:303
FilePath _base_filename
Definition: output_time.hh:274
static Input::Type::Abstract & get_input_format_type()
The specification of output file format.
Definition: output_time.cc:64
std::shared_ptr< OutputMeshBase > get_output_mesh_ptr()
Definition: output_time.cc:137
std::shared_ptr< Observe > observe_
Definition: output_time.hh:290
void update_time(double field_time)
Definition: output_time.cc:142
Definition: mesh.h:99
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
Definition: output_time.hh:116
std::map< DiscreteSpace, std::vector< FieldInterpolationData > > InterpolationMap
Definition: output_time.hh:121
void get_output_params(bool &parallel, int &rank)
Definition: output_time.hh:198
OutputTime()
Default constructor. Only for testing.
Definition: output_time.cc:71
std::shared_ptr< ElementDataCache< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
Definition: output_time.hh:299
std::shared_ptr< Observe > observe(Mesh *mesh)
Definition: output_time.cc:228
virtual void init_from_input(const std::string &equation_name, const Input::Record &in_rec)
Constructor of OutputTime object. It opens base file for writing.
Definition: output_time.cc:83
bool is_output_data_caches_init()
Definition: output_time.hh:153
Basic time management functionality for unsteady (and steady) solvers (class Equation).
int get_parallel_current_step()
Return unique value current step for parallel or serial output.
Definition: output_time.cc:246
unsigned int DiscreteSpaceFlags
Definition: output_time.hh:111
bool parallel_
Parallel or serial version of file format (parallel has effect only for VTK)
Definition: output_time.hh:296
virtual void add_dummy_fields()
Complete information about dummy fields, method has effect only for GMSH output.
Definition: output_time.cc:253
Class represents output mesh with discontinuous elements.
Definition: output_mesh.hh:197
bool enable_refinement()
Return auxiliary flag enable_refinement_.
Definition: output_time.hh:158
int current_step
Definition: output_time.hh:249
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
static const unsigned int N_DISCRETE_SPACES
Definition: output_time.hh:97
virtual ~OutputTime()
Destructor of OutputTime. It doesn&#39;t do anything, because all necessary destructors will be called in...
Definition: output_time.cc:105
void clear_data(void)
Clear data for output computed by method compute_field_data.
Definition: output_time.cc:240
void set_stream_precision(std::ofstream &stream)
Definition: output_time.cc:98
std::pair< std::string, unsigned int > FieldInterpolationData
pair of field name and shape (= Scalar 1, Vector 3, Tensor 9)
Definition: output_time.hh:120
ofstream _base_file
Definition: output_time.hh:269
The class for outputting data during time.
Definition: output_time.hh:44
Class for declaration of polymorphic Record.
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
Input::Iterator< Input::Array > get_time_set_array()
Definition: output_time.cc:119
void write_time_frame()
Definition: output_time.cc:197
Input::Iterator< Input::Record > get_output_mesh_record()
Definition: output_time.cc:124
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:244
Record type proxy class.
Definition: type_record.hh:182
bool enable_refinement_
Auxiliary flag for refinement enabling, due to gmsh format.
Definition: output_time.hh:293
double write_time
Definition: output_time.hh:259
std::vector< OutputDataPtr > OutputDataFieldVec
Definition: output_time.hh:117
std::string equation_name_
Definition: output_time.hh:280