diff --git a/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp b/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp index e880051cf5..962938992d 100644 --- a/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp +++ b/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp @@ -48,18 +48,12 @@ void RicExportInpFileFeature::onActionTriggered( bool isChecked ) auto faultReactivationModel = caf::SelectionManager::instance()->selectedItemOfType(); if ( faultReactivationModel ) { - const QString frmTitle( "Fault Reactivation Modeling" ); - if ( !faultReactivationModel->extractAndExportModelData() ) - { - QMessageBox::critical( nullptr, frmTitle, "Unable to get necessary data from the input case." ); - return; - } - QString exportFile = faultReactivationModel->baseDir() + "/faultreactivation.inp"; auto [isOk, errorMessage] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *faultReactivationModel ); if ( !isOk ) { - QString outErrorText = + const QString frmTitle( "Fault Reactivation Modeling" ); + QString outErrorText = QString( "Failed to export INP model to file %1.\n\n%2" ).arg( exportFile ).arg( QString::fromStdString( errorMessage ) ); QMessageBox::critical( nullptr, frmTitle, outErrorText ); } diff --git a/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp b/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp index 73335da878..7fc394ce76 100644 --- a/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp +++ b/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp @@ -70,12 +70,6 @@ void RicRunFaultReactModelingFeature::onActionTriggered( bool isChecked ) return; } - if ( !model->extractAndExportModelData() ) - { - QMessageBox::critical( nullptr, frmTitle, "Unable to get necessary data from the input case." ); - return; - } - QString exportFile = model->inputFilename(); auto [result, errText] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *model ); diff --git a/ApplicationLibCode/Commands/GeoMechCommands/RicShowFaultReactModelFeature.cpp b/ApplicationLibCode/Commands/GeoMechCommands/RicShowFaultReactModelFeature.cpp index c69214e435..3bbd380a7f 100644 --- a/ApplicationLibCode/Commands/GeoMechCommands/RicShowFaultReactModelFeature.cpp +++ b/ApplicationLibCode/Commands/GeoMechCommands/RicShowFaultReactModelFeature.cpp @@ -56,12 +56,6 @@ void RicShowFaultReactModelFeature::onActionTriggered( bool isChecked ) const QString frmTitle( "Fault Reactivation Modeling" ); const QString exportFile = model->inputFilename(); - if ( !model->extractAndExportModelData() ) - { - QMessageBox::critical( nullptr, frmTitle, "Unable to get necessary data from the input case." ); - return; - } - auto [result, errText] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *model ); if ( !result ) { diff --git a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp index c9d7113380..6e5c27dfd2 100644 --- a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp +++ b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp @@ -28,9 +28,12 @@ #include "RiaWellLogUnitTools.h" #include "RifInpExportTools.h" +#include "RifJsonEncodeDecode.h" + #include "RimFaultReactivationDataAccess.h" #include "RimFaultReactivationEnums.h" #include "RimFaultReactivationModel.h" +#include "RimFaultReactivationTools.h" #include #include @@ -42,6 +45,9 @@ std::pair RifFaultReactivationModelExporter::exportToStream( const std::string& exportDirectory, const RimFaultReactivationModel& rimModel ) { + auto dataAccess = extractAndExportModelData( rimModel ); + if ( !dataAccess ) return { false, "Unable to get necessary data from the input case." }; + std::string applicationNameAndVersion = std::string( RI_APPLICATION_NAME ) + " " + std::string( STRPRODUCTVER ); using PartBorderSurface = RimFaultReactivation::BorderSurface; @@ -90,8 +96,6 @@ std::pair RifFaultReactivationModelExporter::exportToStream( double waterDensity = rimModel.waterDensity(); double seaWaterLoad = RiaWellLogUnitTools::gravityAcceleration() * seaBedDepth * waterDensity; - auto dataAccess = rimModel.dataAccess(); - auto model = rimModel.model(); CAF_ASSERT( !model.isNull() ); @@ -808,4 +812,45 @@ std::string RifFaultReactivationModelExporter::createFileName( const std::string std::string RifFaultReactivationModelExporter::createFilePath( const std::string& dir, const std::string& fileName ) { return dir + "/" + fileName; -}; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifFaultReactivationModelExporter::exportModelSettings( const RimFaultReactivationModel& rimModel ) +{ + auto model = rimModel.model(); + + if ( model.isNull() ) return false; + if ( !model->isValid() ) return false; + + QMap settings; + + auto [topPosition, bottomPosition] = model->faultTopBottom(); + auto faultNormal = model->faultNormal(); + + // make sure we move horizontally, and along the 2D model + faultNormal.z() = 0.0; + faultNormal.normalize(); + faultNormal = faultNormal ^ cvf::Vec3d::Z_AXIS; + + RimFaultReactivationTools::addSettingsToMap( settings, faultNormal, topPosition, bottomPosition ); + return ResInsightInternalJson::JsonWriter::encodeFile( rimModel.settingsFilename(), settings ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::shared_ptr + RifFaultReactivationModelExporter::extractAndExportModelData( const RimFaultReactivationModel& rimModel ) +{ + if ( !exportModelSettings( rimModel ) ) return nullptr; + + auto eCase = rimModel.eclipseCase(); + if ( eCase == nullptr ) return nullptr; + + // extract data for each timestep + auto dataAccess = std::make_shared( eCase, rimModel.geoMechCase(), rimModel.selectedTimeStepIndexes() ); + dataAccess->extractModelData( *rimModel.model() ); + return dataAccess; +} diff --git a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h index 14dffd1e79..0f91e0c693 100644 --- a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h +++ b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h @@ -111,4 +111,7 @@ class RifFaultReactivationModelExporter static std::string createFileName( const std::string& title, const std::string& stepName ); static std::string createFilePath( const std::string& dir, const std::string& fileName ); + + static bool exportModelSettings( const RimFaultReactivationModel& model ); + static std::shared_ptr extractAndExportModelData( const RimFaultReactivationModel& model ); }; diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp index 46bcd52f72..6fcc781df5 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp @@ -46,7 +46,6 @@ #include "RimEclipseView.h" #include "RimFaultInView.h" #include "RimFaultInViewCollection.h" -#include "RimFaultReactivationDataAccess.h" #include "RimFaultReactivationEnums.h" #include "RimFaultReactivationTools.h" #include "RimGeoMechCase.h" @@ -542,22 +541,20 @@ void RimFaultReactivationModel::defineEditorAttribute( const caf::PdmFieldHandle //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimEclipseCase* RimFaultReactivationModel::eclipseCase() +RimEclipseCase* RimFaultReactivationModel::eclipseCase() const { auto eCase = firstAncestorOrThisOfType(); - if ( eCase == nullptr ) - { - eCase = dynamic_cast( RiaApplication::instance()->activeGridView()->ownerCase() ); - } - - return eCase; + if ( eCase != nullptr ) + return eCase; + else + return dynamic_cast( RiaApplication::instance()->activeGridView()->ownerCase() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimGeoMechCase* RimFaultReactivationModel::geoMechCase() +RimGeoMechCase* RimFaultReactivationModel::geoMechCase() const { return m_geomechCase(); } @@ -602,6 +599,22 @@ std::vector RimFaultReactivationModel::selectedTimeSteps() const return dates; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimFaultReactivationModel::selectedTimeStepIndexes() const +{ + std::vector selectedTimeStepIndexes; + for ( auto& timeStep : selectedTimeSteps() ) + { + auto idx = std::find( m_availableTimeSteps.begin(), m_availableTimeSteps.end(), timeStep ); + if ( idx == m_availableTimeSteps.end() ) return {}; + + selectedTimeStepIndexes.push_back( idx - m_availableTimeSteps.begin() ); + } + return selectedTimeStepIndexes; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -660,60 +673,6 @@ QString RimFaultReactivationModel::baseFilename() const return tmp; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimFaultReactivationModel::exportModelSettings() -{ - if ( m_2Dmodel.isNull() ) return false; - if ( !m_2Dmodel->isValid() ) return false; - - QMap settings; - - auto [topPosition, bottomPosition] = m_2Dmodel->faultTopBottom(); - auto faultNormal = m_2Dmodel->faultNormal(); - - // make sure we move horizontally, and along the 2D model - faultNormal.z() = 0.0; - faultNormal.normalize(); - faultNormal = faultNormal ^ cvf::Vec3d::Z_AXIS; - - RimFaultReactivationTools::addSettingsToMap( settings, faultNormal, topPosition, bottomPosition ); - - QDir directory( baseDir() ); - return ResInsightInternalJson::JsonWriter::encodeFile( settingsFilename(), settings ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimFaultReactivationModel::extractAndExportModelData() -{ - if ( m_dataAccess ) m_dataAccess->clearModelData(); - - if ( !exportModelSettings() ) return false; - - auto eCase = eclipseCase(); - if ( eCase == nullptr ) return false; - - // get the selected time step indexes - std::vector selectedTimeStepIndexes; - for ( auto& timeStep : selectedTimeSteps() ) - { - auto idx = std::find( m_availableTimeSteps.begin(), m_availableTimeSteps.end(), timeStep ); - if ( idx == m_availableTimeSteps.end() ) return false; - - selectedTimeStepIndexes.push_back( idx - m_availableTimeSteps.begin() ); - } - - // extract data for each timestep - m_dataAccess = std::make_shared( eCase, geoMechCase(), selectedTimeStepIndexes ); - m_dataAccess->extractModelData( *model() ); - m_dataAccess.reset(); - - return true; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -741,14 +700,6 @@ std::array RimFaultReactivationModel::materialParameters( ElementSets return retVal; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::shared_ptr RimFaultReactivationModel::dataAccess() const -{ - return m_dataAccess; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h index e3c741b5eb..36dbe7f7cf 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h @@ -18,7 +18,6 @@ #pragma once #include "RimCheckableNamedObject.h" -#include "RimFaultReactivationDataAccess.h" #include "RimFaultReactivationEnums.h" #include "RimPolylinePickerInterface.h" #include "RimPolylinesDataInterface.h" @@ -53,7 +52,6 @@ class RimTimeStepFilter; class RivFaultReactivationModelPartMgr; class RigBasicPlane; class RigFaultReactivationModel; -class RimFaultReactivationDataAccess; namespace cvf { @@ -102,12 +100,11 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly cvf::ref model() const; bool showModel() const; - bool extractAndExportModelData(); - QString baseDir() const; void setBaseDir( QString path ); std::vector selectedTimeSteps() const; + std::vector selectedTimeStepIndexes() const; std::array materialParameters( ElementSets elementSet ) const; @@ -119,8 +116,6 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly void updateTimeSteps(); - std::shared_ptr dataAccess() const; - bool useGridVoidRatio() const; bool useGridPorePressure() const; bool useGridTemperature() const; @@ -131,6 +126,9 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly double seaBedDepth() const; double waterDensity() const; + RimEclipseCase* eclipseCase() const; + RimGeoMechCase* geoMechCase() const; + protected: caf::PdmFieldHandle* userDescriptionField() override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; @@ -139,13 +137,8 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; - RimEclipseCase* eclipseCase(); - RimGeoMechCase* geoMechCase(); - QString baseFilename() const; - bool exportModelSettings(); - private: std::shared_ptr m_pickTargetsEventHandler; @@ -197,6 +190,4 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly caf::PdmChildArrayField m_materialParameters; std::vector m_availableTimeSteps; - - std::shared_ptr m_dataAccess; };