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