#4477 Add python methods to get NNC connection and available properties

Equivalent to GetNNCPropertyNames and GetNNCConnections in Octave.
This commit is contained in:
Kristian Bendiksen
2020-02-21 10:24:58 +01:00
committed by Gaute Lindkvist
parent 795c29bfb3
commit 1a05430123
6 changed files with 360 additions and 0 deletions

View File

@@ -17,6 +17,9 @@ import rips.generated.PdmObject_pb2 as PdmObject_pb2
import rips.generated.Properties_pb2 as Properties_pb2
import rips.generated.Properties_pb2_grpc as Properties_pb2_grpc
import rips.generated.NNCProperties_pb2 as NNCProperties_pb2
import rips.generated.NNCProperties_pb2_grpc as NNCProperties_pb2_grpc
from rips.grid import Grid
from rips.pdmobject import PdmObject
from rips.view import View
@@ -50,6 +53,8 @@ class Case(PdmObject):
info = self.__case_stub.GetCaseInfo(self.__request)
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(
self.__channel)
self.__nnc_properties_stub = NNCProperties_pb2_grpc.NNCPropertiesStub(
self.__channel)
PdmObject.__init__(self, self.__case_stub.GetPdmObject(self.__request),
self.__channel, project)
@@ -980,3 +985,31 @@ class Case(PdmObject):
for each entry.
"""
return self.__case_stub.GetCoarseningInfoArray(self.__request).data
def available_nnc_properties(self):
"""Get a list of available NNC properties
"""
return self.__nnc_properties_stub.GetAvailableNNCProperties(self.__request).properties
def nnc_connections_async(self):
"""Get the NNC connections. Async, so returns an iterator.
Returns:
An iterator to a chunk object containing an array NNCConnection objects.
Loop through the chunks and then the connection within the chunk to get all connections.
"""
return self.__nnc_properties_stub.GetNNCConnections(self.__request)
def nnc_connections(self):
"""Get the NNC connection. Synchronous, so returns a list.
Returns:
A list of NNCConnection objects.
"""
connections = []
generator = self.nnc_connections_async()
for chunk in generator:
for value in chunk.connections:
connections.append(value)
return connections

View File

@@ -0,0 +1,35 @@
import sys
import os
import grpc
import pytest
import rips.generated.NNCProperties_pb2 as NNCProperties_pb2
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
import dataroot
def test_10kSync(rips_instance, initialize_test):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath)
properties = case.available_nnc_properties()
assert(len(properties) == 3)
assert("TRAN" == properties[0].name)
assert(NNCProperties_pb2.NNCPropertyType.NNC_STATIC == properties[0].property_type)
assert("Binary Formation Allen" == properties[1].name)
assert(NNCProperties_pb2.NNCPropertyType.NNC_GENERATED == properties[1].property_type)
assert("Formation Allen" == properties[2].name)
assert(NNCProperties_pb2.NNCPropertyType.NNC_GENERATED == properties[2].property_type)
nnc_connections = case.nnc_connections()
assert(len(nnc_connections) == 84759)
connection = nnc_connections[0]
assert(connection.cell1.i == 33)
assert(connection.cell1.j == 40)
assert(connection.cell1.k == 14)
assert(connection.cell_grid_index1 == 0)