mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
Migrate all assert macros in ApplicationLibCode to CAF_ASSERT and remove every use of cvfAssert.h. CVF_ASSERT is replaced one to one. CVF_TIGHT_ASSERT is also replaced by CAF_ASSERT, which is semantically exact: CVF_ENABLE_TIGHT_ASSERTS is 1 only under _DEBUG, and that is what CAF_ASSERT now does. The two CVF_FAIL_MSG sites become CAF_ASSERT( false && "message" ), preserving the message with the idiom already used elsewhere in the code base. Counts before and after: CVF_ASSERT 1044 to 0, CVF_TIGHT_ASSERT 66 to 0, CVF_FAIL_MSG 2 to 0, cvfAssert.h references 154 to 0. Include handling: files that included cvfAssert.h directly now include cafAssert.h instead, includes left dead by the migration are removed, and files that were relying on cvfAssert.h transitively get an explicit cafAssert.h. Files that reach cafAssert.h through another caf header are left unchanged; a missing include here is a compile error, not a silently disabled assert. ResultStatisticsCache links only LibCore and therefore had no path to cafAssert.h. Add the cafPdmCore directory as a private include path rather than linking the library, since cafAssert.h is header only. Note that this stops these asserts from firing in Release and RelWithDebInfo, where CVF_ASSERT was previously active.
261 lines
9.7 KiB
C++
261 lines
9.7 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) Statoil ASA
|
|
// Copyright (C) Ceetron Solutions AS
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RigFault.h"
|
|
|
|
#include "RigMainGrid.h"
|
|
|
|
#include "cafAssert.h"
|
|
|
|
cvf::ref<RigFaultsPrCellAccumulator> RigFault::m_faultsPrCellAcc;
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RigFault::RigFault()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RigFault::addCellRangeForFace( cvf::StructGridInterface::FaceType face, const cvf::CellRange& cellRange )
|
|
{
|
|
size_t faceIndex = static_cast<size_t>( face );
|
|
CAF_ASSERT( faceIndex < 6 );
|
|
|
|
m_cellRangesForFaces[faceIndex].push_back( cellRange );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RigFault::setName( const QString& name )
|
|
{
|
|
m_name = name;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString RigFault::name() const
|
|
{
|
|
return m_name;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RigFault::FaultFace>& RigFault::faultFaces()
|
|
{
|
|
return m_faultFaces;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
const std::vector<RigFault::FaultFace>& RigFault::faultFaces() const
|
|
{
|
|
return m_faultFaces;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<size_t>& RigFault::connectionIndices()
|
|
{
|
|
return m_connectionIndices;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
const std::vector<size_t>& RigFault::connectionIndices() const
|
|
{
|
|
return m_connectionIndices;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
/// Order FaultCellAndFace by i, j, face then k.
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RigFault::ordering( CellAndFace first, CellAndFace second )
|
|
{
|
|
size_t i1, i2, j1, j2, k1, k2;
|
|
cvf::StructGridInterface::FaceType f1, f2;
|
|
std::tie( i1, j1, k1, f1 ) = first;
|
|
std::tie( i2, j2, k2, f2 ) = second;
|
|
if ( i1 == i2 )
|
|
{
|
|
if ( j1 == j2 )
|
|
{
|
|
if ( f1 == f2 )
|
|
{
|
|
return k1 < k2;
|
|
}
|
|
else
|
|
{
|
|
return f1 < f2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return j1 < j2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return i1 < i2;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RigFault::computeFaultFacesFromCellRanges( const RigMainGrid* mainGrid )
|
|
{
|
|
if ( !mainGrid ) return;
|
|
|
|
m_faultFaces.clear();
|
|
|
|
for ( size_t faceType = 0; faceType < 6; faceType++ )
|
|
{
|
|
cvf::StructGridInterface::FaceType faceEnum = cvf::StructGridInterface::FaceType( faceType );
|
|
|
|
const std::vector<cvf::CellRange>& cellRanges = m_cellRangesForFaces[faceType];
|
|
|
|
for ( const cvf::CellRange& cellRange : cellRanges )
|
|
{
|
|
cvf::Vec3st min, max;
|
|
cellRange.range( min, max );
|
|
|
|
for ( size_t i = min.x(); i <= max.x(); i++ )
|
|
{
|
|
if ( i >= mainGrid->cellCountI() )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
for ( size_t j = min.y(); j <= max.y(); j++ )
|
|
{
|
|
if ( j >= mainGrid->cellCountJ() )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
for ( size_t k = min.z(); k <= max.z(); k++ )
|
|
{
|
|
if ( k >= mainGrid->cellCountK() )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Do not need to compute global grid cell index as for a maingrid localIndex == globalIndex
|
|
// size_t reservoirCellIndex = grid->reservoirCellIndex(gridLocalCellIndex);
|
|
|
|
size_t ni, nj, nk;
|
|
RigMainGrid::neighborIJKAtCellFace( i, j, k, faceEnum, &ni, &nj, &nk );
|
|
if ( ni < mainGrid->cellCountI() && nj < mainGrid->cellCountJ() && nk < mainGrid->cellCountK() )
|
|
{
|
|
size_t gridLocalCellIndex = mainGrid->cellIndexFromIJK( i, j, k );
|
|
size_t oppositeCellIndex = mainGrid->cellIndexFromIJK( ni, nj, nk );
|
|
|
|
m_faultFaces.push_back( FaultFace( gridLocalCellIndex, faceEnum, oppositeCellIndex ) );
|
|
}
|
|
else
|
|
{
|
|
// cvf::Trace::show("Warning: Undefined Fault neighbor detected.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RigFault::accumulateFaultsPrCell( RigFaultsPrCellAccumulator* faultsPrCellAcc, int faultIdx )
|
|
{
|
|
for ( const FaultFace& ff : m_faultFaces )
|
|
{
|
|
// Could detect overlapping faults here .... if (faultsPrCellAcc->faultIdx(ff.m_nativeReservoirCellIndex,
|
|
// ff.m_nativeFace)
|
|
// >= 0)
|
|
|
|
faultsPrCellAcc->setFaultIdx( ff.m_nativeReservoirCellIndex, ff.m_nativeFace, faultIdx );
|
|
faultsPrCellAcc->setFaultIdx( ff.m_oppositeReservoirCellIndex, cvf::StructGridInterface::oppositeFace( ff.m_nativeFace ), faultIdx );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RigFaultsPrCellAccumulator::RigFaultsPrCellAccumulator( size_t reservoirCellCount )
|
|
{
|
|
std::array<int, 6> initVals = { NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT };
|
|
m_faultIdxForCellFace.resize( reservoirCellCount, initVals );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
int RigFaultsPrCellAccumulator::faultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const
|
|
{
|
|
// Ensure no crash after creating temporary LGRs
|
|
if ( reservoirCellIndex < m_faultIdxForCellFace.size() )
|
|
{
|
|
return m_faultIdxForCellFace[reservoirCellIndex][face];
|
|
}
|
|
return NO_FAULT;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RigFaultsPrCellAccumulator::setFaultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face, int faultIdx )
|
|
{
|
|
m_faultIdxForCellFace[reservoirCellIndex][face] = faultIdx;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::pair<double, cvf::StructGridInterface::FaceType> RigFault::minimumDistanceToPoint( const cvf::Vec3d& point, const RigMainGrid* mainGrid ) const
|
|
{
|
|
double minDistance = std::numeric_limits<double>::max();
|
|
cvf::StructGridInterface::FaceType minFace = cvf::StructGridInterface::NO_FACE;
|
|
for ( const FaultFace& ff : m_faultFaces )
|
|
{
|
|
const RigCell& cell = mainGrid->cell( ff.m_nativeReservoirCellIndex );
|
|
if ( cell.isInvalid() ) continue;
|
|
|
|
for ( auto& c : cell.faceCorners( ff.m_nativeFace ) )
|
|
{
|
|
double distance = ( c - point ).length();
|
|
if ( distance < minDistance )
|
|
{
|
|
minDistance = distance;
|
|
minFace = ff.m_nativeFace;
|
|
}
|
|
}
|
|
}
|
|
return std::make_pair( minDistance, minFace );
|
|
}
|