diff --git a/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp b/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp index 3303e4344c..3223777b0a 100644 --- a/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp +++ b/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp @@ -192,10 +192,10 @@ void RimSimWellInView::wellHeadTopBottomPosition(size_t frameIndex, cvf::Vec3d* RigEclipseCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->eclipseCaseData(); - if (!this->simWellData()->hasWellResult(frameIndex)) return; + if ( !this->simWellData()->hasAnyValidCells(frameIndex) ) return; const RigWellResultFrame& wellResultFrame = this->simWellData()->wellResultFrame(frameIndex); - const RigCell& whCell = rigReservoir->cellFromWellResultCell(wellResultFrame.m_wellHead); + const RigCell& whCell = rigReservoir->cellFromWellResultCell(wellResultFrame.wellHeadOrStartCell()); // Match this position with pipe start position in RivWellPipesPartMgr::calculateWellPipeCenterline() diff --git a/ApplicationCode/ReservoirDataModel/RigSimWellData.cpp b/ApplicationCode/ReservoirDataModel/RigSimWellData.cpp index 27333007ff..a37e6a0cf9 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimWellData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSimWellData.cpp @@ -97,6 +97,39 @@ bool RigSimWellData::hasWellResult(size_t resultTimeStepIndex) const return wellTimeStepIndex != cvf::UNDEFINED_SIZE_T; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigSimWellData::hasAnyValidCells(size_t resultTimeStepIndex) const +{ + if (resultTimeStepIndex >= m_resultTimeStepIndexToWellTimeStepIndex.size()) + { + return false; + } + + size_t wellTimeStepIndex = m_resultTimeStepIndexToWellTimeStepIndex[resultTimeStepIndex]; + + if( wellTimeStepIndex == cvf::UNDEFINED_SIZE_T) return false; + + if (wellResultFrame(resultTimeStepIndex).m_wellHead.isCell()) return true; + + const std::vector &resBranches = wellResultFrame(resultTimeStepIndex).m_wellResultBranches; + + for ( size_t i = 0 ; i < resBranches.size(); ++i ) + { + for (size_t cIdx = 0; cIdx < resBranches[i].m_branchResultPoints.size(); ++cIdx ) + { + if (resBranches[i].m_branchResultPoints[cIdx].isCell()) return true; + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- + bool operator== (const RigWellResultPoint& p1, const RigWellResultPoint& p2) { return @@ -340,3 +373,18 @@ const RigWellResultPoint* RigWellResultFrame::findResultCell(size_t gridIndex, s return NULL; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigWellResultPoint RigWellResultFrame::wellHeadOrStartCell() const +{ + if (m_wellHead.isCell()) return m_wellHead; + + if (m_wellResultBranches.size() && m_wellResultBranches.front().m_branchResultPoints.size() ) + { + return m_wellResultBranches.front().m_branchResultPoints.front(); + } + + return m_wellHead; // Nothing else to do +} diff --git a/ApplicationCode/ReservoirDataModel/RigSimWellData.h b/ApplicationCode/ReservoirDataModel/RigSimWellData.h index 44763f38b4..d945526d14 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimWellData.h +++ b/ApplicationCode/ReservoirDataModel/RigSimWellData.h @@ -166,6 +166,7 @@ public: const RigWellResultPoint* findResultCell(size_t gridIndex, size_t gridCellIndex) const; + RigWellResultPoint wellHeadOrStartCell() const; WellProductionType m_productionType; bool m_isOpen; RigWellResultPoint m_wellHead; @@ -187,6 +188,8 @@ public: bool isMultiSegmentWell() const; bool hasWellResult(size_t resultTimeStepIndex) const; + bool hasAnyValidCells(size_t resultTimeStepIndex) const; + const RigWellResultFrame& wellResultFrame(size_t resultTimeStepIndex) const; bool isOpen(size_t resultTimeStepIndex) const; RigWellResultFrame::WellProductionType wellProductionType(size_t resultTimeStepIndex) const; diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp index 935eed4617..630c81a733 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp @@ -91,8 +91,12 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellF std::vector> &pipeBranchesCLCoords, std::vector> &pipeBranchesCellIds) { + // Initialize the return arrays + pipeBranchesCLCoords.clear(); + pipeBranchesCellIds.clear(); + if ( !wellResults) return; - if ( timeStepIndex >= 0 && !wellResults->hasWellResult(timeStepIndex) ) return; + if ( timeStepIndex >= 0 && !wellResults->hasAnyValidCells(timeStepIndex) ) return; const RigWellResultFrame* wellFramePtr = nullptr; @@ -118,24 +122,14 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellF #endif const RigWellResultFrame& wellFrame = *wellFramePtr; - - // Initialize the return arrays - pipeBranchesCLCoords.clear(); - pipeBranchesCellIds.clear(); - - if ( wellFrame.m_wellResultBranches.size() == 0 ) return; + const std::vector& resBranches = wellFrame.m_wellResultBranches; // Well head // Match this position with well head position in RivWellHeadPartMgr::buildWellHeadParts() - const RigCell& whCell = eclipseCaseData->cellFromWellResultCell(wellFrame.m_wellHead); + const RigCell& whCell = eclipseCaseData->cellFromWellResultCell(wellFrame.wellHeadOrStartCell()); cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K); - const RigWellResultPoint* whResCell = &(wellFrame.m_wellHead); - - - const std::vector& resBranches = wellFrame.m_wellResultBranches; - - if ( ! hasAnyResultCells(resBranches) ) return; + const RigWellResultPoint* whResCell = &(wellFrame.wellHeadOrStartCell()); // Add extra coordinate between cell face and cell center // to make sure the well pipe terminated in a segment parallel to z-axis @@ -594,7 +588,7 @@ public: // Calculate wellhead to branch line ends distances { - const RigCell& whCell = m_eclipseCaseData->cellFromWellResultCell(m_orgWellResultFrame.m_wellHead); + const RigCell& whCell = m_eclipseCaseData->cellFromWellResultCell(m_orgWellResultFrame.wellHeadOrStartCell()); cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K); buildResBranchToBranchLineEndsDistMap(whStartPos, -1); @@ -693,7 +687,7 @@ private: m_branchedWell.m_wellResultBranches.push_back(RigWellResultBranch()); branchIdx = static_cast( m_branchedWell.m_wellResultBranches.size()) - 1; RigWellResultPoint wellHeadAsPoint; - const RigCell& whCell = m_eclipseCaseData->cellFromWellResultCell(m_orgWellResultFrame.m_wellHead); + const RigCell& whCell = m_eclipseCaseData->cellFromWellResultCell(m_orgWellResultFrame.wellHeadOrStartCell()); cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K); wellHeadAsPoint.m_bottomPosition = whStartPos;