BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
raw_grid_geometry.hpp
1 // Copyright (C) 2011-2012 by the Bem++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef fiber_raw_grid_geometry_hpp
22 #define fiber_raw_grid_geometry_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "../common/armadillo_fwd.hpp"
27 
28 namespace Fiber
29 {
30 
31 template <typename CoordinateType>
32 class RawGridGeometry
33 {
34 public:
35  RawGridGeometry(int gridDim, int worldDim) :
36  m_gridDim(gridDim), m_worldDim(worldDim) {
37  if (gridDim > worldDim)
38  throw std::invalid_argument("RawGridGeometry::RawGridGeometry(): "
39  "grid dimension cannot be larger than "
40  "world dimension");
41  }
42 
43  // Const accessors
44 
45  const arma::Mat<CoordinateType>& vertices() const {
46  return m_vertices;
47  }
48 
49  const arma::Mat<int>& elementCornerIndices() const {
50  return m_elementCornerIndices;
51  }
52 
53  const arma::Mat<char>& auxData() const {
54  return m_auxData;
55  }
56 
57  int elementCount() const {
58  return m_elementCornerIndices.n_cols;
59  }
60 
61  int gridDimension() const {
62  return m_gridDim;
63  }
64 
65  int worldDimension() const {
66  return m_worldDim;
67  }
68 
70  arma::Col<int> elementCornerIndices(int elementIndex) const {
71  const int n = elementCornerCount(elementIndex);
72  return m_elementCornerIndices(arma::span(0, n - 1), arma::span(elementIndex));
73  }
74 
76  int elementCornerCount(int elementIndex) const {
77  int n = m_elementCornerIndices.n_rows;
78  while (m_elementCornerIndices(n - 1, elementIndex) < 0)
79  --n;
80  return n;
81  }
82 
83  // Non-const accessors (currently needed for construction)
84 
85  arma::Mat<CoordinateType>& vertices() {
86  return m_vertices;
87  }
88 
89  arma::Mat<int>& elementCornerIndices() {
90  return m_elementCornerIndices;
91  }
92 
93  arma::Mat<char>& auxData() {
94  return m_auxData;
95  }
96 
97  // Auxiliary functions
98 
99  template <typename Geometry>
100  void setupGeometry(int elementIndex, Geometry& geometry) const
101  {
102  const int dimGrid = m_vertices.n_rows;
103  size_t cornerCount = 0;
104  for (; cornerCount < m_elementCornerIndices.n_rows; ++cornerCount)
105  if (m_elementCornerIndices(cornerCount, elementIndex) < 0)
106  break;
107  arma::Mat<CoordinateType> corners(dimGrid, cornerCount);
108  for (size_t cornerIndex = 0; cornerIndex < cornerCount; ++cornerIndex)
109  corners.col(cornerIndex) = m_vertices.col(
110  m_elementCornerIndices(cornerIndex, elementIndex));
111  geometry.setup(corners, m_auxData.unsafe_col(elementIndex));
112  }
113 
114 private:
115  int m_gridDim;
116  int m_worldDim;
117  arma::Mat<CoordinateType> m_vertices;
118  arma::Mat<int> m_elementCornerIndices;
119  arma::Mat<char> m_auxData;
120 };
121 
122 } // namespace Fiber
123 
124 #endif
int elementCornerCount(int elementIndex) const
Number of corners of the given element.
Definition: raw_grid_geometry.hpp:76
arma::Col< int > elementCornerIndices(int elementIndex) const
Indices of the corners of the given element.
Definition: raw_grid_geometry.hpp:70