mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4477 Add python method to set NNC connection values.
Equivalent to SetNNCProperty in Octave.
This commit is contained in:
committed by
Magne Sjaastad
parent
21610d055a
commit
c03633230e
@@ -1097,3 +1097,49 @@ def nnc_connections_generated_values(self, property_name, time_step):
|
||||
"""
|
||||
generator = self.nnc_connections_generated_values_async(property_name, time_step)
|
||||
return self.__nnc_values_generator_to_list(generator)
|
||||
|
||||
@add_method(Case)
|
||||
def __generate_nnc_property_input_chunks(self, array, parameters):
|
||||
index = -1
|
||||
while index < len(array):
|
||||
chunk = NNCProperties_pb2.NNCValuesChunk()
|
||||
if index is -1:
|
||||
chunk.params.CopyFrom(parameters)
|
||||
index += 1
|
||||
else:
|
||||
actual_chunk_size = min(len(array) - index + 1, self.chunk_size)
|
||||
chunk.values.CopyFrom(
|
||||
NNCProperties_pb2.NNCValues(values=array[index:index + actual_chunk_size]))
|
||||
index += actual_chunk_size
|
||||
|
||||
yield chunk
|
||||
# Final empty message to signal completion
|
||||
chunk = NNCProperties_pb2.NNCValuesChunk()
|
||||
yield chunk
|
||||
|
||||
@add_method(Case)
|
||||
def set_nnc_connections_values(
|
||||
self,
|
||||
values,
|
||||
property_name,
|
||||
time_step,
|
||||
porosity_model="MATRIX_MODEL"):
|
||||
"""Set nnc connection values for all connections..
|
||||
|
||||
Arguments:
|
||||
values(list): a list of double precision floating point numbers
|
||||
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()
|
||||
"""
|
||||
porosity_model_enum = Case_pb2.PorosityModelType.Value(porosity_model)
|
||||
request = NNCProperties_pb2.NNCValuesInputRequest(
|
||||
case_id=self.id,
|
||||
property_name=property_name,
|
||||
time_step=time_step,
|
||||
porosity_model=porosity_model_enum,
|
||||
)
|
||||
request_iterator = self.__generate_nnc_property_input_chunks(values, request)
|
||||
reply = self.__nnc_properties_stub.SetNNCValues(request_iterator)
|
||||
if reply.accepted_value_count < len(values):
|
||||
raise IndexError
|
||||
|
||||
@@ -46,6 +46,28 @@ def test_10kSync(rips_instance, initialize_test):
|
||||
for a in allen_vals:
|
||||
assert(isinstance(a, float))
|
||||
|
||||
# Generate some data
|
||||
new_data = []
|
||||
for (c, _) in enumerate(nnc_connections):
|
||||
new_data.append(float(c))
|
||||
|
||||
property_name = "NEW_PROP"
|
||||
case.set_nnc_connections_values(new_data, property_name, 0)
|
||||
new_prop_vals = case.nnc_connections_generated_values(property_name, 0)
|
||||
assert(len(new_prop_vals) == len(new_data))
|
||||
for i in range(0, len(new_data)):
|
||||
assert(new_data[i] == new_prop_vals[i])
|
||||
|
||||
# Set some other data for second time step
|
||||
for i in range(0, len(new_data)):
|
||||
new_data[i] = new_data[i] * 2.0
|
||||
|
||||
case.set_nnc_connections_values(new_data, property_name, 1)
|
||||
new_prop_vals = case.nnc_connections_generated_values(property_name, 1)
|
||||
assert(len(new_prop_vals) == len(nnc_connections))
|
||||
for i in range(0, len(new_data)):
|
||||
assert(new_data[i] == new_prop_vals[i])
|
||||
|
||||
def test_non_existing_dynamic_values(rips_instance, initialize_test):
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.load_case(path=casePath)
|
||||
|
||||
Reference in New Issue
Block a user