BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
concrete_entity_decl.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_concrete_entity_decl_hpp
22 #define bempp_concrete_entity_decl_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "entity.hpp"
27 #include "concrete_geometry.hpp"
28 #include "domain_index.hpp"
29 #include "geometry_type.hpp"
30 
31 #include <boost/utility/enable_if.hpp>
32 #include <dune/common/static_assert.hh>
33 #include <dune/grid/common/geometry.hh>
34 
35 namespace Bempp
36 {
37 
45 template<int codim, typename DuneEntity>
46 class ConcreteEntity: public Entity<codim>
47 {
48  dune_static_assert((int)DuneEntity::codimension == (int)Entity<codim>::codimension,
49  "ConcreteEntity: codimension mismatch");
50 
51 private:
52  const DuneEntity* m_dune_entity;
56 
57  template<typename > friend class ConcreteEntityPointer;
58  template<typename, typename> friend class ConcreteRangeEntityIterator;
59  template<typename, int> friend class ConcreteSubentityIterator;
60 
61  void setDuneEntity(const DuneEntity* dune_entity) {
62  m_dune_entity = dune_entity;
63  m_geometry.uninitialize();
64  }
65 
66 public:
68  explicit ConcreteEntity() :
69  m_dune_entity(0) {
70  }
71 
74  explicit ConcreteEntity(const DomainIndex& /*domain_index*/) :
75  m_dune_entity(0) {
76  }
77 
81  explicit ConcreteEntity(const DuneEntity* dune_entity) :
82  m_dune_entity(dune_entity) {
83  }
84 
88  ConcreteEntity(const DuneEntity* dune_entity,
89  const DomainIndex& /*domain_index*/) :
90  m_dune_entity(dune_entity) {
91  }
92 
94  const DuneEntity& duneEntity() const {
95  return *m_dune_entity;
96  }
97 
98  virtual size_t level() const {
99  return m_dune_entity->level();
100  }
101 
102  virtual const Geometry& geometry() const {
103  if (!m_geometry.isInitialized())
104  m_geometry.setDuneGeometry(m_dune_entity->geometry());
105  return m_geometry;
106  }
107 
108  virtual GeometryType type() const {
109  return m_dune_entity->type();
110  }
111 };
112 
116 template<typename DuneEntity>
117 class ConcreteEntity<0, DuneEntity> : public Entity<0>
118 {
119  dune_static_assert((int)DuneEntity::codimension == (int)codimension,
120  "ConcreteEntity: codimension mismatch");
121 
122 private:
123  const DuneEntity* m_dune_entity;
124  const DomainIndex& m_domain_index;
128 
129  template<typename > friend class ConcreteEntityPointer;
130  template<typename, typename> friend class ConcreteRangeEntityIterator;
131  template<typename, int> friend class ConcreteSubentityIterator;
132 
133  void setDuneEntity(const DuneEntity* dune_entity) {
134  m_dune_entity = dune_entity;
135  }
136 
137 public:
139  explicit ConcreteEntity(const DomainIndex& domain_index) :
140  m_dune_entity(0), m_domain_index(domain_index) {
141  }
142 
146  ConcreteEntity(const DuneEntity* dune_entity,
147  const DomainIndex& domain_index) :
148  m_dune_entity(dune_entity),
149  m_domain_index(domain_index) {
150  }
151 
153  const DuneEntity& duneEntity() const {
154  return *m_dune_entity;
155  }
156 
157  virtual size_t level() const {
158  return m_dune_entity->level();
159  }
160 
161  virtual const Geometry& geometry() const {
162  m_geometry.setDuneGeometry(m_dune_entity->geometry());
163  return m_geometry;
164  }
165 
166  virtual GeometryType type() const {
167  return m_dune_entity->type();
168  }
169 
170  virtual std::auto_ptr<EntityPointer<0> > father() const;
171 
172  virtual bool hasFather() const {
173  return m_dune_entity->hasFather();
174  }
175 
176  virtual bool isLeaf() const {
177  return m_dune_entity->isLeaf();
178  }
179 
180  virtual bool isRegular() const {
181  return m_dune_entity->isRegular();
182  }
183 
184  virtual std::auto_ptr<EntityIterator<0> > sonIterator(int maxlevel) const;
185 
186  virtual bool isNew() const {
187  return m_dune_entity->isNew();
188  }
189 
190  virtual bool mightVanish() const {
191  return m_dune_entity->mightVanish();
192  }
193 
194  virtual int domain() const {
195  return m_domain_index.domain(*this);
196  }
197 
198 private:
199  virtual std::auto_ptr<EntityIterator<1> > subEntityCodim1Iterator() const {
200  return subEntityCodimNIterator<1>();
201  }
202  virtual std::auto_ptr<EntityIterator<2> > subEntityCodim2Iterator() const {
203  return subEntityCodimNIterator<2>();
204  }
205  virtual std::auto_ptr<EntityIterator<3> > subEntityCodim3Iterator() const {
206  return subEntityCodimNIterator<3>();
207  }
208 
209  // these methods are implemented in entity.hpp (outside the declaration of
210  // ConcreteEntity) because they need to know the full declaration of
211  // concrete iterator (which may not be available at this stage)
212  template <int codimSub>
213  typename boost::disable_if_c<(codimSub <= DuneEntity::dimension), std::auto_ptr<EntityIterator<codimSub> > >::type
214  subEntityCodimNIterator() const;
215 
216  template <int codimSub>
217  typename boost::enable_if_c<(codimSub <= DuneEntity::dimension), std::auto_ptr<EntityIterator<codimSub> > >::type
218  subEntityCodimNIterator() const;
219 
220  virtual size_t subEntityCodim1Count() const {
221  return subEntityCodimNCount<1>();
222  }
223  virtual size_t subEntityCodim2Count() const {
224  return subEntityCodimNCount<2>();
225  }
226  virtual size_t subEntityCodim3Count() const {
227  return subEntityCodimNCount<3>();
228  }
229 
230  template <int codimSub>
231  typename boost::disable_if_c<codimSub <= DuneEntity::dimension, size_t>::type
232  subEntityCodimNCount() const {
233  return 0;
234  }
235 
236  template <int codimSub>
237  typename boost::enable_if_c<codimSub <= DuneEntity::dimension, size_t>::type
238  subEntityCodimNCount() const {
239  return m_dune_entity->template count<codimSub>();
240  }
241 };
242 
243 } // namespace Bempp
244 
245 #endif
virtual const Geometry & geometry() const
Reference to the geometry of this entity.
Definition: concrete_entity_decl.hpp:161
virtual std::auto_ptr< EntityIterator< 3 > > subEntityCodim3Iterator() const
Iterator over subentities of codimension 3.
Definition: concrete_entity_decl.hpp:205
virtual bool isRegular() const
True if the element is of regular type in red/green type refinement.
Definition: concrete_entity_decl.hpp:180
virtual bool isNew() const
True if the entity has been created during the last call to adapt().
Definition: concrete_entity_decl.hpp:186
Wrapper of a Dune geometry of type DuneGeometry.
Definition: concrete_geometry.hpp:72
virtual std::auto_ptr< EntityIterator< 2 > > subEntityCodim2Iterator() const
Iterator over subentities of codimension 2.
Definition: concrete_entity_decl.hpp:202
Wrapper of a Dune entity pointer of type DuneEntityPointer.
Definition: concrete_entity_pointer.hpp:37
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 bool hasFather() const
True if entity has a father entity which can be accessed using the father() method.
Definition: concrete_entity_decl.hpp:172
Iterator over entities referenced by a range of Dune iterators of type DuneEntityIt.
Definition: concrete_range_entity_iterator.hpp:43
virtual GeometryType type() const
Type of the reference element.
Definition: concrete_entity_decl.hpp:108
Wrapper of a Dune entity of type DuneEntity and codimension codim.
Definition: concrete_entity_decl.hpp:46
ConcreteEntity(const DomainIndex &domain_index)
Constructor of an empty entity.
Definition: concrete_entity_decl.hpp:139
ConcreteEntity(const DomainIndex &)
Constructor taking a single unused parameter – for compatibility with the specialization for codim = ...
Definition: concrete_entity_decl.hpp:74
virtual bool mightVanish() const
True if the entity might disappear during the next call to adapt().
Definition: concrete_entity_decl.hpp:190
virtual size_t subEntityCodim2Count() const
Number of subentities of codimension 1.
Definition: concrete_entity_decl.hpp:223
virtual bool isLeaf() const
True if the entity is contained in the leaf grid.
Definition: concrete_entity_decl.hpp:176
ConcreteEntity(const DuneEntity *dune_entity, const DomainIndex &)
Constructor from a pointer to DuneEntity.
Definition: concrete_entity_decl.hpp:88
virtual size_t subEntityCodim1Count() const
Number of subentities of codimension 1.
Definition: concrete_entity_decl.hpp:220
virtual size_t level() const
Entity level
Definition: concrete_entity_decl.hpp:157
ConcreteEntity()
Default constructor.
Definition: concrete_entity_decl.hpp:68
virtual int domain() const
Entity level
Definition: concrete_entity_decl.hpp:194
ConcreteEntity(const DuneEntity *dune_entity)
Constructor from a pointer to DuneEntity.
Definition: concrete_entity_decl.hpp:81
const DuneEntity & duneEntity() const
Read-only access to the underlying Dune entity object.
Definition: concrete_entity_decl.hpp:94
virtual GeometryType type() const
Type of the reference element.
Definition: concrete_entity_decl.hpp:166
virtual size_t subEntityCodim3Count() const
Number of subentities of codimension 1.
Definition: concrete_entity_decl.hpp:226
virtual const Geometry & geometry() const
Reference to the geometry of this entity.
Definition: concrete_entity_decl.hpp:102
Definition: domain_index.hpp:32
Iterator over the subentities of codimension codimSub of a given Dune entity of type DuneEntity...
Definition: concrete_subentity_iterator.hpp:38
virtual std::auto_ptr< EntityIterator< 1 > > subEntityCodim1Iterator() const
Iterator over subentities of codimension 1.
Definition: concrete_entity_decl.hpp:199
virtual size_t level() const
Entity level.
Definition: concrete_entity_decl.hpp:98
ConcreteEntity(const DuneEntity *dune_entity, const DomainIndex &domain_index)
Constructor from a pointer to DuneEntity.
Definition: concrete_entity_decl.hpp:146
const DuneEntity & duneEntity() const
Read-only access to the underlying Dune entity object.
Definition: concrete_entity_decl.hpp:153
Abstract wrapper of a geometry.
Definition: geometry.hpp:45