mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-01 03:37:15 -06:00
#4549 Add python method to get cell centers for active cells
Equivalent to GetActiveCellCenters in Octave.
This commit is contained in:
parent
2bf10a7837
commit
a5be62c5b6
@ -10,6 +10,7 @@ service Case
|
||||
rpc GetGridCount(CaseRequest) returns(GridCount) {}
|
||||
rpc GetCellCount(CellInfoRequest) returns (CellCount) {}
|
||||
rpc GetCellInfoForActiveCells(CellInfoRequest) returns (stream CellInfoArray) {}
|
||||
rpc GetCellCenterForActiveCells(CellInfoRequest) returns (stream CellCenters) {}
|
||||
rpc GetCoarseningInfoArray(CaseRequest) returns (CoarseningInfoArray) {}
|
||||
rpc GetTimeSteps(CaseRequest) returns (TimeStepDates) {}
|
||||
rpc GetDaysSinceStart(CaseRequest) returns (DaysSinceStart) {}
|
||||
|
@ -17,3 +17,14 @@ message Vec3i {
|
||||
int32 k = 3;
|
||||
}
|
||||
|
||||
message Vec3d
|
||||
{
|
||||
double x = 1;
|
||||
double y = 2;
|
||||
double z = 3;
|
||||
}
|
||||
|
||||
message CellCenters
|
||||
{
|
||||
repeated Vec3d centers = 1;
|
||||
}
|
||||
|
@ -17,18 +17,6 @@ message GridRequest
|
||||
int32 grid_index = 2;
|
||||
}
|
||||
|
||||
message Vec3d
|
||||
{
|
||||
double x = 1;
|
||||
double y = 2;
|
||||
double z = 3;
|
||||
}
|
||||
|
||||
message CellCenters
|
||||
{
|
||||
repeated Vec3d centers = 1;
|
||||
}
|
||||
|
||||
message GridDimensions
|
||||
{
|
||||
Vec3i dimensions = 1;
|
||||
|
@ -820,3 +820,41 @@ class Case(PdmObject):
|
||||
for pdm_object in pdm_objects:
|
||||
wells.append(SimulationWell(pdm_object.get_value("WellName"), self.case_id, pdm_object))
|
||||
return wells
|
||||
|
||||
|
||||
def active_cell_centers_async(
|
||||
self,
|
||||
porosity_model="MATRIX_MODEL",
|
||||
):
|
||||
"""Get a cell centers for all active cells. Async, so returns an iterator
|
||||
|
||||
Arguments:
|
||||
porosity_model(str): string enum. See available()
|
||||
|
||||
Returns:
|
||||
An iterator to a chunk object containing an array of Vec3d values.
|
||||
Loop through the chunks and then the values within the chunk to get all values.
|
||||
"""
|
||||
porosity_model_enum = Case_pb2.PorosityModelType.Value(porosity_model)
|
||||
request = Case_pb2.CellInfoRequest(case_request=self.__request,
|
||||
porosity_model=porosity_model_enum)
|
||||
return self.__case_stub.GetCellCenterForActiveCells(request)
|
||||
|
||||
def active_cell_centers(
|
||||
self,
|
||||
porosity_model="MATRIX_MODEL",
|
||||
):
|
||||
"""Get a cell centers for all active cells. Synchronous, so returns a list.
|
||||
|
||||
Arguments:
|
||||
porosity_model(str): string enum. See available()
|
||||
|
||||
Returns:
|
||||
A list of Vec3d
|
||||
"""
|
||||
cell_centers = []
|
||||
generator = self.active_cell_centers_async(porosity_model)
|
||||
for chunk in generator:
|
||||
for value in chunk.centers:
|
||||
cell_centers.append(value)
|
||||
return cell_centers
|
||||
|
@ -56,6 +56,12 @@ def test_MultipleCases(rips_instance, initialize_test):
|
||||
for i, case_name in enumerate(case_names):
|
||||
assert(case_name == cases[i].name)
|
||||
|
||||
def get_cell_index_with_ijk(cell_info, i, j, k):
|
||||
for (idx, cell) in enumerate(cell_info):
|
||||
if cell.local_ijk.i == i and cell.local_ijk.j == j and cell.local_ijk.k == k:
|
||||
return idx
|
||||
return -1
|
||||
|
||||
def test_10k(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.load_case(path=case_path)
|
||||
@ -67,6 +73,20 @@ def test_10k(rips_instance, initialize_test):
|
||||
assert(len(time_steps) == 9)
|
||||
days_since_start = case.days_since_start()
|
||||
assert(len(days_since_start) == 9)
|
||||
cell_info = case.cell_info_for_active_cells()
|
||||
assert(len(cell_info) == cell_count_info.active_cell_count)
|
||||
|
||||
# Check an active cell (found in resinsight ui)
|
||||
cell_index = get_cell_index_with_ijk(cell_info, 23, 44, 19)
|
||||
assert(cell_index != -1)
|
||||
|
||||
cell_centers = case.active_cell_centers()
|
||||
assert(len(cell_centers) == cell_count_info.active_cell_count)
|
||||
|
||||
# Check the cell center for the specific cell
|
||||
assert(math.isclose(3627.17, cell_centers[cell_index].x, abs_tol=0.1))
|
||||
assert(math.isclose(5209.75, cell_centers[cell_index].y, abs_tol=0.1))
|
||||
assert(math.isclose(4179.6, cell_centers[cell_index].z, abs_tol=0.1))
|
||||
|
||||
def test_PdmObject(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
|
@ -32,6 +32,15 @@
|
||||
|
||||
using namespace rips;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert internal ResInsight representation of cells with negative depth to positive depth.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static inline void convertVec3dToPositiveDepth( cvf::Vec3d* vec )
|
||||
{
|
||||
double& z = vec->z();
|
||||
z *= -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -216,6 +225,71 @@ grpc::Status RiaActiveCellInfoStateHandler::assignReply( rips::CellInfoArray* re
|
||||
return Status( grpc::OUT_OF_RANGE, "We've reached the end. This is not an error but means transmission is finished" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaActiveCellInfoStateHandler::assignNextActiveCellCenter( rips::Vec3d* cellCenter )
|
||||
{
|
||||
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->globalCellArray();
|
||||
|
||||
while ( m_currentCellIdx < reservoirCells.size() )
|
||||
{
|
||||
size_t cellIdxToTry = m_currentCellIdx++;
|
||||
if ( m_activeCellInfo->isActive( cellIdxToTry ) )
|
||||
{
|
||||
assignCellCenter( cellCenter, reservoirCells, cellIdxToTry );
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
}
|
||||
return Status( grpc::OUT_OF_RANGE, "We've reached the end. This is not an error but means transmission is finished" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaActiveCellInfoStateHandler::assignCellCenter( rips::Vec3d* cellCenter,
|
||||
const std::vector<RigCell>& reservoirCells,
|
||||
size_t cellIdx )
|
||||
|
||||
{
|
||||
cvf::Vec3d center = reservoirCells[cellIdx].center();
|
||||
|
||||
convertVec3dToPositiveDepth( ¢er );
|
||||
|
||||
cellCenter->set_x( center.x() );
|
||||
cellCenter->set_y( center.y() );
|
||||
cellCenter->set_z( center.z() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaActiveCellInfoStateHandler::assignCellCentersReply( rips::CellCenters* reply )
|
||||
{
|
||||
const size_t packageSize = RiaGrpcServiceInterface::numberOfMessagesForByteCount( sizeof( rips::CellCenters ) );
|
||||
size_t packageIndex = 0u;
|
||||
reply->mutable_centers()->Reserve( (int)packageSize );
|
||||
for ( ; packageIndex < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++packageIndex )
|
||||
{
|
||||
rips::Vec3d singleCellCenter;
|
||||
grpc::Status singleCellCenterStatus = assignNextActiveCellCenter( &singleCellCenter );
|
||||
if ( singleCellCenterStatus.ok() )
|
||||
{
|
||||
rips::Vec3d* allocCellCenter = reply->add_centers();
|
||||
*allocCellCenter = singleCellCenter;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( packageIndex > 0u )
|
||||
{
|
||||
return Status::OK;
|
||||
}
|
||||
return Status( grpc::OUT_OF_RANGE, "We've reached the end. This is not an error but means transmission is finished" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -367,6 +441,17 @@ grpc::Status RiaGrpcCaseService::GetCellInfoForActiveCells( grpc::ServerContext*
|
||||
return stateHandler->assignReply( reply );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcCaseService::GetCellCenterForActiveCells( grpc::ServerContext* context,
|
||||
const rips::CellInfoRequest* request,
|
||||
rips::CellCenters* reply,
|
||||
RiaActiveCellInfoStateHandler* stateHandler )
|
||||
{
|
||||
return stateHandler->assignCellCentersReply( reply );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -411,6 +496,14 @@ std::vector<RiaGrpcCallbackInterface*> RiaGrpcCaseService::createCallbacks()
|
||||
&Self::GetCellInfoForActiveCells,
|
||||
&Self::RequestGetCellInfoForActiveCells,
|
||||
new RiaActiveCellInfoStateHandler ),
|
||||
new RiaGrpcServerToClientStreamCallback<Self,
|
||||
CellInfoRequest,
|
||||
CellCenters,
|
||||
RiaActiveCellInfoStateHandler>( this,
|
||||
&Self::GetCellCenterForActiveCells,
|
||||
&Self::RequestGetCellCenterForActiveCells,
|
||||
new RiaActiveCellInfoStateHandler ),
|
||||
|
||||
new RiaGrpcUnaryCallback<Self, CaseRequest, BoundingBox>( this,
|
||||
&Self::GetReservoirBoundingBox,
|
||||
&Self::RequestGetReservoirBoundingBox )};
|
||||
|
@ -48,11 +48,19 @@ public:
|
||||
RiaActiveCellInfoStateHandler();
|
||||
|
||||
Status init( const rips::CellInfoRequest* request );
|
||||
|
||||
RigActiveCellInfo* activeCellInfo() const;
|
||||
const std::vector<RigCell>& reservoirCells() const;
|
||||
|
||||
// For cell info:
|
||||
Status assignNextActiveCellInfoData( rips::CellInfo* cellInfo );
|
||||
void assignCellInfoData( rips::CellInfo* cellInfo, const std::vector<RigCell>& reservoirCells, size_t cellIdx );
|
||||
Status assignReply( rips::CellInfoArray* reply );
|
||||
RigActiveCellInfo* activeCellInfo() const;
|
||||
const std::vector<RigCell>& reservoirCells() const;
|
||||
|
||||
// For cell centers:
|
||||
Status assignNextActiveCellCenter( rips::Vec3d* cellCenter );
|
||||
void assignCellCenter( rips::Vec3d* cellCenter, const std::vector<RigCell>& reservoirCells, size_t cellIdx );
|
||||
Status assignCellCentersReply( rips::CellCenters* reply );
|
||||
|
||||
protected:
|
||||
const rips::CellInfoRequest* m_request;
|
||||
@ -89,6 +97,10 @@ public:
|
||||
const rips::CellInfoRequest* request,
|
||||
rips::CellInfoArray* reply,
|
||||
RiaActiveCellInfoStateHandler* stateHandler );
|
||||
grpc::Status GetCellCenterForActiveCells( grpc::ServerContext* context,
|
||||
const rips::CellInfoRequest* request,
|
||||
rips::CellCenters* reply,
|
||||
RiaActiveCellInfoStateHandler* stateHandler );
|
||||
grpc::Status GetReservoirBoundingBox( grpc::ServerContext* context,
|
||||
const rips::CaseRequest* request,
|
||||
rips::BoundingBox* reply );
|
||||
|
Loading…
Reference in New Issue
Block a user