mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4549 Add python method to get cell centers on a grid
Equivalent to GetCellCenters in Octave.
This commit is contained in:
@@ -13,7 +13,7 @@ import rips.generated.Grid_pb2_grpc as Grid_pb2_grpc
|
||||
class Grid:
|
||||
"""Grid Information. Not meant to be constructed separately
|
||||
|
||||
Create Grid objects using mathods on Case: Grid() and Grids()
|
||||
Create Grid objects using methods on Case: Grid() and Grids()
|
||||
"""
|
||||
def __init__(self, index, case, channel):
|
||||
self.__channel = channel
|
||||
@@ -32,3 +32,30 @@ class Grid:
|
||||
return self.__stub.GetDimensions(
|
||||
Grid_pb2.GridRequest(case_request=case_request,
|
||||
grid_index=self.index)).dimensions
|
||||
|
||||
|
||||
def cell_centers_async(self):
|
||||
"""The cells center for all cells in given grid async.
|
||||
|
||||
Returns:
|
||||
Iterator to a list of Vec3d: class with double attributes x, y, x giving cell centers
|
||||
"""
|
||||
case_request = Case_pb2.CaseRequest(id=self.case.case_id)
|
||||
chunks = self.__stub.GetCellCenters(
|
||||
Grid_pb2.GridRequest(case_request=case_request,
|
||||
grid_index=self.index))
|
||||
for chunk in chunks:
|
||||
yield chunk
|
||||
|
||||
def cell_centers(self):
|
||||
"""The cell center for all cells in given grid
|
||||
|
||||
Returns:
|
||||
List of Vec3d: class with double attributes x, y, x giving cell centers
|
||||
"""
|
||||
centers = []
|
||||
chunks = self.cell_centers_async()
|
||||
for chunk in chunks:
|
||||
for center in chunk.centers:
|
||||
centers.append(center)
|
||||
return centers
|
||||
|
||||
@@ -15,3 +15,6 @@ def test_10k(rips_instance, initialize_test):
|
||||
assert(dimensions.i == 90)
|
||||
assert(dimensions.j == 96)
|
||||
assert(dimensions.k == 36)
|
||||
|
||||
cell_centers = grid.cell_centers()
|
||||
assert(len(cell_centers) == (dimensions.i * dimensions.j * dimensions.k))
|
||||
|
||||
Reference in New Issue
Block a user