Use branch index and branch cell index to identify branch head

Removed obsolete code
p4#: 21974
This commit is contained in:
Magne Sjaastad 2013-06-24 14:02:01 +02:00
parent 12a0040473
commit f02d4b160e
3 changed files with 150 additions and 173 deletions

View File

@ -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 lastCellIndexForSegmentId = cvf::UNDEFINED_SIZE_T;
size_t lastCellIndexForSegmentIdInOutletBranch = cvf::UNDEFINED_SIZE_T;
for (size_t outletCellIdx = 0; outletCellIdx < outletResultBranch.m_wellCells.size(); outletCellIdx++)
{
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 (lastCellIndexForSegmentIdInOutletBranch == cvf::UNDEFINED_SIZE_T)
{
if (outletResultBranch.m_wellCells[lastCellIndexForSegmentId].hasGridConnections())
{
wellResultBranch.m_branchHead = outletResultBranch.m_wellCells[lastCellIndexForSegmentId];
// 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
{
// There are no connections on outlet branch segment
// Add center coordinate of first connected well cell
RigWellResultCell& outletCell = outletResultBranch.m_wellCells[lastCellIndexForSegmentIdInOutletBranch];
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;
wellResultLeafBranch.m_outletBranchIndex = currentGridBranchStartIndex + outletErtBranchId;
wellResultLeafBranch.m_outletBranchHeadCellIndex = lastCellIndexForSegmentIdInOutletBranch;
}
}
if (firstCellWithGridConnection != cvf::UNDEFINED_SIZE_T)
// Update outlet well cells with no grid cell connections
for (int branchIdx = 0; branchIdx < branchCount; branchIdx++)
{
const RigCell& cell = m_eclipseCase->cellFromWellResultCell(wellResultBranch.m_wellCells[firstCellWithGridConnection]);
cvf::Vec3d coordToAdd = cell.center();
RigWellResultBranch& wellResultLeafBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx];
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<double>(coordCount + 1);
cvf::Vec3d toBeAdded = coordToAdd / static_cast<double>(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)
const RigWellResultCell* leafBranchHead = wellResFrame.findResultCellFromOutletSpecification(wellResultLeafBranch.m_outletBranchIndex, wellResultLeafBranch.m_outletBranchHeadCellIndex);
if (!leafBranchHead || leafBranchHead->hasGridConnections())
{
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];
RigWellResultBranch& outletResultBranch = wellResFrame.m_wellResultBranches[wellResultLeafBranch.m_outletBranchIndex];
for (int outletBranchCellIdx = 0; outletBranchCellIdx < outletResultBranch.m_wellCells.size(); outletBranchCellIdx++)
size_t firstCellIndexWithGridConnectionInLeafBranch = cvf::UNDEFINED_SIZE_T;
for (size_t j = 0; j < wellResultLeafBranch.m_wellCells.size(); j++)
{
if (outletResultBranch.m_wellCells[outletBranchCellIdx].m_ertSegmentId == branchHead.m_ertSegmentId)
if (wellResultLeafBranch.m_wellCells[j].hasGridConnections())
{
currentCellIndex = outletBranchCellIdx;
firstCellIndexWithGridConnectionInLeafBranch = j;
break;
}
}
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<double>(branchConnectionCount + 1);
cvf::Vec3d additionalWeightedCoord = firstGridConnectionCenterInLeafBranch / static_cast<double>(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
{
currentCellIndex--;
cellIndexInOutletBranch--;
}
if(currentCellIndex >= 0 && currentCellIndex < outletResultBranch.m_wellCells.size())
if(cellIndexInOutletBranch >= 0 && cellIndexInOutletBranch < outletResultBranch.m_wellCells.size())
{
currCell = outletResultBranch.m_wellCells[currentCellIndex];
currCell = outletResultBranch.m_wellCells[cellIndexInOutletBranch];
}
}
}
wellResultBranch.m_branchHead = outletCell;
}
}
}
else
{
// No branch head is assigned, use well head as fall back
wellResultBranch.m_branchHead = wellResFrame.m_wellHead;
}
CVF_ASSERT(wellResultBranch.m_branchHead.hasConnections());
}
}
}

View File

@ -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<RigWellResultBranch>& 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,26 +266,22 @@ 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
else if (leafBranchHead)
{
// 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::Vec3d interpolatedCoord = leafBranchHead->m_averageCenter;
CVF_ASSERT(interpolatedCoord != cvf::Vec3d::UNDEFINED);
if (interpolatedCoord != cvf::Vec3d::UNDEFINED)
@ -329,6 +290,9 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector
pipeBranchesCellIds.back().push_back(RigWellResultCell());
}
}
else
{
// 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)

View File

@ -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;
@ -83,11 +86,11 @@ struct RigWellResultBranch
// For standard wells, this is always well head.
RigWellResultCell m_branchHead;
// 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;
// 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;
};
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;