Flow123d  release_2.2.0-914-gf1a3a4f
output_mesh.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_mesh.hh
15  * @brief Classes for auxiliary output mesh.
16  */
17 
18 #ifndef OUTPUT_MESH_HH_
19 #define OUTPUT_MESH_HH_
20 
21 #include <string>
22 #include <functional>
23 
24 #include "system/sys_profiler.hh"
25 #include "input/accessors.hh"
26 
28 #include "mesh/point.hh"
29 
30 class Mesh;
31 template<class T> class ElementDataCache;
32 template<int> class ElementAccessor;
33 
36 
37 class OutputMeshBase;
38 class OutputMesh;
40 class OutputMSH;
41 class OutputVTK;
42 
43 
44 /**
45  * @brief Base class for Output mesh.
46  *
47  * Defines common members for Output mesh classes:
48  * - OutputMesh represents output mesh with continuous elements
49  * - OutputMeshDiscontinuous represents output mesh with discontinuous elements
50  *
51  * Making of output meshes and calling of their initialization methods must be execute in correct order, see example:
52 @code
53  // Create or get Mesh object
54  Mesh * my_mesh = ...
55 
56  // Construct mesh with continuous elements
57  std::make_shared<OutputMesh> output_mesh = std::make_shared<OutputMesh>(*my_mesh);
58  // Creates the mesh identical to the computational one.
59  output_mesh->create_mesh();
60 
61  // Construct mesh with discontinuous elements
62  std::make_shared<OutputMeshDiscontinuous> output_mesh_discont = std::make_shared<OutputMeshDiscontinuous>(*my_mesh);
63  // Creates mesh from the original my_mesh.
64  output_mesh_discont->create_mesh();
65 @endcode
66  */
67 class OutputMeshBase : public std::enable_shared_from_this<OutputMeshBase>
68 {
69 public:
70  /// Shortcut instead of spacedim template. We suppose only spacedim=3 at the moment.
71  static const unsigned int spacedim = 3;
72 
73  typedef std::function<void(const std::vector< Space<spacedim>::Point > &, const ElementAccessor<spacedim> &, std::vector<double> &)>
75 
76  /// Constructor. Takes computational mesh as a parameter.
77  OutputMeshBase(Mesh &mesh);
78  /// Constructor. Takes computational mesh and input record as a parameters.
79  OutputMeshBase(Mesh &mesh, const Input::Record &in_rec);
80  virtual ~OutputMeshBase();
81 
82  /**
83  * @brief The specification of output mesh.
84  * @return record for output mesh
85  */
86  static const Input::Type::Record & get_input_type();
87 
88  /// Gives iterator to the FIRST element of the output mesh.
90  /// Gives iterator to the LAST element of the output mesh.
92 
93  /// Creates the output mesh identical to the orig mesh.
94  virtual void create_mesh()=0;
95 
96  /// Creates refined mesh.
97  virtual void create_refined_mesh()=0;
98 
99  /// Creates sub mesh containing only local elements.
100  virtual void create_sub_mesh()=0;
101 
102  /// Selects the error control field computing function of output field set according to input record.
103  void set_error_control_field(ErrorControlFieldFunc error_control_field_func);
104 
105  /// Returns number of nodes.
106  unsigned int n_nodes();
107  /// Returns number of element.
108  unsigned int n_elements();
109 
110  /// Check if nodes_, connectivity_ and offsets_ data caches are created
111  bool is_created();
112 
113  /// Create nodes and elements data caches
114  void create_id_caches();
115 
116 protected:
117  /**
118  * Possible types of OutputMesh.
119  */
120  enum MeshType
121  {
122  orig, //!< same as original (computational) mesh
123  refined, //!< refined mesh
124  discont //!< discontinuous mesh
125  };
126 
127 
128  /// Input record for output mesh.
130 
131  /// Pointer to the computational mesh.
133 
134  /// Maximal level of refinement.
135  const unsigned int max_level_;
136 
137  /// Refinement error control field function (hold value_list function of field).
139 
140  MeshType mesh_type_; ///< Type of OutputMesh
141  bool refine_by_error_; ///< True, if output mesh is to be refined by error criterion.
142  double refinement_error_tolerance_; ///< Tolerance for error criterion refinement.
143 
144  /// Vector of element indices in the computational mesh. (Important when refining.)
145  std::shared_ptr<std::vector<unsigned int>> orig_element_indices_;
146 
147  /// Vector of node coordinates. [spacedim x n_nodes]
148  std::shared_ptr<ElementDataCache<double>> nodes_;
149  /// Vector maps the nodes to their coordinates in vector @p nodes_.
150  std::shared_ptr<ElementDataCache<unsigned int>> connectivity_;
151  /// Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
152  std::shared_ptr<ElementDataCache<unsigned int>> offsets_;
153 
154  /// Vector gets ids of nodes. Data is used in GMSH output.
155  std::shared_ptr<ElementDataCache<unsigned int>> node_ids_;
156  /// Vector gets ids of elements. Data is used in GMSH output.
157  std::shared_ptr<ElementDataCache<unsigned int>> elem_ids_;
158  /// Vector gets ids of regions. Data is used in GMSH output.
159  std::shared_ptr<ElementDataCache<unsigned int>> region_ids_;
160  /// Vector gets partitions of elements. Data is used in GMSH output.
161  std::shared_ptr<ElementDataCache<int>> partitions_;
162 
163  /// Friend provides access to vectors for element accessor class.
164  friend class OutputElement;
165  friend class OutputTime;
166  friend class OutputMSH;
167  friend class OutputVTK;
168 };
169 
170 
171 /// @brief Class represents output mesh with continuous elements.
173 {
174 public:
175  OutputMesh(Mesh &mesh);
176  OutputMesh(Mesh &mesh, const Input::Record &in_rec);
177  ~OutputMesh();
178 
179  /// Creates the output mesh identical to the orig mesh.
180  void create_mesh() override;
181 
182  /// Creates refined mesh.
183  void create_refined_mesh() override;
184 
185  /// Creates sub mesh.
186  void create_sub_mesh() override;
187 
188 protected:
189  bool refinement_criterion();
190 
191  /// Friend provides access to vectors for discontinous output mesh.
193 };
194 
195 
196 /// @brief Class represents output mesh with discontinuous elements.
198 {
199 public:
201  OutputMeshDiscontinuous(Mesh &mesh, const Input::Record& in_rec);
203 
204  /// Creates the output mesh identical to the orig mesh.
205  void create_mesh() override;
206 
207  /// Creates discontinuous refined mesh.
208  void create_refined_mesh() override;
209 
210  /// Creates sub mesh.
211  void create_sub_mesh() override;
212 
213 protected:
214  ///Auxiliary structure defining element of refined output mesh.
215  struct AuxElement{
217  unsigned int level;
218  };
219 
220  ///Performs the actual refinement of AuxElement. Recurrent.
221  template<int dim>
222  void refine_aux_element(const AuxElement& aux_element,
223  std::vector< AuxElement >& refinement,
224  const ElementAccessor<spacedim> &ele_acc
225  );
226 
227  /// Collects different refinement criteria results.
228  bool refinement_criterion(const AuxElement& ele,
229  const ElementAccessor<spacedim> &ele_acc);
230 
231  /// Refinement flag - checks only maximal level of refinement.
232  bool refinement_criterion_uniform(const AuxElement& ele);
233 
234  /// Refinement flag - measures discretisation error according to error control field.
235  bool refinement_criterion_error(const AuxElement& ele,
236  const Space<spacedim>::Point &centre,
237  const ElementAccessor<spacedim> &ele_acc
238  );
239 };
240 
241 #endif // OUTPUT_MESH_HH_
242 
Class represents output mesh with continuous elements.
Definition: output_mesh.hh:172
static const unsigned int spacedim
Shortcut instead of spacedim template. We suppose only spacedim=3 at the moment.
Definition: output_mesh.hh:71
Base class for Output mesh.
Definition: output_mesh.hh:67
GeneralIterator< OutputElement > OutputElementIterator
Definition: output_mesh.hh:34
Represents an element of the output mesh. Provides element access on the data of the output mesh (nod...
std::function< void(const std::vector< Space< spacedim >::Point > &, const ElementAccessor< spacedim > &, std::vector< double > &)> ErrorControlFieldFunc
Definition: output_mesh.hh:74
unsigned int n_elements()
Returns number of element.
Definition: output_mesh.cc:88
Mesh * orig_mesh_
Pointer to the computational mesh.
Definition: output_mesh.hh:132
static const Input::Type::Record & get_input_type()
The specification of output mesh.
Definition: output_mesh.cc:27
const unsigned int max_level_
Maximal level of refinement.
Definition: output_mesh.hh:135
Definition: mesh.h:99
Template GeneralIterator serves as general template for internal iterators.
double refinement_error_tolerance_
Tolerance for error criterion refinement.
Definition: output_mesh.hh:142
discontinuous mesh
Definition: output_mesh.hh:124
std::shared_ptr< ElementDataCache< unsigned int > > connectivity_
Vector maps the nodes to their coordinates in vector nodes_.
Definition: output_mesh.hh:150
std::shared_ptr< ElementDataCache< unsigned int > > node_ids_
Vector gets ids of nodes. Data is used in GMSH output.
Definition: output_mesh.hh:155
std::shared_ptr< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
Definition: output_mesh.hh:152
unsigned int n_nodes()
Returns number of nodes.
Definition: output_mesh.cc:94
std::shared_ptr< ElementDataCache< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
Definition: output_mesh.hh:148
Class represents output mesh with discontinuous elements.
Definition: output_mesh.hh:197
ErrorControlFieldFunc error_control_field_func_
Refinement error control field function (hold value_list function of field).
Definition: output_mesh.hh:138
arma::vec::fixed< spacedim > Point
Definition: point.hh:33
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
virtual void create_refined_mesh()=0
Creates refined mesh.
Auxiliary structure defining element of refined output mesh.
Definition: output_mesh.hh:215
This class is used for output data to VTK file format.
Definition: output_vtk.hh:36
void set_error_control_field(ErrorControlFieldFunc error_control_field_func)
Selects the error control field computing function of output field set according to input record...
Definition: output_mesh.cc:83
std::shared_ptr< ElementDataCache< unsigned int > > region_ids_
Vector gets ids of regions. Data is used in GMSH output.
Definition: output_mesh.hh:159
virtual ~OutputMeshBase()
Definition: output_mesh.cc:64
virtual void create_sub_mesh()=0
Creates sub mesh containing only local elements.
The class for outputting data during time.
Definition: output_time.hh:44
Input::Record input_record_
Input record for output mesh.
Definition: output_mesh.hh:129
OutputElementIterator end()
Gives iterator to the LAST element of the output mesh.
Definition: output_mesh.cc:75
std::shared_ptr< ElementDataCache< int > > partitions_
Vector gets partitions of elements. Data is used in GMSH output.
Definition: output_mesh.hh:161
bool refine_by_error_
True, if output mesh is to be refined by error criterion.
Definition: output_mesh.hh:141
virtual void create_mesh()=0
Creates the output mesh identical to the orig mesh.
MeshType mesh_type_
Type of OutputMesh.
Definition: output_mesh.hh:140
Record type proxy class.
Definition: type_record.hh:182
std::vector< Space< spacedim >::Point > nodes
Definition: output_mesh.hh:216
General iterator template. Provides iterator over objects in some container.
void create_id_caches()
Create nodes and elements data caches.
Definition: output_mesh.cc:100
bool is_created()
Check if nodes_, connectivity_ and offsets_ data caches are created.
Definition: output_mesh.cc:132
std::shared_ptr< ElementDataCache< unsigned int > > elem_ids_
Vector gets ids of elements. Data is used in GMSH output.
Definition: output_mesh.hh:157
same as original (computational) mesh
Definition: output_mesh.hh:122
This class is used for output data to VTK file format.
Definition: output_msh.hh:27
std::shared_ptr< std::vector< unsigned int > > orig_element_indices_
Vector of element indices in the computational mesh. (Important when refining.)
Definition: output_mesh.hh:145
OutputElementIterator begin()
Gives iterator to the FIRST element of the output mesh.
Definition: output_mesh.cc:68
OutputMeshBase(Mesh &mesh)
Constructor. Takes computational mesh as a parameter.
Definition: output_mesh.cc:42