Skip to content

Commit 750a7ed

Browse files
authored
Merge pull request #513 from rbe051/bug_fixes_polyhedral_grid
Bug fixes PolyhedralGrid
2 parents d4a93c9 + 52bb4b8 commit 750a7ed

File tree

3 files changed

+192
-123
lines changed

3 files changed

+192
-123
lines changed

opm/grid/polyhedralgrid/grid.hh

Lines changed: 73 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace Dune
9191
typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridGeometry > Geometry;
9292

9393
typedef PolyhedralGridLocalGeometry< dimension-codim, dimensionworld, const Grid> LocalGeometryImpl;
94-
typedef Dune::Geometry< dimension-codim, dimension, const Grid, PolyhedralGridLocalGeometry > LocalGeometry;
94+
typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridLocalGeometry > LocalGeometry;
9595

9696
typedef PolyhedralGridEntity< codim, dimension, const Grid > EntityImpl;
9797
typedef Dune::Entity< codim, dimension, const Grid, PolyhedralGridEntity > Entity;
@@ -179,7 +179,8 @@ namespace Dune
179179
static UnstructuredGridPtr
180180
allocateGrid ( std::size_t nCells, std::size_t nFaces, std::size_t nFaceNodes, std::size_t nCellFaces, std::size_t nNodes )
181181
{
182-
UnstructuredGridType *grid = allocate_grid( dim, nCells, nFaces, nFaceNodes, nCellFaces, nNodes );
182+
// Note that we here assign a grid of dimension dimworld in order to obtain global coordinates in the correct dimension
183+
UnstructuredGridType *grid = allocate_grid( dimworld, nCells, nFaces, nFaceNodes, nCellFaces, nNodes );
183184
if( !grid )
184185
DUNE_THROW( GridError, "Unable to allocate grid" );
185186
return UnstructuredGridPtr( grid );
@@ -972,60 +973,41 @@ namespace Dune
972973
{
973974
const int codim = EntitySeed :: codimension;
974975
const int index = seed.index();
975-
switch (codim)
976-
{
977-
case 0:
978-
{
979-
return cellVertices_[ index ].size();
980-
}
981-
case 1:
982-
{
983-
//return grid_.cell_facepos[ index+1 ] - grid_.cell_facepos[ index ];
984-
return grid_.face_nodepos[ index+1 ] - grid_.face_nodepos[ index ];
985-
}
986-
case dim:
987-
{
988-
return 1;
989-
}
990-
default:
991-
{
992-
return 0;
993-
}
994-
}
976+
if (codim==0)
977+
return cellVertices_[ index ].size();
978+
if (codim==1)
979+
return grid_.face_nodepos[ index+1 ] - grid_.face_nodepos[ index ];
980+
if (codim==dim)
981+
return 1;
982+
return 0;
995983
}
996984

997985
template <class EntitySeed>
998986
GlobalCoordinate
999987
corner ( const EntitySeed& seed, const int i ) const
1000988
{
1001989
const int codim = EntitySeed :: codimension;
1002-
switch (codim)
990+
if (codim==0)
1003991
{
1004-
case 0:
1005-
{
1006-
const int coordIndex = GlobalCoordinate :: dimension * cellVertices_[ seed.index() ][ i ];
1007-
return copyToGlobalCoordinate( grid_.node_coordinates + coordIndex );
1008-
}
1009-
case 1:
1010-
{
1011-
// for faces we need to swap vertices in 3d since in UnstructuredGrid
1012-
// those are ordered counter clockwise, for 2d this does not matter
1013-
// TODO: Improve this for performance reasons
1014-
const int crners = corners( seed );
1015-
const int crner = (crners == 4 && EntitySeed :: dimension == 3 && i > 1 ) ? 5 - i : i;
1016-
const int faceVertex = grid_.face_nodes[ grid_.face_nodepos[seed.index() ] + crner ];
1017-
return copyToGlobalCoordinate( grid_.node_coordinates + GlobalCoordinate :: dimension * faceVertex );
1018-
}
1019-
case dim:
1020-
{
1021-
const int coordIndex = GlobalCoordinate :: dimension * seed.index();
1022-
return copyToGlobalCoordinate( grid_.node_coordinates + coordIndex );
1023-
}
1024-
default:
1025-
{
1026-
return GlobalCoordinate( 0 );
1027-
}
992+
const int coordIndex = GlobalCoordinate :: dimension * cellVertices_[ seed.index() ][ i ];
993+
return copyToGlobalCoordinate( grid_.node_coordinates + coordIndex );
994+
}
995+
if (codim==1)
996+
{
997+
// for faces we need to swap vertices in 3d since in UnstructuredGrid
998+
// those are ordered counter clockwise, for 2d this does not matter
999+
// TODO: Improve this for performance reasons
1000+
const int crners = corners( seed );
1001+
const int crner = (crners == 4 && EntitySeed :: dimension == 3 && i > 1 ) ? 5 - i : i;
1002+
const int faceVertex = grid_.face_nodes[ grid_.face_nodepos[seed.index() ] + crner ];
1003+
return copyToGlobalCoordinate( grid_.node_coordinates + GlobalCoordinate :: dimension * faceVertex );
10281004
}
1005+
if (codim==dim)
1006+
{
1007+
const int coordIndex = GlobalCoordinate :: dimension * seed.index();
1008+
return copyToGlobalCoordinate( grid_.node_coordinates + coordIndex );
1009+
}
1010+
return GlobalCoordinate( 0 );
10291011
}
10301012

10311013
template <class EntitySeed>
@@ -1034,25 +1016,19 @@ namespace Dune
10341016
const int index = seed.index();
10351017
if( seed.codimension == 0 )
10361018
{
1037-
switch (codim)
1038-
{
1039-
case 0:
1040-
return 1;
1041-
case 1:
1042-
return grid_.cell_facepos[ index+1 ] - grid_.cell_facepos[ index ];
1043-
case dim:
1044-
return cellVertices_[ index ].size();
1045-
}
1019+
if (codim==0)
1020+
return 1;
1021+
if (codim==1)
1022+
return grid_.cell_facepos[ index+1 ] - grid_.cell_facepos[ index ];
1023+
if (codim==dim)
1024+
return cellVertices_[ index ].size();
10461025
}
10471026
else if( seed.codimension == 1 )
10481027
{
1049-
switch (codim)
1050-
{
1051-
case 1:
1052-
return 1;
1053-
case dim:
1054-
return grid_.face_nodepos[ index+1 ] - grid_.face_nodepos[ index ];
1055-
}
1028+
if (codim==1)
1029+
return 1;
1030+
if (codim==dim)
1031+
return grid_.face_nodepos[ index+1 ] - grid_.face_nodepos[ index ];
10561032
}
10571033
else if ( seed.codimension == dim )
10581034
{
@@ -1532,7 +1508,6 @@ namespace Dune
15321508

15331509
// check face normals
15341510
{
1535-
typedef Dune::FieldVector< double, dim > Coordinate;
15361511
const int faces = grid_.number_of_faces;
15371512
for( int face = 0 ; face < faces; ++face )
15381513
{
@@ -1544,41 +1519,41 @@ namespace Dune
15441519
if( grid_.face_areas[ face ] < 0 )
15451520
std::abort();
15461521

1547-
Coordinate centerDiff( 0 );
1522+
GlobalCoordinate centerDiff( 0 );
15481523
if( b >= 0 )
15491524
{
1550-
for( int d=0; d<dim; ++d )
1525+
for( int d=0; d<dimworld; ++d )
15511526
{
1552-
centerDiff[ d ] = grid_.cell_centroids[ b*dim + d ];
1527+
centerDiff[ d ] = grid_.cell_centroids[ b*dimworld + d ];
15531528
}
15541529
}
15551530
else
15561531
{
1557-
for( int d=0; d<dim; ++d )
1532+
for( int d=0; d<dimworld; ++d )
15581533
{
1559-
centerDiff[ d ] = grid_.face_centroids[ face*dim + d ];
1534+
centerDiff[ d ] = grid_.face_centroids[ face*dimworld + d ];
15601535
}
15611536
}
15621537

15631538
if( a >= 0 )
15641539
{
1565-
for( int d=0; d<dim; ++d )
1540+
for( int d=0; d<dimworld; ++d )
15661541
{
1567-
centerDiff[ d ] -= grid_.cell_centroids[ a*dim + d ];
1542+
centerDiff[ d ] -= grid_.cell_centroids[ a*dimworld + d ];
15681543
}
15691544
}
15701545
else
15711546
{
1572-
for( int d=0; d<dim; ++d )
1547+
for( int d=0; d<dimworld; ++d )
15731548
{
1574-
centerDiff[ d ] -= grid_.face_centroids[ face*dim + d ];
1549+
centerDiff[ d ] -= grid_.face_centroids[ face*dimworld + d ];
15751550
}
15761551
}
15771552

1578-
Coordinate normal( 0 );
1579-
for( int d=0; d<dim; ++d )
1553+
GlobalCoordinate normal( 0 );
1554+
for( int d=0; d<dimworld; ++d )
15801555
{
1581-
normal[ d ] = grid_.face_normals[ face*dim + d ];
1556+
normal[ d ] = grid_.face_normals[ face*dimworld + d ];
15821557
}
15831558

15841559
if( centerDiff.two_norm() < 1e-10 )
@@ -1593,9 +1568,11 @@ namespace Dune
15931568
}
15941569
}
15951570

1571+
// if no face_tag is available we set the reference element based
1572+
// on the number of nodes in a cell.
1573+
// By default set all types to None. This corresponds to hasPolygon
15961574
GeometryType tmp;
15971575
tmp = Dune::GeometryTypes::none(dim);
1598-
// by default set all types to None
15991576
cellGeomTypes_.resize( numCells );
16001577
std::fill( cellGeomTypes_.begin(), cellGeomTypes_.end(), tmp );
16011578

@@ -1622,44 +1599,28 @@ namespace Dune
16221599
hasPolyhedron = true;
16231600
}
16241601
}
1625-
1626-
// if no face_tag is available we assume that no reference element can be
1627-
// assigned to the elements
1602+
// Propogate the cell geometry type to all codimensions
16281603
geomTypes_.resize(dim + 1);
1629-
tmp = Dune::GeometryTypes::cube(0);
1630-
geomTypes_[ dim ].push_back( tmp );
1631-
tmp = Dune::GeometryTypes::cube(1);
1632-
geomTypes_[ dim-1 ].push_back( tmp );
1633-
1634-
if( hasSimplex )
1635-
{
1636-
tmp = Dune::GeometryTypes::simplex(dim);
1637-
geomTypes_[ 0 ].push_back( tmp );
1638-
}
1639-
1640-
if( hasCube )
1641-
{
1642-
tmp = Dune::GeometryTypes::cube(dim);
1643-
geomTypes_[ 0 ].push_back( tmp );
1644-
}
1645-
1646-
if( hasPolyhedron )
1647-
{
1648-
tmp = Dune::GeometryTypes::none(dim);
1649-
geomTypes_[ 0 ].push_back( tmp );
1650-
}
1651-
1652-
if( dim > 2 )
1604+
for (int codim = 0; codim <= dim; ++codim)
16531605
{
1654-
for( const auto& elemType : geomTypes_[ 0 ] )
1606+
if( hasSimplex )
16551607
{
1656-
if( elemType.isSimplex() )
1657-
tmp = Dune::GeometryTypes::simplex(2);
1658-
else if ( elemType.isCube() )
1659-
tmp = Dune::GeometryTypes::cube(2);
1660-
else
1661-
tmp = Dune::GeometryTypes::none(2);
1662-
geomTypes_[ 1 ].push_back( tmp );
1608+
tmp = Dune::GeometryTypes::simplex(dim - codim);
1609+
geomTypes_[ codim ].push_back( tmp );
1610+
}
1611+
else if ( hasCube )
1612+
{
1613+
tmp = Dune::GeometryTypes::cube(dim - codim);
1614+
geomTypes_[ codim ].push_back( tmp );
1615+
}
1616+
else if (hasPolyhedron)
1617+
{
1618+
tmp = Dune::GeometryTypes::none(dim - codim);
1619+
geomTypes_[ codim ].push_back( tmp );
1620+
}
1621+
else
1622+
{
1623+
OPM_THROW(std::runtime_error, "Grid error, unkown geometry type.");
16631624
}
16641625
}
16651626

@@ -1691,17 +1652,6 @@ namespace Dune
16911652
}
16921653
}
16931654
}
1694-
1695-
/*
1696-
for( int i=0; i<= dim ; ++ i )
1697-
{
1698-
for( const auto& geomType : geomTypes_[ i ] )
1699-
{
1700-
std::cout << "Codim " << i << " type = " << geomType << std::endl;
1701-
}
1702-
}
1703-
*/
1704-
//print( std::cout, grid_ );
17051655
}
17061656

17071657
void print( std::ostream& out, const UnstructuredGridType& grid ) const

opm/grid/polyhedralgrid/intersection.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace Dune
5050
intersectionIdx_( -1 )
5151
{}
5252

53+
PolyhedralGridIntersection ( )
54+
: data_( ),
55+
seed_(),
56+
intersectionIdx_( -1 )
57+
{}
58+
5359
PolyhedralGridIntersection ( ExtraData data, const EntitySeed& seed, const int intersectionIdx )
5460
: data_( data ),
5561
seed_( seed ),

0 commit comments

Comments
 (0)