#4549 Add python method to get cell corners for active cells

Equivalent to GetActiveCellCorners in Octave.
This commit is contained in:
Kristian Bendiksen
2020-02-19 11:33:25 +01:00
parent c20c3bc2ac
commit c64281c525
5 changed files with 174 additions and 1 deletions

View File

@@ -858,3 +858,40 @@ class Case(PdmObject):
for value in chunk.centers:
cell_centers.append(value)
return cell_centers
def active_cell_corners_async(
self,
porosity_model="MATRIX_MODEL",
):
"""Get a cell corners for all active cells. Async, so returns an iterator
Arguments:
porosity_model(str): string enum. See available()
Returns:
An iterator to a chunk object containing an array of CellCorners (which is eight Vec3d values).
Loop through the chunks and then the values within the chunk to get all values.
"""
porosity_model_enum = Case_pb2.PorosityModelType.Value(porosity_model)
request = Case_pb2.CellInfoRequest(case_request=self.__request,
porosity_model=porosity_model_enum)
return self.__case_stub.GetCellCornersForActiveCells(request)
def active_cell_corners(
self,
porosity_model="MATRIX_MODEL",
):
"""Get a cell corners for all active cells. Synchronous, so returns a list.
Arguments:
porosity_model(str): string enum. See available()
Returns:
A list of CellCorners
"""
cell_corners = []
generator = self.active_cell_corners_async(porosity_model)
for chunk in generator:
for value in chunk.cells:
cell_corners.append(value)
return cell_corners

View File

@@ -62,6 +62,11 @@ def get_cell_index_with_ijk(cell_info, i, j, k):
return idx
return -1
def check_corner(actual, expected):
assert(math.isclose(actual.x, expected[0], abs_tol=0.1))
assert(math.isclose(actual.y, expected[1], abs_tol=0.1))
assert(math.isclose(actual.z, expected[2], abs_tol=0.1))
def test_10k(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
@@ -88,6 +93,26 @@ def test_10k(rips_instance, initialize_test):
assert(math.isclose(5209.75, cell_centers[cell_index].y, abs_tol=0.1))
assert(math.isclose(4179.6, cell_centers[cell_index].z, abs_tol=0.1))
cell_corners = case.active_cell_corners()
assert(len(cell_corners) == cell_count_info.active_cell_count)
# Expected values from ResInsight UI
expected_corners = [[ 3565.22, 5179.02, 4177.18],
[ 3655.67, 5145.34, 4176.63],
[ 3690.07, 5240.69, 4180.02],
[ 3599.87, 5275.16, 4179.32],
[ 3564.13, 5178.61, 4179.75],
[ 3654.78, 5144.79, 4179.23],
[ 3688.99, 5239.88, 4182.7],
[ 3598.62, 5274.48, 4181.96]]
check_corner(cell_corners[cell_index].c0, expected_corners[0])
check_corner(cell_corners[cell_index].c1, expected_corners[1])
check_corner(cell_corners[cell_index].c2, expected_corners[2])
check_corner(cell_corners[cell_index].c3, expected_corners[3])
check_corner(cell_corners[cell_index].c4, expected_corners[4])
check_corner(cell_corners[cell_index].c5, expected_corners[5])
check_corner(cell_corners[cell_index].c6, expected_corners[6])
check_corner(cell_corners[cell_index].c7, expected_corners[7])
def test_PdmObject(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)