#4549 Add python method to get properties for selected cells.

Equivalent to GetGridPropertyForSelectedCells in Octave.
This commit is contained in:
Kristian Bendiksen
2020-02-19 22:01:42 +01:00
parent 8a1fa38435
commit d497f04d0d
6 changed files with 165 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ service Properties
{
rpc GetAvailableProperties(AvailablePropertiesRequest) returns (AvailableProperties) {}
rpc GetActiveCellProperty(PropertyRequest) returns (stream PropertyChunk) {}
rpc GetSelectedCellProperty(PropertyRequest) returns (stream PropertyChunk) {}
rpc GetGridProperty(PropertyRequest) returns (stream PropertyChunk) {}
rpc SetActiveCellProperty(stream PropertyInputChunk) returns (ClientToServerStreamReply) {}
rpc SetGridProperty(stream PropertyInputChunk) returns (ClientToServerStreamReply) {}

View File

@@ -15,7 +15,9 @@ if resinsight is not None:
cells = case.selected_cells()
print("Found " + str(len(cells)) + " selected cells")
for cell in cells:
time_step_info = case.time_steps()
for (idx, cell) in enumerate(cells):
print("Selected cell: [{}, {}, {}] grid: {}".format(cell.ijk.i+1, cell.ijk.j+1, cell.ijk.k+1, cell.grid_index))
# Get the grid and dimensions
@@ -41,3 +43,8 @@ if resinsight is not None:
print("c5:\n" + str(cell_corners.c5))
print("c6:\n" + str(cell_corners.c6))
print("c7:\n" + str(cell_corners.c7))
for (tidx, timestep) in enumerate(time_step_info):
# Read the full SOIL result for time step
soil_results = case.selected_cell_property('DYNAMIC_NATIVE', 'SOIL', tidx)
print("SOIL: {} ({}.{}.{})".format(soil_results[idx], timestep.year, timestep.month, timestep.day))

View File

@@ -585,6 +585,61 @@ class Case(PdmObject):
all_values.append(value)
return all_values
def selected_cell_property_async(self,
property_type,
property_name,
time_step,
porosity_model="MATRIX_MODEL"):
"""Get a cell property for all selected cells. Async, so returns an iterator
Arguments:
property_type(str): string enum. See available()
property_name(str): name of an Eclipse property
time_step(int): the time step for which to get the property for
porosity_model(str): string enum. See available()
Returns:
An iterator to a chunk object containing an array of double values
Loop through the chunks and then the values within the chunk to get all values.
"""
property_type_enum = Properties_pb2.PropertyType.Value(property_type)
porosity_model_enum = Case_pb2.PorosityModelType.Value(porosity_model)
request = Properties_pb2.PropertyRequest(
case_request=self.__request,
property_type=property_type_enum,
property_name=property_name,
time_step=time_step,
porosity_model=porosity_model_enum,
)
for chunk in self.__properties_stub.GetSelectedCellProperty(request):
yield chunk
def selected_cell_property(self,
property_type,
property_name,
time_step,
porosity_model="MATRIX_MODEL"):
"""Get a cell property for all selected cells. Sync, so returns a list
Arguments:
property_type(str): string enum. See available()
property_name(str): name of an Eclipse property
time_step(int): the time step for which to get the property for
porosity_model(str): string enum. See available()
Returns:
A list containing double values
Loop through the chunks and then the values within the chunk to get all values.
"""
all_values = []
generator = self.selected_cell_property_async(property_type,
property_name, time_step,
porosity_model)
for chunk in generator:
for value in chunk.values:
all_values.append(value)
return all_values
def grid_property_async(
self,
property_type,

View File

@@ -177,3 +177,9 @@ def test_selected_cells(rips_instance, initialize_test):
assert(case.name == "TEST10K_FLT_LGR_NNC")
selected_cells = case.selected_cells()
assert(len(selected_cells) == 0)
time_step_info = case.time_steps()
for (tidx, timestep) in enumerate(time_step_info):
# Try to read for SOIL the time step (will be empty since nothing is selected)
soil_results = case.selected_cell_property('DYNAMIC_NATIVE', 'SOIL', tidx)
assert(len(soil_results) == 0)

View File

@@ -35,6 +35,9 @@
#include "Rim3dView.h"
#include "RimEclipseCase.h"
#include "RimEclipseResultDefinition.h"
#include "Riu3dSelectionManager.h"
#include <algorithm>
@@ -263,6 +266,73 @@ private:
std::vector<double>* m_resultValues;
};
class RiaSelectedCellResultsStateHandler : public RiaCellResultsStateHandler
{
public:
RiaSelectedCellResultsStateHandler( bool clientStreamer = false )
: RiaCellResultsStateHandler( clientStreamer )
{
}
protected:
void initResultAccess( RigEclipseCaseData* caseData,
size_t gridIndex,
RiaDefines::PorosityModelType porosityModel,
size_t timeStepIndex,
RigEclipseResultAddress resVarAddr ) override
{
std::vector<RiuSelectionItem*> items;
Riu3dSelectionManager::instance()->selectedItems( items );
// Only eclipse cases are currently supported. Also filter by case.
std::vector<RiuEclipseSelectionItem*> eclipseItems;
for ( auto item : items )
{
RiuEclipseSelectionItem* eclipseItem = dynamic_cast<RiuEclipseSelectionItem*>( item );
if ( eclipseItem && eclipseItem->m_resultDefinition->eclipseCase()->caseId == caseData->ownerCase()->caseId )
{
eclipseItems.push_back( eclipseItem );
}
}
m_cellCount = eclipseItems.size();
if ( m_resultValues.empty() )
{
m_resultValues.resize( m_cellCount );
}
for ( size_t idx = 0; idx < m_cellCount; idx++ )
{
const RiuEclipseSelectionItem* item = eclipseItems[idx];
CVF_ASSERT( item->type() == RiuSelectionItem::ECLIPSE_SELECTION_OBJECT );
size_t cellIndex = item->m_gridLocalCellIndex;
cvf::ref<RigResultAccessor> resultAccessor =
RigResultAccessorFactory::createFromResultAddress( caseData, gridIndex, porosityModel, timeStepIndex, resVarAddr );
if ( resultAccessor.isNull() )
{
continue;
}
double cellValue = resultAccessor->cellScalar( cellIndex );
if ( cellValue == HUGE_VAL )
{
cellValue = 0.0;
}
m_resultValues[idx] = cellValue;
}
}
double cellResult( size_t currentCellIndex ) const override { return m_resultValues[currentCellIndex]; }
void setCellResult( size_t currentCellIndex, double value ) override { m_resultValues[currentCellIndex] = value; }
private:
std::vector<double> m_resultValues;
};
class RiaGridCellResultsStateHandler : public RiaCellResultsStateHandler
{
public:
@@ -339,6 +409,17 @@ grpc::Status RiaGrpcPropertiesService::GetActiveCellProperty( grpc::ServerContex
return stateHandler->assignStreamReply( reply );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
grpc::Status RiaGrpcPropertiesService::GetSelectedCellProperty( grpc::ServerContext* context,
const PropertyRequest* request,
PropertyChunk* reply,
RiaSelectedCellResultsStateHandler* stateHandler )
{
return stateHandler->assignStreamReply( reply );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -418,6 +499,15 @@ std::vector<RiaGrpcCallbackInterface*> RiaGrpcPropertiesService::createCallbacks
&Self::GetGridProperty,
&Self::RequestGetGridProperty,
new RiaGridCellResultsStateHandler ) );
callbacks.push_back(
new RiaGrpcServerToClientStreamCallback<Self,
PropertyRequest,
PropertyChunk,
RiaSelectedCellResultsStateHandler>( this,
&Self::GetSelectedCellProperty,
&Self::RequestGetSelectedCellProperty,
new RiaSelectedCellResultsStateHandler ) );
}
return callbacks;
}

View File

@@ -25,6 +25,7 @@
class RiaActiveCellResultsStateHandler;
class RiaGridCellResultsStateHandler;
class RiaSelectedCellResultsStateHandler;
//==================================================================================================
//
@@ -41,6 +42,10 @@ public:
const rips::PropertyRequest* request,
rips::PropertyChunk* reply,
RiaActiveCellResultsStateHandler* stateHandler );
grpc::Status GetSelectedCellProperty( grpc::ServerContext* context,
const rips::PropertyRequest* request,
rips::PropertyChunk* reply,
RiaSelectedCellResultsStateHandler* stateHandler );
grpc::Status GetGridProperty( grpc::ServerContext* context,
const rips::PropertyRequest* request,
rips::PropertyChunk* reply,