BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
modified_helmholtz_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_modified_helmholtz_3d_hypersingular_off_diagonal_kernel_functor_hpp
22 #define fiber_modified_helmholtz_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 
46 template <typename ValueType_>
48 {
49 public:
50  typedef ValueType_ ValueType;
51  typedef typename ScalarTraits<ValueType>::RealType CoordinateType;
52 
54  ValueType waveNumber) :
55  m_waveNumber(waveNumber)
56  {}
57 
58  int kernelCount() const { return 1; }
59  int kernelRowCount(int /* kernelIndex */) const { return 1; }
60  int kernelColCount(int /* kernelIndex */) const { return 1; }
61 
62  void addGeometricalDependencies(size_t& testGeomDeps, size_t& trialGeomDeps) const {
63  testGeomDeps |= GLOBALS | NORMALS;
64  trialGeomDeps |= GLOBALS | NORMALS;
65  }
66 
67  ValueType waveNumber() const { return m_waveNumber; }
68 
69  template <template <typename T> class CollectionOf2dSlicesOfNdArrays>
70  void evaluate(
72  const ConstGeometricalDataSlice<CoordinateType>& trialGeomData,
73  CollectionOf2dSlicesOfNdArrays<ValueType>& result) const {
74  const int coordCount = 3;
75  const ValueType waveNumber = m_waveNumber;
76 
77  CoordinateType distanceSq = 0.;
78  CoordinateType nTest_diff = 0;
79  CoordinateType nTrial_diff = 0;
80  CoordinateType nTest_nTrial = 0.;
81  for (int coordIndex = 0; coordIndex < coordCount; ++coordIndex) {
82  CoordinateType diff = trialGeomData.global(coordIndex) -
83  testGeomData.global(coordIndex);
84  distanceSq += diff * diff;
85  nTest_diff += diff * testGeomData.normal(coordIndex);
86  nTrial_diff += diff * trialGeomData.normal(coordIndex);
87  nTest_nTrial += testGeomData.normal(coordIndex) *
88  trialGeomData.normal(coordIndex);
89  }
90  CoordinateType distance = sqrt(distanceSq);
91  ValueType kr = waveNumber * distance;
92  const CoordinateType ONE = 1., THREE = 3.;
93  result[0](0, 0) =
94  static_cast<CoordinateType>(1.0 / (4.0 * M_PI)) /
95  (distance * distanceSq * distanceSq) *
96  (-distanceSq * nTest_nTrial * (ONE + kr) +
97  nTest_diff * nTrial_diff *
98  (THREE + THREE * kr + kr * kr)) *
99  exp(-kr);
100  }
101 
102  CoordinateType estimateRelativeScale(CoordinateType distance) const {
103  return exp(-realPart(m_waveNumber) * distance);
104  }
105 
106 private:
107  ValueType m_waveNumber;
108 };
109 
110 } // namespace Fiber
111 
112 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
Kernel functor for the hypersingular operator associated with the modified Helmholtz equation in 3D...
Definition: modified_helmholtz_3d_hypersingular_off_diagonal_kernel_functor.hpp:47
Access to slices of geometrical data.
Definition: geometrical_data.hpp:88