BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
default_kernel_trial_integral_imp.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_default_kernel_trial_integral_imp_hpp
22 #define fiber_default_kernel_trial_integral_imp_hpp
23 
24 #include "default_kernel_trial_integral.hpp"
25 
26 #include "geometrical_data.hpp"
27 
28 #include <algorithm>
29 
30 namespace Fiber
31 {
32 
33 /*
34 template <typename BasisFunctionType_, typename KernelType_,
35  typename ResultType_>
36 class IntegrandFunctor
37 {
38 public:
39  typedef BasisFunctionType_ BasisFunctionType;
40  typedef KernelType_ KernelType;
41  typedef ResultType_ ResultType;
42  typedef typename ScalarTraits<ResultType>::RealType CoordinateType;
43 
44  void addGeometricalDependencies(int& trialGeomDeps) const;
45 
46  void evaluate(
47  const ConstGeometricalDataSlice<CoordinateType>& trialGeomData,
48  const CollectionOf2dSlicesOfConst4dArrays<KernelType>& kernels,
49  const CollectionOf1dSlicesOfConst2dArrays<BasisFunctionType>&
50  weightedTrialTransformations,
51  std::vector<ResultType>& value) const;
52 };
53 */
54 
55 template <typename IntegrandFunctor>
56 void DefaultKernelTrialIntegral<IntegrandFunctor>::
57 addGeometricalDependencies(size_t& trialGeomDeps) const
58 {
59  trialGeomDeps |= INTEGRATION_ELEMENTS;
60  m_functor.addGeometricalDependencies(trialGeomDeps);
61 }
62 
63 template <typename IntegrandFunctor>
64 int DefaultKernelTrialIntegral<IntegrandFunctor>::resultDimension() const
65 {
66  return m_functor.resultDimension();
67 }
68 
69 template <typename IntegrandFunctor>
70 void DefaultKernelTrialIntegral<IntegrandFunctor>::evaluate(
71  const GeometricalData<CoordinateType>& trialGeomData,
72  const CollectionOf4dArrays<KernelType>& kernels,
73  const CollectionOf2dArrays<ResultType>& trialTransformations,
74  const std::vector<CoordinateType>& weights,
75  _2dArray<ResultType>& result) const
76 {
77  const size_t evalPointCount = kernels[0].extent(2);
78  const size_t quadPointCount = kernels[0].extent(3);
79  const int resultComponentCount = m_functor.resultDimension();
80 
81  for (size_t i = 0; i < kernels.size(); ++i) {
82  assert(kernels[i].extent(2) == evalPointCount);
83  assert(kernels[i].extent(3) == quadPointCount);
84  }
85  for (size_t i = 0; i < trialTransformations.size(); ++i) {
86  assert(trialTransformations[i].extent(1) == quadPointCount);
87  }
88  assert(weights.size() == quadPointCount);
89 
90  result.set_size(resultComponentCount, evalPointCount);
91  std::fill(result.begin(), result.end(), 0.);
92 
93  std::vector<ResultType> value(resultComponentCount);
94 
95  for (size_t evalPoint = 0; evalPoint < evalPointCount; ++evalPoint)
96  for (size_t quadPoint = 0; quadPoint < quadPointCount; ++quadPoint) {
97  m_functor.evaluate(
98  trialGeomData.const_slice(quadPoint),
99  kernels.const_slice(evalPoint, quadPoint),
100  trialTransformations.const_slice(quadPoint),
101  value);
102  for (int dim = 0; dim < resultComponentCount; ++dim)
103  result(dim, evalPoint) += value[dim] * weights[quadPoint];
104  }
105 }
106 
107 template <typename IntegrandFunctor>
108 void DefaultKernelTrialIntegral<IntegrandFunctor>::evaluateWithPureWeights(
109  const GeometricalData<CoordinateType>& trialGeomData,
110  const CollectionOf4dArrays<KernelType>& kernels,
111  const CollectionOf3dArrays<BasisFunctionType>& trialTransformations,
112  const std::vector<CoordinateType>& weights,
113  _3dArray<ResultType>& result) const
114 {
115  const size_t trialDofCount = trialTransformations[0].extent(1);
116  const size_t evalPointCount = kernels[0].extent(2);
117  const size_t quadPointCount = kernels[0].extent(3);
118  const int resultComponentCount = m_functor.resultDimension();
119 
120  for (size_t i = 0; i < kernels.size(); ++i) {
121  assert(kernels[i].extent(2) == evalPointCount);
122  assert(kernels[i].extent(3) == quadPointCount);
123  }
124  for (size_t i = 0; i < trialTransformations.size(); ++i) {
125  assert(trialTransformations[i].extent(1) == trialDofCount);
126  assert(trialTransformations[i].extent(2) == quadPointCount);
127  }
128  assert(weights.size() == quadPointCount);
129 
130  result.set_size(resultComponentCount, trialDofCount, evalPointCount);
131  std::fill(result.begin(), result.end(), 0.);
132 
133  std::vector<ResultType> value(resultComponentCount);
134 
135  for (size_t trialDof = 0; trialDof < trialDofCount; ++trialDof)
136  for (size_t evalPoint = 0; evalPoint < evalPointCount; ++evalPoint)
137  for (size_t quadPoint = 0; quadPoint < quadPointCount; ++quadPoint) {
138  m_functor.evaluate(
139  trialGeomData.const_slice(quadPoint),
140  kernels.const_slice(evalPoint, quadPoint),
141  trialTransformations.const_slice(trialDof, quadPoint),
142  value);
143  for (int dim = 0; dim < resultComponentCount; ++dim)
144  result(dim, trialDof, evalPoint) += value[dim] *
145  trialGeomData.integrationElements(quadPoint) *
146  weights[quadPoint];
147  }
148 }
149 
150 } // namespace Fiber
151 
152 #endif