mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
#12542 Make sure case is open before accessing cell data
* Make sure case is open before accessing cell data * Add Python example to compute average value for a set of cells
This commit is contained in:
1 parent
16aa8946f5
commit
eb284304ff
2 files changed
+55
-3
No files matched your search
@@ -0,0 +1,35 @@
|
||||
###########################################################################################
|
||||
# This example will calculate the average value of the porosity property for a specified
|
||||
# region in the reservoir model. The region is identified by its EQLNUM value.
|
||||
###########################################################################################
|
||||
|
||||
import rips
|
||||
|
||||
resinsight = rips.Instance.find()
|
||||
|
||||
cases = resinsight.project.cases()
|
||||
|
||||
time_step = 0
|
||||
region_number = 2
|
||||
|
||||
for case in cases:
|
||||
sum_poro = 0.0
|
||||
cell_cout = 0
|
||||
|
||||
eqlnum = case.active_cell_property("STATIC_NATIVE", "EQLNUM", time_step)
|
||||
poro = case.active_cell_property("STATIC_NATIVE", "PORO", time_step)
|
||||
if len(eqlnum) != len(poro):
|
||||
print("Size of eqlnum and poro is not identical.")
|
||||
break
|
||||
|
||||
for i in range(len(eqlnum)):
|
||||
if eqlnum[i] == region_number:
|
||||
sum_poro += poro[i]
|
||||
cell_cout += 1
|
||||
|
||||
# Calculate the average porosity for the specified region
|
||||
if cell_cout > 0:
|
||||
average_poro = sum_poro / cell_cout
|
||||
print(
|
||||
f"Case {case.id}: Cell count {cell_cout} Average PORO for region {region_number} = {average_poro}"
|
||||
)
|
||||
@@ -88,8 +88,16 @@ public:
|
||||
|
||||
if ( m_eclipseCase )
|
||||
{
|
||||
// This function will import grid geometry and result data. For this operation, only access to cell result
|
||||
// data is required.
|
||||
m_eclipseCase->ensureReservoirCaseIsOpen();
|
||||
auto caseData = m_eclipseCase->eclipseCaseData();
|
||||
if ( !caseData )
|
||||
{
|
||||
return grpc::Status( grpc::NOT_FOUND, "Eclipse case data not found" );
|
||||
}
|
||||
|
||||
m_porosityModel = static_cast<RiaDefines::PorosityModelType>( request->porosity_model() );
|
||||
auto caseData = m_eclipseCase->eclipseCaseData();
|
||||
auto resultData = caseData->results( m_porosityModel );
|
||||
auto resultType = static_cast<RiaDefines::ResultCatType>( request->property_type() );
|
||||
size_t timeStep = static_cast<size_t>( request->time_step() );
|
||||
@@ -131,7 +139,7 @@ public:
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Client streamers need to be initialised with the encapsulated parameters
|
||||
/// Client streamers need to be initialized with the encapsulated parameters
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Status init( const PropertyInputChunk* chunk )
|
||||
{
|
||||
@@ -409,8 +417,17 @@ grpc::Status RiaGrpcPropertiesService::GetAvailableProperties( grpc::ServerConte
|
||||
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( RiaGrpcHelper::findCase( caseId ) );
|
||||
if ( eclipseCase )
|
||||
{
|
||||
// This function will import grid geometry and result data. For this operation, only access to cell result
|
||||
// data is required.
|
||||
eclipseCase->ensureReservoirCaseIsOpen();
|
||||
auto caseData = eclipseCase->eclipseCaseData();
|
||||
if ( !caseData )
|
||||
{
|
||||
return grpc::Status( grpc::NOT_FOUND, "Eclipse case data not found" );
|
||||
}
|
||||
|
||||
auto porosityModel = static_cast<RiaDefines::PorosityModelType>( request->porosity_model() );
|
||||
auto resultData = eclipseCase->eclipseCaseData()->results( porosityModel );
|
||||
auto resultData = caseData->results( porosityModel );
|
||||
auto resultType = static_cast<RiaDefines::ResultCatType>( request->property_type() );
|
||||
QStringList resultNames = resultData->resultNames( resultType );
|
||||
if ( !resultNames.empty() )
|
||||
|
||||
Reference in new issue
Block a user