#12487 Python: add export from eclipse case to corner point grid.

Exports to zcorn, coords and actnum arrays.

Fixes #12487.
This commit is contained in:
Kristian Bendiksen authored and Magne Sjaastad committed 2025-09-25 10:56:04 +02:00
1 parent 88799eb7cc
commit 1271d6942d
5 files changed
+437 -2

No files matched your search

@@ -22,13 +22,17 @@
#include "RiaGuiApplication.h"
#include "RiaKeyValueStoreUtil.h"
#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
#include "RigEclipseResultAddress.h"
#include "RigGridExportAdapter.h"
#include "RigMainGrid.h"
#include "RigResdataGridConverter.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimCase.h"
#include "RimEclipseCase.h"
#include "RimProject.h"
@@ -181,3 +185,70 @@ std::expected<caf::PdmObjectHandle*, QString> RimcEclipseCase_exportValuesIntern
return nullptr;
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseCase, RimcEclipseCase_exportCornerPointGridInternal, "export_corner_point_grid_internal" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcEclipseCase_exportCornerPointGridInternal::RimcEclipseCase_exportCornerPointGridInternal( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Export Corner Point Grid Internal", "", "", "Export Corner Point Grid Internal" );
CAF_PDM_InitScriptableFieldNoDefault( &m_zcornKey, "ZcornKey", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_coordKey, "CoordKey", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_actnumKey, "ActnumKey", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcEclipseCase_exportCornerPointGridInternal::execute()
{
auto eclipseCase = self<RimEclipseCase>();
if ( !eclipseCase )
{
return std::unexpected( "Unable to get Eclipse case." );
}
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
if ( !eclipseCaseData )
{
return std::unexpected( "Unable to load eclipse case data." );
}
auto keyValueStore = RiaApplication::instance()->keyValueStore();
// Use RigGridExportAdapter to handle full grid export
// Export the full grid (no min/max bounds, no refinement, no visibility override)
RigGridExportAdapter gridAdapter( eclipseCaseData, cvf::Vec3st::ZERO, cvf::Vec3st::UNDEFINED, cvf::Vec3st( 1, 1, 1 ), nullptr );
// Use the existing conversion utility to get the arrays in the correct format
std::vector<float> coordArray;
std::vector<float> zcornArray;
std::vector<int> actnumArray;
RigResdataGridConverter::convertGridToCornerPointArrays( gridAdapter, coordArray, zcornArray, actnumArray );
// Convert actnum from int to float for key-value store
std::vector<float> actnumFloat;
actnumFloat.reserve( actnumArray.size() );
for ( int value : actnumArray )
{
actnumFloat.push_back( static_cast<float>( value ) );
}
// Store arrays in key-value store
keyValueStore->set( m_zcornKey().toStdString(), RiaKeyValueStoreUtil::convertToByteVector( zcornArray ) );
keyValueStore->set( m_coordKey().toStdString(), RiaKeyValueStoreUtil::convertToByteVector( coordArray ) );
keyValueStore->set( m_actnumKey().toStdString(), RiaKeyValueStoreUtil::convertToByteVector( actnumFloat ) );
// Store grid dimensions as well
std::vector<float> dimensions = { static_cast<float>( gridAdapter.cellCountI() ),
static_cast<float>( gridAdapter.cellCountJ() ),
static_cast<float>( gridAdapter.cellCountK() ) };
keyValueStore->set( ( m_zcornKey().toStdString() + "_dimensions" ), RiaKeyValueStoreUtil::convertToByteVector( dimensions ) );
return nullptr;
}