mirror of
https://github.com/OPM/ResInsight.git
synced 2024-12-29 10:21:54 -06:00
#4463 Added command for creating grid statistics
This commit is contained in:
parent
beb6256f53
commit
d9a0953b45
@ -30,6 +30,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateGridCaseGroup.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateStatisticsCase.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@ -63,6 +64,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateGridCaseGroup.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCreateStatisticsCase.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
@ -0,0 +1,77 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicfCreateStatisticsCase.h"
|
||||
|
||||
#include "RimCaseCollection.h"
|
||||
#include "RimEclipseStatisticsCase.h"
|
||||
#include "RimEclipseStatisticsCaseCollection.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicfCreateStatisticsCaseResult, "createStatisticsCaseResult");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCreateStatisticsCaseResult::RicfCreateStatisticsCaseResult(int caseId /*= -1*/)
|
||||
{
|
||||
CAF_PDM_InitObject("statistics_case_result", "", "", "");
|
||||
CAF_PDM_InitField(&this->caseId, "caseId", caseId, "", "", "", "");
|
||||
}
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RicfCreateStatisticsCase, "createStatisticsCase");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCreateStatisticsCase::RicfCreateStatisticsCase()
|
||||
{
|
||||
RICF_InitField(&m_caseGroupId, "caseGroupId", -1, "Case Group Id", "", "", "");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCommandResponse RicfCreateStatisticsCase::execute()
|
||||
{
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
|
||||
std::vector<RimIdenticalGridCaseGroup*> gridCaseGroups;
|
||||
project->descendantsIncludingThisOfType(gridCaseGroups);
|
||||
for (auto gridCaseGroup : gridCaseGroups)
|
||||
{
|
||||
if (gridCaseGroup->groupId() == m_caseGroupId())
|
||||
{
|
||||
RimEclipseStatisticsCase* createdObject = gridCaseGroup->createAndAppendStatisticsCase();
|
||||
project->assignCaseIdToCase(createdObject);
|
||||
gridCaseGroup->updateConnectedEditors();
|
||||
RicfCommandResponse response;
|
||||
response.setResult(new RicfCreateStatisticsCaseResult(createdObject->caseId()));
|
||||
return response;
|
||||
}
|
||||
}
|
||||
return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, "Could not find grid case group");
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
|
||||
class RicfCreateStatisticsCaseResult : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicfCreateStatisticsCaseResult(int caseId = -1);
|
||||
|
||||
public:
|
||||
caf::PdmField<int> caseId;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCreateStatisticsCase : public RicfCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicfCreateStatisticsCase();
|
||||
|
||||
RicfCommandResponse execute() override;
|
||||
|
||||
private:
|
||||
caf::PdmField<int> m_caseGroupId;
|
||||
};
|
@ -238,6 +238,11 @@ message CreateGridCaseGroupRequest
|
||||
repeated string casePaths = 1;
|
||||
}
|
||||
|
||||
message CreateStatisticsCaseRequest
|
||||
{
|
||||
int32 caseGroupId = 1;
|
||||
}
|
||||
|
||||
message ExportFlowInfoRequest
|
||||
{
|
||||
int32 caseId = 1;
|
||||
@ -287,7 +292,10 @@ message CommandParams
|
||||
CreateSatPressPlotRequest createSaturationPressurePlots = 25;
|
||||
ReplaceCaseRequests replaceMultipleCases = 26;
|
||||
CreateGridCaseGroupRequest createGridCaseGroup = 27;
|
||||
ExportFlowInfoRequest exportFlowCharacteristics = 28;
|
||||
CreateStatisticsCaseRequest createStatisticsCase = 28;
|
||||
ExportFlowInfoRequest exportFlowCharacteristics = 29;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,15 +305,21 @@ message GridCaseGroupResult
|
||||
string groupName = 2;
|
||||
}
|
||||
|
||||
message CreateStatisticsCaseResult
|
||||
{
|
||||
int32 caseId = 1;
|
||||
}
|
||||
|
||||
/* Command reply handles the return values for the generic command
|
||||
* The name of the variable is used to map to the cafPdmObject classKeyword */
|
||||
message CommandReply
|
||||
{
|
||||
oneof result
|
||||
{
|
||||
Empty emptyResult = 1;
|
||||
CaseRequest loadCaseResult = 2;
|
||||
GridCaseGroupResult createGridCaseGroupResult = 3;
|
||||
Empty emptyResult = 1;
|
||||
CaseRequest loadCaseResult = 2;
|
||||
GridCaseGroupResult createGridCaseGroupResult = 3;
|
||||
CreateStatisticsCaseResult createStatisticsCaseResult = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,16 +6,30 @@ package rips;
|
||||
|
||||
service PdmObjectService
|
||||
{
|
||||
rpc GetDescendantPdmObjects(PdmChildObjectRequest) returns (PdmObjectArray) {}
|
||||
rpc GetDescendantPdmObjects(PdmDescendantObjectRequest) returns (PdmObjectArray) {}
|
||||
rpc GetChildPdmObjects(PdmChildObjectRequest) returns (PdmObjectArray) {}
|
||||
rpc GetAncestorPdmObject(PdmParentObjectRequest) returns (PdmObject) {}
|
||||
rpc CreateChildPdmObject(CreatePdmChildObjectRequest) returns (PdmObject) {}
|
||||
rpc UpdateExistingPdmObject(PdmObject) returns (Empty) {}
|
||||
}
|
||||
|
||||
message PdmDescendantObjectRequest
|
||||
{
|
||||
PdmObject object = 1;
|
||||
string child_keyword = 2;
|
||||
}
|
||||
|
||||
message PdmChildObjectRequest
|
||||
{
|
||||
PdmObject object = 1;
|
||||
string child_keyword = 2;
|
||||
PdmObject object = 1;
|
||||
string child_field = 2;
|
||||
}
|
||||
|
||||
message CreatePdmChildObjectRequest
|
||||
{
|
||||
PdmObject object = 1;
|
||||
string child_field = 2;
|
||||
string child_class = 3;
|
||||
}
|
||||
|
||||
message PdmParentObjectRequest
|
||||
|
@ -111,6 +111,12 @@ class Commands:
|
||||
assert(commandReply.HasField("createGridCaseGroupResult"))
|
||||
return (commandReply.createGridCaseGroupResult.groupId, commandReply.createGridCaseGroupResult.groupName)
|
||||
|
||||
def createStatisticsCase(self, caseGroupId):
|
||||
commandReply = self.__execute(createStatisticsCase=Cmd.CreateStatisticsCaseRequest(caseGroupId=caseGroupId))
|
||||
assert(commandReply is not None)
|
||||
assert(commandReply.HasField("createStatisticsCaseResult"))
|
||||
return commandReply.createStatisticsCaseResult.caseId;
|
||||
|
||||
##################
|
||||
# Export Commands
|
||||
##################
|
||||
|
@ -81,15 +81,15 @@ class PdmObject:
|
||||
self.pb2Object.parameters[keyword] = self.__fromValue(value)
|
||||
|
||||
def descendants(self, classKeyword):
|
||||
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_keyword=classKeyword)
|
||||
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
|
||||
|
||||
def children(self, classKeyword):
|
||||
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_keyword=classKeyword)
|
||||
def children(self, childField):
|
||||
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_field=childField)
|
||||
objectList = self.pdmObjectStub.GetChildPdmObjects(request).objects
|
||||
childList = []
|
||||
for object in objectList:
|
||||
@ -102,3 +102,7 @@ class PdmObject:
|
||||
|
||||
def update(self):
|
||||
self.pdmObjectStub.UpdateExistingPdmObject(self.pb2Object)
|
||||
|
||||
# def createChild(self, childField, childClassKeyword):
|
||||
# childRequest = PdmObject_pb2.CreatePdmChildObjectRequest(object=self.pb2Object, child_field=childField, child_class=childClassKeyword)
|
||||
# return PdmObject(self.pdmObjectStub.CreateChildPdmObject(childRequest), self.channel)
|
||||
|
@ -13,15 +13,28 @@ groupId, groupName = resInsight.commands.createGridCaseGroup(casePaths=casePaths
|
||||
print("Group id = " + str(groupId))
|
||||
print("Group name = " + groupName)
|
||||
|
||||
caseId = resInsight.commands.createStatisticsCase(caseGroupId=groupId)
|
||||
|
||||
caseGroups = resInsight.project.descendants("RimIdenticalGridCaseGroup");
|
||||
|
||||
caseIds = []
|
||||
for caseGroup in caseGroups:
|
||||
print ("#### Case Group ####")
|
||||
for kw in caseGroup.keywords():
|
||||
print (kw, caseGroup.getValue(kw))
|
||||
statCases = caseGroup.descendants("RimStatisticalCalculation")
|
||||
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()
|
||||
|
||||
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)
|
||||
|
@ -65,8 +65,8 @@ grpc::Status RiaGrpcPdmObjectService::GetAncestorPdmObject(grpc::ServerContext*
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPdmObjectService::GetDescendantPdmObjects(grpc::ServerContext* context,
|
||||
const rips::PdmChildObjectRequest* request,
|
||||
rips::PdmObjectArray* reply)
|
||||
const rips::PdmDescendantObjectRequest* request,
|
||||
rips::PdmObjectArray* reply)
|
||||
{
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
std::vector<caf::PdmObject*> objectsOfCurrentClass;
|
||||
@ -119,14 +119,24 @@ grpc::Status RiaGrpcPdmObjectService::GetChildPdmObjects(grpc::ServerContext*
|
||||
|
||||
if (matchingObject)
|
||||
{
|
||||
std::vector<caf::PdmObject*> childObjects;
|
||||
matchingObject->childrenFromClassKeyword(QString::fromStdString(request->child_keyword()), childObjects);
|
||||
for (auto pdmChild : childObjects)
|
||||
QString fieldName = QString::fromStdString(request->child_field());
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
matchingObject->fields(fields);
|
||||
for (auto field : fields)
|
||||
{
|
||||
rips::PdmObject* ripsChild = reply->add_objects();
|
||||
copyPdmObjectFromCafToRips(pdmChild, ripsChild);
|
||||
if (field->keyword() == fieldName)
|
||||
{
|
||||
std::vector<caf::PdmObjectHandle*> childObjects;
|
||||
field->childObjects(&childObjects);
|
||||
for (auto pdmChild : childObjects)
|
||||
{
|
||||
rips::PdmObject* ripsChild = reply->add_objects();
|
||||
copyPdmObjectFromCafToRips(static_cast<caf::PdmObject*>(pdmChild), ripsChild);
|
||||
}
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
}
|
||||
return grpc::Status::OK;
|
||||
return grpc::Status(grpc::NOT_FOUND, "Child field not found");
|
||||
}
|
||||
return grpc::Status(grpc::NOT_FOUND, "Current PdmObject not found");
|
||||
}
|
||||
@ -173,6 +183,44 @@ grpc::Status RiaGrpcPdmObjectService::UpdateExistingPdmObject(grpc::ServerContex
|
||||
return grpc::Status(grpc::NOT_FOUND, "PdmObject not found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcPdmObjectService::CreateChildPdmObject(grpc::ServerContext* context,
|
||||
const rips::CreatePdmChildObjectRequest* request,
|
||||
rips::PdmObject* reply)
|
||||
{
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
std::vector<caf::PdmObject*> objectsOfCurrentClass;
|
||||
project->descendantsIncludingThisFromClassKeyword(QString::fromStdString(request->object().class_keyword()),
|
||||
objectsOfCurrentClass);
|
||||
|
||||
caf::PdmObject* matchingObject = nullptr;
|
||||
for (caf::PdmObject* testObject : objectsOfCurrentClass)
|
||||
{
|
||||
if (reinterpret_cast<uint64_t>(testObject) == request->object().address())
|
||||
{
|
||||
matchingObject = testObject;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchingObject)
|
||||
{
|
||||
CAF_ASSERT(request);
|
||||
|
||||
caf::PdmObject* pdmObject = emplaceChildArrayField(matchingObject,
|
||||
QString::fromStdString(request->child_field()),
|
||||
QString::fromStdString(request->child_class()));
|
||||
if (pdmObject)
|
||||
{
|
||||
copyPdmObjectFromCafToRips(pdmObject, reply);
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
return grpc::Status(grpc::NOT_FOUND, "Could not create PdmObject");
|
||||
}
|
||||
return grpc::Status(grpc::NOT_FOUND, "Could not find PdmObject");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -182,9 +230,10 @@ std::vector<RiaGrpcCallbackInterface*> RiaGrpcPdmObjectService::createCallbacks(
|
||||
return
|
||||
{
|
||||
new RiaGrpcUnaryCallback<Self, PdmParentObjectRequest, PdmObject>(this, &Self::GetAncestorPdmObject, &Self::RequestGetAncestorPdmObject),
|
||||
new RiaGrpcUnaryCallback<Self, PdmChildObjectRequest, PdmObjectArray>(this, &Self::GetDescendantPdmObjects, &Self::RequestGetDescendantPdmObjects),
|
||||
new RiaGrpcUnaryCallback<Self, PdmDescendantObjectRequest, PdmObjectArray>(this, &Self::GetDescendantPdmObjects, &Self::RequestGetDescendantPdmObjects),
|
||||
new RiaGrpcUnaryCallback<Self, PdmChildObjectRequest, PdmObjectArray>(this, &Self::GetChildPdmObjects, &Self::RequestGetChildPdmObjects),
|
||||
new RiaGrpcUnaryCallback<Self, PdmObject, Empty>(this, &Self::UpdateExistingPdmObject, &Self::RequestUpdateExistingPdmObject),
|
||||
new RiaGrpcUnaryCallback<Self, CreatePdmChildObjectRequest, PdmObject>(this, &Self::CreateChildPdmObject, &Self::RequestCreateChildPdmObject)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,16 @@ public:
|
||||
grpc::Status GetAncestorPdmObject(grpc::ServerContext* context,
|
||||
const rips::PdmParentObjectRequest* request,
|
||||
rips::PdmObject* reply) override;
|
||||
grpc::Status GetDescendantPdmObjects(grpc::ServerContext* context,
|
||||
const rips::PdmChildObjectRequest* request,
|
||||
rips::PdmObjectArray* reply);
|
||||
grpc::Status GetDescendantPdmObjects(grpc::ServerContext* context,
|
||||
const rips::PdmDescendantObjectRequest* request,
|
||||
rips::PdmObjectArray* reply) override;
|
||||
grpc::Status GetChildPdmObjects(grpc::ServerContext* context,
|
||||
const rips::PdmChildObjectRequest* request,
|
||||
rips::PdmObjectArray* reply);
|
||||
rips::PdmObjectArray* reply) override;
|
||||
|
||||
grpc::Status CreateChildPdmObject(grpc::ServerContext* context,
|
||||
const rips::CreatePdmChildObjectRequest* request,
|
||||
rips::PdmObject* reply) override;
|
||||
|
||||
grpc::Status
|
||||
UpdateExistingPdmObject(grpc::ServerContext* context, const rips::PdmObject* request, rips::Empty* response) override;
|
||||
|
@ -131,3 +131,37 @@ void RiaGrpcServiceInterface::assignFieldValue(const QString& stringValue, caf::
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObject* RiaGrpcServiceInterface::emplaceChildArrayField(caf::PdmObject* parent, const QString& fieldLabel, const QString& classKeyword)
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
parent->fields(fields);
|
||||
|
||||
QString childClassKeyword = classKeyword;
|
||||
|
||||
for (auto field : fields)
|
||||
{
|
||||
auto pdmChildArrayField = dynamic_cast<caf::PdmChildArrayFieldHandle*>(field);
|
||||
if (pdmChildArrayField && pdmChildArrayField->keyword() == fieldLabel)
|
||||
{
|
||||
if (childClassKeyword.isEmpty())
|
||||
{
|
||||
childClassKeyword = pdmChildArrayField->xmlCapability()->childClassKeyword();
|
||||
}
|
||||
|
||||
auto pdmObjectHandle =
|
||||
caf::PdmDefaultObjectFactory::instance()->create(childClassKeyword);
|
||||
caf::PdmObject* pdmObject = dynamic_cast<caf::PdmObject*>(pdmObjectHandle);
|
||||
CAF_ASSERT(pdmObject);
|
||||
if (pdmObject)
|
||||
{
|
||||
pdmChildArrayField->insertAt(-1, pdmObject);
|
||||
return pdmObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,8 @@ public:
|
||||
static void copyPdmObjectFromRipsToCaf(const rips::PdmObject* source, caf::PdmObject* destination);
|
||||
|
||||
static void assignFieldValue(const QString& stringValue, caf::PdmValueField* field);
|
||||
|
||||
static caf::PdmObject* emplaceChildArrayField(caf::PdmObject* parent, const QString& fieldLabel, const QString& classKeyword);
|
||||
};
|
||||
|
||||
#include "cafFactory.h"
|
||||
|
Loading…
Reference in New Issue
Block a user