mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-03 04:40:49 -06:00
Fault distance from point (#13367)
* Add python interface for distance to closest fault * Split up some older code into multiple files. * Add python test
This commit is contained in:
17 files changed
+896
-554
No files matched your search
@@ -231,3 +231,28 @@ void RigFaultsPrCellAccumulator::setFaultIdx( size_t reservoirCellIndex, cvf::St
|
|||||||
{
|
{
|
||||||
m_faultIdxForCellFace[reservoirCellIndex][face] = faultIdx;
|
m_faultIdxForCellFace[reservoirCellIndex][face] = faultIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::pair<double, cvf::StructGridInterface::FaceType> RigFault::minimumDistanceToPoint( const cvf::Vec3d& point, const RigMainGrid* mainGrid ) const
|
||||||
|
{
|
||||||
|
double minDistance = std::numeric_limits<double>::max();
|
||||||
|
cvf::StructGridInterface::FaceType minFace = cvf::StructGridInterface::NO_FACE;
|
||||||
|
for ( const FaultFace& ff : m_faultFaces )
|
||||||
|
{
|
||||||
|
const RigCell& cell = mainGrid->cell( ff.m_nativeReservoirCellIndex );
|
||||||
|
if ( cell.isInvalid() ) continue;
|
||||||
|
|
||||||
|
for ( auto& c : cell.faceCorners( ff.m_nativeFace ) )
|
||||||
|
{
|
||||||
|
double distance = ( c - point ).length();
|
||||||
|
if ( distance < minDistance )
|
||||||
|
{
|
||||||
|
minDistance = distance;
|
||||||
|
minFace = ff.m_nativeFace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::make_pair( minDistance, minFace );
|
||||||
|
}
|
||||||
@@ -97,6 +97,8 @@ public:
|
|||||||
|
|
||||||
static bool ordering( CellAndFace first, CellAndFace second );
|
static bool ordering( CellAndFace first, CellAndFace second );
|
||||||
|
|
||||||
|
std::pair<double, cvf::StructGridInterface::FaceType> minimumDistanceToPoint( const cvf::Vec3d& point, const RigMainGrid* mainGrid ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
||||||
|
|||||||
@@ -809,6 +809,28 @@ const RigFault* RigMainGrid::findFaultFromCellIndexAndCellFace( size_t reservoir
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Returns the name of the closest fault, the distance to the fault, and the face type of the closest face
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::tuple<QString, double, cvf::StructGridInterface::FaceType> RigMainGrid::minimumDistanceFaultToPoint( const cvf::Vec3d& point ) const
|
||||||
|
{
|
||||||
|
double minDistance = std::numeric_limits<double>::max();
|
||||||
|
cvf::StructGridInterface::FaceType minFace = cvf::StructGridInterface::FaceType::NO_FACE;
|
||||||
|
QString minFaultName;
|
||||||
|
for ( const auto& fault : m_faults )
|
||||||
|
{
|
||||||
|
auto [faultMinDistance, faultMinFace] = fault->minimumDistanceToPoint( point, this );
|
||||||
|
|
||||||
|
if ( faultMinDistance < minDistance )
|
||||||
|
{
|
||||||
|
minDistance = faultMinDistance;
|
||||||
|
minFace = faultMinFace;
|
||||||
|
minFaultName = fault->name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { minFaultName, minDistance, minFace };
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include "cvfBoundingBox.h"
|
#include "cvfBoundingBox.h"
|
||||||
#include "cvfCollection.h"
|
#include "cvfCollection.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class RigActiveCellInfo;
|
class RigActiveCellInfo;
|
||||||
@@ -116,6 +118,8 @@ public:
|
|||||||
// invalidate all cells with I > iLimit (0 based index)
|
// invalidate all cells with I > iLimit (0 based index)
|
||||||
void invalidateCellsAboveI( size_t iLimit );
|
void invalidateCellsAboveI( size_t iLimit );
|
||||||
|
|
||||||
|
std::tuple<QString, double, cvf::StructGridInterface::FaceType> minimumDistanceFaultToPoint( const cvf::Vec3d& point ) const;
|
||||||
|
|
||||||
protected: // only for use by file readers and internal services. TODO: replace with a better API
|
protected: // only for use by file readers and internal services. TODO: replace with a better API
|
||||||
friend class RigGridBase;
|
friend class RigGridBase;
|
||||||
friend class RigReservoirBuilder;
|
friend class RigReservoirBuilder;
|
||||||
@@ -124,7 +128,7 @@ protected: // only for use by file readers and internal services. TODO: replace
|
|||||||
friend class RifReaderEclipseOutput;
|
friend class RifReaderEclipseOutput;
|
||||||
friend class RifReaderOpmCommon;
|
friend class RifReaderOpmCommon;
|
||||||
friend class RiaGrpcCaseService;
|
friend class RiaGrpcCaseService;
|
||||||
friend class RiaActiveCellInfoStateHandler;
|
friend class RiaGrpcActiveCellInfoStateHandler;
|
||||||
friend class RicCreateTemporaryLgrFeature;
|
friend class RicCreateTemporaryLgrFeature;
|
||||||
friend class RimCornerPointCase;
|
friend class RimCornerPointCase;
|
||||||
std::vector<RigCell>& reservoirCells();
|
std::vector<RigCell>& reservoirCells();
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ set(SOURCE_GROUP_HEADER_FILES
|
|||||||
RiaGrpcApplicationInterface.h
|
RiaGrpcApplicationInterface.h
|
||||||
RiaGrpcWellPathService.h
|
RiaGrpcWellPathService.h
|
||||||
RiaWellPathDataToGrpcConverter.h
|
RiaWellPathDataToGrpcConverter.h
|
||||||
|
RiaGrpcActiveCellInfoStateHandler.h
|
||||||
|
RiaGrpcSelectedCellsStateHandler.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCE_GROUP_SOURCE_FILES
|
set(SOURCE_GROUP_SOURCE_FILES
|
||||||
@@ -58,6 +60,8 @@ set(SOURCE_GROUP_SOURCE_FILES
|
|||||||
RiaGrpcApplicationInterface.cpp
|
RiaGrpcApplicationInterface.cpp
|
||||||
RiaGrpcWellPathService.cpp
|
RiaGrpcWellPathService.cpp
|
||||||
RiaWellPathDataToGrpcConverter.cpp
|
RiaWellPathDataToGrpcConverter.cpp
|
||||||
|
RiaGrpcActiveCellInfoStateHandler.cpp
|
||||||
|
RiaGrpcSelectedCellsStateHandler.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Find Protobuf installation Looks for protobuf-config.cmake file installed by
|
# Find Protobuf installation Looks for protobuf-config.cmake file installed by
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ service Case {
|
|||||||
rpc GetCaseInfo(CaseRequest) returns (CaseInfo) {}
|
rpc GetCaseInfo(CaseRequest) returns (CaseInfo) {}
|
||||||
rpc GetPdmObject(CaseRequest) returns (PdmObject) {}
|
rpc GetPdmObject(CaseRequest) returns (PdmObject) {}
|
||||||
rpc GetReservoirBoundingBox(CaseRequest) returns (BoundingBox) {}
|
rpc GetReservoirBoundingBox(CaseRequest) returns (BoundingBox) {}
|
||||||
|
rpc GetDistanceToClosestFault(ClosestFaultRequest) returns (ClosestFault) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message CaseRequest { int32 id = 1; }
|
message CaseRequest { int32 id = 1; }
|
||||||
@@ -103,3 +104,14 @@ message SelectedCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message SelectedCells { repeated SelectedCell cells = 1; }
|
message SelectedCells { repeated SelectedCell cells = 1; }
|
||||||
|
|
||||||
|
message ClosestFaultRequest {
|
||||||
|
CaseRequest case_request = 1;
|
||||||
|
Vec3d point = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ClosestFault {
|
||||||
|
string fault_name = 1;
|
||||||
|
double distance = 2;
|
||||||
|
string face_name = 3;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
###################################################################################
|
||||||
|
# This example prints the distance to and the name of the fault closest to a point
|
||||||
|
###################################################################################
|
||||||
|
|
||||||
|
import rips
|
||||||
|
|
||||||
|
resinsight = rips.Instance.find()
|
||||||
|
if resinsight is None:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
cases = resinsight.project.cases()
|
||||||
|
if len(cases) == 0:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
case = cases[0]
|
||||||
|
print("Using case: " + case.name)
|
||||||
|
|
||||||
|
# random test point (positive Z for depth)
|
||||||
|
point_x = 5039.84
|
||||||
|
point_y = 6303.76
|
||||||
|
point_z = 4144.21
|
||||||
|
|
||||||
|
print("Looking for closest fault to point %f, %f, %f:" % (point_x, point_y, point_z))
|
||||||
|
|
||||||
|
faultname, distance, facename = case.distance_to_closest_fault(
|
||||||
|
point_x, point_y, point_z
|
||||||
|
)
|
||||||
|
|
||||||
|
if facename == "":
|
||||||
|
print("- No fault found!")
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
"- Distance to closest fault %s is %f, closest face direction is %s"
|
||||||
|
% (faultname, distance, facename)
|
||||||
|
)
|
||||||
@@ -43,6 +43,7 @@ import Case_pb2
|
|||||||
import Case_pb2_grpc
|
import Case_pb2_grpc
|
||||||
import Commands_pb2 as Cmd
|
import Commands_pb2 as Cmd
|
||||||
import PdmObject_pb2 as PdmObject_pb2
|
import PdmObject_pb2 as PdmObject_pb2
|
||||||
|
import Definitions_pb2
|
||||||
|
|
||||||
import Properties_pb2
|
import Properties_pb2
|
||||||
import Properties_pb2_grpc
|
import Properties_pb2_grpc
|
||||||
@@ -300,6 +301,17 @@ def reservoir_boundingbox(self):
|
|||||||
return self.__case_stub.GetReservoirBoundingBox(self.__request())
|
return self.__case_stub.GetReservoirBoundingBox(self.__request())
|
||||||
|
|
||||||
|
|
||||||
|
@add_method(Case)
|
||||||
|
def distance_to_closest_fault(self, x: float, y: float, z: float):
|
||||||
|
"""Find the closest fault to the given point and return the distance, fault name and fault face"""
|
||||||
|
request = Case_pb2.ClosestFaultRequest(
|
||||||
|
case_request=self.__request(), point=Definitions_pb2.Vec3d(x=x, y=y, z=z)
|
||||||
|
)
|
||||||
|
reply = self.__case_stub.GetDistanceToClosestFault(request)
|
||||||
|
|
||||||
|
return (reply.fault_name, reply.distance, reply.face_name)
|
||||||
|
|
||||||
|
|
||||||
@add_method(Case)
|
@add_method(Case)
|
||||||
def reservoir_depth_range(self) -> Tuple[float, float]:
|
def reservoir_depth_range(self) -> Tuple[float, float]:
|
||||||
"""Get the reservoir depth range
|
"""Get the reservoir depth range
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import math
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||||
|
import rips
|
||||||
|
|
||||||
|
import dataroot
|
||||||
|
|
||||||
|
|
||||||
|
def test_faultDistance(rips_instance, initialize_test):
|
||||||
|
case = rips_instance.project.load_case(
|
||||||
|
dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||||
|
)
|
||||||
|
|
||||||
|
# a test point
|
||||||
|
point_x = 4817.84
|
||||||
|
point_y = 5204.76
|
||||||
|
point_z = 4137.21
|
||||||
|
|
||||||
|
faultname, distance, facename = case.distance_to_closest_fault(
|
||||||
|
point_x, point_y, point_z
|
||||||
|
)
|
||||||
|
|
||||||
|
# Fault name is unstable between grid readers, so we skip this check
|
||||||
|
# assert faultname == "Undefined Grid Faults"
|
||||||
|
|
||||||
|
assert facename == "I+"
|
||||||
|
assert math.isclose(distance, 53.84, abs_tol=0.1)
|
||||||
@@ -0,0 +1,359 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2025 Equinor ASA
|
||||||
|
//
|
||||||
|
// 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 "RiaGrpcActiveCellInfoStateHandler.h"
|
||||||
|
|
||||||
|
#include "RiaGrpcCallbacks.h"
|
||||||
|
#include "RiaGrpcHelper.h"
|
||||||
|
#include "RiaSocketTools.h"
|
||||||
|
|
||||||
|
#include "RigActiveCellInfo.h"
|
||||||
|
#include "RigCaseCellResultsData.h"
|
||||||
|
#include "RigEclipseCaseData.h"
|
||||||
|
#include "RigEclipseResultAddress.h"
|
||||||
|
#include "RigMainGrid.h"
|
||||||
|
|
||||||
|
#include "RimEclipseCase.h"
|
||||||
|
#include "RimEclipseResultDefinition.h"
|
||||||
|
|
||||||
|
#include "Riu3dSelectionManager.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
using namespace rips;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RiaGrpcActiveCellInfoStateHandler::RiaGrpcActiveCellInfoStateHandler()
|
||||||
|
: m_request( nullptr )
|
||||||
|
, m_eclipseCase( nullptr )
|
||||||
|
, m_activeCellInfo( nullptr )
|
||||||
|
, m_currentCellIdx( 0u )
|
||||||
|
, m_porosityModel( RiaDefines::PorosityModelType::MATRIX_MODEL )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcActiveCellInfoStateHandler::init( const rips::CellInfoRequest* request )
|
||||||
|
{
|
||||||
|
CAF_ASSERT( request );
|
||||||
|
m_request = request;
|
||||||
|
|
||||||
|
m_porosityModel = RiaDefines::PorosityModelType( m_request->porosity_model() );
|
||||||
|
RimCase* rimCase = RiaGrpcHelper::findCase( m_request->case_request().id() );
|
||||||
|
m_eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase );
|
||||||
|
|
||||||
|
if ( !m_eclipseCase )
|
||||||
|
{
|
||||||
|
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case not found" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_eclipseCase->eclipseCaseData() || !m_eclipseCase->eclipseCaseData()->mainGrid() )
|
||||||
|
{
|
||||||
|
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case Data not found" );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_activeCellInfo = m_eclipseCase->eclipseCaseData()->activeCellInfo( m_porosityModel );
|
||||||
|
|
||||||
|
if ( !m_activeCellInfo )
|
||||||
|
{
|
||||||
|
return grpc::Status( grpc::NOT_FOUND, "Active Cell Info not found" );
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t globalCoarseningBoxCount = 0;
|
||||||
|
|
||||||
|
for ( size_t gridIdx = 0; gridIdx < m_eclipseCase->eclipseCaseData()->gridCount(); gridIdx++ )
|
||||||
|
{
|
||||||
|
m_globalCoarseningBoxIndexStart.push_back( globalCoarseningBoxCount );
|
||||||
|
|
||||||
|
RigGridBase* grid = m_eclipseCase->eclipseCaseData()->grid( gridIdx );
|
||||||
|
|
||||||
|
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
||||||
|
globalCoarseningBoxCount += localCoarseningBoxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return grpc::Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcActiveCellInfoStateHandler::assignNextActiveCellInfoData( rips::CellInfo* cellInfo )
|
||||||
|
{
|
||||||
|
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
||||||
|
|
||||||
|
while ( m_currentCellIdx < reservoirCells.size() )
|
||||||
|
{
|
||||||
|
size_t cellIdxToTry = m_currentCellIdx++;
|
||||||
|
if ( m_activeCellInfo->isActive( cellIdxToTry ) )
|
||||||
|
{
|
||||||
|
assignCellInfoData( cellInfo, 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 RiaGrpcActiveCellInfoStateHandler::assignCellInfoData( rips::CellInfo* cellInfo,
|
||||||
|
const std::vector<RigCell>& reservoirCells,
|
||||||
|
size_t cellIdx )
|
||||||
|
{
|
||||||
|
RigGridBase* grid = reservoirCells[cellIdx].hostGrid();
|
||||||
|
CVF_ASSERT( grid != nullptr );
|
||||||
|
size_t cellIndex = reservoirCells[cellIdx].gridLocalCellIndex();
|
||||||
|
|
||||||
|
size_t i, j, k;
|
||||||
|
grid->ijkFromCellIndex( cellIndex, &i, &j, &k );
|
||||||
|
|
||||||
|
size_t pi, pj, pk;
|
||||||
|
RigGridBase* parentGrid = nullptr;
|
||||||
|
|
||||||
|
if ( grid->isMainGrid() )
|
||||||
|
{
|
||||||
|
pi = i;
|
||||||
|
pj = j;
|
||||||
|
pk = k;
|
||||||
|
parentGrid = grid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t parentCellIdx = reservoirCells[cellIdx].parentCellIndex();
|
||||||
|
parentGrid = ( static_cast<RigLocalGrid*>( grid ) )->parentGrid();
|
||||||
|
CVF_ASSERT( parentGrid != nullptr );
|
||||||
|
parentGrid->ijkFromCellIndex( parentCellIdx, &pi, &pj, &pk );
|
||||||
|
}
|
||||||
|
|
||||||
|
cellInfo->set_grid_index( (int)grid->gridIndex() );
|
||||||
|
cellInfo->set_parent_grid_index( (int)parentGrid->gridIndex() );
|
||||||
|
|
||||||
|
size_t coarseningIdx = reservoirCells[cellIdx].coarseningBoxIndex();
|
||||||
|
if ( coarseningIdx != cvf::UNDEFINED_SIZE_T )
|
||||||
|
{
|
||||||
|
size_t globalCoarseningIdx = m_globalCoarseningBoxIndexStart[grid->gridIndex()] + coarseningIdx;
|
||||||
|
cellInfo->set_coarsening_box_index( (int)globalCoarseningIdx );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cellInfo->set_coarsening_box_index( -1 );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
rips::Vec3i* local_ijk = new rips::Vec3i;
|
||||||
|
local_ijk->set_i( (int)i );
|
||||||
|
local_ijk->set_j( (int)j );
|
||||||
|
local_ijk->set_k( (int)k );
|
||||||
|
cellInfo->set_allocated_local_ijk( local_ijk );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
rips::Vec3i* parent_ijk = new rips::Vec3i;
|
||||||
|
parent_ijk->set_i( (int)pi );
|
||||||
|
parent_ijk->set_j( (int)pj );
|
||||||
|
parent_ijk->set_k( (int)pk );
|
||||||
|
cellInfo->set_allocated_parent_ijk( parent_ijk );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RigActiveCellInfo* RiaGrpcActiveCellInfoStateHandler::activeCellInfo() const
|
||||||
|
{
|
||||||
|
return m_activeCellInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
const std::vector<RigCell>& RiaGrpcActiveCellInfoStateHandler::reservoirCells() const
|
||||||
|
{
|
||||||
|
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
||||||
|
return reservoirCells;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcActiveCellInfoStateHandler::assignReply( rips::CellInfoArray* reply )
|
||||||
|
{
|
||||||
|
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::CellInfo ) );
|
||||||
|
size_t indexInPackage = 0u;
|
||||||
|
reply->mutable_data()->Reserve( (int)packageSize );
|
||||||
|
|
||||||
|
// Stream until you've reached the package size or total cell count. Whatever comes first.
|
||||||
|
// If you've reached the package size you'll come back for another round.
|
||||||
|
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
|
||||||
|
{
|
||||||
|
rips::CellInfo singleCellInfo;
|
||||||
|
grpc::Status singleCellInfoStatus = assignNextActiveCellInfoData( &singleCellInfo );
|
||||||
|
if ( singleCellInfoStatus.ok() )
|
||||||
|
{
|
||||||
|
rips::CellInfo* allocCellInfo = reply->add_data();
|
||||||
|
*allocCellInfo = singleCellInfo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( indexInPackage > 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" );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcActiveCellInfoStateHandler::assignNextActiveCellCenter( rips::Vec3d* cellCenter )
|
||||||
|
{
|
||||||
|
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
||||||
|
|
||||||
|
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 RiaGrpcActiveCellInfoStateHandler::assignCellCenter( rips::Vec3d* cellCenter,
|
||||||
|
const std::vector<RigCell>& reservoirCells,
|
||||||
|
size_t cellIdx )
|
||||||
|
|
||||||
|
{
|
||||||
|
cvf::Vec3d center = reservoirCells[cellIdx].center();
|
||||||
|
|
||||||
|
RiaGrpcHelper::convertVec3dToPositiveDepth( ¢er );
|
||||||
|
|
||||||
|
cellCenter->set_x( center.x() );
|
||||||
|
cellCenter->set_y( center.y() );
|
||||||
|
cellCenter->set_z( center.z() );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcActiveCellInfoStateHandler::assignCellCentersReply( rips::CellCenters* reply )
|
||||||
|
{
|
||||||
|
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::Vec3d ) );
|
||||||
|
size_t indexInPackage = 0u;
|
||||||
|
reply->mutable_centers()->Reserve( (int)packageSize );
|
||||||
|
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
|
||||||
|
{
|
||||||
|
rips::Vec3d singleCellCenter;
|
||||||
|
grpc::Status singleCellCenterStatus = assignNextActiveCellCenter( &singleCellCenter );
|
||||||
|
if ( singleCellCenterStatus.ok() )
|
||||||
|
{
|
||||||
|
rips::Vec3d* allocCellCenter = reply->add_centers();
|
||||||
|
*allocCellCenter = singleCellCenter;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( indexInPackage > 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" );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
Status RiaGrpcActiveCellInfoStateHandler::assignNextActiveCellCorners( rips::CellCorners* cellCorners )
|
||||||
|
{
|
||||||
|
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
||||||
|
|
||||||
|
while ( m_currentCellIdx < reservoirCells.size() )
|
||||||
|
{
|
||||||
|
size_t cellIdxToTry = m_currentCellIdx++;
|
||||||
|
if ( m_activeCellInfo->isActive( cellIdxToTry ) )
|
||||||
|
{
|
||||||
|
assignCellCorners( cellCorners, 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 RiaGrpcActiveCellInfoStateHandler::assignCellCorners( rips::CellCorners* corners,
|
||||||
|
const std::vector<RigCell>& reservoirCells,
|
||||||
|
size_t cellIdx )
|
||||||
|
{
|
||||||
|
RigGridBase* grid = m_eclipseCase->eclipseCaseData()->mainGrid();
|
||||||
|
std::array<cvf::Vec3d, 8> cornerVerts = grid->cellCornerVertices( cellIdx );
|
||||||
|
for ( cvf::Vec3d& corner : cornerVerts )
|
||||||
|
{
|
||||||
|
RiaGrpcHelper::convertVec3dToPositiveDepth( &corner );
|
||||||
|
}
|
||||||
|
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c0(), cornerVerts[0] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c1(), cornerVerts[1] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c2(), cornerVerts[2] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c3(), cornerVerts[3] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c4(), cornerVerts[4] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c5(), cornerVerts[5] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c6(), cornerVerts[6] );
|
||||||
|
RiaGrpcHelper::setCornerValues( corners->mutable_c7(), cornerVerts[7] );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
Status RiaGrpcActiveCellInfoStateHandler::assignCellCornersReply( rips::CellCornersArray* reply )
|
||||||
|
{
|
||||||
|
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::CellCorners ) );
|
||||||
|
size_t indexInPackage = 0u;
|
||||||
|
reply->mutable_cells()->Reserve( (int)packageSize );
|
||||||
|
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
|
||||||
|
{
|
||||||
|
rips::CellCorners singleCellCorners;
|
||||||
|
grpc::Status singleCellCornersStatus = assignNextActiveCellCorners( &singleCellCorners );
|
||||||
|
if ( singleCellCornersStatus.ok() )
|
||||||
|
{
|
||||||
|
rips::CellCorners* allocCellCorners = reply->add_cells();
|
||||||
|
*allocCellCorners = singleCellCorners;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( indexInPackage > 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" );
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2025 Equinor ASA
|
||||||
|
//
|
||||||
|
// 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 "Case.grpc.pb.h"
|
||||||
|
|
||||||
|
#include "RiaPorosityModel.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class RigCell;
|
||||||
|
class RigActiveCellInfo;
|
||||||
|
class RimEclipseCase;
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
//
|
||||||
|
// State handler for streaming of active cell info
|
||||||
|
//
|
||||||
|
//==================================================================================================
|
||||||
|
class RiaGrpcActiveCellInfoStateHandler
|
||||||
|
{
|
||||||
|
using Status = grpc::Status;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RiaGrpcActiveCellInfoStateHandler();
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
// For cell corners:
|
||||||
|
Status assignNextActiveCellCorners( rips::CellCorners* cellCorners );
|
||||||
|
void assignCellCorners( rips::CellCorners* cellCorners, const std::vector<RigCell>& reservoirCells, size_t cellIdx );
|
||||||
|
Status assignCellCornersReply( rips::CellCornersArray* reply );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const rips::CellInfoRequest* m_request;
|
||||||
|
RimEclipseCase* m_eclipseCase;
|
||||||
|
RiaDefines::PorosityModelType m_porosityModel;
|
||||||
|
RigActiveCellInfo* m_activeCellInfo;
|
||||||
|
std::vector<size_t> m_globalCoarseningBoxIndexStart;
|
||||||
|
size_t m_currentCellIdx;
|
||||||
|
};
|
||||||
@@ -17,8 +17,10 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "RiaGrpcCaseService.h"
|
#include "RiaGrpcCaseService.h"
|
||||||
|
|
||||||
|
#include "RiaGrpcActiveCellInfoStateHandler.h"
|
||||||
#include "RiaGrpcCallbacks.h"
|
#include "RiaGrpcCallbacks.h"
|
||||||
#include "RiaGrpcHelper.h"
|
#include "RiaGrpcHelper.h"
|
||||||
|
#include "RiaGrpcSelectedCellsStateHandler.h"
|
||||||
#include "RiaSocketTools.h"
|
#include "RiaSocketTools.h"
|
||||||
|
|
||||||
#include "RigActiveCellInfo.h"
|
#include "RigActiveCellInfo.h"
|
||||||
@@ -36,327 +38,6 @@
|
|||||||
|
|
||||||
using namespace rips;
|
using namespace rips;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
RiaActiveCellInfoStateHandler::RiaActiveCellInfoStateHandler()
|
|
||||||
: m_request( nullptr )
|
|
||||||
, m_eclipseCase( nullptr )
|
|
||||||
, m_activeCellInfo( nullptr )
|
|
||||||
, m_currentCellIdx( 0u )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
grpc::Status RiaActiveCellInfoStateHandler::init( const rips::CellInfoRequest* request )
|
|
||||||
{
|
|
||||||
CAF_ASSERT( request );
|
|
||||||
m_request = request;
|
|
||||||
|
|
||||||
m_porosityModel = RiaDefines::PorosityModelType( m_request->porosity_model() );
|
|
||||||
RimCase* rimCase = RiaGrpcHelper::findCase( m_request->case_request().id() );
|
|
||||||
m_eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase );
|
|
||||||
|
|
||||||
if ( !m_eclipseCase )
|
|
||||||
{
|
|
||||||
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case not found" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !m_eclipseCase->eclipseCaseData() || !m_eclipseCase->eclipseCaseData()->mainGrid() )
|
|
||||||
{
|
|
||||||
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case Data not found" );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_activeCellInfo = m_eclipseCase->eclipseCaseData()->activeCellInfo( m_porosityModel );
|
|
||||||
|
|
||||||
if ( !m_activeCellInfo )
|
|
||||||
{
|
|
||||||
return grpc::Status( grpc::NOT_FOUND, "Active Cell Info not found" );
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t globalCoarseningBoxCount = 0;
|
|
||||||
|
|
||||||
for ( size_t gridIdx = 0; gridIdx < m_eclipseCase->eclipseCaseData()->gridCount(); gridIdx++ )
|
|
||||||
{
|
|
||||||
m_globalCoarseningBoxIndexStart.push_back( globalCoarseningBoxCount );
|
|
||||||
|
|
||||||
RigGridBase* grid = m_eclipseCase->eclipseCaseData()->grid( gridIdx );
|
|
||||||
|
|
||||||
size_t localCoarseningBoxCount = grid->coarseningBoxCount();
|
|
||||||
globalCoarseningBoxCount += localCoarseningBoxCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return grpc::Status::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
grpc::Status RiaActiveCellInfoStateHandler::assignNextActiveCellInfoData( rips::CellInfo* cellInfo )
|
|
||||||
{
|
|
||||||
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
|
||||||
|
|
||||||
while ( m_currentCellIdx < reservoirCells.size() )
|
|
||||||
{
|
|
||||||
size_t cellIdxToTry = m_currentCellIdx++;
|
|
||||||
if ( m_activeCellInfo->isActive( cellIdxToTry ) )
|
|
||||||
{
|
|
||||||
assignCellInfoData( cellInfo, 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::assignCellInfoData( rips::CellInfo* cellInfo,
|
|
||||||
const std::vector<RigCell>& reservoirCells,
|
|
||||||
size_t cellIdx )
|
|
||||||
{
|
|
||||||
RigGridBase* grid = reservoirCells[cellIdx].hostGrid();
|
|
||||||
CVF_ASSERT( grid != nullptr );
|
|
||||||
size_t cellIndex = reservoirCells[cellIdx].gridLocalCellIndex();
|
|
||||||
|
|
||||||
size_t i, j, k;
|
|
||||||
grid->ijkFromCellIndex( cellIndex, &i, &j, &k );
|
|
||||||
|
|
||||||
size_t pi, pj, pk;
|
|
||||||
RigGridBase* parentGrid = nullptr;
|
|
||||||
|
|
||||||
if ( grid->isMainGrid() )
|
|
||||||
{
|
|
||||||
pi = i;
|
|
||||||
pj = j;
|
|
||||||
pk = k;
|
|
||||||
parentGrid = grid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t parentCellIdx = reservoirCells[cellIdx].parentCellIndex();
|
|
||||||
parentGrid = ( static_cast<RigLocalGrid*>( grid ) )->parentGrid();
|
|
||||||
CVF_ASSERT( parentGrid != nullptr );
|
|
||||||
parentGrid->ijkFromCellIndex( parentCellIdx, &pi, &pj, &pk );
|
|
||||||
}
|
|
||||||
|
|
||||||
cellInfo->set_grid_index( (int)grid->gridIndex() );
|
|
||||||
cellInfo->set_parent_grid_index( (int)parentGrid->gridIndex() );
|
|
||||||
|
|
||||||
size_t coarseningIdx = reservoirCells[cellIdx].coarseningBoxIndex();
|
|
||||||
if ( coarseningIdx != cvf::UNDEFINED_SIZE_T )
|
|
||||||
{
|
|
||||||
size_t globalCoarseningIdx = m_globalCoarseningBoxIndexStart[grid->gridIndex()] + coarseningIdx;
|
|
||||||
cellInfo->set_coarsening_box_index( (int)globalCoarseningIdx );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cellInfo->set_coarsening_box_index( -1 );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
rips::Vec3i* local_ijk = new rips::Vec3i;
|
|
||||||
local_ijk->set_i( (int)i );
|
|
||||||
local_ijk->set_j( (int)j );
|
|
||||||
local_ijk->set_k( (int)k );
|
|
||||||
cellInfo->set_allocated_local_ijk( local_ijk );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
rips::Vec3i* parent_ijk = new rips::Vec3i;
|
|
||||||
parent_ijk->set_i( (int)pi );
|
|
||||||
parent_ijk->set_j( (int)pj );
|
|
||||||
parent_ijk->set_k( (int)pk );
|
|
||||||
cellInfo->set_allocated_parent_ijk( parent_ijk );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
RigActiveCellInfo* RiaActiveCellInfoStateHandler::activeCellInfo() const
|
|
||||||
{
|
|
||||||
return m_activeCellInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
const std::vector<RigCell>& RiaActiveCellInfoStateHandler::reservoirCells() const
|
|
||||||
{
|
|
||||||
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
|
||||||
return reservoirCells;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
grpc::Status RiaActiveCellInfoStateHandler::assignReply( rips::CellInfoArray* reply )
|
|
||||||
{
|
|
||||||
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::CellInfo ) );
|
|
||||||
size_t indexInPackage = 0u;
|
|
||||||
reply->mutable_data()->Reserve( (int)packageSize );
|
|
||||||
|
|
||||||
// Stream until you've reached the package size or total cell count. Whatever comes first.
|
|
||||||
// If you've reached the package size you'll come back for another round.
|
|
||||||
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
|
|
||||||
{
|
|
||||||
rips::CellInfo singleCellInfo;
|
|
||||||
grpc::Status singleCellInfoStatus = assignNextActiveCellInfoData( &singleCellInfo );
|
|
||||||
if ( singleCellInfoStatus.ok() )
|
|
||||||
{
|
|
||||||
rips::CellInfo* allocCellInfo = reply->add_data();
|
|
||||||
*allocCellInfo = singleCellInfo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( indexInPackage > 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" );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
grpc::Status RiaActiveCellInfoStateHandler::assignNextActiveCellCenter( rips::Vec3d* cellCenter )
|
|
||||||
{
|
|
||||||
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
RiaGrpcHelper::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 = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::Vec3d ) );
|
|
||||||
size_t indexInPackage = 0u;
|
|
||||||
reply->mutable_centers()->Reserve( (int)packageSize );
|
|
||||||
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
|
|
||||||
{
|
|
||||||
rips::Vec3d singleCellCenter;
|
|
||||||
grpc::Status singleCellCenterStatus = assignNextActiveCellCenter( &singleCellCenter );
|
|
||||||
if ( singleCellCenterStatus.ok() )
|
|
||||||
{
|
|
||||||
rips::Vec3d* allocCellCenter = reply->add_centers();
|
|
||||||
*allocCellCenter = singleCellCenter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( indexInPackage > 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" );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
Status RiaActiveCellInfoStateHandler::assignNextActiveCellCorners( rips::CellCorners* cellCorners )
|
|
||||||
{
|
|
||||||
const std::vector<RigCell>& reservoirCells = m_eclipseCase->eclipseCaseData()->mainGrid()->reservoirCells();
|
|
||||||
|
|
||||||
while ( m_currentCellIdx < reservoirCells.size() )
|
|
||||||
{
|
|
||||||
size_t cellIdxToTry = m_currentCellIdx++;
|
|
||||||
if ( m_activeCellInfo->isActive( cellIdxToTry ) )
|
|
||||||
{
|
|
||||||
assignCellCorners( cellCorners, 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::assignCellCorners( rips::CellCorners* corners,
|
|
||||||
const std::vector<RigCell>& reservoirCells,
|
|
||||||
size_t cellIdx )
|
|
||||||
{
|
|
||||||
RigGridBase* grid = m_eclipseCase->eclipseCaseData()->mainGrid();
|
|
||||||
std::array<cvf::Vec3d, 8> cornerVerts = grid->cellCornerVertices( cellIdx );
|
|
||||||
for ( cvf::Vec3d& corner : cornerVerts )
|
|
||||||
{
|
|
||||||
RiaGrpcHelper::convertVec3dToPositiveDepth( &corner );
|
|
||||||
}
|
|
||||||
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c0(), cornerVerts[0] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c1(), cornerVerts[1] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c2(), cornerVerts[2] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c3(), cornerVerts[3] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c4(), cornerVerts[4] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c5(), cornerVerts[5] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c6(), cornerVerts[6] );
|
|
||||||
RiaGrpcHelper::setCornerValues( corners->mutable_c7(), cornerVerts[7] );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
Status RiaActiveCellInfoStateHandler::assignCellCornersReply( rips::CellCornersArray* reply )
|
|
||||||
{
|
|
||||||
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::CellCorners ) );
|
|
||||||
size_t indexInPackage = 0u;
|
|
||||||
reply->mutable_cells()->Reserve( (int)packageSize );
|
|
||||||
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
|
|
||||||
{
|
|
||||||
rips::CellCorners singleCellCorners;
|
|
||||||
grpc::Status singleCellCornersStatus = assignNextActiveCellCorners( &singleCellCorners );
|
|
||||||
if ( singleCellCornersStatus.ok() )
|
|
||||||
{
|
|
||||||
rips::CellCorners* allocCellCorners = reply->add_cells();
|
|
||||||
*allocCellCorners = singleCellCorners;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( indexInPackage > 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" );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -502,10 +183,10 @@ grpc::Status RiaGrpcCaseService::GetPdmObject( grpc::ServerContext* context,
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
grpc::Status RiaGrpcCaseService::GetCellInfoForActiveCells( grpc::ServerContext* context,
|
grpc::Status RiaGrpcCaseService::GetCellInfoForActiveCells( grpc::ServerContext* context,
|
||||||
const rips::CellInfoRequest* request,
|
const rips::CellInfoRequest* request,
|
||||||
rips::CellInfoArray* reply,
|
rips::CellInfoArray* reply,
|
||||||
RiaActiveCellInfoStateHandler* stateHandler )
|
RiaGrpcActiveCellInfoStateHandler* stateHandler )
|
||||||
{
|
{
|
||||||
return stateHandler->assignReply( reply );
|
return stateHandler->assignReply( reply );
|
||||||
}
|
}
|
||||||
@@ -513,10 +194,10 @@ grpc::Status RiaGrpcCaseService::GetCellInfoForActiveCells( grpc::ServerContext*
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
grpc::Status RiaGrpcCaseService::GetCellCenterForActiveCells( grpc::ServerContext* context,
|
grpc::Status RiaGrpcCaseService::GetCellCenterForActiveCells( grpc::ServerContext* context,
|
||||||
const rips::CellInfoRequest* request,
|
const rips::CellInfoRequest* request,
|
||||||
rips::CellCenters* reply,
|
rips::CellCenters* reply,
|
||||||
RiaActiveCellInfoStateHandler* stateHandler )
|
RiaGrpcActiveCellInfoStateHandler* stateHandler )
|
||||||
{
|
{
|
||||||
return stateHandler->assignCellCentersReply( reply );
|
return stateHandler->assignCellCentersReply( reply );
|
||||||
}
|
}
|
||||||
@@ -524,10 +205,10 @@ grpc::Status RiaGrpcCaseService::GetCellCenterForActiveCells( grpc::ServerContex
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
grpc::Status RiaGrpcCaseService::GetCellCornersForActiveCells( grpc::ServerContext* context,
|
grpc::Status RiaGrpcCaseService::GetCellCornersForActiveCells( grpc::ServerContext* context,
|
||||||
const rips::CellInfoRequest* request,
|
const rips::CellInfoRequest* request,
|
||||||
rips::CellCornersArray* reply,
|
rips::CellCornersArray* reply,
|
||||||
RiaActiveCellInfoStateHandler* stateHandler )
|
RiaGrpcActiveCellInfoStateHandler* stateHandler )
|
||||||
{
|
{
|
||||||
return stateHandler->assignCellCornersReply( reply );
|
return stateHandler->assignCellCornersReply( reply );
|
||||||
}
|
}
|
||||||
@@ -535,128 +216,10 @@ grpc::Status RiaGrpcCaseService::GetCellCornersForActiveCells( grpc::ServerConte
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RiaSelectedCellsStateHandler::RiaSelectedCellsStateHandler()
|
grpc::Status RiaGrpcCaseService::GetSelectedCells( grpc::ServerContext* context,
|
||||||
: m_request( nullptr )
|
const rips::CaseRequest* request,
|
||||||
, m_eclipseCase( nullptr )
|
rips::SelectedCells* reply,
|
||||||
, m_currentItem( 0u )
|
RiaGrpcSelectedCellsStateHandler* stateHandler )
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
Status RiaSelectedCellsStateHandler::init( const rips::CaseRequest* request )
|
|
||||||
{
|
|
||||||
CAF_ASSERT( request );
|
|
||||||
m_request = request;
|
|
||||||
|
|
||||||
RimCase* rimCase = RiaGrpcHelper::findCase( m_request->id() );
|
|
||||||
m_eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase );
|
|
||||||
|
|
||||||
if ( !m_eclipseCase )
|
|
||||||
{
|
|
||||||
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case not found" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !m_eclipseCase->eclipseCaseData() || !m_eclipseCase->eclipseCaseData()->mainGrid() )
|
|
||||||
{
|
|
||||||
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case Data not found" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return grpc::Status::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
Status RiaSelectedCellsStateHandler::assignNextSelectedCell( rips::SelectedCell* cell,
|
|
||||||
const std::vector<RiuEclipseSelectionItem*>& items )
|
|
||||||
{
|
|
||||||
while ( m_currentItem < items.size() )
|
|
||||||
{
|
|
||||||
size_t itemToTry = m_currentItem++;
|
|
||||||
|
|
||||||
const RiuEclipseSelectionItem* item = items[itemToTry];
|
|
||||||
CVF_ASSERT( item->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT );
|
|
||||||
assignSelectedCell( cell, item );
|
|
||||||
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 RiaSelectedCellsStateHandler::assignSelectedCell( rips::SelectedCell* cell, const RiuEclipseSelectionItem* item )
|
|
||||||
{
|
|
||||||
CVF_ASSERT( item->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT );
|
|
||||||
size_t i = -1;
|
|
||||||
size_t j = -1;
|
|
||||||
size_t k = -1;
|
|
||||||
item->m_resultDefinition->eclipseCase()
|
|
||||||
->eclipseCaseData()
|
|
||||||
->grid( item->m_gridIndex )
|
|
||||||
->ijkFromCellIndex( item->m_gridLocalCellIndex, &i, &j, &k );
|
|
||||||
|
|
||||||
cell->set_grid_index( item->m_gridIndex );
|
|
||||||
rips::Vec3i* ijk = new rips::Vec3i;
|
|
||||||
ijk->set_i( (int)i );
|
|
||||||
ijk->set_j( (int)j );
|
|
||||||
ijk->set_k( (int)k );
|
|
||||||
cell->set_allocated_ijk( ijk );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
grpc::Status RiaSelectedCellsStateHandler::assignReply( rips::SelectedCells* reply )
|
|
||||||
{
|
|
||||||
std::vector<RiuSelectionItem*> items;
|
|
||||||
Riu3dSelectionManager::instance()->selectedItems( items );
|
|
||||||
|
|
||||||
// Only eclipse cases are currently supported. Also filter by case.
|
|
||||||
std::vector<RiuEclipseSelectionItem*> eclipseItems;
|
|
||||||
for ( auto item : items )
|
|
||||||
{
|
|
||||||
RiuEclipseSelectionItem* eclipseItem = dynamic_cast<RiuEclipseSelectionItem*>( item );
|
|
||||||
if ( eclipseItem && eclipseItem->m_resultDefinition->eclipseCase()->caseId() == m_request->id() )
|
|
||||||
{
|
|
||||||
eclipseItems.push_back( eclipseItem );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::SelectedCell ) );
|
|
||||||
size_t indexInPackage = 0u;
|
|
||||||
reply->mutable_cells()->Reserve( (int)packageSize );
|
|
||||||
for ( ; indexInPackage < packageSize && m_currentItem < eclipseItems.size(); ++indexInPackage )
|
|
||||||
{
|
|
||||||
rips::SelectedCell singleSelectedCell;
|
|
||||||
grpc::Status singleSelectedCellStatus = assignNextSelectedCell( &singleSelectedCell, eclipseItems );
|
|
||||||
if ( singleSelectedCellStatus.ok() )
|
|
||||||
{
|
|
||||||
rips::SelectedCell* allocSelectedCell = reply->add_cells();
|
|
||||||
*allocSelectedCell = singleSelectedCell;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( indexInPackage > 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" );
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
grpc::Status RiaGrpcCaseService::GetSelectedCells( grpc::ServerContext* context,
|
|
||||||
const rips::CaseRequest* request,
|
|
||||||
rips::SelectedCells* reply,
|
|
||||||
RiaSelectedCellsStateHandler* stateHandler )
|
|
||||||
{
|
{
|
||||||
return stateHandler->assignReply( reply );
|
return stateHandler->assignReply( reply );
|
||||||
}
|
}
|
||||||
@@ -723,6 +286,30 @@ grpc::Status RiaGrpcCaseService::GetCoarseningInfoArray( grpc::ServerContext*
|
|||||||
return Status( grpc::NOT_FOUND, "Case not found" );
|
return Status( grpc::NOT_FOUND, "Case not found" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcCaseService::GetDistanceToClosestFault( grpc::ServerContext* context,
|
||||||
|
const rips::ClosestFaultRequest* request,
|
||||||
|
rips::ClosestFault* reply )
|
||||||
|
{
|
||||||
|
RimCase* rimCase = RiaGrpcHelper::findCase( request->case_request().id() );
|
||||||
|
if ( auto eCase = dynamic_cast<RimEclipseCase*>( rimCase ) )
|
||||||
|
{
|
||||||
|
cvf::Vec3d point( request->point() );
|
||||||
|
point.z() = -point.z(); // Convert to internal coordinate system
|
||||||
|
|
||||||
|
auto [faultName, distance, faceType] = eCase->mainGrid()->minimumDistanceFaultToPoint( point );
|
||||||
|
|
||||||
|
reply->set_distance( distance );
|
||||||
|
reply->set_face_name( RiaGrpcHelper::faceTypeToString( faceType ) );
|
||||||
|
reply->set_fault_name( faultName.toStdString() );
|
||||||
|
|
||||||
|
return grpc::Status::OK;
|
||||||
|
}
|
||||||
|
return Status( grpc::NOT_FOUND, "Eclipse Case not found" );
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -741,38 +328,42 @@ std::vector<RiaGrpcCallbackInterface*> RiaGrpcCaseService::createCallbacks()
|
|||||||
new RiaGrpcServerToClientStreamCallback<Self,
|
new RiaGrpcServerToClientStreamCallback<Self,
|
||||||
CellInfoRequest,
|
CellInfoRequest,
|
||||||
CellInfoArray,
|
CellInfoArray,
|
||||||
RiaActiveCellInfoStateHandler>( this,
|
RiaGrpcActiveCellInfoStateHandler>( this,
|
||||||
&Self::GetCellInfoForActiveCells,
|
&Self::GetCellInfoForActiveCells,
|
||||||
&Self::RequestGetCellInfoForActiveCells,
|
&Self::RequestGetCellInfoForActiveCells,
|
||||||
new RiaActiveCellInfoStateHandler ),
|
new RiaGrpcActiveCellInfoStateHandler ),
|
||||||
new RiaGrpcServerToClientStreamCallback<Self,
|
new RiaGrpcServerToClientStreamCallback<Self,
|
||||||
CellInfoRequest,
|
CellInfoRequest,
|
||||||
CellCenters,
|
CellCenters,
|
||||||
RiaActiveCellInfoStateHandler>( this,
|
RiaGrpcActiveCellInfoStateHandler>( this,
|
||||||
&Self::GetCellCenterForActiveCells,
|
&Self::GetCellCenterForActiveCells,
|
||||||
&Self::RequestGetCellCenterForActiveCells,
|
&Self::RequestGetCellCenterForActiveCells,
|
||||||
new RiaActiveCellInfoStateHandler ),
|
new RiaGrpcActiveCellInfoStateHandler ),
|
||||||
new RiaGrpcServerToClientStreamCallback<Self,
|
new RiaGrpcServerToClientStreamCallback<Self,
|
||||||
CellInfoRequest,
|
CellInfoRequest,
|
||||||
CellCornersArray,
|
CellCornersArray,
|
||||||
RiaActiveCellInfoStateHandler>( this,
|
RiaGrpcActiveCellInfoStateHandler>( this,
|
||||||
&Self::GetCellCornersForActiveCells,
|
&Self::GetCellCornersForActiveCells,
|
||||||
&Self::RequestGetCellCornersForActiveCells,
|
&Self::RequestGetCellCornersForActiveCells,
|
||||||
new RiaActiveCellInfoStateHandler ),
|
new RiaGrpcActiveCellInfoStateHandler ),
|
||||||
new RiaGrpcServerToClientStreamCallback<Self,
|
new RiaGrpcServerToClientStreamCallback<Self,
|
||||||
CaseRequest,
|
CaseRequest,
|
||||||
SelectedCells,
|
SelectedCells,
|
||||||
RiaSelectedCellsStateHandler>( this,
|
RiaGrpcSelectedCellsStateHandler>( this,
|
||||||
&Self::GetSelectedCells,
|
&Self::GetSelectedCells,
|
||||||
&Self::RequestGetSelectedCells,
|
&Self::RequestGetSelectedCells,
|
||||||
new RiaSelectedCellsStateHandler ),
|
new RiaGrpcSelectedCellsStateHandler ),
|
||||||
new RiaGrpcUnaryCallback<Self, CaseRequest, BoundingBox>( this,
|
new RiaGrpcUnaryCallback<Self, CaseRequest, BoundingBox>( this,
|
||||||
&Self::GetReservoirBoundingBox,
|
&Self::GetReservoirBoundingBox,
|
||||||
&Self::RequestGetReservoirBoundingBox ),
|
&Self::RequestGetReservoirBoundingBox ),
|
||||||
|
|
||||||
new RiaGrpcUnaryCallback<Self, CaseRequest, CoarseningInfoArray>( this,
|
new RiaGrpcUnaryCallback<Self, CaseRequest, CoarseningInfoArray>( this,
|
||||||
&Self::GetCoarseningInfoArray,
|
&Self::GetCoarseningInfoArray,
|
||||||
&Self::RequestGetCoarseningInfoArray ) };
|
&Self::RequestGetCoarseningInfoArray ),
|
||||||
|
|
||||||
|
new RiaGrpcUnaryCallback<Self, ClosestFaultRequest, ClosestFault>( this,
|
||||||
|
&Self::GetDistanceToClosestFault,
|
||||||
|
&Self::RequestGetDistanceToClosestFault ) };
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool RiaGrpcCaseService_init =
|
static bool RiaGrpcCaseService_init =
|
||||||
|
|||||||
@@ -28,77 +28,15 @@ namespace rips
|
|||||||
{
|
{
|
||||||
class CaseRequest;
|
class CaseRequest;
|
||||||
class PdmObject;
|
class PdmObject;
|
||||||
|
class CaseInfo;
|
||||||
} // namespace rips
|
} // namespace rips
|
||||||
|
|
||||||
class RiaGrpcCallbackInterface;
|
class RiaGrpcCallbackInterface;
|
||||||
class RigCell;
|
class RigCell;
|
||||||
class RigActiveCellInfo;
|
class RigActiveCellInfo;
|
||||||
class RimEclipseCase;
|
class RimEclipseCase;
|
||||||
class RiuEclipseSelectionItem;
|
class RiaGrpcActiveCellInfoStateHandler;
|
||||||
|
class RiaGrpcSelectedCellsStateHandler;
|
||||||
//==================================================================================================
|
|
||||||
//
|
|
||||||
// State handler for streaming of active cell info
|
|
||||||
//
|
|
||||||
//==================================================================================================
|
|
||||||
class RiaActiveCellInfoStateHandler
|
|
||||||
{
|
|
||||||
using Status = grpc::Status;
|
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
// 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 );
|
|
||||||
|
|
||||||
// For cell corners:
|
|
||||||
Status assignNextActiveCellCorners( rips::CellCorners* cellCorners );
|
|
||||||
void assignCellCorners( rips::CellCorners* cellCorners, const std::vector<RigCell>& reservoirCells, size_t cellIdx );
|
|
||||||
Status assignCellCornersReply( rips::CellCornersArray* reply );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const rips::CellInfoRequest* m_request;
|
|
||||||
RimEclipseCase* m_eclipseCase;
|
|
||||||
RiaDefines::PorosityModelType m_porosityModel;
|
|
||||||
RigActiveCellInfo* m_activeCellInfo;
|
|
||||||
std::vector<size_t> m_globalCoarseningBoxIndexStart;
|
|
||||||
size_t m_currentCellIdx;
|
|
||||||
};
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
//
|
|
||||||
// State handler for streaming of selected cells
|
|
||||||
//
|
|
||||||
//==================================================================================================
|
|
||||||
class RiaSelectedCellsStateHandler
|
|
||||||
{
|
|
||||||
using Status = grpc::Status;
|
|
||||||
|
|
||||||
public:
|
|
||||||
RiaSelectedCellsStateHandler();
|
|
||||||
|
|
||||||
Status init( const rips::CaseRequest* request );
|
|
||||||
Status assignReply( rips::SelectedCells* reply );
|
|
||||||
void assignSelectedCell( rips::SelectedCell* cell, const RiuEclipseSelectionItem* item );
|
|
||||||
Status assignNextSelectedCell( rips::SelectedCell* cell, const std::vector<RiuEclipseSelectionItem*>& items );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const rips::CaseRequest* m_request;
|
|
||||||
RimEclipseCase* m_eclipseCase;
|
|
||||||
size_t m_currentItem;
|
|
||||||
};
|
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
//
|
//
|
||||||
@@ -122,22 +60,22 @@ public:
|
|||||||
grpc::Status GetCaseInfo( grpc::ServerContext* context, const rips::CaseRequest* request, rips::CaseInfo* reply ) override;
|
grpc::Status GetCaseInfo( grpc::ServerContext* context, const rips::CaseRequest* request, rips::CaseInfo* reply ) override;
|
||||||
grpc::Status
|
grpc::Status
|
||||||
GetPdmObject( grpc::ServerContext* context, const rips::CaseRequest* request, rips::PdmObject* reply ) override;
|
GetPdmObject( grpc::ServerContext* context, const rips::CaseRequest* request, rips::PdmObject* reply ) override;
|
||||||
grpc::Status GetCellInfoForActiveCells( grpc::ServerContext* context,
|
grpc::Status GetCellInfoForActiveCells( grpc::ServerContext* context,
|
||||||
const rips::CellInfoRequest* request,
|
const rips::CellInfoRequest* request,
|
||||||
rips::CellInfoArray* reply,
|
rips::CellInfoArray* reply,
|
||||||
RiaActiveCellInfoStateHandler* stateHandler );
|
RiaGrpcActiveCellInfoStateHandler* stateHandler );
|
||||||
grpc::Status GetCellCenterForActiveCells( grpc::ServerContext* context,
|
grpc::Status GetCellCenterForActiveCells( grpc::ServerContext* context,
|
||||||
const rips::CellInfoRequest* request,
|
const rips::CellInfoRequest* request,
|
||||||
rips::CellCenters* reply,
|
rips::CellCenters* reply,
|
||||||
RiaActiveCellInfoStateHandler* stateHandler );
|
RiaGrpcActiveCellInfoStateHandler* stateHandler );
|
||||||
grpc::Status GetCellCornersForActiveCells( grpc::ServerContext* context,
|
grpc::Status GetCellCornersForActiveCells( grpc::ServerContext* context,
|
||||||
const rips::CellInfoRequest* request,
|
const rips::CellInfoRequest* request,
|
||||||
rips::CellCornersArray* reply,
|
rips::CellCornersArray* reply,
|
||||||
RiaActiveCellInfoStateHandler* stateHandler );
|
RiaGrpcActiveCellInfoStateHandler* stateHandler );
|
||||||
grpc::Status GetSelectedCells( grpc::ServerContext* context,
|
grpc::Status GetSelectedCells( grpc::ServerContext* context,
|
||||||
const rips::CaseRequest* request,
|
const rips::CaseRequest* request,
|
||||||
rips::SelectedCells* reply,
|
rips::SelectedCells* reply,
|
||||||
RiaSelectedCellsStateHandler* stateHandler );
|
RiaGrpcSelectedCellsStateHandler* stateHandler );
|
||||||
grpc::Status GetReservoirBoundingBox( grpc::ServerContext* context,
|
grpc::Status GetReservoirBoundingBox( grpc::ServerContext* context,
|
||||||
const rips::CaseRequest* request,
|
const rips::CaseRequest* request,
|
||||||
rips::BoundingBox* reply ) override;
|
rips::BoundingBox* reply ) override;
|
||||||
@@ -145,5 +83,9 @@ public:
|
|||||||
const rips::CaseRequest* request,
|
const rips::CaseRequest* request,
|
||||||
rips::CoarseningInfoArray* reply ) override;
|
rips::CoarseningInfoArray* reply ) override;
|
||||||
|
|
||||||
|
grpc::Status GetDistanceToClosestFault( grpc::ServerContext* context,
|
||||||
|
const rips::ClosestFaultRequest* request,
|
||||||
|
rips::ClosestFault* reply ) override;
|
||||||
|
|
||||||
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
|
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
|
||||||
};
|
};
|
||||||
@@ -105,3 +105,25 @@ RimCase* RiaGrpcHelper::findCase( int caseId )
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RiaGrpcHelper::faceTypeToString( cvf::StructGridInterface::FaceType faceType )
|
||||||
|
{
|
||||||
|
switch ( faceType )
|
||||||
|
{
|
||||||
|
case cvf::StructGridInterface::POS_I:
|
||||||
|
return "I+";
|
||||||
|
case cvf::StructGridInterface::NEG_I:
|
||||||
|
return "I-";
|
||||||
|
case cvf::StructGridInterface::POS_J:
|
||||||
|
return "J+";
|
||||||
|
case cvf::StructGridInterface::NEG_J:
|
||||||
|
return "J-";
|
||||||
|
case cvf::StructGridInterface::POS_K:
|
||||||
|
return "K+";
|
||||||
|
case cvf::StructGridInterface::NEG_K:
|
||||||
|
return "K-";
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Definitions.grpc.pb.h"
|
#include "Definitions.grpc.pb.h"
|
||||||
|
|
||||||
|
#include "cvfStructGrid.h"
|
||||||
#include "cvfVector3.h"
|
#include "cvfVector3.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -51,4 +52,6 @@ public:
|
|||||||
|
|
||||||
static size_t numberOfDataUnitsInPackage( size_t dataUnitSize, size_t packageByteCount = 64 * 1024u );
|
static size_t numberOfDataUnitsInPackage( size_t dataUnitSize, size_t packageByteCount = 64 * 1024u );
|
||||||
static RimCase* findCase( int caseId );
|
static RimCase* findCase( int caseId );
|
||||||
|
|
||||||
|
static std::string faceTypeToString( cvf::StructGridInterface::FaceType );
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2019- Equinor ASA
|
||||||
|
//
|
||||||
|
// 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 "RiaGrpcSelectedCellsStateHandler.h"
|
||||||
|
|
||||||
|
#include "RiaGrpcCallbacks.h"
|
||||||
|
#include "RiaGrpcHelper.h"
|
||||||
|
#include "RiaSocketTools.h"
|
||||||
|
|
||||||
|
#include "RigActiveCellInfo.h"
|
||||||
|
#include "RigCaseCellResultsData.h"
|
||||||
|
#include "RigEclipseCaseData.h"
|
||||||
|
#include "RigEclipseResultAddress.h"
|
||||||
|
#include "RigMainGrid.h"
|
||||||
|
|
||||||
|
#include "RimEclipseCase.h"
|
||||||
|
#include "RimEclipseResultDefinition.h"
|
||||||
|
|
||||||
|
#include "Riu3dSelectionManager.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
using namespace rips;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RiaGrpcSelectedCellsStateHandler::RiaGrpcSelectedCellsStateHandler()
|
||||||
|
: m_request( nullptr )
|
||||||
|
, m_eclipseCase( nullptr )
|
||||||
|
, m_currentItem( 0u )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
Status RiaGrpcSelectedCellsStateHandler::init( const rips::CaseRequest* request )
|
||||||
|
{
|
||||||
|
CAF_ASSERT( request );
|
||||||
|
m_request = request;
|
||||||
|
|
||||||
|
RimCase* rimCase = RiaGrpcHelper::findCase( m_request->id() );
|
||||||
|
m_eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase );
|
||||||
|
|
||||||
|
if ( !m_eclipseCase )
|
||||||
|
{
|
||||||
|
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case not found" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_eclipseCase->eclipseCaseData() || !m_eclipseCase->eclipseCaseData()->mainGrid() )
|
||||||
|
{
|
||||||
|
return grpc::Status( grpc::NOT_FOUND, "Eclipse Case Data not found" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return grpc::Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
Status RiaGrpcSelectedCellsStateHandler::assignNextSelectedCell( rips::SelectedCell* cell,
|
||||||
|
const std::vector<RiuEclipseSelectionItem*>& items )
|
||||||
|
{
|
||||||
|
while ( m_currentItem < items.size() )
|
||||||
|
{
|
||||||
|
size_t itemToTry = m_currentItem++;
|
||||||
|
|
||||||
|
const RiuEclipseSelectionItem* item = items[itemToTry];
|
||||||
|
CVF_ASSERT( item->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT );
|
||||||
|
assignSelectedCell( cell, item );
|
||||||
|
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 RiaGrpcSelectedCellsStateHandler::assignSelectedCell( rips::SelectedCell* cell, const RiuEclipseSelectionItem* item )
|
||||||
|
{
|
||||||
|
CVF_ASSERT( item->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT );
|
||||||
|
size_t i = -1;
|
||||||
|
size_t j = -1;
|
||||||
|
size_t k = -1;
|
||||||
|
item->m_resultDefinition->eclipseCase()
|
||||||
|
->eclipseCaseData()
|
||||||
|
->grid( item->m_gridIndex )
|
||||||
|
->ijkFromCellIndex( item->m_gridLocalCellIndex, &i, &j, &k );
|
||||||
|
|
||||||
|
cell->set_grid_index( item->m_gridIndex );
|
||||||
|
rips::Vec3i* ijk = new rips::Vec3i;
|
||||||
|
ijk->set_i( (int)i );
|
||||||
|
ijk->set_j( (int)j );
|
||||||
|
ijk->set_k( (int)k );
|
||||||
|
cell->set_allocated_ijk( ijk );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
grpc::Status RiaGrpcSelectedCellsStateHandler::assignReply( rips::SelectedCells* reply )
|
||||||
|
{
|
||||||
|
std::vector<RiuSelectionItem*> items;
|
||||||
|
Riu3dSelectionManager::instance()->selectedItems( items );
|
||||||
|
|
||||||
|
// Only eclipse cases are currently supported. Also filter by case.
|
||||||
|
std::vector<RiuEclipseSelectionItem*> eclipseItems;
|
||||||
|
for ( auto item : items )
|
||||||
|
{
|
||||||
|
RiuEclipseSelectionItem* eclipseItem = dynamic_cast<RiuEclipseSelectionItem*>( item );
|
||||||
|
if ( eclipseItem && eclipseItem->m_resultDefinition->eclipseCase()->caseId() == m_request->id() )
|
||||||
|
{
|
||||||
|
eclipseItems.push_back( eclipseItem );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t packageSize = RiaGrpcHelper::numberOfDataUnitsInPackage( sizeof( rips::SelectedCell ) );
|
||||||
|
size_t indexInPackage = 0u;
|
||||||
|
reply->mutable_cells()->Reserve( (int)packageSize );
|
||||||
|
for ( ; indexInPackage < packageSize && m_currentItem < eclipseItems.size(); ++indexInPackage )
|
||||||
|
{
|
||||||
|
rips::SelectedCell singleSelectedCell;
|
||||||
|
grpc::Status singleSelectedCellStatus = assignNextSelectedCell( &singleSelectedCell, eclipseItems );
|
||||||
|
if ( singleSelectedCellStatus.ok() )
|
||||||
|
{
|
||||||
|
rips::SelectedCell* allocSelectedCell = reply->add_cells();
|
||||||
|
*allocSelectedCell = singleSelectedCell;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( indexInPackage > 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" );
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2025 Equinor ASA
|
||||||
|
//
|
||||||
|
// 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 "Case.grpc.pb.h"
|
||||||
|
|
||||||
|
#include "RiaGrpcServiceInterface.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace rips
|
||||||
|
{
|
||||||
|
class CaseRequest;
|
||||||
|
} // namespace rips
|
||||||
|
|
||||||
|
class RimEclipseCase;
|
||||||
|
class RiuEclipseSelectionItem;
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
//
|
||||||
|
// State handler for streaming of selected cells
|
||||||
|
//
|
||||||
|
//==================================================================================================
|
||||||
|
class RiaGrpcSelectedCellsStateHandler
|
||||||
|
{
|
||||||
|
using Status = grpc::Status;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RiaGrpcSelectedCellsStateHandler();
|
||||||
|
|
||||||
|
Status init( const rips::CaseRequest* request );
|
||||||
|
Status assignReply( rips::SelectedCells* reply );
|
||||||
|
void assignSelectedCell( rips::SelectedCell* cell, const RiuEclipseSelectionItem* item );
|
||||||
|
Status assignNextSelectedCell( rips::SelectedCell* cell, const std::vector<RiuEclipseSelectionItem*>& items );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const rips::CaseRequest* m_request;
|
||||||
|
RimEclipseCase* m_eclipseCase;
|
||||||
|
size_t m_currentItem;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user