Flow123d  last_with_con_2.0.0-4-g42e6930
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 
26 class FilePath;
27 class Observe;
28 class OutputDataBase;
29 class Mesh;
30 class FieldCommon; // in fact not necessary, output_data_by_field() can use directly name as parameter
31 template <int spacedim, class Value>
32 class Field;
33 class FieldSet;
34 template <int spacedim, class Value>
35 class MultiField;
36 class TimeGovernor;
37 class OutputMesh;
39 
40 
41 /**
42  * \brief The class for outputting data during time.
43  *
44  * This class is descendant of Output class. This class is used for outputting
45  * data varying in time. Own output to specific file formats is done at other
46  * places to. See output_vtk.cc and output_msh.cc.
47  */
48 class OutputTime {
49 
50 public:
51  /// Default constructor. Only for testing.
52  OutputTime();
53 
54 
55  /**
56  * \brief Constructor of OutputTime object. It opens base file for writing.
57  *
58  * \param[in] equation_name The name of equation, used for forming output file name.
59  * \param[in] in_rec The reference on the input record
60  */
61  void init_from_input(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec);
62 
63  /**
64  * \brief Destructor of OutputTime. It doesn't do anything, because all
65  * necessary destructors will be called in destructor of Output
66  */
67  virtual ~OutputTime();
68 
69  /**
70  * Return the input array for the output time set of the output stream.
71  */
73 
74  /**
75  * \brief The specification of output stream
76  *
77  * \return This variable defines record for output stream
78  */
79  static const Input::Type::Record & get_input_type();
80 
81  /**
82  * \brief The specification of output file format
83  */
85 
86  /**
87  * Types of reference data
88  */
89  static const unsigned int N_DISCRETE_SPACES = 3;
91  NODE_DATA = 0,
94  };
95 
96  /**
97  * \brief This method delete all object instances of class OutputTime stored
98  * in output_streams vector
99  */
100  //static void destroy_all(void);
101 
102  /**
103  * \brief This method tries to create new instance of OutputTime according
104  * record in configuration file.
105  */
106  static std::shared_ptr<OutputTime> create_output_stream(const std::string &equation_name, Mesh &mesh, const Input::Record &in_rec);
107 
108  /**
109  * Create the output mesh from the given computational mesh. The field set passed in is used
110  * to select the field used for adaptivity of the output mesh.
111  */
112  void make_output_mesh(FieldSet &output_fields);
113 
114  /**
115  * \brief Generic method for registering output data stored in MultiField
116  *
117  * @param ref_type Type of output (element, node, corner data).
118  * @param multi_field The actual field for output.
119  */
120  template<int spacedim, class Value>
121  void register_data(const DiscreteSpace type,
122  MultiField<spacedim, Value> &multi_field);
123 
124  /**
125  * \brief Generic method for registering of output data stored in Field
126  *
127  * @param ref_type Type of output (element, node, corner data).
128  * @param field The actual field for output.
129  */
130  template<int spacedim, class Value>
131  void register_data(const DiscreteSpace ref_type,
132  Field<spacedim, Value> &field);
133 
134  /**
135  * Write all data registered as a new time frame.
136  */
137  void write_time_frame();
138 
139  /**
140  * Getter of the oubserve object.
141  */
142  std::shared_ptr<Observe> observe();
143 
144  /**
145  * \brief Clear data for output computed by method @p compute_field_data.
146  */
147  void clear_data(void);
148 
149  /**
150  * Declaration of new exception info used in following exception
151  */
152  TYPEDEF_ERR_INFO(EI_FieldName, std::string);
153 
154  /**
155  * Declaration of exception
156  */
157  DECLARE_EXCEPTION(ExcOutputVariableVector, << "Can not output field " << EI_FieldName::qval
158  << " returning variable size vectors. Try convert to MultiField.\n");
159 
160 
161 protected:
162 
164 
165  /**
166  * Interpolate given @p field into output discrete @p space and store the values
167  * into private storage for postponed output.
168  */
169  template<int spacedim, class Value>
171 
172  /**
173  * Change main filename to have prescribed extension.
174  */
175  void fix_main_file_extension(std::string extension);
176 
177 
178  /**
179  * \brief Virtual method for writing data to output file
180  */
181  virtual int write_data(void) = 0;
182 
183  /**
184  * Cached MPI rank of process (is tested in methods)
185  */
186  int rank;
187 
188  /**
189  * Map field name to its OutputData object.
190  */
191  typedef std::shared_ptr<OutputDataBase> OutputDataPtr;
193 
194  /**
195  * Registered output data. Single map for every value of DiscreteSpace
196  * corresponding to nodes, elements and corners.
197  */
198  OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES];
199 
200  /**
201  * Current step
202  */
204 
205  /**
206  * The newest time of registered data
207  */
208  double time;
209 
210  /**
211  * The last time, when data was wrote to this stream
212  */
213  double write_time;
214 
215  /**
216  * Maps names of output fields required by user to their indices in
217  * output_data_vec_.
218  */
219  typedef unsigned int DiscreteSpaceFlags;
220 
221  /**
222  * Record for current output stream
223  */
225 
226  /**
227  * Base output stream
228  */
229  ofstream _base_file;
230 
231  /**
232  * Name of base output file
233  */
235 
236  /**
237  * Name of the equation owning the output stream. Usually the balance equation.
238  * Used for forming default output file name and the name of observe output file.
239  */
240  std::string equation_name_;
241 
242  /**
243  * Cached pointer at mesh used by this output stream
244  */
246 
247  /// Output mesh.
248  std::shared_ptr<OutputMesh> output_mesh_;
249  /// Discontinuous (non-conforming) mesh. Used for CORNER_DATA.
250  std::shared_ptr<OutputMeshDiscontinuous> output_mesh_discont_;
251 
252  std::shared_ptr<Observe> observe_;
253 
254  /// Auxliary flag for refinement enabling, due to gmsh format.
256 };
257 
258 
259 #endif /* OUTPUT_TIME_HH_ */
Class represents output mesh with continuous elements.
Definition: output_mesh.hh:112
std::shared_ptr< Observe > observe()
Definition: output_time.cc:230
double time
Definition: output_time.hh:208
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:60
Mesh * _mesh
Definition: output_time.hh:245
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:61
Common parent class for templated OutputData.
std::shared_ptr< OutputMesh > output_mesh_
Output mesh.
Definition: output_time.hh:248
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:76
Input::Record input_record_
Definition: output_time.hh:224
std::shared_ptr< OutputMeshDiscontinuous > output_mesh_discont_
Discontinuous (non-conforming) mesh. Used for CORNER_DATA.
Definition: output_time.hh:250
void fix_main_file_extension(std::string extension)
Definition: output_time.cc:157
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")
static const Input::Type::Record & get_input_type()
The specification of output stream.
Definition: output_time.cc:38
FilePath _base_filename
Definition: output_time.hh:234
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:62
static Input::Type::Abstract & get_input_format_type()
The specification of output file format.
Definition: output_time.cc:58
void register_data(const DiscreteSpace type, MultiField< spacedim, Value > &multi_field)
Generic method for registering output data stored in MultiField.
std::shared_ptr< Observe > observe_
Definition: output_time.hh:252
Definition: mesh.h:95
void make_output_mesh(FieldSet &output_fields)
Definition: output_time.cc:111
OutputTime()
Default constructor. Only for testing.
Definition: output_time.cc:65
Basic time management functionality for unsteady (and steady) solvers (class Equation).
unsigned int DiscreteSpaceFlags
Definition: output_time.hh:219
int current_step
Definition: output_time.hh:203
Accessor to the data with type Type::Record.
Definition: accessors.hh:277
static const unsigned int N_DISCRETE_SPACES
Definition: output_time.hh:89
virtual ~OutputTime()
Destructor of OutputTime. It doesn&#39;t do anything, because all necessary destructors will be called in...
Definition: output_time.cc:92
void clear_data(void)
Clear data for output computed by method compute_field_data.
Definition: output_time.cc:243
ofstream _base_file
Definition: output_time.hh:229
The class for outputting data during time.
Definition: output_time.hh:48
void compute_field_data(DiscreteSpace type, Field< spacedim, Value > &field)
Class for declaration of polymorphic Record.
Dedicated class for storing path to input and output files.
Definition: file_path.hh:48
Input::Iterator< Input::Array > get_time_set_array()
Definition: output_time.cc:106
void write_time_frame()
Definition: output_time.cc:201
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:187
virtual int write_data(void)=0
Virtual method for writing data to output file.
void compute_discontinuous_output_mesh()
Definition: output_time.cc:149
OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES]
Definition: output_time.hh:198
std::shared_ptr< OutputDataBase > OutputDataPtr
Definition: output_time.hh:191
Record type proxy class.
Definition: type_record.hh:171
bool enable_refinement_
Auxliary flag for refinement enabling, due to gmsh format.
Definition: output_time.hh:255
double write_time
Definition: output_time.hh:213
std::vector< OutputDataPtr > OutputDataFieldVec
Definition: output_time.hh:192
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:55
std::string equation_name_
Definition: output_time.hh:240