Flow123d  release_2.2.0-41-g0958a8d
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, Mesh &mesh, 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  static const unsigned int N_DISCRETE_SPACES = 3;
97  NODE_DATA = 0,
100  };
101 
102  /**
103  * Maps names of output fields required by user to their indices in
104  * output_data_vec_.
105  */
106  typedef unsigned int DiscreteSpaceFlags;
107 
108  /**
109  * Map field name to its OutputData object.
110  */
111  typedef std::shared_ptr<ElementDataCacheBase> OutputDataPtr;
113 
114  /**
115  * \brief This method delete all object instances of class OutputTime stored
116  * in output_streams vector
117  */
118  //static void destroy_all(void);
119 
120  /**
121  * \brief This method tries to create new instance of OutputTime according
122  * record in configuration file.
123  */
124  static std::shared_ptr<OutputTime> create_output_stream(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec);
125 
126  /**
127  * Write all data registered as a new time frame.
128  */
129  void write_time_frame();
130 
131  /**
132  * Getter of the observe object.
133  */
134  std::shared_ptr<Observe> observe();
135 
136  /**
137  * \brief Clear data for output computed by method @p compute_field_data.
138  */
139  void clear_data(void);
140 
141  /**
142  * Return if shared pointer to output_mesh_ is created.
143  */
144  inline bool is_output_mesh_init() {
145  return (bool)(output_mesh_);
146  }
147 
148  /// Return auxiliary flag enable_refinement_.
149  inline bool enable_refinement() {
150  return enable_refinement_;
151  }
152 
153  /**
154  * Create shared pointer of \p output_mesh_ or \p output_mesh_discont_ (if discont is true) and return its.
155  *
156  * @param init_input Call constructor with initialization from Input Record
157  * @param discont Determines type of output mesh (output_mesh_ or output_mesh_discont_)
158  */
159  std::shared_ptr<OutputMeshBase> create_output_mesh_ptr(bool init_input, bool discont = false);
160 
161  /**
162  * Get shared pointer of \p output_mesh_ or \p output_mesh_discont_ (if discont is true).
163  */
164  std::shared_ptr<OutputMeshBase> get_output_mesh_ptr(bool discont = false);
165 
166  /**
167  * Return MPI rank of process
168  */
169  inline int get_rank() {
170  return rank;
171  }
172 
173  /**
174  * Update the last time is actual \p time is less than \p field_time
175  */
176  void update_time(double field_time);
177 
178  /**
179  * Prepare data for computing field values.
180  *
181  * Method:
182  * - compute discontinuous mesh if CORNER_DATA is calculated
183  * - find and return ElementDataCache of given field_name, create its if doesn't exist
184  *
185  * @param field_name Quantity name of founding ElementDataCache
186  * @param space_type Output discrete space
187  * @param n_rows Count of rows of data cache (used only if new cache is created)
188  * @param n_cols Count of columns of data cache (used only if new cache is created)
189  */
190  template <typename T>
191  ElementDataCache<T> & prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols);
192 
193 
194 protected:
195 
197 
198  /**
199  * Change main filename to have prescribed extension.
200  */
201  void fix_main_file_extension(std::string extension);
202 
203 
204  /**
205  * \brief Virtual method for writing data to output file
206  */
207  virtual int write_data(void) = 0;
208 
209  /**
210  * Cached MPI rank of process (is tested in methods)
211  */
212  int rank;
213 
214  /**
215  * Registered output data. Single map for every value of DiscreteSpace
216  * corresponding to nodes, elements and corners.
217  */
218  OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES];
219 
220  /**
221  * Current step
222  */
224 
225  /**
226  * The newest time of registered data
227  */
228  double time;
229 
230  /**
231  * The last time, when data was wrote to this stream
232  */
233  double write_time;
234 
235  /**
236  * Record for current output stream
237  */
239 
240  /**
241  * Base output stream
242  */
243  ofstream _base_file;
244 
245  /**
246  * Name of base output file
247  */
249 
250  /**
251  * Name of the equation owning the output stream. Usually the balance equation.
252  * Used for forming default output file name and the name of observe output file.
253  */
254  std::string equation_name_;
255 
256  /**
257  * Number of decimal digits used for output of double values.
258  */
260 
261  /**
262  * Cached pointer at mesh used by this output stream
263  */
265 
266  /// Output mesh.
267  std::shared_ptr<OutputMesh> output_mesh_;
268  /// Discontinuous (non-conforming) mesh. Used for CORNER_DATA.
269  std::shared_ptr<OutputMeshDiscontinuous> output_mesh_discont_;
270 
271  std::shared_ptr<Observe> observe_;
272 
273  /// Auxiliary flag for refinement enabling, due to gmsh format.
275 };
276 
277 
278 #endif /* OUTPUT_TIME_HH_ */
Class represents output mesh with continuous elements.
Definition: output_mesh.hh:127
ElementDataCache< T > & prepare_compute_data(std::string field_name, DiscreteSpace space_type, unsigned int n_rows, unsigned int n_cols)
std::shared_ptr< Observe > observe()
Definition: output_time.cc:239
double time
Definition: output_time.hh:228
Mesh * _mesh
Definition: output_time.hh:264
std::shared_ptr< OutputMesh > output_mesh_
Output mesh.
Definition: output_time.hh:267
virtual void init_from_input(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec)
Constructor of OutputTime object. It opens base file for writing.
Definition: output_time.cc:78
Input::Record input_record_
Definition: output_time.hh:238
Base class for Output mesh.
Definition: output_mesh.hh:62
std::shared_ptr< OutputMeshDiscontinuous > output_mesh_discont_
Discontinuous (non-conforming) mesh. Used for CORNER_DATA.
Definition: output_time.hh:269
void fix_main_file_extension(std::string extension)
Definition: output_time.cc:162
static const Input::Type::Record & get_input_type()
The specification of output stream.
Definition: output_time.cc:37
FilePath _base_filename
Definition: output_time.hh:248
static Input::Type::Abstract & get_input_format_type()
The specification of output file format.
Definition: output_time.cc:60
std::shared_ptr< Observe > observe_
Definition: output_time.hh:271
void update_time(double field_time)
Definition: output_time.cc:147
Definition: mesh.h:97
std::shared_ptr< ElementDataCacheBase > OutputDataPtr
Definition: output_time.hh:111
OutputTime()
Default constructor. Only for testing.
Definition: output_time.cc:67
Basic time management functionality for unsteady (and steady) solvers (class Equation).
unsigned int DiscreteSpaceFlags
Definition: output_time.hh:106
Class represents output mesh with discontinuous elements.
Definition: output_mesh.hh:149
bool enable_refinement()
Return auxiliary flag enable_refinement_.
Definition: output_time.hh:149
bool is_output_mesh_init()
Definition: output_time.hh:144
int get_rank()
Definition: output_time.hh:169
int current_step
Definition: output_time.hh:223
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
static const unsigned int N_DISCRETE_SPACES
Definition: output_time.hh:95
virtual ~OutputTime()
Destructor of OutputTime. It doesn&#39;t do anything, because all necessary destructors will be called in...
Definition: output_time.cc:101
void clear_data(void)
Clear data for output computed by method compute_field_data.
Definition: output_time.cc:252
std::shared_ptr< OutputMeshBase > get_output_mesh_ptr(bool discont=false)
Definition: output_time.cc:138
void set_stream_precision(std::ofstream &stream)
Definition: output_time.cc:94
ofstream _base_file
Definition: output_time.hh:243
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:115
void write_time_frame()
Definition: output_time.cc:210
static std::shared_ptr< OutputTime > create_output_stream(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec)
This method delete all object instances of class OutputTime stored in output_streams vector...
Definition: output_time.cc:196
Input::Iterator< Input::Record > get_output_mesh_record()
Definition: output_time.cc:120
std::shared_ptr< OutputMeshBase > create_output_mesh_ptr(bool init_input, bool discont=false)
Definition: output_time.cc:125
virtual int write_data(void)=0
Virtual method for writing data to output file.
void compute_discontinuous_output_mesh()
Definition: output_time.cc:154
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
Definition: output_time.hh:218
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:274
double write_time
Definition: output_time.hh:233
std::vector< OutputDataPtr > OutputDataFieldVec
Definition: output_time.hh:112
std::string equation_name_
Definition: output_time.hh:254