This commit is contained in:
Gaute Lindkvist
2019-09-19 13:48:03 +02:00
parent 9bc2781817
commit 9a0f135431
7 changed files with 123 additions and 124 deletions

View File

@@ -48,7 +48,7 @@ class Case (PdmObject):
return 0
def grid_path(self):
return self.getValue("CaseFileName")
return self.get_value("CaseFileName")
def grid(self, index):
"""Get Grid of a given index. Returns a rips Grid object
@@ -132,9 +132,9 @@ class Case (PdmObject):
"""
active_cell_info_chunks = self.cell_info_for_active_cells_async()
received_active_cells = []
for activeCellChunk in active_cell_info_chunks:
for activeCell in activeCellChunk.data:
received_active_cells.append(activeCell)
for active_cell_chunk in active_cell_info_chunks:
for active_cell in active_cell_chunk.data:
received_active_cells.append(active_cell)
return received_active_cells
def time_steps(self):
@@ -162,10 +162,10 @@ class Case (PdmObject):
def views(self):
"""Get a list of views belonging to a case"""
pdm_objects = self.children("ReservoirViews")
viewList = []
view_list = []
for pdm_object in pdm_objects:
viewList.append(View(pdm_object))
return viewList
view_list.append(View(pdm_object))
return view_list
def view(self, id):
"""Get a particular view belonging to a case by providing view id

View File

@@ -14,11 +14,10 @@ class GridCaseGroup (PdmObject):
Operate on a ResInsight case group specified by a Case Group Id integer.
Attributes:
id (int): Grid Case Group Id corresponding to case group Id in ResInsight project.
name (str): Case name
group_id (int): Grid Case Group Id corresponding to case group Id in ResInsight project.
"""
def __init__(self, pdm_object):
self.groupId = pdm_object.getValue("GroupId")
self.group_id = pdm_object.get_value("GroupId")
PdmObject.__init__(self, pdm_object.pb2Object, pdm_object.channel)
def statistics_cases(self):
@@ -28,10 +27,10 @@ class GridCaseGroup (PdmObject):
def views(self):
"""Get a list of views belonging to a grid case group"""
pbm_objects = self.descendants("ReservoirView")
pdm_objects = self.descendants("ReservoirView")
view_list = []
for pbm_object in pbm_objects:
view_list.append(View(pbm_object))
for pdm_object in pdm_objects:
view_list.append(View(pdm_object))
return view_list
def view(self, id):

View File

@@ -9,10 +9,10 @@ import PdmObject_pb2
import PdmObject_pb2_grpc
class PdmObject:
def __init__(self, pb2Object, channel):
self.pb2Object = pb2Object
def __init__(self, pb2_object, channel):
self.pb2_object = pb2_object
self.channel = channel
self.pdmObjectStub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel)
self.pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel)
def address(self):
"""Get the unique address of the PdmObject
@@ -21,59 +21,59 @@ class PdmObject:
A 64-bit unsigned integer address
"""
return self.pb2Object.address
return self.pb2_object.address
def classKeyword(self):
def class_keyword(self):
"""Get the class keyword in the ResInsight Data Model for the given PdmObject"""
return self.pb2Object.class_keyword
return self.pb2_object.class_keyword
def keywords(self):
"""Get a list of all parameter keywords available in the object"""
listOfKeywords = []
for keyword in self.pb2Object.parameters:
listOfKeywords.append(keyword)
return listOfKeywords
list_of_keywords = []
for keyword in self.pb2_object.parameters:
list_of_keywords.append(keyword)
return list_of_keywords
def printObjectInfo(self):
def print_object_info(self):
"""Print the structure and data content of the PdmObject"""
print ("Class Keyword: " + self.classKeyword())
print ("Class Keyword: " + self.class_keyword())
for keyword in self.keywords():
print(keyword + " [" + type(self.getValue(keyword)).__name__ + "]: " + str(self.getValue(keyword)))
print(keyword + " [" + type(self.get_value(keyword)).__name__ + "]: " + str(self.get_value(keyword)))
def __toValue(self, value):
def __to_value(self, value):
if value.lower() == 'false':
return False
elif value.lower() == 'true':
return True
else:
try:
intVal = int(value)
return intVal
int_val = int(value)
return int_val
except ValueError:
try:
floatVal = float(value)
return floatVal
float_val = float(value)
return float_val
except ValueError:
# We may have a string. Strip internal start and end quotes
value = value.strip('\"')
if self.__islist(value):
return self.__makelist(value)
return value
def __fromValue(self, value):
def __from_value(self, value):
if isinstance(value, bool):
if value:
return "true"
else:
return "false"
elif isinstance(value, list):
listofstrings = []
list_of_strings = []
for val in value:
listofstrings.append(self.__fromValue('\"' + val + '\"'))
return "[" + ", ".join(listofstrings) + "]"
list_of_strings.append(self.__from_value('\"' + val + '\"'))
return "[" + ", ".join(list_of_strings) + "]"
else:
return str(value)
def getValue(self, keyword):
def get_value(self, keyword):
"""Get the value associated with the provided keyword
Arguments:
keyword(str): A string containing the parameter keyword
@@ -81,72 +81,72 @@ class PdmObject:
Returns:
The value of the parameter. Can be int, str or list.
"""
value = self.pb2Object.parameters[keyword]
return self.__toValue(value)
value = self.pb2_object.parameters[keyword]
return self.__to_value(value)
def __islist(self, value):
return value.startswith("[") and value.endswith("]")
def __makelist(self, liststring):
liststring = liststring.lstrip("[")
liststring = liststring.rstrip("]")
strings = liststring.split(", ")
def __makelist(self, list_string):
list_string = list_string.lstrip("[")
list_string = list_string.rstrip("]")
strings = list_string.split(", ")
values = []
for string in strings:
values.append(self.__toValue(string))
values.append(self.__to_value(string))
return values
def setValue(self, keyword, value):
def set_value(self, keyword, value):
"""Set the value associated with the provided keyword
Arguments:
keyword(str): A string containing the parameter keyword
value(varying): A value matching the type of the parameter.
See keyword documentation and/or printObjectInfo() to find
See keyword documentation and/or print_object_info() to find
the correct data type.
"""
self.pb2Object.parameters[keyword] = self.__fromValue(value)
self.pb2_object.parameters[keyword] = self.__from_value(value)
def descendants(self, classKeyword):
def descendants(self, class_keyword):
"""Get a list of all project tree descendants matching the class keyword
Arguments:
classKeyword[str]: A class keyword matching the type of class wanted
class_keyword[str]: A class keyword matching the type of class wanted
Returns:
A list of PdmObjects matching the keyword provided
"""
request = PdmObject_pb2.PdmDescendantObjectRequest(object=self.pb2Object, child_keyword=classKeyword)
objectList = self.pdmObjectStub.GetDescendantPdmObjects(request).objects
childList = []
for object in objectList:
childList.append(PdmObject(object, self.channel))
return childList
request = PdmObject_pb2.PdmDescendantObjectRequest(object=self.pb2_object, child_keyword=class_keyword)
object_list = self.pdm_object_stub.GetDescendantPdmObjects(request).objects
child_list = []
for object in object_list:
child_list.append(PdmObject(object, self.channel))
return child_list
def children(self, childField):
"""Get a list of all direct project tree children inside the provided childField
def children(self, child_field):
"""Get a list of all direct project tree children inside the provided child_field
Arguments:
childField[str]: A field name
child_field[str]: A field name
Returns:
A list of PdmObjects inside the childField
A list of PdmObjects inside the child_field
"""
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_field=childField)
objectList = self.pdmObjectStub.GetChildPdmObjects(request).objects
childList = []
for object in objectList:
childList.append(PdmObject(object, self.channel))
return childList
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2_object, child_field=child_field)
object_list = self.pdm_object_stub.GetChildPdmObjects(request).objects
child_list = []
for object in object_list:
child_list.append(PdmObject(object, self.channel))
return child_list
def ancestor(self, classKeyword):
"""Find the first ancestor that matches the provided classKeyword
def ancestor(self, class_keyword):
"""Find the first ancestor that matches the provided class_keyword
Arguments:
classKeyword[str]: A class keyword matching the type of class wanted
class_keyword[str]: A class keyword matching the type of class wanted
"""
request = PdmObject_pb2.PdmParentObjectRequest(object=self.pb2Object, parent_keyword=classKeyword)
return PdmObject(self.pdmObjectStub.GetAncestorPdmObject(request), self.channel)
request = PdmObject_pb2.PdmParentObjectRequest(object=self.pb2_object, parent_keyword=class_keyword)
return PdmObject(self.pdm_object_stub.GetAncestorPdmObject(request), self.channel)
def update(self):
"""Sync all fields from the Python Object to ResInsight"""
self.pdmObjectStub.UpdateExistingPdmObject(self.pb2Object)
self.pdm_object_stub.UpdateExistingPdmObject(self.pb2_object)
# def createChild(self, childField, childClassKeyword):
# childRequest = PdmObject_pb2.CreatePdmChildObjectRequest(object=self.pb2Object, child_field=childField, child_class=childClassKeyword)
# def createChild(self, child_field, childClassKeyword):
# childRequest = PdmObject_pb2.CreatePdmChildObjectRequest(object=self.pb2Object, child_field=child_field, child_class=childClassKeyword)
# return PdmObject(self.pdmObjectStub.CreateChildPdmObject(childRequest), self.channel)

View File

@@ -11,19 +11,19 @@ for casePath in casePaths:
caseGroup = resinsight.project.create_grid_case_group(casePaths=casePaths)
caseGroup.printObjectInfo()
caseGroup.print_object_info()
#statCases = caseGroup.statistics_cases()
#caseIds = []
#for statCase in statCases:
# statCase.setValue("DynamicPropertiesToCalculate", ["SWAT"])
# statCase.set_value("DynamicPropertiesToCalculate", ["SWAT"])
# statCase.update()
# caseIds.append(statCase.getValue("CaseId"))
# caseIds.append(statCase.get_value("CaseId"))
resinsight.commands.compute_case_group_statistics(caseGroupId=caseGroup.groupId)
view = caseGroup.views()[0]
cellResult = view.cellResult()
cellResult.setValue("ResultVariable", "PRESSURE_DEV")
cellResult.set_value("ResultVariable", "PRESSURE_DEV")
cellResult.update()

View File

@@ -10,25 +10,25 @@ class View (PdmObject):
"""
def __init__(self, pbmObject):
self.id = pbmObject.getValue("ViewId")
self.id = pbmObject.get_value("ViewId")
PdmObject.__init__(self, pbmObject.pb2Object, pbmObject.channel)
def showGridBox(self):
"""Check if the grid box is meant to be shown in the view"""
return self.getValue("ShowGridBox")
return self.get_value("ShowGridBox")
def setShowGridBox(self, value):
"""Set if the grid box is meant to be shown in the view"""
self.setValue("ShowGridBox", value)
self.set_value("ShowGridBox", value)
def backgroundColor(self):
"""Get the current background color in the view"""
return self.getValue("ViewBackgroundColor")
return self.get_value("ViewBackgroundColor")
def setBackgroundColor(self, bgColor):
"""Set the background color in the view"""
self.setValue("ViewBackgroundColor", bgColor)
self.set_value("ViewBackgroundColor", bgColor)
def cellResult(self):
"""Retrieve the current cell results"""
@@ -50,8 +50,8 @@ class View (PdmObject):
resultVariable (str): String representing the result variable.
"""
cellResult = self.cellResult()
cellResult.setValue("ResultType", resultType)
cellResult.setValue("ResultVariable", resultVariable)
cellResult.set_value("ResultType", resultType)
cellResult.set_value("ResultVariable", resultVariable)
cellResult.update()
def applyFlowDiagnosticsCellResult(self,
@@ -77,12 +77,12 @@ class View (PdmObject):
Requires selectionMode to be 'FLOW_TR_BY_SELECTION'.
"""
cellResult = self.cellResult()
cellResult.setValue("ResultType", "FLOW_DIAGNOSTICS")
cellResult.setValue("ResultVariable", resultVariable)
cellResult.setValue("FlowTracerSelectionMode", selectionMode)
cellResult.set_value("ResultType", "FLOW_DIAGNOSTICS")
cellResult.set_value("ResultVariable", resultVariable)
cellResult.set_value("FlowTracerSelectionMode", selectionMode)
if selectionMode == 'FLOW_TR_BY_SELECTION':
cellResult.setValue("SelectedInjectorTracers", injectors)
cellResult.setValue("SelectedProducerTracers", producers)
cellResult.set_value("SelectedInjectorTracers", injectors)
cellResult.set_value("SelectedProducerTracers", producers)
cellResult.update()
def case(self):
@@ -92,7 +92,7 @@ class View (PdmObject):
pdmCase = self.ancestor("ResInsightGeoMechCase")
if pdmCase is None:
return None
return rips.Case(self.channel, pdmCase.getValue("CaseId"))
return rips.Case(self.channel, pdmCase.get_value("CaseId"))
def clone(self):
"""Clone the current view"""

View File

@@ -22,60 +22,60 @@ def test_OneCase(rips_instance, initialize_test):
assert(len(cases) is 1)
def test_MultipleCases(rips_instance, initialize_test):
casePaths = []
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
case_paths = []
case_paths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
case_paths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
case_paths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
caseNames = []
for casePath in casePaths:
caseName = os.path.splitext(os.path.basename(casePath))[0]
caseNames.append(caseName)
rips_instance.project.load_case(path=casePath)
case_names = []
for case_path in case_paths:
case_name = os.path.splitext(os.path.basename(case_path))[0]
case_names.append(case_name)
rips_instance.project.load_case(path=case_path)
cases = rips_instance.project.cases()
assert(len(cases) == len(caseNames))
for i, caseName in enumerate(caseNames):
assert(caseName == cases[i].name)
assert(len(cases) == len(case_names))
for i, case_name in enumerate(case_names):
assert(case_name == cases[i].name)
def test_10k(rips_instance, initialize_test):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath)
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.grid_count() == 2)
cellCountInfo = case.cell_count()
assert(cellCountInfo.active_cell_count == 11125)
assert(cellCountInfo.reservoir_cell_count == 316224)
timeSteps = case.time_steps()
assert(len(timeSteps) == 9)
daysSinceStart = case.days_since_start()
assert(len(daysSinceStart) == 9)
cell_count_info = case.cell_count()
assert(cell_count_info.active_cell_count == 11125)
assert(cell_count_info.reservoir_cell_count == 316224)
time_steps = case.time_steps()
assert(len(time_steps) == 9)
days_since_start = case.days_since_start()
assert(len(days_since_start) == 9)
def test_PdmObject(rips_instance, initialize_test):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath)
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.id == 0)
assert(case.address() is not 0)
assert(case.classKeyword() == "EclipseCase")
caseId = case.getValue('CaseId')
assert(caseId == case.id)
assert(case.class_keyword() == "EclipseCase")
case_id = case.get_value('CaseId')
assert(case_id == case.id)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_brugge_0010(rips_instance, initialize_test):
casePath = dataroot.PATH + "/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID"
case = rips_instance.project.load_case(path=casePath)
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.grid_count() == 1)
cellCountInfo = case.cell_count()
assert(cellCountInfo.active_cell_count == 43374)
assert(cellCountInfo.reservoir_cell_count == 60048)
timeSteps = case.time_steps()
assert(len(timeSteps) == 11)
daysSinceStart = case.days_since_start()
assert(len(daysSinceStart) == 11)
time_steps = case.time_steps()
assert(len(time_steps) == 11)
days_since_start = case.days_since_start()
assert(len(days_since_start) == 11)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_replaceCase(rips_instance, initialize_test):
project = rips_instance.project.open(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp")
casePath = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
case = project.case(id=0)
assert(case is not None)
assert(case.name == "TEST10K_FLT_LGR_NNC")
@@ -83,7 +83,7 @@ def test_replaceCase(rips_instance, initialize_test):
cases = rips_instance.project.cases()
assert(len(cases) is 1)
rips_instance.commands.replace_case(newGridFile=casePath, caseId=case.id)
rips_instance.commands.replace_case(new_grid_file=case_path, case_id=case.id)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
case = project.case(id=0)

View File

@@ -10,7 +10,7 @@ import rips
import dataroot
def test_exportSnapshots(rips_instance, initialize_test):
if not rips_instance.isGui():
if not rips_instance.is_gui():
pytest.skip("Cannot run test without a GUI")
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"