dune-spgrid 2.7
intersection.hh
Go to the documentation of this file.
1#ifndef DUNE_SPGRID_INTERSECTION_HH
2#define DUNE_SPGRID_INTERSECTION_HH
3
4#include <type_traits>
5
6#include <dune/common/typetraits.hh>
7
8#include <dune/geometry/type.hh>
9
10#include <dune/grid/common/intersection.hh>
11
14
15namespace Dune
16{
17
18 // External Forward Declarations
19 // -----------------------------
20
21 template< int, int, class >
22 class SPEntity;
23
24
25
26 // SPIntersection
27 // --------------
28
35 template< class Grid >
37 {
39
40 typedef typename std::remove_const< Grid >::type::Traits Traits;
41
42 typedef typename Traits::ReferenceCube ReferenceCube;
43
44 public:
45 typedef typename ReferenceCube::ctype ctype;
46
47 static const int dimension = ReferenceCube::dimension;
48 static const int mydimension = dimension-1;
49 static const int dimensionworld = dimension;
50
51 typedef typename Traits::template Codim< 0 >::Entity Entity;
52
53 typedef typename Traits::template Codim< 1 >::Geometry Geometry;
54 typedef typename Traits::template Codim< 1 >::LocalGeometry LocalGeometry;
55
56 private:
59
60 public:
63
65
68
69 private:
70 typedef typename EntityInfo::MultiIndex MultiIndex;
71
72 typedef typename GridLevel::Mesh Mesh;
74 typedef typename PartitionList::Partition Partition;
75
76 public:
77 SPIntersection () = default;
78
79 SPIntersection ( const ElementInfo &insideInfo, int face )
80 : normalId_( face ),
81 insideInfo_( insideInfo )
82 {}
83
85 : normalId_( face ),
86 insideInfo_( entityInfo.gridLevel(), entityInfo.id() - normalId_, entityInfo.partitionNumber() )
87 {}
88
89 bool boundary () const
90 {
91 return (insideInfo_.id()[ normalId_.axis() ] + normalId_.sign() == 2*gridLevel().globalMesh().bound( normalId_ ));
92 }
93
94 int boundaryId () const
95 {
96 return (boundary() ? (indexInInside()+1) : 0);
97 }
98
99 std::size_t boundarySegmentIndex () const
100 {
101 assert( boundary() );
102 return gridLevel().boundaryIndex( insideInfo_.id(), insideInfo_.partitionNumber(), normalId_.face() );
103 }
104
105 bool neighbor () const
106 {
107 const Partition &partition = gridLevel().template partition< All_Partition >().partition( insideInfo_.partitionNumber() );
108 return ((insideInfo_.id()[ normalId_.axis() ] + normalId_.sign() != partition.bound( normalId_ )) || partition.hasNeighbor( indexInInside() ));
109 }
110
111 Entity inside () const { return Entity( EntityImpl( insideInfo_ ) ); }
112
113 Entity outside () const;
114
115 bool conforming () const
116 {
117 return true;
118 }
119
121 {
122 return gridLevel().grid().localFaceGeometry( indexInInside() );
123 }
124
126 {
127 return gridLevel().grid().localFaceGeometry( indexInOutside() );
128 }
129
131 {
132 return Geometry( GeometryImpl( entityInfo() ) );
133 }
134
135 GeometryType type () const { return GeometryTypes::cube( mydimension ); }
136
137 int indexInInside () const { return normalId_.face(); }
138 int indexInOutside () const { return (-normalId_).face(); }
139
140 NormalVector outerNormal ( const LocalVector &local ) const
141 {
142 return unitOuterNormal( local );
143 }
144
146 {
148 }
149
150 NormalVector centerUnitOuterNormal () const { return normalId_; }
151
152 NormalVector unitOuterNormal ( const LocalVector &local ) const { return normalId_; }
153
154 bool equals ( const This &other ) const
155 {
156 return (indexInInside() == other.indexInInside()) && insideInfo_.equals( other.insideInfo_ );
157 }
158
159 const GridLevel &gridLevel () const { return insideInfo_.gridLevel(); }
160
161 void setInside ( const ElementInfo &insideInfo ) { insideInfo_ = insideInfo; }
162
164 {
165 insideInfo_ = ElementInfo( entityInfo.gridLevel(), entityInfo.id() - normalId_, entityInfo.partitionNumber() );
166 }
167
169 {
170 return EntityInfo( gridLevel(), insideInfo_.id() + normalId_, insideInfo_.partitionNumber() );
171 }
172
173 private:
174 SPNormalId< dimension > normalId_;
175 ElementInfo insideInfo_;
176 };
177
178
179
180 // Implementation of SPIntersection
181 // --------------------------------
182
183 template< class Grid >
184 inline typename SPIntersection< Grid >::Entity
186 {
187 MultiIndex id = insideInfo_.id() + normalId_ + normalId_;
188 if( !boundary() )
189 return Entity( EntityImpl( ElementInfo( gridLevel(), id, insideInfo_.partitionNumber() ) ) );
190
191 const PartitionList &allPartition = gridLevel().template partition< All_Partition >();
192 const Partition &partition = allPartition.partition( insideInfo_.partitionNumber() );
193
194 assert( partition.hasNeighbor( indexInInside() ) );
195 const Partition &nbPartition = allPartition.partition( partition.neighbor( indexInInside() ) );
196
197 // manipulate id in case of periodic (i.e., transformed) neighbors
198 const int bound = nbPartition.bound( -normalId_ );
199 id[ normalId_.axis() ] = bound + normalId_.sign()*(1 - (bound & 1));
200 return Entity( EntityImpl( ElementInfo( gridLevel(), id, nbPartition.number() ) ) );
201 }
202
203} // namespace Dune
204
205#endif // #ifndef DUNE_SPGRID_INTERSECTION_HH
Definition: iostream.hh:7
const Partition & partition(const unsigned int number) const
Definition: cachedpartitionlist.hh:94
Definition: entity.hh:146
Definition: entityinfo.hh:24
const GridLevel & gridLevel() const
Definition: entityinfo.hh:66
unsigned int partitionNumber() const
Definition: entityinfo.hh:73
const MultiIndex & id() const
Definition: entityinfo.hh:68
bool equals(const This &other) const
Definition: entityinfo.hh:77
ctype faceVolume(int i) const
Definition: geometricgridlevel.hh:75
Definition: geometry.hh:87
Base::LocalVector LocalVector
Definition: geometry.hh:108
Definition: gridlevel.hh:35
const PartitionList & partition() const
Definition: gridlevel.hh:227
size_t boundaryIndex(const MultiIndex &id, const unsigned int partitionNumber, const int face) const
Definition: gridlevel.hh:272
const Grid & grid() const
Definition: gridlevel.hh:82
Definition: intersection.hh:37
__SPGrid::EntityInfo< Grid, 1 > EntityInfo
Definition: intersection.hh:62
NormalVector outerNormal(const LocalVector &local) const
Definition: intersection.hh:140
int indexInOutside() const
Definition: intersection.hh:138
Traits::template Codim< 1 >::LocalGeometry LocalGeometry
Definition: intersection.hh:54
std::size_t boundarySegmentIndex() const
Definition: intersection.hh:99
GeometryType type() const
Definition: intersection.hh:135
bool equals(const This &other) const
Definition: intersection.hh:154
LocalGeometry geometryInOutside() const
Definition: intersection.hh:125
bool neighbor() const
Definition: intersection.hh:105
bool conforming() const
Definition: intersection.hh:115
Traits::template Codim< 0 >::Entity Entity
Definition: intersection.hh:51
SPIntersection()=default
EntityImpl::EntityInfo ElementInfo
Definition: intersection.hh:61
SPIntersection(const EntityInfo &entityInfo, int face)
Definition: intersection.hh:84
bool boundary() const
Definition: intersection.hh:89
NormalVector centerUnitOuterNormal() const
Definition: intersection.hh:150
void setEntityInfo(const EntityInfo &entityInfo)
Definition: intersection.hh:163
void setInside(const ElementInfo &insideInfo)
Definition: intersection.hh:161
Geometry geometry() const
Definition: intersection.hh:130
LocalGeometry geometryInInside() const
Definition: intersection.hh:120
static const int dimensionworld
Definition: intersection.hh:49
NormalVector unitOuterNormal(const LocalVector &local) const
Definition: intersection.hh:152
Traits::template Codim< 1 >::Geometry Geometry
Definition: intersection.hh:53
SPIntersection(const ElementInfo &insideInfo, int face)
Definition: intersection.hh:79
Entity inside() const
Definition: intersection.hh:111
EntityInfo entityInfo() const
Definition: intersection.hh:168
const GridLevel & gridLevel() const
Definition: intersection.hh:159
static const int dimension
Definition: intersection.hh:47
static const int mydimension
Definition: intersection.hh:48
int indexInInside() const
Definition: intersection.hh:137
EntityImpl::GridLevel GridLevel
Definition: intersection.hh:64
SPNormalVector< ctype, dimensionworld > NormalVector
Definition: intersection.hh:67
ReferenceCube::ctype ctype
Definition: intersection.hh:45
Entity outside() const
Definition: intersection.hh:185
GeometryImpl::LocalVector LocalVector
Definition: intersection.hh:66
NormalVector integrationOuterNormal(const LocalVector &local) const
Definition: intersection.hh:145
int boundaryId() const
Definition: intersection.hh:94
Definition: normal.hh:16
int sign() const
Definition: normal.hh:86
int face() const
Definition: normal.hh:82
int axis() const
Definition: normal.hh:84
const MultiIndex & bound(unsigned int b) const
Definition: partition.hh:37
Definition: partition.hh:79
unsigned int number() const
Definition: partition.hh:242
bool hasNeighbor(const int face) const
Definition: partition.hh:267
const unsigned int & neighbor(const int face) const
Definition: partition.hh:250