mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4523 Add simplified interface for grid case group statistics
This commit is contained in:
parent
d9a0953b45
commit
21a444fd70
@ -37,6 +37,7 @@ CAF_PDM_SOURCE_INIT(RicfComputeCaseGroupStatistics, "computeCaseGroupStatistics"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfComputeCaseGroupStatistics::RicfComputeCaseGroupStatistics()
|
||||
{
|
||||
RICF_InitField(&m_groupId, "caseGroupId", -1, "Case Group ID", "", "", "");
|
||||
RICF_InitField(&m_caseIds, "caseIds", std::vector<int>(), "Case IDs", "", "", "");
|
||||
}
|
||||
|
||||
@ -47,7 +48,20 @@ RicfCommandResponse RicfComputeCaseGroupStatistics::execute()
|
||||
{
|
||||
RicfCommandResponse response;
|
||||
|
||||
for (int caseId : m_caseIds())
|
||||
std::vector<int> caseIds = m_caseIds.v();
|
||||
|
||||
if (m_groupId() >= 0)
|
||||
{
|
||||
for (RimIdenticalGridCaseGroup* group : RiaApplication::instance()->project()->activeOilField()->analysisModels()->caseGroups)
|
||||
{
|
||||
for (RimEclipseCase* c : group->statisticsCaseCollection->reservoirs)
|
||||
{
|
||||
caseIds.push_back(c->caseId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int caseId : caseIds)
|
||||
{
|
||||
bool foundCase = false;
|
||||
for (RimIdenticalGridCaseGroup* group : RiaApplication::instance()->project()->activeOilField()->analysisModels()->caseGroups)
|
||||
|
@ -37,5 +37,6 @@ public:
|
||||
RicfCommandResponse execute() override;
|
||||
|
||||
private:
|
||||
caf::PdmField< int > m_groupId;
|
||||
caf::PdmField< std::vector<int> > m_caseIds;
|
||||
};
|
||||
|
@ -162,6 +162,7 @@ if (PYTHON_EXECUTABLE)
|
||||
"rips/Case.py"
|
||||
"rips/Commands.py"
|
||||
"rips/Grid.py"
|
||||
"rips/GridCaseGroup.py"
|
||||
"rips/Project.py"
|
||||
"rips/Properties.py"
|
||||
"rips/Instance.py"
|
||||
|
@ -168,6 +168,7 @@ message SetMainWindowSizeParams
|
||||
message ComputeCaseGroupStatRequest
|
||||
{
|
||||
repeated int32 caseIds = 1;
|
||||
int32 caseGroupId = 2;
|
||||
}
|
||||
|
||||
message SetTimeStepParams
|
||||
|
@ -223,10 +223,9 @@ 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 computeCaseGroupStatistics(self, caseIds = [], caseGroupId = -1):
|
||||
return self.__execute(computeCaseGroupStatistics=Cmd.ComputeCaseGroupStatRequest(caseIds=caseIds,
|
||||
caseGroupId=caseGroupId))
|
||||
|
||||
def setTimeStep(self, caseId, timeStep):
|
||||
return self.__execute(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep))
|
||||
|
48
ApplicationCode/GrpcInterface/Python/rips/GridCaseGroup.py
Normal file
48
ApplicationCode/GrpcInterface/Python/rips/GridCaseGroup.py
Normal file
@ -0,0 +1,48 @@
|
||||
import grpc
|
||||
import os
|
||||
import sys
|
||||
from .PdmObject import PdmObject
|
||||
from .View import View
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||
|
||||
import PdmObject_pb2
|
||||
|
||||
class GridCaseGroup (PdmObject):
|
||||
"""ResInsight Grid Case Group class
|
||||
|
||||
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
|
||||
"""
|
||||
def __init__(self, pdmObject):
|
||||
self.groupId = pdmObject.getValue("GroupId")
|
||||
PdmObject.__init__(self, pdmObject.pb2Object, pdmObject.channel)
|
||||
|
||||
def statisticsCases(self):
|
||||
statCaseCollection = self.children("StatisticsCaseCollection")[0]
|
||||
return statCaseCollection.children("Reservoirs")
|
||||
|
||||
def views(self):
|
||||
"""Get a list of views belonging to a grid case group"""
|
||||
pbmObjects = self.descendants("ReservoirView")
|
||||
viewList = []
|
||||
for pbmObject in pbmObjects:
|
||||
viewList.append(View(pbmObject))
|
||||
return viewList
|
||||
|
||||
def view(self, id):
|
||||
"""Get a particular view belonging to a case group by providing view id
|
||||
Arguments:
|
||||
id(int): view id
|
||||
|
||||
Returns: a view object
|
||||
|
||||
"""
|
||||
views = self.views()
|
||||
for viewObject in views:
|
||||
if viewObject.id == id:
|
||||
return viewObject
|
||||
return None
|
@ -4,6 +4,7 @@ import sys
|
||||
|
||||
from .Case import Case
|
||||
from .Commands import Commands
|
||||
from .GridCaseGroup import GridCaseGroup
|
||||
from .PdmObject import PdmObject
|
||||
from .View import View
|
||||
|
||||
@ -113,4 +114,29 @@ class Project (PdmObject):
|
||||
for viewObject in views:
|
||||
if viewObject.id == id:
|
||||
return viewObject
|
||||
return None
|
||||
return None
|
||||
|
||||
def gridCaseGroups(self):
|
||||
caseGroups = self.descendants("RimIdenticalGridCaseGroup");
|
||||
|
||||
caseGroupList = []
|
||||
for pb2Group in caseGroups:
|
||||
caseGroupList.append(GridCaseGroup(pb2Group))
|
||||
return caseGroupList
|
||||
|
||||
def gridCaseGroup(self, groupId):
|
||||
"""Get a particular grid case group belonging to a project
|
||||
Arguments:
|
||||
groupId(int): group id
|
||||
|
||||
Returns: a grid case group object
|
||||
"""
|
||||
caseGroups = self.gridCaseGroups()
|
||||
for caseGroup in caseGroups:
|
||||
if caseGroup.groupId == groupId:
|
||||
return caseGroup
|
||||
return None
|
||||
|
||||
def createGridCaseGroup(self, casePaths):
|
||||
groupId, groupName = Commands(self.channel).createGridCaseGroup(casePaths)
|
||||
return self.gridCaseGroup(groupId)
|
@ -7,34 +7,26 @@ import rips
|
||||
resInsight = rips.Instance.find()
|
||||
|
||||
casePaths = []
|
||||
casePaths.append("../../../../TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID")
|
||||
casePaths.append("../../../../TestModels/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID")
|
||||
groupId, groupName = resInsight.commands.createGridCaseGroup(casePaths=casePaths)
|
||||
print("Group id = " + str(groupId))
|
||||
print("Group name = " + groupName)
|
||||
casePaths.append("C:/Users/lindkvis/Projects/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID")
|
||||
casePaths.append("C:/Users/lindkvis/Projects/ResInsight/TestModels/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID")
|
||||
for casePath in casePaths:
|
||||
assert os.path.exists(casePath), "You need to set valid case paths for this script to work"
|
||||
|
||||
caseId = resInsight.commands.createStatisticsCase(caseGroupId=groupId)
|
||||
caseGroup = resInsight.project.createGridCaseGroup(casePaths=casePaths)
|
||||
|
||||
caseGroups = resInsight.project.descendants("RimIdenticalGridCaseGroup");
|
||||
caseGroup.printObjectInfo()
|
||||
|
||||
#statCases = caseGroup.statisticsCases()
|
||||
#caseIds = []
|
||||
#for statCase in statCases:
|
||||
# statCase.setValue("DynamicPropertiesToCalculate", ["SWAT"])
|
||||
# statCase.update()
|
||||
# caseIds.append(statCase.getValue("CaseId"))
|
||||
|
||||
caseIds = []
|
||||
for caseGroup in caseGroups:
|
||||
print ("#### Case Group ####")
|
||||
for kw in caseGroup.keywords():
|
||||
print (kw, caseGroup.getValue(kw))
|
||||
resInsight.commands.computeCaseGroupStatistics(caseGroupId=caseGroup.groupId)
|
||||
|
||||
for caseCollection in caseGroup.children("StatisticsCaseCollection"):
|
||||
print (" ### Case Collection ###")
|
||||
statCases = caseCollection.children("Reservoirs")
|
||||
|
||||
for statCase in statCases:
|
||||
print(" ## Stat Case ##")
|
||||
for skw in statCase.keywords():
|
||||
print(" ", skw, statCase.getValue(skw))
|
||||
statCase.setValue("DynamicPropertiesToCalculate", statCase.getValue("DynamicPropertiesToCalculate") + ["SWAT"])
|
||||
statCase.update()
|
||||
caseIds.append(statCase.getValue("CaseId"))
|
||||
|
||||
print(caseIds)
|
||||
resInsight.commands.computeCaseGroupStatistics(caseIds=caseIds)
|
||||
view = caseGroup.views()[0]
|
||||
cellResult = view.cellResult()
|
||||
cellResult.setValue("ResultVariable", "PRESSURE_DEV")
|
||||
cellResult.update()
|
||||
|
Loading…
Reference in New Issue
Block a user