//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimCase::computeCachedData() { RigCaseData* rigEclipseCase = reservoirData(); if (rigEclipseCase) { caf::ProgressInfo pInf(30, ""); pInf.setNextProgressIncrement(1); rigEclipseCase->computeActiveCellBoundingBoxes(); pInf.incrementProgress(); pInf.setNextProgressIncrement(10); rigEclipseCase->mainGrid()->computeCachedData(); pInf.incrementProgress(); pInf.setProgressDescription("Calculating faults"); rigEclipseCase->mainGrid()->calculateFaults(); pInf.incrementProgress(); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::createGeometry(ReservoirGeometryCacheType geometryType) { RigCaseData* res = m_reservoirView->eclipseCase()->reservoirData(); 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; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { if (changedField == &releaseResultMemory) { if (this->reservoirData()) { for (size_t i = 0; i < reservoirViews().size(); i++) { RimReservoirView* reservoirView = reservoirViews()[i]; CVF_ASSERT(reservoirView); RimResultSlot* result = reservoirView->cellResult; CVF_ASSERT(result); result->setResultVariable(RimDefines::undefinedResultName()); result->loadResult(); RimCellEdgeResultSlot* cellEdgeResult = reservoirView->cellEdgeResult; CVF_ASSERT(cellEdgeResult); cellEdgeResult->resultVariable.v() = RimDefines::undefinedResultName(); cellEdgeResult->loadResult(); reservoirView->createDisplayModelAndRedraw(); } RigCaseCellResultsData* matrixModelResults = reservoirData()->results(RifReaderInterface::MATRIX_RESULTS); if (matrixModelResults) { matrixModelResults->clearAllResults(); } RigCaseCellResultsData* fractureModelResults = reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS); if (fractureModelResults) { fractureModelResults->clearAllResults(); } } releaseResultMemory = oldValue.toBool(); } else if (changedField == &flipXAxis || changedField == &flipYAxis) { RigCaseData* rigEclipseCase = reservoirData(); if (rigEclipseCase) { rigEclipseCase->mainGrid()->setFlipAxis(flipXAxis, flipYAxis); computeCachedData(); for (size_t i = 0; i < reservoirViews().size(); i++) { RimReservoirView* reservoirView = reservoirViews()[i]; reservoirView->scheduleReservoirGridGeometryRegen(); reservoirView->schedulePipeGeometryRegen(); reservoirView->createDisplayModelAndRedraw(); } } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex) { m_wellHeadParts.clear(); if (m_rimReservoirView.isNull()) return; RigCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData(); RimEclipseWell* well = m_rimWell; RigSingleWellResultsData* wellResults = well->wellResults(); if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0) { wellResults->computeStaticWellCellPath(); } if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0) return; if (!wellResults->hasWellResult(frameIndex)) return; const RigWellResultFrame& wellResultFrame = wellResults->wellResultFrame(frameIndex); const RigCell& whCell = rigReservoir->cellFromWellResultCell(wellResultFrame.m_wellHead); double characteristicCellSize = rigReservoir->mainGrid()->characteristicIJCellSize(); // Match this position with pipe start position in RivWellPipesPartMgr::calculateWellPipeCenterline() cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K); whStartPos -= rigReservoir->mainGrid()->displayModelOffset(); whStartPos.transformPoint(m_scaleTransform->worldTransform()); // Compute well head based on the z position of the top of the K column the well head is part of cvf::Vec3d whEndPos = whStartPos; if (m_rimReservoirView->wellCollection()->wellHeadPosition() == RimEclipseWellCollection::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); topCellPos -= rigReservoir->mainGrid()->displayModelOffset(); topCellPos.transformPoint(m_scaleTransform->worldTransform()); // Modify position if top active cell is closer to sea than well head if (kIndexWellHeadCell > k) { whEndPos.z() = topCellPos.z() + characteristicCellSize; } } else { // Position well head at top of active cells bounding box cvf::Vec3d activeCellsBoundingBoxMax = m_rimReservoirView->currentActiveCellInfo()->geometryBoundingBox().max(); activeCellsBoundingBoxMax -= rigReservoir->mainGrid()->displayModelOffset(); activeCellsBoundingBoxMax.transformPoint(m_scaleTransform->worldTransform()); whEndPos.z() = activeCellsBoundingBoxMax.z(); } cvf::Vec3d arrowPosition = whEndPos; arrowPosition.z() += 2.0; // Well head pipe geometry { cvf::ref<cvf::Vec3dArray> wellHeadPipeCoords = new cvf::Vec3dArray; wellHeadPipeCoords->resize(2); wellHeadPipeCoords->set(0, whStartPos); wellHeadPipeCoords->set(1, whEndPos); cvf::ref<RivPipeGeometryGenerator> pipeGeomGenerator = new RivPipeGeometryGenerator; pipeGeomGenerator->setPipeCenterCoords(wellHeadPipeCoords.p()); pipeGeomGenerator->setPipeColor(well->wellPipeColor()); pipeGeomGenerator->setCrossSectionVertexCount(m_rimReservoirView->wellCollection()->pipeCrossSectionVertexCount()); double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() * m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize; pipeGeomGenerator->setRadius(pipeRadius); cvf::ref<cvf::DrawableGeo> pipeSurface = pipeGeomGenerator->createPipeSurface(); cvf::ref<cvf::DrawableGeo> centerLineDrawable = pipeGeomGenerator->createCenterLine(); if (pipeSurface.notNull()) { cvf::ref<cvf::Part> part = new cvf::Part; part->setName("RivWellHeadPartMgr: surface " + cvfqt::Utils::toString(well->name())); part->setDrawable(pipeSurface.p()); caf::SurfaceEffectGenerator surfaceGen(cvf::Color4f(well->wellPipeColor()), caf::PO_1); cvf::ref<cvf::Effect> eff = surfaceGen.generateEffect(); part->setEffect(eff.p()); m_wellHeadParts.push_back(part.p()); } if (centerLineDrawable.notNull()) { cvf::ref<cvf::Part> part = new cvf::Part; part->setName("RivWellHeadPartMgr: centerline " + cvfqt::Utils::toString(well->name())); part->setDrawable(centerLineDrawable.p()); caf::MeshEffectGenerator meshGen(well->wellPipeColor()); cvf::ref<cvf::Effect> eff = meshGen.generateEffect(); part->setEffect(eff.p()); m_wellHeadParts.push_back(part.p()); } } double arrowLength = characteristicCellSize * m_rimReservoirView->wellCollection()->wellHeadScaleFactor(); cvf::Vec3d textPosition = arrowPosition; textPosition.z() += 1.2 * arrowLength; cvf::Mat4f matr; if (wellResultFrame.m_productionType != RigWellResultFrame::PRODUCER) { matr = cvf::Mat4f::fromRotation(cvf::Vec3f(1.0f, 0.0f, 0.0f), cvf::Math::toRadians(180.0f)); } double ijScaleFactor = arrowLength / 6; matr(0, 0) *= ijScaleFactor; matr(1, 1) *= ijScaleFactor; matr(2, 2) *= arrowLength; if (wellResultFrame.m_productionType != RigWellResultFrame::PRODUCER) { arrowPosition.z() += arrowLength; } matr.setTranslation(cvf::Vec3f(arrowPosition)); cvf::GeometryBuilderFaceList builder; cvf::ArrowGenerator gen; gen.setShaftRelativeRadius(0.5f); gen.setHeadRelativeRadius(1.0f); gen.setHeadRelativeLength(0.4f); gen.setNumSlices(m_rimReservoirView->wellCollection()->pipeCrossSectionVertexCount()); gen.generate(&builder); cvf::ref<cvf::Vec3fArray> vertices = builder.vertices(); cvf::ref<cvf::UIntArray> faceList = builder.faceList(); size_t i; for (i = 0; i < vertices->size(); i++) { cvf::Vec3f v = vertices->get(i); v.transformPoint(matr); vertices->set(i, v); } cvf::ref<cvf::DrawableGeo> geo1 = new cvf::DrawableGeo; geo1->setVertexArray(vertices.p()); geo1->setFromFaceList(*faceList); geo1->computeNormals(); { cvf::ref<cvf::Part> part = new cvf::Part; part->setName("RivWellHeadPartMgr: arrow " + cvfqt::Utils::toString(well->name())); part->setDrawable(geo1.p()); cvf::Color4f headColor(cvf::Color3::GRAY); if (wellResultFrame.m_isOpen) { if (wellResultFrame.m_productionType == RigWellResultFrame::PRODUCER) { headColor = cvf::Color4f(cvf::Color3::GREEN); } else if (wellResultFrame.m_productionType == RigWellResultFrame::OIL_INJECTOR) { headColor = cvf::Color4f(cvf::Color3::ORANGE); } else if (wellResultFrame.m_productionType == RigWellResultFrame::GAS_INJECTOR) { headColor = cvf::Color4f(cvf::Color3::RED); } else if (wellResultFrame.m_productionType == RigWellResultFrame::WATER_INJECTOR) { headColor = cvf::Color4f(cvf::Color3::BLUE); } } caf::SurfaceEffectGenerator surfaceGen(headColor, caf::PO_1); cvf::ref<cvf::Effect> eff = surfaceGen.generateEffect(); part->setEffect(eff.p()); m_wellHeadParts.push_back(part.p()); } if (m_rimReservoirView->wellCollection()->showWellLabel() && well->showWellLabel() && !well->name().isEmpty()) { cvf::Font* standardFont = RiaApplication::instance()->standardFont(); cvf::ref<cvf::DrawableText> drawableText = new cvf::DrawableText; drawableText->setFont(standardFont); drawableText->setCheckPosVisible(false); drawableText->setDrawBorder(false); drawableText->setDrawBackground(false); drawableText->setVerticalAlignment(cvf::TextDrawer::CENTER); drawableText->setTextColor(m_rimReservoirView->wellCollection()->wellLabelColor()); cvf::String cvfString = cvfqt::Utils::toString(well->name()); cvf::Vec3f textCoord(textPosition); drawableText->addText(cvfString, textCoord); cvf::ref<cvf::Part> part = new cvf::Part; part->setName("RivWellHeadPartMgr: text " + cvfString); part->setDrawable(drawableText.p()); cvf::ref<cvf::Effect> eff = new cvf::Effect; part->setEffect(eff.p()); part->setPriority(11); m_wellHeadParts.push_back(part.p()); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::createPropertyFilteredWellGeometry(size_t frameIndex) { RigCaseData* res = m_reservoirView->eclipseCase()->reservoirData(); 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) { if (m_geometriesNeedsRegen[RANGE_FILTERED_WELL_CELLS]) createGeometry(RANGE_FILTERED_WELL_CELLS); rangeVisibility = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gIdx); if (m_geometriesNeedsRegen[VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER]) createGeometry(VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER); wellCellsOutsideRange = m_geometries[VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(gIdx); if (m_geometriesNeedsRegen[VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER]) createGeometry(VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER); wellFenceCells = m_geometries[VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(gIdx); } else if (hasActiveRangeFilters && !hasVisibleWellCells) { if (m_geometriesNeedsRegen[RANGE_FILTERED_WELL_CELLS]) createGeometry(RANGE_FILTERED_WELL_CELLS); rangeVisibility = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gIdx); wellCellsOutsideRange = rangeVisibility; wellFenceCells = rangeVisibility; } else if (!hasActiveRangeFilters && hasVisibleWellCells) { if (m_geometriesNeedsRegen[VISIBLE_WELL_CELLS]) createGeometry(VISIBLE_WELL_CELLS); wellCellsOutsideRange = m_geometries[VISIBLE_WELL_CELLS].cellVisibility(gIdx); if (m_geometriesNeedsRegen[VISIBLE_WELL_FENCE_CELLS]) createGeometry(VISIBLE_WELL_FENCE_CELLS); wellFenceCells = m_geometries[VISIBLE_WELL_FENCE_CELLS].cellVisibility(gIdx); rangeVisibility = wellCellsOutsideRange; } else if (!hasActiveRangeFilters && !hasVisibleWellCells) { if (m_geometriesNeedsRegen[ALL_WELL_CELLS]) createGeometry(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->propertyFilterCollection()); m_propFilteredWellGeometryFrames[frameIndex]->setCellVisibility(gIdx, cellVisibility.p()); } m_propFilteredWellGeometryFramesNeedsRegen[frameIndex] = false; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility, ReservoirGeometryCacheType geometryType, RigGridBase* grid, size_t gridIdx) { RigCaseData* eclipseCase = m_reservoirView->eclipseCase()->reservoirData(); RigActiveCellInfo* activeCellInfo = m_reservoirView->currentActiveCellInfo(); switch (geometryType) { 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; if (m_geometriesNeedsRegen[ALL_WELL_CELLS]) createGeometry(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; if (m_geometriesNeedsRegen[ALL_WELL_CELLS]) createGeometry(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; if (m_geometriesNeedsRegen[ACTIVE]) createGeometry(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; if (m_geometriesNeedsRegen[INACTIVE]) createGeometry(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; if (m_geometriesNeedsRegen[ALL_WELL_CELLS]) createGeometry(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; if (m_geometriesNeedsRegen[VISIBLE_WELL_CELLS]) createGeometry(VISIBLE_WELL_CELLS); if (m_geometriesNeedsRegen[RANGE_FILTERED_WELL_CELLS]) createGeometry(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; if (m_geometriesNeedsRegen[VISIBLE_WELL_FENCE_CELLS]) createGeometry(VISIBLE_WELL_FENCE_CELLS); if (m_geometriesNeedsRegen[RANGE_FILTERED]) createGeometry(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; } }