2019-08-19 13:46:14 +02:00
|
|
|
###########################################################################################
|
|
|
|
|
# This example will asynchronously calculate the average value for SOIL for all time steps
|
|
|
|
|
###########################################################################################
|
|
|
|
|
|
2019-06-04 08:43:57 +02:00
|
|
|
import rips
|
|
|
|
|
import itertools
|
|
|
|
|
import time
|
|
|
|
|
|
2019-09-19 13:25:04 +02:00
|
|
|
resinsight = rips.Instance.find()
|
2019-06-04 10:34:31 +02:00
|
|
|
|
|
|
|
|
start = time.time()
|
2019-08-19 13:46:14 +02:00
|
|
|
|
|
|
|
|
# Get the case with case id 0
|
2019-09-19 13:25:04 +02:00
|
|
|
case = resinsight.project.case(id=0)
|
2019-06-04 08:43:57 +02:00
|
|
|
|
2019-08-19 13:46:14 +02:00
|
|
|
# Get a list of all time steps
|
2019-09-19 11:14:40 +02:00
|
|
|
timeSteps = case.time_steps()
|
2019-06-04 08:43:57 +02:00
|
|
|
|
|
|
|
|
averages = []
|
2019-06-06 09:13:23 +02:00
|
|
|
for i in range(0, len(timeSteps)):
|
2019-08-19 13:46:14 +02:00
|
|
|
# Get the results from time step i asynchronously
|
|
|
|
|
# It actually returns a generator object almost immediately
|
2019-09-19 14:25:38 +02:00
|
|
|
resultChunks = case.properties.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i)
|
2019-06-04 08:43:57 +02:00
|
|
|
mysum = 0.0
|
|
|
|
|
count = 0
|
2019-08-19 13:46:14 +02:00
|
|
|
# Loop through and append the average. each time we loop resultChunks
|
|
|
|
|
# We will trigger a read of the input data, meaning the script will start
|
|
|
|
|
# Calculating averages before the whole resultValue for this time step has been received
|
2019-06-04 08:43:57 +02:00
|
|
|
for chunk in resultChunks:
|
|
|
|
|
mysum += sum(chunk.values)
|
|
|
|
|
count += len(chunk.values)
|
|
|
|
|
|
|
|
|
|
averages.append(mysum/count)
|
|
|
|
|
|
|
|
|
|
end = time.time()
|
|
|
|
|
print("Time elapsed: ", end - start)
|
|
|
|
|
print(averages)
|