From a0d81a08e8a838524985ff46c4b8cca2a040fe23 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 5 Jun 2019 11:26:19 +0200 Subject: [PATCH] #4465 Implement all remaining command file commands and add tests for some commands --- .../GrpcInterface/CMakeLists.cmake | 3 + .../GrpcInterface/GrpcProtos/Commands.proto | 2 +- .../Python/examples/CommandExample.py | 9 ++- .../GrpcInterface/Python/rips/Commands.py | 77 ++++++++++++++++++- .../Python/tests/test_commands.py | 32 ++++++++ 5 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 ApplicationCode/GrpcInterface/Python/tests/test_commands.py diff --git a/ApplicationCode/GrpcInterface/CMakeLists.cmake b/ApplicationCode/GrpcInterface/CMakeLists.cmake index a555057fa6..1e810b7009 100644 --- a/ApplicationCode/GrpcInterface/CMakeLists.cmake +++ b/ApplicationCode/GrpcInterface/CMakeLists.cmake @@ -169,6 +169,9 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE}) "examples/SoilAverage.py" "examples/SoilAverageNoComm.py" "tests/test_cases.py" + "tests/test_commands.py" + "tests/test_grids.py" + "tests/test_properties.py" "tests/conftest.py" "tests/dataroot.py" "requirements.txt" diff --git a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto index 0f8f62a5fb..b44f72918d 100644 --- a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto +++ b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto @@ -83,7 +83,7 @@ enum CompdatExportType enum CompdatCombinationMode { INDIVIDUALLY = 0; - COMBINED = 1; + caCOMBINED = 1; } message ExportWellPathCompRequest diff --git a/ApplicationCode/GrpcInterface/Python/examples/CommandExample.py b/ApplicationCode/GrpcInterface/Python/examples/CommandExample.py index e45b9776fb..f9b6376641 100644 --- a/ApplicationCode/GrpcInterface/Python/examples/CommandExample.py +++ b/ApplicationCode/GrpcInterface/Python/examples/CommandExample.py @@ -14,6 +14,13 @@ resInsight.commands.setMainWindowSize(width=800, height=500) with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: print("Temporary folder: ", tmpdirname) resInsight.commands.setExportFolder(type='SNAPSHOTS', path=tmpdirname) + resInsight.commands.setExportFolder(type='PROPERTIES', path=tmpdirname) resInsight.commands.exportSnapshots() print(os.listdir(tmpdirname)) - assert(len(os.listdir(tmpdirname)) > 0) \ No newline at end of file + assert(len(os.listdir(tmpdirname)) > 0) + case = resInsight.project.case(id=0) + resInsight.commands.exportPropertyInViews(0, "3D View", 0) + expectedFileName = case.name + "-" + str("3D_View") + "-" + "T3" + "-SOIL" + fullPath = tmpdirname + "/" + expectedFileName + assert(os.path.exists(fullPath)) + diff --git a/ApplicationCode/GrpcInterface/Python/rips/Commands.py b/ApplicationCode/GrpcInterface/Python/rips/Commands.py index c0f6939834..e45bc4864b 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Commands.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Commands.py @@ -73,6 +73,35 @@ class Commands: viewNames=viewNames, undefinedValue=undefinedValue)) + def exportWellPathCompletions(self, caseId, timeStep, wellPathNames, fileSplit, + compdatExport, includePerforations, includeFishbones, + excludeMainBoreForFishbones, combinationMode): + if (isinstance(wellPathNames, str)): + wellPathNames = [wellPathNames] + return self.execute(exportWellPathCompletions=Cmd.ExportWellPathCompRequest(caseId=caseId, + timeStep=timeStep, + wellPathNames=wellPathNames, + fileSplit=fileSplit, + compdatExport=compdatExport, + includePerforations=includePerforations, + includeFishbones=includeFishbones, + excludeMainBoreForFishbones=excludeMainBoreForFishbones, + combinationMode=combinationMode)) + + def exportSimWellFractureCompletions(self, caseId, viewName, timeStep, simulationWellNames, fileSplit, compdatExport): + if(isinstance(simulationWellNames, str)): + simulationWellNames = [simulationWellNames] + return self.execute(exportSimWellFractureCompletions=Cmd.ExportSimWellPathFraqRequest(caseId=caseId, + viewName=viewName, + timeStep=timeStep, + simulationWellNames=simulationWellNames, + fileSplit=fileSplit, + compdatExport=compdatExport)) + + def exportMsw(self, caseId, wellPath): + return self.execute(exportMsw=Cmd.ExportMswRequest(caseId=caseId, + wellPath=wellPath)) + def exportWellPaths(self, wellPaths=[], mdStepSize=5.0): if isinstance(wellPaths, str): wellPaths = [wellpaths] @@ -100,7 +129,53 @@ class Commands: def setMainWindowSize(self, width, height): return self.execute(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)) + def computeCaseGroupStatistics(self, caseIds): + if isinstance(caseIds, int): + caseIds = [caseIds] + return self.execute(computeCaseGroupStatistics=Cmd.ComputeCaseGroupStatRequest(caseIds=caseIds)) + def setTimeStep(self, caseId, timeStep): return self.execute(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep)) - + + def scaleFractureTemplate(self, id, halfLength, height, dFactor, conductivity): + return self.execute(scaleFractureTemplate=Cmd.ScaleFractureTemplateRequest(id=id, + halfLength=halfLength, + height=height, + dFactor=dFactor, + conductivity=conductivity)) + + def setFractureContainment(self, id, topLayer, baseLayer): + return self.execute(setFractureContainment=Cmd.SetFracContainmentRequest(id=id, + topLayer=topLayer, + baseLayer=baseLayer)) + + def createMultipleFractures(self, caseId, templateId, wellPathNames, minDistFromWellTd, + maxFracturesPerWell, topLayer, baseLayer, spacing, action): + if isinstance(wellPathNames, str): + wellPathNames = [wellPathNames] + return self.execute(createMultipleFractures=Cmd.MultipleFracAction(caseId=caseId, + templateId=templateId, + wellPathNames=wellPathNames, + minDistFromWellTd=minDistFromWellTd, + maxFracturesPerWell=maxFracturesPerWell, + topLayer=topLayer, + baseLayer=baseLayer, + spacing=spacing, + action=action)) + + def createLgrForCompletions(self, caseId, timeStep, wellPathNames, refinementI, refinementJ, refinementK, splitType): + if isinstance(wellPathNames, str): + wellPathNames = [wellPathNames] + return self.execute(createLgrForCompletions=Cmd.CreateLgrForCompRequest(caseId=caseId, + timeStep=timeStep, + wellPathNames=wellPathNames, + refinementI=refinementI, + refinementJ=refinementJ, + refinementK=refinementK, + splitType=splitType)) + + def createSaturationPressurePlots(self, caseIds): + if isinstance(caseIds, int): + caseIds = [caseIds] + return self.execute(createSaturationPressurePlots=Cmd.CreateSatPressPlotRequest(caseIds=caseIds)) diff --git a/ApplicationCode/GrpcInterface/Python/tests/test_commands.py b/ApplicationCode/GrpcInterface/Python/tests/test_commands.py new file mode 100644 index 0000000000..ef65e34baf --- /dev/null +++ b/ApplicationCode/GrpcInterface/Python/tests/test_commands.py @@ -0,0 +1,32 @@ +import sys +import os +import tempfile + +sys.path.insert(1, os.path.join(sys.path[0], '..')) +import rips + +import dataroot + +def test_exportSnapshots(rips_instance, initializeTest): + casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" + rips_instance.project.loadCase(casePath) + with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: + print("Temporary folder: ", tmpdirname) + rips_instance.commands.setExportFolder(type='SNAPSHOTS', path=tmpdirname) + rips_instance.commands.exportSnapshots() + print(os.listdir(tmpdirname)) + assert(len(os.listdir(tmpdirname)) > 0) + for fileName in os.listdir(tmpdirname): + assert(os.path.splitext(fileName)[1] == '.png') + +def test_exportPropertyInView(rips_instance, initializeTest): + casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" + rips_instance.project.loadCase(casePath) + with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: + print("Temporary folder: ", tmpdirname) + rips_instance.commands.setExportFolder(type='PROPERTIES', path=tmpdirname) + case = rips_instance.project.case(id=0) + rips_instance.commands.exportPropertyInViews(0, "3D View", 0) + expectedFileName = case.name + "-" + str("3D_View") + "-" + "T0" + "-SOIL" + fullPath = tmpdirname + "/" + expectedFileName + assert(os.path.exists(fullPath)) \ No newline at end of file