Flow123d  DF_patch_fe_darcy_complete-579fe1e
patch_point_values.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 patch_point_values.hh
15  * @brief Store finite element data on the actual patch
16  * such as shape function values, gradients, Jacobian
17  * of the mapping from the reference cell etc.
18  * @author David Flanderka
19  */
20 
21 #ifndef PATCH_POINT_VALUES_HH_
22 #define PATCH_POINT_VALUES_HH_
23 
24 #include <Eigen/Dense>
25 #include <unordered_set>
26 
27 #include "fem/eigen_tools.hh"
29 #include "fem/arena_resource.hh"
30 #include "fem/arena_vec.hh"
31 #include "mesh/accessors.hh"
32 
33 
34 
35 using Scalar = double;
38 
39 
40 /// Distinguishes operations by type and size of output rows
42 {
43  elemOp, ///< operation is evaluated on elements or sides
44  pointOp, ///< operation is evaluated on quadrature points
45  fixedSizeOp ///< operation has fixed size and it is filled during initialization
46 };
47 
48 
49 /// Distinguishes operations by type and size of output rows
51 {
53  side_domain =1
54 };
55 
56 
57 /**
58  * Describes meaning of IntTableArena (of PatchPointValues) rows
59  *
60  * Meaning of domain is element or side
61  */
63 {
64  // field_quad_on_quads =0, ///< Index of quadrature point in ElementCacheMap (field ordering)
65  domain_on_quads =1, ///< Index of bulk element or side for each quadrature point in patch
66  mesh_elem_on_quads =2, ///< Element idx in Mesh for each quadrature point in patch
67  patch_elem_on_domain =3, ///< Index of patch element for each bulk element or side
68  // - last two rows are allocated only for side point table
69  ref_side_on_sides =4, ///< Ref index of side in element for each side in patch
70  ref_side_on_quads =5 ///< Ref index of side in element for each quadrature point in patch
71 };
72 
73 
74 
76 public:
77  /// Default constructor
79 
80  /// Copy constructor
82  : permanent_(other.permanent_), temporary_(other.temporary_) {}
83 
84 
85  /// Declaration of operators
87  permanent_ = other.permanent_;
88  temporary_ = other.temporary_;
89  return *this;
90  }
91 
93  {
94  temporary_++;
95  return (*this);
96  }
97 
98  inline RevertibleValue& operator+= (std::size_t inc_val)
99  {
100  temporary_ += inc_val;
101  return (*this);
102  }
103 
104  inline std::size_t operator() () const
105  {
106  return permanent_;
107  }
108 
109 
110  /// Reset value to zero
111  void reset() {
112  permanent_ = 0;
113  temporary_ = 0;
114  }
115 
116 // /// Revert temporary value.
117 // inline void revert_temporary() {
118 // temporary_ = permanent_;
119 // }
120 
121  /// Finalize temporary value.
122  inline void make_permanent() {
124  }
125 
126 // /// Return temporary value.
127 // inline std::size_t temporary_value() const
128 // {
129 // return temporary_;
130 // }
131 
132 private:
133  std::size_t permanent_;
134  std::size_t temporary_;
135 };
136 
137 
138 template<unsigned int spacedim = 3>
140 
141 
142 
143 /**
144  * v Class for storing FE data of quadrature points on one patch.
145  *
146  * Store data of bulk or side quadrature points of one dimension.
147  */
148 template<unsigned int spacedim = 3>
150 {
151 public:
152  /**
153  * Stores shared data members between PatchFeValues and PatchPoinValues
154  */
155  struct PatchFeData {
156  public:
157  /// Constructor
158  PatchFeData(size_t buffer_size, size_t simd_alignment)
159  : asm_arena_(buffer_size, simd_alignment), patch_arena_(nullptr) {}
160 
161  /// Destructor
163  if (patch_arena_!=nullptr)
164  delete patch_arena_;
165  }
166 
167  AssemblyArena asm_arena_; ///< Assembly arena, created and filled once during initialization
168  PatchArena *patch_arena_; ///< Patch arena, reseted before patch reinit
169  ArenaVec<double> zero_vec_; ///< ArenaVec of zero values of maximal length using in zero PatchPointValues construction
170  };
171 
172  /**
173  * Constructor
174  *
175  * @param dim Set dimension
176  */
178  : elem_dim_list_(elems_dim_list), points_map_(300, 0) {
179  reset();
180 
181  if (domain == bulk_domain) {
182  this->int_sizes_ = {pointOp, pointOp, pointOp, elemOp};
183  } else if (domain == side_domain) {
184  this->int_sizes_ = {pointOp, pointOp, pointOp, elemOp, elemOp, pointOp};
185  }
186  int_table_.resize(int_sizes_.size());
187  }
188 
189  /**
190  * Destructor.
191  */
192  virtual ~PatchPointValues() {}
193 
194  /// Reset number of columns (points and elements)
195  inline void reset() {
197  i_mesh_item_ = 0;
198  elem_dim_list_->clear();
199  n_elems_.clear();
200  side_list_.clear();
201  }
202 
203  /// Getter for n_mesh_items__
204  inline uint n_mesh_items() const {
205  return n_mesh_items_();
206  }
207 
208  /// Resize data tables. Method is called before reinit of patch.
209  void resize_tables(uint max_quad_size, PatchArena &patch_arena) {
210  std::vector<std::size_t> sizes = {n_mesh_items_(), n_mesh_items_()*max_quad_size};
211  for (uint i=0; i<int_table_.rows(); ++i) {
212  int_table_(i) = ArenaVec<uint>(sizes[ int_sizes_[i] ], patch_arena);
213  }
214  }
215 
216  /**
217  * Register bulk point, add to int_table_
218  *
219  * @param patch_elm_idx Index of element on patch (in int_table_).
220  * @param elm_cache_map_idx Index of point in ElementCacheMap.
221  * @param elem_idx Index of element in Mesh.
222  * @param i_point_on_elem Index of point on element
223  */
224  uint register_bulk_point(uint patch_elm_idx, uint elm_cache_map_idx, uint elem_idx, uint i_point_on_elem) {
225  uint point_pos = i_point_on_elem * n_mesh_items() + patch_elm_idx; // index of bulk point on patch
226  //int_table_(field_quad_on_quads)(point_pos) = elm_cache_map_idx;
227  int_table_(domain_on_quads)(point_pos) = patch_elm_idx;
228  int_table_(mesh_elem_on_quads)(point_pos) = elem_idx;
229 
230  points_map_[elm_cache_map_idx] = point_pos;
231  return point_pos;
232  }
233 
234  /**
235  * Register side point, add to int_table_
236  *
237  * @param patch_side_idx Index of side on patch (in int_table_).
238  * @param elm_cache_map_idx Index of point in ElementCacheMap.
239  * @param elem_idx Index of element in Mesh.
240  * @param side_idx Index of side on element.
241  * @param i_point_on_side Index of point on side
242  */
243  uint register_side_point(uint patch_side_idx, uint elm_cache_map_idx, uint elem_idx, uint side_idx, uint i_point_on_side) {
244  uint point_pos = i_point_on_side * n_mesh_items() + patch_side_idx; // index of side point on patch
245  //int_table_(field_quad_on_quads)(point_pos) = elm_cache_map_idx;
246  int_table_(domain_on_quads)(point_pos) = patch_side_idx;
247  int_table_(mesh_elem_on_quads)(point_pos) = elem_idx;
248  int_table_(ref_side_on_quads)(point_pos) = side_idx;
249 
250  points_map_[elm_cache_map_idx] = point_pos;
251  return point_pos;
252  }
253 
254  /// Set number of elements and points as permanent
257  }
258 //protected:
259 
260  /**
261  * Hold integer values of quadrature points of defined operations.
262  *
263  * Table contains following rows:
264  * 0: Index of quadrature point in ElementCacheMap
265  * 1: Index of element (bulk PPV) / side (side PPV) in PatchOp::result_ table to which quadrature point is relevant
266  * 2: Element idx in Mesh
267  * 3. Mapping between short and long element representation (for element)
268  * Or index of element in PatchOp::result_ table to which side is relevant (for side)
269  * - last two rows are allocated only for side point table
270  * 4: Index of side in element - short vector, size of column = number of sides
271  * 5: Index of side in element - long vector, size of column = number of points
272  * Number of used rows is given by int_sizes_.
273  */
275 
276  /// Set size and type of rows of int_table_, value is set implicitly in constructor of descendants
278 
279  ElemDimList<spacedim> *elem_dim_list_; ///< Number and list of elements on patch
280  RevertibleValue n_mesh_items_; ///< Number of elements or sides in patch
281  uint i_mesh_item_; ///< Index of registered element or side in table, helper value used during patch creating
282  std::vector<uint> points_map_; ///< Map of point patch indices to PatchOp::result_ and int_table_ tables
283 
284  /**
285  * Holds map of idx of registered elements and its idx in bulk PatchPointValues, data member ensures control of duplicity
286  *
287  * TODO will be deleted after sorting elements in ElementCacheMap by dimension
288  */
289  std::unordered_map<uint, uint> n_elems_;
290  std::vector<Side> side_list_; ///< List of sides on patch
291 };
292 
293 
294 
295 #endif /* PATCH_POINT_VALUES_HH_ */
RevertibleValue n_mesh_items_
Number of elements or sides in patch.
void resize_tables(uint max_quad_size, PatchArena &patch_arena)
Resize data tables. Method is called before reinit of patch.
std::vector< uint > points_map_
Map of point patch indices to PatchOp::result_ and int_table_ tables.
uint register_bulk_point(uint patch_elm_idx, uint elm_cache_map_idx, uint elem_idx, uint i_point_on_elem)
uint n_mesh_items() const
Getter for n_mesh_items__.
ElemDimList< spacedim > * elem_dim_list_
Number and list of elements on patch.
void reset()
Reset number of columns (points and elements)
uint i_mesh_item_
Index of registered element or side in table, helper value used during patch creating.
uint register_side_point(uint patch_side_idx, uint elm_cache_map_idx, uint elem_idx, uint side_idx, uint i_point_on_side)
IntTableArena int_table_
std::vector< Side > side_list_
List of sides on patch.
PatchPointValues(ElemDimList< spacedim > *elems_dim_list, fem_domain domain)
std::unordered_map< uint, uint > n_elems_
std::vector< OpSizeType > int_sizes_
Set size and type of rows of int_table_, value is set implicitly in constructor of descendants.
void make_permanent_mesh_items()
Set number of elements and points as permanent.
Store finite element data on the actual patch such as shape function values, gradients,...
Eigen::Vector< ArenaVec< uint >, Eigen::Dynamic > IntTableArena
Definition: eigen_tools.hh:39
unsigned int uint
double Scalar
Definition: op_accessors.hh:25
IntTableRows
@ domain_on_quads
Index of bulk element or side for each quadrature point in patch.
@ patch_elem_on_domain
Index of patch element for each bulk element or side.
@ ref_side_on_sides
Ref index of side in element for each side in patch.
@ mesh_elem_on_quads
Element idx in Mesh for each quadrature point in patch.
@ ref_side_on_quads
Ref index of side in element for each quadrature point in patch.
fem_domain
Distinguishes operations by type and size of output rows.
@ bulk_domain
@ side_domain
OpSizeType
Distinguishes operations by type and size of output rows.
@ pointOp
operation is evaluated on quadrature points
@ elemOp
operation is evaluated on elements or sides
@ fixedSizeOp
operation has fixed size and it is filled during initialization
Definitions of particular quadrature rules on simplices.
AssemblyArena asm_arena_
Assembly arena, created and filled once during initialization.
ArenaVec< double > zero_vec_
ArenaVec of zero values of maximal length using in zero PatchPointValues construction.
PatchFeData(size_t buffer_size, size_t simd_alignment)
Constructor.
PatchArena * patch_arena_
Patch arena, reseted before patch reinit.
RevertibleValue & operator++()
RevertibleValue()
Default constructor.
RevertibleValue & operator=(RevertibleValue &other)
Declaration of operators.
RevertibleValue(const RevertibleValue &other)
Copy constructor.
void reset()
Reset value to zero.
std::size_t operator()() const
RevertibleValue & operator+=(std::size_t inc_val)
void make_permanent()
Finalize temporary value.