#4550 Add python method to get simulation wells with status and cells info.

This commit is contained in:
Kristian Bendiksen
2020-02-11 21:20:53 +01:00
parent 2788c7a6c1
commit f7af2ed83e
12 changed files with 426 additions and 9 deletions

View File

@@ -0,0 +1,27 @@
###################################################################################
# This example will connect to ResInsight, retrieve a list of
# simulation wells and print info
###################################################################################
# Import the ResInsight Processing Server Module
import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
cases = resinsight.project.cases()
for case in cases:
print("Case id: " + str(case.case_id))
print("Case name: " + case.name)
timesteps = case.time_steps()
sim_wells = case.simulation_wells()
for sim_well in sim_wells:
print("Simulation well: " + sim_well.name)
for (tidx, timestep) in enumerate(timesteps):
status = sim_well.status(tidx)
cells = sim_well.cells(tidx)
print("timestep: " + str(tidx) + " type: " + status.well_type + " open: " + str(status.is_open) + " cells:" + str(len(cells)))

View File

@@ -17,12 +17,12 @@ import rips.generated.PdmObject_pb2 as PdmObject_pb2
import rips.generated.Properties_pb2 as Properties_pb2
import rips.generated.Properties_pb2_grpc as Properties_pb2_grpc
from rips.grid import Grid
from rips.pdmobject import PdmObject
from rips.view import View
from rips.contour_map import ContourMap, ContourMapType
from rips.well_bore_stability_plot import WellBoreStabilityPlot, WbsParameters
from rips.simulation_well import SimulationWell
class Case(PdmObject):
"""ResInsight case class
@@ -808,3 +808,15 @@ class Case(PdmObject):
res = self._execute_command(importFormationNames=Cmd.ImportFormationNamesRequest(formationFiles=formation_files,
applyToCaseId=self.case_id))
def simulation_wells(self):
"""Get a list of all simulation wells for a case
Returns:
A list of rips SimulationWell objects
"""
pdm_objects = self.descendants("Well")
wells = []
for pdm_object in pdm_objects:
wells.append(SimulationWell(pdm_object.get_value("WellName"), self.case_id, pdm_object))
return wells

View File

@@ -0,0 +1,39 @@
"""
ResInsight SimulationWell
"""
import grpc
import rips.generated.SimulationWell_pb2 as SimulationWell_pb2
import rips.generated.SimulationWell_pb2_grpc as SimulationWell_pb2_grpc
import rips.generated.Properties_pb2 as Properties_pb2
import rips.generated.Properties_pb2_grpc as Properties_pb2_grpc
import rips.generated.Commands_pb2 as Cmd
from rips.pdmobject import PdmObject
class SimulationWell(PdmObject):
"""ResInsight simulation well class
Attributes:
name(string): Name of the well.
"""
def __init__(self, name, case_id, pdm_object):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), pdm_object.project())
self._simulation_well_stub = SimulationWell_pb2_grpc.SimulationWellStub(pdm_object.channel())
self.name = name
self.case_id = case_id
def status(self, timestep):
sim_well_request = SimulationWell_pb2.SimulationWellRequest(case_id=self.case_id,
well_name=self.name,
timestep=timestep)
return self._simulation_well_stub.GetSimulationWellStatus(sim_well_request)
def cells(self, timestep):
sim_well_request = SimulationWell_pb2.SimulationWellRequest(case_id=self.case_id,
well_name=self.name,
timestep=timestep)
return self._simulation_well_stub.GetSimulationWellCells(sim_well_request).data

View File

@@ -0,0 +1,49 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
import dataroot
def test_10k(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(len(case.grids()) == 2)
cell_count_info = case.cell_count()
sim_wells = case.simulation_wells()
assert(len(sim_wells) == 3)
assert(sim_wells[0].name == "GI1")
assert(sim_wells[1].name == "GP1")
assert(sim_wells[2].name == "GP2")
timesteps = case.time_steps()
# On time step 0 all simulation wells are undefined
for sim_well in sim_wells:
status = sim_well.status(0)
assert(status.well_type == "NotDefined")
# On time step 3 all wells are producing
for sim_well in sim_wells:
status = sim_well.status(3)
assert(status.well_type == "Producer")
# On time step 0 all simulation wells have no cells
for sim_well in sim_wells:
cells = sim_well.cells(0)
assert(len(cells) == 0)
# On the other time steps there should be cells
expected_cell_count = {}
expected_cell_count["GP1"] = 105
expected_cell_count["GI1"] = 38
expected_cell_count["GP2"] = 18
for sim_well in sim_wells:
for (tidx, timestep) in enumerate(timesteps):
if (tidx > 0):
cells = sim_well.cells(tidx)
print("well: " + sim_well.name + " timestep: " + str(tidx) + " cells:" + str(len(cells)))
assert(len(cells) == expected_cell_count[sim_well.name])