//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
RivTernaryTextureCoordsCreator::RivTernaryTextureCoordsCreator(
    RimEclipseCellColors* cellResultColors, 
    RimTernaryLegendConfig* ternaryLegendConfig,
    size_t timeStepIndex, 
    size_t gridIndex, 
    const cvf::StructGridQuadToCellFaceMapper* quadMapper)
{
    CVF_ASSERT(quadMapper);
    m_quadMapper = quadMapper;

    RigEclipseCaseData* eclipseCase = cellResultColors->reservoirView()->eclipseCase()->eclipseCaseData();

    size_t resTimeStepIdx = timeStepIndex;

    if (cellResultColors->hasStaticResult()) resTimeStepIdx = 0;

    RiaDefines::PorosityModelType porosityModel = cellResultColors->porosityModel();

    cvf::ref<RigResultAccessor> soil = RigResultAccessorFactory::createFromResultAddress(eclipseCase, gridIndex, porosityModel, resTimeStepIdx, RigEclipseResultAddress("SOIL"));
    cvf::ref<RigResultAccessor> sgas = RigResultAccessorFactory::createFromResultAddress(eclipseCase, gridIndex, porosityModel, resTimeStepIdx, RigEclipseResultAddress("SGAS"));
    cvf::ref<RigResultAccessor> swat = RigResultAccessorFactory::createFromResultAddress(eclipseCase, gridIndex, porosityModel, resTimeStepIdx, RigEclipseResultAddress("SWAT"));

    m_resultAccessor = new RigTernaryResultAccessor();
    m_resultAccessor->setTernaryResultAccessors(soil.p(), sgas.p(), swat.p());

    cvf::ref<RigPipeInCellEvaluator> pipeInCellEval = 
        new RigPipeInCellEvaluator(cellResultColors->reservoirView()->wellCollection()->resultWellGeometryVisibilities(timeStepIndex),
                                   eclipseCase->gridCellToResultWellIndex(gridIndex));

    const RivTernaryScalarMapper* mapper = ternaryLegendConfig->scalarMapper();

    m_texMapper = new RivTernaryResultToTextureMapper(mapper, pipeInCellEval.p());
    CVF_ASSERT(m_texMapper.notNull());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSaturationPressurePlot*>
    RicCreateSaturationPressurePlotsFeature::createPlots(RimEclipseResultCase* eclipseResultCase)
{
    std::vector<RimSaturationPressurePlot*> plots;

    if (!eclipseResultCase)
    {
        RiaLogging::error(
            "RicCreateSaturationPressurePlotsFeature:: No case specified for creation of saturation pressure plots");

        return plots;
    }

    RimProject* project = RiaApplication::instance()->project();

    RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();

    if (eclipseResultCase && eclipseResultCase->ensureReservoirCaseIsOpen())
    {
        eclipseResultCase->ensureDeckIsParsedForEquilData();

        RigEclipseCaseData* eclipseCaseData = eclipseResultCase->eclipseCaseData();

        bool requiredInputDataPresent = false;
        if (!eclipseCaseData->equilData().empty())
        {
            if (eclipseCaseData && eclipseCaseData->results(RiaDefines::MATRIX_MODEL))
            {
                RigCaseCellResultsData* resultData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);

                if (resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PRESSURE")) &&
                    resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PDEW")) &&
                    resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PBUB")))
                {
                    requiredInputDataPresent = true;
                }
            }
        }

        if (requiredInputDataPresent)
        {
            plots = collection->createSaturationPressurePlots(eclipseResultCase);
            for (auto plot : plots)
            {
                plot->loadDataAndUpdate();
                plot->zoomAll();
                plot->updateConnectedEditors();
            }
        }
    }

    return plots;
}
Esempio n. 3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
double RimSimWellInView::pipeRadius()
{
    RimEclipseView* reservoirView;
    firstAncestorOrThisOfTypeAsserted(reservoirView);

    RigEclipseCaseData* rigReservoir = reservoirView->eclipseCase()->eclipseCaseData();
    
    double characteristicCellSize = rigReservoir->mainGrid()->characteristicIJCellSize();

    double pipeRadius = reservoirView->wellCollection()->pipeScaleFactor() * this->pipeScaleFactor() * characteristicCellSize;

    return pipeRadius;
}
Esempio n. 4
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
std::vector<const RigWellPath*> RimSimWellInView::wellPipeBranches() const
{
    RimSimWellInViewCollection* simWellCollection = nullptr;
    this->firstAncestorOrThisOfTypeAsserted(simWellCollection);

    RimEclipseCase* eclipseCase = nullptr;
    this->firstAncestorOrThisOfTypeAsserted(eclipseCase);
    RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData();
    CVF_ASSERT(caseData);

    bool includeCellCenters = this->isUsingCellCenterForPipe();
    bool detectBrances      = simWellCollection->isAutoDetectingBranches;

    return caseData->simulationWellBranches(this->name(), includeCellCenters, detectBrances);
}
Esempio n. 5
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::createGeometry(RivCellSetEnum geometryType)
{
    RigEclipseCaseData* res = m_reservoirView->eclipseCase()->eclipseCaseData();
    m_geometries[geometryType].clearAndSetReservoir(res, m_reservoirView);
    m_geometries[geometryType].setTransform(m_scaleTransform.p());
    
    std::vector<RigGridBase*> grids;
    res->allGrids(&grids);

    for (size_t i = 0; i < grids.size(); ++i)
    {
        cvf::ref<cvf::UByteArray> cellVisibility = m_geometries[geometryType].cellVisibility(i); 
        computeVisibility(cellVisibility.p(), geometryType, grids[i], i);
        
        m_geometries[geometryType].setCellVisibility(i, cellVisibility.p());
    }

    m_geometriesNeedsRegen[geometryType] = false;
}
Esempio n. 6
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RiuRelativePermeabilityPlotUpdater::queryDataAndUpdatePlot(const RimEclipseView& eclipseView, size_t gridIndex, size_t gridLocalCellIndex, RiuRelativePermeabilityPlotPanel* plotPanel)
{
    CVF_ASSERT(plotPanel);

    RimEclipseResultCase* eclipseResultCase = dynamic_cast<RimEclipseResultCase*>(eclipseView.eclipseCase());
    RigEclipseCaseData* eclipseCaseData = eclipseResultCase ? eclipseResultCase->eclipseCaseData() : nullptr;
    if (eclipseResultCase && eclipseCaseData && eclipseResultCase->flowDiagSolverInterface())
    {
        size_t activeCellIndex = CellLookupHelper::mapToActiveCellIndex(eclipseCaseData, gridIndex, gridLocalCellIndex);
        if (activeCellIndex != cvf::UNDEFINED_SIZE_T)
        {
            //cvf::Trace::show("Updating RelPerm plot for active cell index: %d", static_cast<int>(activeCellIndex));

            std::vector<RigFlowDiagSolverInterface::RelPermCurve> relPermCurveArr = eclipseResultCase->flowDiagSolverInterface()->calculateRelPermCurves(activeCellIndex);

            // Make sure we load the results that we'll query below
            RigCaseCellResultsData* cellResultsData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);
            cellResultsData->findOrLoadScalarResult(RiaDefines::DYNAMIC_NATIVE, "SWAT");
            cellResultsData->findOrLoadScalarResult(RiaDefines::DYNAMIC_NATIVE, "SGAS");
            cellResultsData->findOrLoadScalarResult(RiaDefines::STATIC_NATIVE, "SATNUM");

            // Fetch SWAT and SGAS cell values for the selected cell
            const size_t timeStepIndex = static_cast<size_t>(eclipseView.currentTimeStep());
            cvf::ref<RigResultAccessor> swatAccessor = RigResultAccessorFactory::createFromNameAndType(eclipseCaseData, gridIndex, RiaDefines::MATRIX_MODEL, timeStepIndex, "SWAT", RiaDefines::DYNAMIC_NATIVE);
            cvf::ref<RigResultAccessor> sgasAccessor = RigResultAccessorFactory::createFromNameAndType(eclipseCaseData, gridIndex, RiaDefines::MATRIX_MODEL, timeStepIndex, "SGAS", RiaDefines::DYNAMIC_NATIVE);
            cvf::ref<RigResultAccessor> satnumAccessor = RigResultAccessorFactory::createFromNameAndType(eclipseCaseData, gridIndex, RiaDefines::MATRIX_MODEL, timeStepIndex, "SATNUM", RiaDefines::STATIC_NATIVE);
            const double cellSWAT = swatAccessor.notNull() ? swatAccessor->cellScalar(gridLocalCellIndex) : HUGE_VAL;
            const double cellSGAS = sgasAccessor.notNull() ? sgasAccessor->cellScalar(gridLocalCellIndex) : HUGE_VAL;
            const double cellSATNUM = satnumAccessor.notNull() ? satnumAccessor->cellScalar(gridLocalCellIndex) : HUGE_VAL;
            //cvf::Trace::show("cellSWAT = %f  cellSGAS = %f  cellSATNUM = %f", cellSWAT, cellSGAS, cellSATNUM);

            QString cellRefText = constructCellReferenceText(eclipseCaseData, gridIndex, gridLocalCellIndex, cellSATNUM);
            QString caseName = eclipseResultCase->caseUserDescription;

            plotPanel->setPlotData(eclipseCaseData->unitsType(), relPermCurveArr, cellSWAT, cellSGAS, caseName, cellRefText);

            return true;
        }
    }

    return false;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivCellEdgeGeometryUtils::addCellEdgeResultsToDrawableGeo(
    size_t timeStepIndex,
    RimEclipseCellColors* cellResultColors,
    RimCellEdgeColors* cellEdgeResultColors,
    const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
    cvf::DrawableGeo* geo,
    size_t gridIndex,
    bool useDefaultValueForHugeVals,
    float opacityLevel)
{
    RigEclipseCaseData* eclipseCase = cellResultColors->reservoirView()->eclipseCase()->eclipseCaseData();
    CVF_ASSERT(eclipseCase != nullptr);

    // Create result access objects

    cvf::ref<RigResultAccessor> cellCenterDataAccessObject = createCellCenterResultAccessor(cellResultColors, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
    cvf::ref<RigResultAccessor> cellEdgeResultAccessor = createCellEdgeResultAccessor(cellResultColors, cellEdgeResultColors, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));

    size_t vertexCount = geo->vertexArray()->size();
    size_t quadCount = vertexCount / 4;

    cvf::ref<cvf::Vec2fArray> localCoords = new cvf::Vec2fArray;
    localCoords->resize(vertexCount);

    cvf::ref<cvf::IntArray> faceIndexArray = new cvf::IntArray;
    faceIndexArray->resize(vertexCount);

    cvf::ref<cvf::FloatArray> cellColorTextureCoordArray = new cvf::FloatArray;
    cellColorTextureCoordArray->resize(vertexCount);

    // Build six cell face color arrays
    cvf::Collection<cvf::FloatArray> cellEdgeColorTextureCoordsArrays;
    size_t idx;
    for (idx = 0; idx < 6; idx++)
    {
        cvf::ref<cvf::FloatArray> colorArray = new cvf::FloatArray;
        colorArray->resize(vertexCount);
        cellEdgeColorTextureCoordsArrays.push_back(colorArray.p());
    }

    cvf::ScalarMapper* cellResultScalarMapper = cellResultColors->legendConfig()->scalarMapper();
    cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultColors->legendConfig()->scalarMapper();

    double ignoredScalarValue = cellEdgeResultColors->ignoredScalarValue();

    const std::vector<cvf::ubyte>* isWellPipeVisible = nullptr;
    cvf::cref<cvf::UIntArray>      gridCellToWellindexMap;

    if (opacityLevel < 1.0f)
    {
        isWellPipeVisible = &(cellResultColors->reservoirView()->wellCollection()->resultWellGeometryVisibilities(timeStepIndex));
        gridCellToWellindexMap = eclipseCase->gridCellToResultWellIndex(gridIndex);
    }

#pragma omp parallel for
    for (int quadIdx = 0; quadIdx < static_cast<int>(quadCount); quadIdx++)
    {
        localCoords->set(quadIdx * 4 + 0, cvf::Vec2f(0, 0));
        localCoords->set(quadIdx * 4 + 1, cvf::Vec2f(1, 0));
        localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1));
        localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1));

        faceIndexArray->set(quadIdx * 4 + 0, quadToCellFaceMapper->cellFace(quadIdx));
        faceIndexArray->set(quadIdx * 4 + 1, quadToCellFaceMapper->cellFace(quadIdx));
        faceIndexArray->set(quadIdx * 4 + 2, quadToCellFaceMapper->cellFace(quadIdx));
        faceIndexArray->set(quadIdx * 4 + 3, quadToCellFaceMapper->cellFace(quadIdx));

        size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx);
        {
            cvf::StructGridInterface::FaceType cellFace = quadToCellFaceMapper->cellFace(quadIdx);
            double scalarValue = cellCenterDataAccessObject->cellFaceScalar(cellIndex, cellFace);

            {
                float cellColorTextureCoord = 0.5f; // If no results exists, the texture will have a special color
                if (useDefaultValueForHugeVals || scalarValue != HUGE_VAL)
                {
                    if (scalarValue != HUGE_VAL)
                    {
                        cellColorTextureCoord = cellResultScalarMapper->mapToTextureCoord(scalarValue)[0];
                    }

                    // If we are dealing with wellcells, the default is transparent.
                    // we need to make cells opaque if there are no wellpipe through them.
                    if (opacityLevel < 1.0f)
                    {
                        cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex);
                        if (wellIndex != cvf::UNDEFINED_UINT)
                        {
                            if (!(*isWellPipeVisible)[wellIndex])
                            {
                                cellColorTextureCoord += 2.0f; // The shader must interpret values in the range 2-3 as "opaque"
                            }
                        }
                    }
                }
                else
                {
                    cellColorTextureCoord = -1.0f; // Undefined texture coord. Shader handles this.
                }

                cellColorTextureCoordArray->set(quadIdx * 4 + 0, cellColorTextureCoord);
                cellColorTextureCoordArray->set(quadIdx * 4 + 1, cellColorTextureCoord);
                cellColorTextureCoordArray->set(quadIdx * 4 + 2, cellColorTextureCoord);
                cellColorTextureCoordArray->set(quadIdx * 4 + 3, cellColorTextureCoord);
            }
        }


        for (size_t cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
        {
            float edgeColor = -1.0f; // Undefined texture coord. Shader handles this.

            double scalarValue = cellEdgeResultAccessor->cellFaceScalar(cellIndex, static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx));

            if (!hideScalarValue(scalarValue, ignoredScalarValue, 1e-2))
            {
                edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];
            }

            cvf::FloatArray* colArr = cellEdgeColorTextureCoordsArrays.at(cubeFaceIdx);

            colArr->set(quadIdx * 4 + 0, edgeColor);
            colArr->set(quadIdx * 4 + 1, edgeColor);
            colArr->set(quadIdx * 4 + 2, edgeColor);
            colArr->set(quadIdx * 4 + 3, edgeColor);
        }
    }

    geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_localCoord", localCoords.p()));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorCell", cellColorTextureCoordArray.p()));

    cvf::ref<cvf::IntVertexAttributeDirect> faceIntAttribute = new cvf::IntVertexAttributeDirect("a_face", faceIndexArray.p());
    geo->setVertexAttribute(faceIntAttribute.p());

    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosI", cellEdgeColorTextureCoordsArrays.at(0)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegI", cellEdgeColorTextureCoordsArrays.at(1)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosJ", cellEdgeColorTextureCoordsArrays.at(2)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegJ", cellEdgeColorTextureCoordsArrays.at(3)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosK", cellEdgeColorTextureCoordsArrays.at(4)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegK", cellEdgeColorTextureCoordsArrays.at(5)));
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivCellEdgeGeometryUtils::addTernaryCellEdgeResultsToDrawableGeo(size_t timeStepIndex, RimEclipseCellColors* cellResultColors, RimCellEdgeColors* cellEdgeResultColors,
    const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
    cvf::DrawableGeo* geo, size_t gridIndex, float opacityLevel)
{
    RigEclipseCaseData* eclipseCase = cellResultColors->reservoirView()->eclipseCase()->eclipseCaseData();
    CVF_ASSERT(eclipseCase != nullptr);

    cvf::ref<RigResultAccessor> cellEdgeResultAccessor = createCellEdgeResultAccessor(cellResultColors, cellEdgeResultColors, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));

    size_t vertexCount = geo->vertexArray()->size();
    size_t quadCount = vertexCount / 4;

    cvf::ref<cvf::Vec2fArray> localCoords = new cvf::Vec2fArray;
    localCoords->resize(vertexCount);

    cvf::ref<cvf::IntArray> faceIndexArray = new cvf::IntArray;
    faceIndexArray->resize(vertexCount);

    cvf::ref<cvf::Vec2fArray> vCellColorTextureCoordArray = new cvf::Vec2fArray;
    vCellColorTextureCoordArray->resize(vertexCount);

    // Build six cell face color arrays
    cvf::Collection<cvf::FloatArray> cellEdgeColorTextureCoordsArrays;
    size_t idx;
    for (idx = 0; idx < 6; idx++)
    {
        cvf::ref<cvf::FloatArray> colorArray = new cvf::FloatArray;
        colorArray->resize(vertexCount);
        cellEdgeColorTextureCoordsArrays.push_back(colorArray.p());
    }

    cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultColors->legendConfig()->scalarMapper();

    double ignoredScalarValue = cellEdgeResultColors->ignoredScalarValue();

    RivTernaryTextureCoordsCreator texturer(cellResultColors, cellResultColors->ternaryLegendConfig(),
        timeStepIndex,
        gridIndex,
        quadToCellFaceMapper);

    texturer.createTextureCoords(vCellColorTextureCoordArray.p());

#pragma omp parallel for
    for (int quadIdx = 0; quadIdx < static_cast<int>(quadCount); quadIdx++)
    {
        localCoords->set(quadIdx * 4 + 0, cvf::Vec2f(0, 0));
        localCoords->set(quadIdx * 4 + 1, cvf::Vec2f(1, 0));
        localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1));
        localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1));

        faceIndexArray->set(quadIdx * 4 + 0, quadToCellFaceMapper->cellFace(quadIdx));
        faceIndexArray->set(quadIdx * 4 + 1, quadToCellFaceMapper->cellFace(quadIdx));
        faceIndexArray->set(quadIdx * 4 + 2, quadToCellFaceMapper->cellFace(quadIdx));
        faceIndexArray->set(quadIdx * 4 + 3, quadToCellFaceMapper->cellFace(quadIdx));

        size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx);

        for (size_t cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
        {
            float edgeColor = -1.0f; // Undefined texture coord. Shader handles this.

            double scalarValue = cellEdgeResultAccessor->cellFaceScalar(cellIndex, static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx));

            if (!hideScalarValue(scalarValue, ignoredScalarValue, 1e-2))
            {
                edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];
            }

            cvf::FloatArray* colArr = cellEdgeColorTextureCoordsArrays.at(cubeFaceIdx);

            colArr->set(quadIdx * 4 + 0, edgeColor);
            colArr->set(quadIdx * 4 + 1, edgeColor);
            colArr->set(quadIdx * 4 + 2, edgeColor);
            colArr->set(quadIdx * 4 + 3, edgeColor);
        }
    }

    geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_localCoord", localCoords.p()));
    geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_cellTextureCoord", vCellColorTextureCoordArray.p()));

    cvf::ref<cvf::IntVertexAttributeDirect> faceIntAttribute = new cvf::IntVertexAttributeDirect("a_face", faceIndexArray.p());
    geo->setVertexAttribute(faceIntAttribute.p());

    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosI", cellEdgeColorTextureCoordsArrays.at(0)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegI", cellEdgeColorTextureCoordsArrays.at(1)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosJ", cellEdgeColorTextureCoordsArrays.at(2)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegJ", cellEdgeColorTextureCoordsArrays.at(3)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosK", cellEdgeColorTextureCoordsArrays.at(4)));
    geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegK", cellEdgeColorTextureCoordsArrays.at(5)));

}
Esempio n. 9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::createPropertyFilteredWellGeometry(size_t frameIndex)
{
    RigEclipseCaseData* res = m_reservoirView->eclipseCase()->eclipseCaseData();

    if ( frameIndex >= m_propFilteredWellGeometryFrames.size())
    { 
        m_propFilteredWellGeometryFrames.resize(frameIndex + 1);
        m_propFilteredWellGeometryFramesNeedsRegen.resize(frameIndex + 1, true);
    }

    if ( m_propFilteredWellGeometryFrames[frameIndex].isNull())  m_propFilteredWellGeometryFrames[frameIndex] = new RivReservoirPartMgr;

    m_propFilteredWellGeometryFrames[frameIndex]->clearAndSetReservoir(res, m_reservoirView);
    m_propFilteredWellGeometryFrames[frameIndex]->setTransform(m_scaleTransform.p());

    std::vector<RigGridBase*> grids;
    res->allGrids(&grids);

    bool hasActiveRangeFilters = m_reservoirView->rangeFilterCollection()->hasActiveFilters();
    bool hasVisibleWellCells = m_reservoirView->wellCollection()->hasVisibleWellCells();

    for (size_t gIdx = 0; gIdx < grids.size(); ++gIdx)
    {
        cvf::ref<cvf::UByteArray> cellVisibility = m_propFilteredWellGeometryFrames[frameIndex]->cellVisibility(gIdx); 
        cvf::ref<cvf::UByteArray> rangeVisibility; 
        cvf::ref<cvf::UByteArray> wellCellsOutsideRange; 
        cvf::ref<cvf::UByteArray> wellFenceCells;  

        if (hasActiveRangeFilters && hasVisibleWellCells)
        {
            ensureStaticGeometryPartsCreated(RANGE_FILTERED_WELL_CELLS);
            rangeVisibility = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gIdx);

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER);
            wellCellsOutsideRange = m_geometries[VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(gIdx);

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER);
            wellFenceCells = m_geometries[VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(gIdx);

        }
        else if (hasActiveRangeFilters && !hasVisibleWellCells)
        {
            ensureStaticGeometryPartsCreated(RANGE_FILTERED_WELL_CELLS);
            rangeVisibility = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gIdx);
            wellCellsOutsideRange = rangeVisibility;
            wellFenceCells = rangeVisibility;
        }
        else if (!hasActiveRangeFilters && hasVisibleWellCells)
        {
            ensureStaticGeometryPartsCreated(VISIBLE_WELL_CELLS);
            wellCellsOutsideRange = m_geometries[VISIBLE_WELL_CELLS].cellVisibility(gIdx);

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_FENCE_CELLS);
            wellFenceCells = m_geometries[VISIBLE_WELL_FENCE_CELLS].cellVisibility(gIdx);

            rangeVisibility = wellCellsOutsideRange;
        }
        else if (!hasActiveRangeFilters && !hasVisibleWellCells)
        {
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);
            wellFenceCells = m_geometries[ALL_WELL_CELLS].cellVisibility(gIdx);
            wellCellsOutsideRange = wellFenceCells;
            rangeVisibility = wellFenceCells;
        }

        cellVisibility->resize(rangeVisibility->size());

#pragma omp parallel for
        for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
        {
            (*cellVisibility)[cellIdx] =  (*wellFenceCells)[cellIdx] || (*rangeVisibility)[cellIdx] || (*wellCellsOutsideRange)[cellIdx];
        }

        computePropertyVisibility(cellVisibility.p(), grids[gIdx], frameIndex, cellVisibility.p(), m_reservoirView->eclipsePropertyFilterCollection()); 

        m_propFilteredWellGeometryFrames[frameIndex]->setCellVisibility(gIdx, cellVisibility.p());
    }

    m_propFilteredWellGeometryFramesNeedsRegen[frameIndex] = false;
}
Esempio n. 10
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility, RivCellSetEnum geometryType, RigGridBase* grid, size_t gridIdx)
{
    RigEclipseCaseData* eclipseCase = m_reservoirView->eclipseCase()->eclipseCaseData();
    RigActiveCellInfo* activeCellInfo = m_reservoirView->currentActiveCellInfo();

    switch (geometryType)
    {
    case OVERRIDDEN_CELL_VISIBILITY:
        computeOverriddenCellVisibility(cellVisibility, grid);
    break;
    case ACTIVE:
        computeNativeVisibility(cellVisibility, grid, activeCellInfo, eclipseCase->wellCellsInGrid(gridIdx), false, false, true, m_reservoirView->showMainGrid() );
        break;
    case ALL_WELL_CELLS:
        copyByteArray(cellVisibility, eclipseCase->wellCellsInGrid(gridIdx));
        break;
    case VISIBLE_WELL_CELLS:
        {
            cvf::ref<cvf::UByteArray> allWellCellsVisibility;
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);

            allWellCellsVisibility = m_geometries[ALL_WELL_CELLS].cellVisibility(gridIdx);

            m_reservoirView->calculateVisibleWellCellsIncFence(cellVisibility, grid);

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = (*allWellCellsVisibility)[cellIdx] && (*cellVisibility)[cellIdx];
            }
        }
        break;
    case VISIBLE_WELL_FENCE_CELLS:
        {
            cvf::ref<cvf::UByteArray> allWellCellsVisibility;
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);

            allWellCellsVisibility = m_geometries[ALL_WELL_CELLS].cellVisibility(gridIdx);

            m_reservoirView->calculateVisibleWellCellsIncFence(cellVisibility, grid);

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = !(*allWellCellsVisibility)[cellIdx] && (*cellVisibility)[cellIdx];
            }
        }
        break;
    case INACTIVE:
        computeNativeVisibility(cellVisibility, grid, activeCellInfo, eclipseCase->wellCellsInGrid(gridIdx),  m_reservoirView->showInvalidCells(), true, false, m_reservoirView->showMainGrid());
        break;
    case RANGE_FILTERED:
        {
            cvf::ref<cvf::UByteArray> nativeVisibility;
            ensureStaticGeometryPartsCreated(ACTIVE);

            nativeVisibility = m_geometries[ACTIVE].cellVisibility(gridIdx);
            computeRangeVisibility(geometryType, cellVisibility, grid, nativeVisibility.p(), m_reservoirView->rangeFilterCollection());
        }
        break;
    case RANGE_FILTERED_INACTIVE:
        {
            cvf::ref<cvf::UByteArray> nativeVisibility;
            ensureStaticGeometryPartsCreated(INACTIVE);

            nativeVisibility = m_geometries[INACTIVE].cellVisibility(gridIdx);
            computeRangeVisibility(geometryType, cellVisibility, grid, nativeVisibility.p(), m_reservoirView->rangeFilterCollection());
        }
        break;
    case RANGE_FILTERED_WELL_CELLS:
        {
            cvf::ref<cvf::UByteArray> nativeVisibility;
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);

            nativeVisibility = m_geometries[ALL_WELL_CELLS].cellVisibility(gridIdx);
            computeRangeVisibility(geometryType, cellVisibility, grid, nativeVisibility.p(), m_reservoirView->rangeFilterCollection());
        }
        break;
    case VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER:
        {
            cvf::ref<cvf::UByteArray> visibleWellCells;
            cvf::ref<cvf::UByteArray> rangeFilteredWellCells;

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_CELLS);
            ensureStaticGeometryPartsCreated(RANGE_FILTERED_WELL_CELLS);

            visibleWellCells = m_geometries[VISIBLE_WELL_CELLS].cellVisibility(gridIdx);
            rangeFilteredWellCells = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gridIdx);

            cellVisibility->resize(visibleWellCells->size());

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = (*visibleWellCells)[cellIdx] && !(*rangeFilteredWellCells)[cellIdx];
            }
        }
        break;
    case VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER:
        {
            cvf::ref<cvf::UByteArray> visibleWellCells;
            cvf::ref<cvf::UByteArray> rangeFilteredWellCells;

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_FENCE_CELLS);
            ensureStaticGeometryPartsCreated(RANGE_FILTERED);

            visibleWellCells = m_geometries[VISIBLE_WELL_FENCE_CELLS].cellVisibility(gridIdx);
            rangeFilteredWellCells = m_geometries[RANGE_FILTERED].cellVisibility(gridIdx);

            cellVisibility->resize(visibleWellCells->size());

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = (*visibleWellCells)[cellIdx] && !(*rangeFilteredWellCells)[cellIdx];
            }
        }
        break;
    default:
        CVF_ASSERT(false); // Call special function for property filtered stuff
        break;
    }
}
Esempio n. 11
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RimEclipseCellColors::updateLegendData(RimEclipseCase*         rimEclipseCase, 
                                            int                     currentTimeStep,
                                            RimRegularLegendConfig* legendConfig, 
                                            RimTernaryLegendConfig* ternaryLegendConfig)
{
    if (!legendConfig) legendConfig = this->legendConfig();
    if (!ternaryLegendConfig) ternaryLegendConfig = this->m_ternaryLegendConfig();

    if ( this->hasResult() )
    {
        if ( this->isFlowDiagOrInjectionFlooding() )
        {
            CVF_ASSERT(currentTimeStep >= 0);

            double globalMin, globalMax;
            double globalPosClosestToZero, globalNegClosestToZero;
            RigFlowDiagResults* flowResultsData = this->flowDiagSolution()->flowDiagResults();
            RigFlowDiagResultAddress resAddr = this->flowDiagResAddress();

            flowResultsData->minMaxScalarValues(resAddr, currentTimeStep, &globalMin, &globalMax);
            flowResultsData->posNegClosestToZero(resAddr, currentTimeStep, &globalPosClosestToZero, &globalNegClosestToZero);

            double localMin, localMax;
            double localPosClosestToZero, localNegClosestToZero;
            if ( this->hasDynamicResult() )
            {
                flowResultsData->minMaxScalarValues(resAddr, currentTimeStep, &localMin, &localMax);
                flowResultsData->posNegClosestToZero(resAddr, currentTimeStep, &localPosClosestToZero, &localNegClosestToZero);
            }
            else
            {
                localMin = globalMin;
                localMax = globalMax;

                localPosClosestToZero = globalPosClosestToZero;
                localNegClosestToZero = globalNegClosestToZero;
            }

            CVF_ASSERT(legendConfig);

            legendConfig->disableAllTimeStepsRange(true);
            legendConfig->setClosestToZeroValues(globalPosClosestToZero, globalNegClosestToZero, 
                                                         localPosClosestToZero, localNegClosestToZero);
            legendConfig->setAutomaticRanges(globalMin, globalMax, localMin, localMax);

            if ( this->hasCategoryResult() && m_reservoirView)
            {
                std::set<std::tuple<QString, int, cvf::Color3ub>, TupleCompare > categories;
                //std::set<std::tuple<QString, int, cvf::Color3ub> > categories;

                std::vector<QString> tracerNames = this->flowDiagSolution()->tracerNames();
                int tracerIndex = 0;
                for ( const auto& tracerName : tracerNames )
                {
                    RimSimWellInView* well = m_reservoirView->wellCollection()->findWell(RimFlowDiagSolution::removeCrossFlowEnding(tracerName));
                    cvf::Color3ub color(cvf::Color3::GRAY);
                    if ( well ) color = cvf::Color3ub(well->wellPipeColor());

                    categories.insert(std::make_tuple(tracerName, tracerIndex, color));
                    ++tracerIndex;
                }

                std::vector<std::tuple<QString, int, cvf::Color3ub>> reverseCategories;
                for ( auto tupIt = categories.rbegin(); tupIt != categories.rend(); ++tupIt )
                {
                    reverseCategories.push_back(*tupIt);
                }

                legendConfig->setCategoryItems(reverseCategories);
            }
        }
        else
        {
            CVF_ASSERT(rimEclipseCase);
            if ( !rimEclipseCase ) return;

            RigEclipseCaseData* eclipseCase = rimEclipseCase->eclipseCaseData();
            CVF_ASSERT(eclipseCase);
            if ( !eclipseCase ) return;

            RigCaseCellResultsData* cellResultsData = eclipseCase->results(this->porosityModel());
            CVF_ASSERT(cellResultsData);

            double globalMin, globalMax;
            double globalPosClosestToZero, globalNegClosestToZero;

            cellResultsData->minMaxCellScalarValues(this->eclipseResultAddress(), globalMin, globalMax);
            cellResultsData->posNegClosestToZero(this->eclipseResultAddress(), globalPosClosestToZero, globalNegClosestToZero);

            double localMin, localMax;
            double localPosClosestToZero, localNegClosestToZero;
            if ( this->hasDynamicResult() && currentTimeStep >= 0)
            {
                cellResultsData->minMaxCellScalarValues(this->eclipseResultAddress(), currentTimeStep, localMin, localMax);
                cellResultsData->posNegClosestToZero(this->eclipseResultAddress(), currentTimeStep, localPosClosestToZero, localNegClosestToZero);
            }
            else
            {
                localMin = globalMin;
                localMax = globalMax;

                localPosClosestToZero = globalPosClosestToZero;
                localNegClosestToZero = globalNegClosestToZero;
            }

            CVF_ASSERT(legendConfig);

            legendConfig->disableAllTimeStepsRange(false);
            legendConfig->setClosestToZeroValues(globalPosClosestToZero, globalNegClosestToZero, localPosClosestToZero, localNegClosestToZero);
            legendConfig->setAutomaticRanges(globalMin, globalMax, localMin, localMax);

            if ( this->hasCategoryResult() )
            {
                if ( this->resultType() == RiaDefines::FORMATION_NAMES )
                {
                    const std::vector<QString>& fnVector = eclipseCase->activeFormationNames()->formationNames();
                    legendConfig->setNamedCategoriesInverse(fnVector);
                }
                else if ( this->resultType() == RiaDefines::DYNAMIC_NATIVE && this->resultVariable() == RiaDefines::completionTypeResultName() )
                {   
                    const std::vector<int>& visibleCategories = cellResultsData->uniqueCellScalarValues(this->eclipseResultAddress());

                    std::vector<RiaDefines::WellPathComponentType> supportedCompletionTypes =
                        { RiaDefines::WELL_PATH, RiaDefines::FISHBONES, RiaDefines::PERFORATION_INTERVAL, RiaDefines::FRACTURE };
                    
                    RiaColorTables::WellPathComponentColors colors = RiaColorTables::wellPathComponentColors();
                    
                    std::vector< std::tuple<QString, int, cvf::Color3ub> > categories;
                    for (auto completionType : supportedCompletionTypes)
                    {
                        if (std::find(visibleCategories.begin(), visibleCategories.end(), completionType) != visibleCategories.end())
                        {
                            QString categoryText = caf::AppEnum<RiaDefines::WellPathComponentType>::uiText(completionType);
                            categories.push_back(std::make_tuple(categoryText, completionType, colors[completionType]));
                        }
                    }

                    legendConfig->setCategoryItems(categories);
                }
                else
                {
                    legendConfig->setIntegerCategories(cellResultsData->uniqueCellScalarValues(this->eclipseResultAddress()));
                }
            }
        }
    }

    // Ternary legend update
    {
        CVF_ASSERT(rimEclipseCase);
        if ( !rimEclipseCase ) return;

        RigEclipseCaseData* eclipseCase = rimEclipseCase->eclipseCaseData();
        CVF_ASSERT(eclipseCase);
        if ( !eclipseCase ) return;


        RigCaseCellResultsData* cellResultsData = eclipseCase->results(this->porosityModel());

        size_t maxTimeStepCount = cellResultsData->maxTimeStepCount();
        if ( this->isTernarySaturationSelected() && maxTimeStepCount > 1 )
        {
            RigCaseCellResultsData* gridCellResults = this->currentGridCellResults();
            {
                RigEclipseResultAddress resAddr(RiaDefines::DYNAMIC_NATIVE, "SOIL");

                if ( gridCellResults->ensureKnownResultLoaded(resAddr) )
                {
                    double globalMin = 0.0;
                    double globalMax = 1.0;
                    double localMin = 0.0;
                    double localMax = 1.0;

                    cellResultsData->minMaxCellScalarValues(resAddr, globalMin, globalMax);
                    cellResultsData->minMaxCellScalarValues(resAddr, currentTimeStep, localMin, localMax);

                    ternaryLegendConfig->setAutomaticRanges(RimTernaryLegendConfig::TERNARY_SOIL_IDX, globalMin, globalMax, localMin, localMax);
                }
            }

            {
                RigEclipseResultAddress resAddr(RiaDefines::DYNAMIC_NATIVE, "SGAS");
                
                if ( gridCellResults->ensureKnownResultLoaded(resAddr) )
                {
                    double globalMin = 0.0;
                    double globalMax = 1.0;
                    double localMin = 0.0;
                    double localMax = 1.0;

                    cellResultsData->minMaxCellScalarValues(resAddr, globalMin, globalMax);
                    cellResultsData->minMaxCellScalarValues(resAddr, currentTimeStep, localMin, localMax);

                    ternaryLegendConfig->setAutomaticRanges(RimTernaryLegendConfig::TERNARY_SGAS_IDX, globalMin, globalMax, localMin, localMax);
                }
            }

            {
                RigEclipseResultAddress resAddr(RiaDefines::DYNAMIC_NATIVE, "SWAT");

                if ( gridCellResults->ensureKnownResultLoaded(resAddr) )
                {
                    double globalMin = 0.0;
                    double globalMax = 1.0;
                    double localMin = 0.0;
                    double localMax = 1.0;

                    cellResultsData->minMaxCellScalarValues(resAddr, globalMin, globalMax);
                    cellResultsData->minMaxCellScalarValues(resAddr, currentTimeStep, localMin, localMax);

                    ternaryLegendConfig->setAutomaticRanges(RimTernaryLegendConfig::TERNARY_SWAT_IDX, globalMin, globalMax, localMin, localMax);
                }
            }
        }
    }
}
Esempio n. 12
0
//--------------------------------------------------------------------------------------------------
/// frameIndex = -1 will use the static well frame
//--------------------------------------------------------------------------------------------------
void RimSimWellInView::wellHeadTopBottomPosition(int frameIndex, cvf::Vec3d* top, cvf::Vec3d* bottom)
{

    RimEclipseView* m_rimReservoirView;
    firstAncestorOrThisOfTypeAsserted(m_rimReservoirView);
    
    RigEclipseCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->eclipseCaseData();

    const RigWellResultFrame* wellResultFramePtr = nullptr;
    const RigCell* whCellPtr = nullptr;

    if (frameIndex >= 0)
    {
        if ( !this->simWellData()->hasAnyValidCells(frameIndex) ) return;

        wellResultFramePtr = &(this->simWellData()->wellResultFrame(frameIndex));
        whCellPtr = &(rigReservoir->cellFromWellResultCell(wellResultFramePtr->wellHeadOrStartCell()));
    }
    else
    {
        wellResultFramePtr = &(this->simWellData()->staticWellCells());
        whCellPtr = &(rigReservoir->cellFromWellResultCell(wellResultFramePtr->wellHeadOrStartCell()));
    }

    const RigWellResultFrame& wellResultFrame = *wellResultFramePtr;
    const RigCell& whCell = *whCellPtr;

    // Match this position with pipe start position in RivWellPipesPartMgr::calculateWellPipeCenterline()

    (*bottom) = whCell.faceCenter(cvf::StructGridInterface::NEG_K);

    // Compute well head based on the z position of the top of the K column the well head is part of
    (*top) = (*bottom);
    if ( m_rimReservoirView->wellCollection()->wellHeadPosition() == RimSimWellInViewCollection::WELLHEAD_POS_TOP_COLUMN )
    {
        // Position well head at top active cell of IJ-column

        size_t i, j, k;
        rigReservoir->mainGrid()->ijkFromCellIndex(whCell.mainGridCellIndex(), &i, &j, &k);

        size_t kIndexWellHeadCell = k;
        k = 0;

        size_t topActiveCellIndex = rigReservoir->mainGrid()->cellIndexFromIJK(i, j, k);
        while ( k < kIndexWellHeadCell && !m_rimReservoirView->currentActiveCellInfo()->isActive(topActiveCellIndex) )
        {
            k++;
            topActiveCellIndex = rigReservoir->mainGrid()->cellIndexFromIJK(i, j, k);
        }

        const RigCell& topActiveCell = rigReservoir->mainGrid()->cell(topActiveCellIndex);
        cvf::Vec3d topCellPos = topActiveCell.faceCenter(cvf::StructGridInterface::NEG_K);

        // Modify position if top active cell is closer to sea than well head
        if ( kIndexWellHeadCell > k )
        {
            top->z() = topCellPos.z();
        }
    }
    else
    {
        // Position well head at top of active cells bounding box

        cvf::Vec3d activeCellsBoundingBoxMax = m_rimReservoirView->currentActiveCellInfo()->geometryBoundingBox().max();

        top->z() = activeCellsBoundingBoxMax.z();
    }
}
Esempio n. 13
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString Rim3dWellLogExtractionCurve::createCurveAutoName() const
{
    RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value());
    RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value());

    QStringList generatedCurveName;
    
    if (m_nameConfig->addWellName())
    {
        RimWellPath* wellPath;
        this->firstAncestorOrThisOfTypeAsserted(wellPath);
        if (!wellPath->name().isEmpty())
        {
            generatedCurveName += wellPath->name();
        }
    }

    if (m_nameConfig->addCaseName() && m_case())
    {
        generatedCurveName.push_back(m_case->caseUserDescription());
    }

    if (m_nameConfig->addProperty() && !resultPropertyString().isEmpty())
    {
        generatedCurveName.push_back(resultPropertyString());
    }

    if (m_nameConfig->addTimeStep() || m_nameConfig->addDate())
    {
        size_t maxTimeStep = 0;

        if (eclipseCase)
        {
            RigEclipseCaseData* data = eclipseCase->eclipseCaseData();
            if (data)
            {
                maxTimeStep = data->results(m_eclipseResultDefinition->porosityModel())->maxTimeStepCount();
            }
        }
        else if (geomCase)
        {
            RigGeoMechCaseData* data = geomCase->geoMechData();
            if (data)
            {
                maxTimeStep = data->femPartResults()->frameCount();
            }
        }

        if (m_nameConfig->addDate())
        {
            QString dateString = wellDate();
            if (!dateString.isEmpty())
            {
                generatedCurveName.push_back(dateString);
            }
        }

        if (m_nameConfig->addTimeStep())
        {
            generatedCurveName.push_back(QString("[%1/%2]").arg(m_timeStep()).arg(maxTimeStep));
        }
    }

    return generatedCurveName.join(", ");
}