diff --git a/ApplicationLibCode/Application/RiaResultNames.cpp b/ApplicationLibCode/Application/RiaResultNames.cpp index 0e96b96946..d4e6097201 100644 --- a/ApplicationLibCode/Application/RiaResultNames.cpp +++ b/ApplicationLibCode/Application/RiaResultNames.cpp @@ -361,6 +361,14 @@ QString RiaResultNames::indexKResultName() return "INDEX_K"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaResultNames::faultDistanceName() +{ + return "FAULTDIST"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/RiaResultNames.h b/ApplicationLibCode/Application/RiaResultNames.h index 1d0974375a..7c106974b2 100644 --- a/ApplicationLibCode/Application/RiaResultNames.h +++ b/ApplicationLibCode/Application/RiaResultNames.h @@ -70,6 +70,8 @@ QString indexIResultName(); QString indexJResultName(); QString indexKResultName(); +QString faultDistanceName(); + QString soil(); QString sgas(); QString swat(); diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp index 8cf8c0083e..9ac9300741 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -1038,12 +1038,17 @@ void RigCaseCellResultsData::createPlaceholderResultEntries() { findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::indexIResultName() ), false ); - findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::indexJResultName() ), false ); findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::indexKResultName() ), false ); } + + // Fault distance + { + findOrCreateScalarResultIndex( RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::faultDistanceName() ), + false ); + } } //-------------------------------------------------------------------------------------------------- @@ -1254,6 +1259,10 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResult( const RigEclipseResu { computeIndexResults(); } + else if ( resultName == RiaResultNames::faultDistanceName() ) + { + computeFaultDistance(); + } } else if ( type == RiaDefines::ResultCatType::DYNAMIC_NATIVE ) { @@ -2002,6 +2011,72 @@ void RigCaseCellResultsData::computeIndexResults() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigCaseCellResultsData::computeFaultDistance() +{ + size_t reservoirCellCount = activeCellInfo()->reservoirCellCount(); + if ( reservoirCellCount == 0 ) return; + + size_t resultIndex = findScalarResultIndexFromAddress( + RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, RiaResultNames::faultDistanceName() ) ); + + if ( resultIndex == cvf::UNDEFINED_SIZE_T ) return; + + std::vector>& result = m_cellScalarResults[resultIndex]; + + if ( result.empty() ) result.resize( 1 ); + + bool shouldCompute = false; + if ( result[0].size() < reservoirCellCount ) + { + result[0].resize( reservoirCellCount, std::numeric_limits::infinity() ); + shouldCompute = true; + } + + if ( !shouldCompute ) return; + + const std::vector& globalCellArray = m_ownerMainGrid->globalCellArray(); + + long long numCells = static_cast( globalCellArray.size() ); + + std::vector faceTypes = cvf::StructGridInterface::validFaceTypes(); + + // Preprocessing: create vector of all fault face centers. + std::vector faultFaceCenters; + for ( long long cellIdx = 0; cellIdx < numCells; cellIdx++ ) + { + if ( activeCellInfo()->isActive( cellIdx ) ) + { + const RigCell& cell = globalCellArray[cellIdx]; + for ( auto faceType : faceTypes ) + { + if ( m_ownerMainGrid->findFaultFromCellIndexAndCellFace( cellIdx, faceType ) ) + faultFaceCenters.push_back( cell.faceCenter( faceType ) ); + } + } + } + +#pragma omp parallel for + for ( long long cellIdx = 0; cellIdx < numCells; cellIdx++ ) + { + const RigCell& cell = globalCellArray[cellIdx]; + + size_t resultIndex = cellIdx; + if ( resultIndex == cvf::UNDEFINED_SIZE_T || !activeCellInfo()->isActive( cellIdx ) ) continue; + + // Find closest fault face + double shortestDistance = std::numeric_limits::infinity(); + for ( const cvf::Vec3d& faultFaceCenter : faultFaceCenters ) + { + shortestDistance = std::min( cell.center().pointDistance( faultFaceCenter ), shortestDistance ); + } + + result[0][resultIndex] = shortestDistance; + } +} + namespace RigTransmissibilityCalcTools { void calculateConnectionGeometry( const RigCell& c1, diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h index d181abdb35..c3000629b3 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -187,6 +187,7 @@ private: void computeMobilePV(); void computeIndexResults(); + void computeFaultDistance(); bool isDataPresent( size_t scalarResultIndex ) const; diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp index d03dd935f8..ff9923fa26 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp @@ -233,6 +233,21 @@ StructGridInterface::FaceType StructGridInterface::oppositeFace( FaceType face ) return opposite; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector StructGridInterface::validFaceTypes() +{ + return { + cvf::StructGridInterface::FaceType::NEG_I, + cvf::StructGridInterface::FaceType::POS_I, + cvf::StructGridInterface::FaceType::NEG_J, + cvf::StructGridInterface::FaceType::POS_J, + cvf::StructGridInterface::FaceType::NEG_K, + cvf::StructGridInterface::FaceType::POS_K, + }; +} + //-------------------------------------------------------------------------------------------------- /// Return values are set to cvf::UNDEFINED_SIZE_T if the neighbor is in the negative area //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.h b/Fwk/AppFwk/CommonCode/cvfStructGrid.h index e82be4f043..6407b93e96 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.h +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.h @@ -125,6 +125,7 @@ public: static std::pair edgeVertexIndices( cvf::StructGridInterface::FaceType face1, cvf::StructGridInterface::FaceType face2 ); + static std::vector validFaceTypes(); private: mutable double m_characteristicCellSizeI;