BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
simple_test_scalar_kernel_trial_integrand_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_simple_test_scalar_kernel_trial_integrand_functor_hpp
22 #define fiber_simple_test_scalar_kernel_trial_integrand_functor_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include <cassert>
27 #include "collection_of_3d_arrays.hpp"
28 #include "geometrical_data.hpp"
29 #include "conjugate.hpp"
30 #include "scalar_traits.hpp"
31 
32 namespace Fiber
33 {
34 
42 template <typename BasisFunctionType_, typename KernelType_,
43  typename ResultType_>
45 {
46 public:
47  typedef BasisFunctionType_ BasisFunctionType;
48  typedef KernelType_ KernelType;
49  typedef ResultType_ ResultType;
50  typedef typename ScalarTraits<ResultType>::RealType CoordinateType;
51 
52  void addGeometricalDependencies(size_t& testGeomDeps, size_t& trialGeomDeps) const {
53  // do nothing
54  }
55 
56  // It is possible that this function could be generalised to
57  // multiple shapeset transformations or kernels and that the additional
58  // loops could be optimised away by the compiler.
59  template <template <typename T> class CollectionOf2dSlicesOfConstNdArrays>
60  ResultType evaluate(
61  const ConstGeometricalDataSlice<CoordinateType>& /* testGeomData */,
62  const ConstGeometricalDataSlice<CoordinateType>& /* trialGeomData */,
65  const CollectionOf2dSlicesOfConstNdArrays<KernelType>& kernelValues) const {
66  // Assert that there is at least one scalar-valued kernel
67  assert(kernelValues.size() >= 1);
68  assert(kernelValues[0].extent(0) == 1);
69  assert(kernelValues[0].extent(1) == 1);
70 
71  // Assert that there is at least one test and trial transformation
72  // and that the dimensions of the first pair agree
73  assert(testValues.size() >= 1);
74  assert(trialValues.size() >= 1);
75  assert(testValues[0].extent(0) == trialValues[0].extent(0));
76 
77  const int transformationDim = testValues[0].extent(0);
78 
79  BasisFunctionType dotProduct = 0.;
80  for (int dim = 0; dim < transformationDim; ++dim)
81  dotProduct += conjugate(testValues[0](dim)) *
82  trialValues[0](dim);
83  ResultType result = dotProduct * kernelValues[0](0, 0);
84  return result;
85  }
86 };
87 
88 template <typename BasisFunctionType_, typename KernelType_,
89  typename ResultType_, int transformationDim>
91 {
92 public:
93  typedef BasisFunctionType_ BasisFunctionType;
94  typedef KernelType_ KernelType;
95  typedef ResultType_ ResultType;
96  typedef typename ScalarTraits<ResultType>::RealType CoordinateType;
97 
98  void addGeometricalDependencies(size_t& testGeomDeps, size_t& trialGeomDeps) const {
99  // do nothing
100  }
101 
102  // It is possible that this function could be generalised to
103  // multiple shapeset transformations or kernels and that the additional
104  // loops could be optimised away by the compiler.
105  template <template <typename T> class CollectionOf2dSlicesOfConstNdArrays>
106  ResultType evaluate(
107  const ConstGeometricalDataSlice<CoordinateType>& /* testGeomData */,
108  const ConstGeometricalDataSlice<CoordinateType>& /* trialGeomData */,
111  const CollectionOf2dSlicesOfConstNdArrays<KernelType>& kernelValues) const {
112  // Assert that there is at least one scalar-valued kernel
113  assert(kernelValues.size() >= 1);
114  assert(kernelValues[0].extent(0) == 1);
115  assert(kernelValues[0].extent(1) == 1);
116 
117  // Assert that there is at least one test and trial transformation
118  // and that the dimensions of the first pair agree
119  assert(testValues.size() >= 1);
120  assert(trialValues.size() >= 1);
121 
122  assert(testValues[0].extent(0) == transformationDim);
123  assert(trialValues[0].extent(0) == transformationDim);
124 
125  BasisFunctionType dotProduct = 0.;
126  for (int dim = 0; dim < transformationDim; ++dim)
127  dotProduct += conjugate(testValues[0](dim)) *
128  trialValues[0](dim);
129  ResultType result = dotProduct * kernelValues[0](0, 0);
130  return result;
131  }
132 };
133 
134 
135 } // namespace Fiber
136 
137 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
Definition: collection_of_3d_arrays.hpp:151
Functor evaluating the integrand of the simplest boundary integral operator.
Definition: simple_test_scalar_kernel_trial_integrand_functor.hpp:44
Definition: simple_test_scalar_kernel_trial_integrand_functor.hpp:90
Access to slices of geometrical data.
Definition: geometrical_data.hpp:88