From f02d4b160e380b452e4aaafe806b177efd9439cc Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 24 Jun 2013 14:02:01 +0200 Subject: [PATCH] Use branch index and branch cell index to identify branch head Removed obsolete code p4#: 21974 --- .../FileInterface/RifReaderEclipseOutput.cpp | 213 +++++++++--------- .../RivWellPipesPartMgr.cpp | 70 ++---- .../RigSingleWellResultsData.h | 40 +++- 3 files changed, 150 insertions(+), 173 deletions(-) diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index f5ba9162e6..7a93a5df95 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -995,128 +995,123 @@ void RifReaderEclipseOutput::readWellCells(const ecl_grid_type* mainEclGrid) if (well_state_is_MSW(ert_well_state)) { + + // Assign outlet well cells to leaf branch well heads + for (int branchIdx = 0; branchIdx < branchCount; branchIdx++) { - RigWellResultBranch& wellResultBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx]; + RigWellResultBranch& wellResultLeafBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx]; const well_segment_type* outletBranchSegment = outletBranchSegmentList[branchIdx]; - if (outletBranchSegment) + CVF_ASSERT(outletBranchSegment); + + int outletErtBranchId = well_segment_get_branch_id(outletBranchSegment); + + RigWellResultBranch& outletResultBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + outletErtBranchId]; + + int outletErtSegmentId = well_segment_get_branch_id(outletBranchSegment); + size_t lastCellIndexForSegmentIdInOutletBranch = cvf::UNDEFINED_SIZE_T; + for (size_t outletCellIdx = 0; outletCellIdx < outletResultBranch.m_wellCells.size(); outletCellIdx++) { - int outletErtBranchId = well_segment_get_branch_id(outletBranchSegment); - - RigWellResultBranch& outletResultBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + outletErtBranchId]; - - int outletErtSegmentId = well_segment_get_branch_id(outletBranchSegment); - size_t lastCellIndexForSegmentId = cvf::UNDEFINED_SIZE_T; - for (size_t outletCellIdx = 0; outletCellIdx < outletResultBranch.m_wellCells.size(); outletCellIdx++) + if (outletResultBranch.m_wellCells[outletCellIdx].m_ertSegmentId == outletErtSegmentId) { - if (outletResultBranch.m_wellCells[outletCellIdx].m_ertSegmentId == outletErtSegmentId) - { - lastCellIndexForSegmentId = outletCellIdx; - } + lastCellIndexForSegmentIdInOutletBranch = outletCellIdx; } + } - CVF_ASSERT(lastCellIndexForSegmentId != cvf::UNDEFINED_SIZE_T); - - if (lastCellIndexForSegmentId != cvf::UNDEFINED_SIZE_T) - { - if (outletResultBranch.m_wellCells[lastCellIndexForSegmentId].hasGridConnections()) - { - wellResultBranch.m_branchHead = outletResultBranch.m_wellCells[lastCellIndexForSegmentId]; - } - else - { - // There are no connections on outlet branch segment - // Add center coordinate of first connected well cell - - RigWellResultCell& outletCell = outletResultBranch.m_wellCells[lastCellIndexForSegmentId]; - - size_t firstCellWithGridConnection = cvf::UNDEFINED_SIZE_T; - for (size_t j = 0; j < wellResultBranch.m_wellCells.size(); j++) - { - if (wellResultBranch.m_wellCells[j].hasGridConnections()) - { - firstCellWithGridConnection = j; - break; - } - } - - if (firstCellWithGridConnection != cvf::UNDEFINED_SIZE_T) - { - const RigCell& cell = m_eclipseCase->cellFromWellResultCell(wellResultBranch.m_wellCells[firstCellWithGridConnection]); - cvf::Vec3d coordToAdd = cell.center(); - - size_t currentCellIndex = lastCellIndexForSegmentId; - RigWellResultCell& currCell = outletResultBranch.m_wellCells[currentCellIndex]; - - while (currentCellIndex != cvf::UNDEFINED_SIZE_T && !currCell.hasGridConnections()) - { - size_t coordCount = currCell.m_connectedBranchCount; - if (coordCount == 0) - { - currCell.m_interpolatedCenter = coordToAdd; - } - else - { - cvf::Vec3d tmp = currCell.m_interpolatedCenter * coordCount / static_cast(coordCount + 1); - cvf::Vec3d toBeAdded = coordToAdd / static_cast(coordCount + 1); - - currCell.m_interpolatedCenter = tmp + toBeAdded; - } - - currCell.m_connectedBranchCount++; - - if (currentCellIndex == 0) - { - currentCellIndex = cvf::UNDEFINED_SIZE_T; - - // Find the branch the outlet is connected to, and continue update of - // segments until a segment with a grid connection is found - RigWellResultCell& branchHead = outletResultBranch.m_branchHead; - if (branchHead.m_ertBranchId == -1 || currCell.m_ertBranchId == branchHead.m_ertBranchId) - { - continue; - } - - for (int outletBranchIdx = 0; outletBranchIdx < branchCount; outletBranchIdx++) - { - if (wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + outletBranchIdx].m_ertBranchId == branchHead.m_ertBranchId) - { - outletResultBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + outletBranchIdx]; - - for (int outletBranchCellIdx = 0; outletBranchCellIdx < outletResultBranch.m_wellCells.size(); outletBranchCellIdx++) - { - if (outletResultBranch.m_wellCells[outletBranchCellIdx].m_ertSegmentId == branchHead.m_ertSegmentId) - { - currentCellIndex = outletBranchCellIdx; - } - } - } - } - } - else - { - currentCellIndex--; - } - - if(currentCellIndex >= 0 && currentCellIndex < outletResultBranch.m_wellCells.size()) - { - currCell = outletResultBranch.m_wellCells[currentCellIndex]; - } - } - } - - wellResultBranch.m_branchHead = outletCell; - } - } + if (lastCellIndexForSegmentIdInOutletBranch == cvf::UNDEFINED_SIZE_T) + { + // Did not find the cell in the outlet branch based on branch id and segment id from outlet cell in leaf branch + // CVF_ASSERT(0); } else { - // No branch head is assigned, use well head as fall back - wellResultBranch.m_branchHead = wellResFrame.m_wellHead; + RigWellResultCell& outletCell = outletResultBranch.m_wellCells[lastCellIndexForSegmentIdInOutletBranch]; + + wellResultLeafBranch.m_outletBranchIndex = currentGridBranchStartIndex + outletErtBranchId; + wellResultLeafBranch.m_outletBranchHeadCellIndex = lastCellIndexForSegmentIdInOutletBranch; + } + } + + + // Update outlet well cells with no grid cell connections + + for (int branchIdx = 0; branchIdx < branchCount; branchIdx++) + { + RigWellResultBranch& wellResultLeafBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx]; + + const RigWellResultCell* leafBranchHead = wellResFrame.findResultCellFromOutletSpecification(wellResultLeafBranch.m_outletBranchIndex, wellResultLeafBranch.m_outletBranchHeadCellIndex); + if (!leafBranchHead || leafBranchHead->hasGridConnections()) + { + continue; + } + + RigWellResultBranch& outletResultBranch = wellResFrame.m_wellResultBranches[wellResultLeafBranch.m_outletBranchIndex]; + + size_t firstCellIndexWithGridConnectionInLeafBranch = cvf::UNDEFINED_SIZE_T; + for (size_t j = 0; j < wellResultLeafBranch.m_wellCells.size(); j++) + { + if (wellResultLeafBranch.m_wellCells[j].hasGridConnections()) + { + firstCellIndexWithGridConnectionInLeafBranch = j; + break; + } } - CVF_ASSERT(wellResultBranch.m_branchHead.hasConnections()); + if (firstCellIndexWithGridConnectionInLeafBranch != cvf::UNDEFINED_SIZE_T) + { + const RigCell& firstCellWithGridConnectionInLeafBranch = m_eclipseCase->cellFromWellResultCell(wellResultLeafBranch.m_wellCells[firstCellIndexWithGridConnectionInLeafBranch]); + cvf::Vec3d firstGridConnectionCenterInLeafBranch = firstCellWithGridConnectionInLeafBranch.center(); + + size_t cellIndexInOutletBranch = wellResultLeafBranch.m_outletBranchHeadCellIndex; + CVF_ASSERT(cellIndexInOutletBranch != cvf::UNDEFINED_SIZE_T); + + RigWellResultCell& currCell = outletResultBranch.m_wellCells[cellIndexInOutletBranch]; + + while (cellIndexInOutletBranch != cvf::UNDEFINED_SIZE_T && !currCell.hasGridConnections()) + { + size_t branchConnectionCount = currCell.m_branchConnectionCount; + if (branchConnectionCount == 0) + { + currCell.m_averageCenter = firstGridConnectionCenterInLeafBranch; + } + else + { + cvf::Vec3d currentWeightedCoord = currCell.m_averageCenter * branchConnectionCount / static_cast(branchConnectionCount + 1); + cvf::Vec3d additionalWeightedCoord = firstGridConnectionCenterInLeafBranch / static_cast(branchConnectionCount + 1); + + currCell.m_averageCenter = currentWeightedCoord + additionalWeightedCoord; + } + + currCell.m_branchConnectionCount++; + + if (cellIndexInOutletBranch == 0) + { + cellIndexInOutletBranch = cvf::UNDEFINED_SIZE_T; + + // Find the branch the outlet is connected to, and continue update of + // segments until a segment with a grid connection is found + const RigWellResultCell* leafBranchHead = wellResFrame.findResultCellFromOutletSpecification(outletResultBranch.m_outletBranchIndex, outletResultBranch.m_outletBranchHeadCellIndex); + + if (leafBranchHead && + !leafBranchHead->hasGridConnections() && + leafBranchHead->m_ertBranchId != outletResultBranch.m_ertBranchId) + { + outletResultBranch = wellResFrame.m_wellResultBranches[outletResultBranch.m_outletBranchIndex]; + cellIndexInOutletBranch = outletResultBranch.m_outletBranchHeadCellIndex; + } + } + else + { + cellIndexInOutletBranch--; + } + + if(cellIndexInOutletBranch >= 0 && cellIndexInOutletBranch < outletResultBranch.m_wellCells.size()) + { + currCell = outletResultBranch.m_wellCells[cellIndexInOutletBranch]; + } + } + } } } } diff --git a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp index c6a22373a8..45c9c7133e 100644 --- a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp @@ -161,41 +161,6 @@ void RivWellPipesPartMgr::buildWellPipeParts() m_needsTransformUpdate = false; } -bool isIdentical(const RigWellResultCell* a, const RigWellResultCell* b) -{ - CVF_ASSERT(a && b); - - if (a->m_gridCellIndex != b->m_gridCellIndex) return false; - if (a->m_gridIndex != b->m_gridIndex) return false; - - return true; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const RigWellResultCell* findOutletWellResultCell(const RigWellResultCell& branchHead, const std::vector& wellResultBranches, RigCaseData* rigCaseData) -{ - CVF_ASSERT(rigCaseData); - - for (size_t i = 0; i < wellResultBranches.size(); i++) - { - if (wellResultBranches[i].m_ertBranchId == branchHead.m_ertBranchId) - { - for (size_t cellIdx = 0; cellIdx < wellResultBranches[i].m_wellCells.size(); cellIdx++) - { - if (wellResultBranches[i].m_wellCells[cellIdx].m_ertSegmentId == branchHead.m_ertSegmentId) - { - return &(wellResultBranches[i].m_wellCells[cellIdx]); - } - } - } - } - - return NULL; -} - //-------------------------------------------------------------------------------------------------- /// @@ -301,34 +266,33 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector } else { - if (resBranches[brIdx].m_branchHead.hasGridConnections()) + const RigWellResultCell* leafBranchHead = staticWellFrame.findResultCellFromOutletSpecification(resBranches[brIdx].m_outletBranchIndex, resBranches[brIdx].m_outletBranchHeadCellIndex); + if (leafBranchHead && leafBranchHead->hasGridConnections()) { // Create a new branch and use branch head as previous result cell - prevResCell = &(resBranches[brIdx].m_branchHead); + prevResCell = leafBranchHead; - const RigCell& cell = rigReservoir->cellFromWellResultCell(resBranches[brIdx].m_branchHead); + const RigCell& cell = rigReservoir->cellFromWellResultCell(*leafBranchHead); cvf::Vec3d branchHeadStartPos = cell.faceCenter(cvf::StructGridInterface::NEG_K); pipeBranchesCLCoords.back().push_back(branchHeadStartPos); pipeBranchesCellIds.back().push_back(*prevResCell); } + else if (leafBranchHead) + { + cvf::Vec3d interpolatedCoord = leafBranchHead->m_averageCenter; + + CVF_ASSERT(interpolatedCoord != cvf::Vec3d::UNDEFINED); + if (interpolatedCoord != cvf::Vec3d::UNDEFINED) + { + pipeBranchesCLCoords.back().push_back(interpolatedCoord); + pipeBranchesCellIds.back().push_back(RigWellResultCell()); + } + } else { - // Find outlet well result cell - const RigWellResultCell* outletCell = findOutletWellResultCell(resBranches[brIdx].m_branchHead, resBranches, rigReservoir); - CVF_ASSERT(outletCell); - if (outletCell) - { - cvf::Vec3d interpolatedCoord = outletCell->m_interpolatedCenter; - - CVF_ASSERT(interpolatedCoord != cvf::Vec3d::UNDEFINED); - if (interpolatedCoord != cvf::Vec3d::UNDEFINED) - { - pipeBranchesCLCoords.back().push_back(interpolatedCoord); - pipeBranchesCellIds.back().push_back(RigWellResultCell()); - } - } + // No well head found } } } @@ -351,7 +315,7 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector if (resCell.hasBranchConnections()) { // Use the interpolated value of branch head - cvf::Vec3d interpolatedCoord = resCell.m_interpolatedCenter; + cvf::Vec3d interpolatedCoord = resCell.m_averageCenter; CVF_ASSERT(interpolatedCoord != cvf::Vec3d::UNDEFINED); if (interpolatedCoord != cvf::Vec3d::UNDEFINED) diff --git a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h index d5d918748b..3954c0d11b 100644 --- a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h @@ -35,13 +35,13 @@ struct RigWellResultCell m_isOpen(false), m_ertBranchId(-1), m_ertSegmentId(-1), - m_interpolatedCenter(cvf::Vec3d::UNDEFINED), - m_connectedBranchCount(0) + m_averageCenter(cvf::Vec3d::UNDEFINED), + m_branchConnectionCount(0) { } bool hasBranchConnections() const { - return m_connectedBranchCount != 0; + return m_branchConnectionCount != 0; } bool hasGridConnections() const @@ -63,17 +63,20 @@ struct RigWellResultCell int m_ertBranchId; int m_ertSegmentId; - cvf::Vec3d m_interpolatedCenter; - size_t m_connectedBranchCount; + cvf::Vec3d m_averageCenter; + size_t m_branchConnectionCount; }; struct RigWellResultBranch { RigWellResultBranch() : m_branchIndex(cvf::UNDEFINED_SIZE_T), - m_ertBranchId(-1) + m_ertBranchId(-1), + m_outletBranchIndex(cvf::UNDEFINED_SIZE_T), + m_outletBranchHeadCellIndex(cvf::UNDEFINED_SIZE_T) {} + size_t m_branchIndex; int m_ertBranchId; @@ -82,12 +85,12 @@ struct RigWellResultBranch // Grid cell from last connection in outlet segment. For MSW wells, this is either well head or a well result cell in another branch // For standard wells, this is always well head. RigWellResultCell m_branchHead; + + // Grid cell from last connection in outlet segment. For MSW wells, this is either well head or a well result cell in another branch + // For standard wells, this is always well head. + size_t m_outletBranchIndex; + size_t m_outletBranchHeadCellIndex; - // If the outlet segment does not have any connections, it is not possible to populate branch head - // Instead, use the intersection segment outlet branch index and the depth of this segment to identify intersection point - // when computing centerline coords in RivWellPipesPartMgr - int m_outletErtBranchId; - double m_connectionDepthOnOutletBranch; }; class RigWellResultFrame @@ -125,6 +128,21 @@ public: return NULL; } + const RigWellResultCell* findResultCellFromOutletSpecification(size_t branchIndex, size_t wellResultCellIndex) const + { + if (branchIndex != cvf::UNDEFINED_SIZE_T && branchIndex < m_wellResultBranches.size()) + { + const RigWellResultBranch& resBranch = m_wellResultBranches[branchIndex]; + if (wellResultCellIndex != cvf::UNDEFINED_SIZE_T && wellResultCellIndex < resBranch.m_wellCells.size()) + { + return (&resBranch.m_wellCells[wellResultCellIndex]); + } + } + + return NULL; + } + + WellProductionType m_productionType; bool m_isOpen; RigWellResultCell m_wellHead;