Flow123d  DF_patch_fe_darcy_complete-579fe1e
integral_data.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 integral_data.hh
15  * @brief
16  * @author David Flanderka
17  */
18 
19 #ifndef INTEGRAL_DATA_HH_
20 #define INTEGRAL_DATA_HH_
21 
22 #include <vector>
23 #include <memory>
24 #include <armadillo>
25 #include <unordered_set>
26 #include <unordered_map>
27 #include <boost/functional/hash.hpp> // for boost::hash_value
28 #include "fem/dh_cell_accessor.hh"
29 #include "tools/revertable_list.hh"
30 #include "mesh/range_wrapper.hh"
31 
32 template <unsigned int dim> class BulkIntegralAcc;
33 template <unsigned int dim> class EdgeIntegralAcc;
34 template <unsigned int dim> class CouplingIntegralAcc;
35 template <unsigned int dim> class BoundaryIntegralAcc;
36 template <int spacedim> class ElementAccessor;
37 
38 
39 
40 /**
41  * Helper structure holds data of cell (bulk) integral
42  *
43  * Data is specified by cell and subset index in EvalPoint object
44  */
46  /// Default constructor
48 
49  /// Constructor with data mebers initialization
50  BulkIntegralData(DHCellAccessor dhcell, unsigned int subset_idx)
51  : cell(dhcell), subset_index(subset_idx) {}
52 
53  /// Copy constructor
55  : cell(other.cell), subset_index(other.subset_index) {}
56 
57  DHCellAccessor cell; ///< Specified cell (element)
58  unsigned int subset_index; ///< Index (order) of subset in EvalPoints object
59 };
60 
61 /**
62  * Helper structure holds data of edge integral
63  *
64  * Data is specified by side and subset index in EvalPoint object
65  */
67  /// Default constructor
70 
71  /// Copy constructor
74 
75  /// Constructor with data mebers initialization
77  : edge_side_range(range), subset_index(subset_idx) {}
78 
79  RangeConvert<DHEdgeSide, DHCellSide> edge_side_range; ///< Specified cell side (element)
80  unsigned int subset_index; ///< Index (order) of subset in EvalPoints object
81 };
82 
83 /**
84  * Helper structure holds data of neighbour (coupling) integral
85  *
86  * Data is specified by cell, side and their subset indices in EvalPoint object
87  */
89  /// Default constructor
91 
92  /// Constructor with data mebers initialization
93  CouplingIntegralData(DHCellAccessor dhcell, unsigned int bulk_idx, DHCellSide dhside, unsigned int side_idx)
94  : cell(dhcell), bulk_subset_index(bulk_idx), side(dhside), side_subset_index(side_idx) {}
95 
96  /// Copy constructor
99 
101  unsigned int bulk_subset_index; ///< Index (order) of lower dim subset in EvalPoints object
102  DHCellSide side; ///< Specified cell side (higher dim element)
103  unsigned int side_subset_index; ///< Index (order) of higher dim subset in EvalPoints object
104 };
105 
106 /**
107  * Helper structure holds data of boundary integral
108  *
109  * Data is specified by side and subset indices of side and appropriate boundary element in EvalPoint object
110  */
112  /// Default constructor
114 
115  /// Constructor with data mebers initialization
116  BoundaryIntegralData(unsigned int bdr_idx, DHCellSide dhside, unsigned int side_idx)
117  : bdr_subset_index(bdr_idx), side(dhside), side_subset_index(side_idx) {}
118 
119  /// Copy constructor
122 
123  // We don't need hold ElementAccessor of boundary element, side.cond().element_accessor() provides it.
124  unsigned int bdr_subset_index; ///< Index (order) of subset on boundary element in EvalPoints object
125  DHCellSide side; ///< Specified cell side (bulk element)
126  unsigned int side_subset_index; ///< Index (order) of subset on side of bulk element in EvalPoints object
127 };
128 
129 
130 /**
131  * Define vector of RevertableLists.
132  *
133  * Used in IntegralData structure and in AssemblyBase for sorting integral data of integrals
134  * with different quadrature order of same type to separate RevertableLists
135  */
136 template<class Type>
138 public:
139  /// Default constructor
141  {}
142 
143  /// Constructor, initialize vec_list_
145  : vec_list_(size) {}
146 
147  /// Set size of vec_list_
148  void set_size(uint new_size) {
149  ASSERT_GE(new_size, vec_list_.size());
150  vec_list_.resize(new_size);
151  }
152 
153  /// Finalize temporary part of data.
154  inline void make_permanent()
155  {
156  for (auto &rl : vec_list_) rl.make_permanent();
157  }
158 
159  /// Erase temporary part of data.
160  inline void revert_temporary()
161  {
162  for (auto &rl : vec_list_) rl.revert_temporary();
163  }
164 
165  /// Clear the list.
166  inline void reset()
167  {
168  for (auto &rl : vec_list_) rl.reset();
169  }
170 
171  inline RevertableList<Type> & operator[](std::size_t item) {
172  return vec_list_[item];
173  }
174 
175  inline const RevertableList<Type> & operator[](std::size_t item) const {
176  return vec_list_[item];
177  }
178 
179 private:
181 };
182 
183 
184 /// Set of integral data of given dimension used in assemblation
185 struct IntegralData {
186 public:
187  RevertableListVector<BulkIntegralData> bulk_; ///< Holds data for computing bulk integrals.
188  RevertableListVector<EdgeIntegralData> edge_; ///< Holds data for computing edge integrals.
189  RevertableListVector<CouplingIntegralData> coupling_; ///< Holds data for computing couplings integrals.
190  RevertableListVector<BoundaryIntegralData> boundary_; ///< Holds data for computing boundary integrals.
191 };
192 
193 
194 
195 
196 
197 /// Define Integral Tuple hash function - helper struct of IntegralPtrMap
199  std::size_t operator()(std::tuple<uint, uint> tpl) const {
200  return boost::hash_value( tpl );
201  }
202 
203  /// Create tuple from dimennsion and size of Quadrature
204  static std::tuple<uint, uint> integral_tuple(uint dim, uint quad_size) {
205  return std::make_tuple(dim, quad_size);
206  }
207 
208 };
209 
210 /// Alias for unordered_map of shared_ptr<Integral> with custom hash
211 template<typename Integral>
212 using IntegralPtrMap = std::unordered_map<std::tuple<uint, uint>, std::shared_ptr<Integral>, IntegralTplHash>;
213 
214 
215 /// Set of integral of given dimension necessary in assemblation
216 template<unsigned int dim>
217 struct DimIntegrals {
218  IntegralPtrMap<BulkIntegralAcc<dim>> bulk_; ///< Bulk integrals of elements
219  IntegralPtrMap<EdgeIntegralAcc<dim>> edge_; ///< Edge integrals between elements of same dimensions
220  IntegralPtrMap<CouplingIntegralAcc<dim>> coupling_; ///< Coupling integrals between elements of dimensions dim and dim-1
221  IntegralPtrMap<BoundaryIntegralAcc<dim>> boundary_; ///< Boundary integrals betwwen side and boundary element of dim-1
222 };
223 
224 
225 
226 
227 /// Define Integral Tuple hash function - helper struct of OperationMap
229  std::size_t operator()(std::tuple<std::string, uint> tpl) const {
230  return boost::hash_value( tpl );
231  }
232 
233  /// Create tuple from typeid(Operation).name and size of Quadrature
234  static std::tuple<std::string, uint> op_tuple(std::string op_type, uint quad_size) {
235  return std::make_tuple(op_type, quad_size);
236  }
237 
238 };
239 
240 /// Alias for unordered_map of Operation pointer with custom hash
241 template<typename Operation>
242 using OperationMap = std::unordered_map<std::tuple<std::string, uint>, Operation *, OperationTplHash>;
243 
244 
245 
246 #endif /* INTEGRAL_DATA_HH_ */
#define ASSERT_GE(a, b)
Definition of comparative assert macro (Greater or Equal) only for debug mode.
Definition: asserts.hh:325
Cell accessor allow iterate over DOF handler cells.
Side accessor allows to iterate over sides of DOF handler cell.
Class allows to iterate over sides of edge.
Iter< Object > make_iter(Object obj)
std::unordered_map< std::tuple< std::string, uint >, Operation *, OperationTplHash > OperationMap
Alias for unordered_map of Operation pointer with custom hash.
std::unordered_map< std::tuple< uint, uint >, std::shared_ptr< Integral >, IntegralTplHash > IntegralPtrMap
Alias for unordered_map of shared_ptr<Integral> with custom hash.
unsigned int uint
Implementation of range helper class.
BoundaryIntegralData()
Default constructor.
BoundaryIntegralData(unsigned int bdr_idx, DHCellSide dhside, unsigned int side_idx)
Constructor with data mebers initialization.
BoundaryIntegralData(const BoundaryIntegralData &other)
Copy constructor.
unsigned int bdr_subset_index
Index (order) of subset on boundary element in EvalPoints object.
unsigned int side_subset_index
Index (order) of subset on side of bulk element in EvalPoints object.
DHCellSide side
Specified cell side (bulk element)
BulkIntegralData()
Default constructor.
BulkIntegralData(const BulkIntegralData &other)
Copy constructor.
BulkIntegralData(DHCellAccessor dhcell, unsigned int subset_idx)
Constructor with data mebers initialization.
DHCellAccessor cell
Specified cell (element)
unsigned int subset_index
Index (order) of subset in EvalPoints object.
unsigned int bulk_subset_index
Index (order) of lower dim subset in EvalPoints object.
DHCellSide side
Specified cell side (higher dim element)
CouplingIntegralData(const CouplingIntegralData &other)
Copy constructor.
CouplingIntegralData()
Default constructor.
CouplingIntegralData(DHCellAccessor dhcell, unsigned int bulk_idx, DHCellSide dhside, unsigned int side_idx)
Constructor with data mebers initialization.
unsigned int side_subset_index
Index (order) of higher dim subset in EvalPoints object.
DHCellAccessor cell
Set of integral of given dimension necessary in assemblation.
IntegralPtrMap< BoundaryIntegralAcc< dim > > boundary_
Boundary integrals betwwen side and boundary element of dim-1.
IntegralPtrMap< EdgeIntegralAcc< dim > > edge_
Edge integrals between elements of same dimensions.
IntegralPtrMap< BulkIntegralAcc< dim > > bulk_
Bulk integrals of elements.
IntegralPtrMap< CouplingIntegralAcc< dim > > coupling_
Coupling integrals between elements of dimensions dim and dim-1.
EdgeIntegralData(const EdgeIntegralData &other)
Copy constructor.
unsigned int subset_index
Index (order) of subset in EvalPoints object.
EdgeIntegralData()
Default constructor.
RangeConvert< DHEdgeSide, DHCellSide > edge_side_range
Specified cell side (element)
EdgeIntegralData(RangeConvert< DHEdgeSide, DHCellSide > range, unsigned int subset_idx)
Constructor with data mebers initialization.
Set of integral data of given dimension used in assemblation.
RevertableListVector< CouplingIntegralData > coupling_
Holds data for computing couplings integrals.
RevertableListVector< BulkIntegralData > bulk_
Holds data for computing bulk integrals.
RevertableListVector< BoundaryIntegralData > boundary_
Holds data for computing boundary integrals.
RevertableListVector< EdgeIntegralData > edge_
Holds data for computing edge integrals.
Define Integral Tuple hash function - helper struct of IntegralPtrMap.
std::size_t operator()(std::tuple< uint, uint > tpl) const
static std::tuple< uint, uint > integral_tuple(uint dim, uint quad_size)
Create tuple from dimennsion and size of Quadrature.
Define Integral Tuple hash function - helper struct of OperationMap.
static std::tuple< std::string, uint > op_tuple(std::string op_type, uint quad_size)
Create tuple from typeid(Operation).name and size of Quadrature.
std::size_t operator()(std::tuple< std::string, uint > tpl) const
std::vector< RevertableList< Type > > vec_list_
RevertableListVector(uint list_size)
Constructor, initialize vec_list_.
void set_size(uint new_size)
Set size of vec_list_.
RevertableList< Type > & operator[](std::size_t item)
const RevertableList< Type > & operator[](std::size_t item) const
void revert_temporary()
Erase temporary part of data.
void make_permanent()
Finalize temporary part of data.
RevertableListVector()
Default constructor.
void reset()
Clear the list.
Struct is a container that encapsulates variable size arrays.