mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-12 08:25:03 -05:00
* gRPC: Make names more consistent * gRPC: clean up case info and improve Python API for cases * gRPC: much more object oriented Python interface * Python: Make a proper pip-installable package * Update rips Python package to auto generate setup.py with version number * Python: add setup.py to gitignore * Python: Update Python RIPS interface * gRPC: Remove example client from cmake file and unit test * gRPC: Fix up unit test after merge and hide warnings * gRPC: fix up python client code
This commit is contained in:
1 parent
936fab3e32
commit
a468532d7f
50 files changed
+1058
-698
No files matched your search
@@ -313,12 +313,12 @@ if (MSVC)
|
||||
set( EXE_FILES WIN32)
|
||||
if (RESINSIGHT_ENABLE_GRPC)
|
||||
# GRPC generates a lot of harmless warnings on MSVC
|
||||
set_source_files_properties(${GRPC_CPP_SOURCES} PROPERTIES COMPILE_FLAGS "/wd4251 /wd4702 /wd4005 /wd4244 /wd4125")
|
||||
set_source_files_properties(${GRPC_CPP_SOURCES} ${GRPC_UNIT_TEST_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "/wd4251 /wd4702 /wd4005 /wd4244 /wd4125")
|
||||
endif(RESINSIGHT_ENABLE_GRPC)
|
||||
elseif (APPLE)
|
||||
set( EXE_FILES MACOSX_BUNDLE)
|
||||
else()
|
||||
set_source_files_properties(${GRPC_CPP_SOURCES} PROPERTIES COMPILE_FLAGS "-Wno-overloaded-virtual")
|
||||
set_source_files_properties(${GRPC_CPP_SOURCES} ${GRPC_UNIT_TESTS_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "-Wno-overloaded-virtual")
|
||||
endif()
|
||||
set( EXE_FILES
|
||||
${EXE_FILES}
|
||||
|
||||
@@ -5,20 +5,22 @@ set ( SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCallbacks.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridInfoService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectInfoService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcResInfoService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppInfoService.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.h
|
||||
)
|
||||
|
||||
set ( SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridInfoService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectInfoService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcResInfoService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppInfoService.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.cpp
|
||||
)
|
||||
|
||||
@@ -70,12 +72,12 @@ endif(PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||
# Proto files
|
||||
set(PROTO_FILES
|
||||
"Empty"
|
||||
"CaseInfo"
|
||||
"GridInfo"
|
||||
"ProjectInfo"
|
||||
"Case"
|
||||
"Project"
|
||||
"Commands"
|
||||
"ResInfo"
|
||||
"AppInfo"
|
||||
"Properties"
|
||||
"Grid"
|
||||
)
|
||||
|
||||
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/Python")
|
||||
@@ -138,24 +140,33 @@ foreach(proto_file ${PROTO_FILES})
|
||||
|
||||
endforeach(proto_file)
|
||||
|
||||
if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||
if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||
list(APPEND GRPC_PYTHON_SOURCES
|
||||
${GRPC_PYTHON_GENERATED_SOURCES}
|
||||
"generated/RiaVersionInfo.py"
|
||||
"api/__init__.py"
|
||||
"api/ResInsight.py"
|
||||
"rips/__init__.py"
|
||||
"rips/AppInfo.py"
|
||||
"rips/Case.py"
|
||||
"rips/Commands.py"
|
||||
"rips/Grid.py"
|
||||
"rips/Project.py"
|
||||
"rips/Properties.py"
|
||||
"rips/Instance.py"
|
||||
"examples/CommandExample.py"
|
||||
"examples/GridInfoStreamingExample.py"
|
||||
"examples/CaseInfoStreamingExample.py"
|
||||
"examples/PoroPermXSync.py"
|
||||
"examples/PoroPermXAsync.py"
|
||||
"examples/SoilPorvAsync.py"
|
||||
"examples/SoilPorvSync.py"
|
||||
"examples/ResultValues.py"
|
||||
"examples/SelectedCases.py"
|
||||
"examples/AllCases.py"
|
||||
"examples/SetActiveCellProperties.py"
|
||||
"examples/SetGridProperties.py"
|
||||
"examples/GridInformation.py"
|
||||
"tests/test_sample.py"
|
||||
"requirements.txt"
|
||||
"setup.py.cmake"
|
||||
"README.md"
|
||||
"LICENSE"
|
||||
)
|
||||
|
||||
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
|
||||
@@ -173,6 +184,9 @@ list ( APPEND GRPC_CPP_SOURCES ${SOURCE_GROUP_SOURCE_FILES})
|
||||
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
|
||||
${GRPC_PYTHON_SOURCE_PATH}/generated/RiaVersionInfo.py
|
||||
)
|
||||
CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
|
||||
${GRPC_PYTHON_SOURCE_PATH}/setup.py
|
||||
)
|
||||
|
||||
source_group( "GrpcInterface" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.cmake )
|
||||
source_group( "GrpcInterface\\GrpcProtos" FILES ${GRPC_PROTO_FILES_FULL_PATH} )
|
||||
+1
-1
@@ -4,7 +4,7 @@ package rips;
|
||||
|
||||
import "Empty.proto";
|
||||
|
||||
service ResInfo {
|
||||
service AppInfo {
|
||||
rpc GetVersion(Empty) returns (Version) {}
|
||||
}
|
||||
|
||||
+38
-18
@@ -1,19 +1,44 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "CaseInfo.proto";
|
||||
|
||||
package rips;
|
||||
|
||||
service GridInfo
|
||||
service Case
|
||||
{
|
||||
// This function returns a two dimensional matrix: One row for each grid, starting with the main grid.
|
||||
rpc GetGridCount(Case) returns(GridCount) {}
|
||||
rpc GetGridDimensions(Case) returns (GridDimensions) {}
|
||||
rpc GetGridCount(CaseRequest) returns(GridCount) {}
|
||||
rpc GetCellCount(CellInfoRequest) returns (CellCount) {}
|
||||
rpc GetCellInfoForActiveCells(CellInfoRequest) returns (stream CellInfoArray) {}
|
||||
rpc GetAllCoarseningInfoArray(Case) returns (CoarseningInfoArray) {}
|
||||
rpc GetTimeSteps(Case) returns (TimeStepDates) {}
|
||||
rpc GetTimeStepDaysSinceStart(Case) returns (DoubleDates) {}
|
||||
rpc GetCoarseningInfoArray(CaseRequest) returns (CoarseningInfoArray) {}
|
||||
rpc GetTimeSteps(CaseRequest) returns (TimeStepDates) {}
|
||||
rpc GetTimeStepDaysSinceStart(CaseRequest) returns (DoubleDates) {}
|
||||
rpc GetCaseInfo(CaseRequest) returns (CaseInfo) {}
|
||||
}
|
||||
|
||||
message CaseRequest {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
message CaseInfo
|
||||
{
|
||||
int32 id = 1;
|
||||
int32 group_id = 2;
|
||||
string name = 3;
|
||||
string type = 4;
|
||||
}
|
||||
|
||||
message CaseInfoArray
|
||||
{
|
||||
repeated CaseInfo data = 1;
|
||||
}
|
||||
|
||||
message CaseGroup
|
||||
{
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message CaseGroups
|
||||
{
|
||||
repeated CaseGroup case_groups = 1;
|
||||
}
|
||||
|
||||
message GridCount
|
||||
@@ -21,11 +46,6 @@ message GridCount
|
||||
int32 count = 1;
|
||||
}
|
||||
|
||||
message GridDimensions
|
||||
{
|
||||
repeated Vec3i dimensions = 1;
|
||||
}
|
||||
|
||||
message Vec3i {
|
||||
int32 i = 1;
|
||||
int32 j = 2;
|
||||
@@ -46,7 +66,7 @@ enum PorosityModelType
|
||||
|
||||
message CellInfoRequest
|
||||
{
|
||||
int32 case_id = 1;
|
||||
CaseRequest case_request = 1;
|
||||
PorosityModelType porosity_model = 2;
|
||||
}
|
||||
|
||||
@@ -77,7 +97,7 @@ message CoarseningInfo
|
||||
|
||||
message TimeStepDates
|
||||
{
|
||||
repeated TimeStepDate date = 1;
|
||||
repeated TimeStepDate dates = 1;
|
||||
}
|
||||
|
||||
message TimeStepDate
|
||||
@@ -92,5 +112,5 @@ message TimeStepDate
|
||||
|
||||
message DoubleDates
|
||||
{
|
||||
repeated double date_decimal = 1;
|
||||
}
|
||||
repeated double date_decimals = 1;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package rips;
|
||||
|
||||
message Case {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
message CaseInfo
|
||||
{
|
||||
int32 id = 1;
|
||||
int32 group_id = 2;
|
||||
string name = 3;
|
||||
string type = 4;
|
||||
}
|
||||
|
||||
message CaseInfos
|
||||
{
|
||||
repeated CaseInfo case_info = 1;
|
||||
}
|
||||
|
||||
message CaseGroup
|
||||
{
|
||||
int32 id = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message CaseGroups
|
||||
{
|
||||
repeated CaseGroup case_group = 1;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "CaseInfo.proto";
|
||||
import "Case.proto";
|
||||
import "Empty.proto";
|
||||
|
||||
package rips;
|
||||
@@ -272,8 +272,8 @@ message CommandReply
|
||||
{
|
||||
oneof result
|
||||
{
|
||||
Empty emptyResult = 1;
|
||||
Case loadCaseResult = 2;
|
||||
Empty emptyResult = 1;
|
||||
CaseRequest loadCaseResult = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package rips;
|
||||
|
||||
import "Case.proto";
|
||||
|
||||
service Grid
|
||||
{
|
||||
rpc GetCellCenters(GridRequest) returns(CellCenters) {}
|
||||
rpc GetDimensions(GridRequest) returns (GridDimensions) {}
|
||||
}
|
||||
|
||||
message GridRequest
|
||||
{
|
||||
CaseRequest case_request = 1;
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "Case.proto";
|
||||
import "Empty.proto";
|
||||
|
||||
package rips;
|
||||
|
||||
service Project {
|
||||
rpc GetCurrentCase(Empty) returns (CaseRequest) {}
|
||||
rpc GetSelectedCases(Empty) returns (CaseInfoArray) {}
|
||||
rpc GetAllCaseGroups(Empty) returns (CaseGroups) {}
|
||||
rpc GetAllCases(Empty) returns (CaseInfoArray) {}
|
||||
rpc GetCasesInGroup(CaseGroup) returns (CaseInfoArray) {}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "CaseInfo.proto";
|
||||
import "Empty.proto";
|
||||
|
||||
package rips;
|
||||
|
||||
service ProjectInfo {
|
||||
rpc CurrentCase(Empty) returns (Case) {}
|
||||
rpc CurrentCaseInfo(Empty) returns (CaseInfo) {}
|
||||
rpc CaseInfoFromCase(Case) returns (CaseInfo) {}
|
||||
rpc SelectedCases(Empty) returns (CaseInfos) {}
|
||||
rpc AllCaseGroups(Empty) returns (CaseGroups) {}
|
||||
rpc AllCases(Empty) returns (CaseInfos) {}
|
||||
rpc CasesInGroup(CaseGroup) returns (CaseInfos) {}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "Empty.proto";
|
||||
import "CaseInfo.proto";
|
||||
import "GridInfo.proto";
|
||||
import "Case.proto";
|
||||
|
||||
package rips;
|
||||
|
||||
service Properties
|
||||
{
|
||||
rpc GetAvailableProperties(PropertiesRequest) returns (AvailableProperties) {}
|
||||
rpc GetActiveCellResults(ResultRequest) returns (stream ResultArray) {}
|
||||
rpc GetGridResults(ResultRequest) returns (stream ResultArray) {}
|
||||
rpc SetActiveCellResults(stream ResultRequestChunk) returns (Empty) {}
|
||||
rpc SetGridResults(stream ResultRequestChunk) returns (Empty) {}
|
||||
rpc GetAvailableProperties(AvailablePropertiesRequest) returns (AvailableProperties) {}
|
||||
rpc GetActiveCellProperty(PropertyRequest) returns (stream PropertyChunk) {}
|
||||
rpc GetGridProperty(PropertyRequest) returns (stream PropertyChunk) {}
|
||||
rpc SetActiveCellProperty(stream PropertyInputChunk) returns (Empty) {}
|
||||
rpc SetGridProperty(stream PropertyInputChunk) returns (Empty) {}
|
||||
}
|
||||
|
||||
enum PropertyType
|
||||
@@ -29,9 +28,9 @@ enum PropertyType
|
||||
UNDEFINED = 999;
|
||||
}
|
||||
|
||||
message PropertiesRequest
|
||||
message AvailablePropertiesRequest
|
||||
{
|
||||
Case request_case = 1;
|
||||
CaseRequest case_request = 1;
|
||||
PropertyType property_type = 2;
|
||||
PorosityModelType porosity_model = 3;
|
||||
}
|
||||
@@ -41,9 +40,9 @@ message AvailableProperties
|
||||
repeated string property_names = 1;
|
||||
}
|
||||
|
||||
message ResultRequest
|
||||
message PropertyRequest
|
||||
{
|
||||
Case request_case = 1;
|
||||
CaseRequest case_request = 1;
|
||||
PropertyType property_type = 2;
|
||||
string property_name = 3;
|
||||
int32 time_step = 4;
|
||||
@@ -56,14 +55,17 @@ message TimeStep
|
||||
int32 index = 1;
|
||||
}
|
||||
|
||||
message ResultRequestChunk
|
||||
message PropertyInputChunk
|
||||
{
|
||||
// Params needs to be sent in the first message
|
||||
ResultRequest params = 1;
|
||||
ResultArray values = 2;
|
||||
oneof ChunkType
|
||||
{
|
||||
// Params needs to be sent in the first message
|
||||
PropertyRequest params = 1;
|
||||
PropertyChunk values = 2;
|
||||
}
|
||||
}
|
||||
|
||||
message ResultArray
|
||||
message PropertyChunk
|
||||
{
|
||||
repeated double values = 1;
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
generated
|
||||
generated
|
||||
dist
|
||||
build
|
||||
rips.egg-info
|
||||
setup.py
|
||||
@@ -0,0 +1,14 @@
|
||||
Copyright (C) 2019- Equinor ASA
|
||||
|
||||
ResInsight is free software: you can redistribute it andor 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.orglicensesgpl.html>
|
||||
for more details.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# ResInsight Processing Server - rips
|
||||
|
||||
A Python interface for the ResInsight visualization and post-processing suite for Reservoir Simulations
|
||||
|
||||
[Learn More](https://www.resinsight.org)
|
||||
@@ -1,302 +0,0 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
import logging
|
||||
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
from Empty_pb2 import Empty
|
||||
import CaseInfo_pb2
|
||||
import CaseInfo_pb2_grpc
|
||||
import Commands_pb2 as Cmd
|
||||
import Commands_pb2_grpc as CmdRpc
|
||||
import GridInfo_pb2
|
||||
import GridInfo_pb2_grpc
|
||||
import ProjectInfo_pb2
|
||||
import ProjectInfo_pb2_grpc
|
||||
import ResInfo_pb2
|
||||
import ResInfo_pb2_grpc
|
||||
import Properties_pb2
|
||||
import Properties_pb2_grpc
|
||||
import RiaVersionInfo
|
||||
|
||||
class ResInfo:
|
||||
def __init__(self, channel):
|
||||
self.resInfo = ResInfo_pb2_grpc.ResInfoStub(channel)
|
||||
def versionMessage(self):
|
||||
return self.resInfo.GetVersion(Empty())
|
||||
def majorVersion(self):
|
||||
return self.versionMessage().major_version
|
||||
def minorVersion(self):
|
||||
return self.versionMessage().minor_version
|
||||
def patchVersion(self):
|
||||
return self.versionMessage().patch_version
|
||||
def versionString(self):
|
||||
return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion())
|
||||
|
||||
class CommandExecutor:
|
||||
def __init__(self, channel):
|
||||
self.commands = CmdRpc.CommandsStub(channel)
|
||||
|
||||
def execute(self, commandParams):
|
||||
try:
|
||||
return self.commands.Execute(commandParams)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error")
|
||||
|
||||
def setTimeStep(self, caseId, timeStep):
|
||||
return self.execute(Cmd.CommandParams(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep)))
|
||||
|
||||
def setMainWindowSize(self, width, height):
|
||||
return self.execute(Cmd.CommandParams(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)))
|
||||
|
||||
def openProject(self, path):
|
||||
return self.execute(Cmd.CommandParams(openProject=Cmd.FilePathRequest(path=path)))
|
||||
|
||||
def loadCase(self, path):
|
||||
commandReply = self.execute(Cmd.CommandParams(loadCase=Cmd.FilePathRequest(path=path)))
|
||||
assert commandReply.HasField("loadCaseResult")
|
||||
return commandReply.loadCaseResult.id
|
||||
|
||||
def closeProject(self):
|
||||
return self.execute(Cmd.CommandParams(closeProject=Empty()))
|
||||
|
||||
def exportWellPaths(self, wellPaths=[], mdStepSize=5.0):
|
||||
if isinstance(wellPaths, str):
|
||||
wellPathArray = [str]
|
||||
elif isinstance(wellPaths, list):
|
||||
wellPathArray = wellPaths
|
||||
return self.execute(Cmd.CommandParams(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize)))
|
||||
|
||||
class GridInfo:
|
||||
def __init__(self, channel):
|
||||
self.gridInfo = GridInfo_pb2_grpc.GridInfoStub(channel)
|
||||
|
||||
def gridCount(self, caseId=0):
|
||||
return self.gridInfo.GetGridCount(CaseInfo_pb2.Case(id=caseId)).count
|
||||
|
||||
def gridDimensions(self, caseId=0):
|
||||
return self.gridInfo.GetGridDimensions(CaseInfo_pb2.Case(id=caseId)).dimensions
|
||||
|
||||
def cellCount(self, caseId=0, porosityModel='MATRIX_MODEL'):
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = GridInfo_pb2.CellInfoRequest(case_id=caseId,
|
||||
porosity_model=porosityModel)
|
||||
return self.gridInfo.GetCellCount(request)
|
||||
|
||||
def cellInfoForActiveCells(self, caseId=0, porosityModel='MATRIX_MODEL'):
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = GridInfo_pb2.CellInfoRequest(case_id=caseId,
|
||||
porosity_model=porosityModel)
|
||||
return self.gridInfo.GetCellInfoForActiveCells(request)
|
||||
|
||||
def timeSteps(self, caseId=0):
|
||||
return self.gridInfo.GetTimeSteps(CaseInfo_pb2.Case(id=caseId))
|
||||
|
||||
class ProjectInfo:
|
||||
def __init__(self, channel):
|
||||
self.projectInfo = ProjectInfo_pb2_grpc.ProjectInfoStub(channel)
|
||||
def selectedCases(self):
|
||||
selected = self.projectInfo.SelectedCases(Empty())
|
||||
if selected is not None:
|
||||
return selected.case_info
|
||||
else:
|
||||
return None
|
||||
def allCases(self):
|
||||
cases = self.projectInfo.AllCases(Empty())
|
||||
if cases is not None:
|
||||
return cases.case_info
|
||||
else:
|
||||
return None
|
||||
|
||||
class Properties:
|
||||
def __init__(self, channel):
|
||||
self.properties = Properties_pb2_grpc.PropertiesStub(channel)
|
||||
|
||||
def generateResultRequestArrayIterator(self, values_iterator, parameters):
|
||||
chunk = Properties_pb2.ResultRequestChunk()
|
||||
chunk.params.CopyFrom(parameters)
|
||||
yield chunk
|
||||
|
||||
for values in values_iterator:
|
||||
valmsg = Properties_pb2.ResultArray(values = values)
|
||||
chunk.values.CopyFrom(valmsg)
|
||||
yield chunk
|
||||
|
||||
def generateResultRequestChunks(self, array, parameters):
|
||||
# Each double is 8 bytes. A good chunk size is 64KiB = 65536B
|
||||
# Meaning ideal number of doubles would be 8192.
|
||||
# However we need overhead space, so if we choose 8160 in chunk size
|
||||
# We have 256B left for overhead which should be plenty
|
||||
chunkSize = 8000
|
||||
index = -1
|
||||
while index < len(array):
|
||||
chunk = Properties_pb2.ResultRequestChunk()
|
||||
if index is -1:
|
||||
chunk.params.CopyFrom(parameters)
|
||||
index += 1;
|
||||
else:
|
||||
actualChunkSize = min(len(array) - index + 1, chunkSize)
|
||||
chunk.values.CopyFrom(Properties_pb2.ResultArray(values = array[index:index+actualChunkSize]))
|
||||
index += actualChunkSize
|
||||
|
||||
yield chunk
|
||||
# Final empty message to signal completion
|
||||
chunk = Properties_pb2.ResultRequestChunk()
|
||||
yield chunk
|
||||
|
||||
def availableProperties(self, caseId, propertyType, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.PropertiesRequest (request_case = CaseInfo_pb2.Case(id=caseId),
|
||||
property_type = propertyTypeEnum,
|
||||
porosity_model = porosityModelEnum)
|
||||
return self.properties.GetAvailableProperties(request).property_names
|
||||
def activeCellResults(self, caseId, propertyType, propertyName, timeStep, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
porosity_model = porosityModelEnum)
|
||||
for chunk in self.properties.GetActiveCellResults(request):
|
||||
yield chunk
|
||||
|
||||
def gridCellResults(self, caseId, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
return self.properties.GetGridResults(request)
|
||||
|
||||
def setActiveCellResultsAsync(self, values_iterator, caseId, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
try:
|
||||
reply_iterator = self.generateResultRequestArrayIterator(values_iterator, request)
|
||||
self.properties.SetActiveCellResults(reply_iterator)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
|
||||
def setActiveCellResults(self, values, caseId, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
try:
|
||||
request_iterator = self.generateResultRequestChunks(values, request)
|
||||
self.properties.SetActiveCellResults(request_iterator)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
def setGridResults(self, values, caseId, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
try:
|
||||
request_iterator = self.generateResultRequestArrays(values, request)
|
||||
self.properties.SetGridResults(request_iterator)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
|
||||
class Instance:
|
||||
@staticmethod
|
||||
def is_port_in_use(port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.settimeout(0.2)
|
||||
return s.connect_ex(('localhost', port)) == 0
|
||||
|
||||
@staticmethod
|
||||
def launch():
|
||||
port = 50051
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
port = int(portEnv)
|
||||
|
||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
||||
if resInsightExecutable is None:
|
||||
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
|
||||
return None
|
||||
|
||||
while Instance.is_port_in_use(port):
|
||||
port += 1
|
||||
|
||||
print('Port ' + str(port))
|
||||
print('Trying to launch', resInsightExecutable)
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
|
||||
print(pid)
|
||||
return Instance(port)
|
||||
|
||||
@staticmethod
|
||||
def find(startPort = 50051, endPort = 50071):
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
startPort = int(portEnv)
|
||||
endPort = startPort + 20
|
||||
|
||||
for tryPort in range(startPort, endPort):
|
||||
if Instance.is_port_in_use(tryPort):
|
||||
return Instance(tryPort)
|
||||
|
||||
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
|
||||
return None
|
||||
|
||||
def __init__(self, port = 50051):
|
||||
logging.basicConfig()
|
||||
location = "localhost:" + str(port)
|
||||
self.channel = grpc.insecure_channel(location)
|
||||
|
||||
# Main version check package
|
||||
self.resInfo = ResInfo(self.channel)
|
||||
try:
|
||||
majorVersionOk = self.resInfo.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
|
||||
minorVersionOk = self.resInfo.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
|
||||
if not (majorVersionOk and minorVersionOk):
|
||||
raise Exception('Version of ResInsight does not match version of Python API')
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.UNAVAILABLE:
|
||||
print('Info: Could not find any instances at port ' + str(port))
|
||||
except Exception as e:
|
||||
print('Error:', e)
|
||||
|
||||
# Service packages
|
||||
self.commands = CommandExecutor(self.channel)
|
||||
self.gridInfo = GridInfo(self.channel)
|
||||
self.projectInfo = ProjectInfo(self.channel)
|
||||
self.properties = Properties(self.channel)
|
||||
|
||||
Whitespace-only changes.
@@ -1,13 +1,11 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import rips
|
||||
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
resInsight = rips.Instance.find()
|
||||
if resInsight is not None:
|
||||
caseInfos = resInsight.projectInfo.allCases()
|
||||
|
||||
print ("Got " + str(len(caseInfos)) + " cases: ")
|
||||
for caseInfo in caseInfos:
|
||||
print(caseInfo.name)
|
||||
cases = resInsight.project.cases()
|
||||
|
||||
print ("Got " + str(len(cases)) + " cases: ")
|
||||
for case in cases:
|
||||
print(case.name)
|
||||
+4
-2
@@ -7,10 +7,12 @@ resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
cellCounts = resInsight.gridInfo.cellCount(caseId=0)
|
||||
case = resInsight.project.case(id = 0)
|
||||
|
||||
cellCounts = case.cellCount()
|
||||
print("Number of active cells: " + str(cellCounts.active_cell_count))
|
||||
|
||||
activeCellInfoChunks = resInsight.gridInfo.cellInfoForActiveCells(caseId=0)
|
||||
activeCellInfoChunks = case.cellInfoForActiveCells()
|
||||
|
||||
#print("Number of grids: " + str(gridCount))
|
||||
#print(gridDimensions)
|
||||
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
cases = resInsight.project.cases()
|
||||
print("Number of cases found: ", len(cases))
|
||||
for case in cases:
|
||||
print(case.name)
|
||||
grids = case.grids()
|
||||
print("Number of grids: ", len(grids))
|
||||
for grid in grids:
|
||||
print("Grid dimensions: ", grid.dimensions())
|
||||
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ def createResult(poroChunks, permxChunks):
|
||||
yield resultChunk
|
||||
|
||||
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
case = resInsight.project.case(id=0)
|
||||
|
||||
poroChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
|
||||
permxChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
|
||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
||||
|
||||
resInsight.properties.setActiveCellResultsAsync(createResult(poroChunks, permxChunks), 0, 'GENERATED', 'POROPERMXAS', 0)
|
||||
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks), 'GENERATED', 'POROPERMXAS', 0)
|
||||
|
||||
print("Transferred all results back")
|
||||
@@ -4,26 +4,25 @@ sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
for i in range(0, 40):
|
||||
poroChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
|
||||
poroResults = []
|
||||
for poroChunk in poroChunks:
|
||||
for poro in poroChunk.values:
|
||||
poroResults.append(poro)
|
||||
case = resInsight.project.case(id=0)
|
||||
|
||||
permxChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
|
||||
permxResults = []
|
||||
for permxChunk in permxChunks:
|
||||
for permx in permxChunk.values:
|
||||
permxResults.append(permx)
|
||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||
poroResults = []
|
||||
for poroChunk in poroChunks:
|
||||
for poro in poroChunk.values:
|
||||
poroResults.append(poro)
|
||||
|
||||
results = []
|
||||
for (poro, permx) in zip(poroResults, permxResults):
|
||||
results.append(poro * permx)
|
||||
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
||||
permxResults = []
|
||||
for permxChunk in permxChunks:
|
||||
for permx in permxChunk.values:
|
||||
permxResults.append(permx)
|
||||
|
||||
resInsight.properties.setActiveCellResults(results, 0, 'GENERATED', 'POROPERMXSY', 0)
|
||||
results = []
|
||||
for (poro, permx) in zip(poroResults, permxResults):
|
||||
results.append(poro * permx)
|
||||
|
||||
case.properties.setActiveCellProperty(results, 'GENERATED', 'POROPERMXSY', 0)
|
||||
|
||||
print("Transferred all results back")
|
||||
@@ -1,28 +0,0 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
poroChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
|
||||
poroResults = []
|
||||
for poroChunk in poroChunks:
|
||||
for poro in poroChunk.values:
|
||||
poroResults.append(poro)
|
||||
|
||||
permxChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
|
||||
permxResults = []
|
||||
for permxChunk in permxChunks:
|
||||
for permx in permxChunk.values:
|
||||
permxResults.append(permx)
|
||||
|
||||
results = []
|
||||
for (poro, permx) in zip(poroResults, permxResults):
|
||||
results.append(poro * permx)
|
||||
|
||||
print("Transferred " + str(len(results)) + " cell results")
|
||||
print("30th active cell: ")
|
||||
print(results[29])
|
||||
@@ -6,9 +6,12 @@ import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
if resInsight is not None:
|
||||
caseInfos = resInsight.projectInfo.selectedCases()
|
||||
cases = resInsight.project.selectedCases()
|
||||
|
||||
print ("Got " + str(len(cases)) + " cases: ")
|
||||
for case in cases:
|
||||
print(case.name)
|
||||
for property in case.properties.available('DYNAMIC_NATIVE'):
|
||||
print(property)
|
||||
|
||||
|
||||
print ("Got " + str(len(caseInfos)) + " cases: ")
|
||||
for caseInfo in caseInfos:
|
||||
print(caseInfo.name)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
|
||||
activeCellCount = resInsight.gridInfo.cellCount(caseId=0).active_cell_count
|
||||
|
||||
values = []
|
||||
for i in range(0, activeCellCount):
|
||||
values.append(i % 2 * 0.5);
|
||||
|
||||
|
||||
timeSteps = resInsight.gridInfo.timeSteps(caseId=0)
|
||||
for i in range(0, len(timeSteps.date)):
|
||||
print("Applying values to all time step " + str(i))
|
||||
resInsight.properties.setActiveCellResults(values, 0, 'DYNAMIC_NATIVE', 'SOIL', i)
|
||||
|
||||
@@ -5,12 +5,13 @@ import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
|
||||
totalCellCount = resInsight.gridInfo.cellCount(caseId=0).reservoir_cell_count
|
||||
case = resInsight.project.case(id=0)
|
||||
totalCellCount = case.cellCount().reservoir_cell_count
|
||||
|
||||
values = []
|
||||
for i in range(0, totalCellCount):
|
||||
values.append(i % 2 * 0.75);
|
||||
|
||||
print("Applying values to full grid")
|
||||
resInsight.properties.setGridResults(values, 0, 'DYNAMIC_NATIVE', 'SOIL', 0)
|
||||
case.properties.setGridProperty(values, 'DYNAMIC_NATIVE', 'SOIL', 0)
|
||||
|
||||
@@ -14,18 +14,18 @@ def createResult(soilChunks, porvChunks):
|
||||
|
||||
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
resInsight = ResInsight.Instance.find()
|
||||
case = resInsight.project.case(id=0)
|
||||
timeStepInfo = case.timeSteps()
|
||||
|
||||
timeStepInfo = resInsight.gridInfo.timeSteps(0)
|
||||
|
||||
porvChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORV', 0)
|
||||
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
||||
porvArray = []
|
||||
for porvChunk in porvChunks:
|
||||
porvArray.append(porvChunk)
|
||||
|
||||
for i in range (0, len(timeStepInfo.date)):
|
||||
soilChunks = resInsight.properties.activeCellResults(0, 'DYNAMIC_NATIVE', 'SOIL', i)
|
||||
for i in range (0, len(timeStepInfo.dates)):
|
||||
soilChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
||||
input_iterator = createResult(soilChunks, iter(porvArray))
|
||||
resInsight.properties.setActiveCellResultsAsync(input_iterator, 0, 'GENERATED', 'SOILPORVAsync', i)
|
||||
case.properties.setActiveCellPropertyAsync(input_iterator, 'GENERATED', 'SOILPORVAsync', i)
|
||||
|
||||
print("Transferred all results back")
|
||||
@@ -3,20 +3,19 @@ import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
resInsight = ResInsight.Instance.find()
|
||||
case = resInsight.case(id=0)
|
||||
|
||||
porvChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORV', 0)
|
||||
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
||||
porvResults = []
|
||||
for porvChunk in porvChunks:
|
||||
for porv in porvChunk.values:
|
||||
porvResults.append(porv)
|
||||
|
||||
timeStepInfo = resInsight.gridInfo.timeSteps(0)
|
||||
timeStepInfo = case.timeSteps()
|
||||
|
||||
for i in range (0, len(timeStepInfo.date)):
|
||||
soilChunks = resInsight.properties.activeCellResults(0, 'DYNAMIC_NATIVE', 'SOIL', i)
|
||||
for i in range (0, len(timeStepInfo.dates)):
|
||||
soilChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
||||
soilResults = []
|
||||
for soilChunk in soilChunks:
|
||||
for soil in soilChunk.values:
|
||||
@@ -25,5 +24,5 @@ for i in range (0, len(timeStepInfo.date)):
|
||||
for (soil, porv) in zip(soilResults, porvResults):
|
||||
results.append(soil * porv)
|
||||
|
||||
resInsight.properties.setActiveCellResults(results, 0, 'GENERATED', 'SOILPORVSync', i)
|
||||
case.properties.setActiveCellProperty(results, 'GENERATED', 'SOILPORVSync', i)
|
||||
print("Transferred all results back")
|
||||
@@ -0,0 +1,3 @@
|
||||
grpcio
|
||||
grpcio-tools
|
||||
protobuf
|
||||
@@ -0,0 +1,25 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
from Empty_pb2 import Empty
|
||||
|
||||
import AppInfo_pb2
|
||||
import AppInfo_pb2_grpc
|
||||
|
||||
class AppInfo:
|
||||
def __init__(self, channel):
|
||||
self.appInfo = AppInfo_pb2_grpc.AppInfoStub(channel)
|
||||
def versionMessage(self):
|
||||
return self.appInfo.GetVersion(Empty())
|
||||
def majorVersion(self):
|
||||
return self.versionMessage().major_version
|
||||
def minorVersion(self):
|
||||
return self.versionMessage().minor_version
|
||||
def patchVersion(self):
|
||||
return self.versionMessage().patch_version
|
||||
def versionString(self):
|
||||
return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion())
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
from .Grid import Grid
|
||||
from .Properties import Properties
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
import Case_pb2
|
||||
import Case_pb2_grpc
|
||||
|
||||
class Case:
|
||||
def __init__(self, channel, id):
|
||||
self.channel = channel
|
||||
self.stub = Case_pb2_grpc.CaseStub(channel)
|
||||
self.id = id
|
||||
info = self.stub.GetCaseInfo(Case_pb2.CaseRequest(id=self.id))
|
||||
self.name = info.name
|
||||
self.groupId = info.group_id
|
||||
self.type = info.type
|
||||
self.properties = Properties(self)
|
||||
self.request = Case_pb2.CaseRequest(id=self.id)
|
||||
|
||||
def gridCount(self):
|
||||
try:
|
||||
return self.stub.GetGridCount(self.request).count
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
return 0
|
||||
print("ERROR: ", e)
|
||||
return 0
|
||||
|
||||
def grid(self, index):
|
||||
return Grid(index, self)
|
||||
|
||||
def grids(self):
|
||||
gridList = []
|
||||
for i in range(0, self.gridCount()):
|
||||
gridList.append(Grid(i, self))
|
||||
return gridList
|
||||
|
||||
def cellCount(self, porosityModel='MATRIX_MODEL'):
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Case_pb2.CellInfoRequest(request_case=self.request,
|
||||
porosity_model=porosityModel)
|
||||
return self.stub.GetCellCount(request)
|
||||
|
||||
def cellInfoForActiveCells(self, porosityModel='MATRIX_MODEL'):
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Case_pb2.CellInfoRequest(request_case=self.request,
|
||||
porosity_model=porosityModel)
|
||||
return self.stub.GetCellInfoForActiveCells(request)
|
||||
|
||||
def timeSteps(self):
|
||||
return self.stub.GetTimeSteps(self.request)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
|
||||
import Commands_pb2 as Cmd
|
||||
import Commands_pb2_grpc as CmdRpc
|
||||
|
||||
class Commands:
|
||||
def __init__(self, channel):
|
||||
self.commands = CmdRpc.CommandsStub(channel)
|
||||
|
||||
def execute(self, commandParams):
|
||||
try:
|
||||
return self.commands.Execute(commandParams)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error")
|
||||
|
||||
def setTimeStep(self, caseId, timeStep):
|
||||
return self.execute(Cmd.CommandParams(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep)))
|
||||
|
||||
def setMainWindowSize(self, width, height):
|
||||
return self.execute(Cmd.CommandParams(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)))
|
||||
|
||||
def openProject(self, path):
|
||||
return self.execute(Cmd.CommandParams(openProject=Cmd.FilePathRequest(path=path)))
|
||||
|
||||
def loadCase(self, path):
|
||||
commandReply = self.execute(Cmd.CommandParams(loadCase=Cmd.FilePathRequest(path=path)))
|
||||
assert commandReply.HasField("loadCaseResult")
|
||||
return commandReply.loadCaseResult.id
|
||||
|
||||
def closeProject(self):
|
||||
return self.execute(Cmd.CommandParams(closeProject=Empty()))
|
||||
|
||||
def exportWellPaths(self, wellPaths=[], mdStepSize=5.0):
|
||||
if isinstance(wellPaths, str):
|
||||
wellPathArray = [str]
|
||||
elif isinstance(wellPaths, list):
|
||||
wellPathArray = wellPaths
|
||||
return self.execute(Cmd.CommandParams(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize)))
|
||||
@@ -0,0 +1,18 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
import Grid_pb2
|
||||
import Grid_pb2_grpc
|
||||
|
||||
class Grid:
|
||||
def __init__(self, index, case):
|
||||
self.case = case
|
||||
self.index = index
|
||||
self.stub = Grid_pb2_grpc.GridStub(self.case.channel)
|
||||
|
||||
def dimensions(self):
|
||||
return self.stub.GetDimensions(Grid_pb2.GridRequest(case_request = self.case.request, grid_index = self.index)).dimensions
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
import logging
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
import RiaVersionInfo
|
||||
|
||||
from .AppInfo import AppInfo
|
||||
from .Commands import Commands
|
||||
from .Project import Project
|
||||
|
||||
class Instance:
|
||||
@staticmethod
|
||||
def is_port_in_use(port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.settimeout(0.2)
|
||||
return s.connect_ex(('localhost', port)) == 0
|
||||
|
||||
@staticmethod
|
||||
def launch():
|
||||
port = 50051
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
port = int(portEnv)
|
||||
|
||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
||||
if resInsightExecutable is None:
|
||||
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
|
||||
return None
|
||||
|
||||
while Instance.is_port_in_use(port):
|
||||
port += 1
|
||||
|
||||
print('Port ' + str(port))
|
||||
print('Trying to launch', resInsightExecutable)
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
|
||||
print(pid)
|
||||
return Instance(port)
|
||||
|
||||
@staticmethod
|
||||
def find(startPort = 50051, endPort = 50071):
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
startPort = int(portEnv)
|
||||
endPort = startPort + 20
|
||||
|
||||
for tryPort in range(startPort, endPort):
|
||||
if Instance.is_port_in_use(tryPort):
|
||||
return Instance(tryPort)
|
||||
|
||||
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
|
||||
return None
|
||||
|
||||
def __init__(self, port = 50051):
|
||||
logging.basicConfig()
|
||||
location = "localhost:" + str(port)
|
||||
self.channel = grpc.insecure_channel(location)
|
||||
|
||||
# Main version check package
|
||||
self.appInfo = AppInfo(self.channel)
|
||||
try:
|
||||
majorVersionOk = self.appInfo.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
|
||||
minorVersionOk = self.appInfo.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
|
||||
if not (majorVersionOk and minorVersionOk):
|
||||
raise Exception('Version of ResInsight does not match version of Python API')
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.UNAVAILABLE:
|
||||
print('Info: Could not find any instances at port ' + str(port))
|
||||
except Exception as e:
|
||||
print('Error:', e)
|
||||
|
||||
# Service packages
|
||||
self.commands = Commands(self.channel)
|
||||
self.project = Project(self.channel)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
|
||||
from .Case import Case
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
from Empty_pb2 import Empty
|
||||
import Project_pb2
|
||||
import Project_pb2_grpc
|
||||
|
||||
class Project:
|
||||
def __init__(self, channel):
|
||||
self.channel = channel
|
||||
self.project = Project_pb2_grpc.ProjectStub(channel)
|
||||
|
||||
def selectedCases(self):
|
||||
caseInfos = self.project.GetSelectedCases(Empty())
|
||||
cases = []
|
||||
for caseInfo in caseInfos.data:
|
||||
cases.append(Case(self.channel, caseInfo.id))
|
||||
return cases
|
||||
|
||||
def cases(self):
|
||||
try:
|
||||
caseInfos = self.project.GetAllCases(Empty())
|
||||
|
||||
cases = []
|
||||
for caseInfo in caseInfos.data:
|
||||
cases.append(Case(self.channel, caseInfo.id))
|
||||
return cases
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
return []
|
||||
else:
|
||||
print("ERROR: ", e)
|
||||
return []
|
||||
|
||||
def case(self, id):
|
||||
try:
|
||||
case = Case(self.channel, id)
|
||||
return case
|
||||
except grpc.RpcError as e:
|
||||
return None
|
||||
@@ -0,0 +1,130 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
import Properties_pb2
|
||||
import Properties_pb2_grpc
|
||||
import Case_pb2
|
||||
import Case_pb2_grpc
|
||||
|
||||
class Properties:
|
||||
def __init__(self, case):
|
||||
self.case = case
|
||||
self.propertiesStub = Properties_pb2_grpc.PropertiesStub(self.case.channel)
|
||||
|
||||
def generatePropertyInputIterator(self, values_iterator, parameters):
|
||||
chunk = Properties_pb2.PropertyInputChunk()
|
||||
chunk.params.CopyFrom(parameters)
|
||||
yield chunk
|
||||
|
||||
for values in values_iterator:
|
||||
valmsg = Properties_pb2.PropertyChunk(values = values)
|
||||
chunk.values.CopyFrom(valmsg)
|
||||
yield chunk
|
||||
|
||||
def generatePropertyInputChunks(self, array, parameters):
|
||||
# Each double is 8 bytes. A good chunk size is 64KiB = 65536B
|
||||
# Meaning ideal number of doubles would be 8192.
|
||||
# However we need overhead space, so if we choose 8160 in chunk size
|
||||
# We have 256B left for overhead which should be plenty
|
||||
chunkSize = 8000
|
||||
index = -1
|
||||
while index < len(array):
|
||||
chunk = Properties_pb2.PropertyInputChunk()
|
||||
if index is -1:
|
||||
chunk.params.CopyFrom(parameters)
|
||||
index += 1;
|
||||
else:
|
||||
actualChunkSize = min(len(array) - index + 1, chunkSize)
|
||||
chunk.values.CopyFrom(Properties_pb2.PropertyChunk(values = array[index:index+actualChunkSize]))
|
||||
index += actualChunkSize
|
||||
|
||||
yield chunk
|
||||
# Final empty message to signal completion
|
||||
chunk = Properties_pb2.PropertyInputChunk()
|
||||
yield chunk
|
||||
|
||||
def available(self, propertyType, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.AvailablePropertiesRequest (case_request = Case_pb2.CaseRequest(id=self.case.id),
|
||||
property_type = propertyTypeEnum,
|
||||
porosity_model = porosityModelEnum)
|
||||
return self.propertiesStub.GetAvailableProperties(request).property_names
|
||||
|
||||
def activeCellProperty(self, propertyType, propertyName, timeStep, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.PropertyRequest(case_request = Case_pb2.CaseRequest(id=self.case.id),
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
porosity_model = porosityModelEnum)
|
||||
for chunk in self.propertiesStub.GetActiveCellProperty(request):
|
||||
yield chunk
|
||||
|
||||
def gridProperty(self, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.PropertyRequest(case_request = self.case.request,
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
return self.propertiesStub.GetGridProperty(request)
|
||||
|
||||
def setActiveCellPropertyAsync(self, values_iterator, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.PropertyRequest(case_request = self.case.request,
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
try:
|
||||
reply_iterator = self.generatePropertyInputIterator(values_iterator, request)
|
||||
self.propertiesStub.SetActiveCellProperty(reply_iterator)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
|
||||
def setActiveCellProperty(self, values, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.PropertyRequest(case_request = self.case.request,
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
try:
|
||||
request_iterator = self.generatePropertyInputChunks(values, request)
|
||||
self.propertiesStub.SetActiveCellProperty(request_iterator)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
def setGridProperty(self, values, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Properties_pb2.PropertyRequest(case_request = self.case.request,
|
||||
property_type = propertyTypeEnum,
|
||||
property_name = propertyName,
|
||||
time_step = timeStep,
|
||||
grid_index = gridIndex,
|
||||
porosity_model = porosityModelEnum)
|
||||
try:
|
||||
request_iterator = self.generatePropertyInputChunks(values, request)
|
||||
self.propertiesStub.SetGridProperty(request_iterator)
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
@@ -0,0 +1,78 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
import logging
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
import RiaVersionInfo
|
||||
|
||||
from AppInfo import AppInfo
|
||||
from Commands import Commands
|
||||
from Project import Project
|
||||
|
||||
class Instance:
|
||||
@staticmethod
|
||||
def is_port_in_use(port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.settimeout(0.2)
|
||||
return s.connect_ex(('localhost', port)) == 0
|
||||
|
||||
@staticmethod
|
||||
def launch():
|
||||
port = 50051
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
port = int(portEnv)
|
||||
|
||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
||||
if resInsightExecutable is None:
|
||||
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
|
||||
return None
|
||||
|
||||
while Instance.is_port_in_use(port):
|
||||
port += 1
|
||||
|
||||
print('Port ' + str(port))
|
||||
print('Trying to launch', resInsightExecutable)
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
|
||||
print(pid)
|
||||
return Instance(port)
|
||||
|
||||
@staticmethod
|
||||
def find(startPort = 50051, endPort = 50071):
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
startPort = int(portEnv)
|
||||
endPort = startPort + 20
|
||||
|
||||
for tryPort in range(startPort, endPort):
|
||||
if Instance.is_port_in_use(tryPort):
|
||||
return Instance(tryPort)
|
||||
|
||||
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
|
||||
return None
|
||||
|
||||
def __init__(self, port = 50051):
|
||||
logging.basicConfig()
|
||||
location = "localhost:" + str(port)
|
||||
self.channel = grpc.insecure_channel(location)
|
||||
|
||||
# Main version check package
|
||||
self.appInfo = AppInfo(self.channel)
|
||||
try:
|
||||
majorVersionOk = self.appInfo.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
|
||||
minorVersionOk = self.appInfo.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
|
||||
if not (majorVersionOk and minorVersionOk):
|
||||
raise Exception('Version of ResInsight does not match version of Python API')
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.UNAVAILABLE:
|
||||
print('Info: Could not find any instances at port ' + str(port))
|
||||
except Exception as e:
|
||||
print('Error:', e)
|
||||
|
||||
# Service packages
|
||||
self.commands = Commands(self.channel)
|
||||
self.project = Project(self.channel)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
name = "rips"
|
||||
from .Case import Case
|
||||
from .Grid import Grid
|
||||
from .Properties import Properties
|
||||
from .Instance import Instance
|
||||
@@ -0,0 +1,21 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
with open('README.md') as f:
|
||||
readme = f.read()
|
||||
|
||||
with open('LICENSE') as f:
|
||||
license = f.read()
|
||||
|
||||
RIPS_DIST_VERSION = '1'
|
||||
|
||||
setup(
|
||||
name='rips',
|
||||
version='@RESINSIGHT_MAJOR_VERSION@.@RESINSIGHT_MINOR_VERSION@.@RESINSIGHT_PATCH_VERSION@.' + RIPS_DIST_VERSION,
|
||||
description='Python Interface for ResInsight',
|
||||
long_description=readme,
|
||||
author='Ceetron Solutions',
|
||||
author_email='info@ceetronsolutions.com',
|
||||
url='http://www.resinsight.org',
|
||||
license=license,
|
||||
packages=find_packages(exclude=('tests', 'docs', '__pycache', 'examples'))
|
||||
)
|
||||
+6
-6
@@ -15,7 +15,7 @@
|
||||
// for more details.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiaGrpcResInfoService.h"
|
||||
#include "RiaGrpcAppInfoService.h"
|
||||
|
||||
#include "RiaVersionInfo.h"
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
@@ -23,7 +23,7 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcResInfoService::GetVersion(grpc::ServerContext* context, const rips::Empty* request, rips::Version* reply)
|
||||
grpc::Status RiaGrpcAppInfoService::GetVersion(grpc::ServerContext* context, const rips::Empty* request, rips::Version* reply)
|
||||
{
|
||||
reply->set_major_version(RESINSIGHT_MAJOR_VERSION);
|
||||
reply->set_minor_version(RESINSIGHT_MINOR_VERSION);
|
||||
@@ -34,11 +34,11 @@ grpc::Status RiaGrpcResInfoService::GetVersion(grpc::ServerContext* context, con
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcResInfoService::createCallbacks()
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcAppInfoService::createCallbacks()
|
||||
{
|
||||
typedef RiaGrpcResInfoService Self;
|
||||
typedef RiaGrpcAppInfoService Self;
|
||||
return { new RiaGrpcUnaryCallback<Self, rips::Empty, rips::Version>(this, &Self::GetVersion, &Self::RequestGetVersion) };
|
||||
}
|
||||
|
||||
static bool RiaGrpcResInfoService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcResInfoService>(typeid(RiaGrpcResInfoService).hash_code());
|
||||
static bool RiaGrpcAppInfoService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcAppInfoService>(typeid(RiaGrpcAppInfoService).hash_code());
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "RiaGrpcServiceInterface.h"
|
||||
|
||||
#include "ResInfo.grpc.pb.h"
|
||||
#include "AppInfo.grpc.pb.h"
|
||||
|
||||
#include <grpcpp/grpcpp.h>
|
||||
#include <vector>
|
||||
@@ -39,7 +39,7 @@ class PdmValueField;
|
||||
|
||||
class RiaGrpcCallbackInterface;
|
||||
|
||||
class RiaGrpcResInfoService : public rips::ResInfo::AsyncService, public RiaGrpcServiceInterface
|
||||
class RiaGrpcAppInfoService : public rips::AppInfo::AsyncService, public RiaGrpcServiceInterface
|
||||
{
|
||||
public:
|
||||
grpc::Status GetVersion(grpc::ServerContext* context, const rips::Empty* request, rips::Version* reply) override;
|
||||
+40
-42
@@ -15,8 +15,9 @@
|
||||
// for more details.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiaGrpcGridInfoService.h"
|
||||
#include "RiaGrpcCaseService.h"
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
#include "RiaSocketTools.h"
|
||||
|
||||
#include "RigActiveCellInfo.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
@@ -49,7 +50,7 @@ grpc::Status RiaActiveCellInfoStateHandler::init(const rips::CellInfoRequest* re
|
||||
m_request = request;
|
||||
|
||||
m_porosityModel = RiaDefines::PorosityModelType(m_request->porosity_model());
|
||||
RimCase* rimCase = RiaGrpcServiceInterface::findCase(m_request->case_id());
|
||||
RimCase* rimCase = RiaGrpcServiceInterface::findCase(m_request->case_request().id());
|
||||
m_eclipseCase = dynamic_cast<RimEclipseCase*>(rimCase);
|
||||
|
||||
if (!m_eclipseCase)
|
||||
@@ -213,7 +214,7 @@ grpc::Status RiaActiveCellInfoStateHandler::assignReply(rips::CellInfoArray* rep
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcGridInfoService::GetGridCount(grpc::ServerContext* context, const rips::Case* request, rips::GridCount* reply)
|
||||
grpc::Status RiaGrpcCaseService::GetGridCount(grpc::ServerContext* context, const rips::CaseRequest* request, rips::GridCount* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->id());
|
||||
|
||||
@@ -230,36 +231,9 @@ grpc::Status RiaGrpcGridInfoService::GetGridCount(grpc::ServerContext* context,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcGridInfoService::GetGridDimensions(grpc::ServerContext* context,
|
||||
const rips::Case* request,
|
||||
rips::GridDimensions* reply)
|
||||
grpc::Status RiaGrpcCaseService::GetCellCount(grpc::ServerContext* context, const rips::CellInfoRequest* request, rips::CellCount* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->id());
|
||||
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(rimCase);
|
||||
if (eclipseCase)
|
||||
{
|
||||
size_t gridCount = eclipseCase->mainGrid()->gridCount();
|
||||
for (size_t i = 0; i < gridCount; ++i)
|
||||
{
|
||||
const RigGridBase* grid = eclipseCase->mainGrid()->gridByIndex(i);
|
||||
rips::Vec3i* dimensions = reply->add_dimensions();
|
||||
dimensions->set_i((int)grid->cellCountI());
|
||||
dimensions->set_j((int)grid->cellCountJ());
|
||||
dimensions->set_k((int)grid->cellCountK());
|
||||
}
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
return grpc::Status(grpc::NOT_FOUND, "Eclipse Case not found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcGridInfoService::GetCellCount(grpc::ServerContext* context, const rips::CellInfoRequest* request, rips::CellCount* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->case_id());
|
||||
RimCase* rimCase = findCase(request->case_request().id());
|
||||
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(rimCase);
|
||||
if (eclipseCase)
|
||||
@@ -278,7 +252,7 @@ grpc::Status RiaGrpcGridInfoService::GetCellCount(grpc::ServerContext* context,
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status
|
||||
RiaGrpcGridInfoService::GetTimeSteps(grpc::ServerContext* context, const rips::Case* request, rips::TimeStepDates* reply)
|
||||
RiaGrpcCaseService::GetTimeSteps(grpc::ServerContext* context, const rips::CaseRequest* request, rips::TimeStepDates* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->id());
|
||||
|
||||
@@ -288,7 +262,7 @@ RiaGrpcGridInfoService::GetTimeSteps(grpc::ServerContext* context, const rips::C
|
||||
std::vector<QDateTime> timeStepDates = eclipseCase->timeStepDates();
|
||||
for (QDateTime dateTime : timeStepDates)
|
||||
{
|
||||
rips::TimeStepDate* date = reply->add_date();
|
||||
rips::TimeStepDate* date = reply->add_dates();
|
||||
date->set_year(dateTime.date().year());
|
||||
date->set_month(dateTime.date().month());
|
||||
date->set_day(dateTime.date().day());
|
||||
@@ -301,10 +275,34 @@ RiaGrpcGridInfoService::GetTimeSteps(grpc::ServerContext* context, const rips::C
|
||||
return grpc::Status(grpc::NOT_FOUND, "Eclipse Case not found");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcGridInfoService::GetCellInfoForActiveCells(grpc::ServerContext* context,
|
||||
grpc::Status
|
||||
RiaGrpcCaseService::GetCaseInfo(grpc::ServerContext* context, const rips::CaseRequest* request, rips::CaseInfo* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->id());
|
||||
if (rimCase)
|
||||
{
|
||||
qint64 caseId = rimCase->caseId();
|
||||
qint64 caseGroupId = -1;
|
||||
QString caseName, caseType;
|
||||
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||
|
||||
reply->set_id(caseId);
|
||||
reply->set_group_id(caseGroupId);
|
||||
reply->set_name(caseName.toStdString());
|
||||
reply->set_type(caseType.toStdString());
|
||||
return Status::OK;
|
||||
}
|
||||
return Status(grpc::NOT_FOUND, "No cases found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcCaseService::GetCellInfoForActiveCells(grpc::ServerContext* context,
|
||||
const rips::CellInfoRequest* request,
|
||||
rips::CellInfoArray* reply,
|
||||
RiaActiveCellInfoStateHandler* stateHandler)
|
||||
@@ -315,17 +313,17 @@ grpc::Status RiaGrpcGridInfoService::GetCellInfoForActiveCells(grpc::ServerConte
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcGridInfoService::createCallbacks()
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcCaseService::createCallbacks()
|
||||
{
|
||||
typedef RiaGrpcGridInfoService Self;
|
||||
typedef RiaGrpcCaseService Self;
|
||||
|
||||
return {new RiaGrpcUnaryCallback<Self, Case, GridCount>(this, &Self::GetGridCount, &Self::RequestGetGridCount),
|
||||
new RiaGrpcUnaryCallback<Self, Case, GridDimensions>(this, &Self::GetGridDimensions, &Self::RequestGetGridDimensions),
|
||||
return {new RiaGrpcUnaryCallback<Self, CaseRequest, GridCount>(this, &Self::GetGridCount, &Self::RequestGetGridCount),
|
||||
new RiaGrpcUnaryCallback<Self, CellInfoRequest, CellCount>(this, &Self::GetCellCount, &Self::RequestGetCellCount),
|
||||
new RiaGrpcUnaryCallback<Self, Case, TimeStepDates>(this, &Self::GetTimeSteps, &Self::RequestGetTimeSteps),
|
||||
new RiaGrpcUnaryCallback<Self, CaseRequest, TimeStepDates>(this, &Self::GetTimeSteps, &Self::RequestGetTimeSteps),
|
||||
new RiaGrpcUnaryCallback<Self, CaseRequest, CaseInfo>(this, &Self::GetCaseInfo, &Self::RequestGetCaseInfo),
|
||||
new RiaGrpcServerStreamCallback<Self, CellInfoRequest, CellInfoArray, RiaActiveCellInfoStateHandler>(
|
||||
this, &Self::GetCellInfoForActiveCells, &Self::RequestGetCellInfoForActiveCells, new RiaActiveCellInfoStateHandler)};
|
||||
}
|
||||
|
||||
static bool RiaGrpcGridInfoService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcGridInfoService>(typeid(RiaGrpcGridInfoService).hash_code());
|
||||
static bool RiaGrpcCaseService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcCaseService>(typeid(RiaGrpcCaseService).hash_code());
|
||||
+6
-6
@@ -17,7 +17,7 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "GridInfo.grpc.pb.h"
|
||||
#include "Case.grpc.pb.h"
|
||||
|
||||
#include "RiaGrpcServiceInterface.h"
|
||||
#include "RiaPorosityModel.h"
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
namespace rips
|
||||
{
|
||||
class Case;
|
||||
class CaseRequest;
|
||||
}
|
||||
|
||||
class RiaGrpcCallbackInterface;
|
||||
@@ -66,13 +66,13 @@ protected:
|
||||
// gRPC-service answering requests about grid information for a given case
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaGrpcGridInfoService final : public rips::GridInfo::AsyncService, public RiaGrpcServiceInterface
|
||||
class RiaGrpcCaseService final : public rips::Case::AsyncService, public RiaGrpcServiceInterface
|
||||
{
|
||||
public:
|
||||
grpc::Status GetGridCount(grpc::ServerContext* context, const rips::Case* request, rips::GridCount* reply) override;
|
||||
grpc::Status GetGridDimensions(grpc::ServerContext* context, const rips::Case* request, rips::GridDimensions* reply) override;
|
||||
grpc::Status GetGridCount(grpc::ServerContext* context, const rips::CaseRequest* request, rips::GridCount* reply) override;
|
||||
grpc::Status GetCellCount(grpc::ServerContext* context, const rips::CellInfoRequest* request, rips::CellCount* reply) override;
|
||||
grpc::Status GetTimeSteps(grpc::ServerContext* context, const rips::Case* request, rips::TimeStepDates* reply) override;
|
||||
grpc::Status GetTimeSteps(grpc::ServerContext* context, const rips::CaseRequest* request, rips::TimeStepDates* reply) override;
|
||||
grpc::Status GetCaseInfo(grpc::ServerContext* context, const rips::CaseRequest* request, rips::CaseInfo* reply) override;
|
||||
|
||||
grpc::Status GetCellInfoForActiveCells(grpc::ServerContext* context,
|
||||
const rips::CellInfoRequest* request,
|
||||
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RiaGrpcGridService.h"
|
||||
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
|
||||
#include "RigEclipseCaseData.h"
|
||||
#include "RigMainGrid.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
|
||||
using namespace rips;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcGridService::GetDimensions(grpc::ServerContext* context,
|
||||
const GridRequest* request,
|
||||
GridDimensions* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->case_request().id());
|
||||
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(rimCase);
|
||||
if (eclipseCase)
|
||||
{
|
||||
size_t gridIndex = (size_t) request->grid_index();
|
||||
if (gridIndex < eclipseCase->mainGrid()->gridCount())
|
||||
{
|
||||
const RigGridBase* grid = eclipseCase->mainGrid()->gridByIndex(gridIndex);
|
||||
Vec3i* dimensions = new Vec3i;
|
||||
dimensions->set_i((int)grid->cellCountI());
|
||||
dimensions->set_j((int)grid->cellCountJ());
|
||||
dimensions->set_k((int)grid->cellCountK());
|
||||
|
||||
reply->set_allocated_dimensions(dimensions);
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
return grpc::Status(grpc::NOT_FOUND, "Grid not found");
|
||||
}
|
||||
|
||||
return grpc::Status(grpc::NOT_FOUND, "Eclipse Case not found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcGridService::createCallbacks()
|
||||
{
|
||||
typedef RiaGrpcGridService Self;
|
||||
|
||||
return {
|
||||
new RiaGrpcUnaryCallback<Self, GridRequest, GridDimensions>(
|
||||
this, &Self::GetDimensions, &Self::RequestGetDimensions)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
static bool RiaGrpcGridService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcGridService>(typeid(RiaGrpcGridService).hash_code());
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "Grid.grpc.pb.h"
|
||||
|
||||
#include "RiaGrpcServiceInterface.h"
|
||||
|
||||
class RiaGrpcGridService final : public rips::Grid::AsyncService, public RiaGrpcServiceInterface
|
||||
{
|
||||
public:
|
||||
grpc::Status GetDimensions(grpc::ServerContext* context, const rips::GridRequest* request, rips::GridDimensions* reply) override;
|
||||
|
||||
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
|
||||
};
|
||||
+20
-71
@@ -1,4 +1,4 @@
|
||||
#include "RiaGrpcProjectInfoService.h"
|
||||
#include "RiaGrpcProjectService.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include "CaseInfo.grpc.pb.h"
|
||||
#include "Case.grpc.pb.h"
|
||||
|
||||
using grpc::ServerCompletionQueue;
|
||||
using grpc::ServerContext;
|
||||
@@ -27,7 +27,7 @@ using namespace rips;
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status RiaGrpcProjectInfoService::CurrentCase(ServerContext* context, const rips::Empty* request, rips::Case* reply)
|
||||
Status RiaGrpcProjectService::GetCurrentCase(ServerContext* context, const rips::Empty* request, rips::CaseRequest* reply)
|
||||
{
|
||||
RimGridView* view = RiaApplication::instance()->activeGridView();
|
||||
if (view)
|
||||
@@ -45,56 +45,7 @@ Status RiaGrpcProjectInfoService::CurrentCase(ServerContext* context, const rips
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status RiaGrpcProjectInfoService::CurrentCaseInfo(ServerContext* context, const rips::Empty* request, rips::CaseInfo* reply)
|
||||
{
|
||||
RimGridView* view = RiaApplication::instance()->activeGridView();
|
||||
if (view)
|
||||
{
|
||||
RimCase* currentCase = view->ownerCase();
|
||||
if (currentCase)
|
||||
{
|
||||
qint64 caseId = currentCase->caseId();
|
||||
qint64 caseGroupId = -1;
|
||||
QString caseName, caseType;
|
||||
RiaSocketTools::getCaseInfoFromCase(currentCase, caseId, caseName, caseType, caseGroupId);
|
||||
|
||||
reply->set_id(caseId);
|
||||
reply->set_group_id(caseGroupId);
|
||||
reply->set_name(caseName.toStdString());
|
||||
reply->set_type(caseType.toStdString());
|
||||
return Status::OK;
|
||||
}
|
||||
}
|
||||
return Status(grpc::NOT_FOUND, "No current case found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status
|
||||
RiaGrpcProjectInfoService::CaseInfoFromCase(grpc::ServerContext* context, const rips::Case* request, rips::CaseInfo* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->id());
|
||||
if (rimCase)
|
||||
{
|
||||
qint64 caseId = rimCase->caseId();
|
||||
qint64 caseGroupId = -1;
|
||||
QString caseName, caseType;
|
||||
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||
|
||||
reply->set_id(caseId);
|
||||
reply->set_group_id(caseGroupId);
|
||||
reply->set_name(caseName.toStdString());
|
||||
reply->set_type(caseType.toStdString());
|
||||
return Status::OK;
|
||||
}
|
||||
return Status(grpc::NOT_FOUND, "No cases found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status RiaGrpcProjectInfoService::SelectedCases(ServerContext* context, const rips::Empty* request, rips::CaseInfos* reply)
|
||||
Status RiaGrpcProjectService::GetSelectedCases(ServerContext* context, const rips::Empty* request, rips::CaseInfoArray* reply)
|
||||
{
|
||||
std::vector<RimCase*> cases;
|
||||
caf::SelectionManager::instance()->objectsByType(&cases);
|
||||
@@ -111,7 +62,7 @@ Status RiaGrpcProjectInfoService::SelectedCases(ServerContext* context, const ri
|
||||
QString caseName, caseType;
|
||||
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||
|
||||
rips::CaseInfo* caseInfo = reply->add_case_info();
|
||||
rips::CaseInfo* caseInfo = reply->add_data();
|
||||
caseInfo->set_id(caseId);
|
||||
caseInfo->set_group_id(caseGroupId);
|
||||
caseInfo->set_name(caseName.toStdString());
|
||||
@@ -124,7 +75,7 @@ Status RiaGrpcProjectInfoService::SelectedCases(ServerContext* context, const ri
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status
|
||||
RiaGrpcProjectInfoService::AllCaseGroups(grpc::ServerContext* context, const rips::Empty* request, rips::CaseGroups* reply)
|
||||
RiaGrpcProjectService::GetAllCaseGroups(grpc::ServerContext* context, const rips::Empty* request, rips::CaseGroups* reply)
|
||||
{
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
RimEclipseCaseCollection* analysisModels =
|
||||
@@ -133,7 +84,7 @@ grpc::Status
|
||||
{
|
||||
for (RimIdenticalGridCaseGroup* cg : analysisModels->caseGroups())
|
||||
{
|
||||
rips::CaseGroup* caseGroup = reply->add_case_group();
|
||||
rips::CaseGroup* caseGroup = reply->add_case_groups();
|
||||
caseGroup->set_id(cg->groupId());
|
||||
caseGroup->set_name(cg->name().toStdString());
|
||||
}
|
||||
@@ -145,7 +96,7 @@ grpc::Status
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcProjectInfoService::AllCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfos* reply)
|
||||
grpc::Status RiaGrpcProjectService::GetAllCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfoArray* reply)
|
||||
{
|
||||
std::vector<RimCase*> cases;
|
||||
RiaApplication::instance()->project()->allCases(cases);
|
||||
@@ -162,7 +113,7 @@ grpc::Status RiaGrpcProjectInfoService::AllCases(grpc::ServerContext* context, c
|
||||
QString caseName, caseType;
|
||||
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||
|
||||
rips::CaseInfo* caseInfo = reply->add_case_info();
|
||||
rips::CaseInfo* caseInfo = reply->add_data();
|
||||
caseInfo->set_id(caseId);
|
||||
caseInfo->set_group_id(caseGroupId);
|
||||
caseInfo->set_name(caseName.toStdString());
|
||||
@@ -175,7 +126,7 @@ grpc::Status RiaGrpcProjectInfoService::AllCases(grpc::ServerContext* context, c
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status
|
||||
RiaGrpcProjectInfoService::CasesInGroup(grpc::ServerContext* context, const rips::CaseGroup* request, rips::CaseInfos* reply)
|
||||
RiaGrpcProjectService::GetCasesInGroup(grpc::ServerContext* context, const rips::CaseGroup* request, rips::CaseInfoArray* reply)
|
||||
{
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
RimEclipseCaseCollection* analysisModels =
|
||||
@@ -217,7 +168,7 @@ grpc::Status
|
||||
QString caseName, caseType;
|
||||
RiaSocketTools::getCaseInfoFromCase(rimCase, caseId, caseName, caseType, caseGroupId);
|
||||
|
||||
rips::CaseInfo* caseInfo = reply->add_case_info();
|
||||
rips::CaseInfo* caseInfo = reply->add_data();
|
||||
caseInfo->set_id(caseId);
|
||||
caseInfo->set_group_id(caseGroupId);
|
||||
caseInfo->set_name(caseName.toStdString());
|
||||
@@ -231,19 +182,17 @@ grpc::Status
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcProjectInfoService::createCallbacks()
|
||||
std::vector<RiaGrpcCallbackInterface*> RiaGrpcProjectService::createCallbacks()
|
||||
{
|
||||
typedef RiaGrpcProjectInfoService Self;
|
||||
typedef RiaGrpcProjectService Self;
|
||||
|
||||
return {
|
||||
new RiaGrpcUnaryCallback<Self, Empty, Case>(this, &Self::CurrentCase, &Self::RequestCurrentCase),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseInfo>(this, &Self::CurrentCaseInfo, &Self::RequestCurrentCaseInfo),
|
||||
new RiaGrpcUnaryCallback<Self, Case, CaseInfo>(this, &Self::CaseInfoFromCase, &Self::RequestCaseInfoFromCase),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseInfos>(this, &Self::SelectedCases, &Self::RequestSelectedCases),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseGroups>(this, &Self::AllCaseGroups, &Self::RequestAllCaseGroups),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseInfos>(this, &Self::AllCases, &Self::RequestAllCases),
|
||||
new RiaGrpcUnaryCallback<Self, CaseGroup, CaseInfos>(this, &Self::CasesInGroup, &Self::RequestCasesInGroup)};
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseRequest>(this, &Self::GetCurrentCase, &Self::RequestGetCurrentCase),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseInfoArray>(this, &Self::GetSelectedCases, &Self::RequestGetSelectedCases),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseGroups>(this, &Self::GetAllCaseGroups, &Self::RequestGetAllCaseGroups),
|
||||
new RiaGrpcUnaryCallback<Self, Empty, CaseInfoArray>(this, &Self::GetAllCases, &Self::RequestGetAllCases),
|
||||
new RiaGrpcUnaryCallback<Self, CaseGroup, CaseInfoArray>(this, &Self::GetCasesInGroup, &Self::RequestGetCasesInGroup)};
|
||||
}
|
||||
|
||||
static bool RiaGrpcProjectInfoService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcProjectInfoService>(typeid(RiaGrpcProjectInfoService).hash_code());
|
||||
static bool RiaGrpcProjectService_init =
|
||||
RiaGrpcServiceFactory::instance()->registerCreator<RiaGrpcProjectService>(typeid(RiaGrpcProjectService).hash_code());
|
||||
+8
-10
@@ -17,7 +17,7 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "ProjectInfo.grpc.pb.h"
|
||||
#include "Project.grpc.pb.h"
|
||||
#include "RiaGrpcServiceInterface.h"
|
||||
|
||||
#include <grpcpp/grpcpp.h>
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace rips
|
||||
{
|
||||
class Empty;
|
||||
class CaseInfo;
|
||||
class CaseRequest;
|
||||
} // namespace rips
|
||||
|
||||
class RiaGrpcCallbackInterface;
|
||||
@@ -35,16 +35,14 @@ class RiaGrpcCallbackInterface;
|
||||
// gRPC-service answering requests about project information
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaGrpcProjectInfoService final : public rips::ProjectInfo::AsyncService, public RiaGrpcServiceInterface
|
||||
class RiaGrpcProjectService final : public rips::Project::AsyncService, public RiaGrpcServiceInterface
|
||||
{
|
||||
public:
|
||||
grpc::Status CurrentCase(grpc::ServerContext* context, const rips::Empty* request, rips::Case* reply) override;
|
||||
grpc::Status CurrentCaseInfo(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfo* reply) override;
|
||||
grpc::Status CaseInfoFromCase(grpc::ServerContext* context, const rips::Case* request, rips::CaseInfo* reply) override;
|
||||
grpc::Status SelectedCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfos* reply) override;
|
||||
grpc::Status AllCaseGroups(grpc::ServerContext* context, const rips::Empty* request, rips::CaseGroups* reply) override;
|
||||
grpc::Status AllCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfos* reply) override;
|
||||
grpc::Status CasesInGroup(grpc::ServerContext* context, const rips::CaseGroup* request, rips::CaseInfos* reply) override;
|
||||
grpc::Status GetCurrentCase(grpc::ServerContext* context, const rips::Empty* request, rips::CaseRequest* reply) override;
|
||||
grpc::Status GetSelectedCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfoArray* reply) override;
|
||||
grpc::Status GetAllCaseGroups(grpc::ServerContext* context, const rips::Empty* request, rips::CaseGroups* reply) override;
|
||||
grpc::Status GetAllCases(grpc::ServerContext* context, const rips::Empty* request, rips::CaseInfoArray* reply) override;
|
||||
grpc::Status GetCasesInGroup(grpc::ServerContext* context, const rips::CaseGroup* request, rips::CaseInfoArray* reply) override;
|
||||
|
||||
public:
|
||||
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "RiaGrpcPropertiesService.h"
|
||||
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
#include "RiaGrpcGridInfoService.h"
|
||||
#include "RiaGrpcCaseService.h"
|
||||
|
||||
#include "RigActiveCellInfo.h"
|
||||
#include "RigActiveCellsResultAccessor.h"
|
||||
@@ -61,9 +61,9 @@ public:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status init(const ResultRequest* request)
|
||||
Status init(const PropertyRequest* request)
|
||||
{
|
||||
int caseId = request->request_case().id();
|
||||
int caseId = request->case_request().id();
|
||||
m_eclipseCase = dynamic_cast<RimEclipseCase*>(RiaGrpcServiceInterface::findCase(caseId));
|
||||
|
||||
if (m_eclipseCase)
|
||||
@@ -110,21 +110,21 @@ public:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Client streamers need to be initialised with the encapsulated parameters
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status init(const ResultRequestChunk* request)
|
||||
Status init(const PropertyInputChunk* chunk)
|
||||
{
|
||||
if (request->has_params())
|
||||
if (chunk->has_params())
|
||||
{
|
||||
return init(&(request->params()));
|
||||
return init(&(chunk->params()));
|
||||
}
|
||||
return grpc::Status(grpc::INVALID_ARGUMENT, "Need to have ResultRequest parameters in first message");
|
||||
return grpc::Status(grpc::INVALID_ARGUMENT, "Need to have PropertyRequest parameters in first message");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status assignStreamReply(ResultArray* reply)
|
||||
Status assignStreamReply(PropertyChunk* reply)
|
||||
{
|
||||
const size_t packageSize = RiaGrpcServiceInterface::numberOfMessagesForByteCount(sizeof(rips::ResultArray));
|
||||
const size_t packageSize = RiaGrpcServiceInterface::numberOfMessagesForByteCount(sizeof(rips::PropertyChunk));
|
||||
size_t packageIndex = 0u;
|
||||
reply->mutable_values()->Reserve((int)packageSize);
|
||||
for (; packageIndex < packageSize && m_currentCellIdx < m_cellCount; ++packageIndex, ++m_currentCellIdx)
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status receiveStreamRequest(const ResultRequestChunk* request)
|
||||
Status receiveStreamRequest(const PropertyInputChunk* request)
|
||||
{
|
||||
if (request->has_values())
|
||||
{
|
||||
@@ -183,7 +183,7 @@ protected:
|
||||
virtual void setCellResult(size_t currentCellIndex, double value) = 0;
|
||||
|
||||
protected:
|
||||
const rips::ResultRequest* m_request;
|
||||
const rips::PropertyRequest* m_request;
|
||||
RimEclipseCase* m_eclipseCase;
|
||||
size_t m_currentCellIdx;
|
||||
size_t m_cellCount;
|
||||
@@ -263,11 +263,11 @@ private:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPropertiesService::GetAvailableProperties(grpc::ServerContext* context,
|
||||
const PropertiesRequest* request,
|
||||
AvailableProperties* reply)
|
||||
grpc::Status RiaGrpcPropertiesService::GetAvailableProperties(grpc::ServerContext* context,
|
||||
const AvailablePropertiesRequest* request,
|
||||
AvailableProperties* reply)
|
||||
{
|
||||
int caseId = request->request_case().id();
|
||||
int caseId = request->case_request().id();
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(RiaGrpcServiceInterface::findCase(caseId));
|
||||
if (eclipseCase)
|
||||
{
|
||||
@@ -291,9 +291,9 @@ grpc::Status RiaGrpcPropertiesService::GetAvailableProperties(grpc::ServerContex
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPropertiesService::GetActiveCellResults(grpc::ServerContext* context,
|
||||
const ResultRequest* request,
|
||||
ResultArray* reply,
|
||||
grpc::Status RiaGrpcPropertiesService::GetActiveCellProperty(grpc::ServerContext* context,
|
||||
const PropertyRequest* request,
|
||||
PropertyChunk* reply,
|
||||
RiaActiveCellResultsStateHandler* stateHandler)
|
||||
{
|
||||
return stateHandler->assignStreamReply(reply);
|
||||
@@ -303,9 +303,9 @@ grpc::Status RiaGrpcPropertiesService::GetActiveCellResults(grpc::ServerContext*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPropertiesService::GetGridResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequest* request,
|
||||
rips::ResultArray* reply,
|
||||
grpc::Status RiaGrpcPropertiesService::GetGridProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyRequest* request,
|
||||
rips::PropertyChunk* reply,
|
||||
RiaGridCellResultsStateHandler* stateHandler)
|
||||
{
|
||||
return stateHandler->assignStreamReply(reply);
|
||||
@@ -314,8 +314,8 @@ grpc::Status RiaGrpcPropertiesService::GetGridResults(grpc::ServerContext*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPropertiesService::SetActiveCellResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequestChunk* request,
|
||||
grpc::Status RiaGrpcPropertiesService::SetActiveCellProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyInputChunk* request,
|
||||
rips::Empty* reply,
|
||||
RiaActiveCellResultsStateHandler* stateHandler)
|
||||
{
|
||||
@@ -326,8 +326,8 @@ grpc::Status RiaGrpcPropertiesService::SetActiveCellResults(grpc::ServerContext*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPropertiesService::SetGridResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequestChunk* request,
|
||||
grpc::Status RiaGrpcPropertiesService::SetGridProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyInputChunk* request,
|
||||
rips::Empty* reply,
|
||||
RiaGridCellResultsStateHandler* stateHandler)
|
||||
{
|
||||
@@ -340,16 +340,16 @@ std::vector<RiaGrpcCallbackInterface*> RiaGrpcPropertiesService::createCallbacks
|
||||
{
|
||||
typedef RiaGrpcPropertiesService Self;
|
||||
|
||||
return {new RiaGrpcUnaryCallback<Self, PropertiesRequest, AvailableProperties>(
|
||||
return {new RiaGrpcUnaryCallback<Self, AvailablePropertiesRequest, AvailableProperties>(
|
||||
this, &Self::GetAvailableProperties, &Self::RequestGetAvailableProperties),
|
||||
new RiaGrpcServerStreamCallback<Self, ResultRequest, ResultArray, RiaActiveCellResultsStateHandler>(
|
||||
this, &Self::GetActiveCellResults, &Self::RequestGetActiveCellResults, new RiaActiveCellResultsStateHandler),
|
||||
new RiaGrpcServerStreamCallback<Self, ResultRequest, ResultArray, RiaGridCellResultsStateHandler>(
|
||||
this, &Self::GetGridResults, &Self::RequestGetGridResults, new RiaGridCellResultsStateHandler),
|
||||
new RiaGrpcClientStreamCallback<Self, ResultRequestChunk, Empty, RiaActiveCellResultsStateHandler>(
|
||||
this, &Self::SetActiveCellResults, &Self::RequestSetActiveCellResults, new RiaActiveCellResultsStateHandler(true)),
|
||||
new RiaGrpcClientStreamCallback<Self, ResultRequestChunk, Empty, RiaGridCellResultsStateHandler>(
|
||||
this, &Self::SetGridResults, &Self::RequestSetGridResults, new RiaGridCellResultsStateHandler(true))
|
||||
new RiaGrpcServerStreamCallback<Self, PropertyRequest, PropertyChunk, RiaActiveCellResultsStateHandler>(
|
||||
this, &Self::GetActiveCellProperty, &Self::RequestGetActiveCellProperty, new RiaActiveCellResultsStateHandler),
|
||||
new RiaGrpcServerStreamCallback<Self, PropertyRequest, PropertyChunk, RiaGridCellResultsStateHandler>(
|
||||
this, &Self::GetGridProperty, &Self::RequestGetGridProperty, new RiaGridCellResultsStateHandler),
|
||||
new RiaGrpcClientStreamCallback<Self, PropertyInputChunk, Empty, RiaActiveCellResultsStateHandler>(
|
||||
this, &Self::SetActiveCellProperty, &Self::RequestSetActiveCellProperty, new RiaActiveCellResultsStateHandler(true)),
|
||||
new RiaGrpcClientStreamCallback<Self, PropertyInputChunk, Empty, RiaGridCellResultsStateHandler>(
|
||||
this, &Self::SetGridProperty, &Self::RequestSetGridProperty, new RiaGridCellResultsStateHandler(true))
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -34,25 +34,25 @@ class RiaGridCellResultsStateHandler;
|
||||
class RiaGrpcPropertiesService final : public rips::Properties::AsyncService, public RiaGrpcServiceInterface
|
||||
{
|
||||
public:
|
||||
grpc::Status GetAvailableProperties(grpc::ServerContext* context,
|
||||
const rips::PropertiesRequest* request,
|
||||
rips::AvailableProperties* reply) override;
|
||||
grpc::Status GetActiveCellResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequest* request,
|
||||
rips::ResultArray* reply,
|
||||
RiaActiveCellResultsStateHandler* stateHandler);
|
||||
grpc::Status GetGridResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequest* request,
|
||||
rips::ResultArray* reply,
|
||||
RiaGridCellResultsStateHandler* stateHandler);
|
||||
grpc::Status SetActiveCellResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequestChunk* request,
|
||||
rips::Empty* reply,
|
||||
RiaActiveCellResultsStateHandler* stateHandler);
|
||||
grpc::Status SetGridResults(grpc::ServerContext* context,
|
||||
const rips::ResultRequestChunk* request,
|
||||
rips::Empty* reply,
|
||||
RiaGridCellResultsStateHandler* stateHandler);
|
||||
grpc::Status GetAvailableProperties(grpc::ServerContext* context,
|
||||
const rips::AvailablePropertiesRequest* request,
|
||||
rips::AvailableProperties* reply) override;
|
||||
grpc::Status GetActiveCellProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyRequest* request,
|
||||
rips::PropertyChunk* reply,
|
||||
RiaActiveCellResultsStateHandler* stateHandler);
|
||||
grpc::Status GetGridProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyRequest* request,
|
||||
rips::PropertyChunk* reply,
|
||||
RiaGridCellResultsStateHandler* stateHandler);
|
||||
grpc::Status SetActiveCellProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyInputChunk* chunk,
|
||||
rips::Empty* reply,
|
||||
RiaActiveCellResultsStateHandler* stateHandler);
|
||||
grpc::Status SetGridProperty(grpc::ServerContext* context,
|
||||
const rips::PropertyInputChunk* chunk,
|
||||
rips::Empty* reply,
|
||||
RiaGridCellResultsStateHandler* stateHandler);
|
||||
|
||||
std::vector<RiaGrpcCallbackInterface*> createCallbacks() override;
|
||||
};
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "RiaGrpcCallbacks.h"
|
||||
#include "RiaGrpcServiceInterface.h"
|
||||
#include "RiaGrpcGridInfoService.h"
|
||||
#include "RiaGrpcCaseService.h"
|
||||
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigMainGrid.h"
|
||||
|
||||
@@ -57,6 +57,15 @@ ${CMAKE_CURRENT_LIST_DIR}/RimWellPathCompletions-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimSummaryCaseCollection-Test.cpp
|
||||
)
|
||||
|
||||
if (RESINSIGHT_ENABLE_GRPC)
|
||||
list(APPEND GPRC_UNIT_TEST_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcInterface-Test.cpp
|
||||
)
|
||||
list(APPEND SOURCE_GROUP_SOURCE_FILES
|
||||
${GRPC_UNIT_TEST_SOURCE_FILES}
|
||||
)
|
||||
endif(RESINSIGHT_ENABLE_GRPC)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <grpc/grpc.h>
|
||||
#include <grpcpp/channel.h>
|
||||
#include <grpcpp/client_context.h>
|
||||
#include <grpcpp/create_channel.h>
|
||||
#include <grpcpp/security/credentials.h>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
|
||||
#include "Properties.grpc.pb.h"
|
||||
|
||||
using grpc::Channel;
|
||||
using grpc::ClientContext;
|
||||
using grpc::ClientReader;
|
||||
using grpc::ClientReaderWriter;
|
||||
using grpc::ClientWriter;
|
||||
using grpc::Status;
|
||||
|
||||
class PropertiesClient
|
||||
{
|
||||
public:
|
||||
PropertiesClient(std::shared_ptr<Channel> channel)
|
||||
: m_stub(rips::Properties::NewStub(channel))
|
||||
{
|
||||
}
|
||||
Status GetActiveCellProperty(rips::PropertyType propType, const std::string& propertyName, int timeStep, std::vector<double>* results) const
|
||||
{
|
||||
rips::PropertyRequest request;
|
||||
rips::CaseRequest* requestCase = new rips::CaseRequest;
|
||||
requestCase->set_id(0);
|
||||
request.set_allocated_case_request(requestCase);
|
||||
request.set_grid_index(0);
|
||||
request.set_porosity_model(rips::PorosityModelType::MATRIX_MODEL);
|
||||
request.set_property_type(propType);
|
||||
request.set_property_name(propertyName);
|
||||
request.set_time_step(timeStep);
|
||||
rips::PropertyChunk resultArray;
|
||||
ClientContext context;
|
||||
|
||||
std::unique_ptr<ClientReader<rips::PropertyChunk>> reader = m_stub->GetActiveCellProperty(&context, request);
|
||||
while (reader->Read(&resultArray))
|
||||
{
|
||||
results->insert(results->end(), resultArray.values().begin(), resultArray.values().end());
|
||||
}
|
||||
return reader->Finish();
|
||||
}
|
||||
private:
|
||||
std::unique_ptr<rips::Properties::Stub> m_stub;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DISABLED_RiaGrpcInterface, SoilAverage)
|
||||
{
|
||||
PropertiesClient client(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
|
||||
|
||||
for (size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
std::vector<double> results;
|
||||
Status status = client.GetActiveCellProperty(rips::PropertyType::DYNAMIC_NATIVE, "SOIL", i, &results);
|
||||
std::cout << "Number of results: " << results.size() << std::endl;
|
||||
double sum = std::accumulate(results.begin(), results.end(), 0.0);
|
||||
std::cout << "Avg: " << sum / static_cast<double>(results.size()) << std::endl;
|
||||
EXPECT_EQ(grpc::OK, status.error_code());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user