Flow123d  release_2.1.0-87-gfbc1563
dofhandler.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 dofhandler.hh
15  * @brief Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between local and global dofs.
16  * @author Jan Stebel
17  */
18 
19 #ifndef DOFHANDLER_HH_
20 #define DOFHANDLER_HH_
21 
22 #include <map>
23 #include <petscmat.h>
24 #include "mesh/mesh_types.hh"
25 #include "mesh/elements.h"
26 #include "la/distribution.hh"
27 
28 
29 template<unsigned int dim, unsigned int spacedim> class FiniteElement;
30 class Mesh;
31 class Distribution;
32 
33 /**
34  * Class DOFHandlerBase provides an abstract interface for various dof handlers:
35  * - basic handler for a given spatial dimension
36  * - multi-dimensional handler for all spatial dimensions (1D-3D)
37  * - handler for a specific region / part of mesh
38  */
40 public:
41 
42  /**
43  * @brief Constructor.
44  * @param _mesh The mesh.
45  */
46  DOFHandlerBase(Mesh &_mesh) : global_dof_offset(0), n_dofs(0), lsize_(0), mesh_(&_mesh) {};
47 
48  /**
49  * @brief Alias for iterator over cells.
50  *
51  * TODO: Notation to be fixed: element or cell
52  * TODO: Iterator goes through cells of all dimensions, but
53  * should go only through dim-dimensional ones.
54  */
56 
57  /**
58  * @brief Getter for the number of all mesh dofs required by the given
59  * finite element.
60  */
61  const unsigned int n_global_dofs() const { return n_dofs; }
62 
63  /**
64  * @brief Returns the number of the first global dof handled by this
65  * DOFHandler.
66  */
67  const unsigned int offset() const { return global_dof_offset; }
68 
69  /**
70  * @brief Returns the number of dofs on the current process.
71  */
72  const unsigned int lsize() const { return lsize_; }
73 
74  /**
75  * @brief Returns the offset of the local part of dofs.
76  */
77  const unsigned int loffset() const { return loffset_; }
78 
79  Distribution *distr() const { return ds_; }
80 
81  Mesh *mesh() const { return mesh_; }
82 
83  /**
84  * @brief Returns the global indices of dofs associated to the @p cell.
85  *
86  * @param cell The cell.
87  * @param indices Array of dof indices on the cell.
88  */
89  virtual void get_dof_indices(const CellIterator &cell, unsigned int indices[]) const = 0;
90 
91  /**
92  * @brief Returns the indices of dofs associated to the @p cell on the local process.
93  *
94  * @param cell The cell.
95  * @param indices Array of dof indices on the cell.
96  */
97  virtual void get_loc_dof_indices(const CellIterator &cell, unsigned int indices[]) const =0;
98 
99  /**
100  * @brief Returns the dof values associated to the @p cell.
101  *
102  * @param cell The cell.
103  * @param values The global vector of values.
104  * @param local_values Array of values at local dofs.
105  */
106  virtual void get_dof_values(const CellIterator &cell, const Vec &values,
107  double local_values[]) const = 0;
108 
109  /// Destructor.
110  virtual ~DOFHandlerBase() {};
111 
112 protected:
113 
114  /**
115  * @brief Index of first global dof.
116  *
117  * Positive value indicates that the first @p global_dof_offset
118  * entries in the global dof vector are reserved for a different
119  * DOFHandler.
120  */
121  unsigned int global_dof_offset;
122 
123  /**
124  * @brief Number of global dofs assigned by the handler.
125  */
126  unsigned int n_dofs;
127 
128  /**
129  * @brief Number of dofs associated to local process.
130  */
131  unsigned int lsize_;
132 
133  /**
134  * @brief Index of the first dof on the local process.
135  */
136  unsigned int loffset_;
137 
138  /**
139  * @brief Pointer to the mesh to which the dof handler is associated.
140  */
142 
143  /**
144  * @brief Distribution of dofs associated to local process.
145  */
147 
148 };
149 
150 
151 
152 
153 ///**
154 // * @brief Provides the numbering of the finite element degrees of freedom
155 // * on the computational mesh.
156 // *
157 // * Class DOFHandler distributes the degrees of freedom (dof) for
158 // * a particular finite element on the computational mesh
159 // * and provides mappings between local and global dofs.
160 // * The template parameter @p dim denotes the spatial dimension of
161 // * the reference finite element.
162 // *
163 // * Currently the functionality is restricted to discontinuous
164 // * finite elements, i.e. when the neighboring elements do not
165 // * share any common dof.
166 // */
167 //template<unsigned int dim, unsigned int spacedim>
168 //class DOFHandler : public DOFHandlerBase {
169 //public:
170 //
171 // /**
172 // * @brief Constructor.
173 // * @param _mesh The mesh.
174 // */
175 // DOFHandler(Mesh &_mesh);
176 //
177 // /**
178 // * @brief Alias for iterator over cells.
179 // *
180 // * TODO: Notation to be fixed: element or cell
181 // * TODO: Iterator goes through cells of all dimensions, but
182 // * should go only through dim-dimensional ones.
183 // */
184 // typedef ElementFullIter CellIterator;
185 //
186 // /**
187 // * @brief Distributes degrees of freedom on the mesh needed
188 // * for the given finite element.
189 // *
190 // * The additional parameter @p offset allows to reserve space
191 // * for another finite element dofs in the beginning of the
192 // * global dof vector.
193 // *
194 // * @param fe The finite element.
195 // * @param offset The offset.
196 // */
197 // void distribute_dofs(FiniteElement<dim,spacedim> &fe, const unsigned int offset = 0);
198 //
199 // /**
200 // * @brief Getter for the number of dofs at a single cell.
201 // *
202 // * This value depends on the given finite element.
203 // */
204 // const unsigned int n_local_dofs();
205 //
206 // /**
207 // * @brief Returns the global indices of dofs associated to the @p cell.
208 // *
209 // * @param cell The cell.
210 // * @param indices Array of dof indices on the cell.
211 // */
212 // void get_dof_indices(const CellIterator &cell, unsigned int indices[]);
213 //
214 // /**
215 // * @brief Returns the dof values associated to the @p cell.
216 // *
217 // * @param cell The cell.
218 // * @param values The global vector of values.
219 // * @param local_values Array of values at local dofs.
220 // */
221 // void get_dof_values(const CellIterator &cell, const Vec &values,
222 // double local_values[]);
223 //
224 // /// Destructor.
225 // ~DOFHandler();
226 //
227 //private:
228 //
229 // /**
230 // * @brief Pointer to the finite element class for which the handler
231 // * distributes dofs.
232 // */
233 // FiniteElement<dim,spacedim> *finite_element;
234 //
235 // /**
236 // * @brief Number of dofs associated to geometrical entities.
237 // *
238 // * Global numbers of dofs associated to nodes (object_dofs[0]),
239 // * 1D edges (object_dofs[1]), 2D faces (object_difs[2]) and
240 // * volumes (object_dofs[3]).
241 // */
242 // int ***object_dofs;
243 //
244 //};
245 
246 
247 
249 public:
250 
251  /**
252  * @brief Constructor.
253  * @param _mesh The mesh.
254  */
255  DOFHandlerMultiDim(Mesh &_mesh);
256 
257  /**
258  * @brief Alias for iterator over cells.
259  *
260  * TODO: Notation to be fixed: element or cell
261  */
263 
264  /**
265  * @brief Distributes degrees of freedom on the mesh needed
266  * for the given finite elements.
267  *
268  * The additional parameter @p offset allows to reserve space
269  * for another finite element dofs in the beginning of the
270  * global dof vector.
271  *
272  * @param fe1d The 1D finite element.
273  * @param fe2d The 2D finite element.
274  * @param fe3d The 3D finite element.
275  * @param offset The offset.
276  */
277  void distribute_dofs(FiniteElement<1,3> &fe1d,
278  FiniteElement<2,3> &fe2d,
279  FiniteElement<3,3> &fe3d,
280  const unsigned int offset = 0);
281 
282  /**
283  * @brief Returns the global indices of dofs associated to the @p cell.
284  *
285  * @param cell The cell.
286  * @param indices Array of dof indices on the cell.
287  */
288  void get_dof_indices(const CellIterator &cell, unsigned int indices[]) const override;
289 
290  /**
291  * @brief Returns the indices of dofs associated to the @p cell on the local process.
292  *
293  * @param cell The cell.
294  * @param indices Array of dof indices on the cell.
295  */
296  void get_loc_dof_indices(const CellIterator &cell, unsigned int indices[]) const override;
297 
298  /**
299  * @brief Returns the dof values associated to the @p cell.
300  *
301  * @param cell The cell.
302  * @param values The global vector of values.
303  * @param local_values Array of values at local dofs.
304  */
305  void get_dof_values(const CellIterator &cell, const Vec &values,
306  double local_values[]) const override;
307 
308  /**
309  * @brief Returns the global index of local element.
310  *
311  * @param loc_el Local index of element.
312  */
313  inline int el_index(int loc_el) const { return el_4_loc[loc_el]; }
314 
315  /**
316  * @brief Returns the global index of local edge.
317  *
318  * @param loc_edg Local index of edge.
319  */
320  inline int edge_index(int loc_edg) const { return edg_4_loc[loc_edg]; }
321 
322  /**
323  * @brief Returns the global index of local neighbour.
324  *
325  * @param loc_nb Local index of neighbour.
326  */
327  inline int nb_index(int loc_nb) const { return nb_4_loc[loc_nb]; }
328 
329  /**
330  * @brief Returns number of local edges.
331  */
332  inline unsigned int n_loc_edges() const { return edg_4_loc.size(); }
333 
334  /**
335  * @brief Returns number of local neighbours.
336  */
337  inline unsigned int n_loc_nb() const { return nb_4_loc.size(); }
338 
339  /**
340  * Returns true if element is on local process.
341  * @param index Global element index.
342  */
343  bool el_is_local(int index) const;
344 
345  /// Returns finite element object for given space dimension.
346  template<unsigned int dim>
347  FiniteElement<dim,3> *fe() const;
348 
349  /// Destructor.
350  ~DOFHandlerMultiDim() override;
351 
352 private:
353 
354  /**
355  * @brief Prepare parallel distribution of elements, edges and neighbours.
356  */
357  void make_elem_partitioning();
358 
359  /**
360  * @brief Pointer to the finite element class for which the handler
361  * distributes dofs.
362  */
366 
367  /**
368  * @brief Number of dofs associated to geometrical entities.
369  *
370  * Global numbers of dofs associated to nodes (object_dofs[0]),
371  * 1D edges (object_dofs[1]), 2D faces (object_difs[2]) and
372  * volumes (object_dofs[3]).
373  */
374  int ***object_dofs;
375 
376 
377  /// Global element index -> index according to partitioning
378  int *row_4_el;
379  /// Local element index -> global element index
380  int *el_4_loc;
381  /// Distribution of elements
383 
384  /// Local edge index -> global edge index
386 
387  /// Local neighbour index -> global neighbour index
389 
390 };
391 
392 
393 
394 
395 #endif /* DOFHANDLER_HH_ */
ElementFullIter CellIterator
Alias for iterator over cells.
Definition: dofhandler.hh:262
const unsigned int lsize() const
Returns the number of dofs on the current process.
Definition: dofhandler.hh:72
vector< int > edg_4_loc
Local edge index -> global edge index.
Definition: dofhandler.hh:385
FiniteElement< 3, 3 > * fe3d_
Definition: dofhandler.hh:365
virtual ~DOFHandlerBase()
Destructor.
Definition: dofhandler.hh:110
FiniteElement< 1, 3 > * fe1d_
Pointer to the finite element class for which the handler distributes dofs.
Definition: dofhandler.hh:363
Distribution * el_ds_
Distribution of elements.
Definition: dofhandler.hh:382
Definition: mesh.h:95
unsigned int global_dof_offset
Index of first global dof.
Definition: dofhandler.hh:110
unsigned int n_loc_nb() const
Returns number of local neighbours.
Definition: dofhandler.hh:337
virtual void get_dof_indices(const CellIterator &cell, unsigned int indices[]) const =0
Returns the global indices of dofs associated to the cell.
int el_index(int loc_el) const
Returns the global index of local element.
Definition: dofhandler.hh:313
Mesh * mesh() const
Definition: dofhandler.hh:81
unsigned int lsize_
Number of dofs associated to local process.
Definition: dofhandler.hh:131
const unsigned int loffset() const
Returns the offset of the local part of dofs.
Definition: dofhandler.hh:77
const unsigned int offset() const
Returns the number of the first global dof handled by this DOFHandler.
Definition: dofhandler.hh:67
Mesh * mesh_
Pointer to the mesh to which the dof handler is associated.
Definition: dofhandler.hh:141
int nb_index(int loc_nb) const
Returns the global index of local neighbour.
Definition: dofhandler.hh:327
Provides the numbering of the finite element degrees of freedom on the computational mesh...
Definition: dofhandler.hh:248
virtual void get_loc_dof_indices(const CellIterator &cell, unsigned int indices[]) const =0
Returns the indices of dofs associated to the cell on the local process.
ElementFullIter CellIterator
Alias for iterator over cells.
Definition: dofhandler.hh:46
Distribution * ds_
Distribution of dofs associated to local process.
Definition: dofhandler.hh:146
int *** object_dofs
Number of dofs associated to geometrical entities.
Definition: dofhandler.hh:374
unsigned int n_loc_edges() const
Returns number of local edges.
Definition: dofhandler.hh:332
virtual void get_dof_values(const CellIterator &cell, const Vec &values, double local_values[]) const =0
Returns the dof values associated to the cell.
Support classes for parallel programing.
FiniteElement< 2, 3 > * fe2d_
Definition: dofhandler.hh:364
unsigned int loffset_
Index of the first dof on the local process.
Definition: dofhandler.hh:136
unsigned int n_dofs
Number of global dofs assigned by the handler.
Definition: dofhandler.hh:126
int * row_4_el
Global element index -> index according to partitioning.
Definition: dofhandler.hh:378
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Definition: dofhandler.hh:29
int edge_index(int loc_edg) const
Returns the global index of local edge.
Definition: dofhandler.hh:320
vector< int > nb_4_loc
Local neighbour index -> global neighbour index.
Definition: dofhandler.hh:388
Distribution * distr() const
Definition: dofhandler.hh:79
int * el_4_loc
Local element index -> global element index.
Definition: dofhandler.hh:380
DOFHandlerBase(Mesh &_mesh)
Constructor.
Definition: dofhandler.hh:46
const unsigned int n_global_dofs() const
Getter for the number of all mesh dofs required by the given finite element.
Definition: dofhandler.hh:61