#4549 Add python method to get properties for selected cells.

Equivalent to GetGridPropertyForSelectedCells in Octave.
This commit is contained in:
Kristian Bendiksen
2020-02-19 22:01:42 +01:00
parent 8a1fa38435
commit d497f04d0d
6 changed files with 165 additions and 1 deletions

View File

@@ -15,7 +15,9 @@ if resinsight is not None:
cells = case.selected_cells()
print("Found " + str(len(cells)) + " selected cells")
for cell in cells:
time_step_info = case.time_steps()
for (idx, cell) in enumerate(cells):
print("Selected cell: [{}, {}, {}] grid: {}".format(cell.ijk.i+1, cell.ijk.j+1, cell.ijk.k+1, cell.grid_index))
# Get the grid and dimensions
@@ -41,3 +43,8 @@ if resinsight is not None:
print("c5:\n" + str(cell_corners.c5))
print("c6:\n" + str(cell_corners.c6))
print("c7:\n" + str(cell_corners.c7))
for (tidx, timestep) in enumerate(time_step_info):
# Read the full SOIL result for time step
soil_results = case.selected_cell_property('DYNAMIC_NATIVE', 'SOIL', tidx)
print("SOIL: {} ({}.{}.{})".format(soil_results[idx], timestep.year, timestep.month, timestep.day))

View File

@@ -585,6 +585,61 @@ class Case(PdmObject):
all_values.append(value)
return all_values
def selected_cell_property_async(self,
property_type,
property_name,
time_step,
porosity_model="MATRIX_MODEL"):
"""Get a cell property for all selected cells. Async, so returns an iterator
Arguments:
property_type(str): string enum. See available()
property_name(str): name of an Eclipse property
time_step(int): the time step for which to get the property for
porosity_model(str): string enum. See available()
Returns:
An iterator to a chunk object containing an array of double values
Loop through the chunks and then the values within the chunk to get all values.
"""
property_type_enum = Properties_pb2.PropertyType.Value(property_type)
porosity_model_enum = Case_pb2.PorosityModelType.Value(porosity_model)
request = Properties_pb2.PropertyRequest(
case_request=self.__request,
property_type=property_type_enum,
property_name=property_name,
time_step=time_step,
porosity_model=porosity_model_enum,
)
for chunk in self.__properties_stub.GetSelectedCellProperty(request):
yield chunk
def selected_cell_property(self,
property_type,
property_name,
time_step,
porosity_model="MATRIX_MODEL"):
"""Get a cell property for all selected cells. Sync, so returns a list
Arguments:
property_type(str): string enum. See available()
property_name(str): name of an Eclipse property
time_step(int): the time step for which to get the property for
porosity_model(str): string enum. See available()
Returns:
A list containing double values
Loop through the chunks and then the values within the chunk to get all values.
"""
all_values = []
generator = self.selected_cell_property_async(property_type,
property_name, time_step,
porosity_model)
for chunk in generator:
for value in chunk.values:
all_values.append(value)
return all_values
def grid_property_async(
self,
property_type,

View File

@@ -177,3 +177,9 @@ def test_selected_cells(rips_instance, initialize_test):
assert(case.name == "TEST10K_FLT_LGR_NNC")
selected_cells = case.selected_cells()
assert(len(selected_cells) == 0)
time_step_info = case.time_steps()
for (tidx, timestep) in enumerate(time_step_info):
# Try to read for SOIL the time step (will be empty since nothing is selected)
soil_results = case.selected_cell_property('DYNAMIC_NATIVE', 'SOIL', tidx)
assert(len(soil_results) == 0)