BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
entity.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_entity_hpp
22 #define bempp_entity_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "geometry_type.hpp"
27 
28 #include <boost/utility/enable_if.hpp>
29 #include <dune/common/static_assert.hh>
30 #include <dune/grid/common/geometry.hh>
31 #include <memory>
32 #include <stdexcept>
33 
34 namespace Bempp
35 {
36 
38 class Geometry;
39 template<int codim> class EntityPointer;
40 template<int codim> class EntityIterator;
45 template<int codim>
46 class Entity
47 {
48 public:
50  virtual ~Entity() {
51  }
52 
54  enum {
55  codimension = codim
56  };
57 
59  virtual size_t level() const = 0;
60 
69  virtual const Geometry& geometry() const = 0;
70 
75  virtual GeometryType type() const = 0;
76 };
77 
80 template<>
81 class Entity<0>
82 {
83 public:
85  virtual ~Entity() {
86  }
87 
89  enum {
90  codimension = 0
91  };
92 
97  virtual size_t level() const = 0;
98 
107  virtual const Geometry& geometry() const = 0;
108 
113  virtual GeometryType type() const = 0;
114 
120  // Default implementation, specialisations for potentially allowed
121  // codimensions (1 to 3) follow after class declaration.
122  template<int codimSub> size_t subEntityCount() const {
123  return 0;
124  }
125 
129  // Default implementation, specialisations for potentially allowed codimensions follow
130  // after class declaration.
131  template<int codimSub>
132  std::auto_ptr<EntityIterator<codimSub> > subEntityIterator() const {
133  throw std::logic_error("Entity::subEntityIterator(): invalid entity codimension");
134  }
135 
141  virtual std::auto_ptr<EntityPointer<0> > father() const = 0;
142 
146  virtual bool hasFather() const = 0;
147 
149  virtual bool isLeaf() const = 0;
150 
155  virtual bool isRegular() const = 0;
156 
163  virtual std::auto_ptr<EntityIterator<0> > sonIterator(int maxlevel) const = 0;
164 
167  virtual bool isNew() const = 0;
168 
174  virtual bool mightVanish() const = 0;
175 
177  virtual int domain() const = 0;
178 
179  // Deferred for possible later implementation:
180  // * Iteration over neighbours: Dune methods ileafbegin(), ileafend(), ilevelbegin(), ilevelend()
181  // * Information about the way this element has been subdivided from
182  // its father element: Dune method geometryInFather().
183 
184 private:
190  virtual std::auto_ptr<EntityIterator<1> > subEntityCodim1Iterator() const = 0;
192  virtual std::auto_ptr<EntityIterator<2> > subEntityCodim2Iterator() const = 0;
194  virtual std::auto_ptr<EntityIterator<3> > subEntityCodim3Iterator() const = 0;
195 
197  virtual size_t subEntityCodim1Count() const = 0;
199  virtual size_t subEntityCodim2Count() const = 0;
201  virtual size_t subEntityCodim3Count() const = 0;
202 
204 };
205 
206 } // namespace Bempp
207 
208 #include "entity_iterator.hpp"
209 
210 namespace Bempp
211 {
212 
213 template<>
214 inline std::auto_ptr<EntityIterator<1> > Entity<0>::subEntityIterator<1>() const
215 {
216  return subEntityCodim1Iterator();
217 }
218 template<>
219 inline std::auto_ptr<EntityIterator<2> > Entity<0>::subEntityIterator<2>() const
220 {
221  return subEntityCodim2Iterator();
222 }
223 template<>
224 inline std::auto_ptr<EntityIterator<3> > Entity<0>::subEntityIterator<3>() const
225 {
226  return subEntityCodim3Iterator();
227 }
228 
229 template<>
230 inline size_t Entity<0>::subEntityCount<1>() const
231 {
232  return subEntityCodim1Count();
233 }
234 template<>
235 inline size_t Entity<0>::subEntityCount<2>() const
236 {
237  return subEntityCodim2Count();
238 }
239 template<>
240 inline size_t Entity<0>::subEntityCount<3>() const
241 {
242  return subEntityCodim3Count();
243 }
244 
245 } // namespace Bempp
246 
247 #endif
size_t subEntityCount() const
Number of subentities of codimension codimSub.
Definition: entity.hpp:120
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 GeometryType type() const =0
Type of the reference element.
virtual ~Entity()
Destructor.
Definition: entity.hpp:85
virtual ~Entity()
Destructor.
Definition: entity.hpp:50
virtual size_t level() const =0
Entity level.
std::auto_ptr< EntityIterator< codimSub > > subEntityIterator() const
Iterator over subentities of codimension codimSub.
Definition: entity.hpp:130
virtual const Geometry & geometry() const =0
Reference to the geometry of this entity.