3#ifndef DUNE_POLYHEDRALGRID_GRID_HH
4#define DUNE_POLYHEDRALGRID_GRID_HH
10#include <opm/grid/utility/platform_dependent/disable_warnings.h>
13#include <dune/common/version.hh>
14#include <dune/common/parallel/mpihelper.hh>
17#include <dune/grid/common/grid.hh>
19#if DUNE_VERSION_GTE(DUNE_COMMON, 2, 7)
20#include <dune/common/parallel/communication.hh>
22#include <dune/common/parallel/collectivecommunication.hh>
26#include <opm/grid/polyhedralgrid/capabilities.hh>
27#include <opm/grid/polyhedralgrid/declaration.hh>
28#include <opm/grid/polyhedralgrid/entity.hh>
29#include <opm/grid/polyhedralgrid/entityseed.hh>
30#include <opm/grid/polyhedralgrid/geometry.hh>
31#include <opm/grid/polyhedralgrid/gridview.hh>
32#include <opm/grid/polyhedralgrid/idset.hh>
35#include <opm/grid/utility/platform_dependent/reenable_warnings.h>
37#include <opm/grid/utility/ErrorMacros.hpp>
42#include <opm/grid/GridManager.hpp>
44#include <opm/grid/MinpvProcessor.hpp>
53 template<
int dim,
int dimworld,
typename coord_t >
60 typedef coord_t ctype;
68 static const int dimension = dim;
69 static const int dimensionworld = dimworld;
71 typedef Dune::FieldVector< ctype, dimensionworld > GlobalCoordinate ;
78 typedef Dune::Intersection< const Grid, LeafIntersectionImpl > LeafIntersection;
79 typedef Dune::Intersection< const Grid, LevelIntersectionImpl > LevelIntersection;
81 typedef Dune::IntersectionIterator< const Grid, LeafIntersectionIteratorImpl, LeafIntersectionImpl > LeafIntersectionIterator;
82 typedef Dune::IntersectionIterator< const Grid, LevelIntersectionIteratorImpl, LevelIntersectionImpl > LevelIntersectionIterator;
85 typedef Dune::EntityIterator< 0, const Grid, HierarchicIteratorImpl > HierarchicIterator;
97 typedef Dune::Entity< codim, dimension, const Grid, PolyhedralGridEntity > Entity;
100 typedef Entity EntityPointer;
105 template< PartitionIteratorType pitype >
109 typedef Dune::EntityIterator< codim, const Grid, LeafIteratorImpl > LeafIterator;
111 typedef LeafIterator LevelIterator;
114 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
115 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
124 typedef Dune::MPIHelper::MPICommunicator MPICommunicator;
125#if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
126 using Communication = Dune::Communication<MPICommunicator>;
127 using CollectiveCommunication = Dune::Communication<MPICommunicator>;
129 using CollectiveCommunication = Dune::CollectiveCommunication<MPICommunicator>;
132 template< PartitionIteratorType pitype >
135 typedef Dune::GridView< PolyhedralGridViewTraits< dim, dimworld, ctype, pitype > > LeafGridView;
136 typedef Dune::GridView< PolyhedralGridViewTraits< dim, dimworld, ctype, pitype > > LevelGridView;
139 typedef typename Partition< All_Partition >::LeafGridView LeafGridView;
140 typedef typename Partition< All_Partition >::LevelGridView LevelGridView;
157 template <
int dim,
int dimworld,
typename coord_t >
160 :
public GridDefaultImplementation
161 < dim, dimworld, coord_t, PolyhedralGridFamily< dim, dimworld, coord_t > >
166 typedef GridDefaultImplementation
182 typedef std::unique_ptr< UnstructuredGridType, UnstructuredGridDeleter > UnstructuredGridPtr;
184 static UnstructuredGridPtr
185 allocateGrid ( std::size_t nCells, std::size_t nFaces, std::size_t nFaceNodes, std::size_t nCellFaces, std::size_t nNodes )
190 DUNE_THROW( GridError,
"Unable to allocate grid" );
191 return UnstructuredGridPtr( grid );
195 computeGeometry ( UnstructuredGridPtr& ug )
205 typedef PolyhedralGridFamily< dim, dimworld, coord_t > GridFamily;
212 typedef typename GridFamily::Traits
Traits;
220 template<
int codim >
241 template< PartitionIteratorType pitype >
244 typedef typename GridFamily::Traits::template Partition< pitype >::LevelGridView LevelGridView;
245 typedef typename GridFamily::Traits::template Partition< pitype >::LeafGridView LeafGridView;
250 typedef typename Partition< All_Partition >::LeafGridView LeafGridView;
312 typedef typename Traits::ctype
ctype;
315#if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
316 using Communication =
typename Traits::Communication;
317 using CommunicationType = Communication;
324 typedef typename Traits :: GlobalCoordinate GlobalCoordinate;
338 const std::vector<double>& poreVolumes = std::vector<double> ())
339 : gridPtr_( createGrid( inputGrid, poreVolumes ) ),
341 comm_( MPIHelper::getCommunicator() ),
342 leafIndexSet_( *this ),
343 globalIdSet_( *this ),
344 localIdSet_( *this ),
357 const std::vector< double >& dx )
358 : gridPtr_( createGrid( n, dx ) ),
360 comm_( MPIHelper::getCommunicator()),
361 leafIndexSet_( *this ),
362 globalIdSet_( *this ),
363 localIdSet_( *this ),
376 : gridPtr_( std::move( gridPtr ) ),
378 comm_( MPIHelper::getCommunicator() ),
379 leafIndexSet_( *this ),
380 globalIdSet_( *this ),
381 localIdSet_( *this ),
397 comm_( MPIHelper::getCommunicator() ),
398 leafIndexSet_( *this ),
399 globalIdSet_( *this ),
400 localIdSet_( *this ),
410 operator const UnstructuredGridType& ()
const {
return grid_; }
437 int size (
int ,
int codim )
const
439 return size( codim );
454 else if ( codim == 1 )
458 else if ( codim == dim )
464 std::cerr <<
"Warning: codimension " << codim <<
" not available in PolyhedralGrid" << std::endl;
477 int size (
int , GeometryType type )
const
479 return size( dim - type.dim() );
486 int size ( GeometryType type )
const
488 return size( dim - type.dim() );
499 return nBndSegments_;
503 template<
int codim >
506 return leafbegin< codim, All_Partition >();
509 template<
int codim >
512 return leafend< codim, All_Partition >();
515 template<
int codim, PartitionIteratorType pitype >
516 typename Codim< codim >::template Partition< pitype >::LeafIterator
519 typedef typename Traits::template Codim< codim >::template Partition< pitype >::LeafIteratorImpl Impl;
520 return Impl( extraData(),
true );
523 template<
int codim, PartitionIteratorType pitype >
524 typename Codim< codim >::template Partition< pitype >::LeafIterator
527 typedef typename Traits::template Codim< codim >::template Partition< pitype >::LeafIteratorImpl Impl;
528 return Impl( extraData(),
false );
531 template<
int codim >
534 return leafbegin< codim, All_Partition >();
537 template<
int codim >
540 return leafend< codim, All_Partition >();
543 template<
int codim, PartitionIteratorType pitype >
544 typename Codim< codim >::template Partition< pitype >::LevelIterator
545 lbegin (
const int )
const
547 return leafbegin< codim, pitype > ();
550 template<
int codim, PartitionIteratorType pitype >
551 typename Codim< codim >::template Partition< pitype >::LevelIterator
552 lend (
const int )
const
554 return leafend< codim, pitype > ();
569 return leafIndexSet();
574 return leafIndexSet_;
577 void globalRefine (
int )
607 template<
class DataHandle >
636 return (codim == 0 ) ? 1 : 0;
672 template<
class DataHandle>
675 CommunicationDirection ,
678 OPM_THROW(std::runtime_error,
"communicate not implemented for polyhedreal grid!");
693 template<
class DataHandle>
696 CommunicationDirection )
const
698 OPM_THROW(std::runtime_error,
"communicate not implemented for polyhedreal grid!");
704 OPM_THROW(std::runtime_error,
"switch to global view not implemented for polyhedreal grid!");
710 OPM_THROW(std::runtime_error,
"switch to distributed view not implemented for polyhedreal grid!");
721 const CommunicationType &
comm ()
const
757 template<
class DataHandle,
class Data >
777 template<
class DofManager >
784 template< PartitionIteratorType pitype >
787 typedef typename Partition< pitype >::LevelGridView View;
788 typedef typename View::GridViewImp ViewImp;
789 return View( ViewImp( *
this ) );
793 template< PartitionIteratorType pitype >
796 typedef typename Traits::template Partition< pitype >::LeafGridView View;
797 typedef typename View::GridViewImp ViewImp;
798 return View( ViewImp( *
this ) );
804 typedef typename LevelGridView::GridViewImp ViewImp;
811 typedef typename LeafGridView::GridViewImp ViewImp;
812 return LeafGridView( ViewImp( *
this ) );
816 template<
class EntitySeed >
823 return EntityPointer( EntityPointerImpl( EntityImpl( extraData(), seed ) ) );
827 template<
class EntitySeed >
832 return EntityImpl( extraData(), seed );
854 const std::array<int, 3>& logicalCartesianSize()
const
859 const int* globalCell()
const
865 const int* globalCellPtr()
const
870 void getIJK(
const int c, std::array<int,3>& ijk)
const
872 int gc = globalCell()[c];
873 ijk[0] = gc % logicalCartesianSize()[0]; gc /= logicalCartesianSize()[0];
874 ijk[1] = gc % logicalCartesianSize()[1];
875 ijk[2] = gc / logicalCartesianSize()[1];
892 template<
class DataHandle>
895 OPM_THROW(std::runtime_error,
"ScatterData not implemented for polyhedral grid!");
900 UnstructuredGridType* createGrid(
const Opm::EclipseGrid& inputGrid,
const std::vector< double >& poreVolumes )
const
904 g.
dims[0] = inputGrid.getNX();
905 g.dims[1] = inputGrid.getNY();
906 g.dims[2] = inputGrid.getNZ();
908 std::vector<double>
coord = inputGrid.getCOORD( );
909 std::vector<double>
zcorn = inputGrid.getZCORN( );
910 std::vector<int>
actnum = inputGrid.getACTNUM( );
912 g.coord =
coord.data();
913 g.zcorn =
zcorn.data();
916 if (!poreVolumes.empty() && (inputGrid.getMinpvMode() != Opm::MinpvMode::ModeEnum::Inactive))
919 const std::vector<double>& minpvv = inputGrid.getMinpvVector();
924 const size_t cartGridSize = g.dims[0] * g.dims[1] * g.dims[2];
925 std::vector<double> thickness(cartGridSize);
926 for (
size_t i = 0; i < cartGridSize; ++i) {
927 thickness[i] = inputGrid.getCellThickness(i);
929 const double z_tolerance = inputGrid.isPinchActive() ? inputGrid.getPinchThresholdThickness() : 0.0;
930 mp.process(thickness, z_tolerance, poreVolumes, minpvv,
actnum, opmfil,
zcorn.data());
944 const double z_tolerance = inputGrid.isPinchActive() ?
945 inputGrid.getPinchThresholdThickness() : 0.0;
948 OPM_THROW(std::runtime_error,
"Failed to construct grid.");
954 UnstructuredGridType* createGrid(
const std::vector< int >& n,
const std::vector< double >& dx )
const
956 UnstructuredGridType* cgrid = nullptr ;
957 assert(
int(n.size()) == dim );
969 OPM_THROW(std::runtime_error,
"Failed to construct grid.");
975#if DUNE_VERSION_LT_REV(DUNE_GRID, 2, 7, 1)
976 using Base::getRealImplementation;
978 typedef typename Traits :: ExtraData ExtraData;
979 ExtraData extraData ()
const {
return this; }
981 template <
class EntitySeed>
982 int corners(
const EntitySeed& seed )
const
984 const int codim = EntitySeed :: codimension;
985 const int index = seed.index();
987 return cellVertices_[ index ].size();
995 template <
class EntitySeed>
997 corner (
const EntitySeed& seed,
const int i )
const
999 const int codim = EntitySeed :: codimension;
1002 const int coordIndex = GlobalCoordinate :: dimension * cellVertices_[ seed.index() ][ i ];
1010 const int crners = corners( seed );
1011 const int crner = (crners == 4 && EntitySeed :: dimension == 3 && i > 1 ) ? 5 - i : i;
1013 return copyToGlobalCoordinate( grid_.
node_coordinates + GlobalCoordinate :: dimension * faceVertex );
1017 const int coordIndex = GlobalCoordinate :: dimension * seed.index();
1020 return GlobalCoordinate( 0 );
1023 template <
class EntitySeed>
1024 int subEntities(
const EntitySeed& seed,
const int codim )
const
1026 const int index = seed.index();
1027 if( seed.codimension == 0 )
1034 return cellVertices_[ index ].size();
1036 else if( seed.codimension == 1 )
1043 else if ( seed.codimension == dim )
1051 template <
int codim,
class EntitySeedArg >
1052 typename Codim<codim>::EntitySeed
1053 subEntitySeed(
const EntitySeedArg& baseSeed,
const int i )
const
1055 assert( codim >= EntitySeedArg::codimension );
1056 assert( i>= 0 && i<subEntities( baseSeed, codim ) );
1057 typedef typename Codim<codim>::EntitySeed EntitySeed;
1060 if( codim == EntitySeedArg::codimension )
1062 return EntitySeed( baseSeed.index() );
1065 if( EntitySeedArg::codimension == 0 )
1071 else if ( codim == dim )
1073 return EntitySeed( cellVertices_[ baseSeed.index() ][ i ] );
1076 else if ( EntitySeedArg::codimension == 1 && codim == dim )
1081 DUNE_THROW(NotImplemented,
"codimension not available");
1082 return EntitySeed();
1085 template <
int codim>
1086 typename Codim<codim>::EntitySeed
1087 subEntitySeed(
const typename Codim<1>::EntitySeed& faceSeed,
const int i )
const
1089 assert( i>= 0 && i<subEntities( faceSeed, codim ) );
1090 typedef typename Codim<codim>::EntitySeed EntitySeed;
1093 return EntitySeed( faceSeed.index() );
1095 else if ( codim == dim )
1101 DUNE_THROW(NotImplemented,
"codimension not available");
1105 bool hasBoundaryIntersections(
const typename Codim<0>::EntitySeed& seed )
const
1107 const int faces = subEntities( seed, 1 );
1108 for(
int f=0; f<faces; ++f )
1110 const auto faceSeed = this->
template subEntitySeed<1>( seed, f );
1111 if( isBoundaryFace( faceSeed ) )
1117 bool isBoundaryFace(
const int face )
const
1120 const int facePos = 2 * face;
1124 bool isBoundaryFace(
const typename Codim<1>::EntitySeed& faceSeed )
const
1126 assert( faceSeed.isValid() );
1127 return isBoundaryFace( faceSeed.index() );
1130 int boundarySegmentIndex(
const typename Codim<0>::EntitySeed& seed,
const int face )
const
1132 const auto faceSeed = this->
template subEntitySeed<1>( seed, face );
1133 assert( faceSeed.isValid() );
1134 const int facePos = 2 * faceSeed.index();
1141 const std::vector< GeometryType > &geomTypes (
const unsigned int codim )
const
1143 static std::vector< GeometryType > emptyDummy;
1144 if (codim < geomTypes_.size())
1146 return geomTypes_[codim];
1152 template <
class Seed >
1153 GeometryType geometryType(
const Seed& seed )
const
1155 if( Seed::codimension == 0 )
1157 assert(!geomTypes( Seed::codimension ).empty());
1158 return geomTypes( Seed::codimension )[ 0 ];
1163 if( dim == 3 && Seed::codimension == 1 )
1166 const int nVx = corners( seed );
1168 face = Dune::GeometryTypes::cube(2);
1170 face = Dune::GeometryTypes::simplex(2);
1172 face = Dune::GeometryTypes::none(2);
1177 assert(!geomTypes( Seed::codimension ).empty());
1178 return geomTypes( Seed::codimension )[ 0 ];
1182 int indexInInside(
const typename Codim<0>::EntitySeed& seed,
const int i )
const
1184 return ( grid_.
cell_facetag ) ? cartesianIndexInInside( seed, i ) : i;
1187 int cartesianIndexInInside(
const typename Codim<0>::EntitySeed& seed,
const int i )
const
1189 assert( i>= 0 && i<subEntities( seed, 1 ) );
1193 typename Codim<0>::EntitySeed
1194 neighbor(
const typename Codim<0>::EntitySeed& seed,
const int i )
const
1196 const int face = this->
template subEntitySeed<1>( seed, i ).index();
1198 if( nb == seed.index() )
1203 typedef typename Codim<0>::EntitySeed EntitySeed;
1204 return EntitySeed( nb );
1208 indexInOutside(
const typename Codim<0>::EntitySeed& seed,
const int i )
const
1213 const int in_inside = cartesianIndexInInside( seed, i );
1214 return in_inside + ((in_inside % 2) ? -1 : 1);
1218 typedef typename Codim<0>::EntitySeed EntitySeed;
1219 EntitySeed nb = neighbor( seed, i );
1220 const int faces = subEntities( seed, 1 );
1221 for(
int face = 0; face<faces; ++ face )
1223 if( neighbor( nb, face ).equals(seed) )
1225 return indexInInside( nb, face );
1228 DUNE_THROW(InvalidStateException,
"inverse intersection not found");
1233 template <
class EntitySeed>
1235 outerNormal(
const EntitySeed& seed,
const int i )
const
1237 const int face = this->
template subEntitySeed<1>( seed, i ).index();
1238 const int normalIdx = face * GlobalCoordinate :: dimension ;
1239 GlobalCoordinate normal = copyToGlobalCoordinate( grid_.
face_normals + normalIdx );
1241 if( nb != seed.index() )
1248 template <
class EntitySeed>
1250 unitOuterNormal(
const EntitySeed& seed,
const int i )
const
1252 const int face = this->
template subEntitySeed<1>( seed, i ).index();
1253 if( seed.index() == grid_.
face_cells[ 2*face ] )
1255 return unitOuterNormals_[ face ];
1259 GlobalCoordinate normal = unitOuterNormals_[ face ];
1265 template <
class EntitySeed>
1266 GlobalCoordinate centroids(
const EntitySeed& seed )
const
1268 if( ! seed.isValid() )
1269 return GlobalCoordinate( 0 );
1271 const int index = GlobalCoordinate :: dimension * seed.index();
1272 const int codim = EntitySeed::codimension;
1273 assert( index >= 0 && index <
size( codim ) * GlobalCoordinate :: dimension );
1279 else if ( codim == 1 )
1283 else if( codim == dim )
1289 DUNE_THROW(InvalidStateException,
"codimension not implemented");
1290 return GlobalCoordinate( 0 );
1294 GlobalCoordinate copyToGlobalCoordinate(
const double* coords )
const
1296 GlobalCoordinate coordinate;
1297 for(
int i=0; i<GlobalCoordinate::dimension; ++i )
1299 coordinate[ i ] = coords[ i ];
1304 template <
class EntitySeed>
1305 double volumes(
const EntitySeed& seed )
const
1307 static const int codim = EntitySeed::codimension;
1308 if( codim == dim || ! seed.isValid() )
1314 assert( seed.isValid() );
1320 else if ( codim == 1 )
1326 DUNE_THROW(InvalidStateException,
"codimension not implemented");
1336 for(
int i=0; i<3; ++i )
1338 cartDims_[ i ] = grid_.
cartdims[ i ];
1342 const int numCells =
size( 0 );
1344 cellVertices_.resize( numCells );
1349 typedef std::array<int, 3> KeyType;
1350 std::map< const KeyType, const int > vertexFaceTags;
1351 const int vertexFacePattern [8][3] = {
1362 for(
int i=0; i<8; ++i )
1364 KeyType key; key.fill( 4 );
1365 for(
int j=0; j<dim; ++j )
1367 key[ j ] = vertexFacePattern[ i ][ j ];
1370 vertexFaceTags.insert( std::make_pair( key, i ) );
1373 for (
int c = 0; c < numCells; ++c)
1383 typedef std::map<int,int> vertexmap_t;
1384 typedef typename vertexmap_t :: iterator iterator;
1386 std::vector< vertexmap_t > cell_pts( dim*2 );
1395 const int node = grid_.
face_nodes[ nodepos ];
1396 iterator it = cell_pts[ faceTag ].find( node );
1397 if( it == cell_pts[ faceTag ].end() )
1399 cell_pts[ faceTag ].insert( std::make_pair( node, 1 ) );
1409 typedef std::map< int, std::set<int> > vertexlist_t;
1410 vertexlist_t vertexList;
1412 for(
int faceTag = 0; faceTag<dim*2; ++faceTag )
1414 for( iterator it = cell_pts[ faceTag ].begin(),
1415 end = cell_pts[ faceTag ].end(); it != end; ++it )
1419 if( (*it).second == 1 )
1421 vertexList[ (*it).first ].insert( faceTag );
1426 assert(
int(vertexList.size()) == ( dim == 2 ? 4 : 8) );
1428 cellVertices_[ c ].resize( vertexList.size() );
1429 for(
auto it = vertexList.begin(), end = vertexList.end(); it != end; ++it )
1431 assert( (*it).second.size() == dim );
1432 KeyType key; key.fill( 4 );
1434 std::copy( (*it).second.begin(), (*it).second.end(), key.begin() );
1435 auto vx = vertexFaceTags.find( key );
1436 assert( vx != vertexFaceTags.end() );
1437 if( vx != vertexFaceTags.end() )
1439 if( (*vx).second >=
int(cellVertices_[ c ].size()) )
1440 cellVertices_[ c ].resize( (*vx).second+1 );
1442 cellVertices_[ c ][ (*vx).second ] = (*it).first ;
1448 geomTypes_.resize(dim + 1);
1450 for (
int codim = 0; codim <= dim; ++codim)
1452 tmp = Dune::GeometryTypes::cube(dim - codim);
1453 geomTypes_[codim].push_back(tmp);
1459 int minVx = std::numeric_limits<int>::max();
1461 for (
int c = 0; c < numCells; ++c)
1463 std::set<int> cell_pts;
1469 cell_pts.insert(fnbeg, fnend);
1472 cellVertices_[ c ].resize( cell_pts.size() );
1473 std::copy(cell_pts.begin(), cell_pts.end(), cellVertices_[ c ].begin() );
1474 maxVx = std::max( maxVx,
int( cell_pts.size() ) );
1475 minVx = std::min( minVx,
int( cell_pts.size() ) );
1478 if( minVx == maxVx && maxVx == 4 )
1480 for (
int c = 0; c < numCells; ++c)
1482 assert( cellVertices_[ c ].
size() == 4 );
1483 GlobalCoordinate center( 0 );
1484 GlobalCoordinate p[ dim+1 ];
1485 for(
int i=0; i<dim+1; ++i )
1487 const int vertex = cellVertices_[ c ][ i ];
1489 for(
int d=0; d<dim; ++d )
1496 for(
int d=0; d<dim; ++d )
1501 Dune::GeometryType simplex;
1502 simplex = Dune::GeometryTypes::simplex(dim);
1504 typedef Dune::AffineGeometry< ctype, dim, dimworld> AffineGeometryType;
1505 AffineGeometryType geometry( simplex, p );
1513 for(
int face = 0 ; face < faces; ++face )
1516 const int b = grid_.
face_cells[ 2*face + 1 ];
1518 assert( a >=0 || b >=0 );
1523 GlobalCoordinate centerDiff( 0 );
1526 for(
int d=0; d<dimworld; ++d )
1533 for(
int d=0; d<dimworld; ++d )
1541 for(
int d=0; d<dimworld; ++d )
1548 for(
int d=0; d<dimworld; ++d )
1554 GlobalCoordinate normal( 0 );
1555 for(
int d=0; d<dimworld; ++d )
1560 if( centerDiff.two_norm() < 1e-10 )
1564 if( centerDiff * normal < 0 )
1572 bool allSimplex = true ;
1573 bool allCube = true ;
1575 for (
int c = 0; c < numCells; ++c)
1577 const int nVx = cellVertices_[ c ].size();
1589 geomTypes_.resize(dim + 1);
1591 for (
int codim = 0; codim <= dim; ++codim)
1595 tmp = Dune::GeometryTypes::simplex(dim - codim);
1596 geomTypes_[ codim ].push_back( tmp );
1600 tmp = Dune::GeometryTypes::cube(dim - codim);
1601 geomTypes_[ codim ].push_back( tmp );
1605 tmp = Dune::GeometryTypes::none(dim - codim);
1606 geomTypes_[ codim ].push_back( tmp );
1616 const int normalIdx = face * GlobalCoordinate :: dimension ;
1617 GlobalCoordinate normal = copyToGlobalCoordinate( grid_.
face_normals + normalIdx );
1618 normal /= normal.two_norm();
1619 unitOuterNormals_[ face ] = normal;
1621 if( isBoundaryFace( face ) )
1625 const int facePos = 2 * face ;
1630 grid_.
face_cells[ facePos ] = -nBndSegments_;
1632 else if ( grid_.
face_cells[ facePos+1 ] < 0 )
1634 grid_.
face_cells[ facePos+1 ] = -nBndSegments_;
1640 void print( std::ostream& out,
const UnstructuredGridType& grid )
const
1643 for(
int c=0; c<numCells; ++c )
1645 out <<
"cell " << c <<
" : faces = " << std::endl;
1651 out << f <<
" vx = " ;
1652 while( fnbeg != fnend )
1654 out << *fnbeg <<
" ";
1661 const auto& vx = cellVertices_[ c ];
1662 out <<
"cell " << c <<
" : vertices = ";
1663 for(
size_t i=0; i<vx.size(); ++i )
1664 out << vx[ i ] <<
" ";
1671 UnstructuredGridPtr gridPtr_;
1672 const UnstructuredGridType& grid_;
1674 CommunicationType comm_;
1675 std::array< int, 3 > cartDims_;
1676 std::vector< std::vector< GeometryType > > geomTypes_;
1677 std::vector< std::vector< int > > cellVertices_;
1679 std::vector< GlobalCoordinate > unitOuterNormals_;
1685 size_t nBndSegments_;
1697 template<
int dim,
int dimworld,
typename coord_t >
1698 template<
int codim >
1748 template< PartitionIteratorType pitype >
1752 ::template Partition< pitype >::LeafIterator
1755 ::template Partition< pitype >::LevelIterator
1782#include <opm/grid/polyhedralgrid/persistentcontainer.hh>
1783#include <opm/grid/polyhedralgrid/cartesianindexmapper.hh>
1784#include <opm/grid/polyhedralgrid/gridhelpers.hh>
Main OPM-Core grid data structure along with helper functions for construction, destruction and readi...
void destroy_grid(struct UnstructuredGrid *g)
Destroy and deallocate an UnstructuredGrid and all its data.
Definition: UnstructuredGrid.c:32
struct UnstructuredGrid * allocate_grid(size_t ndims, size_t ncells, size_t nfaces, size_t nfacenodes, size_t ncellfaces, size_t nnodes)
Allocate and initialise an UnstructuredGrid where pointers are set to location with correct size.
Definition: UnstructuredGrid.c:87
Routines to construct fully formed grid structures from a simple Cartesian (i.e., tensor product) des...
struct UnstructuredGrid * create_grid_cart2d(int nx, int ny, double dx, double dy)
Form geometrically Cartesian grid in two space dimensions with equally sized cells.
Definition: cart_grid.c:95
struct UnstructuredGrid * create_grid_hexa3d(int nx, int ny, int nz, double dx, double dy, double dz)
Form geometrically Cartesian grid in three space dimensions with equally sized cells.
Definition: cart_grid.c:59
Definition: entityseed.hh:16
Definition: entity.hh:152
Definition: geometry.hh:250
Definition: indexset.hh:25
Definition: intersectioniterator.hh:16
Definition: intersection.hh:20
Definition: iterator.hh:21
Definition: geometry.hh:269
identical grid wrapper
Definition: grid.hh:163
void postAdapt()
Definition: grid.hh:614
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:312
int ghostSize(int, int codim) const
obtain size of ghost region for a grid level
Definition: grid.hh:654
bool loadBalance(CommDataHandleIF< DataHandle, Data > &)
rebalance the load each process has to handle
Definition: grid.hh:758
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: grid.hh:249
Traits::template Codim< EntitySeed::codimension >::EntityPointer entityPointer(const EntitySeed &seed) const
obtain EntityPointer from EntitySeed.
Definition: grid.hh:818
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain EntityPointer from EntitySeed.
Definition: grid.hh:829
bool preAdapt()
Definition: grid.hh:592
typename Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: grid.hh:319
int ghostSize(int codim) const
obtain size of ghost region for the leaf grid
Definition: grid.hh:634
bool loadBalance(DofManager &)
rebalance the load each process has to handle
Definition: grid.hh:778
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:287
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:424
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:275
LevelGridView levelGridView(int) const
View for a grid level for All_Partition.
Definition: grid.hh:802
PolyhedralGrid(const std::vector< int > &n, const std::vector< double > &dx)
constructor
Definition: grid.hh:356
Partition< pitype >::LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:794
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:229
int size(int, int codim) const
obtain number of entites on a level
Definition: grid.hh:437
Partition< pitype >::LevelGridView levelGridView(int) const
View for a grid level.
Definition: grid.hh:785
void update()
update grid caches
Definition: grid.hh:848
void switchToDistributedView()
Switch to the distributed view.
Definition: grid.hh:708
int overlapSize(int, int) const
obtain size of overlap region for a grid level
Definition: grid.hh:644
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:448
void scatterData(DataHandle &handle) const
Moves data from the global (all data on process) view to the distributed view.
Definition: grid.hh:893
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:304
const CommunicationType & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:721
int overlapSize(int) const
obtain size of overlap region for the leaf grid
Definition: grid.hh:625
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:233
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:212
PolyhedralGrid(UnstructuredGridPtr &&gridPtr)
constructor
Definition: grid.hh:375
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:231
bool adapt(DataHandle &)
Definition: grid.hh:608
int size(int, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:477
void communicate(DataHandle &, InterfaceType, CommunicationDirection) const
communicate information on leaf entities
Definition: grid.hh:694
size_t numBoundarySegments() const
obtain number of leaf entities
Definition: grid.hh:497
void switchToGlobalView()
Switch to the global view.
Definition: grid.hh:702
bool loadBalance()
rebalance the load each process has to handle
Definition: grid.hh:737
PolyhedralGrid(const UnstructuredGridType &grid)
constructor
Definition: grid.hh:394
LeafGridView leafGridView() const
View for the leaf grid for All_Partition.
Definition: grid.hh:809
int size(GeometryType type) const
returns the number of boundary segments within the macro grid
Definition: grid.hh:486
void communicate(DataHandle &, InterfaceType, CommunicationDirection, int) const
communicate information on a grid level
Definition: grid.hh:673
bool adapt()
Definition: grid.hh:598
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:265
Transform a corner-point grid ZCORN field to account for MINPV processing.
Definition: MinpvProcessor.hpp:37
Routines to form a complete UnstructuredGrid from a corner-point specification.
struct UnstructuredGrid * create_grid_cornerpoint(const struct grdecl *in, double tol)
Construct grid representation from corner-point specification of a particular geological model.
Definition: cornerpoint_grid.c:164
void compute_geometry(struct UnstructuredGrid *g)
Compute derived geometric primitives in a grid.
Definition: cornerpoint_grid.c:137
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Low-level corner-point processing routines and supporting data structures.
traits structure containing types for a codimension
Definition: grid.hh:1701
Partition< All_Partition >::LeafIterator LeafIterator
type of level iterator
Definition: grid.hh:1766
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:1710
Traits::template Codim< codim >::EntityPointer EntityPointer
type of entity pointer
Definition: grid.hh:1716
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:1741
Partition< All_Partition >::LevelIterator LevelIterator
type of leaf iterator
Definition: grid.hh:1775
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:1731
Types for GridView.
Definition: grid.hh:243
Data structure for an unstructured grid, unstructured meaning that any cell may have an arbitrary num...
Definition: UnstructuredGrid.h:99
int * face_nodes
Contains for each face, the indices of its adjacent nodes.
Definition: UnstructuredGrid.h:121
int * face_nodepos
For a face f, face_nodepos[f] contains the starting index for f's nodes in the face_nodes array.
Definition: UnstructuredGrid.h:127
int number_of_cells
The number of cells in the grid.
Definition: UnstructuredGrid.h:109
double * face_areas
Exact or approximate face areas.
Definition: UnstructuredGrid.h:173
int * cell_faces
Contains for each cell, the indices of its adjacent faces.
Definition: UnstructuredGrid.h:146
int number_of_faces
The number of faces in the grid.
Definition: UnstructuredGrid.h:111
double * cell_centroids
Exact or approximate cell centroids, stored consecutively for each cell.
Definition: UnstructuredGrid.h:192
int * cell_facepos
For a cell c, cell_facepos[c] contains the starting index for c's faces in the cell_faces array.
Definition: UnstructuredGrid.h:152
int * cell_facetag
If non-null, this array contains a number for cell-face adjacency indicating the face's position with...
Definition: UnstructuredGrid.h:244
double * cell_volumes
Exact or approximate cell volumes.
Definition: UnstructuredGrid.h:197
int * face_cells
For a face f, face_cells[2*f] and face_cells[2*f + 1] contain the cell indices of the cells adjacent ...
Definition: UnstructuredGrid.h:138
double * face_centroids
Exact or approximate face centroids, stored consecutively for each face.
Definition: UnstructuredGrid.h:168
int number_of_nodes
The number of nodes in the grid.
Definition: UnstructuredGrid.h:113
int cartdims[3]
Contains the size of the logical cartesian structure (if any) of the grid.
Definition: UnstructuredGrid.h:227
int * global_cell
If non-null, this array contains the logical cartesian indices (in a lexicographic ordering) of each ...
Definition: UnstructuredGrid.h:214
double * face_normals
Exact or approximate face normals, stored consecutively for each face.
Definition: UnstructuredGrid.h:184
double * node_coordinates
Node coordinates, stored consecutively for each node.
Definition: UnstructuredGrid.h:160
Raw corner-point specification of a particular geological model.
Definition: preprocess.h:56
const double * coord
Pillar end-points.
Definition: preprocess.h:58
int dims[3]
Cartesian box dimensions.
Definition: preprocess.h:57
const double * zcorn
Corner-point depths.
Definition: preprocess.h:59
const int * actnum
Explicit "active" map.
Definition: preprocess.h:60