BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
local_assembler_construction_helper.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 bempp_local_assembler_construction_helper_hpp
22 #define bempp_local_assembler_construction_helper_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "assembly_options.hpp"
27 #include "../common/not_implemented_error.hpp"
28 #include "../common/shared_ptr.hpp"
29 #include "../fiber/raw_grid_geometry.hpp"
30 #include "../fiber/opencl_handler.hpp"
31 #include "../grid/geometry_factory.hpp"
32 #include "../grid/grid.hpp"
33 #include "../grid/grid_view.hpp"
34 #include "../space/space.hpp"
35 
36 #include "../common/boost_make_shared_fwd.hpp"
37 
38 namespace Bempp
39 {
40 
45 {
46  template <typename CoordinateType, typename BasisFunctionType>
47  static void collectGridData(
48  const Space<BasisFunctionType>& space,
49  shared_ptr<Fiber::RawGridGeometry<CoordinateType> >& rawGeometry,
50  shared_ptr<GeometryFactory>& geometryFactory) {
51  typedef Fiber::RawGridGeometry<CoordinateType> RawGridGeometry;
52 
53  rawGeometry = boost::make_shared<RawGridGeometry>(space.gridDimension(),
54  space.worldDimension());
55  const GridView& view = space.gridView();
56  view.getRawElementData(
57  rawGeometry->vertices(), rawGeometry->elementCornerIndices(),
58  rawGeometry->auxData());
59  geometryFactory = space.elementGeometryFactory();
60  }
61 
62  template <typename BasisFunctionType>
63  static void collectShapesets(
64  const Space<BasisFunctionType>& space,
65  shared_ptr<std::vector<const Fiber::Shapeset<BasisFunctionType>*> >& shapesets) {
66  typedef std::vector<const Fiber::Shapeset<BasisFunctionType>*> ShapesetPtrVector;
67  shapesets = boost::make_shared<ShapesetPtrVector>();
68  getAllShapesets(space, *shapesets);
69  }
70 
71  // Probably in future will be generalised to arbitrary number of grids
72 
73  template <typename CoordinateType>
74  static void makeOpenClHandler(
75  const OpenClOptions& openClOptions,
76  const shared_ptr<Fiber::RawGridGeometry<CoordinateType> >& rawGeometry,
77  shared_ptr<Fiber::OpenClHandler>& openClHandler) {
78  openClHandler = boost::make_shared<Fiber::OpenClHandler>(openClOptions);
79  if (openClHandler->UseOpenCl())
80  openClHandler->pushGeometry(rawGeometry->vertices(),
81  rawGeometry->elementCornerIndices());
82  }
83 
84  template <typename CoordinateType>
85  static void makeOpenClHandler(
86  const OpenClOptions& openClOptions,
87  const shared_ptr<Fiber::RawGridGeometry<CoordinateType> >& testRawGeometry,
88  const shared_ptr<Fiber::RawGridGeometry<CoordinateType> >& trialRawGeometry,
89  shared_ptr<Fiber::OpenClHandler>& openClHandler) {
90  openClHandler = boost::make_shared<Fiber::OpenClHandler>(openClOptions);
91  if (openClHandler->UseOpenCl()) {
92  if (testRawGeometry.get() == trialRawGeometry.get())
93  openClHandler->pushGeometry(testRawGeometry->vertices(),
94  testRawGeometry->elementCornerIndices());
95  else
96  throw NotImplementedError(
97  "LocalAssemblerConstructionHelper::makeOpenClHandler(): "
98  "OpenCL-based assembly of operators with test and trial "
99  "spaces defined on different grids is not currently supported");
100  }
101  }
102 };
103 
104 } // namespace Bempp
105 
106 #endif
shared_ptr< GeometryFactory > elementGeometryFactory() const
Return the GeometryFactory associated with the mesh.
Definition: space.hpp:278
Function space.
Definition: assembled_potential_operator.hpp:35
Exception thrown on attempt to access an unimplemented feature.
Definition: not_implemented_error.hpp:32
int worldDimension() const
Return the underlying world dimension.
Definition: space.cpp:185
int gridDimension() const
Return the underlying grid dimension.
Definition: space.cpp:179
Collection of shape functions defined on a reference element.
Definition: default_local_assembler_for_operators_on_surfaces_utilities.hpp:34
Abstract wrapper of a grid view.
Definition: grid_view.hpp:48
const GridView & gridView() const
Return the grid view of the current space.
Definition: space.cpp:190
Definition: default_local_assembler_for_operators_on_surfaces_utilities.hpp:35
Utility functions used during weak-form assembly.
Definition: local_assembler_construction_helper.hpp:44
Definition: opencl_options.hpp:29