Flow123d  JS_before_hm-979-g397e552
eval_subset.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 eval_subset.hh
15  * @brief
16  * @author David Flanderka
17  */
18 
19 #ifndef EVAL_SUBSET_HH_
20 #define EVAL_SUBSET_HH_
21 
22 #include <memory>
23 #include <armadillo>
24 #include "fields/eval_points.hh"
26 #include "mesh/range_wrapper.hh"
27 #include "fem/dh_cell_accessor.hh"
28 
29 
30 class Side;
31 class BulkPoint;
32 class EdgePoint;
33 
34 
35 /**
36  * Base integral class holds common data members and methods.
37  */
38 class BaseIntegral {
39 public:
40  TYPEDEF_ERR_INFO(EI_ElementIdx, unsigned int);
41  DECLARE_EXCEPTION(ExcElementNotInCache,
42  << "Element of Idx: " << EI_ElementIdx::val << " is not stored in 'Field value data cache'.\n"
43  << "Value can't be computed.\n");
44 
45  /// Default constructor
46  BaseIntegral() : eval_points_(nullptr), dim_(0) {}
47 
48  /// Constructor of bulk (n_permutations==0) or side subset
49  BaseIntegral(std::shared_ptr<EvalPoints> eval_points, unsigned int dim)
50  : eval_points_(eval_points), dim_(dim) {}
51 
52  /// Destructor
53  virtual ~BaseIntegral();
54 
55  /// Getter of eval_points
56  std::shared_ptr<EvalPoints> eval_points() const {
57  return eval_points_;
58  }
59 
60  /// Returns dimension.
61  unsigned int dim() const {
62  return dim_;
63  }
64 protected:
65  /// Pointer to EvalPoints
66  std::shared_ptr<EvalPoints> eval_points_;
67  /// Dimension of points
68  unsigned int dim_;
69 };
70 
71 /**
72  * Integral class of bulk points, allows assemblation of volume integrals.
73  */
74 class BulkIntegral : public BaseIntegral, public std::enable_shared_from_this<BulkIntegral> {
75 public:
76  /// Default constructor
78 
79  /// Constructor of bulk integral
80  BulkIntegral(std::shared_ptr<EvalPoints> eval_points, unsigned int dim)
81  : BaseIntegral(eval_points, dim), subset_index_(eval_points->n_subsets(dim)) {}
82 
83  /// Destructor
84  ~BulkIntegral();
85 
86  /// Return index of data block according to subset in EvalPoints object
87  int get_subset_idx() const {
88  return subset_index_;
89  }
90 
91  /// Returns range of bulk local points for appropriate cell accessor
92  Range< BulkPoint > points(const DHCellAccessor &cell, const ElementCacheMap *elm_cache_map) const;
93 
94 private:
95  /// Index of data block according to subset in EvalPoints object.
96  unsigned int subset_index_;
97 };
98 
99 /**
100  * Integral class of side points, allows assemblation of element - element fluxes.
101  */
102 class EdgeIntegral : public BaseIntegral, public std::enable_shared_from_this<EdgeIntegral> {
103 public:
104  /// Default constructor
105  EdgeIntegral() : BaseIntegral(), perm_indices_(nullptr), n_permutations_(0) {}
106 
107  /// Constructor of edge integral
108  EdgeIntegral(std::shared_ptr<EvalPoints> eval_points, unsigned int dim, unsigned int n_permutations, unsigned int points_per_side);
109 
110  /// Destructor
111  ~EdgeIntegral();
112 
113  /// Getter of n_sides
114  unsigned int n_sides() const {
115  return n_sides_;
116  }
117 
118  /// Return index of data block according to subset in EvalPoints object
119  int get_subset_idx() const {
120  return subset_index_;
121  }
122 
123  /// Returns range of side local points for appropriate cell side accessor
124  Range< EdgePoint > points(const DHCellSide &cell_side, const ElementCacheMap *elm_cache_map) const;
125 
126  /// Returns structure of permutation indices.
127  int perm_idx_ptr(uint i_side, uint i_perm, uint i_point) const {
128  return perm_indices_[i_side][i_perm][i_point];
129  }
130 
131 private:
132  /// Index of data block according to subset in EvalPoints object.
133  unsigned int subset_index_;
134  /// Indices to EvalPoints for different sides and permutations reflecting order of points.
135  unsigned int*** perm_indices_;
136  /// Number of sides (value 0 indicates bulk set)
137  unsigned int n_sides_;
138  /// Number of permutations (value 0 indicates bulk set)
139  unsigned int n_permutations_;
140 
141  friend class EvalPoints;
142  friend class EdgePoint;
143 };
144 
145 /**
146  * Integral class of neighbour points, allows assemblation of element - side fluxes.
147  *
148  * Dimension corresponds with element of higher dim.
149  */
150 class CouplingIntegral : public BaseIntegral, public std::enable_shared_from_this<CouplingIntegral> {
151 public:
152  /// Default constructor
154 
155  /// Constructor of ngh integral
156  CouplingIntegral(std::shared_ptr<EdgeIntegral> edge_integral, std::shared_ptr<BulkIntegral> bulk_integral);
157 
158  /// Destructor
159  ~CouplingIntegral();
160 
161  /// Return index of data block according to subset of higher dim in EvalPoints object
162  int get_subset_high_idx() const {
163  return edge_integral_->get_subset_idx();
164  }
165 
166  /// Return index of data block according to subset of lower dim in EvalPoints object
167  int get_subset_low_idx() const {
168  return bulk_integral_->get_subset_idx();
169  }
170 
171  /// Returns range of bulk local points for appropriate cell accessor
172  Range< BulkPoint > points(const DHCellAccessor &cell, const ElementCacheMap *elm_cache_map) const;
173 
174  /// Returns range of side local points for appropriate cell side accessor
175  Range< EdgePoint > points(const DHCellSide &cell_side, const ElementCacheMap *elm_cache_map) const;
176 
177 private:
178  /// Integral according to side subset part (element of higher dim) in EvalPoints object.
179  std::shared_ptr<EdgeIntegral> edge_integral_;
180  /// Integral according to bulk subset part (element of lower dim) in EvalPoints object.
181  std::shared_ptr<BulkIntegral> bulk_integral_;
182 };
183 
184 /**
185  * Integral class of boundary points, allows assemblation of fluxes between sides and neighbouring boundary elements.
186  */
188 public:
189  /// Default constructor
191 
192  /// Constructor of bulk subset
193  BoundaryIntegral(std::shared_ptr<EdgeIntegral> edge_integral);
194 
195  /// Destructor
196  ~BoundaryIntegral();
197 
198  /// Return index of data block according to subset in EvalPoints object
199  int get_subset_idx() const {
200  return edge_integral_->get_subset_idx();
201  }
202 
203  /// Returns range of bulk local points for appropriate cell accessor
204  Range< EdgePoint > points(const DHCellSide &cell_side, const ElementCacheMap *elm_cache_map) const;
205 
206 private:
207  /// Boundary integral according to edge integral (? but need own special data members and methods ?).
208  std::shared_ptr<EdgeIntegral> edge_integral_;
209 };
210 
211 
212 /**
213  * @brief Point accessor allow iterate over bulk quadrature points defined in local element coordinates.
214  */
215 class BulkPoint {
216 public:
217  /// Default constructor
219  : local_point_idx_(0) {}
220 
221  /// Constructor
222  BulkPoint(DHCellAccessor dh_cell, const ElementCacheMap *elm_cache_map, std::shared_ptr<const BulkIntegral> bulk_integral, unsigned int loc_point_idx)
223  : dh_cell_(dh_cell), integral_(bulk_integral), local_point_idx_(loc_point_idx), elm_cache_map_(elm_cache_map) {}
224 
225  /// Getter of BulkIntegral
226  std::shared_ptr<const BulkIntegral> integral() const {
227  return integral_;
228  }
229 
230  /// Getter of EvalPoints
231  std::shared_ptr<EvalPoints> eval_points() const {
232  return integral_->eval_points();
233  }
234 
235  /// Local coordinates within element
236  template<unsigned int dim>
237  inline arma::vec::fixed<dim> loc_coords() const {
238  return this->eval_points()->local_point<dim>( local_point_idx_ );
239  }
240 
241  // Global coordinates within element
242  //arma::vec3 coords() const;
243 
244  /// Return index of element in data cache.
245  unsigned int element_cache_index() const {
246  return dh_cell_.element_cache_index();
247  }
248 
249  /// Return DH cell accessor.
251  return dh_cell_;
252  }
253 
254  // Index of permutation
255  inline const ElementCacheMap *elm_cache_map() const {
256  return elm_cache_map_;
257  }
258 
259  /// Return index in EvalPoints object
260  unsigned int eval_point_idx() const {
261  return local_point_idx_;
262  }
263 
264  /// Iterates to next point.
265  void inc() {
266  local_point_idx_++;
267  }
268 
269  /// Comparison of accessors.
270  bool operator==(const BulkPoint& other) {
271  return (dh_cell_ == other.dh_cell_) && (local_point_idx_ == other.local_point_idx_);
272  }
273 
274 private:
275  /// DOF handler accessor of element.
277  /// Pointer to bulk integral.
278  std::shared_ptr<const BulkIntegral> integral_;
279  /// Index of the local point in bulk point set.
280  unsigned int local_point_idx_;
281  /// Pointer ElementCacheMap needed for point evaluation.
283 };
284 
285 
286 /**
287  * @brief Point accessor allow iterate over quadrature points of given side defined in local element coordinates.
288  */
289 class EdgePoint {
290 public:
291  /// Default constructor
293  : local_point_idx_(0), elm_cache_map_(nullptr) {}
294 
295  /// Constructor
296  EdgePoint(DHCellSide cell_side, const ElementCacheMap *elm_cache_map, std::shared_ptr<const EdgeIntegral> edge_integral, unsigned int local_point_idx)
297  : cell_side_(cell_side), integral_(edge_integral), local_point_idx_(local_point_idx),
298  permutation_idx_( cell_side.element()->permutation_idx( cell_side_.side_idx() ) ), elm_cache_map_(elm_cache_map) {}
299 
300  /// Getter of EdgeIntegral
301  std::shared_ptr<const EdgeIntegral> integral() const {
302  return integral_;
303  }
304 
305  /// Getter of evaluation points
306  std::shared_ptr<EvalPoints> eval_points() const {
307  return integral_->eval_points();
308  }
309 
310  // Local coordinates within element
311  template<unsigned int dim>
312  inline arma::vec::fixed<dim> loc_coords() const {
313  return this->eval_points()->local_point<dim>( this->eval_point_idx() );
314  }
315 
316  // Global coordinates within element
317  //arma::vec3 coords() const;
318 
319  /// Return index of element in data cache.
320  unsigned int element_cache_index() const {
321  return cell_side_.cell().element_cache_index();
322  }
323 
324  /// Return DH cell accessor.
326  return cell_side_;
327  }
328 
329  // Index of permutation
330  unsigned int permutation_idx() const {
331  return permutation_idx_;
332  }
333 
334  // Index of permutation
335  inline const ElementCacheMap *elm_cache_map() const {
336  return elm_cache_map_;
337  }
338 
339  /// Return index in EvalPoints object
340  unsigned int eval_point_idx() const {
341  return integral_->perm_idx_ptr(cell_side_.side_idx(), permutation_idx_, local_point_idx_);
342  }
343 
344  /// Return corresponds EdgePoint of neighbour side of same dimension (computing of side integrals).
345  EdgePoint permute(DHCellSide edg_side) const;
346 
347  /// Iterates to next point.
348  void inc() {
349  local_point_idx_++;
350  }
351 
352  /// Comparison of accessors.
353  bool operator==(const EdgePoint& other) {
354  return (cell_side_ == other.cell_side_) && (local_point_idx_ == other.local_point_idx_);
355  }
356 
357 private:
358  /// DOF handler accessor of element side.
360  /// Pointer to edge point set
361  std::shared_ptr<const EdgeIntegral> integral_;
362  /// Index of the local point in the composed quadrature.
363  unsigned int local_point_idx_;
364  /// Permutation index corresponding with DHCellSide
365  unsigned int permutation_idx_;
366  /// Pointer ElementCacheMap needed for point evaluation.
368 };
369 
370 
371 
372 #endif /* EVAL_SUBSET_HH_ */
std::shared_ptr< const EdgeIntegral > integral_
Pointer to edge point set.
Definition: eval_subset.hh:361
std::shared_ptr< EdgeIntegral > edge_integral_
Integral according to side subset part (element of higher dim) in EvalPoints object.
Definition: eval_subset.hh:179
unsigned int n_sides() const
Getter of n_sides.
Definition: eval_subset.hh:114
const ElementCacheMap * elm_cache_map() const
Definition: eval_subset.hh:335
Point accessor allow iterate over bulk quadrature points defined in local element coordinates...
Definition: eval_subset.hh:215
unsigned int uint
void inc()
Iterates to next point.
Definition: eval_subset.hh:348
Point accessor allow iterate over quadrature points of given side defined in local element coordinate...
Definition: eval_subset.hh:289
int get_subset_idx() const
Return index of data block according to subset in EvalPoints object.
Definition: eval_subset.hh:119
unsigned int dim() const
Returns dimension.
Definition: eval_subset.hh:61
int perm_idx_ptr(uint i_side, uint i_perm, uint i_point) const
Returns structure of permutation indices.
Definition: eval_subset.hh:127
const ElementCacheMap * elm_cache_map_
Pointer ElementCacheMap needed for point evaluation.
Definition: eval_subset.hh:367
DHCellAccessor dh_cell() const
Return DH cell accessor.
Definition: eval_subset.hh:250
BulkPoint()
Default constructor.
Definition: eval_subset.hh:218
BulkIntegral()
Default constructor.
Definition: eval_subset.hh:77
EdgePoint(DHCellSide cell_side, const ElementCacheMap *elm_cache_map, std::shared_ptr< const EdgeIntegral > edge_integral, unsigned int local_point_idx)
Constructor.
Definition: eval_subset.hh:296
int get_subset_low_idx() const
Return index of data block according to subset of lower dim in EvalPoints object. ...
Definition: eval_subset.hh:167
int get_subset_idx() const
Return index of data block according to subset in EvalPoints object.
Definition: eval_subset.hh:87
Directing class of FieldValueCache.
Cell accessor allow iterate over DOF handler cells.
unsigned int eval_point_idx() const
Return index in EvalPoints object.
Definition: eval_subset.hh:340
BaseIntegral()
Default constructor.
Definition: eval_subset.hh:46
unsigned int permutation_idx() const
Definition: eval_subset.hh:330
unsigned int element_cache_index() const
Return index of element in data cache.
Definition: eval_subset.hh:320
bool operator==(const EdgePoint &other)
Comparison of accessors.
Definition: eval_subset.hh:353
DHCellSide dh_cell_side() const
Return DH cell accessor.
Definition: eval_subset.hh:325
std::shared_ptr< EvalPoints > eval_points_
Pointer to EvalPoints.
Definition: eval_subset.hh:66
DHCellAccessor dh_cell_
DOF handler accessor of element.
Definition: eval_subset.hh:276
std::shared_ptr< const EdgeIntegral > integral() const
Getter of EdgeIntegral.
Definition: eval_subset.hh:301
unsigned int eval_point_idx() const
Return index in EvalPoints object.
Definition: eval_subset.hh:260
std::shared_ptr< EdgeIntegral > edge_integral_
Boundary integral according to edge integral (? but need own special data members and methods ...
Definition: eval_subset.hh:208
std::shared_ptr< BulkIntegral > bulk_integral_
Integral according to bulk subset part (element of lower dim) in EvalPoints object.
Definition: eval_subset.hh:181
unsigned int dim_
Dimension of points.
Definition: eval_subset.hh:68
unsigned int *** perm_indices_
Indices to EvalPoints for different sides and permutations reflecting order of points.
Definition: eval_subset.hh:135
int get_subset_high_idx() const
Return index of data block according to subset of higher dim in EvalPoints object.
Definition: eval_subset.hh:162
BaseIntegral(std::shared_ptr< EvalPoints > eval_points, unsigned int dim)
Constructor of bulk (n_permutations==0) or side subset.
Definition: eval_subset.hh:49
Range helper class.
bool operator==(const BulkPoint &other)
Comparison of accessors.
Definition: eval_subset.hh:270
unsigned int local_point_idx_
Index of the local point in the composed quadrature.
Definition: eval_subset.hh:363
unsigned int subset_index_
Index of data block according to subset in EvalPoints object.
Definition: eval_subset.hh:133
std::shared_ptr< const BulkIntegral > integral() const
Getter of BulkIntegral.
Definition: eval_subset.hh:226
unsigned int element_cache_index() const
Return index of element in data cache.
Definition: eval_subset.hh:245
void inc()
Iterates to next point.
Definition: eval_subset.hh:265
CouplingIntegral()
Default constructor.
Definition: eval_subset.hh:153
std::shared_ptr< EvalPoints > eval_points() const
Getter of EvalPoints.
Definition: eval_subset.hh:231
unsigned int local_point_idx_
Index of the local point in bulk point set.
Definition: eval_subset.hh:280
unsigned int n_permutations_
Number of permutations (value 0 indicates bulk set)
Definition: eval_subset.hh:139
unsigned int permutation_idx_
Permutation index corresponding with DHCellSide.
Definition: eval_subset.hh:365
unsigned int subset_index_
Index of data block according to subset in EvalPoints object.
Definition: eval_subset.hh:96
virtual ~BaseIntegral()
Destructor.
Definition: eval_subset.cc:28
const ElementCacheMap * elm_cache_map() const
Definition: eval_subset.hh:255
arma::vec::fixed< dim > loc_coords() const
Local coordinates within element.
Definition: eval_subset.hh:237
arma::vec::fixed< dim > loc_coords() const
Definition: eval_subset.hh:312
TYPEDEF_ERR_INFO(EI_ElementIdx, unsigned int)
BulkIntegral(std::shared_ptr< EvalPoints > eval_points, unsigned int dim)
Constructor of bulk integral.
Definition: eval_subset.hh:80
Class holds local coordinations of evaluating points (bulk and sides) specified by element dimension...
Definition: eval_points.hh:43
std::shared_ptr< EvalPoints > eval_points() const
Getter of evaluation points.
Definition: eval_subset.hh:306
unsigned int n_sides_
Number of sides (value 0 indicates bulk set)
Definition: eval_subset.hh:137
BulkPoint(DHCellAccessor dh_cell, const ElementCacheMap *elm_cache_map, std::shared_ptr< const BulkIntegral > bulk_integral, unsigned int loc_point_idx)
Constructor.
Definition: eval_subset.hh:222
std::shared_ptr< const BulkIntegral > integral_
Pointer to bulk integral.
Definition: eval_subset.hh:278
BoundaryIntegral()
Default constructor.
Definition: eval_subset.hh:190
DECLARE_EXCEPTION(ExcElementNotInCache,<< "Element of Idx: "<< EI_ElementIdx::val<< " is not stored in 'Field value data cache'.\n"<< "Value can't be computed.\n")
const ElementCacheMap * elm_cache_map_
Pointer ElementCacheMap needed for point evaluation.
Definition: eval_subset.hh:282
EdgeIntegral()
Default constructor.
Definition: eval_subset.hh:105
int get_subset_idx() const
Return index of data block according to subset in EvalPoints object.
Definition: eval_subset.hh:199
DHCellSide cell_side_
DOF handler accessor of element side.
Definition: eval_subset.hh:359
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points.
Definition: eval_subset.hh:56
EdgePoint()
Default constructor.
Definition: eval_subset.hh:292
Implementation of range helper class.
Side accessor allows to iterate over sides of DOF handler cell.