BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
numerical_test_trial_integrator_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 #include "../common/common.hpp"
22 
23 #include "numerical_test_trial_integrator.hpp" // To keep IDEs happy
24 
25 #include "shapeset.hpp"
26 #include "basis_data.hpp"
27 #include "conjugate.hpp"
28 #include "collection_of_shapeset_transformations.hpp"
29 #include "geometrical_data.hpp"
30 #include "opencl_handler.hpp"
31 #include "raw_grid_geometry.hpp"
32 #include "types.hpp"
33 
34 #include <cassert>
35 #include <memory>
36 
37 namespace Fiber
38 {
39 
40 template <typename BasisFunctionType, typename ResultType, typename GeometryFactory>
41 NumericalTestTrialIntegrator<BasisFunctionType, ResultType, GeometryFactory>::
42 NumericalTestTrialIntegrator(
43  const arma::Mat<CoordinateType>& localQuadPoints,
44  const std::vector<CoordinateType> quadWeights,
45  const GeometryFactory& geometryFactory,
46  const RawGridGeometry<CoordinateType>& rawGeometry,
47  const CollectionOfShapesetTransformations<CoordinateType>& testTransformations,
48  const CollectionOfShapesetTransformations<CoordinateType>& trialTransformations,
49  const TestTrialIntegral<BasisFunctionType, ResultType>& integral,
50  const OpenClHandler& openClHandler) :
51  m_localQuadPoints(localQuadPoints),
52  m_quadWeights(quadWeights),
53  m_geometryFactory(geometryFactory),
54  m_rawGeometry(rawGeometry),
55  m_testTransformations(testTransformations),
56  m_trialTransformations(trialTransformations),
57  m_integral(integral),
58  m_openClHandler(openClHandler)
59 {
60  if (localQuadPoints.n_cols != quadWeights.size())
61  throw std::invalid_argument("NumericalTestTrialIntegrator::"
62  "NumericalTestTrialIntegrator(): "
63  "numbers of points and weights do not match");
64 }
65 
66 template <typename BasisFunctionType, typename ResultType, typename GeometryFactory>
67 void NumericalTestTrialIntegrator<BasisFunctionType, ResultType, GeometryFactory>::integrate(
68  const std::vector<int>& elementIndices,
69  const Shapeset<BasisFunctionType>& testShapeset,
70  const Shapeset<BasisFunctionType>& trialShapeset,
71  arma::Cube<ResultType>& result) const
72 {
73  const size_t pointCount = m_localQuadPoints.n_cols;
74  const size_t elementCount = elementIndices.size();
75 
76  if (pointCount == 0 || elementCount == 0)
77  return;
78  // TODO: in the (pathological) case that pointCount == 0 but
79  // elementCount != 0, set elements of result to 0.
80 
81  // Evaluate constants
82  const int componentCount = m_testTransformations.resultDimension(0);
83  const int testDofCount = testShapeset.size();
84  const int trialDofCount = trialShapeset.size();
85 
86 // if (m_trialTransformations.codomainDimension() != componentCount)
87 // throw std::runtime_error("NumericalTestTrialIntegrator::integrate(): "
88 // "test and trial functions "
89 // "must have the same number of components");
90 
91  BasisData<BasisFunctionType> testBasisData, trialBasisData;
92  GeometricalData<CoordinateType> geomData;
93 
94  size_t testBasisDeps = 0, trialBasisDeps = 0;
95  size_t geomDeps = 0; // INTEGRATION_ELEMENTS;
96 
97  m_testTransformations.addDependencies(testBasisDeps, geomDeps);
98  m_trialTransformations.addDependencies(trialBasisDeps, geomDeps);
99  m_integral.addGeometricalDependencies(geomDeps);
100 
101  typedef typename GeometryFactory::Geometry Geometry;
102  std::auto_ptr<Geometry> geometry(m_geometryFactory.make());
103 
104  CollectionOf3dArrays<BasisFunctionType> testValues, trialValues;
105 
106  result.set_size(testDofCount, trialDofCount, elementCount);
107 
108  testShapeset.evaluate(testBasisDeps, m_localQuadPoints, ALL_DOFS, testBasisData);
109  trialShapeset.evaluate(trialBasisDeps, m_localQuadPoints, ALL_DOFS, trialBasisData);
110 
111  // Iterate over the elements
112  for (size_t e = 0; e < elementCount; ++e)
113  {
114  m_rawGeometry.setupGeometry(elementIndices[e], *geometry);
115  geometry->getData(geomDeps, m_localQuadPoints, geomData);
116  m_testTransformations.evaluate(testBasisData, geomData, testValues);
117  m_trialTransformations.evaluate(trialBasisData, geomData, trialValues);
118 
119  m_integral.evaluate(geomData, testValues, trialValues,
120  m_quadWeights, result.slice(e));
121 
122  // for (int trialDof = 0; trialDof < trialDofCount; ++trialDof)
123  // for (int testDof = 0; testDof < testDofCount; ++testDof)
124  // {
125  // ResultType sum = 0.;
126  // for (size_t point = 0; point < pointCount; ++point)
127  // for (int dim = 0; dim < componentCount; ++dim)
128  // sum += m_quadWeights[point] *
129  // geomData.integrationElements(point) *
130  // conjugate(testValues[0](dim, testDof, point)) *
131  // trialValues[0](dim, trialDof, point);
132  // result(testDof, trialDof, e) = sum;
133  // }
134  }
135 }
136 
137 } // namespace Fiber