Flow123d  release_3.0.0-680-gbed5aba
dh_cell_accessor.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 dh_cell_accessor.hh
15  * @brief
16  * @author David Flanderka
17  */
18 
19 #ifndef DH_CELL_ACCESSOR_HH_
20 #define DH_CELL_ACCESSOR_HH_
21 
22 #include "mesh/accessors.hh"
23 #include "fem/dofhandler.hh"
24 
25 /**
26  * Cell accessor allow iterate over DOF handler cells.
27  *
28  * Iterating is possible over different ranges of local and ghost elements.
29  */
31 public:
32  /**
33  * Default invalid accessor.
34  */
36  : dof_handler_(NULL)
37  {}
38 
39  /**
40  * DOF cell accessor.
41  */
42  DHCellAccessor(const DOFHandlerMultiDim *dof_handler, unsigned int loc_idx)
43  : dof_handler_(dof_handler), loc_ele_idx_(loc_idx)
44  {}
45 
46  /// Return local index to element (index of DOF handler).
47  inline unsigned int local_idx() const {
48  ASSERT_LT_DBG(loc_ele_idx_, dof_handler_->el_ds_->lsize()).error("Method 'local_idx()' can't be used for ghost cells!\n");
49  return loc_ele_idx_;
50  }
51 
52  /// Return serial idx to element of loc_ele_idx_.
53  inline unsigned int elm_idx() const {
54  unsigned int ds_lsize = dof_handler_->el_ds_->lsize();
55  if (loc_ele_idx_<ds_lsize) return dof_handler_->el_index(loc_ele_idx_); //own elements
56  else return dof_handler_->ghost_4_loc[loc_ele_idx_-ds_lsize]; //ghost elements
57  }
58 
59  /// Return ElementAccessor to element of loc_ele_idx_.
60  inline const ElementAccessor<3> elm() const {
61  return dof_handler_->mesh()->element_accessor( elm_idx() );
62  }
63 
64  /**
65  * @brief Fill vector of the global indices of dofs associated to the cell.
66  *
67  * @param indices Vector of dof indices on the cell.
68  */
69  unsigned int get_dof_indices(std::vector<int> &indices) const;
70 
71  /**
72  * @brief Returns the indices of dofs associated to the cell on the local process.
73  *
74  * @param indices Array of dof indices on the cell.
75  */
76  unsigned int get_loc_dof_indices(std::vector<LongIdx> &indices) const;
77 
78  /// Return number of dofs on given cell.
79  unsigned int n_dofs() const;
80 
81  /**
82  * @brief Return dof on a given cell.
83  * @param idof Number of dof on the cell.
84  */
85  const Dof &cell_dof(unsigned int idof) const;
86 
87  /// Return dimension of element appropriate to cell.
88  inline unsigned int dim() const {
89  return elm().dim();
90  }
91 
92  /**
93  * @brief Returns finite element object for given space dimension.
94  */
95  template<unsigned int dim>
97  ElementAccessor<3> elm_acc = this->elm();
98  return dof_handler_->ds_->fe<dim>(elm_acc);
99  }
100 
101  /// Iterates to next local element.
102  inline void inc() {
103  loc_ele_idx_++;
104  }
105 
106  /// Comparison of accessors.
107  bool operator==(const DHCellAccessor& other) {
108  return (loc_ele_idx_ == other.loc_ele_idx_);
109  }
110 
111 private:
112  /// Pointer to the DOF handler owning the element.
114  /// Index into DOFHandler::el_4_loc array.
115  unsigned int loc_ele_idx_;
116 };
117 
118 
119 inline unsigned int DHCellAccessor::get_dof_indices(std::vector<int> &indices) const
120 {
121  unsigned int elem_idx = this->elm_idx();
123  unsigned int ndofs = 0;
125  for (unsigned int k=0; k<ndofs; k++)
127 
128  return ndofs;
129 }
130 
131 
133 {
134  unsigned int elem_idx = this->elm_idx();
135  unsigned int ndofs = 0;
137  for (unsigned int k=0; k<ndofs; k++)
138  indices[k] = dof_handler_->cell_starts[dof_handler_->row_4_el[elem_idx]]+k;
139 
140  return ndofs;
141 }
142 
143 
144 inline unsigned int DHCellAccessor::n_dofs() const
145 {
146  switch (this->dim()) {
147  case 1:
148  return fe<1>()->n_dofs();
149  break;
150  case 2:
151  return fe<2>()->n_dofs();
152  break;
153  case 3:
154  return fe<3>()->n_dofs();
155  break;
156  }
157 }
158 
159 
160 inline const Dof &DHCellAccessor::cell_dof(unsigned int idof) const
161 {
162  switch (this->dim())
163  {
164  case 1:
165  return fe<1>()->dof(idof);
166  break;
167  case 2:
168  return fe<2>()->dof(idof);
169  break;
170  case 3:
171  return fe<3>()->dof(idof);
172  break;
173  }
174 }
175 
176 
177 #endif /* DH_CELL_ACCESSOR_HH_ */
const Dof & cell_dof(unsigned int idof) const
Return dof on a given cell.
Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between loca...
unsigned int elm_idx() const
Return serial idx to element of loc_ele_idx_.
void inc()
Iterates to next local element.
unsigned int get_loc_dof_indices(std::vector< LongIdx > &indices) const
Returns the indices of dofs associated to the cell on the local process.
Distribution * el_ds_
Distribution of elements.
Definition: dofhandler.hh:425
unsigned int dim() const
Return dimension of element appropriate to cell.
unsigned int local_idx() const
Return local index to element (index of DOF handler).
FiniteElement< dim > * fe() const
Returns finite element object for given space dimension.
const DOFHandlerMultiDim * dof_handler_
Pointer to the DOF handler owning the element.
int el_index(int loc_el) const
Returns the global index of local element.
Definition: dofhandler.hh:217
Mesh * mesh() const
Returns the mesh.
Definition: dofhandler.hh:81
unsigned int n_dofs() const
Return number of dofs on given cell.
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:719
std::vector< LongIdx > cell_starts
Starting indices for element dofs.
Definition: dofhandler.hh:400
const ElementAccessor< 3 > elm() const
Return ElementAccessor to element of loc_ele_idx_.
std::vector< LongIdx > dof_indices
Dof numbers on local and ghost elements.
Definition: dofhandler.hh:408
Provides the numbering of the finite element degrees of freedom on the computational mesh...
Definition: dofhandler.hh:155
DHCellAccessor(const DOFHandlerMultiDim *dof_handler, unsigned int loc_idx)
vector< LongIdx > ghost_4_loc
Indices of ghost cells (neighbouring with local elements).
Definition: dofhandler.hh:437
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
Definition: asserts.hh:295
std::shared_ptr< DiscreteSpace > ds_
Pointer to the discrete space for which the handler distributes dofs.
Definition: dofhandler.hh:374
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
unsigned int dim() const
Definition: accessors.hh:87
bool operator==(const DHCellAccessor &other)
Comparison of accessors.
unsigned int get_dof_indices(std::vector< int > &indices) const
Fill vector of the global indices of dofs associated to the cell.
LongIdx * row_4_el
Global element index -> index according to partitioning.
Definition: dofhandler.hh:419
unsigned int loc_ele_idx_
Index into DOFHandler::el_4_loc array.
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:299
unsigned int lsize(int proc) const
get local size