2019-08-19 06:46:14 -05:00
|
|
|
##############################################################################
|
|
|
|
# This example will create a derived result for each time step asynchronously
|
|
|
|
##############################################################################
|
|
|
|
|
2019-06-03 14:11:27 -05:00
|
|
|
import rips
|
2019-08-15 01:07:43 -05:00
|
|
|
import time
|
2019-05-31 03:17:44 -05:00
|
|
|
|
2019-08-19 06:46:14 -05:00
|
|
|
# Internal function for creating a result from a small chunk of soil and porv results
|
|
|
|
# The return value of the function is a generator for the results rather than the result itself.
|
2019-09-19 08:14:01 -05:00
|
|
|
def create_result(soil_chunks, porv_chunks):
|
|
|
|
for (soil_chunk, porv_chunk) in zip(soil_chunks, porv_chunks):
|
2019-05-31 03:17:44 -05:00
|
|
|
resultChunk = []
|
|
|
|
number = 0
|
2019-09-19 08:14:01 -05:00
|
|
|
for (soil_value, porv_value) in zip(soil_chunk.values, porv_chunk.values):
|
|
|
|
resultChunk.append(soil_value * porv_value)
|
2019-08-19 06:46:14 -05:00
|
|
|
# Return a Python generator
|
|
|
|
yield resultChunk
|
2019-05-31 03:17:44 -05:00
|
|
|
|
2021-01-26 13:48:01 -06:00
|
|
|
|
|
|
|
resinsight = rips.Instance.find()
|
|
|
|
start = time.time()
|
|
|
|
case = resinsight.project.cases()[0]
|
2019-09-19 04:14:40 -05:00
|
|
|
timeStepInfo = case.time_steps()
|
2019-05-31 03:17:44 -05:00
|
|
|
|
2019-08-19 06:46:14 -05:00
|
|
|
# Get a generator for the porv results. The generator will provide a chunk each time it is iterated
|
2021-01-26 13:48:01 -06:00
|
|
|
porv_chunks = case.active_cell_property_async("STATIC_NATIVE", "PORV", 0)
|
2019-08-19 06:46:14 -05:00
|
|
|
|
|
|
|
# Read the static result into an array, so we don't have to transfer it for each iteration
|
|
|
|
# Note we use the async method even if we synchronise here, because we need the values chunked
|
|
|
|
# ... to match the soil chunks
|
2019-09-19 08:14:01 -05:00
|
|
|
porv_array = []
|
|
|
|
for porv_chunk in porv_chunks:
|
|
|
|
porv_array.append(porv_chunk)
|
2019-05-31 03:17:44 -05:00
|
|
|
|
2021-01-26 13:48:01 -06:00
|
|
|
for i in range(0, len(timeStepInfo)):
|
2019-08-19 06:46:14 -05:00
|
|
|
# Get a generator object for the SOIL property for time step i
|
2021-01-26 13:48:01 -06:00
|
|
|
soil_chunks = case.active_cell_property_async("DYNAMIC_NATIVE", "SOIL", i)
|
2019-08-19 06:46:14 -05:00
|
|
|
# Create the generator object for the SOIL * PORV derived result
|
2019-09-19 08:14:01 -05:00
|
|
|
result_generator = create_result(soil_chunks, iter(porv_array))
|
2019-08-19 06:46:14 -05:00
|
|
|
# Send back the result asynchronously with a generator object
|
2021-01-26 13:48:01 -06:00
|
|
|
case.set_active_cell_property_async(
|
|
|
|
result_generator, "GENERATED", "SOILPORVAsync", i
|
|
|
|
)
|
2019-05-31 03:17:44 -05:00
|
|
|
|
2019-08-15 01:07:43 -05:00
|
|
|
end = time.time()
|
|
|
|
print("Time elapsed: ", end - start)
|
2021-01-26 13:48:01 -06:00
|
|
|
|
2019-08-19 06:46:14 -05:00
|
|
|
print("Transferred all results back")
|
|
|
|
|
2021-01-26 13:48:01 -06:00
|
|
|
view = case.views()[0].apply_cell_result("GENERATED", "SOILPORVAsync")
|