#4549 Add python method to get cell corners on a grid

Equivalent to GetCellCorners in Octave.
This commit is contained in:
Kristian Bendiksen
2020-02-19 10:16:28 +01:00
parent a5be62c5b6
commit c20c3bc2ac
6 changed files with 143 additions and 0 deletions

View File

@@ -59,3 +59,30 @@ class Grid:
for center in chunk.centers:
centers.append(center)
return centers
def cell_corners_async(self):
"""The cell corners for all cells in given grid, async.
Returns:
iterator to a list of CellCorners: a class with Vec3d for each corner (c0, c1.., c7)
"""
case_request = Case_pb2.CaseRequest(id=self.case.case_id)
chunks = self.__stub.GetCellCorners(
Grid_pb2.GridRequest(case_request=case_request,
grid_index=self.index))
for chunk in chunks:
yield chunk
def cell_corners(self):
"""The cell corners for all cells in given grid
Returns:
list of CellCorners: a class with Vec3d for each corner (c0, c1.., c7)
"""
corners = []
chunks = self.cell_corners_async()
for chunk in chunks:
for center in chunk.cells:
corners.append(center)
return corners

View File

@@ -1,11 +1,17 @@
import sys
import os
import math
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
import dataroot
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):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath)
@@ -18,3 +24,30 @@ def test_10k(rips_instance, initialize_test):
cell_centers = grid.cell_centers()
assert(len(cell_centers) == (dimensions.i * dimensions.j * dimensions.k))
# Test a specific cell (results from ResInsight UI)
cell_index = 168143
assert(math.isclose(3627.17, cell_centers[cell_index].x, abs_tol=0.1))
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 = grid.cell_corners()
assert(len(cell_corners) == (dimensions.i * dimensions.j * dimensions.k))
# 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])