Refactor: Use VecIjk0 instead of Vec3st.

This commit is contained in:
Kristian Bendiksen committed 2025-11-17 13:04:13 +01:00
1 parent 7e299c4841
commit 5a7e987034
17 files changed
+273 -243

No files matched your search

@@ -24,6 +24,7 @@
#include "Well/RigSimWellData.h"
#include "Well/RigSimulationWellCenterLineCalculator.h"
#include "cafVecIjk.h"
#include "cvfBoundingBox.h"
#include "cvfObject.h"
@@ -86,21 +87,21 @@ cvf::BoundingBox RigEclipseCaseDataTools::wellBoundingBoxInDomainCoords( RigEcli
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::wellBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const RigSimWellData* simWellData,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe )
std::pair<caf::VecIjk0, caf::VecIjk0> RigEclipseCaseDataTools::wellBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const RigSimWellData* simWellData,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe )
{
if ( !eclipseCaseData || !simWellData ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( !eclipseCaseData || !simWellData ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
cvf::BoundingBox domainBB =
wellBoundingBoxInDomainCoords( eclipseCaseData, simWellData, timeStepIndex, isAutoDetectingBranches, isUsingCellCenterForPipe );
if ( !domainBB.isValid() ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( !domainBB.isValid() ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
auto mainGrid = eclipseCaseData->mainGrid();
if ( !mainGrid ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( !mainGrid ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
// Convert domain bounding box min/max to cell indices
cvf::Vec3d minPoint = domainBB.min();
@@ -110,20 +111,19 @@ std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::wellBoundingBoxIjk(
size_t maxCellIndex = mainGrid->findReservoirCellIndexFromPoint( maxPoint );
if ( minCellIndex == cvf::UNDEFINED_SIZE_T || maxCellIndex == cvf::UNDEFINED_SIZE_T )
return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
// Convert cell indices to IJK coordinates
auto ijkFromCellIndex = []( RigMainGrid* mainGrid, size_t index )
auto ijkFromCellIndex = []( RigMainGrid* mainGrid, size_t index ) -> caf::VecIjk0
{
if ( auto ijkOpt = mainGrid->ijkFromCellIndex( index ); ijkOpt.has_value() )
return cvf::Vec3st( ijkOpt->i(), ijkOpt->j(), ijkOpt->k() );
return cvf::Vec3st::UNDEFINED;
if ( auto ijkOpt = mainGrid->ijkFromCellIndex( index ); ijkOpt.has_value() ) return ijkOpt.value();
return caf::VecIjk0::UNDEFINED;
};
cvf::Vec3st minIjk = ijkFromCellIndex( mainGrid, minCellIndex );
cvf::Vec3st maxIjk = ijkFromCellIndex( mainGrid, maxCellIndex );
caf::VecIjk0 minIjk = ijkFromCellIndex( mainGrid, minCellIndex );
caf::VecIjk0 maxIjk = ijkFromCellIndex( mainGrid, maxCellIndex );
if ( minIjk.isUndefined() || maxIjk.isUndefined() ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( minIjk.isUndefined() || maxIjk.isUndefined() ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
if ( minIjk.x() > maxIjk.x() || minIjk.y() > maxIjk.y() || minIjk.z() > maxIjk.z() )
{
@@ -136,16 +136,16 @@ std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::wellBoundingBoxIjk(
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::wellsBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const std::vector<const RigSimWellData*>& simWells,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe )
std::pair<caf::VecIjk0, caf::VecIjk0> RigEclipseCaseDataTools::wellsBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const std::vector<const RigSimWellData*>& simWells,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe )
{
if ( !eclipseCaseData || simWells.empty() ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( !eclipseCaseData || simWells.empty() ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
cvf::Vec3st globalMin = cvf::Vec3st::UNDEFINED;
cvf::Vec3st globalMax = cvf::Vec3st::UNDEFINED;
caf::VecIjk0 globalMin = caf::VecIjk0::UNDEFINED;
caf::VecIjk0 globalMax = caf::VecIjk0::UNDEFINED;
for ( const auto& well : simWells )
{
@@ -179,15 +179,15 @@ std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::wellsBoundingBoxIjk
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::expandBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const cvf::Vec3st& minIjk,
const cvf::Vec3st& maxIjk,
size_t numPadding )
std::pair<caf::VecIjk0, caf::VecIjk0> RigEclipseCaseDataTools::expandBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const caf::VecIjk0& minIjk,
const caf::VecIjk0& maxIjk,
size_t numPadding )
{
if ( !eclipseCaseData || minIjk.isUndefined() || maxIjk.isUndefined() ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( !eclipseCaseData || minIjk.isUndefined() || maxIjk.isUndefined() ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
auto mainGrid = eclipseCaseData->mainGrid();
if ( !mainGrid ) return { cvf::Vec3st::UNDEFINED, cvf::Vec3st::UNDEFINED };
if ( !mainGrid ) return { caf::VecIjk0::UNDEFINED, caf::VecIjk0::UNDEFINED };
// Calculate expanded bounds with padding, ensuring we stay within grid bounds
size_t expandedMinI = ( minIjk.x() >= numPadding ) ? ( minIjk.x() - numPadding ) : 0;
@@ -198,15 +198,15 @@ std::pair<cvf::Vec3st, cvf::Vec3st> RigEclipseCaseDataTools::expandBoundingBoxIj
size_t expandedMaxJ = std::min( maxIjk.y() + numPadding, mainGrid->cellCountJ() - 1 );
size_t expandedMaxK = std::min( maxIjk.z() + numPadding, mainGrid->cellCountK() - 1 );
return { cvf::Vec3st( expandedMinI, expandedMinJ, expandedMinK ), cvf::Vec3st( expandedMaxI, expandedMaxJ, expandedMaxK ) };
return { caf::VecIjk0( expandedMinI, expandedMinJ, expandedMinK ), caf::VecIjk0( expandedMaxI, expandedMaxJ, expandedMaxK ) };
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::UByteArray> RigEclipseCaseDataTools::createVisibilityFromIjkBounds( RigEclipseCaseData* eclipseCaseData,
const cvf::Vec3st& minIjk,
const cvf::Vec3st& maxIjk )
const caf::VecIjk0& minIjk,
const caf::VecIjk0& maxIjk )
{
if ( !eclipseCaseData || minIjk.isUndefined() || maxIjk.isUndefined() ) return nullptr;
@@ -20,6 +20,7 @@
#include "QString"
#include "cafVecIjk.h"
#include "cvfBoundingBox.h"
#include "cvfObject.h"
#include "cvfVector3.h"
@@ -43,21 +44,21 @@ public:
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe );
static std::pair<cvf::Vec3st, cvf::Vec3st> wellBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const RigSimWellData* simWellData,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe );
static std::pair<caf::VecIjk0, caf::VecIjk0> wellBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const RigSimWellData* simWellData,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe );
static std::pair<cvf::Vec3st, cvf::Vec3st> wellsBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const std::vector<const RigSimWellData*>& simWells,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe );
static std::pair<caf::VecIjk0, caf::VecIjk0> wellsBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData,
const std::vector<const RigSimWellData*>& simWells,
int timeStepIndex,
bool isAutoDetectingBranches,
bool isUsingCellCenterForPipe );
static std::pair<cvf::Vec3st, cvf::Vec3st>
expandBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData, const cvf::Vec3st& minIjk, const cvf::Vec3st& maxIjk, size_t numPadding );
static std::pair<caf::VecIjk0, caf::VecIjk0>
expandBoundingBoxIjk( RigEclipseCaseData* eclipseCaseData, const caf::VecIjk0& minIjk, const caf::VecIjk0& maxIjk, size_t numPadding );
static cvf::ref<cvf::UByteArray>
createVisibilityFromIjkBounds( RigEclipseCaseData* eclipseCaseData, const cvf::Vec3st& minIjk, const cvf::Vec3st& maxIjk );
createVisibilityFromIjkBounds( RigEclipseCaseData* eclipseCaseData, const caf::VecIjk0& minIjk, const caf::VecIjk0& maxIjk );
};
@@ -34,6 +34,8 @@
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "cafVecIjk.h"
namespace RigEclipseResultTools
{
namespace
@@ -260,7 +262,7 @@ int findMaxBcconValue( RimEclipseCase* eclipseCase )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void generateBcconResult( RimEclipseCase* eclipseCase, const cvf::Vec3st& min, const cvf::Vec3st& max )
void generateBcconResult( RimEclipseCase* eclipseCase, const caf::VecIjk0& min, const caf::VecIjk0& max )
{
if ( eclipseCase == nullptr ) return;
@@ -378,38 +380,39 @@ std::vector<BorderCellFace> generateBorderCellFaces( RimEclipseCase* eclipseCase
if ( borderValue != BorderType::BORDER_CELL ) continue;
// Get IJK indices for this cell
size_t i, j, k;
if ( !grid->ijkFromCellIndex( activeCellIdx.value(), &i, &j, &k ) ) continue;
// Check all 6 faces
std::vector<cvf::StructGridInterface::FaceType> faces = cvf::StructGridInterface::validFaceTypes();
for ( auto faceType : faces )
if ( auto ijk = grid->ijkFromCellIndex( activeCellIdx.value() ) )
{
// Get neighbor cell IJK
size_t ni, nj, nk;
cvf::StructGridInterface::neighborIJKAtCellFace( i, j, k, faceType, &ni, &nj, &nk );
// Check all 6 faces
std::vector<cvf::StructGridInterface::FaceType> faces = cvf::StructGridInterface::validFaceTypes();
// Check if neighbor is within bounds
if ( ni >= grid->cellCountI() || nj >= grid->cellCountJ() || nk >= grid->cellCountK() ) continue;
// Get neighbor reservoir cell index
size_t neighborReservoirIdx = grid->cellIndexFromIJK( ni, nj, nk );
// Find active cell index for neighbor
auto it = std::find( activeReservoirCellIdxs.begin(), activeReservoirCellIdxs.end(), ReservoirCellIndex( neighborReservoirIdx ) );
if ( it == activeReservoirCellIdxs.end() ) continue; // Neighbor not active
// Check if neighbor is an interior cell
int neighborBorderValue = static_cast<int>( bordNumValues[neighborReservoirIdx] );
if ( neighborBorderValue == BorderType::INTERIOR_CELL )
for ( auto faceType : faces )
{
// Get boundary condition value from BCCON grid property
int boundaryCondition = static_cast<int>( bcconValues[activeCellIdx.value()] );
if ( boundaryCondition > 0 )
// Get neighbor cell IJK
size_t ni, nj, nk;
cvf::StructGridInterface::neighborIJKAtCellFace( ijk->i(), ijk->j(), ijk->k(), faceType, &ni, &nj, &nk );
// Check if neighbor is within bounds
if ( ni >= grid->cellCountI() || nj >= grid->cellCountJ() || nk >= grid->cellCountK() ) continue;
// Get neighbor reservoir cell index
size_t neighborReservoirIdx = grid->cellIndexFromIJK( ni, nj, nk );
// Find active cell index for neighbor
auto it =
std::find( activeReservoirCellIdxs.begin(), activeReservoirCellIdxs.end(), ReservoirCellIndex( neighborReservoirIdx ) );
if ( it == activeReservoirCellIdxs.end() ) continue; // Neighbor not active
// Check if neighbor is an interior cell
int neighborBorderValue = static_cast<int>( bordNumValues[neighborReservoirIdx] );
if ( neighborBorderValue == BorderType::INTERIOR_CELL )
{
// Add this face to the result
borderCellFaces.push_back( { cvf::Vec3st( i, j, k ), faceType, boundaryCondition } );
// Get boundary condition value from BCCON grid property
int boundaryCondition = static_cast<int>( bcconValues[activeCellIdx.value()] );
if ( boundaryCondition > 0 )
{
// Add this face to the result
borderCellFaces.push_back( { *ijk, faceType, boundaryCondition } );
}
}
}
}
@@ -21,6 +21,7 @@
#include <QString>
#include <vector>
#include "cafVecIjk.h"
#include "cvfArray.h"
#include "cvfStructGrid.h"
@@ -38,7 +39,7 @@ enum BorderType : int
struct BorderCellFace
{
cvf::Vec3st ijk; // Cell indices (0-based)
caf::VecIjk0 ijk; // Cell indices (0-based)
cvf::StructGridInterface::FaceType faceType;
int boundaryCondition; // BCCON grid value
};
@@ -53,7 +54,7 @@ int findMaxOperNumValue( RimEclipseCase* eclipseCase );
int findMaxBcconValue( RimEclipseCase* eclipseCase );
void generateBcconResult( RimEclipseCase* eclipseCase, const cvf::Vec3st& min, const cvf::Vec3st& max );
void generateBcconResult( RimEclipseCase* eclipseCase, const caf::VecIjk0& min, const caf::VecIjk0& max );
std::vector<BorderCellFace> generateBorderCellFaces( RimEclipseCase* eclipseCase );
@@ -26,6 +26,7 @@
#include "RigEclipseCaseData.h"
#include "RigMainGrid.h"
#include "cafVecIjk.h"
#include "cvfAssert.h"
#include "cvfStructGrid.h"
@@ -422,10 +423,10 @@ size_t RigGridExportAdapter::totalCells() const
/// Transform IJK coordinates from global grid space to sector-relative space with refinement
/// Returns 1-based Eclipse coordinates
//--------------------------------------------------------------------------------------------------
std::expected<cvf::Vec3st, QString> RigGridExportAdapter::transformIjkToSectorCoordinates( const cvf::Vec3st& originalIjk,
const cvf::Vec3st& min,
const cvf::Vec3st& max,
const cvf::Vec3st& refinement )
std::expected<caf::VecIjk1, QString> RigGridExportAdapter::transformIjkToSectorCoordinates( const caf::VecIjk0& originalIjk,
const caf::VecIjk0& min,
const caf::VecIjk0& max,
const cvf::Vec3st& refinement )
{
// Check if original IJK is within the sector bounds
if ( originalIjk.x() < min.x() || originalIjk.x() > max.x() || originalIjk.y() < min.y() || originalIjk.y() > max.y() ||
@@ -445,10 +446,9 @@ std::expected<cvf::Vec3st, QString> RigGridExportAdapter::transformIjkToSectorCo
// Transform to sector-relative coordinates with refinement
// Eclipse uses 1-based indexing, so we'll return 1-based coordinates
cvf::Vec3st sectorIjk;
sectorIjk.x() = ( originalIjk.x() - min.x() ) * refinement.x() + 1;
sectorIjk.y() = ( originalIjk.y() - min.y() ) * refinement.y() + 1;
sectorIjk.z() = ( originalIjk.z() - min.z() ) * refinement.z() + 1;
size_t sectorI = ( originalIjk.x() - min.x() ) * refinement.x() + 1;
size_t sectorJ = ( originalIjk.y() - min.y() ) * refinement.y() + 1;
size_t sectorK = ( originalIjk.z() - min.z() ) * refinement.z() + 1;
return sectorIjk;
return caf::VecIjk1( sectorI, sectorJ, sectorK );
}
@@ -18,6 +18,8 @@
#pragma once
#include "cafVecIjk.h"
#include "cvfArray.h"
#include "cvfMatrix4.h"
#include "cvfStructGrid.h"
@@ -87,10 +89,10 @@ public:
bool hasRefinement() const;
// Coordinate transformation utilities
static std::expected<cvf::Vec3st, QString> transformIjkToSectorCoordinates( const cvf::Vec3st& originalIjk,
const cvf::Vec3st& min,
const cvf::Vec3st& max,
const cvf::Vec3st& refinement );
static std::expected<caf::VecIjk1, QString> transformIjkToSectorCoordinates( const caf::VecIjk0& originalIjk,
const caf::VecIjk0& min,
const caf::VecIjk0& max,
const cvf::Vec3st& refinement );
private:
// Internal methods to handle original vs refined cell access