BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
piecewise_constant_scalar_space.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_piecewise_constant_scalar_space_hpp
22 #define bempp_piecewise_constant_scalar_space_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "../grid/grid_view.hpp"
27 #include "../grid/grid_segment.hpp"
28 #include "scalar_space.hpp"
29 #include "../common/types.hpp"
30 #include "../fiber/constant_scalar_shapeset.hpp"
31 
32 #include <map>
33 #include <memory>
34 #include <tbb/mutex.h>
35 
36 
37 namespace Bempp
38 {
39 
41 class GridView;
46 template <typename BasisFunctionType>
47 class PiecewiseConstantScalarSpace : public ScalarSpace<BasisFunctionType>
48 {
49 public:
50  typedef typename ScalarSpace<BasisFunctionType>::CoordinateType CoordinateType;
51 
59  explicit PiecewiseConstantScalarSpace(const shared_ptr<const Grid>& grid);
60 
68  PiecewiseConstantScalarSpace(const shared_ptr<const Grid>& grid,
69  const GridSegment& segment);
70 
71  virtual shared_ptr<const Space<BasisFunctionType> > discontinuousSpace(
72  const shared_ptr<const Space<BasisFunctionType> >& self) const;
73  virtual bool isDiscontinuous() const;
74 
75  virtual bool isBarycentric() const {
76  return false;
77  }
78 
79  virtual shared_ptr<const Space<BasisFunctionType> > barycentricSpace(
80  const shared_ptr<const Space<BasisFunctionType> >& self) const;
81 
82 
83  virtual int domainDimension() const;
84  virtual int codomainDimension() const;
85 
92  virtual ElementVariant elementVariant(const Entity<0>& element) const;
93  virtual void setElementVariant(const Entity<0>& element,
94  ElementVariant variant);
95 
97  const Entity<0>& element) const;
98 
99  virtual bool spaceIsCompatible(const Space<BasisFunctionType>& other) const;
100 
101  virtual SpaceIdentifier spaceIdentifier() const {
102  return PIECEWISE_CONSTANT_SCALAR;
103  }
104 
105  virtual size_t globalDofCount() const;
106  virtual size_t flatLocalDofCount() const;
107  virtual void getGlobalDofs(const Entity<0>& element,
108  std::vector<GlobalDofIndex>& dofs) const;
109  virtual void global2localDofs(
110  const std::vector<GlobalDofIndex>& globalDofs,
111  std::vector<std::vector<LocalDof> >& localDofs) const;
112  virtual void flatLocal2localDofs(
113  const std::vector<FlatLocalDofIndex>& globalDofs,
114  std::vector<LocalDof>& localDofs) const;
115 
116  virtual void getGlobalDofInterpolationPoints(
117  arma::Mat<CoordinateType>& points) const;
119  arma::Mat<CoordinateType>& normals) const;
120 
121  virtual void getGlobalDofPositions(
122  std::vector<Point3D<CoordinateType> >& positions) const;
123  virtual void getFlatLocalDofPositions(
124  std::vector<Point3D<CoordinateType> >& positions) const;
125 
126  virtual void getGlobalDofBoundingBoxes(
127  std::vector<BoundingBox<CoordinateType> >& bboxes) const;
128  virtual void getFlatLocalDofBoundingBoxes(
129  std::vector<BoundingBox<CoordinateType> >& bboxes) const;
130 
131  virtual void getGlobalDofNormals(
132  std::vector<Point3D<CoordinateType> >& normals) const;
133  virtual void getFlatLocalDofNormals(
134  std::vector<Point3D<CoordinateType> >& normals) const;
135 
136  virtual void dumpClusterIds(
137  const char* fileName,
138  const std::vector<unsigned int>& clusterIdsOfGlobalDofs) const;
139  virtual void dumpClusterIdsEx(
140  const char* fileName,
141  const std::vector<unsigned int>& clusterIdsOfGlobalDofs,
142  DofType dofType) const;
143 
144 private:
145  void assignDofsImpl(const GridSegment& segment);
146 
147 private:
148  std::auto_ptr<GridView> m_view;
149  GridSegment m_segment;
151  std::vector<std::vector<GlobalDofIndex> > m_local2globalDofs;
152  std::vector<std::vector<LocalDof> > m_global2localDofs;
153  mutable shared_ptr<Space<BasisFunctionType> > m_barycentricSpace;
154  mutable tbb::mutex m_barycentricSpaceMutex;
155 
156 };
157 
158 } // namespace Bempp
159 
160 #endif
virtual shared_ptr< const Space< BasisFunctionType > > discontinuousSpace(const shared_ptr< const Space< BasisFunctionType > > &self) const
Return a shared pointer to an appropriate counterpart to this space, with basis functions extending o...
Definition: piecewise_constant_scalar_space.cpp:63
virtual bool isDiscontinuous() const
Return true if each basis function of this space extends over only a single element, false otherwise.
Definition: piecewise_constant_scalar_space.cpp:75
Base class for spaces of scalar-valued functions.
Definition: scalar_space.hpp:36
virtual bool isBarycentric() const
Return true if space is based on a barycentric refinement.
Definition: piecewise_constant_scalar_space.hpp:75
Function space.
Definition: assembled_potential_operator.hpp:35
virtual int codomainDimension() const
Dimension of the codomain of the functions.
Definition: piecewise_constant_scalar_space.cpp:87
virtual size_t flatLocalDofCount() const
Total number of local degrees of freedom on all elements.
Definition: piecewise_constant_scalar_space.cpp:208
Bounding box with a reference point.
Definition: bounding_box.hpp:13
PiecewiseConstantScalarSpace(const shared_ptr< const Grid > &grid)
Constructor.
Definition: piecewise_constant_scalar_space.cpp:44
virtual int domainDimension() const
Dimension of the grid on which functions from this space are defined.
Definition: piecewise_constant_scalar_space.cpp:81
virtual void getFlatLocalDofPositions(std::vector< Point3D< CoordinateType > > &positions) const
Retrieve the reference positions of local degrees of freedom ordered by their flat index...
Definition: piecewise_constant_scalar_space.cpp:274
virtual void getGlobalDofInterpolationPoints(arma::Mat< CoordinateType > &points) const
Retrieve the interpolation points of the global degrees of freedom.
Definition: piecewise_constant_scalar_space.cpp:245
virtual shared_ptr< const Space< BasisFunctionType > > barycentricSpace(const shared_ptr< const Space< BasisFunctionType > > &self) const
Return an equivalent space (in terms of global Dofs), but defined using local dofs on the barycentric...
Definition: piecewise_constant_scalar_space.cpp:134
Collection of shape functions defined on a reference element.
Definition: default_local_assembler_for_operators_on_surfaces_utilities.hpp:34
virtual void dumpClusterIds(const char *fileName, const std::vector< unsigned int > &clusterIdsOfGlobalDofs) const
Write a VTK file showing the distribution of global or flat local degrees of freedom into clusters...
Definition: piecewise_constant_scalar_space.cpp:354
virtual void flatLocal2localDofs(const std::vector< FlatLocalDofIndex > &globalDofs, std::vector< LocalDof > &localDofs) const
Map flat indices of local degrees of freedom to local degrees of freedom.
Definition: piecewise_constant_scalar_space.cpp:233
virtual void getGlobalDofBoundingBoxes(std::vector< BoundingBox< CoordinateType > > &bboxes) const
Retrieve bounding boxes of global degrees of freedom.
Definition: piecewise_constant_scalar_space.cpp:281
shared_ptr< const Grid > grid() const
Shared pointer to the grid on which the functions from this space are defined.
Definition: space.hpp:183
Segment of a grid.
Definition: grid_segment.hpp:46
virtual void getGlobalDofs(const Entity< 0 > &element, std::vector< GlobalDofIndex > &dofs) const
Map local degrees of freedom residing on an element to global degrees of freedom. ...
Definition: piecewise_constant_scalar_space.cpp:214
virtual void getFlatLocalDofBoundingBoxes(std::vector< BoundingBox< CoordinateType > > &bboxes) const
Retrieve bounding boxes of local degrees of freedom ordered by their flat index.
Definition: piecewise_constant_scalar_space.cpp:331
virtual ElementVariant elementVariant(const Entity< 0 > &element) const
Return the variant of element element.
Definition: piecewise_constant_scalar_space.cpp:101
virtual void setElementVariant(const Entity< 0 > &element, ElementVariant variant)
Set the variant of element element to variant.
Definition: piecewise_constant_scalar_space.cpp:152
virtual void dumpClusterIdsEx(const char *fileName, const std::vector< unsigned int > &clusterIdsOfGlobalDofs, DofType dofType) const
Write a VTK file showing the distribution of global or flat local degrees of freedom into clusters...
Definition: piecewise_constant_scalar_space.cpp:362
virtual size_t globalDofCount() const
Number of global degrees of freedom.
Definition: piecewise_constant_scalar_space.cpp:202
virtual bool spaceIsCompatible(const Space< BasisFunctionType > &other) const
Return true if other is compatible to this space, i.e. the global dofs of the two spaces agree with e...
Definition: piecewise_constant_scalar_space.cpp:115
virtual const Fiber::Shapeset< BasisFunctionType > & shapeset(const Entity< 0 > &element) const
Reference to the shapeset attached to the specified element.
Definition: piecewise_constant_scalar_space.cpp:94
virtual void getNormalsAtGlobalDofInterpolationPoints(arma::Mat< CoordinateType > &normals) const
Retrieve the unit vectors normal to the grid at the interpolation points of the global degrees of fre...
Definition: piecewise_constant_scalar_space.cpp:254
virtual void getGlobalDofPositions(std::vector< Point3D< CoordinateType > > &positions) const
Retrieve the reference positions of global degrees of freedom.
Definition: piecewise_constant_scalar_space.cpp:262
Abstract wrapper of an entity of codimension 0.
Definition: entity.hpp:81
virtual SpaceIdentifier spaceIdentifier() const
Return the identifier of the space.
Definition: piecewise_constant_scalar_space.hpp:101
virtual void getGlobalDofNormals(std::vector< Point3D< CoordinateType > > &normals) const
Retrieve the unit vectors normal to the grid at the positions of global degrees of freedom...
Definition: piecewise_constant_scalar_space.cpp:338
Space of piecewise constant scalar functions.
Definition: piecewise_constant_scalar_space.hpp:47
virtual void getFlatLocalDofNormals(std::vector< Point3D< CoordinateType > > &normals) const
Retrieve the unit vectors normal to the grid at the positions of global degrees of freedom...
Definition: piecewise_constant_scalar_space.cpp:347
virtual void global2localDofs(const std::vector< GlobalDofIndex > &globalDofs, std::vector< std::vector< LocalDof > > &localDofs) const
Map global degrees of freedom to local degrees of freedom.
Definition: piecewise_constant_scalar_space.cpp:223