BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
laplace_3d_hypersingular_off_diagonal_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_hypersingular_off_diagonal_kernel_functor_hpp
22 #define fiber_laplace_3d_hypersingular_off_diagonal_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 
45 template <typename ValueType_>
47 {
48 public:
49  typedef ValueType_ ValueType;
50  typedef typename ScalarTraits<ValueType>::RealType CoordinateType;
51 
52  int kernelCount() const { return 1; }
53  int kernelRowCount(int /* kernelIndex */) const { return 1; }
54  int kernelColCount(int /* kernelIndex */) const { return 1; }
55 
56  void addGeometricalDependencies(size_t& testGeomDeps, size_t& trialGeomDeps) const {
57  testGeomDeps |= GLOBALS | NORMALS;
58  trialGeomDeps |= GLOBALS | NORMALS;
59  }
60 
61  template <template <typename T> class CollectionOf2dSlicesOfNdArrays>
62  void evaluate(
64  const ConstGeometricalDataSlice<CoordinateType>& trialGeomData,
65  CollectionOf2dSlicesOfNdArrays<ValueType>& result) const {
66  const int coordCount = 3;
67  assert(testGeomData.dimWorld() == coordCount);
68  assert(result.size() == 1);
69 
70  CoordinateType distanceSq = 0.;
71  CoordinateType nTest_diff = 0;
72  CoordinateType nTrial_diff = 0;
73  CoordinateType nTest_nTrial = 0.;
74  for (int coordIndex = 0; coordIndex < coordCount; ++coordIndex) {
75  CoordinateType diff = trialGeomData.global(coordIndex) -
76  testGeomData.global(coordIndex);
77  distanceSq += diff * diff;
78  nTest_diff += diff * testGeomData.normal(coordIndex);
79  nTrial_diff += diff * trialGeomData.normal(coordIndex);
80  nTest_nTrial += testGeomData.normal(coordIndex) *
81  trialGeomData.normal(coordIndex);
82  }
83  CoordinateType distance = sqrt(distanceSq);
84  CoordinateType commonFactor =
85  static_cast<CoordinateType>(-1. / (4. * M_PI)) /
86  (distance * distanceSq * distanceSq);
87  result[0](0, 0) = commonFactor * (
88  nTest_nTrial * distanceSq -
89  static_cast<CoordinateType>(3.) * nTest_diff * nTrial_diff);
90  }
91 };
92 
93 } // namespace Fiber
94 
95 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
Kernel functor for the hypersingular operator associated with the Laplace equation in 3D...
Definition: laplace_3d_hypersingular_off_diagonal_kernel_functor.hpp:46
Access to slices of geometrical data.
Definition: geometrical_data.hpp:88