dune-grid 2.8.0
Loading...
Searching...
No Matches
intersection.cc
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ALBERTA_INTERSECTION_CC
4#define DUNE_ALBERTA_INTERSECTION_CC
5
7
8namespace Dune
9{
10
11 // AlbertaGridIntersectionBase
12 // ---------------------------
13
14 template< class Grid >
15 inline AlbertaGridIntersectionBase< Grid >
16 ::AlbertaGridIntersectionBase ()
17 : grid_( nullptr ),
18 elementInfo_(),
19 oppVertex_( -1 ) // mark invalid intersection
20 {}
21
22 template< class Grid >
24 ::AlbertaGridIntersectionBase ( const EntityImp &entity, const int oppVertex )
25 : grid_( &entity.grid() ),
26 elementInfo_( entity.elementInfo() ),
27 oppVertex_( oppVertex )
28 {}
29
30
31 template< class Grid >
32 inline typename Grid::template Codim< 0 >::Entity
34 {
36 return EntityImp( grid(), elementInfo(), 0 );
37 }
38
39
40 template< class Grid >
42 {
43 return elementInfo().isBoundary( oppVertex_ );
44 }
45
46
47 template< class Grid >
49 {
50 if( boundary() )
51 {
52 const int id = elementInfo().boundaryId( oppVertex_ );
53 assert( id != 0 );
54 return id;
55 }
56 else
57 return 0;
58 }
59
61 template< class Grid >
63 {
64 assert( boundary() );
65 const Alberta::BasicNodeProjection *projection = elementInfo().boundaryProjection( oppVertex_ );
66 assert( projection );
67 return projection->boundaryIndex();
68 }
69
71 template< class Grid >
73 {
74 const int face = (dimension > 1 ? oppVertex_ : 1-oppVertex_);
75 return grid().alberta2generic( 1, face );
76 }
77
79 template< class Grid >
81 {
82 return GeometryTypes::simplex( dimension-1 );
83 }
84
85
86 template< class Grid >
89 {
90 const typename Entity::Geometry geoInside = inside().geometry();
91
92 const int face = indexInInside();
93 auto refSimplex = ReferenceElements< ctype, dimension >::simplex();
94 FieldVector< ctype, dimension > refNormal = refSimplex.integrationOuterNormal( face );
95
96 const typename Entity::Geometry::JacobianInverseTransposed &jInvT
97 = geoInside.impl().jacobianInverseTransposed();
98
99 NormalVector normal;
100 jInvT.mv( refNormal, normal );
101 normal *= geoInside.impl().integrationElement();
102
103 return normal;
104 }
105
106 template<>
108 AlbertaGridIntersectionBase< const AlbertaGrid< 1, 1 > >::centerIntegrationOuterNormal () const
109 {
110 const Alberta::GlobalVector &oppCoord = grid().getCoord( elementInfo(), oppVertex_ );
111 const Alberta::GlobalVector &myCoord = grid().getCoord( elementInfo(), 1-oppVertex_ );
112 NormalVector n;
113 n[ 0 ] = (myCoord[ 0 ] > oppCoord[ 0 ] ? ctype( 1 ) : -ctype( 1 ));
114 return n;
115 }
116
117#if defined GRIDDIM && GRIDDIM > 1
118 template<>
120 AlbertaGridIntersectionBase< const AlbertaGrid< 2, 2 > >::centerIntegrationOuterNormal () const
121 {
122 const Alberta::GlobalVector &coordOne = grid().getCoord( elementInfo(), (oppVertex_+1)%3 );
123 const Alberta::GlobalVector &coordTwo = grid().getCoord( elementInfo(), (oppVertex_+2)%3 );
124
125 NormalVector n;
126 n[ 0 ] = -(coordOne[ 1 ] - coordTwo[ 1 ]);
127 n[ 1 ] = coordOne[ 0 ] - coordTwo[ 0 ];
128 return n;
129 }
130#endif // defined GRIDDIM && GRIDDIM > 1
131
132 template<>
133 inline AlbertaGridIntersectionBase< const AlbertaGrid< 3, 3 > >::NormalVector
134 AlbertaGridIntersectionBase< const AlbertaGrid< 3, 3 > >::centerIntegrationOuterNormal () const
135 {
136 // in this case the orientation is negative, multiply by -1
137 const ALBERTA EL_INFO &elInfo = elementInfo().elInfo();
138 const ctype val = (elInfo.orientation > 0) ? 1.0 : -1.0;
139
140 static const int faceVertices[ 4 ][ 3 ]
141 = { {1,3,2}, {0,2,3}, {0,3,1}, {0,1,2} };
142 const int *localFaces = faceVertices[ oppVertex_ ];
143
144 const Alberta::GlobalVector &coord0 = grid().getCoord( elementInfo(), localFaces[ 0 ] );
145 const Alberta::GlobalVector &coord1 = grid().getCoord( elementInfo(), localFaces[ 1 ] );
146 const Alberta::GlobalVector &coord2 = grid().getCoord( elementInfo(), localFaces[ 2 ] );
147
150 for( int i = 0; i < dimension; ++i )
151 {
152 v[ i ] = coord1[ i ] - coord0[ i ];
153 u[ i ] = coord2[ i ] - coord1[ i ];
154 }
155
156 NormalVector n;
157 for( int i = 0; i < dimension; ++i )
158 {
159 const int j = (i+1)%dimension;
160 const int k = (i+2)%dimension;
161 n[ i ] = val * (u[ j ] * v[ k ] - u[ k ] * v[ j ]);
162 }
163 return n;
164 }
165
166
167 template< class Grid >
170 {
171 return centerIntegrationOuterNormal();
172 }
173
174
175 template< class Grid >
178 {
179 NormalVector normal = centerOuterNormal();
180 normal *= (1.0 / normal.two_norm());
181 return normal;
182 }
183
184
185 template< class Grid >
188 {
189 return centerIntegrationOuterNormal();
190 }
191
192
193 template< class Grid >
196 {
197 return centerOuterNormal();
198 }
199
200
201 template< class Grid >
204 {
205 return centerUnitOuterNormal();
206 }
207
208
209 template< class Grid >
212 {
213 return AlbertaTransformation( elementInfo().transformation( oppVertex_ ) );
214 }
215
216
217 template< class Grid >
219 {
220 return *grid_;
221 }
222
223
224 template< class Grid >
227 {
228 assert( !!elementInfo_ );
229 return elementInfo_;
230 }
231
232
233
234 // AlbertaGridIntersectionBase::GlobalCoordReader
235 // ----------------------------------------------
236
237 template< class GridImp >
239 {
241
242 static const int dimension = Grid::dimension;
243 static const int codimension = 1;
244 static const int mydimension = dimension - codimension;
245 static const int coorddimension = Grid::dimensionworld;
246
248
251
252 private:
253 const Grid &grid_;
255 const int subEntity_;
256 const int twist_;
257
258 public:
259 GlobalCoordReader ( const GridImp &grid,
261 int subEntity )
262 : grid_( grid ),
264 subEntity_( subEntity ),
265 twist_( elementInfo.template twist< codimension >( subEntity ) )
266 {}
267
268 void coordinate ( int i, Coordinate &x ) const
269 {
270 assert( !elementInfo_ == false );
271 assert( (i >= 0) && (i <= mydimension) );
272
273 const int ti = Alberta::applyInverseTwist< mydimension >( twist_, i );
274 const int k = mapVertices( subEntity_, ti );
275 const Alberta::GlobalVector &coord = grid_.getCoord( elementInfo_, k );
276 for( int j = 0; j < coorddimension; ++j )
277 x[ j ] = coord[ j ];
278 }
279
280 bool hasDeterminant () const
281 {
282 return false;
283 }
284
286 {
287 assert( false );
288 return ctype( 0 );
289 }
290
291 private:
292 static int mapVertices ( int subEntity, int i )
293 {
295 }
296 };
297
298
299
300
301 // AlbertaGridIntersectionBase::LocalCoordReader
302 // ---------------------------------------------
303
304 template< class GridImp >
306 {
308
309 static const int dimension = Grid::dimension;
310 static const int codimension = 1;
311 static const int mydimension = dimension - codimension;
312 static const int coorddimension = dimension;
313
315
317
318 typedef typename Grid::template Codim< 0 >::Geometry ElementGeometry;
319 typedef typename Grid::template Codim< 1 >::Geometry FaceGeometry;
320
321 private:
322 const ElementGeometry &elementGeometry_;
323 const FaceGeometry &faceGeometry_;
324
325 public:
326 LocalCoordReader ( const ElementGeometry &elementGeometry,
327 const FaceGeometry &faceGeometry )
328 : elementGeometry_( elementGeometry ),
329 faceGeometry_( faceGeometry )
330 {}
331
332 void coordinate ( int i, Coordinate &x ) const
333 {
334 x = elementGeometry_.local( faceGeometry_.corner( i ) );
335 }
336
337 bool hasDeterminant () const
338 {
339 return false;
340 }
341
343 {
344 return ctype( 0 );
345 }
346 };
347
348
349
350 // AlbertaGridLeafIntersection
351 // ---------------------------
352
353 template< class GridImp >
355 {
356 assert( oppVertex_ <= dimension );
357 ++oppVertex_;
358 neighborInfo_ = ElementInfo();
359 }
360
361 template< class GridImp >
362 inline typename GridImp::template Codim< 0 >::Entity
364 {
366
367 if( !neighborInfo_ )
368 {
369 assert( neighbor() );
370
371 neighborInfo_ = elementInfo().leafNeighbor( oppVertex_ );
372 }
373
374 assert( !neighborInfo_ == false );
375 assert( neighborInfo_.el() != NULL );
376 return EntityImp( grid(), neighborInfo_, 0 );
377 }
378
379 template< class GridImp >
381 {
382 assert( oppVertex_ <= dimension );
383 return elementInfo().hasLeafNeighbor( oppVertex_ );
384 }
385
386
387 template< class GridImp >
390 {
391 typedef AlbertaGridLocalGeometryProvider< GridImp > LocalGeoProvider;
392 const int twist = elementInfo().template twist< 1 >( oppVertex_ );
393 const int face = (dimension > 1 ? oppVertex_ : 1-oppVertex_);
394 return LocalGeometry( LocalGeoProvider::instance().faceGeometry( face, twist ) );
395 }
396
397
398 template< class GridImp >
401 {
402 assert( neighbor() );
403
404 typedef AlbertaGridLocalGeometryProvider< GridImp > LocalGeoProvider;
405 const ALBERTA EL_INFO &elInfo = elementInfo().elInfo();
406 const int oppVertex = elInfo.opp_vertex[ oppVertex_ ];
407 const int twist = elementInfo().twistInNeighbor( oppVertex_ );
408 const int face = (dimension > 1 ? oppVertex : 1-oppVertex);
409 return LocalGeometry( LocalGeoProvider::instance().faceGeometry( face, twist ) );
410 }
411
412
413 template< class GridImp >
416 {
417 const int face = (dimension > 1 ? oppVertex_ : 1-oppVertex_);
418 const GlobalCoordReader coordReader( grid(), elementInfo(), face );
419 return Geometry( GeometryImpl( coordReader ) );
420 }
421
422
423 template< class GridImp >
425 {
426 const ALBERTA EL_INFO &elInfo = elementInfo().elInfo();
427 const int oppVertex = elInfo.opp_vertex[ oppVertex_ ];
428 const int face = (dimension > 1 ? oppVertex : 1-oppVertex);
429 return grid().alberta2generic( 1, face );
430 }
431
432} // namespace Dune
433
434#endif // #ifndef DUNE_ALBERTA_INTERSECTION_CC
#define ALBERTA
Definition albertaheader.hh:27
ALBERTA REAL Real
Definition misc.hh:46
ALBERTA REAL_D GlobalVector
Definition misc.hh:48
Include standard header files.
FieldTraits< value_type >::real_type two_norm() const
LocalGeometry geometryInOutside() const
Definition intersection.cc:400
GridImp::template Codim< 0 >::Entity outside() const
Definition intersection.cc:363
void next()
Definition intersection.cc:354
Base::GeometryImpl GeometryImpl
Definition albertagrid/intersection.hh:128
int indexInOutside() const
Definition intersection.cc:424
LocalGeometry geometryInInside() const
Definition intersection.cc:389
Base::GlobalCoordReader GlobalCoordReader
Definition albertagrid/intersection.hh:131
Base::Geometry Geometry
Definition albertagrid/intersection.hh:120
Geometry geometry() const
Definition intersection.cc:415
bool neighbor() const
Definition intersection.cc:380
Base::LocalGeometry LocalGeometry
Definition albertagrid/intersection.hh:121
Definition albertagrid/entity.hh:44
Definition albertagrid/geometry.hh:472
FieldVector< ctype, coorddimension > Coordinate
Definition intersection.cc:250
Alberta::Real ctype
Definition intersection.cc:247
std::remove_const< GridImp >::type Grid
Definition intersection.cc:240
Alberta::ElementInfo< dimension > ElementInfo
Definition intersection.cc:249
ctype determinant() const
Definition intersection.cc:285
bool hasDeterminant() const
Definition intersection.cc:280
GlobalCoordReader(const GridImp &grid, const ElementInfo &elementInfo, int subEntity)
Definition intersection.cc:259
void coordinate(int i, Coordinate &x) const
Definition intersection.cc:268
Grid::template Codim< 1 >::Geometry FaceGeometry
Definition intersection.cc:319
Alberta::Real ctype
Definition intersection.cc:314
LocalCoordReader(const ElementGeometry &elementGeometry, const FaceGeometry &faceGeometry)
Definition intersection.cc:326
std::remove_const< GridImp >::type Grid
Definition intersection.cc:307
void coordinate(int i, Coordinate &x) const
Definition intersection.cc:332
bool hasDeterminant() const
Definition intersection.cc:337
ctype determinant() const
Definition intersection.cc:342
FieldVector< ctype, coorddimension > Coordinate
Definition intersection.cc:316
Grid::template Codim< 0 >::Geometry ElementGeometry
Definition intersection.cc:318
Definition albertagrid/intersection.hh:30
NormalVector centerOuterNormal() const
Definition intersection.cc:169
const ElementInfo & elementInfo() const
Definition intersection.cc:226
NormalVector centerIntegrationOuterNormal() const
Definition intersection.cc:88
Grid::ctype ctype
Definition albertagrid/intersection.hh:34
NormalVector integrationOuterNormal(const LocalCoordType &local) const
Definition intersection.cc:187
ElementInfo elementInfo_
Definition albertagrid/intersection.hh:91
NormalVector centerUnitOuterNormal() const
Definition intersection.cc:177
int indexInInside() const
Definition intersection.cc:72
Entity inside() const
Definition intersection.cc:33
NormalVector unitOuterNormal(const LocalCoordType &local) const
Definition intersection.cc:203
const Grid & grid() const
Definition intersection.cc:218
static const int dimension
Definition albertagrid/intersection.hh:36
bool boundary() const
Definition intersection.cc:41
size_t boundarySegmentIndex() const
Definition intersection.cc:62
GeometryType type() const
Definition intersection.cc:80
AlbertaTransformation transformation() const
Definition intersection.cc:211
NormalVector outerNormal(const LocalCoordType &local) const
Definition intersection.cc:195
int boundaryId() const
Definition intersection.cc:48
const Grid * grid_
Definition albertagrid/intersection.hh:90
Definition misc.hh:441
Definition albertagrid/projection.hh:206
unsigned int boundaryIndex() const
Definition albertagrid/projection.hh:216
Definition transformation.hh:16
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition common/entity.hh:98
Grid abstract base class.
Definition common/grid.hh:372
@ dimensionworld
The dimension of the world the grid lives in.
Definition common/grid.hh:392
@ dimension
The dimension of the grid.
Definition common/grid.hh:386