diff --git a/ApplicationLibCode/FileInterface/RifOpmRadialGridTools.cpp b/ApplicationLibCode/FileInterface/RifOpmRadialGridTools.cpp index 3026c8be42..f7d3a79a35 100644 --- a/ApplicationLibCode/FileInterface/RifOpmRadialGridTools.cpp +++ b/ApplicationLibCode/FileInterface/RifOpmRadialGridTools.cpp @@ -26,8 +26,6 @@ #include "ExportCommands/RicExportLgrFeature.h" #include "RicCreateTemporaryLgrFeature.h" -#include "RifReaderEclipseOutput.h" - #include "RigActiveCellInfo.h" #include "RigEclipseCaseData.h" #include "RigMainGrid.h" @@ -219,8 +217,8 @@ void RifOpmRadialGridTools::transferCylindricalCoords( Opm::EclIO::EGrid& opmMai std::array opmY{}; std::array opmZ{}; - const auto hostCellGlobalIndices = opmGrid.hostCellsGlobalIndex(); - const size_t* cellMappingECLRi = RifReaderEclipseOutput::eclipseCellIndexMapping(); + const auto hostCellGlobalIndices = opmGrid.hostCellsGlobalIndex(); + const auto& cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping(); bool convertCylindricalCoords = false; @@ -236,7 +234,7 @@ void RifOpmRadialGridTools::transferCylindricalCoords( Opm::EclIO::EGrid& opmMai for ( size_t opmNodeIndex = 0; opmNodeIndex < 8; opmNodeIndex++ ) { - size_t riNodeIndex = riNodeStartIndex + cellMappingECLRi[opmNodeIndex]; + size_t riNodeIndex = riNodeStartIndex + cornerIndexMapping[opmNodeIndex]; // The radial grid is specified with (0,0) as center, add grid center to get correct global coordinates riNodes[riNodeIndex] = cvf::Vec3d( opmX[opmNodeIndex], opmY[opmNodeIndex], -opmZ[opmNodeIndex] ); @@ -267,10 +265,10 @@ void RifOpmRadialGridTools::convertRadialGridToCartesianGrid( Opm::EclIO::EGrid& std::array opmY{}; std::array opmZ{}; - const auto hostCellGlobalIndices = opmGrid.hostCellsGlobalIndex(); - const size_t* cellMappingECLRi = RifReaderEclipseOutput::eclipseCellIndexMapping(); - const auto gridDimension = opmGrid.dimension(); - const auto riNodes = riMainGrid->modifiableNodes(); + const auto hostCellGlobalIndices = opmGrid.hostCellsGlobalIndex(); + const auto& cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping(); + const auto gridDimension = opmGrid.dimension(); + const auto riNodes = riMainGrid->modifiableNodes(); for ( int opmCellIndex = 0; opmCellIndex < static_cast( cellCount ); opmCellIndex++ ) { @@ -292,7 +290,7 @@ void RifOpmRadialGridTools::convertRadialGridToCartesianGrid( Opm::EclIO::EGrid& for ( size_t opmNodeIndex = 0; opmNodeIndex < 8; opmNodeIndex++ ) { - size_t riNodeIndex = riNodeStartIndex + cellMappingECLRi[opmNodeIndex]; + size_t riNodeIndex = riNodeStartIndex + cornerIndexMapping[opmNodeIndex]; // The radial grid is specified with (0,0) as center, add grid center to get correct global coordinates cvf::Vec3d riNode( opmX[opmNodeIndex] + xCenterCoordOpm, opmY[opmNodeIndex] + yCenterCoordOpm, -opmZ[opmNodeIndex] ); diff --git a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp index 5bbbab75b3..0ec6e86034 100644 --- a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp @@ -85,39 +85,6 @@ /// //-------------------------------------------------------------------------------------------------- -// The indexing conventions for vertices in ECLIPSE -// -// 2-------------3 -// /| /| -// / | / | /j -// / | / | / -// 0-------------1 | *---i -// | | | | | -// | 6---------|---7 | -// | / | / |k -// | / | / -// |/ |/ -// 4-------------5 -// vertex indices -// -// The indexing conventions for vertices in ResInsight -// -// 7-------------6 |k -// /| /| | /j -// / | / | |/ -// / | / | *---i -// 4-------------5 | -// | | | | -// | 3---------|---2 -// | / | / -// | / | / -// |/ |/ -// 0-------------1 -// vertex indices -// - -static const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; - //-------------------------------------------------------------------------------------------------- /// Constructor //-------------------------------------------------------------------------------------------------- @@ -211,10 +178,11 @@ bool RifReaderEclipseOutput::transferGridCellData( RigMainGrid* mainGrid } // Corner coordinates - int cIdx; + const auto& cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping(); + int cIdx; for ( cIdx = 0; cIdx < 8; ++cIdx ) { - double* point = gridNodes[(size_t)gridLocalCellIndex * 8 + cellMappingECLRi[cIdx]].ptr(); + double* point = gridNodes[(size_t)gridLocalCellIndex * 8 + cornerIndexMapping[cIdx]].ptr(); ecl_grid_get_cell_corner_xyz1( localEclGrid, gridLocalCellIndex, cIdx, &( point[0] ), &( point[1] ), &( point[2] ) ); point[2] = -point[2]; // Flipping Z making depth become negative z values cell.cornerIndices()[cIdx] = nodeStartIndex + (size_t)gridLocalCellIndex * 8 + cIdx; @@ -669,14 +637,6 @@ void RifReaderEclipseOutput::setFileDataAccess( RifEclipseRestartDataAccess* res m_dynamicResultsAccess = restartDataAccess; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const size_t* RifReaderEclipseOutput::eclipseCellIndexMapping() -{ - return cellMappingECLRi; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.h b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.h index 9ecbd871ec..a0bc82a9ee 100644 --- a/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.h +++ b/ApplicationLibCode/FileInterface/RifReaderEclipseOutput.h @@ -61,8 +61,6 @@ public: void setHdf5FileName( const QString& fileName ); void setFileDataAccess( RifEclipseRestartDataAccess* restartDataAccess ); - static const size_t* eclipseCellIndexMapping(); - bool openAndReadActiveCellData( const QString& fileName, const std::vector& mainCaseTimeSteps, RigEclipseCaseData* eclipseCase ); bool staticResult( const QString& result, RiaDefines::PorosityModelType matrixOrFracture, std::vector* values ) override; diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp index ee9a9d951c..6e8ba520b5 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp @@ -558,8 +558,7 @@ void RifReaderOpmCommon::transferGeometry( Opm::EclIO::EGrid& opmMainGrid, auto radialGridCenterTopLayerOpm = isRadialGrid ? RifOpmRadialGridTools::computeXyCenterForTopOfCells( opmMainGrid, opmGrid, localGrid ) : std::map>(); - // use same mapping as resdata - const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; + const auto& cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping(); #pragma omp parallel for for ( int opmCellIndex = 0; opmCellIndex < static_cast( localGrid->cellCount() ); opmCellIndex++ ) @@ -601,7 +600,7 @@ void RifReaderOpmCommon::transferGeometry( Opm::EclIO::EGrid& opmMainGrid, for ( size_t opmNodeIndex = 0; opmNodeIndex < 8; opmNodeIndex++ ) { - auto riCornerIndex = cellMappingECLRi[opmNodeIndex]; + auto riCornerIndex = cornerIndexMapping[opmNodeIndex]; size_t riNodeIndex = riNodeStartIndex + riCornerIndex; auto& riNode = riNodes[riNodeIndex - nodeStartIndex]; diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp b/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp index 6ab6aebbf1..703617c456 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp @@ -264,8 +264,7 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa auto radialGridCenterTopLayerOpm = isRadialGrid ? RifOpmRadialGridTools::computeXyCenterForTopOfCells( opmMainGrid, opmGrid, localGrid ) : std::map>(); - // use same mapping as resdata - const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; + const auto& cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping(); std::map activeCellMap; int nativeIdx = 0; @@ -324,7 +323,7 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa for ( size_t opmNodeIndex = 0; opmNodeIndex < 8; opmNodeIndex++ ) { - auto riCornerIndex = cellMappingECLRi[opmNodeIndex]; + auto riCornerIndex = cornerIndexMapping[opmNodeIndex]; size_t riNodeIndex = riNodeStartIndex + riCornerIndex; auto& riNode = riNodes[riNodeIndex - nodeStartIndex]; diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemTypes.cpp b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemTypes.cpp index fb5520bff5..80c9fb1b89 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemTypes.cpp +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemTypes.cpp @@ -44,7 +44,13 @@ int RigFemTypes::elementFaceCount( RigElementType elmType ) } //-------------------------------------------------------------------------------------------------- +/// HEX8 node and face ordering matches the reservoir grid definition in +/// cvf::StructGridInterface::cellFaceVertexIndices() (Fwk/AppFwk/CommonCode/cvfStructGrid.cpp), and the +/// face index equals cvf::StructGridInterface::FaceType. /// +/// The tables are intentionally kept as a local copy, as FEM elements are a separate grid definition and +/// the explicit indices are easier to check against element documentation. Consistency with the reservoir +/// grid is verified by unit tests. //-------------------------------------------------------------------------------------------------- // HEX8 // 7---------6 Increased k -> Increased depth : 4 5 6 7 is the deepest quad @@ -58,8 +64,15 @@ int RigFemTypes::elementFaceCount( RigElementType elmType ) const int* RigFemTypes::localElmNodeIndicesForFace( RigElementType elmType, int faceIdx, int* faceNodeCount ) { - static const int HEX8_Faces[6][4] = { { 1, 2, 6, 5 }, { 0, 4, 7, 3 }, { 3, 7, 6, 2 }, { 0, 1, 5, 4 }, { 4, 5, 6, 7 }, { 0, 3, 2, 1 } }; - static const int CAX4_Faces[4] = { 0, 1, 2, 3 }; + static const int HEX8_Faces[6][4] = { + { 1, 2, 6, 5 }, // POS_I + { 0, 4, 7, 3 }, // NEG_I + { 3, 7, 6, 2 }, // POS_J + { 0, 1, 5, 4 }, // NEG_J + { 4, 5, 6, 7 }, // POS_K + { 0, 3, 2, 1 }, // NEG_K + }; + static const int CAX4_Faces[4] = { 0, 1, 2, 3 }; switch ( elmType ) { diff --git a/ApplicationLibCode/ProjectDataModel/RimCornerPointCase.cpp b/ApplicationLibCode/ProjectDataModel/RimCornerPointCase.cpp index 75c485de3f..56b45a7708 100644 --- a/ApplicationLibCode/ProjectDataModel/RimCornerPointCase.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimCornerPointCase.cpp @@ -269,7 +269,7 @@ void RimCornerPointCase::buildGrid( RigEclipseCaseData& eclipseCaseData, std::span gridNodes = mainGrid->allocateNodes( static_cast( cellCount ) * 8 ); - const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; + const auto& cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping(); cvf::Vec3d offset( 0.0, 0.0, 0.0 ); cvf::Vec3d scale( 1.0, 1.0, 1.0 ); @@ -308,7 +308,7 @@ void RimCornerPointCase::buildGrid( RigEclipseCaseData& eclipseCaseData, // Corner coordinates for ( int cIdx = 0; cIdx < 8; ++cIdx ) { - double* point = gridNodes[(size_t)gridLocalCellIndex * 8 + cellMappingECLRi[cIdx]].ptr(); + double* point = gridNodes[(size_t)gridLocalCellIndex * 8 + cornerIndexMapping[cIdx]].ptr(); point[0] = corners[cIdx].x(); point[1] = corners[cIdx].y(); diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.cpp index 8f486f8cfe..0f69a2badf 100644 --- a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.cpp +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.cpp @@ -29,9 +29,6 @@ #include -// map from cell face corner index to neighbor cell face corner index, ref StructGridInterface::cellFaceVertexIndices -const std::vector RigGridQualityResultCalculator::m_cornerMap = { 0, 3, 2, 1 }; - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -201,10 +198,11 @@ int RigGridQualityResultCalculator::faulted( const RigCell& cell ) auto cellCorners = cell.faceCorners( face ); auto neighborCorners = neighborCell.faceCorners( cvf::StructGridInterface::oppositeFace( face ) ); + const auto& cornerMap = cvf::StructGridInterface::oppositeFaceVertexIndexMap(); for ( size_t i = 0; i < cellCorners.size(); i++ ) { // map from cell face corner index to neighbor cell face corner index - double zDiff = std::abs( cellCorners[i].z() - neighborCorners[m_cornerMap[i]].z() ); + double zDiff = std::abs( cellCorners[i].z() - neighborCorners[cornerMap[i]].z() ); if ( zDiff > faultedThreshold ) { result += 1; @@ -225,10 +223,11 @@ int RigGridQualityResultCalculator::negativeThickness( const RigCell& cell ) auto cornersTop = cell.faceCorners( cvf::StructGridInterface::POS_K ); auto cornersBottom = cell.faceCorners( cvf::StructGridInterface::NEG_K ); + const auto& cornerMap = cvf::StructGridInterface::oppositeFaceVertexIndexMap(); for ( size_t i = 0; i < 4; i++ ) { // map from top face corner index to bottom face corner index - if ( cornersTop[i].z() > cornersBottom[m_cornerMap[i]].z() ) + if ( cornersTop[i].z() > cornersBottom[cornerMap[i]].z() ) { isNegative = 1; break; diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.h b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.h index 1feba1ad0f..db6fe1a657 100644 --- a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.h +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigGridQualityResultCalculator.h @@ -48,7 +48,4 @@ private: static RigEclipseResultAddress createDoubleAddress( QString resultName ); static RigEclipseResultAddress createIntegerAddress( QString resultName ); - - // map from cell face corner index to neighbor cell face corner index, ref StructGridInterface::cellFaceVertexIndices - static const std::vector m_cornerMap; }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigCell.cpp b/ApplicationLibCode/ReservoirDataModel/RigCell.cpp index 870056375c..e37b9817aa 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCell.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCell.cpp @@ -551,11 +551,12 @@ std::pair RigCell::minMaxAnglesSides() const //-------------------------------------------------------------------------------------------------- bool RigCell::isCollapsedVertically() const { - static const double collapsedThreshold = 1e-5; - static const std::vector cornerMap = { 0, 3, 2, 1 }; // map from top to bottom inside cell + static const double collapsedThreshold = 1e-5; - auto cornersTop = faceCorners( cvf::StructGridInterface::POS_K ); - auto cornersBottom = faceCorners( cvf::StructGridInterface::NEG_K ); + // map from top to bottom inside cell + const auto& cornerMap = cvf::StructGridInterface::oppositeFaceVertexIndexMap(); + auto cornersTop = faceCorners( cvf::StructGridInterface::POS_K ); + auto cornersBottom = faceCorners( cvf::StructGridInterface::NEG_K ); for ( size_t i = 0; i < 4; i++ ) { if ( isNear( cornersTop[i], cornersBottom[cornerMap[i]], collapsedThreshold ) ) diff --git a/ApplicationLibCode/ReservoirDataModel/RigCellGeometryTools.cpp b/ApplicationLibCode/ReservoirDataModel/RigCellGeometryTools.cpp index e12f3bbcde..2cad73fa00 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCellGeometryTools.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCellGeometryTools.cpp @@ -894,12 +894,12 @@ bool RigCellGeometryTools::pointInsideCellNegK2D( const cvf::Vec3d& point, const { std::vector polygon; - const std::vector negK = { 0, 3, 2, 1, 0 }; - + const auto& negK = cvf::StructGridInterface::cellFaceVertexIndices( cvf::StructGridInterface::NEG_K ); for ( auto i : negK ) { polygon.push_back( cellCorners[i] ); } + polygon.push_back( cellCorners[negK.front()] ); return RigCellGeometryTools::pointInsidePolygon2D( point, polygon ); } diff --git a/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp index f354bb565f..0ef5e5d071 100644 --- a/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp @@ -229,9 +229,6 @@ public: static bool RiaGetActiveCellCenters_init = RiaSocketCommandFactory::instance()->registerCreator( RiaGetActiveCellCenters::commandName() ); -// NB: Match this mapping with the mapping in RifReaderEclipseOutput.cpp -static const size_t cellCornerMappingEclipse[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -288,7 +285,7 @@ public: { for ( size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++ ) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + size_t cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping()[cornerIdx]; quint64 valueIndex = 0; @@ -375,7 +372,7 @@ public: { for ( size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++ ) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + size_t cornerIndexMapping = cvf::StructGridInterface::reservoirSimulatorCornerIndexMapping()[cornerIdx]; quint64 valueIndex = 0; diff --git a/ApplicationLibCode/UnitTests/StructGridInterface-Test.cpp b/ApplicationLibCode/UnitTests/StructGridInterface-Test.cpp index b75adae292..db16d6199f 100644 --- a/ApplicationLibCode/UnitTests/StructGridInterface-Test.cpp +++ b/ApplicationLibCode/UnitTests/StructGridInterface-Test.cpp @@ -49,3 +49,58 @@ TEST( StructGridInterfaceTest, TestEdgeVertices ) EXPECT_EQ( indices.second, 1 ); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( StructGridInterfaceTest, OppositeFaceVertexIndexMapConnectsCoincidentPillarVertices ) +{ + // Unit cube corners using the ResInsight corner ordering + const std::array corners = { Vec3d( 0, 0, 0 ), + Vec3d( 1, 0, 0 ), + Vec3d( 1, 1, 0 ), + Vec3d( 0, 1, 0 ), + Vec3d( 0, 0, 1 ), + Vec3d( 1, 0, 1 ), + Vec3d( 1, 1, 1 ), + Vec3d( 0, 1, 1 ) }; + + const auto& map = StructGridInterface::oppositeFaceVertexIndexMap(); + + for ( auto face : StructGridInterface::validFaceTypes() ) + { + const auto axis = static_cast( StructGridInterface::gridAxisFromFace( face ) ); + + const auto& faceIndices = StructGridInterface::cellFaceVertexIndices( face ); + const auto& oppositeIndices = StructGridInterface::cellFaceVertexIndices( StructGridInterface::oppositeFace( face ) ); + + for ( size_t i = 0; i < 4; i++ ) + { + Vec3d diff = corners[faceIndices[i]] - corners[oppositeIndices[map[i]]]; + diff[axis] = 0.0; + EXPECT_DOUBLE_EQ( 0.0, diff.length() ) << "face " << face << " local vertex " << i; + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( StructGridInterfaceTest, LegacyCellFaceVertexIndicesMatchesTable ) +{ + for ( auto face : StructGridInterface::validFaceTypes() ) + { + ubyte legacy[4]; + StructGridInterface::cellFaceVertexIndices( face, legacy ); + + const auto& indices = StructGridInterface::cellFaceVertexIndices( face ); + for ( size_t i = 0; i < 4; i++ ) + { + EXPECT_EQ( indices[i], legacy[i] ); + } + } + + ubyte untouched[4] = { 9, 9, 9, 9 }; + StructGridInterface::cellFaceVertexIndices( StructGridInterface::NO_FACE, untouched ); + EXPECT_EQ( 9, untouched[0] ); +} diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp index 4b84e4244c..f6c3c9e6c8 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp @@ -71,58 +71,87 @@ StructGridInterface::StructGridInterface() //-------------------------------------------------------------------------------------------------- void StructGridInterface::cellFaceVertexIndices( FaceType face, cvf::ubyte vertexIndices[4] ) { - // - // 7---------6 - // /| /| |k - // / | / | | /j - // 4---------5 | |/ - // | 3------|--2 *---i - // | / | / - // |/ |/ - // 0---------1 + if ( face < POS_I || face > NEG_K ) return; - if ( face == NEG_K ) - { - vertexIndices[0] = 0; - vertexIndices[1] = 3; - vertexIndices[2] = 2; - vertexIndices[3] = 1; - } - else if ( face == POS_K ) - { - vertexIndices[0] = 4; - vertexIndices[1] = 5; - vertexIndices[2] = 6; - vertexIndices[3] = 7; - } - else if ( face == NEG_J ) - { - vertexIndices[0] = 0; - vertexIndices[1] = 1; - vertexIndices[2] = 5; - vertexIndices[3] = 4; - } - else if ( face == POS_J ) - { - vertexIndices[0] = 3; - vertexIndices[1] = 7; - vertexIndices[2] = 6; - vertexIndices[3] = 2; - } - else if ( face == NEG_I ) - { - vertexIndices[0] = 0; - vertexIndices[1] = 4; - vertexIndices[2] = 7; - vertexIndices[3] = 3; - } - else if ( face == POS_I ) - { - vertexIndices[0] = 1; - vertexIndices[1] = 2; - vertexIndices[2] = 6; - vertexIndices[3] = 5; - } + const auto& indices = cellFaceVertexIndices( face ); + std::copy( indices.begin(), indices.end(), vertexIndices ); +} + +//-------------------------------------------------------------------------------------------------- +/// Corner indices of a cell face +/// +/// 7---------6 +/// /| /| |k +/// / | / | | /j +/// 4---------5 | |/ +/// | 3------|--2 *---i +/// | / | / +/// |/ |/ +/// 0---------1 +//-------------------------------------------------------------------------------------------------- +const std::array& StructGridInterface::cellFaceVertexIndices( FaceType face ) +{ + // Indexed by FaceType: POS_I, NEG_I, POS_J, NEG_J, POS_K, NEG_K + static constexpr std::array, 6> faceVertexIndices = { { + { 1, 2, 6, 5 }, + { 0, 4, 7, 3 }, + { 3, 7, 6, 2 }, + { 0, 1, 5, 4 }, + { 4, 5, 6, 7 }, + { 0, 3, 2, 1 }, + } }; + + CVF_ASSERT( face >= POS_I && face <= NEG_K ); + return faceVertexIndices[face]; +} + +//-------------------------------------------------------------------------------------------------- +/// Maps a face-local vertex index on a face to the face-local vertex index of the coincident vertex on the +/// opposite face, either of the same cell (connected by an edge) or of the neighbor cell across the face. +/// See cellFaceVertexIndices(). The mapping is its own inverse. +//-------------------------------------------------------------------------------------------------- +const std::array& StructGridInterface::oppositeFaceVertexIndexMap() +{ + static constexpr std::array map = { 0, 3, 2, 1 }; + return map; +} + +//-------------------------------------------------------------------------------------------------- +/// Maps between reservoir simulator corner ordering and ResInsight corner ordering. +/// The mapping is its own inverse. +/// +/// Reservoir simulator corner ordering (i fastest, then j, then k, with k pointing downwards) +/// +/// 2-------------3 +/// /| /| +/// / | / | /j +/// / | / | / +/// 0-------------1 | *---i +/// | | | | | +/// | 6---------|---7 | +/// | / | / |k +/// | / | / +/// |/ |/ +/// 4-------------5 +/// +/// ResInsight corner ordering +/// +/// 7-------------6 |k +/// /| /| | /j +/// / | / | |/ +/// / | / | *---i +/// 4-------------5 | +/// | | | | +/// | 3---------|---2 +/// | / | / +/// | / | / +/// |/ |/ +/// 0-------------1 +//-------------------------------------------------------------------------------------------------- +const std::array& StructGridInterface::reservoirSimulatorCornerIndexMapping() +{ + static constexpr std::array map = { 0, 1, 3, 2, 4, 5, 7, 6 }; + return map; } //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.h b/Fwk/AppFwk/CommonCode/cvfStructGrid.h index c9e393ad89..a6ae56cf36 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.h +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.h @@ -109,7 +109,11 @@ public: virtual cvf::Vec3d gridPointCoordinate( size_t i, size_t j, size_t k ) const = 0; public: - static void cellFaceVertexIndices( FaceType face, cvf::ubyte vertexIndices[4] ); + static void cellFaceVertexIndices( FaceType face, cvf::ubyte vertexIndices[4] ); + static const std::array& cellFaceVertexIndices( FaceType face ); + static const std::array& oppositeFaceVertexIndexMap(); + static const std::array& reservoirSimulatorCornerIndexMapping(); + static FaceType oppositeFace( FaceType face ); static void neighborIJKAtCellFace( size_t i, size_t j,