mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-01 03:37:15 -06:00
Python: more examples + a comparable Octave Example
This commit is contained in:
parent
35059d1d67
commit
5379e95857
@ -0,0 +1,32 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
import itertools
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
resultChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
|
||||
|
||||
results = []
|
||||
for resultChunk in resultChunks:
|
||||
for value in resultChunk.values:
|
||||
results.append(value)
|
||||
|
||||
print("Transferred " + str(len(results)) + " poro results")
|
||||
|
||||
resultChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
|
||||
|
||||
permres = []
|
||||
for resultChunk in resultChunks:
|
||||
for value in resultChunk.values:
|
||||
permres.append(value)
|
||||
|
||||
print("Transferred " + str(len(permres)) + " permx results")
|
||||
poropermx = []
|
||||
for (poro, permx) in zip(results, permres):
|
||||
poropermx.append(poro * permx)
|
||||
|
||||
resInsight.properties.setActiveCellResults(poropermx, 0, 'GENERATED', 'PORO*PERMX2', 0)
|
@ -0,0 +1,22 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
import itertools
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
poroChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
|
||||
permxChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
|
||||
|
||||
results = []
|
||||
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
||||
print("Received chunks")
|
||||
for (poro, permx) in zip(poroChunk.values, permxChunk.values):
|
||||
results.append(poro * permx)
|
||||
|
||||
print("Transferred " + str(len(results)) + " poro and permx results")
|
||||
|
||||
resInsight.properties.setActiveCellResults(results, 0, 'GENERATED', 'PORO*PERMX2', 0)
|
29
ApplicationCode/GrpcInterface/Python/examples/SoilAverage.py
Normal file
29
ApplicationCode/GrpcInterface/Python/examples/SoilAverage.py
Normal file
@ -0,0 +1,29 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
import itertools
|
||||
import time
|
||||
|
||||
start = time.time()
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
case = resInsight.project.case(id=0)
|
||||
grid = case.grid(index = 0)
|
||||
|
||||
timeSteps = case.timeSteps()
|
||||
|
||||
averages = []
|
||||
for i in range(0, len(timeSteps)):
|
||||
resultChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
||||
mysum = 0.0
|
||||
count = 0
|
||||
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)
|
@ -0,0 +1,16 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
averages = []
|
||||
for i in range(0, 10):
|
||||
values = []
|
||||
|
||||
sum = 0.0
|
||||
count = 0
|
||||
for j in range(0, 1199516):
|
||||
sum += j
|
||||
count += 1
|
||||
|
||||
averages.append(sum / count)
|
||||
|
||||
print (averages)
|
@ -52,5 +52,5 @@ class Case:
|
||||
return self.stub.GetCellInfoForActiveCells(request)
|
||||
|
||||
def timeSteps(self):
|
||||
return self.stub.GetTimeSteps(self.request)
|
||||
return self.stub.GetTimeSteps(self.request).dates
|
||||
|
@ -111,6 +111,7 @@ class Properties:
|
||||
print("Command not found")
|
||||
else:
|
||||
print("Other error", e)
|
||||
|
||||
def setGridProperty(self, values, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
|
12
OctavePlugin/OctaveScripts/SoilAverage.m
Normal file
12
OctavePlugin/OctaveScripts/SoilAverage.m
Normal file
@ -0,0 +1,12 @@
|
||||
addpath("C:/cmake_build/ResInsightQt5/OctavePlugin");
|
||||
|
||||
tic();
|
||||
|
||||
timeSteps = riGetTimeStepDates(0)
|
||||
disp("Number of time steps: "), disp(size(timeSteps))
|
||||
for i = 1:size(timeSteps)
|
||||
SOIL = riGetActiveCellProperty(0, "SOIL", i);
|
||||
avg = mean(SOIL)
|
||||
endfor
|
||||
elapsed_time = toc();
|
||||
disp("Elapsed time: "), disp(elapsed_time)
|
Loading…
Reference in New Issue
Block a user