BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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_space_hpp
22 #define bempp_space_hpp
23 
24 #include "space_identifier.hpp"
25 
26 #include "../common/common.hpp"
27 #include "bempp/common/config_trilinos.hpp"
28 
29 
30 #include "../common/bounding_box.hpp"
31 #include "../common/not_implemented_error.hpp"
32 #include "../common/deprecated.hpp"
33 #include "../common/shared_ptr.hpp"
34 #include "../common/types.hpp"
35 #include "../fiber/basis.hpp"
36 #include "../fiber/collection_of_basis_transformations.hpp"
37 #include "../fiber/scalar_traits.hpp"
38 
39 #include "../common/armadillo_fwd.hpp"
40 #include <vector>
41 
42 namespace Fiber
43 {
44 
46 template <typename ValueType> class BasisData;
47 template <typename CoordinateType> class GeometricalData;
50 } // namespace Fiber
51 
52 namespace Bempp
53 {
54 
56 class Grid;
57 class GridView;
58 class GeometryFactory;
59 template <int codim> class Entity;
60 template <int codim> class EntityPointer;
61 template <typename ValueType> class DiscreteSparseBoundaryOperator;
62 template <typename ValueType> class DiscreteBoundaryOperator;
65 enum DofType
66 {
67  GLOBAL_DOFS, FLAT_LOCAL_DOFS
68 };
69 
86 template <typename BasisFunctionType>
87 class Space
88 {
89 public:
100 
101  // A grid reference is necessary because e.g. when setting the element
102  // variant it is necessary to check whether the element is triangular
103  // or quadrilateral. Also, requests for element refinement should probably
104  // be made via Space rather than via Grid.
114  explicit Space(const shared_ptr<const Grid>& grid);
115 
117  Space(const Space<BasisFunctionType>& other);
118 
120  virtual ~Space();
121 
124 
125 
160  virtual shared_ptr<const Space<BasisFunctionType> > discontinuousSpace(
161  const shared_ptr<const Space<BasisFunctionType> >& self) const = 0;
162 
165  virtual bool isDiscontinuous() const = 0;
166 
169  virtual bool isBarycentric() const = 0;
170 
173  virtual int domainDimension() const = 0;
174 
179  virtual int codomainDimension() const = 0;
180 
183  shared_ptr<const Grid> grid() const { return m_grid; }
184 
191  const Entity<0>& element) const {
192  // It might be good to print a deprecation warning
193  return dynamic_cast<const Fiber::Basis<BasisFunctionType>& >(
194  shapeset(element));
195  }
196 
200  const Entity<0>& element) const {
201  throw NotImplementedError(
202  "Space::shapeset(): not implemented.\nNote that the "
203  "Space::basis() function has been renamed to shapeset(). "
204  "If you have implemented basis() in a subclass of Space, "
205  "please implement shapeset() instead.");
206  }
207 
215  return dynamic_cast<const CollectionOfBasisTransformations&>(
217  }
218 
221  virtual shared_ptr<const Space<BasisFunctionType> > barycentricSpace(
222  const shared_ptr<const Space<BasisFunctionType> >& self) const;
223 
225  unsigned int level() const {return m_level; }
226 
228  int gridDimension() const;
229 
231  int worldDimension() const;
232 
234  const GridView& gridView() const;
235 
250  throw NotImplementedError(
251  "Space::basisFunctionValue(): not implemented.\n"
252  "Note that the Space::shapeFunctionValue() function has "
253  "been renamed to basisFunctionValue(). If you have "
254  "implemented shapeFunctionValue() in a subclass of Space, "
255  "please implement basisFunctionValue() instead.");
256  }
257 
271  virtual void setElementVariant(const Entity<0>& element, ElementVariant variant) = 0;
272 
276  virtual ElementVariant elementVariant(const Entity<0>& element) const = 0;
277 
280  shared_ptr<GeometryFactory> elementGeometryFactory() const {
281  return m_elementGeometryFactory;
282  }
283 
284  // additional functions for e.g. increasing polynomial order of all elements
285  // ...
286 
297 
304  BEMPP_DEPRECATED bool dofsAssigned() const;
305 
307  virtual size_t flatLocalDofCount() const = 0;
308 
310  virtual size_t globalDofCount() const = 0;
311 
326  virtual void getGlobalDofs(const Entity<0>& element,
327  std::vector<GlobalDofIndex>& dofs) const;
328 
343  virtual void getGlobalDofs(const Entity<0>& element,
344  std::vector<GlobalDofIndex>& dofs,
345  std::vector<BasisFunctionType>& localDofWeights) const;
346 
348  virtual bool gridIsIdentical(const Space<BasisFunctionType>& other) const;
349 
351  virtual SpaceIdentifier spaceIdentifier() const = 0;
352 
355  virtual bool spaceIsCompatible(const Space<BasisFunctionType>& other) const = 0;
356 
369  virtual void global2localDofs(
370  const std::vector<GlobalDofIndex>& globalDofs,
371  std::vector<std::vector<LocalDof> >& localDofs) const;
372 
373  virtual void global2localDofs(
374  const std::vector<GlobalDofIndex>& globalDofs,
375  std::vector<std::vector<LocalDof> >& localDofs,
376  std::vector<std::vector<BasisFunctionType> >& localDofWeights) const;
377 
386  virtual void flatLocal2localDofs(
387  const std::vector<FlatLocalDofIndex>& flatLocalDofs,
388  std::vector<LocalDof>& localDofs) const = 0;
389 
424  virtual void getGlobalDofInterpolationPoints(
425  arma::Mat<CoordinateType>& points) const {
426  throw NotImplementedError(
427  "Space::getGlobalDofInterpolationPoints(): not implemented");
428  }
429 
438  arma::Mat<CoordinateType>& normals) const {
439  throw NotImplementedError(
440  "Space::getNormalsAtGlobalDofInterpolationPoints(): not implemented");
441  }
442 
450  arma::Mat<CoordinateType>& directions) const {
451  throw NotImplementedError(
452  "Space::getGlobalDofInterpolationDirections(): not implemented");
453  }
454 
459  // These functions are used only by the ACA assembler.
460  // For the moment, Point will always be 3D, independently from the
461  // actual dimension of the space. Once Ahmed's bemcluster is made dimension-
462  // independent, we may come up with a more elegant solution.
472  virtual void getGlobalDofBoundingBoxes(
473  std::vector<BoundingBox<CoordinateType> >& boundingBoxes) const {
474  throw NotImplementedError("Space::getGlobalDofBoundingBoxes(): "
475  "implementation missing");
476  }
477 
488  virtual void getFlatLocalDofBoundingBoxes(
489  std::vector<BoundingBox<CoordinateType> >& boundingBoxes) const {
490  throw NotImplementedError("Space::getFlatLocalDofBoundingBoxes(): "
491  "implementation missing");
492  }
493 
504  virtual void getGlobalDofPositions(
505  std::vector<Point3D<CoordinateType> >& positions) const = 0;
506 
518  virtual void getFlatLocalDofPositions(
519  std::vector<Point3D<CoordinateType> >& positions) const = 0;
528  virtual void getGlobalDofNormals(
529  std::vector<Point3D<CoordinateType> >& normals) const {
530  throw NotImplementedError("Space::getGlobalDofNormals(): not implemented");
531  }
540  virtual void getFlatLocalDofNormals(
541  std::vector<Point3D<CoordinateType> >& normals) const {
542  throw NotImplementedError("Space::getFlatLocalDofNormals(): not implemented");
543  }
544 
568  BEMPP_DEPRECATED virtual void dumpClusterIds(
569  const char* fileName,
570  const std::vector<unsigned int>& clusterIdsOfGlobalDofs) const = 0;
571 
592  virtual void dumpClusterIdsEx(
593  const char* fileName,
594  const std::vector<unsigned int>& clusterIdsOfGlobalDofs,
595  DofType dofType) const;
598 private:
600  shared_ptr<const Grid> m_grid;
601  shared_ptr<GeometryFactory> m_elementGeometryFactory;
602  unsigned int m_level;
603  std::auto_ptr<GridView> m_view;
605 };
606 
620 template <typename BasisFunctionType>
621 void getAllShapesets(const Space<BasisFunctionType>& space,
622  std::vector<const Fiber::Shapeset<BasisFunctionType>*>& shapesets);
623 
629 template <typename BasisFunctionType>
630 void BEMPP_DEPRECATED getAllBases(const Space<BasisFunctionType>& space,
631  std::vector<const Fiber::Basis<BasisFunctionType>*>& bases);
632 
636 template <typename BasisFunctionType>
637 int maximumShapesetOrder(const Space<BasisFunctionType>& space);
638 
639 #ifdef WITH_TRILINOS
640 template <typename BasisFunctionType, typename ResultType>
641 shared_ptr<DiscreteSparseBoundaryOperator<ResultType> >
642 constructOperatorMappingGlobalToFlatLocalDofs(const Space<BasisFunctionType>& space);
643 
644 template <typename BasisFunctionType, typename ResultType>
645 shared_ptr<DiscreteSparseBoundaryOperator<ResultType> >
646 constructOperatorMappingFlatLocalToGlobalDofs(const Space<BasisFunctionType>& space);
647 #endif // WITH_TRILINOS
648 
649 } //namespace Bempp
650 
651 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
shared_ptr< GeometryFactory > elementGeometryFactory() const
Return the GeometryFactory associated with the mesh.
Definition: space.hpp:278
Fiber::ScalarTraits< BasisFunctionType >::ComplexType ComplexType
Equivalent to std::complex&lt;CoordinateType&gt;.
Definition: space.hpp:93
Fiber::CollectionOfShapesetTransformations< CoordinateType > CollectionOfShapesetTransformations
Appropriate instantiation of Fiber::CollectionOfShapesetTransformations.
Definition: space.hpp:96
virtual const Fiber::Shapeset< BasisFunctionType > & shapeset(const Entity< 0 > &element) const
Reference to the shapeset attached to the specified element.
Definition: space.hpp:199
BEMPP_DEPRECATED bool dofsAssigned() const
True if global degrees of freedom have been already assigned to local degrees of freedom, false otherwise.
Definition: space.cpp:172
virtual bool isDiscontinuous() const =0
Return true if each basis function of this space extends over only a single element, false otherwise.
virtual ~Space()
Destructor.
Definition: space.cpp:155
Function space.
Definition: assembled_potential_operator.hpp:35
virtual int codomainDimension() const =0
Dimension of the codomain of the functions.
virtual SpaceIdentifier spaceIdentifier() const =0
Return the identifier of the space.
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: space.hpp:520
#define BEMPP_DEPRECATED
Macro used to mark deprecated functions or classes.
Definition: deprecated.hpp:41
virtual void getGlobalDofPositions(std::vector< Point3D< CoordinateType > > &positions) const =0
Retrieve the reference positions of global degrees of freedom.
Exception thrown on attempt to access an unimplemented feature.
Definition: not_implemented_error.hpp:32
virtual BEMPP_DEPRECATED const Fiber::Basis< BasisFunctionType > & basis(const Entity< 0 > &element) const
Reference to the shapeset attached to the specified element.
Definition: space.hpp:190
virtual shared_ptr< const Space< BasisFunctionType > > discontinuousSpace(const shared_ptr< const Space< BasisFunctionType > > &self) const =0
Return a shared pointer to an appropriate counterpart to this space, with basis functions extending o...
virtual void flatLocal2localDofs(const std::vector< FlatLocalDofIndex > &flatLocalDofs, std::vector< LocalDof > &localDofs) const =0
Map flat indices of local degrees of freedom to local degrees of freedom.
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: space.cpp:236
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: space.hpp:532
Space(const shared_ptr< const Grid > &grid)
Constructor.
Definition: space.cpp:137
virtual BEMPP_DEPRECATED const CollectionOfBasisTransformations & shapeFunctionValue() const
Transformation mapping shape functions to basis functions.
Definition: space.hpp:214
int worldDimension() const
Return the underlying world dimension.
Definition: space.cpp:185
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: space.cpp:207
int gridDimension() const
Return the underlying grid dimension.
Definition: space.cpp:179
Fiber::ScalarTraits< BasisFunctionType >::RealType CoordinateType
Type used to represent coordinates.
Definition: space.hpp:91
virtual const CollectionOfShapesetTransformations & basisFunctionValue() const
Transformation mapping shape functions to basis functions.
Definition: space.hpp:249
Collection of shape functions defined on a reference element.
Definition: default_local_assembler_for_operators_on_surfaces_utilities.hpp:34
virtual int domainDimension() const =0
Dimension of the grid on which functions from this space are defined.
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: space.cpp:337
virtual ElementVariant elementVariant(const Entity< 0 > &element) const =0
Return current variant of element element.
virtual BEMPP_DEPRECATED void dumpClusterIds(const char *fileName, const std::vector< unsigned int > &clusterIdsOfGlobalDofs) const =0
Write a VTK file showing the distribution of global or flat local degrees of freedom into clusters...
virtual bool isBarycentric() const =0
Return true if space is based on a barycentric refinement.
virtual size_t flatLocalDofCount() const =0
Total number of local degrees of freedom on all elements.
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
shared_ptr< const Grid > grid() const
Shared pointer to the grid on which the functions from this space are defined.
Definition: space.hpp:183
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: space.cpp:215
Fiber::CollectionOfBasisTransformations< CoordinateType > CollectionOfBasisTransformations
Appropriate instantiation of Fiber::CollectionOfBasisTransformations.
Definition: space.hpp:99
Space< BasisFunctionType > & operator=(const Space< BasisFunctionType > &other)
Assignment operator.
Definition: space.cpp:160
virtual bool gridIsIdentical(const Space< BasisFunctionType > &other) const
Return true if both spaces act on the same grid.
Definition: space.cpp:196
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: space.hpp:431
Collection of shape function transformations.
Definition: collection_of_basis_transformations.hpp:36
virtual void getGlobalDofInterpolationPoints(arma::Mat< CoordinateType > &points) const
Retrieve the interpolation points of the global degrees of freedom.
Definition: space.hpp:418
unsigned int level() const
Return the grid level of the current space.
Definition: space.hpp:225
BEMPP_DEPRECATED void assignDofs()
Assign global degrees of freedom to local degrees of freedom.
Definition: space.cpp:167
virtual void getFlatLocalDofPositions(std::vector< Point3D< CoordinateType > > &positions) const =0
Retrieve the reference positions of local degrees of freedom ordered by their flat index...
virtual void getGlobalDofBoundingBoxes(std::vector< BoundingBox< CoordinateType > > &boundingBoxes) const
Retrieve bounding boxes of global degrees of freedom.
Definition: space.hpp:464
virtual size_t globalDofCount() const =0
Number of global degrees of freedom.
virtual void setElementVariant(const Entity< 0 > &element, ElementVariant variant)=0
Set the variant of element element to variant.
Abstract wrapper of an entity of codimension 0.
Definition: entity.hpp:81
virtual void getFlatLocalDofBoundingBoxes(std::vector< BoundingBox< CoordinateType > > &boundingBoxes) const
Retrieve bounding boxes of local degrees of freedom ordered by their flat index.
Definition: space.hpp:480
virtual bool spaceIsCompatible(const Space< BasisFunctionType > &other) const =0
Return true if other is compatible to this space, i.e. the global dofs of the two spaces agree with e...
virtual void getGlobalDofInterpolationDirections(arma::Mat< CoordinateType > &directions) const
Retrieve the interpolation directions of the global degrees of freedom.
Definition: space.hpp:443