Flow123d  release_1.8.2-1603-g0109a2b
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 OutputDataBase;
27 class Mesh;
28 class FieldCommon; // in fact not necessary, output_data_by_field() can use directly name as parameter
29 template <int spacedim, class Value>
30 class Field;
31 template <int spacedim, class Value>
32 class MultiField;
33 class TimeGovernor;
34 
35 /**
36  * \brief The class for outputting data during time.
37  *
38  * This class is descendant of Output class. This class is used for outputting
39  * data varying in time. Own output to specific file formats is done at other
40  * places to. See output_vtk.cc and output_msh.cc.
41  */
42 class OutputTime {
43 
44 public:
45  /// Default constructor. Only for testing.
46  OutputTime();
47 
48 
49  /**
50  * \brief Constructor of OutputTime object. It opens base file for writing.
51  *
52  * \param[in] in_rec The reference on the input record
53  */
54  OutputTime(const Input::Record &in_rec);
55 
56  /**
57  * \brief Destructor of OutputTime. It doesn't do anything, because all
58  * necessary destructors will be called in destructor of Output
59  */
60  virtual ~OutputTime();
61 
62  /**
63  * \brief The specification of output stream
64  *
65  * \return This variable defines record for output stream
66  */
67  static const Input::Type::Record & get_input_type();
68 
69  /**
70  * \brief The specification of output file format
71  */
73 
74  /**
75  * Types of reference data
76  */
77  static const unsigned int N_DISCRETE_SPACES = 3;
79  NODE_DATA = 0,
82  };
83 
84  /**
85  * \brief This method delete all object instances of class OutputTime stored
86  * in output_streams vector
87  */
88  //static void destroy_all(void);
89 
90  /**
91  * \brief This method tries to create new instance of OutputTime according
92  * record in configuration file.
93  */
94  static std::shared_ptr<OutputTime> create_output_stream(const Input::Record &in_rec);
95 
96  /**
97  * \brief Generic method for registering output data stored in MultiField
98  *
99  * @param ref_type Type of output (element, node, corner data).
100  * @param multi_field The actual field for output.
101  */
102  template<int spacedim, class Value>
103  void register_data(const DiscreteSpace type,
104  MultiField<spacedim, Value> &multi_field);
105 
106  /**
107  * \brief Generic method for registering of output data stored in Field
108  *
109  * @param ref_type Type of output (element, node, corner data).
110  * @param field The actual field for output.
111  */
112  template<int spacedim, class Value>
113  void register_data(const DiscreteSpace ref_type,
114  Field<spacedim, Value> &field);
115 
116  /**
117  * Write all data registered as a new time frame.
118  */
119  void write_time_frame();
120 
121  /**
122  * \brief Registers names of output fields that can be written using this stream.
123  * @param in_array Array of admissible fields (array of selections).
124  */
125  void add_admissible_field_names(const Input::Array &in_array);
126 
127  /**
128  * \brief Clear data for output computed by method @p compute_field_data.
129  */
130  void clear_data(void);
131 
132  /**
133  * Add time marks matching given @p tg.output_mark_type as well as general output type
134  * TimeMarks::type_output(). The time marks denotes times when output should be performed according
135  * to the input record of the output stream, namely keys: time_step, time_list, and include_input_times.
136  */
137  void mark_output_times(const TimeGovernor &tg);
138 
139  /**
140  * Declaration of new exception info used in following exception
141  */
142  TYPEDEF_ERR_INFO(EI_FieldName, std::string);
143 
144  /**
145  * Declaration of exception
146  */
147  DECLARE_EXCEPTION(ExcOutputVariableVector, << "Can not output field " << EI_FieldName::qval
148  << " returning variable size vectors. Try convert to MultiField.\n");
149 
150  /**
151  * Record for current output stream
152  */
154 
155 protected:
156 
157  /**
158  * Interpolate given @p field into output discrete @p space and store the values
159  * into private storage for postponed output.
160  */
161  template<int spacedim, class Value>
163 
164  /**
165  * Change main filename to have prescribed extension.
166  */
167  void fix_main_file_extension(std::string extension);
168 
169 
170  /**
171  * \brief Virtual method for writing data to output file
172  */
173  virtual int write_data(void) = 0;
174 
175  /**
176  * Cached MPI rank of process (is tested in methods)
177  */
178  int rank;
179 
180  /**
181  * Map field name to its OutputData object.
182  */
183  typedef std::shared_ptr<OutputDataBase> OutputDataPtr;
185 
186  /**
187  * Registered output data. Single map for every value of DiscreteSpace
188  * corresponding to nodes, elements and corners.
189  */
190  OutputDataFieldVec output_data_vec_[N_DISCRETE_SPACES];
191 
192  /**
193  * Current step
194  */
196 
197  /**
198  * The newest time of registered data
199  */
200  double time;
201 
202  /**
203  * The last time, when data was wrote to this stream
204  */
205  double write_time;
206 
207  /**
208  * Maps names of output fields required by user to their indices in
209  * output_data_vec_.
210  */
211  typedef unsigned int DiscreteSpaceFlags;
213 
214  /**
215  * Record for current output stream
216  */
218 
219  /**
220  * Base output stream
221  */
222  ofstream _base_file;
223 
224  /**
225  * Name of base output file
226  */
228 
229  /**
230  * Cached pointer at mesh used by this output stream
231  */
233 };
234 
235 
236 #endif /* OUTPUT_TIME_HH_ */
double time
Definition: output_time.hh:200
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:57
Mesh * _mesh
Definition: output_time.hh:232
Common parent class for templated OutputData.
Input::Record input_record_
Definition: output_time.hh:217
Accessor to input data conforming to declared Array.
Definition: accessors.hh:552
static Input::Type::Abstract & get_input_format_type()
The specification of output file format.
Definition: output_time.cc:55
void fix_main_file_extension(std::string extension)
Definition: output_time.cc:103
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")
void add_admissible_field_names(const Input::Array &in_array)
Registers names of output fields that can be written using this stream.
Definition: output_time.cc:151
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:62
void register_data(const DiscreteSpace type, MultiField< spacedim, Value > &multi_field)
Generic method for registering output data stored in MultiField.
Definition: mesh.h:99
OutputTime()
Default constructor. Only for testing.
Definition: output_time.cc:61
static const Input::Type::Record & get_input_type()
The specification of output stream.
Definition: output_time.cc:34
Basic time management functionality for unsteady (and steady) solvers (class Equation).
std::map< std::string, DiscreteSpaceFlags > output_names
Definition: output_time.hh:212
unsigned int DiscreteSpaceFlags
Definition: output_time.hh:211
int current_step
Definition: output_time.hh:195
Accessor to the data with type Type::Record.
Definition: accessors.hh:277
static const unsigned int N_DISCRETE_SPACES
Definition: output_time.hh:77
Input::AbstractRecord format_record_
Definition: output_time.hh:153
virtual ~OutputTime()
Destructor of OutputTime. It doesn&#39;t do anything, because all necessary destructors will be called in...
Definition: output_time.cc:84
void clear_data(void)
Clear data for output computed by method compute_field_data.
Definition: output_time.cc:223
ofstream _base_file
Definition: output_time.hh:222
The class for outputting data during time.
Definition: output_time.hh:42
void mark_output_times(const TimeGovernor &tg)
Definition: output_time.cc:168
void compute_field_data(DiscreteSpace type, Field< spacedim, Value > &field)
string _base_filename
Definition: output_time.hh:227
Class for declaration of polymorphic Record.
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:444
static std::shared_ptr< OutputTime > create_output_stream(const Input::Record &in_rec)
This method delete all object instances of class OutputTime stored in output_streams vector...
Definition: output_time.cc:134
void write_time_frame()
Definition: output_time.cc:201
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:190
std::shared_ptr< OutputDataBase > OutputDataPtr
Definition: output_time.hh:183
Record type proxy class.
Definition: type_record.hh:171
double write_time
Definition: output_time.hh:205
std::vector< OutputDataPtr > OutputDataFieldVec
Definition: output_time.hh:184
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:55