BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
grid_view.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 #ifndef bempp_grid_view_hpp
21 #define bempp_grid_view_hpp
22 
23 #include "../common/common.hpp"
24 
25 #include "geometry_type.hpp"
26 #include "entity_iterator.hpp"
27 
28 #include "../common/armadillo_fwd.hpp"
29 #include <boost/utility/enable_if.hpp>
30 #include <dune/grid/io/file/vtk/vtkwriter.hh>
31 #include <memory>
32 #include <stdexcept>
33 
34 namespace Bempp
35 {
36 
38 template<int codim> class Entity;
39 template<int codim> class EntityCache;
40 class IndexSet;
41 class Mapper;
42 class ReverseElementMapper;
43 class VtkWriter;
48 class GridView
49 {
50 public:
52  virtual ~GridView() {
53  }
54 
56  virtual int dim() const = 0;
57 
59  virtual int dimWorld() const = 0;
60 
62  virtual const IndexSet& indexSet() const = 0;
63 
65  virtual const Mapper& elementMapper() const = 0;
66 
68  virtual size_t entityCount(int codim) const = 0;
69 
71  virtual size_t entityCount(const GeometryType &type) const = 0;
72 
78  virtual bool containsEntity(const Entity<0>& e) const = 0;
83  virtual bool containsEntity(const Entity<1>& e) const = 0;
88  virtual bool containsEntity(const Entity<2>& e) const = 0;
93  virtual bool containsEntity(const Entity<3>& e) const = 0;
94 
96  // Default implementation; specialisations for potentially allowed codimensions follow
97  // after class declaration.
98  template<int codim>
99  std::auto_ptr<EntityIterator<codim> > entityIterator() const {
100  throw std::logic_error("GridView::entityIterator(): invalid entity codimension");
101  }
102 
123  void getRawElementData(arma::Mat<float>& vertices,
124  arma::Mat<int>& elementCorners,
125  arma::Mat<char>& auxData ) const;
127  void getRawElementData(arma::Mat<double>& vertices,
128  arma::Mat<int>& elementCorners,
129  arma::Mat<char>& auxData ) const;
130 
131 
138  void getRawElementData(arma::Mat<double>& vertices,
139  arma::Mat<int>& elementCorners,
140  arma::Mat<char>& auxData,
141  std::vector<int>& domainIndices) const;
143  void getRawElementData(arma::Mat<float>& vertices,
144  arma::Mat<int>& elementCorners,
145  arma::Mat<char>& auxData,
146  std::vector<int>& domainIndices) const;
147 
158  virtual const ReverseElementMapper& reverseElementMapper() const = 0;
159 
163  virtual std::auto_ptr<VtkWriter> vtkWriter(Dune::VTK::DataMode dm=Dune::VTK::conforming) const = 0;
164 
165  // Deferred for later implementation:
166  // * Iteration over neighbours: Dune methods ibegin() and iend().
167 
168 private:
169  virtual void getRawElementDataDoubleImpl(
170  arma::Mat<double>& vertices,
171  arma::Mat<int>& elementCorners,
172  arma::Mat<char>& auxData,
173  std::vector<int>* domainIndices) const = 0;
174  virtual void getRawElementDataFloatImpl(
175  arma::Mat<float>& vertices,
176  arma::Mat<int>& elementCorners,
177  arma::Mat<char>& auxData,
178  std::vector<int>* domainIndices) const = 0;
179 
181  virtual std::auto_ptr<EntityIterator<0> > entityCodim0Iterator() const = 0;
183  virtual std::auto_ptr<EntityIterator<1> > entityCodim1Iterator() const = 0;
185  virtual std::auto_ptr<EntityIterator<2> > entityCodim2Iterator() const = 0;
187  virtual std::auto_ptr<EntityIterator<3> > entityCodim3Iterator() const = 0;
188 };
189 
190 inline void GridView::getRawElementData(arma::Mat<double>& vertices,
191  arma::Mat<int>& elementCorners,
192  arma::Mat<char>& auxData) const
193 {
194  getRawElementDataDoubleImpl(vertices, elementCorners, auxData, 0);
195 }
196 
197 inline void GridView::getRawElementData(arma::Mat<float>& vertices,
198  arma::Mat<int>& elementCorners,
199  arma::Mat<char>& auxData) const
200 {
201  getRawElementDataFloatImpl(vertices, elementCorners, auxData, 0);
202 }
203 
204 inline void GridView::getRawElementData(arma::Mat<double>& vertices,
205  arma::Mat<int>& elementCorners,
206  arma::Mat<char>& auxData,
207  std::vector<int>& domainIndices) const
208 {
209  getRawElementDataDoubleImpl(vertices, elementCorners, auxData,
210  &domainIndices);
211 }
212 
213 inline void GridView::getRawElementData(arma::Mat<float>& vertices,
214  arma::Mat<int>& elementCorners,
215  arma::Mat<char>& auxData,
216  std::vector<int>& domainIndices) const
217 {
218  getRawElementDataFloatImpl(vertices, elementCorners, auxData,
219  &domainIndices);
220 }
221 
222 
223 template<>
224 inline std::auto_ptr<EntityIterator<0> > GridView::entityIterator<0>() const
225 {
226  return entityCodim0Iterator();
227 }
228 template<>
229 inline std::auto_ptr<EntityIterator<1> > GridView::entityIterator<1>() const
230 {
231  return entityCodim1Iterator();
232 }
233 template<>
234 inline std::auto_ptr<EntityIterator<2> > GridView::entityIterator<2>() const
235 {
236  return entityCodim2Iterator();
237 }
238 template<>
239 inline std::auto_ptr<EntityIterator<3> > GridView::entityIterator<3>() const
240 {
241  return entityCodim3Iterator() ;
242 }
243 
244 } // namespace Bempp
245 
246 #endif
virtual int dimWorld() const =0
Dimension of the space containing the grid.
virtual int dim() const =0
Dimension of the grid.
Abstract wrapper of an entity of codimension codim.
Definition: entity.hpp:46
Dune::GeometryType GeometryType
Identifier of geometry type.
Definition: geometry_type.hpp:34
virtual ~GridView()
Definition: grid_view.hpp:52
virtual const Mapper & elementMapper() const =0
The element mapper.
virtual const IndexSet & indexSet() const =0
The index set.
Abstract wrapper of an index set.
Definition: index_set.hpp:36
void getRawElementData(arma::Mat< float > &vertices, arma::Mat< int > &elementCorners, arma::Mat< char > &auxData) const
Get raw data describing the geometry of all codim-0 entities contained in this grid view...
Definition: grid_view.hpp:197
virtual std::auto_ptr< EntityIterator< 2 > > entityCodim2Iterator() const =0
Iterator over entities of codimension 2 contained in this view.
Mapping from codim-0 entity indices to entity pointers.
Definition: reverse_element_mapper.hpp:37
virtual std::auto_ptr< EntityIterator< 0 > > entityCodim0Iterator() const =0
Iterator over entities of codimension 0 contained in this view.
virtual std::auto_ptr< EntityIterator< 3 > > entityCodim3Iterator() const =0
Iterator over entities of codimension 3 contained in this view.
Abstract wrapper of a grid view.
Definition: grid_view.hpp:48
virtual const ReverseElementMapper & reverseElementMapper() const =0
Mapping from codim-0 entity index to entity pointer.
virtual size_t entityCount(int codim) const =0
Number of entities with codimension codim.
virtual std::auto_ptr< EntityIterator< 1 > > entityCodim1Iterator() const =0
Iterator over entities of codimension 1 contained in this view.
std::auto_ptr< EntityIterator< codim > > entityIterator() const
Iterator over entities of codimension codim contained in this view.
Definition: grid_view.hpp:99
Abstract wrapper of an entity of codimension 0.
Definition: entity.hpp:81
Abstract mapper class.
Definition: mapper.hpp:39
virtual std::auto_ptr< VtkWriter > vtkWriter(Dune::VTK::DataMode dm=Dune::VTK::conforming) const =0
Create a VtkWriter for this grid view.
virtual bool containsEntity(const Entity< 0 > &e) const =0
True if the entity e of codimension 0 is contained in this grid view.