mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Minor gRPC updates
This commit is contained in:
@@ -9,6 +9,7 @@ service GridInfo
|
||||
// This function returns a two dimensional matrix: One row for each grid, starting with the main grid.
|
||||
rpc GetGridCount(Case) returns(GridCount) {}
|
||||
rpc GetGridDimensions(Case) returns (GridDimensions) {}
|
||||
rpc GetCellCount(CellInfoRequest) returns (CellCount) {}
|
||||
rpc GetCellInfoForActiveCells(CellInfoRequest) returns (stream CellInfoArray) {}
|
||||
rpc GetAllCoarseningInfoArray(Case) returns (CoarseningInfoArray) {}
|
||||
rpc GetTimeSteps(Case) returns (TimeStepDates) {}
|
||||
@@ -31,6 +32,12 @@ message Vec3i {
|
||||
int32 k = 3;
|
||||
}
|
||||
|
||||
message CellCount
|
||||
{
|
||||
int32 active_cell_count = 1;
|
||||
int32 reservoir_cell_count = 2;
|
||||
}
|
||||
|
||||
enum PorosityModelType
|
||||
{
|
||||
MATRIX_MODEL = 0;
|
||||
|
||||
@@ -255,6 +255,53 @@ grpc::Status RiaGrpcGridInfoService::GetGridDimensions(grpc::ServerContext*
|
||||
return grpc::Status(grpc::NOT_FOUND, "Eclipse Case not found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status RiaGrpcGridInfoService::GetCellCount(grpc::ServerContext* context, const rips::CellInfoRequest* request, rips::CellCount* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->case_id());
|
||||
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(rimCase);
|
||||
if (eclipseCase)
|
||||
{
|
||||
auto porosityModel = RiaDefines::PorosityModelType(request->porosity_model());
|
||||
RigActiveCellInfo* activeCellInfo = eclipseCase->eclipseCaseData()->activeCellInfo(porosityModel);
|
||||
reply->set_active_cell_count((int) activeCellInfo->reservoirActiveCellCount());
|
||||
reply->set_reservoir_cell_count((int) activeCellInfo->reservoirCellCount());
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
return grpc::Status(grpc::NOT_FOUND, "Eclipse Case not found");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
grpc::Status
|
||||
RiaGrpcGridInfoService::GetTimeSteps(grpc::ServerContext* context, const rips::Case* request, rips::TimeStepDates* reply)
|
||||
{
|
||||
RimCase* rimCase = findCase(request->id());
|
||||
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(rimCase);
|
||||
if (eclipseCase)
|
||||
{
|
||||
std::vector<QDateTime> timeStepDates = eclipseCase->timeStepDates();
|
||||
for (QDateTime dateTime : timeStepDates)
|
||||
{
|
||||
rips::TimeStepDate* date = reply->add_date();
|
||||
date->set_year(dateTime.date().year());
|
||||
date->set_month(dateTime.date().month());
|
||||
date->set_day(dateTime.date().day());
|
||||
date->set_hour(dateTime.time().hour());
|
||||
date->set_minute(dateTime.time().minute());
|
||||
date->set_second(dateTime.time().second());
|
||||
}
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
return grpc::Status(grpc::NOT_FOUND, "Eclipse Case not found");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -275,6 +322,8 @@ std::vector<RiaAbstractGrpcCallback*> RiaGrpcGridInfoService::createCallbacks()
|
||||
|
||||
return {new RiaGrpcCallback<Self, Case, GridCount>(this, &Self::GetGridCount, &Self::RequestGetGridCount),
|
||||
new RiaGrpcCallback<Self, Case, GridDimensions>(this, &Self::GetGridDimensions, &Self::RequestGetGridDimensions),
|
||||
new RiaGrpcCallback<Self, CellInfoRequest, CellCount>(this, &Self::GetCellCount, &Self::RequestGetCellCount),
|
||||
new RiaGrpcCallback<Self, Case, TimeStepDates>(this, &Self::GetTimeSteps, &Self::RequestGetTimeSteps),
|
||||
new RiaGrpcStreamCallback<Self, CellInfoRequest, CellInfoArray, RiaActiveCellInfoStateHandler>(
|
||||
this, &Self::GetCellInfoForActiveCells, &Self::RequestGetCellInfoForActiveCells, new RiaActiveCellInfoStateHandler)};
|
||||
}
|
||||
|
||||
@@ -71,9 +71,12 @@ class RiaGrpcGridInfoService final : public rips::GridInfo::AsyncService, public
|
||||
public:
|
||||
grpc::Status GetGridCount(grpc::ServerContext* context, const rips::Case* request, rips::GridCount* reply) override;
|
||||
grpc::Status GetGridDimensions(grpc::ServerContext* context, const rips::Case* request, rips::GridDimensions* reply) override;
|
||||
grpc::Status GetCellCount(grpc::ServerContext* context, const rips::CellInfoRequest* request, rips::CellCount* reply) override;
|
||||
grpc::Status GetTimeSteps(grpc::ServerContext* context, const rips::Case* request, rips::TimeStepDates* reply) override;
|
||||
|
||||
grpc::Status GetCellInfoForActiveCells(grpc::ServerContext* context,
|
||||
const rips::CellInfoRequest* request,
|
||||
rips::CellInfoArray* reply,
|
||||
RiaActiveCellInfoStateHandler* stateHandler);
|
||||
RiaActiveCellInfoStateHandler* stateHandler);
|
||||
std::vector<RiaAbstractGrpcCallback*> createCallbacks() override;
|
||||
};
|
||||
|
||||
@@ -76,9 +76,21 @@ class GridInfo:
|
||||
def gridDimensions(self, caseId=0):
|
||||
return self.gridInfo.GetGridDimensions(CaseInfo_pb2.Case(id=caseId)).dimensions
|
||||
|
||||
def cellInfoForActiveCells(self, caseId=0):
|
||||
return self.gridInfo.GetCellInfoForActiveCells(CaseInfo_pb2.Case(id=caseId))
|
||||
|
||||
def cellCount(self, caseId=0, porosityModel='MATRIX_MODEL'):
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = GridInfo_pb2.CellInfoRequest(case_id=caseId,
|
||||
porosity_model=porosityModel)
|
||||
return self.gridInfo.GetCellCount(request)
|
||||
|
||||
def cellInfoForActiveCells(self, caseId=0, porosityModel='MATRIX_MODEL'):
|
||||
porosityModelEnum = GridInfo_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = GridInfo_pb2.CellInfoRequest(case_id=caseId,
|
||||
porosity_model=porosityModel)
|
||||
return self.gridInfo.GetCellInfoForActiveCells(request)
|
||||
|
||||
def timeSteps(self, caseId=0):
|
||||
return self.gridInfo.GetTimeSteps(CaseInfo_pb2.Case(id=caseId))
|
||||
|
||||
class ProjectInfo:
|
||||
def __init__(self, channel):
|
||||
self.projectInfo = ProjectInfo_pb2_grpc.ProjectInfoStub(channel)
|
||||
|
||||
@@ -7,6 +7,9 @@ resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
cellCounts = resInsight.gridInfo.cellCount(caseId=0)
|
||||
print("Number of active cells: " + str(cellCounts.active_cell_count))
|
||||
|
||||
activeCellInfoChunks = resInsight.gridInfo.cellInfoForActiveCells(caseId=0)
|
||||
|
||||
#print("Number of grids: " + str(gridCount))
|
||||
@@ -16,6 +19,7 @@ receivedActiveCells = []
|
||||
for activeCellChunk in activeCellInfoChunks:
|
||||
for activeCell in activeCellChunk.data:
|
||||
receivedActiveCells.append(activeCell)
|
||||
print("Number of active cells: " + str(len(receivedActiveCells)))
|
||||
|
||||
assert(cellCounts.active_cell_count == len(receivedActiveCells))
|
||||
print("First active cell: ")
|
||||
print(receivedActiveCells[0])
|
||||
|
||||
@@ -4,13 +4,16 @@ sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
|
||||
activeCellCount = resInsight.gridInfo.cellCount(caseId=0).active_cell_count
|
||||
|
||||
values = []
|
||||
for i in range(0, 11124):
|
||||
for i in range(0, activeCellCount):
|
||||
values.append(i % 2 * 0.5);
|
||||
|
||||
print("Applying all values to time step 0")
|
||||
resInsight.properties.setActiveCellResults(values, 0, 'DYNAMIC_NATIVE', 'SOIL', 0)
|
||||
|
||||
timeSteps = resInsight.gridInfo.timeSteps(caseId=0)
|
||||
for i in range(0, len(timeSteps)):
|
||||
print("Applying values to all time step " + str(i))
|
||||
resInsight.properties.setActiveCellResults(values, 0, 'DYNAMIC_NATIVE', 'SOIL', i)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user