BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
geometrical_data.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_geometrical_data_hpp
22 #define fiber_geometrical_data_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "../common/armadillo_fwd.hpp"
27 #include "_3d_array.hpp"
28 
29 #include <cassert>
30 
31 namespace Fiber
32 {
33 
35 enum GeometricalDataType
36 {
37  GLOBALS = 0x0001,
38  INTEGRATION_ELEMENTS = 0x0002,
39  NORMALS = 0x0004,
40  JACOBIANS_TRANSPOSED = 0x0008,
41  JACOBIAN_INVERSES_TRANSPOSED = 0x0010
42 };
43 
45 template <typename CoordinateType> class ConstGeometricalDataSlice;
53 template <typename CoordinateType>
55 {
56  arma::Mat<CoordinateType> globals;
57  arma::Row<CoordinateType> integrationElements;
58  Fiber::_3dArray<CoordinateType> jacobiansTransposed;
59  Fiber::_3dArray<CoordinateType> jacobianInversesTransposed;
60  arma::Mat<CoordinateType> normals;
61 
62  // For the time being, I (somewhat dangerously) assume that
63  // integrationElements or globals or normals are always used
64  int pointCount() const {
65  int result = std::max(std::max(globals.n_cols, normals.n_cols),
66  integrationElements.n_cols);
67  assert(result > 0);
68  return result;
69  }
70 
71  int dimWorld() const {
72  int result = std::max(globals.n_rows, normals.n_rows);
73  assert(result > 0);
74  return result;
75  }
76 
77  ConstGeometricalDataSlice<CoordinateType> const_slice(int point) const {
78  return ConstGeometricalDataSlice<CoordinateType>(*this, point);
79  }
80 };
81 
87 template <typename CoordinateType>
89 {
90 public:
92  int point) :
93  m_geomData(geomData), m_point(point) {}
94 
95  CoordinateType global(int dim) const {
96  return m_geomData.globals(dim, m_point);
97  }
98  CoordinateType integrationElement() const {
99  return m_geomData.integrationElements(m_point);
100  }
101  CoordinateType jacobianTransposed(int row, int col) const {
102  return m_geomData.jacobiansTransposed(row, col, m_point);
103  }
104  CoordinateType jacobianInverseTransposed(int row, int col) const {
105  return m_geomData.jacobianInversesTransposed(row, col, m_point);
106  }
107  CoordinateType normal(int dim) const {
108  return m_geomData.normals(dim, m_point);
109  }
110 
111  int dimWorld() const {
112  return m_geomData.dimWorld();
113  }
114 
115  // Inefficient, but safe
116  GeometricalData<CoordinateType> asGeometricalData() const {
118  if (!m_geomData.globals.is_empty())
119  result.globals = m_geomData.globals.col(m_point);
120  if (!m_geomData.integrationElements.is_empty())
121  result.integrationElements =
122  m_geomData.integrationElements(m_point);
123  if (!m_geomData.jacobiansTransposed.is_empty()) {
124  result.jacobiansTransposed.set_size(
125  1, 1, m_geomData.jacobiansTransposed.extent(2));
126  for (size_t i = 0; i < result.jacobiansTransposed.extent(2); ++i)
127  result.jacobiansTransposed(0, 0, i) =
128  m_geomData.jacobiansTransposed(m_point, m_point, i);
129  }
130  if (!m_geomData.jacobianInversesTransposed.is_empty()) {
131  result.jacobianInversesTransposed.set_size(
132  1, 1, m_geomData.jacobianInversesTransposed.extent(2));
133  for (size_t i = 0; i < result.jacobianInversesTransposed.extent(2); ++i)
134  result.jacobianInversesTransposed(0, 0, i) =
135  m_geomData.jacobianInversesTransposed(m_point, m_point, i);
136  }
137  if (!m_geomData.normals.is_empty())
138  result.normals = m_geomData.normals.col(m_point);
139  return result;
140  }
141 
142 private:
143  const GeometricalData<CoordinateType>& m_geomData;
144  int m_point;
145 };
146 
147 } // namespace Fiber
148 
149 #endif
Storage of geometrical data.
Definition: geometrical_data.hpp:54
Access to slices of geometrical data.
Definition: geometrical_data.hpp:88