///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2016- Statoil ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RivWellConnectionsPartMgr.h" #include "RimEclipseResultCase.h" #include "RimEclipseView.h" #include "RimEclipseWell.h" #include "RimEclipseWellCollection.h" #include "RigSingleWellResultsData.h" #include "RigFlowDiagResults.h" #include "RigEclipseCaseData.h" #include "RigMainGrid.h" #include "RigActiveCellInfo.h" #include "cafEffectGenerator.h" #include "cafDisplayCoordTransform.h" #include "cvfDrawableGeo.h" #include "cvfPart.h" #include "cvfModelBasicList.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RivWellConnectionsPartMgr::RivWellConnectionsPartMgr(RimEclipseView* reservoirView, RimEclipseWell* well) { m_rimReservoirView = reservoirView; m_rimWell = well; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RivWellConnectionsPartMgr::~RivWellConnectionsPartMgr() { } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RivWellConnectionsPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex) { if ( m_rimReservoirView.isNull() ) return; if ( !m_rimReservoirView->eclipseCase() ) return; if ( !m_rimWell->showWell() ) return; if ( !m_rimWell->wellResults()->hasWellResult(frameIndex) ) return; if ( !m_rimWell->wellResults()->wellResultFrame(frameIndex).m_isOpen ) return; if ( m_rimWell->wellResults()->wellResultFrame(frameIndex).m_productionType == RigWellResultFrame::UNDEFINED_PRODUCTION_TYPE ) return; bool isProducer = (m_rimWell->wellResults()->wellResultFrame(frameIndex).m_productionType == RigWellResultFrame::PRODUCER); double pipeRadius = m_rimWell->pipeRadius(); cvf::Vec3d wellHeadTop; cvf::Vec3d wellHeadBottom; double characteristicCellSize; double mainArrowZHeight; cvf::ref displayCordXf; RigFlowDiagResults* flowResults; std::string injectorName; std::string producerName; double fluxWidthScale = 0.0; { RimEclipseResultCase* eclResCase = dynamic_cast(m_rimReservoirView->eclipseCase()); if ( !eclResCase ) return; if ( !eclResCase->defaultFlowDiagSolution() ) return; flowResults = eclResCase->defaultFlowDiagSolution()->flowDiagResults(); displayCordXf = m_rimReservoirView->displayCoordTransform(); RigEclipseCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->eclipseCaseData(); characteristicCellSize = rigReservoir->mainGrid()->characteristicIJCellSize(); m_rimWell->wellHeadTopBottomPosition(frameIndex, &wellHeadTop, &wellHeadBottom); wellHeadTop = displayCordXf->transformToDisplayCoord(wellHeadTop); wellHeadBottom = displayCordXf->transformToDisplayCoord(wellHeadBottom); wellHeadTop.z() += characteristicCellSize; cvf::Vec3d activeCellsBoundingBoxMax = displayCordXf->transformToDisplayCoord(m_rimReservoirView->currentActiveCellInfo()->geometryBoundingBox().max()); mainArrowZHeight = activeCellsBoundingBoxMax.z() - characteristicCellSize; // Above the bbox somewhat; if ( isProducer ) producerName = m_rimWell->name().toStdString(); else injectorName = m_rimWell->name().toStdString(); double maxAbsFlux = flowResults->maxAbsPairFlux(static_cast(frameIndex)); if (maxAbsFlux != 0.0) fluxWidthScale = characteristicCellSize / maxAbsFlux; } RimEclipseWellCollection* wellColl = m_rimReservoirView->wellCollection(); for ( RimEclipseWell * otherWell: wellColl->wells ) { if ( otherWell == m_rimWell ) continue; if ( !otherWell->showWell() ) continue; if ( !otherWell->wellResults()->hasWellResult(frameIndex) ) continue; if ( !otherWell->wellResults()->wellResultFrame(frameIndex).m_isOpen ) continue; if ( otherWell->wellResults()->wellResultFrame(frameIndex).m_productionType == RigWellResultFrame::UNDEFINED_PRODUCTION_TYPE ) continue; bool isOtherProducer = (otherWell->wellResults()->wellResultFrame(frameIndex).m_productionType == RigWellResultFrame::PRODUCER); if (isProducer == isOtherProducer) continue; if ( isOtherProducer ) producerName = otherWell->name().toStdString(); else injectorName = otherWell->name().toStdString(); std::pair injProdFluxPair = flowResults->injectorProducerPairFluxes(injectorName, producerName, static_cast(frameIndex)); if ( fabs(injProdFluxPair.first) < 1e-3 && fabs(injProdFluxPair.second) < 1e-3 ) continue; float width = fluxWidthScale * (isProducer ? injProdFluxPair.second: injProdFluxPair.first); cvf::Vec3d otherWellHeadTop; cvf::Vec3d otherWellHeadBottom; { otherWell->wellHeadTopBottomPosition(frameIndex, &otherWellHeadTop, &otherWellHeadBottom); otherWellHeadTop = displayCordXf->transformToDisplayCoord(otherWellHeadTop); otherWellHeadBottom = displayCordXf->transformToDisplayCoord(otherWellHeadBottom); otherWellHeadTop.z() += characteristicCellSize; } { cvf::Vec3f startPoint = cvf::Vec3f(0.5*(wellHeadTop + otherWellHeadTop)); startPoint.z() = mainArrowZHeight; cvf::Vec3f endPoint = cvf::Vec3f(wellHeadTop + (2* pipeRadius * (otherWellHeadTop - wellHeadTop).getNormalized())); cvf::ref part = new cvf::Part; cvf::ref geo = createArrow(startPoint, endPoint, width, isProducer); part->setDrawable(geo.p()); caf::SurfaceEffectGenerator surfaceGen(cvf::Color4f(otherWell->wellPipeColor()), caf::PO_1); cvf::ref eff = surfaceGen.generateCachedEffect(); part->setEffect(eff.p()); model->addPart(part.p()); } } } cvf::ref< cvf::DrawableGeo> RivWellConnectionsPartMgr::createArrow(const cvf::Vec3f& startPoint, const cvf::Vec3f& endPoint, double width, bool useArrowEnd) { // 0 2 4 6 8 10 12 14 // : flat : : : : flat : : : end // 1 3 5 7 9 11 13 15 // Producer end: // 16 // 18 // 17 static const cvf::uint producerArrowFaceList[7 * 5 + 4] ={ 4, 0, 1, 3, 2, 4, 2, 3, 5, 4, 4, 4, 5, 7, 6, 4, 6, 7, 9, 8, 4, 8, 9, 11, 10, 4, 10, 11, 13, 12, 4, 12, 13, 15, 14, 3, 16, 17, 18 }; // Injector end // 16 // 18 // 17 static const cvf::uint injectorArrowFaceList[7 * 5 + 8] ={ 4, 0, 1, 3, 2, 4, 2, 3, 5, 4, 4, 4, 5, 7, 6, 4, 6, 7, 9, 8, 4, 8, 9, 11, 10, 4, 10, 11, 13, 12, 4, 12, 13, 15, 14, 3, 14, 18, 16, 3, 18, 15, 17 }; cvf::Vec3f endPointInTopPlane = endPoint; endPointInTopPlane.z() = startPoint.z(); cvf::Vec3f heightDiff = cvf::Vec3f::ZERO; heightDiff.z() = 0.5*(startPoint.z() - endPoint.z()); cvf::Vec3f fromTo = endPointInTopPlane - startPoint; float halfWidth = width * 0.5; cvf::Vec3f widthVector = halfWidth *(fromTo.getNormalized() ^ -cvf::Vec3f::Z_AXIS); cvf::ref< cvf::Vec3fArray> arrowVertexArray = new cvf::Vec3fArray; arrowVertexArray->resize(16+3); (*arrowVertexArray)[0] = 0.0f* fromTo + startPoint + widthVector; (*arrowVertexArray)[1] = 0.0f* fromTo + startPoint - widthVector; (*arrowVertexArray)[2] = 0.7f* fromTo + startPoint + widthVector; (*arrowVertexArray)[3] = 0.7f* fromTo + startPoint - widthVector; (*arrowVertexArray)[4] = (0.04f + 0.7f)* fromTo + startPoint + widthVector + 0.05f * heightDiff; (*arrowVertexArray)[5] = (0.04f + 0.7f)* fromTo + startPoint - widthVector + 0.05f * heightDiff; (*arrowVertexArray)[6] = (2*0.04f + 0.7f)* fromTo + startPoint + widthVector + 0.15f * heightDiff; (*arrowVertexArray)[7] = (2*0.04f + 0.7f)* fromTo + startPoint - widthVector + 0.15f * heightDiff; (*arrowVertexArray)[8] = (3*0.04f + 0.7f)* fromTo + startPoint + widthVector + 0.2f * heightDiff; (*arrowVertexArray)[9] = (3*0.04f + 0.7f)* fromTo + startPoint - widthVector + 0.2f * heightDiff; (*arrowVertexArray)[10] = (4*0.04f + 0.7f)* fromTo + startPoint + widthVector + 0.175f * heightDiff; (*arrowVertexArray)[11] = (4*0.04f + 0.7f)* fromTo + startPoint - widthVector + 0.175f * heightDiff; (*arrowVertexArray)[12] = (5*0.04f + 0.7f)* fromTo + startPoint + widthVector; (*arrowVertexArray)[13] = (5*0.04f + 0.7f)* fromTo + startPoint - widthVector; (*arrowVertexArray)[14] = (6*0.04f + 0.7f)* fromTo + startPoint + widthVector - 0.5f * heightDiff; (*arrowVertexArray)[15] = (6*0.04f + 0.7f)* fromTo + startPoint - widthVector - 0.5f * heightDiff; if ( useArrowEnd ) { (*arrowVertexArray)[16] = (6*0.04f + 0.7f)* fromTo + startPoint + 1.1f*widthVector - 0.5f * heightDiff; (*arrowVertexArray)[17] = (6*0.04f + 0.7f)* fromTo + startPoint - 1.1f*widthVector - 0.5f * heightDiff; (*arrowVertexArray)[18] = 1.0f * fromTo + startPoint - 1.0f * heightDiff; } else { (*arrowVertexArray)[16] = 1.0f * fromTo + startPoint + 0.5f*widthVector - 1.0f * heightDiff; (*arrowVertexArray)[17] = 1.0f * fromTo + startPoint - 0.5f*widthVector - 1.0f * heightDiff; (*arrowVertexArray)[18] = (6*0.04f + 0.7f)* fromTo + startPoint - 0.5f * heightDiff; } cvf::ref geo = new cvf::DrawableGeo; geo->setVertexArray(arrowVertexArray.p()); if ( useArrowEnd ) geo->setFromFaceList(cvf::UIntArray(producerArrowFaceList, 7 * 5 + 4)); else geo->setFromFaceList(cvf::UIntArray(injectorArrowFaceList, 7 * 5 + 8)); return geo; }