BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
dune_basis_helper.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_dune_basis_helper_hpp
22 #define fiber_dune_basis_helper_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "types.hpp"
27 #include "_3d_array.hpp"
28 #include "_4d_array.hpp"
29 
30 #include "../common/armadillo_fwd.hpp"
31 #include "../common/deprecated.hpp"
32 #include <cassert>
33 #include <vector>
34 
35 namespace Fiber
36 {
37 
38 template <typename CoordinateType, typename ValueType, typename DuneBasis>
39 void evaluateShapeFunctionsWithDune(
40  const arma::Mat<CoordinateType>& local,
41  LocalDofIndex localDofIndex,
42  _3dArray<ValueType>& result,
43  const DuneBasis& basis = DuneBasis())
44 {
45  typedef typename DuneBasis::Traits Traits;
46  assert(local.n_rows == Traits::dimDomain);
47  assert(localDofIndex == ALL_DOFS ||
48  (localDofIndex >= 0 && localDofIndex < basis.size()));
49 
50  const int functionCount = localDofIndex == ALL_DOFS ? basis.size() : 1;
51  const int pointCount = local.n_cols;
52 
53  typename Traits::DomainType point;
54  std::vector<typename Traits::RangeType> values;
55  result.set_size(Traits::dimRange, functionCount, pointCount);
56 
57  for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex)
58  {
59  for (int dim = 0; dim < Traits::dimDomain; ++dim)
60  point[dim] = local(dim, pointIndex);
61  basis.evaluateFunction(point, values);
62  if (localDofIndex == ALL_DOFS)
63  for (int functionIndex = 0; functionIndex < functionCount; ++functionIndex)
64  for (int dim = 0; dim < Traits::dimRange; ++dim)
65  result(dim, functionIndex, pointIndex) = values[functionIndex][dim];
66  else
67  for (int dim = 0; dim < Traits::dimRange; ++dim)
68  result(dim, 0, pointIndex) = values[localDofIndex][dim];
69  }
70 }
71 
72 template <typename CoordinateType, typename ValueType, typename DuneBasis>
73 BEMPP_DEPRECATED void evaluateBasisFunctionsWithDune(
74  const arma::Mat<CoordinateType>& local,
75  LocalDofIndex localDofIndex,
76  _3dArray<ValueType>& result,
77  const DuneBasis& basis = DuneBasis())
78 {
79  evaluateShapeFunctionsWithDune(local, localDofIndex, result, basis);
80 }
81 
82 template <typename CoordinateType, typename ValueType, typename DuneBasis>
83 void evaluateShapeFunctionDerivativesWithDune(
84  const arma::Mat<CoordinateType>& local,
85  LocalDofIndex localDofIndex,
86  _4dArray<ValueType>& result,
87  const DuneBasis& basis = DuneBasis())
88 {
89  typedef typename DuneBasis::Traits Traits;
90  assert(local.n_rows == Traits::dimDomain);
91  assert(localDofIndex == ALL_DOFS ||
92  (localDofIndex >= 0 && localDofIndex < basis.size()));
93 
94  const int functionCount = localDofIndex == ALL_DOFS ? basis.size() : 1;
95  const int pointCount = local.n_cols;
96 
97  typename Traits::DomainType point;
98  std::vector<typename Traits::JacobianType> jacobians;
99  result.set_size(Traits::dimRange, Traits::dimDomain, functionCount, pointCount);
100 
101  for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex)
102  {
103  for (int dim = 0; dim < Traits::dimDomain; ++dim)
104  point[dim] = local(dim, pointIndex);
105  basis.evaluateJacobian(point, jacobians);
106  if (localDofIndex == ALL_DOFS)
107  for (int functionIndex = 0; functionIndex < functionCount; ++functionIndex)
108  for (int dimD = 0; dimD < Traits::dimDomain; ++dimD)
109  for (int dimR = 0; dimR < Traits::dimRange; ++dimR)
110  result(dimR, dimD, functionIndex, pointIndex) =
111  jacobians[functionIndex][dimR][dimD];
112  else
113  for (int dimD = 0; dimD < Traits::dimDomain; ++dimD)
114  for (int dimR = 0; dimR < Traits::dimRange; ++dimR)
115  result(dimR, dimD, 0, pointIndex) =
116  jacobians[localDofIndex][dimR][dimD];
117  }
118 }
119 
120 template <typename CoordinateType, typename ValueType, typename DuneBasis>
121 BEMPP_DEPRECATED void evaluateBasisFunctionDerivativesWithDune(
122  const arma::Mat<CoordinateType>& local,
123  LocalDofIndex localDofIndex,
124  _4dArray<ValueType>& result,
125  const DuneBasis& basis = DuneBasis())
126 {
127  evaluateShapeFunctionDerivativesWithDune(local, localDofIndex,
128  result, basis);
129 }
130 
131 } // namespace Fiber
132 
133 #endif
#define BEMPP_DEPRECATED
Macro used to mark deprecated functions or classes.
Definition: deprecated.hpp:41