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