BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
concrete_index_set.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_concrete_index_set_hpp
21 #define bempp_concrete_index_set_hpp
22 
23 #include "../common/common.hpp"
24 
25 #include "index_set.hpp"
26 #include "concrete_entity.hpp"
27 
28 #include <stdexcept>
29 
30 namespace Bempp
31 {
32 
33 
44 template<typename DuneGridView>
46 {
47 public:
49  typedef typename DuneGridView::IndexSet DuneIndexSet;
50 
51 private:
52  const DuneIndexSet* m_dune_index_set;
53 
54 public:
58  explicit ConcreteIndexSet(const DuneIndexSet* dune_index_set) :
59  m_dune_index_set(dune_index_set) {
60  }
61 
63  const DuneIndexSet& duneIndexSet() const {
64  return *m_dune_index_set;
65  }
66 
67  virtual IndexType entityIndex(const Entity<0>& e) const {
68  return entityCodimNIndex(e);
69  }
70  virtual IndexType entityIndex(const Entity<1>& e) const {
71  return entityCodimNIndex(e);
72  }
73  virtual IndexType entityIndex(const Entity<2>& e) const {
74  return entityCodimNIndex(e);
75  }
76  virtual IndexType entityIndex(const Entity<3>& e) const {
77  return entityCodimNIndex(e);
78  }
79 
80  virtual IndexType subEntityIndex(const Entity<0>& e, size_t i, int codimSub) const {
81  // Prevent an assert in FoamGrid from crashing the Python interpreter
82  if (codimSub > DuneGridView::Grid::dimension)
83  throw std::invalid_argument("IndexSet::subEntityIndex(): codimSub exceeds grid dimension");
84  typedef typename DuneGridView::template Codim<0>::Entity DuneEntity;
85  typedef ConcreteEntity<0, DuneEntity> ConcEntity;
86  const ConcEntity& ce = dynamic_cast<const ConcEntity&>(e);
87  return m_dune_index_set->subIndex(ce.duneEntity(), i, codimSub);
88  }
89 
90 private:
91  template <int codim>
92  typename boost::disable_if_c<codim <= DuneGridView::dimension, IndexType>::type
93  entityCodimNIndex(const Entity<codim>& e) const {
94  throw std::logic_error("IndexSet::entityIndex(): invalid entity codimension");
95  }
96 
97  template <int codim>
98  typename boost::enable_if_c<codim <= DuneGridView::dimension, IndexType>::type
99  entityCodimNIndex(const Entity<codim>& e) const {
100  typedef typename DuneGridView::template Codim<codim>::Entity DuneEntity;
101  typedef ConcreteEntity<codim, DuneEntity> ConcEntity;
102  const ConcEntity& ce = dynamic_cast<const ConcEntity&>(e);
103  return m_dune_index_set->index(ce.duneEntity());
104  }
105 };
106 
107 } // namespace Bempp
108 
109 #endif
virtual IndexType entityIndex(const Entity< 2 > &e) const
Index of the entity of codimension 2.
Definition: concrete_index_set.hpp:73
Abstract wrapper of an entity of codimension codim.
Definition: entity.hpp:46
Wrapper of a Dune entity of type DuneEntity and codimension 0.
Definition: concrete_entity_decl.hpp:117
virtual IndexType subEntityIndex(const Entity< 0 > &e, size_t i, int codimSub) const
Index of i&#39;th subentity of codimension codimSub of entity e of codimension 0.
Definition: concrete_index_set.hpp:80
virtual IndexType entityIndex(const Entity< 0 > &e) const
Index of the entity of codimension 0.
Definition: concrete_index_set.hpp:67
Abstract wrapper of an index set.
Definition: index_set.hpp:36
virtual IndexType entityIndex(const Entity< 3 > &e) const
Index of the entity of codimension 3.
Definition: concrete_index_set.hpp:76
size_t IndexType
Index type.
Definition: index_set.hpp:47
ConcreteIndexSet(const DuneIndexSet *dune_index_set)
Constructor.
Definition: concrete_index_set.hpp:58
DuneGridView::IndexSet DuneIndexSet
Type of the wrapped Dune index set.
Definition: concrete_index_set.hpp:49
Wrapper of the index set specific to a Dune grid view class DuneGridView.
Definition: concrete_index_set.hpp:45
const DuneIndexSet & duneIndexSet() const
Read-only access to the underlying Dune index set.
Definition: concrete_index_set.hpp:63
Abstract wrapper of an entity of codimension 0.
Definition: entity.hpp:81
virtual IndexType entityIndex(const Entity< 1 > &e) const
Index of the entity of codimension 1.
Definition: concrete_index_set.hpp:70