Example #1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RigGridBase::isCellValid(size_t i, size_t j, size_t k) const
{
    if (i >= cellCountI() || j >= cellCountJ() || k >= cellCountK())
    {
        return false;
    }

    size_t idx = cellIndexFromIJK(i, j, k);
    const RigCell& c = cell(idx);
    return !c.isInvalid();
}
Example #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RigGridBase::cellIJKNeighbor(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);

    if (!isCellValid(ni, nj, nk))
    {
        return false;
    }

    if (neighborCellIndex)
    {
        *neighborCellIndex = cellIndexFromIJK(ni, nj, nk);
    }

    return true;
}
Example #3
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);
        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]];
            
            caf::SizeTArray8& 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);

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

    addFaults(eclipseCase);

    // Set all cells active
    RigActiveCellInfo* activeCellInfo = eclipseCase->activeCellInfo(RiaDefines::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();

    // Add grid coarsening for main grid
    if (cellDimension().x() > 4 &&
        cellDimension().y() > 5 &&
        cellDimension().z() > 6)
    {
        eclipseCase->mainGrid()->addCoarseningBox(1, 2, 1, 3, 1, 4);
        eclipseCase->mainGrid()->addCoarseningBox(3, 4, 4, 5, 5, 6);
    }
}
Example #4
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void StructGridInterface::characteristicCellSizes(double* iSize, double* jSize, double* kSize)
{
    CVF_ASSERT(iSize && jSize && kSize);

    if (m_characteristicCellSizeI == cvf::UNDEFINED_DOUBLE
        || m_characteristicCellSizeJ == cvf::UNDEFINED_DOUBLE
        || m_characteristicCellSizeK == cvf::UNDEFINED_DOUBLE)
    {

        ubyte faceConnPosI[4];
        cellFaceVertexIndices(StructGridInterface::POS_I, faceConnPosI);

        ubyte faceConnNegI[4];
        cellFaceVertexIndices(StructGridInterface::NEG_I, faceConnNegI);
        
        ubyte faceConnPosJ[4];
        cellFaceVertexIndices(StructGridInterface::POS_J, faceConnPosJ);

        ubyte faceConnNegJ[4];
        cellFaceVertexIndices(StructGridInterface::NEG_J, faceConnNegJ);

        ubyte faceConnPosK[4];
        cellFaceVertexIndices(StructGridInterface::POS_K, faceConnPosK);

        ubyte faceConnNegK[4];
        cellFaceVertexIndices(StructGridInterface::NEG_K, faceConnNegK);

        double iSize = 0.0;
        double jSize = 0.0;
        double kSize = 0.0;

        cvf::Vec3d cornerVerts[8];
        size_t cellCount = 0;

        size_t k;
        for (k = 0; k < cellCountK(); k++)
        {
            size_t j;
            for (j = 0; j < cellCountJ(); j++)
            {
                size_t i;
                for (i = 0; i < cellCountI(); i += 10)  // NB! Evaluate every n-th cell
                {
                    if (isCellValid(i, j, k))
                    {
                        size_t cellIndex = cellIndexFromIJK(i, j, k);
                        cellCornerVertices(cellIndex, cornerVerts);

                        iSize += (cornerVerts[faceConnPosI[0]] - cornerVerts[faceConnNegI[0]]).lengthSquared();
                        iSize += (cornerVerts[faceConnPosI[1]] - cornerVerts[faceConnNegI[3]]).lengthSquared();
                        iSize += (cornerVerts[faceConnPosI[2]] - cornerVerts[faceConnNegI[2]]).lengthSquared();
                        iSize += (cornerVerts[faceConnPosI[3]] - cornerVerts[faceConnNegI[1]]).lengthSquared();

                        jSize += (cornerVerts[faceConnPosJ[0]] - cornerVerts[faceConnNegJ[0]]).lengthSquared();
                        jSize += (cornerVerts[faceConnPosJ[1]] - cornerVerts[faceConnNegJ[3]]).lengthSquared();
                        jSize += (cornerVerts[faceConnPosJ[2]] - cornerVerts[faceConnNegJ[2]]).lengthSquared();
                        jSize += (cornerVerts[faceConnPosJ[3]] - cornerVerts[faceConnNegJ[1]]).lengthSquared();

                        kSize += (cornerVerts[faceConnPosK[0]] - cornerVerts[faceConnNegK[0]]).lengthSquared();
                        kSize += (cornerVerts[faceConnPosK[1]] - cornerVerts[faceConnNegK[3]]).lengthSquared();
                        kSize += (cornerVerts[faceConnPosK[2]] - cornerVerts[faceConnNegK[2]]).lengthSquared();
                        kSize += (cornerVerts[faceConnPosK[3]] - cornerVerts[faceConnNegK[1]]).lengthSquared();

                        cellCount++;
                    }
                }
            }
        }

        double divisor = cellCount * 4.0;

        if (divisor > 0.0)
        {
            m_characteristicCellSizeI = cvf::Math::sqrt(iSize / divisor);
            m_characteristicCellSizeJ = cvf::Math::sqrt(jSize / divisor);
            m_characteristicCellSizeK = cvf::Math::sqrt(kSize / divisor);
        }
    }

    *iSize = m_characteristicCellSizeI;
    *jSize = m_characteristicCellSizeJ;
    *kSize = m_characteristicCellSizeK;
}