Flow123d  JS_constraints-e651b99
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
51  : cell(dhcell) {}
52 
53  /// Copy constructor
55  : cell(other.cell) {}
56 
57  DHCellAccessor cell; ///< Specified cell (element)
58 };
59 
60 /**
61  * Helper structure holds data of edge integral
62  *
63  * Data is specified by side and subset index in EvalPoint object
64  */
66  /// Default constructor
69 
70  /// Copy constructor
73 
74  /// Constructor with data mebers initialization
76  : edge_side_range(range) {}
77 
78  RangeConvert<DHEdgeSide, DHCellSide> edge_side_range; ///< Specified cell side (element)
79 };
80 
81 /**
82  * Helper structure holds data of neighbour (coupling) integral
83  *
84  * Data is specified by cell, side and their subset indices in EvalPoint object
85  */
87  /// Default constructor
89 
90  /// Constructor with data mebers initialization
92  : cell(dhcell), side(dhside) {}
93 
94  /// Copy constructor
96  : cell(other.cell), side(other.side) {}
97 
99  DHCellSide side; ///< Specified cell side (higher dim element)
100 };
101 
102 /**
103  * Helper structure holds data of boundary integral
104  *
105  * Data is specified by side and subset indices of side and appropriate boundary element in EvalPoint object
106  */
108  /// Default constructor
110 
111  /// Constructor with data mebers initialization
113  : side(dhside) {}
114 
115  /// Copy constructor
117  : side(other.side) {}
118 
119  // We don't need hold ElementAccessor of boundary element, side.cond().element_accessor() provides it.
120  DHCellSide side; ///< Specified cell side (bulk element)
121 };
122 
123 
124 
125 
126 /// Define Integral Tuple hash function - helper struct of IntegralPtrMap
128  std::size_t operator()(std::tuple<uint, uint> tpl) const {
129  return boost::hash_value( tpl );
130  }
131 
132  /// Create tuple from dimennsion and size of Quadrature
133  static std::tuple<uint, uint> integral_tuple(uint dim, uint quad_size) {
134  return std::make_tuple(dim, quad_size);
135  }
136 
137 };
138 
139 /// Alias for unordered_map of shared_ptr<Integral> with custom hash
140 template<typename Integral>
141 using IntegralPtrMap = std::unordered_map<std::tuple<uint, uint>, std::shared_ptr<Integral>, IntegralTplHash>;
142 
143 
144 /// Set of integral of given dimension necessary in assemblation
145 template<unsigned int dim>
146 struct DimIntegrals {
147 public:
148  IntegralPtrMap<BulkIntegralAcc<dim>> bulk_; ///< Bulk integrals of elements
149  IntegralPtrMap<EdgeIntegralAcc<dim>> edge_; ///< Edge integrals between elements of same dimensions
150  IntegralPtrMap<CouplingIntegralAcc<dim>> coupling_; ///< Coupling integrals between elements of dimensions dim and dim-1
151  IntegralPtrMap<BoundaryIntegralAcc<dim>> boundary_; ///< Boundary integrals betwwen side and boundary element of dim-1
152 
153 
154  /// Finalize temporary part of integral data.
155  inline void make_permanent()
156  {
157  for (auto &it : bulk_) it.second->patch_data().make_permanent();
158  for (auto &it : edge_) it.second->patch_data().make_permanent();
159  for (auto &it : coupling_) it.second->patch_data().make_permanent();
160  for (auto &it : boundary_) it.second->patch_data().make_permanent();
161  }
162 
163  /// Erase temporary part of integral data.
164  inline void revert_temporary()
165  {
166  for (auto &it : bulk_) it.second->patch_data().revert_temporary();
167  for (auto &it : edge_) it.second->patch_data().revert_temporary();
168  for (auto &it : coupling_) it.second->patch_data().revert_temporary();
169  for (auto &it : boundary_) it.second->patch_data().revert_temporary();
170  }
171 
172  /// Clear list of integral data.
173  inline void reset()
174  {
175  for (auto &it : bulk_) it.second->patch_data().reset();
176  for (auto &it : edge_) it.second->patch_data().reset();
177  for (auto &it : coupling_) it.second->patch_data().reset();
178  for (auto &it : boundary_) it.second->patch_data().reset();
179  }
180 
181  /// Return number of cells on patch
182  inline unsigned int n_patch_cells() const {
183  if (bulk_.size() > 0) return bulk_.begin()->second->patch_data().permanent_size();
184  else return 0;
185  }
186 
187  /// Return number of edges on patch
188  inline unsigned int n_patch_edges() const {
189  if (edge_.size() > 0) return edge_.begin()->second->patch_data().permanent_size();
190  else return 0;
191  }
192 
193  /// Return number of neighbours on patch
194  inline unsigned int n_patch_neighbours() const {
195  if (coupling_.size() > 0) return coupling_.begin()->second->patch_data().permanent_size();
196  else return 0;
197  }
198 
199  /// Return number of boundaries on patch
200  inline unsigned int n_patch_boundaries() const {
201  if (boundary_.size() > 0) return boundary_.begin()->second->patch_data().permanent_size();
202  else return 0;
203  }
204 
205 };
206 
207 
208 
209 
210 /// Define Integral Tuple hash function - helper struct of OperationMap
212  std::size_t operator()(std::tuple<std::string, uint> tpl) const {
213  return boost::hash_value( tpl );
214  }
215 
216  /// Create tuple from typeid(Operation).name and size of Quadrature
217  static std::tuple<std::string, uint> op_tuple(std::string op_type, uint quad_size) {
218  return std::make_tuple(op_type, quad_size);
219  }
220 
221 };
222 
223 /// Alias for unordered_map of Operation pointer with custom hash
224 template<typename Operation>
225 using OperationMap = std::unordered_map<std::tuple<std::string, uint>, Operation *, OperationTplHash>;
226 
227 
228 
229 #endif /* INTEGRAL_DATA_HH_ */
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(DHCellSide dhside)
Constructor with data mebers initialization.
BoundaryIntegralData(const BoundaryIntegralData &other)
Copy constructor.
DHCellSide side
Specified cell side (bulk element)
BulkIntegralData()
Default constructor.
BulkIntegralData(const BulkIntegralData &other)
Copy constructor.
BulkIntegralData(DHCellAccessor dhcell)
Constructor with data mebers initialization.
DHCellAccessor cell
Specified cell (element)
DHCellSide side
Specified cell side (higher dim element)
CouplingIntegralData(const CouplingIntegralData &other)
Copy constructor.
CouplingIntegralData()
Default constructor.
CouplingIntegralData(DHCellAccessor dhcell, DHCellSide dhside)
Constructor with data mebers initialization.
DHCellAccessor cell
Set of integral of given dimension necessary in assemblation.
unsigned int n_patch_neighbours() const
Return number of neighbours on patch.
void revert_temporary()
Erase temporary part of integral data.
void reset()
Clear list of integral data.
IntegralPtrMap< BoundaryIntegralAcc< dim > > boundary_
Boundary integrals betwwen side and boundary element of dim-1.
unsigned int n_patch_boundaries() const
Return number of boundaries on patch.
IntegralPtrMap< EdgeIntegralAcc< dim > > edge_
Edge integrals between elements of same dimensions.
IntegralPtrMap< BulkIntegralAcc< dim > > bulk_
Bulk integrals of elements.
void make_permanent()
Finalize temporary part of integral data.
unsigned int n_patch_cells() const
Return number of cells on patch.
IntegralPtrMap< CouplingIntegralAcc< dim > > coupling_
Coupling integrals between elements of dimensions dim and dim-1.
unsigned int n_patch_edges() const
Return number of edges on patch.
EdgeIntegralData(const EdgeIntegralData &other)
Copy constructor.
EdgeIntegralData(RangeConvert< DHEdgeSide, DHCellSide > range)
Constructor with data mebers initialization.
EdgeIntegralData()
Default constructor.
RangeConvert< DHEdgeSide, DHCellSide > edge_side_range
Specified cell side (element)
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