mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#633) Moved well centerline calculation to make it available for cross sections
This commit is contained in:
parent
f18ad19fe2
commit
faf35d32c6
@ -49,6 +49,7 @@
|
|||||||
#include "cvfRay.h"
|
#include "cvfRay.h"
|
||||||
#include "cvfScalarMapperDiscreteLinear.h"
|
#include "cvfScalarMapperDiscreteLinear.h"
|
||||||
#include "cvfTransform.h"
|
#include "cvfTransform.h"
|
||||||
|
#include "RigSimulationWellCenterLineCalculator.h"
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -101,7 +102,7 @@ void RivWellPipesPartMgr::buildWellPipeParts()
|
|||||||
m_pipeBranchesCLCoords.clear();
|
m_pipeBranchesCLCoords.clear();
|
||||||
std::vector< std::vector <RigWellResultPoint> > pipeBranchesCellIds;
|
std::vector< std::vector <RigWellResultPoint> > pipeBranchesCellIds;
|
||||||
|
|
||||||
calculateWellPipeCenterline(m_pipeBranchesCLCoords, pipeBranchesCellIds);
|
RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(m_rimWell.p(), m_pipeBranchesCLCoords, pipeBranchesCellIds);
|
||||||
|
|
||||||
double characteristicCellSize = m_rimReservoirView->eclipseCase()->reservoirData()->mainGrid()->characteristicIJCellSize();
|
double characteristicCellSize = m_rimReservoirView->eclipseCase()->reservoirData()->mainGrid()->characteristicIJCellSize();
|
||||||
double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() *m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize;
|
double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() *m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize;
|
||||||
@ -167,351 +168,6 @@ void RivWellPipesPartMgr::buildWellPipeParts()
|
|||||||
m_needsTransformUpdate = false;
|
m_needsTransformUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/// Based on the points and cells, calculate a pipe centerline
|
|
||||||
/// The returned CellIds is one less than the number of centerline points,
|
|
||||||
/// and are describing the lines between the points, starting with the first line
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
|
|
||||||
std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds) const
|
|
||||||
{
|
|
||||||
CVF_ASSERT(m_rimWell.notNull());
|
|
||||||
CVF_ASSERT(m_rimReservoirView.notNull());
|
|
||||||
|
|
||||||
bool isAutoDetectBranches = m_rimReservoirView->wellCollection()->isAutoDetectingBranches();
|
|
||||||
|
|
||||||
RigCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData();
|
|
||||||
RigSingleWellResultsData* wellResults = m_rimWell->wellResults();
|
|
||||||
|
|
||||||
// Make sure we have computed the static representation of the well
|
|
||||||
if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0)
|
|
||||||
{
|
|
||||||
wellResults->computeStaticWellCellPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
const RigWellResultFrame& staticWellFrame = wellResults->m_staticWellCells;
|
|
||||||
if (staticWellFrame.m_wellResultBranches.size() == 0) return;
|
|
||||||
|
|
||||||
// Initialize the return arrays
|
|
||||||
pipeBranchesCLCoords.clear();
|
|
||||||
pipeBranchesCellIds.clear();
|
|
||||||
|
|
||||||
// Well head
|
|
||||||
// Match this position with well head position in RivWellHeadPartMgr::buildWellHeadParts()
|
|
||||||
const RigCell& whCell = rigReservoir->cellFromWellResultCell(staticWellFrame.m_wellHead);
|
|
||||||
cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K);
|
|
||||||
const RigWellResultPoint* whResCell = &(staticWellFrame.m_wellHead);
|
|
||||||
|
|
||||||
// Loop over all the well branches
|
|
||||||
const std::vector<RigWellResultBranch>& resBranches = staticWellFrame.m_wellResultBranches;
|
|
||||||
bool hasResultCells = false;
|
|
||||||
if (resBranches.size())
|
|
||||||
{
|
|
||||||
for (size_t i = 0 ; i < resBranches.size(); ++i)
|
|
||||||
{
|
|
||||||
if (resBranches[i].m_branchResultPoints.size() != 0)
|
|
||||||
{
|
|
||||||
hasResultCells = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasResultCells)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Add extra coordinate between cell face and cell center
|
|
||||||
// to make sure the well pipe terminated in a segment parallel to z-axis
|
|
||||||
cvf::Vec3d whIntermediate = whStartPos;
|
|
||||||
whIntermediate.z() = (whStartPos.z() + whCell.center().z()) / 2.0;
|
|
||||||
|
|
||||||
const RigWellResultPoint* prevWellResPoint = NULL;
|
|
||||||
|
|
||||||
CVF_ASSERT(wellResults->isMultiSegmentWell() || resBranches.size() <= 1);
|
|
||||||
|
|
||||||
// The centerline is calculated by adding a point when the pipe enters a cell,
|
|
||||||
// and one when the line leaves the cell.
|
|
||||||
// For the sake of the loop:
|
|
||||||
// The currentResultPoint (Cell) and the one we index by the loop variable is the one we calculate the entry point to.
|
|
||||||
// The previous cell is the one we leave, and calculate the "out-point" from
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++)
|
|
||||||
{
|
|
||||||
|
|
||||||
// Skip empty branches. Do not know why they exist, but they make problems.
|
|
||||||
|
|
||||||
bool hasValidData = false;
|
|
||||||
for (size_t cIdx = 0; cIdx < resBranches[brIdx].m_branchResultPoints.size(); ++cIdx)
|
|
||||||
{
|
|
||||||
if (resBranches[brIdx].m_branchResultPoints[cIdx].isValid())
|
|
||||||
{
|
|
||||||
hasValidData = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasValidData) continue;
|
|
||||||
|
|
||||||
|
|
||||||
prevWellResPoint = NULL;
|
|
||||||
|
|
||||||
// Find the start the MSW well-branch centerline. Normal wells are started "once" at wellhead in the code above
|
|
||||||
|
|
||||||
pipeBranchesCLCoords.push_back(std::vector<cvf::Vec3d>());
|
|
||||||
pipeBranchesCellIds.push_back(std::vector <RigWellResultPoint>());
|
|
||||||
|
|
||||||
if (brIdx == 0)
|
|
||||||
{
|
|
||||||
// The first branch contains segment number 1, and this is the only segment connected to well head
|
|
||||||
// See Eclipse documentation for the keyword WELSEGS
|
|
||||||
prevWellResPoint = whResCell;
|
|
||||||
|
|
||||||
pipeBranchesCLCoords.back().push_back(whStartPos);
|
|
||||||
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
|
||||||
|
|
||||||
pipeBranchesCLCoords.back().push_back(whIntermediate);
|
|
||||||
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop over all the resultPoints in the branch
|
|
||||||
|
|
||||||
const std::vector<RigWellResultPoint>& resBranchCells = resBranches[brIdx].m_branchResultPoints;
|
|
||||||
|
|
||||||
for (int cIdx = 0; cIdx < static_cast<int>(resBranchCells.size()); cIdx++) // Need int because cIdx can temporarily end on -1
|
|
||||||
{
|
|
||||||
std::vector<cvf::Vec3d>& branchCLCoords = pipeBranchesCLCoords.back();
|
|
||||||
std::vector<RigWellResultPoint>& branchCellIds = pipeBranchesCellIds.back();
|
|
||||||
|
|
||||||
const RigWellResultPoint& currentWellResPoint = resBranchCells[cIdx];
|
|
||||||
|
|
||||||
// Ignore invalid cells
|
|
||||||
|
|
||||||
if (!currentWellResPoint.isValid())
|
|
||||||
{
|
|
||||||
//CVF_ASSERT(false); // Some segments does not get anything yet.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add cl contribution for a geometrical resultPoint by adding exit point from previous cell,
|
|
||||||
// and then the result point position
|
|
||||||
|
|
||||||
if (!currentWellResPoint.isCell())
|
|
||||||
{
|
|
||||||
// Use the interpolated value of branch head
|
|
||||||
CVF_ASSERT(currentWellResPoint.isPointValid());
|
|
||||||
|
|
||||||
cvf::Vec3d currentPoint = currentWellResPoint.m_bottomPosition;
|
|
||||||
|
|
||||||
// If we have a real previous cell, we need to go out of it, before adding the current point
|
|
||||||
// That is: add a CL-point describing where it leaves the previous cell.
|
|
||||||
|
|
||||||
if (prevWellResPoint && prevWellResPoint->isCell())
|
|
||||||
{
|
|
||||||
// Create ray between the previous and this position
|
|
||||||
|
|
||||||
const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint);
|
|
||||||
cvf::Vec3d centerPreviousCell = prevCell.center();
|
|
||||||
|
|
||||||
cvf::Ray rayToThisCell;
|
|
||||||
rayToThisCell.setOrigin(centerPreviousCell);
|
|
||||||
rayToThisCell.setDirection((currentPoint - centerPreviousCell).getNormalized());
|
|
||||||
|
|
||||||
cvf::Vec3d outOfPrevCell(centerPreviousCell);
|
|
||||||
|
|
||||||
//int intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell);
|
|
||||||
//CVF_ASSERT(intersectionOk);
|
|
||||||
//CVF_ASSERT(intersectionOk);
|
|
||||||
if ((currentPoint - outOfPrevCell).lengthSquared() > 1e-3)
|
|
||||||
{
|
|
||||||
branchCLCoords.push_back(outOfPrevCell);
|
|
||||||
branchCellIds.push_back(RigWellResultPoint());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
branchCLCoords.push_back(currentPoint);
|
|
||||||
branchCellIds.push_back(currentWellResPoint);
|
|
||||||
|
|
||||||
prevWellResPoint = ¤tWellResPoint;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Handle currentWellResPoint as a real cell result points.
|
|
||||||
//
|
|
||||||
|
|
||||||
const RigCell& cell = rigReservoir->cellFromWellResultCell(currentWellResPoint);
|
|
||||||
|
|
||||||
// Check if this and the previous cells has shared faces
|
|
||||||
|
|
||||||
cvf::StructGridInterface::FaceType sharedFace;
|
|
||||||
if (prevWellResPoint && prevWellResPoint->isCell() && rigReservoir->findSharedSourceFace(sharedFace, currentWellResPoint, *prevWellResPoint))
|
|
||||||
{
|
|
||||||
// If they share faces, the shared face center is used as point
|
|
||||||
// describing the entry of this cell. (And exit of the previous cell)
|
|
||||||
|
|
||||||
branchCLCoords.push_back(cell.faceCenter(sharedFace));
|
|
||||||
branchCellIds.push_back(currentWellResPoint);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// This and the previous cell does not share a face.
|
|
||||||
// Then we need to calculate the exit of the previous cell, and the entry point into this cell
|
|
||||||
|
|
||||||
cvf::Vec3d centerPreviousCell(cvf::Vec3d::ZERO);
|
|
||||||
cvf::Vec3d centerThisCell = cell.center();
|
|
||||||
bool distanceToWellHeadIsLonger = true;
|
|
||||||
|
|
||||||
// If we have a previous well result point, use its center as measure point and ray intersection start
|
|
||||||
// when considering things.
|
|
||||||
|
|
||||||
if (prevWellResPoint && prevWellResPoint->isValid())
|
|
||||||
{
|
|
||||||
if (prevWellResPoint->isCell())
|
|
||||||
{
|
|
||||||
const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint);
|
|
||||||
centerPreviousCell = prevCell.center();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
centerPreviousCell = prevWellResPoint->m_bottomPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
distanceToWellHeadIsLonger = (centerThisCell - centerPreviousCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// First make sure this cell is not starting a new "display" branch for none MSW's
|
|
||||||
|
|
||||||
if ( wellResults->isMultiSegmentWell()
|
|
||||||
|| !isAutoDetectBranches
|
|
||||||
|| (prevWellResPoint == whResCell)
|
|
||||||
|| distanceToWellHeadIsLonger)
|
|
||||||
{
|
|
||||||
// Not starting a "display" branch for normal wells
|
|
||||||
// Calculate the exit of the previous cell, and the entry point into this cell
|
|
||||||
|
|
||||||
cvf::Vec3d intoThisCell(centerThisCell); // Use cell center as default for "into" point.
|
|
||||||
|
|
||||||
if (prevWellResPoint && prevWellResPoint->isValid())
|
|
||||||
{
|
|
||||||
// We have a defined previous point
|
|
||||||
// Create ray between the previous and this cell
|
|
||||||
|
|
||||||
cvf::Ray rayToThisCell;
|
|
||||||
rayToThisCell.setOrigin(centerPreviousCell);
|
|
||||||
rayToThisCell.setDirection((centerThisCell - centerPreviousCell).getNormalized());
|
|
||||||
|
|
||||||
// Intersect with the current cell to find a better entry point than the cell center
|
|
||||||
|
|
||||||
int intersectionCount = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell);
|
|
||||||
bool isPreviousResPointInsideCurrentCell = (intersectionCount % 2); // Must intersect uneven times to be inside. (1 % 2 = 1)
|
|
||||||
|
|
||||||
// If we have a real previous cell, we need to go out of it, before entering this.
|
|
||||||
// That is: add a CL-point describing where it leaves the previous cell.
|
|
||||||
|
|
||||||
if ( prevWellResPoint->isCell())
|
|
||||||
{
|
|
||||||
cvf::Vec3d outOfPrevCell(centerPreviousCell);
|
|
||||||
|
|
||||||
const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint);
|
|
||||||
//bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell);
|
|
||||||
//CVF_ASSERT(intersectionOk);
|
|
||||||
//CVF_ASSERT(intersectionOk);
|
|
||||||
if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3)
|
|
||||||
{
|
|
||||||
branchCLCoords.push_back(outOfPrevCell);
|
|
||||||
branchCellIds.push_back(RigWellResultPoint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (isPreviousResPointInsideCurrentCell)
|
|
||||||
{
|
|
||||||
// Since the previous point actually is inside this cell,
|
|
||||||
/// use that as the entry point into this cell
|
|
||||||
intoThisCell = centerPreviousCell;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
branchCLCoords.push_back(intoThisCell);
|
|
||||||
branchCellIds.push_back(currentWellResPoint);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Need to start a "display branch" for a Normal Well.
|
|
||||||
|
|
||||||
CVF_ASSERT(!wellResults->isMultiSegmentWell());
|
|
||||||
|
|
||||||
// This cell is further from the previous cell than from the well head,
|
|
||||||
// thus we interpret it as a new branch.
|
|
||||||
|
|
||||||
// First finish the current branch in the previous cell
|
|
||||||
//branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPreviousCell - branchCLCoords.back()) );
|
|
||||||
finishPipeCenterLine(pipeBranchesCLCoords, centerPreviousCell);
|
|
||||||
|
|
||||||
// Create new display branch
|
|
||||||
pipeBranchesCLCoords.push_back(std::vector<cvf::Vec3d>());
|
|
||||||
pipeBranchesCellIds.push_back(std::vector <RigWellResultPoint>());
|
|
||||||
|
|
||||||
// Start the new branch by entering the first cell (the wellhead) and intermediate
|
|
||||||
prevWellResPoint = whResCell;
|
|
||||||
pipeBranchesCLCoords.back().push_back(whStartPos);
|
|
||||||
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
|
||||||
|
|
||||||
// Include intermediate
|
|
||||||
pipeBranchesCLCoords.back().push_back(whIntermediate);
|
|
||||||
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
|
||||||
|
|
||||||
// Well now we need to step one back to take this cell again, but in the new branch.
|
|
||||||
cIdx--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prevWellResPoint = ¤tWellResPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the last cell, add the point 0.5 past the center of that cell
|
|
||||||
// Remember that prevWellResPoint actually is the last one in this branch.
|
|
||||||
|
|
||||||
cvf::Vec3d centerLastCell;
|
|
||||||
if (prevWellResPoint && prevWellResPoint->isCell())
|
|
||||||
{
|
|
||||||
const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint);
|
|
||||||
centerLastCell = prevCell.center();
|
|
||||||
finishPipeCenterLine(pipeBranchesCLCoords, centerLastCell);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Remove the ID that is superfluous since we will not add an ending point
|
|
||||||
pipeBranchesCellIds.back().pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CVF_ASSERT(pipeBranchesCellIds.size() == pipeBranchesCLCoords.size());
|
|
||||||
for (size_t i = 0 ; i < pipeBranchesCellIds.size() ; ++i)
|
|
||||||
{
|
|
||||||
CVF_ASSERT(pipeBranchesCellIds[i].size() == pipeBranchesCLCoords[i].size()-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/// All branches are completed using the point 0.5 past the center of
|
|
||||||
/// last cell.
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RivWellPipesPartMgr::finishPipeCenterLine(std::vector< std::vector<cvf::Vec3d> > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter) const
|
|
||||||
{
|
|
||||||
CVF_ASSERT(pipeBranchesCLCoords.size());
|
|
||||||
CVF_ASSERT(pipeBranchesCLCoords.back().size());
|
|
||||||
|
|
||||||
cvf::Vec3d entryPointLastCell = pipeBranchesCLCoords.back().back();
|
|
||||||
|
|
||||||
pipeBranchesCLCoords.back().push_back(entryPointLastCell + 1.5*(lastCellCenter - entryPointLastCell) );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -65,13 +65,6 @@ private:
|
|||||||
void buildWellPipeParts();
|
void buildWellPipeParts();
|
||||||
|
|
||||||
|
|
||||||
//void calculateWellPipeCenterline(std::vector<cvf::Vec3d>& coords) const;
|
|
||||||
|
|
||||||
void calculateWellPipeCenterline(std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
|
|
||||||
std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds ) const;
|
|
||||||
|
|
||||||
void finishPipeCenterLine( std::vector< std::vector<cvf::Vec3d> > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter ) const;
|
|
||||||
|
|
||||||
struct RivPipeBranchData
|
struct RivPipeBranchData
|
||||||
{
|
{
|
||||||
std::vector <RigWellResultPoint> m_cellIds;
|
std::vector <RigWellResultPoint> m_cellIds;
|
||||||
|
@ -9,6 +9,7 @@ set (SOURCE_GROUP_HEADER_FILES
|
|||||||
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapper.h
|
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapper.h
|
||||||
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapperTools.h
|
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapperTools.h
|
||||||
${CEE_CURRENT_LIST_DIR}RigCaseToCaseRangeFilterMapper.h
|
${CEE_CURRENT_LIST_DIR}RigCaseToCaseRangeFilterMapper.h
|
||||||
|
${CEE_CURRENT_LIST_DIR}RigSimulationWellCenterLineCalculator.h
|
||||||
${CEE_CURRENT_LIST_DIR}RigWellLogFile.h
|
${CEE_CURRENT_LIST_DIR}RigWellLogFile.h
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ set (SOURCE_GROUP_SOURCE_FILES
|
|||||||
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapper.cpp
|
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapper.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapperTools.cpp
|
${CEE_CURRENT_LIST_DIR}RigCaseToCaseCellMapperTools.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RigCaseToCaseRangeFilterMapper.cpp
|
${CEE_CURRENT_LIST_DIR}RigCaseToCaseRangeFilterMapper.cpp
|
||||||
|
${CEE_CURRENT_LIST_DIR}RigSimulationWellCenterLineCalculator.cpp
|
||||||
${CEE_CURRENT_LIST_DIR}RigWellLogFile.cpp
|
${CEE_CURRENT_LIST_DIR}RigWellLogFile.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -0,0 +1,380 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) Statoil ASA
|
||||||
|
// Copyright (C) Ceetron Solutions AS
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RigSimulationWellCenterLineCalculator.h"
|
||||||
|
#include "RimEclipseView.h"
|
||||||
|
#include "RimEclipseWell.h"
|
||||||
|
#include "RimEclipseWellCollection.h"
|
||||||
|
#include "RimEclipseCase.h"
|
||||||
|
#include "RigCaseData.h"
|
||||||
|
#include "cvfRay.h"
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Based on the points and cells, calculate a pipe centerline
|
||||||
|
/// The returned CellIds is one less than the number of centerline points,
|
||||||
|
/// and are describing the lines between the points, starting with the first line
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclipseWell* rimWell,
|
||||||
|
std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
|
||||||
|
std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds)
|
||||||
|
{
|
||||||
|
bool isAutoDetectBranches = false;
|
||||||
|
RigCaseData* eclipseCaseData = NULL;
|
||||||
|
RigSingleWellResultsData* wellResults = NULL;
|
||||||
|
|
||||||
|
{
|
||||||
|
CVF_ASSERT(rimWell);
|
||||||
|
RimEclipseView* eclipseView;
|
||||||
|
rimWell->firstAnchestorOrThisOfType(eclipseView);
|
||||||
|
CVF_ASSERT(eclipseView);
|
||||||
|
|
||||||
|
isAutoDetectBranches = eclipseView->wellCollection()->isAutoDetectingBranches();
|
||||||
|
eclipseCaseData = eclipseView->eclipseCase()->reservoirData();
|
||||||
|
wellResults = rimWell->wellResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we have computed the static representation of the well
|
||||||
|
if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0)
|
||||||
|
{
|
||||||
|
wellResults->computeStaticWellCellPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
const RigWellResultFrame& staticWellFrame = wellResults->m_staticWellCells;
|
||||||
|
if (staticWellFrame.m_wellResultBranches.size() == 0) return;
|
||||||
|
|
||||||
|
// Initialize the return arrays
|
||||||
|
pipeBranchesCLCoords.clear();
|
||||||
|
pipeBranchesCellIds.clear();
|
||||||
|
|
||||||
|
// Well head
|
||||||
|
// Match this position with well head position in RivWellHeadPartMgr::buildWellHeadParts()
|
||||||
|
const RigCell& whCell = eclipseCaseData->cellFromWellResultCell(staticWellFrame.m_wellHead);
|
||||||
|
cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K);
|
||||||
|
const RigWellResultPoint* whResCell = &(staticWellFrame.m_wellHead);
|
||||||
|
|
||||||
|
// Loop over all the well branches
|
||||||
|
const std::vector<RigWellResultBranch>& resBranches = staticWellFrame.m_wellResultBranches;
|
||||||
|
bool hasResultCells = false;
|
||||||
|
if (resBranches.size())
|
||||||
|
{
|
||||||
|
for (size_t i = 0 ; i < resBranches.size(); ++i)
|
||||||
|
{
|
||||||
|
if (resBranches[i].m_branchResultPoints.size() != 0)
|
||||||
|
{
|
||||||
|
hasResultCells = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasResultCells)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Add extra coordinate between cell face and cell center
|
||||||
|
// to make sure the well pipe terminated in a segment parallel to z-axis
|
||||||
|
cvf::Vec3d whIntermediate = whStartPos;
|
||||||
|
whIntermediate.z() = (whStartPos.z() + whCell.center().z()) / 2.0;
|
||||||
|
|
||||||
|
const RigWellResultPoint* prevWellResPoint = NULL;
|
||||||
|
|
||||||
|
CVF_ASSERT(wellResults->isMultiSegmentWell() || resBranches.size() <= 1);
|
||||||
|
|
||||||
|
// The centerline is calculated by adding a point when the pipe enters a cell,
|
||||||
|
// and one when the line leaves the cell.
|
||||||
|
// For the sake of the loop:
|
||||||
|
// The currentResultPoint (Cell) and the one we index by the loop variable is the one we calculate the entry point to.
|
||||||
|
// The previous cell is the one we leave, and calculate the "out-point" from
|
||||||
|
|
||||||
|
|
||||||
|
for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Skip empty branches. Do not know why they exist, but they make problems.
|
||||||
|
|
||||||
|
bool hasValidData = false;
|
||||||
|
for (size_t cIdx = 0; cIdx < resBranches[brIdx].m_branchResultPoints.size(); ++cIdx)
|
||||||
|
{
|
||||||
|
if (resBranches[brIdx].m_branchResultPoints[cIdx].isValid())
|
||||||
|
{
|
||||||
|
hasValidData = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasValidData) continue;
|
||||||
|
|
||||||
|
|
||||||
|
prevWellResPoint = NULL;
|
||||||
|
|
||||||
|
// Find the start the MSW well-branch centerline. Normal wells are started "once" at wellhead in the code above
|
||||||
|
|
||||||
|
pipeBranchesCLCoords.push_back(std::vector<cvf::Vec3d>());
|
||||||
|
pipeBranchesCellIds.push_back(std::vector <RigWellResultPoint>());
|
||||||
|
|
||||||
|
if (brIdx == 0)
|
||||||
|
{
|
||||||
|
// The first branch contains segment number 1, and this is the only segment connected to well head
|
||||||
|
// See Eclipse documentation for the keyword WELSEGS
|
||||||
|
prevWellResPoint = whResCell;
|
||||||
|
|
||||||
|
pipeBranchesCLCoords.back().push_back(whStartPos);
|
||||||
|
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
||||||
|
|
||||||
|
pipeBranchesCLCoords.back().push_back(whIntermediate);
|
||||||
|
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over all the resultPoints in the branch
|
||||||
|
|
||||||
|
const std::vector<RigWellResultPoint>& resBranchCells = resBranches[brIdx].m_branchResultPoints;
|
||||||
|
|
||||||
|
for (int cIdx = 0; cIdx < static_cast<int>(resBranchCells.size()); cIdx++) // Need int because cIdx can temporarily end on -1
|
||||||
|
{
|
||||||
|
std::vector<cvf::Vec3d>& branchCLCoords = pipeBranchesCLCoords.back();
|
||||||
|
std::vector<RigWellResultPoint>& branchCellIds = pipeBranchesCellIds.back();
|
||||||
|
|
||||||
|
const RigWellResultPoint& currentWellResPoint = resBranchCells[cIdx];
|
||||||
|
|
||||||
|
// Ignore invalid cells
|
||||||
|
|
||||||
|
if (!currentWellResPoint.isValid())
|
||||||
|
{
|
||||||
|
//CVF_ASSERT(false); // Some segments does not get anything yet.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add cl contribution for a geometrical resultPoint by adding exit point from previous cell,
|
||||||
|
// and then the result point position
|
||||||
|
|
||||||
|
if (!currentWellResPoint.isCell())
|
||||||
|
{
|
||||||
|
// Use the interpolated value of branch head
|
||||||
|
CVF_ASSERT(currentWellResPoint.isPointValid());
|
||||||
|
|
||||||
|
cvf::Vec3d currentPoint = currentWellResPoint.m_bottomPosition;
|
||||||
|
|
||||||
|
// If we have a real previous cell, we need to go out of it, before adding the current point
|
||||||
|
// That is: add a CL-point describing where it leaves the previous cell.
|
||||||
|
|
||||||
|
if (prevWellResPoint && prevWellResPoint->isCell())
|
||||||
|
{
|
||||||
|
// Create ray between the previous and this position
|
||||||
|
|
||||||
|
const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint);
|
||||||
|
cvf::Vec3d centerPreviousCell = prevCell.center();
|
||||||
|
|
||||||
|
cvf::Ray rayToThisCell;
|
||||||
|
rayToThisCell.setOrigin(centerPreviousCell);
|
||||||
|
rayToThisCell.setDirection((currentPoint - centerPreviousCell).getNormalized());
|
||||||
|
|
||||||
|
cvf::Vec3d outOfPrevCell(centerPreviousCell);
|
||||||
|
|
||||||
|
//int intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell);
|
||||||
|
//CVF_ASSERT(intersectionOk);
|
||||||
|
//CVF_ASSERT(intersectionOk);
|
||||||
|
if ((currentPoint - outOfPrevCell).lengthSquared() > 1e-3)
|
||||||
|
{
|
||||||
|
branchCLCoords.push_back(outOfPrevCell);
|
||||||
|
branchCellIds.push_back(RigWellResultPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
branchCLCoords.push_back(currentPoint);
|
||||||
|
branchCellIds.push_back(currentWellResPoint);
|
||||||
|
|
||||||
|
prevWellResPoint = ¤tWellResPoint;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle currentWellResPoint as a real cell result points.
|
||||||
|
//
|
||||||
|
|
||||||
|
const RigCell& cell = eclipseCaseData->cellFromWellResultCell(currentWellResPoint);
|
||||||
|
|
||||||
|
// Check if this and the previous cells has shared faces
|
||||||
|
|
||||||
|
cvf::StructGridInterface::FaceType sharedFace;
|
||||||
|
if (prevWellResPoint && prevWellResPoint->isCell() && eclipseCaseData->findSharedSourceFace(sharedFace, currentWellResPoint, *prevWellResPoint))
|
||||||
|
{
|
||||||
|
// If they share faces, the shared face center is used as point
|
||||||
|
// describing the entry of this cell. (And exit of the previous cell)
|
||||||
|
|
||||||
|
branchCLCoords.push_back(cell.faceCenter(sharedFace));
|
||||||
|
branchCellIds.push_back(currentWellResPoint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This and the previous cell does not share a face.
|
||||||
|
// Then we need to calculate the exit of the previous cell, and the entry point into this cell
|
||||||
|
|
||||||
|
cvf::Vec3d centerPreviousCell(cvf::Vec3d::ZERO);
|
||||||
|
cvf::Vec3d centerThisCell = cell.center();
|
||||||
|
bool distanceToWellHeadIsLonger = true;
|
||||||
|
|
||||||
|
// If we have a previous well result point, use its center as measure point and ray intersection start
|
||||||
|
// when considering things.
|
||||||
|
|
||||||
|
if (prevWellResPoint && prevWellResPoint->isValid())
|
||||||
|
{
|
||||||
|
if (prevWellResPoint->isCell())
|
||||||
|
{
|
||||||
|
const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint);
|
||||||
|
centerPreviousCell = prevCell.center();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
centerPreviousCell = prevWellResPoint->m_bottomPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
distanceToWellHeadIsLonger = (centerThisCell - centerPreviousCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// First make sure this cell is not starting a new "display" branch for none MSW's
|
||||||
|
|
||||||
|
if ( wellResults->isMultiSegmentWell()
|
||||||
|
|| !isAutoDetectBranches
|
||||||
|
|| (prevWellResPoint == whResCell)
|
||||||
|
|| distanceToWellHeadIsLonger)
|
||||||
|
{
|
||||||
|
// Not starting a "display" branch for normal wells
|
||||||
|
// Calculate the exit of the previous cell, and the entry point into this cell
|
||||||
|
|
||||||
|
cvf::Vec3d intoThisCell(centerThisCell); // Use cell center as default for "into" point.
|
||||||
|
|
||||||
|
if (prevWellResPoint && prevWellResPoint->isValid())
|
||||||
|
{
|
||||||
|
// We have a defined previous point
|
||||||
|
// Create ray between the previous and this cell
|
||||||
|
|
||||||
|
cvf::Ray rayToThisCell;
|
||||||
|
rayToThisCell.setOrigin(centerPreviousCell);
|
||||||
|
rayToThisCell.setDirection((centerThisCell - centerPreviousCell).getNormalized());
|
||||||
|
|
||||||
|
// Intersect with the current cell to find a better entry point than the cell center
|
||||||
|
|
||||||
|
int intersectionCount = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell);
|
||||||
|
bool isPreviousResPointInsideCurrentCell = (intersectionCount % 2); // Must intersect uneven times to be inside. (1 % 2 = 1)
|
||||||
|
|
||||||
|
// If we have a real previous cell, we need to go out of it, before entering this.
|
||||||
|
// That is: add a CL-point describing where it leaves the previous cell.
|
||||||
|
|
||||||
|
if ( prevWellResPoint->isCell())
|
||||||
|
{
|
||||||
|
cvf::Vec3d outOfPrevCell(centerPreviousCell);
|
||||||
|
|
||||||
|
const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint);
|
||||||
|
//bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell);
|
||||||
|
//CVF_ASSERT(intersectionOk);
|
||||||
|
//CVF_ASSERT(intersectionOk);
|
||||||
|
if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3)
|
||||||
|
{
|
||||||
|
branchCLCoords.push_back(outOfPrevCell);
|
||||||
|
branchCellIds.push_back(RigWellResultPoint());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isPreviousResPointInsideCurrentCell)
|
||||||
|
{
|
||||||
|
// Since the previous point actually is inside this cell,
|
||||||
|
/// use that as the entry point into this cell
|
||||||
|
intoThisCell = centerPreviousCell;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
branchCLCoords.push_back(intoThisCell);
|
||||||
|
branchCellIds.push_back(currentWellResPoint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Need to start a "display branch" for a Normal Well.
|
||||||
|
|
||||||
|
CVF_ASSERT(!wellResults->isMultiSegmentWell());
|
||||||
|
|
||||||
|
// This cell is further from the previous cell than from the well head,
|
||||||
|
// thus we interpret it as a new branch.
|
||||||
|
|
||||||
|
// First finish the current branch in the previous cell
|
||||||
|
//branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPreviousCell - branchCLCoords.back()) );
|
||||||
|
finishPipeCenterLine(pipeBranchesCLCoords, centerPreviousCell);
|
||||||
|
|
||||||
|
// Create new display branch
|
||||||
|
pipeBranchesCLCoords.push_back(std::vector<cvf::Vec3d>());
|
||||||
|
pipeBranchesCellIds.push_back(std::vector <RigWellResultPoint>());
|
||||||
|
|
||||||
|
// Start the new branch by entering the first cell (the wellhead) and intermediate
|
||||||
|
prevWellResPoint = whResCell;
|
||||||
|
pipeBranchesCLCoords.back().push_back(whStartPos);
|
||||||
|
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
||||||
|
|
||||||
|
// Include intermediate
|
||||||
|
pipeBranchesCLCoords.back().push_back(whIntermediate);
|
||||||
|
pipeBranchesCellIds.back().push_back(*prevWellResPoint);
|
||||||
|
|
||||||
|
// Well now we need to step one back to take this cell again, but in the new branch.
|
||||||
|
cIdx--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prevWellResPoint = ¤tWellResPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For the last cell, add the point 0.5 past the center of that cell
|
||||||
|
// Remember that prevWellResPoint actually is the last one in this branch.
|
||||||
|
|
||||||
|
cvf::Vec3d centerLastCell;
|
||||||
|
if (prevWellResPoint && prevWellResPoint->isCell())
|
||||||
|
{
|
||||||
|
const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint);
|
||||||
|
centerLastCell = prevCell.center();
|
||||||
|
finishPipeCenterLine(pipeBranchesCLCoords, centerLastCell);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Remove the ID that is superfluous since we will not add an ending point
|
||||||
|
pipeBranchesCellIds.back().pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CVF_ASSERT(pipeBranchesCellIds.size() == pipeBranchesCLCoords.size());
|
||||||
|
for (size_t i = 0 ; i < pipeBranchesCellIds.size() ; ++i)
|
||||||
|
{
|
||||||
|
CVF_ASSERT(pipeBranchesCellIds[i].size() == pipeBranchesCLCoords[i].size()-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// All branches are completed using the point 0.5 past the center of
|
||||||
|
/// last cell.
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RigSimulationWellCenterLineCalculator::finishPipeCenterLine(std::vector< std::vector<cvf::Vec3d> > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter)
|
||||||
|
{
|
||||||
|
CVF_ASSERT(pipeBranchesCLCoords.size());
|
||||||
|
CVF_ASSERT(pipeBranchesCLCoords.back().size());
|
||||||
|
|
||||||
|
cvf::Vec3d entryPointLastCell = pipeBranchesCLCoords.back().back();
|
||||||
|
|
||||||
|
pipeBranchesCLCoords.back().push_back(entryPointLastCell + 1.5*(lastCellCenter - entryPointLastCell) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) Statoil ASA
|
||||||
|
// Copyright (C) Ceetron Solutions AS
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/gpl.html>
|
||||||
|
// for more details.
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "RigSingleWellResultsData.h"
|
||||||
|
#include "cvfVector3.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class RimEclipseWell;
|
||||||
|
|
||||||
|
class RigSimulationWellCenterLineCalculator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void calculateWellPipeCenterline(RimEclipseWell* m_rimWell,
|
||||||
|
std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
|
||||||
|
std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds) ;
|
||||||
|
private:
|
||||||
|
static void finishPipeCenterLine( std::vector< std::vector<cvf::Vec3d> > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter ) ;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user