BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
laplace_3d_double_layer_potential_kernel_functor.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_laplace_3d_double_layer_potential_kernel_functor_hpp
22 #define fiber_laplace_3d_double_layer_potential_kernel_functor_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "geometrical_data.hpp"
27 #include "scalar_traits.hpp"
28 
29 namespace Fiber
30 {
31 
43 template <typename ValueType_>
45 {
46 public:
47  typedef ValueType_ ValueType;
48  typedef typename ScalarTraits<ValueType>::RealType CoordinateType;
49 
50  int kernelCount() const { return 1; }
51  int kernelRowCount(int /* kernelIndex */) const { return 1; }
52  int kernelColCount(int /* kernelIndex */) const { return 1; }
53 
54  void addGeometricalDependencies(size_t& testGeomDeps, size_t& trialGeomDeps) const {
55  testGeomDeps |= GLOBALS;
56  trialGeomDeps |= GLOBALS | NORMALS;
57  }
58 
59  template <template <typename T> class CollectionOf2dSlicesOfNdArrays>
60  void evaluate(
62  const ConstGeometricalDataSlice<CoordinateType>& trialGeomData,
63  CollectionOf2dSlicesOfNdArrays<ValueType>& result) const {
64  const int coordCount = 3;
65  assert(testGeomData.dimWorld() == coordCount);
66  assert(result.size() == 1);
67 
68  CoordinateType numeratorSum = 0., distanceSq = 0.;
69  for (int coordIndex = 0; coordIndex < coordCount; ++coordIndex) {
70  CoordinateType diff = trialGeomData.global(coordIndex) -
71  testGeomData.global(coordIndex);
72  distanceSq += diff * diff;
73  numeratorSum += diff * trialGeomData.normal(coordIndex);
74  }
75  CoordinateType distance = sqrt(distanceSq);
76  result[0](0, 0) = -numeratorSum /
77  (static_cast<CoordinateType>(4. * M_PI) * distance * distanceSq);
78  }
79 };
80 
81 } // namespace Fiber
82 
83 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
Double-layer-potential kernel functor for the Laplace equation in 3D.
Definition: laplace_3d_double_layer_potential_kernel_functor.hpp:44
Access to slices of geometrical data.
Definition: geometrical_data.hpp:88