mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
gRPC: Move all python code into the ApplicationCode/GrpcInterface folder
This commit is contained in:
parent
9ac15ec553
commit
c9d56bda9c
@ -23,9 +23,6 @@ endif(Qt5Core_FOUND)
|
|||||||
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.h.cmake
|
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.h.cmake
|
||||||
${CMAKE_BINARY_DIR}/Generated/RiaVersionInfo.h
|
${CMAKE_BINARY_DIR}/Generated/RiaVersionInfo.h
|
||||||
)
|
)
|
||||||
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
|
|
||||||
${CMAKE_SOURCE_DIR}/Python/generated/RiaVersionInfo.py
|
|
||||||
)
|
|
||||||
|
|
||||||
if (MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11))
|
if (MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11))
|
||||||
# VS 2017 : Disable warnings from from gtest code, using deprecated code related to TR1
|
# VS 2017 : Disable warnings from from gtest code, using deprecated code related to TR1
|
||||||
|
@ -79,7 +79,7 @@ set(PROTO_FILES
|
|||||||
"Properties"
|
"Properties"
|
||||||
)
|
)
|
||||||
|
|
||||||
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_SOURCE_DIR}/Python")
|
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/Python")
|
||||||
set(GRPC_PYTHON_DEST_PATH "${CMAKE_BINARY_DIR}/Python")
|
set(GRPC_PYTHON_DEST_PATH "${CMAKE_BINARY_DIR}/Python")
|
||||||
|
|
||||||
foreach(proto_file ${PROTO_FILES})
|
foreach(proto_file ${PROTO_FILES})
|
||||||
@ -150,7 +150,8 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
|||||||
"examples/ResultValues.py"
|
"examples/ResultValues.py"
|
||||||
"examples/SelectedCases.py"
|
"examples/SelectedCases.py"
|
||||||
"examples/AllCases.py"
|
"examples/AllCases.py"
|
||||||
"examples/SetResultValues.py"
|
"examples/SetActiveCellProperties.py"
|
||||||
|
"examples/SetGridProperties.py"
|
||||||
"tests/test_sample.py"
|
"tests/test_sample.py"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -158,7 +159,7 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
|||||||
list(APPEND GRPC_PYTHON_SOURCES_FULL_PATH "${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}")
|
list(APPEND GRPC_PYTHON_SOURCES_FULL_PATH "${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}")
|
||||||
endforeach()
|
endforeach()
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
source_group(TREE ${GRPC_PYTHON_SOURCE_PATH} FILES ${GRPC_PYTHON_SOURCES_FULL_PATH} PREFIX "Python")
|
source_group(TREE ${GRPC_PYTHON_SOURCE_PATH} FILES ${GRPC_PYTHON_SOURCES_FULL_PATH} PREFIX "GrpcInterface\\Python")
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
|
|
||||||
endif(PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
endif(PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||||
@ -166,5 +167,9 @@ endif(PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
|||||||
list ( APPEND GRPC_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
list ( APPEND GRPC_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||||
list ( APPEND GRPC_CPP_SOURCES ${SOURCE_GROUP_SOURCE_FILES})
|
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
|
||||||
|
)
|
||||||
|
|
||||||
source_group( "GrpcInterface" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.cmake )
|
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} )
|
source_group( "GrpcInterface\\GrpcProtos" FILES ${GRPC_PROTO_FILES_FULL_PATH} )
|
@ -131,20 +131,16 @@ class Properties:
|
|||||||
chunk = Properties_pb2.ResultRequestChunk()
|
chunk = Properties_pb2.ResultRequestChunk()
|
||||||
if index is -1:
|
if index is -1:
|
||||||
chunk.params.CopyFrom(parameters)
|
chunk.params.CopyFrom(parameters)
|
||||||
print("Added parameters")
|
|
||||||
index += 1;
|
index += 1;
|
||||||
else:
|
else:
|
||||||
actualChunkSize = min(len(array) - index + 1, chunkSize)
|
actualChunkSize = min(len(array) - index + 1, chunkSize)
|
||||||
chunk.values.CopyFrom(Properties_pb2.ResultArray(values = array[index:index+actualChunkSize]))
|
chunk.values.CopyFrom(Properties_pb2.ResultArray(values = array[index:index+actualChunkSize]))
|
||||||
print("Added values")
|
|
||||||
index += actualChunkSize
|
index += actualChunkSize
|
||||||
|
|
||||||
print(index)
|
|
||||||
yield chunk
|
yield chunk
|
||||||
# Final empty message to signal completion
|
# Final empty message to signal completion
|
||||||
chunk = Properties_pb2.ResultRequestChunk()
|
chunk = Properties_pb2.ResultRequestChunk()
|
||||||
yield chunk
|
yield chunk
|
||||||
print("finished")
|
|
||||||
|
|
||||||
def availableProperties(self, caseId, propertyType, porosityModel = 'MATRIX_MODEL'):
|
def availableProperties(self, caseId, propertyType, porosityModel = 'MATRIX_MODEL'):
|
||||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||||
@ -175,7 +171,6 @@ class Properties:
|
|||||||
def setActiveCellResults(self, values, caseId, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
def setActiveCellResults(self, values, caseId, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||||
print (propertyName)
|
|
||||||
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
request = Properties_pb2.ResultRequest(request_case = CaseInfo_pb2.Case(id=caseId),
|
||||||
property_type = propertyTypeEnum,
|
property_type = propertyTypeEnum,
|
||||||
property_name = propertyName,
|
property_name = propertyName,
|
||||||
@ -184,7 +179,6 @@ class Properties:
|
|||||||
porosity_model = porosityModelEnum)
|
porosity_model = porosityModelEnum)
|
||||||
try:
|
try:
|
||||||
request_iterator = self.generateResultRequestArrays(values, request)
|
request_iterator = self.generateResultRequestArrays(values, request)
|
||||||
print("Starting to send data")
|
|
||||||
self.properties.SetActiveCellResults(request_iterator)
|
self.properties.SetActiveCellResults(request_iterator)
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||||
@ -192,6 +186,24 @@ class Properties:
|
|||||||
else:
|
else:
|
||||||
print("Other error", e)
|
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:
|
class Instance:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_port_in_use(port):
|
def is_port_in_use(port):
|
@ -0,0 +1,16 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||||
|
import ResInsight
|
||||||
|
|
||||||
|
resInsight = ResInsight.Instance.find()
|
||||||
|
|
||||||
|
totalCellCount = resInsight.gridInfo.cellCount(caseId=0).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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user