Skip to content

Commit

Permalink
Use reservoirBuilder from mock builder
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Dec 16, 2023
1 parent 59ecfde commit 80c151b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 245 deletions.
4 changes: 2 additions & 2 deletions ApplicationLibCode/ReservoirDataModel/RigReservoirBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void RigReservoirBuilder::addLocalGridRefinement( const cvf::Vec3st& minCellPosi
void RigReservoirBuilder::populateReservoir( RigEclipseCaseData* eclipseCase )
{
std::vector<cvf::Vec3d>& mainGridNodes = eclipseCase->mainGrid()->nodes();
appendNodes( m_minWorldCoordinate, m_maxWorldCoordinate, cellDimension(), mainGridNodes );
appendNodes( m_minWorldCoordinate, m_maxWorldCoordinate, ijkCount(), mainGridNodes );
size_t mainGridNodeCount = mainGridNodes.size();
size_t mainGridCellCount = mainGridNodeCount / 8;

Expand Down Expand Up @@ -275,7 +275,7 @@ size_t RigReservoirBuilder::cellIndexFromIJK( size_t i, size_t j, size_t k ) con
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3st RigReservoirBuilder::cellDimension()
cvf::Vec3st RigReservoirBuilder::ijkCount() const
{
return cvf::Vec3st( m_gridPointDimensions.x() - 1, m_gridPointDimensions.y() - 1, m_gridPointDimensions.z() - 1 );
}
6 changes: 3 additions & 3 deletions ApplicationLibCode/ReservoirDataModel/RigReservoirBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class RigReservoirBuilder
RigReservoirBuilder();

void setWorldCoordinates( cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate );
void setIJKCount( const cvf::Vec3st& ijkCount );

void setIJKCount( const cvf::Vec3st& ijkCount );
cvf::Vec3st ijkCount() const;

void addLocalGridRefinement( const cvf::Vec3st& minCellPosition,
const cvf::Vec3st& maxCellPosition,
Expand All @@ -63,8 +65,6 @@ class RigReservoirBuilder

size_t cellIndexFromIJK( size_t i, size_t j, size_t k ) const;

cvf::Vec3st cellDimension();

private:
cvf::Vec3d m_minWorldCoordinate;
cvf::Vec3d m_maxWorldCoordinate;
Expand Down
226 changes: 16 additions & 210 deletions ApplicationLibCode/ReservoirDataModel/RigReservoirBuilderMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@
//--------------------------------------------------------------------------------------------------
RigReservoirBuilderMock::RigReservoirBuilderMock()
{
m_resultCount = 0;
m_timeStepCount = 0;
m_gridPointDimensions = cvf::Vec3st::ZERO;
m_enableWellData = true;
m_resultCount = 0;
m_timeStepCount = 0;
m_enableWellData = true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::setGridPointDimensions( const cvf::Vec3st& gridPointDimensions )
{
m_gridPointDimensions = gridPointDimensions;
m_reservoirBuilder.setIJKCount( { gridPointDimensions.x() - 1, gridPointDimensions.y() - 1, gridPointDimensions.z() - 1 } );
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -62,213 +61,19 @@ void RigReservoirBuilderMock::setResultInfo( size_t resultCount, size_t timeStep
m_timeStepCount = timeStepCount;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::appendNodes( const cvf::Vec3d& min,
const cvf::Vec3d& max,
const cvf::Vec3st& cubeDimension,
std::vector<cvf::Vec3d>& nodes )
{
double dx = ( max.x() - min.x() ) / static_cast<double>( cubeDimension.x() );
double dy = ( max.y() - min.y() ) / static_cast<double>( cubeDimension.y() );
double dz = ( max.z() - min.z() ) / static_cast<double>( cubeDimension.z() );

double zPos = min.z();

size_t k;
for ( k = 0; k < cubeDimension.z(); k++ )
{
double yPos = min.y();

size_t j;
for ( j = 0; j < cubeDimension.y(); j++ )
{
double xPos = min.x();

size_t i;
for ( i = 0; i < cubeDimension.x(); i++ )
{
cvf::Vec3d cornerA( xPos, yPos, zPos );
cvf::Vec3d cornerB( xPos + dx, yPos + dy, zPos + dz );

appendCubeNodes( cornerA, cornerB, nodes );

xPos += dx;
}

yPos += dy;
}

zPos += dz;
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::appendCubeNodes( const cvf::Vec3d& min, const cvf::Vec3d& max, std::vector<cvf::Vec3d>& nodes )
{
//
// 7---------6 Faces:
// /| /| |k 0 bottom 0, 3, 2, 1
// / | / | | /j 1 top 4, 5, 6, 7
// 4---------5 | |/ 2 front 0, 1, 5, 4
// | 3------|--2 *---i 3 right 1, 2, 6, 5
// | / | / 4 back 3, 7, 6, 2
// |/ |/ 5 left 0, 4, 7, 3
// 0---------1

cvf::Vec3d v0( min.x(), min.y(), min.z() );
cvf::Vec3d v1( max.x(), min.y(), min.z() );
cvf::Vec3d v2( max.x(), max.y(), min.z() );
cvf::Vec3d v3( min.x(), max.y(), min.z() );

cvf::Vec3d v4( min.x(), min.y(), max.z() );
cvf::Vec3d v5( max.x(), min.y(), max.z() );
cvf::Vec3d v6( max.x(), max.y(), max.z() );
cvf::Vec3d v7( min.x(), max.y(), max.z() );

nodes.push_back( v0 );
nodes.push_back( v1 );
nodes.push_back( v2 );
nodes.push_back( v3 );
nodes.push_back( v4 );
nodes.push_back( v5 );
nodes.push_back( v6 );
nodes.push_back( v7 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::appendCells( size_t nodeStartIndex, size_t cellCount, RigGridBase* hostGrid, std::vector<RigCell>& cells )
{
size_t cellIndexStart = cells.size();
cells.resize( cells.size() + cellCount );

#pragma omp parallel for
for ( long long i = 0; i < static_cast<long long>( cellCount ); i++ )
{
RigCell& riCell = cells[cellIndexStart + i];

riCell.setHostGrid( hostGrid );
riCell.setGridLocalCellIndex( i );

riCell.cornerIndices()[0] = nodeStartIndex + i * 8 + 0;
riCell.cornerIndices()[1] = nodeStartIndex + i * 8 + 1;
riCell.cornerIndices()[2] = nodeStartIndex + i * 8 + 2;
riCell.cornerIndices()[3] = nodeStartIndex + i * 8 + 3;
riCell.cornerIndices()[4] = nodeStartIndex + i * 8 + 4;
riCell.cornerIndices()[5] = nodeStartIndex + i * 8 + 5;
riCell.cornerIndices()[6] = nodeStartIndex + i * 8 + 6;
riCell.cornerIndices()[7] = nodeStartIndex + i * 8 + 7;

riCell.setParentCellIndex( 0 );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::populateReservoir( RigEclipseCaseData* eclipseCase )
{
std::vector<cvf::Vec3d>& mainGridNodes = eclipseCase->mainGrid()->nodes();
appendNodes( m_minWorldCoordinate, m_maxWorldCoordinate, cellDimension(), mainGridNodes );
size_t mainGridNodeCount = mainGridNodes.size();
size_t mainGridCellCount = mainGridNodeCount / 8;

// Must create cells in main grid here, as this information is used when creating LGRs
appendCells( 0, mainGridCellCount, eclipseCase->mainGrid(), eclipseCase->mainGrid()->globalCellArray() );

size_t totalCellCount = mainGridCellCount;

size_t lgrIdx;
for ( lgrIdx = 0; lgrIdx < m_localGridRefinements.size(); lgrIdx++ )
{
LocalGridRefinement& lgr = m_localGridRefinements[lgrIdx];

// Compute all global cell indices to be replaced by local grid refinement
std::vector<size_t> mainGridIndicesWithSubGrid;
{
size_t i;
for ( i = lgr.m_mainGridMinCellPosition.x(); i <= lgr.m_mainGridMaxCellPosition.x(); i++ )
{
size_t j;
for ( j = lgr.m_mainGridMinCellPosition.y(); j <= lgr.m_mainGridMaxCellPosition.y(); j++ )
{
size_t k;
for ( k = lgr.m_mainGridMinCellPosition.z(); k <= lgr.m_mainGridMaxCellPosition.z(); k++ )
{
mainGridIndicesWithSubGrid.push_back( cellIndexFromIJK( i, j, k ) );
}
}
}
}

// Create local grid and set local grid dimensions
RigLocalGrid* localGrid = new RigLocalGrid( eclipseCase->mainGrid() );
localGrid->setGridId( 1 );
localGrid->setGridName( "LGR_1" );
eclipseCase->mainGrid()->addLocalGrid( localGrid );
localGrid->setParentGrid( eclipseCase->mainGrid() );

localGrid->setIndexToStartOfCells( mainGridNodes.size() / 8 );
cvf::Vec3st gridPointDimensions( lgr.m_singleCellRefinementFactors.x() *
( lgr.m_mainGridMaxCellPosition.x() - lgr.m_mainGridMinCellPosition.x() + 1 ) +
1,
lgr.m_singleCellRefinementFactors.y() *
( lgr.m_mainGridMaxCellPosition.y() - lgr.m_mainGridMinCellPosition.y() + 1 ) +
1,
lgr.m_singleCellRefinementFactors.z() *
( lgr.m_mainGridMaxCellPosition.z() - lgr.m_mainGridMinCellPosition.z() + 1 ) +
1 );
localGrid->setGridPointDimensions( gridPointDimensions );

cvf::BoundingBox bb;
size_t cellIdx;
for ( cellIdx = 0; cellIdx < mainGridIndicesWithSubGrid.size(); cellIdx++ )
{
RigCell& cell = eclipseCase->mainGrid()->globalCellArray()[mainGridIndicesWithSubGrid[cellIdx]];

std::array<size_t, 8>& indices = cell.cornerIndices();
int nodeIdx;
for ( nodeIdx = 0; nodeIdx < 8; nodeIdx++ )
{
bb.add( eclipseCase->mainGrid()->nodes()[indices[nodeIdx]] );
}
// Deactivate cell in main grid
cell.setSubGrid( localGrid );
}

cvf::Vec3st lgrCellDimensions = gridPointDimensions - cvf::Vec3st( 1, 1, 1 );
appendNodes( bb.min(), bb.max(), lgrCellDimensions, mainGridNodes );

size_t subGridCellCount = ( mainGridNodes.size() / 8 ) - totalCellCount;
appendCells( totalCellCount * 8, subGridCellCount, localGrid, eclipseCase->mainGrid()->globalCellArray() );
totalCellCount += subGridCellCount;
}

eclipseCase->mainGrid()->setGridPointDimensions( m_gridPointDimensions );
m_reservoirBuilder.populateReservoir( eclipseCase );

if ( m_enableWellData )
{
addWellData( eclipseCase, eclipseCase->mainGrid() );
}

// addFaults( eclipseCase );

// Set all cells active
RigActiveCellInfo* activeCellInfo = eclipseCase->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL );
activeCellInfo->setReservoirCellCount( eclipseCase->mainGrid()->globalCellArray().size() );
for ( size_t i = 0; i < eclipseCase->mainGrid()->globalCellArray().size(); i++ )
{
activeCellInfo->setCellResultIndex( i, i );
}

activeCellInfo->setGridCount( 1 );
activeCellInfo->setGridActiveCellCounts( 0, eclipseCase->mainGrid()->globalCellArray().size() );
activeCellInfo->computeDerivedData();
addFaults( eclipseCase );

// Add grid coarsening for main grid
// if ( cellDimension().x() > 4 && cellDimension().y() > 5 && cellDimension().z() > 6 )
Expand All @@ -285,16 +90,15 @@ void RigReservoirBuilderMock::addLocalGridRefinement( const cvf::Vec3st& mainGri
const cvf::Vec3st& mainGridEnd,
const cvf::Vec3st& refinementFactors )
{
m_localGridRefinements.push_back( LocalGridRefinement( mainGridStart, mainGridEnd, refinementFactors ) );
m_reservoirBuilder.addLocalGridRefinement( mainGridStart, mainGridEnd, refinementFactors );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::setWorldCoordinates( cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate )
{
m_minWorldCoordinate = minWorldCoordinate;
m_maxWorldCoordinate = maxWorldCoordinate;
m_reservoirBuilder.setWorldCoordinates( minWorldCoordinate, maxWorldCoordinate );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -500,23 +304,25 @@ void RigReservoirBuilderMock::addFaults( RigEclipseCaseData* eclipseCase )

cvf::Collection<RigFault> faults;

auto cellDimension = m_reservoirBuilder.ijkCount();

{
cvf::ref<RigFault> fault = new RigFault;
fault->setName( "Fault A" );

cvf::Vec3st min = cvf::Vec3st::ZERO;
cvf::Vec3st max( 0, 0, cellDimension().z() - 2 );
cvf::Vec3st max( 0, 0, cellDimension.z() - 2 );

if ( cellDimension().x() > 5 )
if ( cellDimension.x() > 5 )
{
min.x() = cellDimension().x() / 2;
min.x() = cellDimension.x() / 2;
max.x() = min.x() + 2;
}

if ( cellDimension().y() > 5 )
if ( cellDimension.y() > 5 )
{
min.y() = cellDimension().y() / 2;
max.y() = cellDimension().y() / 2;
min.y() = cellDimension.y() / 2;
max.y() = cellDimension.y() / 2;
}

cvf::CellRange cellRange( min, max );
Expand Down
37 changes: 7 additions & 30 deletions ApplicationLibCode/ReservoirDataModel/RigReservoirBuilderMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ class RigReservoirBuilderMock
void setResultInfo( size_t resultCount, size_t timeStepCount );
void enableWellData( bool enableWellData );

size_t resultCount() const { return m_resultCount; }
size_t timeStepCount() const { return m_timeStepCount; }
cvf::Vec3st gridPointDimensions() const { return m_gridPointDimensions; }
size_t resultCount() const { return m_resultCount; }
size_t timeStepCount() const { return m_timeStepCount; }

void addLocalGridRefinement( const cvf::Vec3st& minCellPosition,
const cvf::Vec3st& maxCellPosition,
Expand All @@ -63,34 +62,12 @@ class RigReservoirBuilderMock

static void
addNnc( RigMainGrid* grid, size_t i1, size_t j1, size_t k1, size_t i2, size_t j2, size_t k2, RigConnectionContainer& nncConnections );
void addWellData( RigEclipseCaseData* eclipseCase, RigGridBase* grid );
static void appendCells( size_t nodeStartIndex, size_t cellCount, RigGridBase* hostGrid, std::vector<RigCell>& cells );

static void appendNodes( const cvf::Vec3d& min, const cvf::Vec3d& max, const cvf::Vec3st& cubeDimension, std::vector<cvf::Vec3d>& nodes );
static void appendCubeNodes( const cvf::Vec3d& min, const cvf::Vec3d& max, std::vector<cvf::Vec3d>& nodes );

size_t cellIndexFromIJK( size_t i, size_t j, size_t k ) const
{
CVF_TIGHT_ASSERT( i < ( m_gridPointDimensions.x() - 1 ) );
CVF_TIGHT_ASSERT( j < ( m_gridPointDimensions.y() - 1 ) );
CVF_TIGHT_ASSERT( k < ( m_gridPointDimensions.z() - 1 ) );

size_t ci = i + j * ( m_gridPointDimensions.x() - 1 ) + k * ( ( m_gridPointDimensions.x() - 1 ) * ( m_gridPointDimensions.y() - 1 ) );
return ci;
}

cvf::Vec3st cellDimension()
{
return cvf::Vec3st( m_gridPointDimensions.x() - 1, m_gridPointDimensions.y() - 1, m_gridPointDimensions.z() - 1 );
}
void addWellData( RigEclipseCaseData* eclipseCase, RigGridBase* grid );

private:
cvf::Vec3d m_minWorldCoordinate;
cvf::Vec3d m_maxWorldCoordinate;
cvf::Vec3st m_gridPointDimensions;
size_t m_resultCount;
size_t m_timeStepCount;
bool m_enableWellData;
size_t m_resultCount;
size_t m_timeStepCount;
bool m_enableWellData;

std::vector<LocalGridRefinement> m_localGridRefinements;
RigReservoirBuilder m_reservoirBuilder;
};

0 comments on commit 80c151b

Please sign in to comment.