#4547 Add simplified synchronous methods for activeCellProperty and gridProperty

This commit is contained in:
Gaute Lindkvist 2019-08-07 23:33:08 +02:00
parent 136251c4b1
commit 0a30e6c340
10 changed files with 99 additions and 72 deletions

View File

@ -182,7 +182,8 @@ if (PYTHON_EXECUTABLE)
"rips/examples/GridInformation.py"
"rips/examples/InputPropTestSync.py"
"rips/examples/InputPropTestAsync.py"
"rips/examples/SoilAverage.py"
"rips/examples/SoilAverageAsync.py"
"rips/examples/SoilAverageSync.py"
"rips/examples/SoilAverageNoComm.py"
"rips/tests/test_cases.py"
"rips/tests/test_commands.py"

View File

@ -78,7 +78,7 @@ class Properties:
porosity_model = porosityModelEnum)
return self.propertiesStub.GetAvailableProperties(request).property_names
def activeCellProperty(self, propertyType, propertyName, timeStep, porosityModel = 'MATRIX_MODEL'):
def activeCellPropertyAsync(self, propertyType, propertyName, timeStep, porosityModel = 'MATRIX_MODEL'):
"""Get a cell property for all active cells. Async, so returns an iterator
Arguments:
@ -101,7 +101,27 @@ class Properties:
for chunk in self.propertiesStub.GetActiveCellProperty(request):
yield chunk
def gridProperty(self, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
def activeCellProperty(self, propertyType, propertyName, timeStep, porosityModel = 'MATRIX_MODEL'):
"""Get a cell property for all active cells. Sync, so returns a list
Arguments:
propertyType(str): string enum. See available()
propertyName(str): name of an Eclipse property
timeStep(int): the time step for which to get the property for
porosityModel(str): string enum. See available()
Returns:
A list containing double values
You first loop through the chunks and then the values within the chunk to get all values.
"""
allValues = []
generator = self.activeCellPropertyAsync(propertyType, propertyName, timeStep, porosityModel)
for chunk in generator:
for value in chunk.values:
allValues.append(value)
return allValues
def gridPropertyAsync(self, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
"""Get a cell property for all grid cells. Async, so returns an iterator
Arguments:
@ -126,6 +146,26 @@ class Properties:
for chunk in self.propertiesStub.GetGridProperty(request):
yield chunk
def gridProperty(self, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
"""Get a cell property for all grid cells. Synchronous, so returns a list
Arguments:
propertyType(str): string enum. See available()
propertyName(str): name of an Eclipse property
timeStep(int): the time step for which to get the property for
gridIndex(int): index to the grid we're getting values for
porosityModel(str): string enum. See available()
Returns:
A list of double values
"""
allValues = []
generator = self.gridPropertyAsync(propertyType, propertyName, timeStep, gridIndex, porosityModel)
for chunk in generator:
for value in chunk.values:
allValues.append(value)
return allValues
def setActiveCellPropertyAsync(self, values_iterator, propertyType, propertyName, timeStep, porosityModel = 'MATRIX_MODEL'):
"""Set a cell property for all active cells. Async, and so takes an iterator to the input values

View File

@ -11,36 +11,8 @@ if resInsight is not None:
print ("Got " + str(len(cases)) + " cases: ")
for case in cases:
print(case.name)
assert(case.address() is not 0)
assert(case.classKeyword() == "EclipseCase")
print("\n#### Case ####")
for keyword in case.keywords():
print (keyword + ": " + str(case.getValue(keyword)))
print ("\n####Project#####")
pdmProject = case.ancestor(classKeyword="ResInsightProject")
assert(pdmProject)
assert(pdmProject.address() is not 0)
assert(pdmProject.address() == resInsight.project.address())
for keyword in resInsight.project.keywords():
print (keyword + ": " + str(resInsight.project.getValue(keyword)))
pdmViews = resInsight.project.views()
for view in pdmViews:
print ("\n####View####")
print(view.classKeyword(), view.address())
for viewKeyword in view.keywords():
print(viewKeyword + "-> " + str(view.getValue(viewKeyword)))
views = case.views()
for view in views:
view.setShowGridBox(not view.showGridBox())
view.setBackgroundColor("#3388AA")
view.update()
print ("\n####Cell Result####")
firstView = case.view(id=0)
assert(firstView is not None)
cellResult = firstView.cellResult()
print(cellResult.classKeyword(), cellResult.address())
for resultKeyword in cellResult.keywords():
print(resultKeyword + "->" + str(cellResult.getValue(resultKeyword)))
cellResult.setValue("ResultVariable", "SOIL")
cellResult.setValue("ResultType", "DYNAMIC_NATIVE")
cellResult.update()

View File

@ -16,8 +16,8 @@ resInsight = rips.Instance.find()
start = time.time()
case = resInsight.project.case(id=0)
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
poroChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PORO', 0)
permxChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PERMX', 0)
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks),
'GENERATED', 'POROPERMXAS', 0)

View File

@ -9,17 +9,8 @@ resInsight = rips.Instance.find()
start = time.time()
case = resInsight.project.case(id=0)
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
poroResults = []
for poroChunk in poroChunks:
for poro in poroChunk.values:
poroResults.append(poro)
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
permxResults = []
for permxChunk in permxChunks:
for permx in permxChunk.values:
permxResults.append(permx)
poroResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
permxResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
results = []
for (poro, permx) in zip(poroResults, permxResults):
@ -29,5 +20,4 @@ case.properties.setActiveCellProperty(results, 'GENERATED', 'POROPERMXSY', 0)
end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")

View File

@ -15,7 +15,7 @@ timeSteps = case.timeSteps()
averages = []
for i in range(0, len(timeSteps)):
resultChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
resultChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', i)
mysum = 0.0
count = 0
for chunk in resultChunks:

View File

@ -0,0 +1,24 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
import itertools
import time
resInsight = rips.Instance.find()
start = time.time()
case = resInsight.project.case(id=0)
grid = case.grid(index = 0)
timeSteps = case.timeSteps()
averages = []
for i in range(0, len(timeSteps)):
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
mysum = sum(results)
averages.append(mysum/len(results))
end = time.time()
print("Time elapsed: ", end - start)
print(averages)

View File

@ -18,13 +18,13 @@ resInsight = rips.Instance.find()
case = resInsight.project.case(id=0)
timeStepInfo = case.timeSteps()
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
porvChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PORV', 0)
porvArray = []
for porvChunk in porvChunks:
porvArray.append(porvChunk)
for i in range (0, len(timeStepInfo)):
soilChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
soilChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', i)
input_iterator = createResult(soilChunks, iter(porvArray))
case.properties.setActiveCellPropertyAsync(input_iterator, 'GENERATED', 'SOILPORVAsync', i)

View File

@ -6,20 +6,11 @@ import rips
resInsight = rips.Instance.find()
case = resInsight.project.case(id=0)
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
porvResults = []
for porvChunk in porvChunks:
for porv in porvChunk.values:
porvResults.append(porv)
porvResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
timeStepInfo = case.timeSteps()
for i in range (0, len(timeStepInfo)):
soilChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
soilResults = []
for soilChunk in soilChunks:
for soil in soilChunk.values:
soilResults.append(soil)
soilResults = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
results = []
for (soil, porv) in zip(soilResults, porvResults):
results.append(soil * porv)

View File

@ -7,11 +7,11 @@ import rips
import dataroot
def test_10k(rips_instance, initializeTest):
def test_10kAsync(rips_instance, initializeTest):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.loadCase(path=casePath)
resultChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', 1)
resultChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', 1)
mysum = 0.0
count = 0
for chunk in resultChunks:
@ -22,6 +22,16 @@ def test_10k(rips_instance, initializeTest):
assert(average != pytest.approx(0.0158893, abs=0.0000001))
assert(average == pytest.approx(0.0558893, abs=0.0000001))
def test_10kSync(rips_instance, initializeTest):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.loadCase(path=casePath)
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', 1)
mysum = sum(results)
average = mysum / len(results)
assert(mysum == pytest.approx(621.768, abs=0.001))
assert(average != pytest.approx(0.0158893, abs=0.0000001))
assert(average == pytest.approx(0.0558893, abs=0.0000001))
def createResult(poroChunks, permxChunks):
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
@ -30,9 +40,8 @@ def createResult(poroChunks, permxChunks):
resultChunk.append(poro * permx)
yield resultChunk
def checkResults(poroChunks, permxChunks, poroPermXChunks):
for (poroChunk, permxChunk, poroPermXChunk) in zip(poroChunks, permxChunks, poroPermXChunks):
for (poro, permx, poropermx) in zip(poroChunk.values, permxChunk.values, poroPermXChunk.values):
def checkResults(poroValues, permxValues, poropermxValues):
for (poro, permx, poropermx) in zip(poroValues, permxValues, poropermxValues):
recalc = poro * permx
assert(recalc == pytest.approx(poropermx, rel=1.0e-10))
@ -40,16 +49,16 @@ def test_10k_PoroPermX(rips_instance, initializeTest):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.loadCase(path=casePath)
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
poroChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PORO', 0)
permxChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PERMX', 0)
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks), 'GENERATED', 'POROPERMXAS', 0)
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
poroPermXChunks = case.properties.activeCellProperty('GENERATED', 'POROPERMXAS', 0)
poro = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
permx = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
poroPermX = case.properties.activeCellProperty('GENERATED', 'POROPERMXAS', 0)
checkResults(poroChunks, permxChunks, poroPermXChunks)
checkResults(poro, permx, poroPermX)