Parallelize another loop in fault calculation

This commit is contained in:
Gaute Lindkvist 2020-05-14 11:36:20 +02:00
parent c5661f3fce
commit 3a526ab555
3 changed files with 78 additions and 56 deletions

View File

@ -351,6 +351,17 @@ bool RigGridBase::cellIJKNeighbor( size_t i, size_t j, size_t k, FaceType face,
return true; return true;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigGridBase::cellIJKNeighborUnguarded( size_t i, size_t j, size_t k, FaceType face, size_t* neighborCellIndex ) const
{
size_t ni, nj, nk;
neighborIJKAtCellFace( i, j, k, face, &ni, &nj, &nk );
*neighborCellIndex = cellIndexFromIJK( ni, nj, nk );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -106,6 +106,7 @@ public:
bool isCellValid( size_t i, size_t j, size_t k ) const override; bool isCellValid( size_t i, size_t j, size_t k ) const override;
bool cellIJKNeighbor( size_t i, size_t j, size_t k, FaceType face, size_t* neighborCellIndex ) const override; bool cellIJKNeighbor( size_t i, size_t j, size_t k, FaceType face, size_t* neighborCellIndex ) const override;
void cellIJKNeighborUnguarded( size_t i, size_t j, size_t k, FaceType face, size_t* neighborCellIndex ) const;
private: private:
std::string m_gridName; std::string m_gridName;

View File

@ -450,6 +450,13 @@ void RigMainGrid::calculateFaults( const RigActiveCellInfo* activeCellInfo )
std::vector<RigFault::FaultFace>& unNamedFaultFaces = unNamedFault->faultFaces(); std::vector<RigFault::FaultFace>& unNamedFaultFaces = unNamedFault->faultFaces();
std::vector<RigFault::FaultFace>& unNamedFaultFacesInactive = unNamedFaultWithInactive->faultFaces(); std::vector<RigFault::FaultFace>& unNamedFaultFacesInactive = unNamedFaultWithInactive->faultFaces();
#pragma omp parallel
{
std::vector<RigFault::FaultFace> threadUnNamedFaultFaces;
std::vector<RigFault::FaultFace> threadUnNamedFaultFacesInactive;
#pragma omp for schedule( guided )
for ( int gcIdx = 0; gcIdx < static_cast<int>( m_cells.size() ); ++gcIdx ) for ( int gcIdx = 0; gcIdx < static_cast<int>( m_cells.size() ); ++gcIdx )
{ {
addUnNamedFaultFaces( gcIdx, addUnNamedFaultFaces( gcIdx,
@ -457,10 +464,21 @@ void RigMainGrid::calculateFaults( const RigActiveCellInfo* activeCellInfo )
vxs, vxs,
unNamedFaultIdx, unNamedFaultIdx,
unNamedFaultWithInactiveIdx, unNamedFaultWithInactiveIdx,
unNamedFaultFaces, threadUnNamedFaultFaces,
unNamedFaultFacesInactive, threadUnNamedFaultFacesInactive,
m_faultsPrCellAcc.p() ); m_faultsPrCellAcc.p() );
} }
#pragma omp critical
{
unNamedFaultFaces.insert( unNamedFaultFaces.end(),
threadUnNamedFaultFaces.begin(),
threadUnNamedFaultFaces.end() );
unNamedFaultFacesInactive.insert( unNamedFaultFacesInactive.end(),
threadUnNamedFaultFacesInactive.begin(),
threadUnNamedFaultFacesInactive.end() );
}
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -480,6 +498,8 @@ void RigMainGrid::addUnNamedFaultFaces( int gcIdx,
return; return;
} }
const double tolerance = 1e-6;
size_t neighborReservoirCellIdx; size_t neighborReservoirCellIdx;
size_t neighborGridCellIdx; size_t neighborGridCellIdx;
size_t i = 0; size_t i = 0;
@ -490,7 +510,7 @@ void RigMainGrid::addUnNamedFaultFaces( int gcIdx,
bool firstNO_FAULTFaceForCell = true; bool firstNO_FAULTFaceForCell = true;
bool isCellActive = true; bool isCellActive = true;
char upperLimitForFaceType = cvf::StructGridInterface::FaceType::POS_K; const char upperLimitForFaceType = cvf::StructGridInterface::FaceType::POS_K;
// Compare only I and J faces // Compare only I and J faces
for ( char faceIdx = 0; faceIdx < upperLimitForFaceType; ++faceIdx ) for ( char faceIdx = 0; faceIdx < upperLimitForFaceType; ++faceIdx )
@ -513,21 +533,19 @@ void RigMainGrid::addUnNamedFaultFaces( int gcIdx,
firstNO_FAULTFaceForCell = false; firstNO_FAULTFaceForCell = false;
} }
if ( !hostGrid->cellIJKNeighbor( i, j, k, face, &neighborGridCellIdx ) ) hostGrid->cellIJKNeighborUnguarded( i, j, k, face, &neighborGridCellIdx );
{
continue;
}
neighborReservoirCellIdx = hostGrid->reservoirCellIndex( neighborGridCellIdx ); neighborReservoirCellIdx = hostGrid->reservoirCellIndex( neighborGridCellIdx );
if ( m_cells[neighborReservoirCellIdx].isInvalid() ) if ( neighborReservoirCellIdx >= m_cells.size() || m_cells[neighborReservoirCellIdx].isInvalid() )
{ {
continue; continue;
} }
// Add as fault face only if the grid index is less than the neighbors
if ( static_cast<size_t>( gcIdx ) < neighborReservoirCellIdx )
{
bool isNeighborCellActive = activeCellInfo->isActive( neighborReservoirCellIdx ); bool isNeighborCellActive = activeCellInfo->isActive( neighborReservoirCellIdx );
double tolerance = 1e-6;
std::array<size_t, 4> faceIdxs; std::array<size_t, 4> faceIdxs;
m_cells[gcIdx].faceIndices( face, &faceIdxs ); m_cells[gcIdx].faceIndices( face, &faceIdxs );
std::array<size_t, 4> nbFaceIdxs; std::array<size_t, 4> nbFaceIdxs;
@ -553,12 +571,13 @@ void RigMainGrid::addUnNamedFaultFaces( int gcIdx,
if ( !( isCellActive && isNeighborCellActive ) ) faultIdx = unNamedFaultWithInactiveIdx; if ( !( isCellActive && isNeighborCellActive ) ) faultIdx = unNamedFaultWithInactiveIdx;
faultsPrCellAcc->setFaultIdx( gcIdx, face, faultIdx ); faultsPrCellAcc->setFaultIdx( gcIdx, face, faultIdx );
faultsPrCellAcc->setFaultIdx( neighborReservoirCellIdx, StructGridInterface::oppositeFace( face ), faultIdx );
// Add as fault face only if the grid index is less than the neighbors #pragma omp critical
if ( static_cast<size_t>( gcIdx ) < neighborReservoirCellIdx )
{ {
faultsPrCellAcc->setFaultIdx( neighborReservoirCellIdx,
StructGridInterface::oppositeFace( face ),
faultIdx );
}
RigFault::FaultFace ff( gcIdx, cvf::StructGridInterface::FaceType( faceIdx ), neighborReservoirCellIdx ); RigFault::FaultFace ff( gcIdx, cvf::StructGridInterface::FaceType( faceIdx ), neighborReservoirCellIdx );
if ( isCellActive && isNeighborCellActive ) if ( isCellActive && isNeighborCellActive )
{ {
@ -569,15 +588,6 @@ void RigMainGrid::addUnNamedFaultFaces( int gcIdx,
unNamedFaultFacesInactive.push_back( ff ); unNamedFaultFacesInactive.push_back( ff );
} }
} }
else
{
CVF_FAIL_MSG( "Found fault with global neighbor index less than the native index. " ); // Should never
// occur. because
// we flag the
// opposite face
// in the
// faultsPrCellAcc
}
} }
} }
} }