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