diff --git a/ApplicationLibCode/Commands/GeoMechCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/GeoMechCommands/CMakeLists_files.cmake index 540177f86a5..ccf5cfa1683 100644 --- a/ApplicationLibCode/Commands/GeoMechCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/GeoMechCommands/CMakeLists_files.cmake @@ -11,6 +11,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewWellIntegrityAnalysisFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicRunWellIntegrityAnalysisFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewFaultReactModelingFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicRunFaultReactModelingFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -26,6 +27,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewWellIntegrityAnalysisFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicRunWellIntegrityAnalysisFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewFaultReactModelingFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicRunFaultReactModelingFeature.cpp ) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp b/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp new file mode 100644 index 00000000000..3782d3ed761 --- /dev/null +++ b/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.cpp @@ -0,0 +1,133 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicRunFaultReactModelingFeature.h" + +#include "RiaApplication.h" +#include "RiaPreferencesGeoMech.h" + +#include "RifFaultReactivationModelExporter.h" + +#include "RimFaultReactivationModel.h" +#include "RimProcess.h" +#include "RimProject.h" + +#include "Riu3DMainWindowTools.h" +#include "Riu3dSelectionManager.h" +#include "RiuFileDialogTools.h" + +#include "cafProgressInfo.h" +#include "cafSelectionManagerTools.h" + +#include +#include + +CAF_CMD_SOURCE_INIT( RicRunFaultReactModelingFeature, "RicRunFaultReactModelingFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicRunFaultReactModelingFeature::onActionTriggered( bool isChecked ) +{ + RimFaultReactivationModel* model = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + + if ( model == nullptr ) return; + + const QString frmTitle( "Fault Reactivation Modeling" ); + + QString outErrorText; + + caf::ProgressInfo runProgress( 3, frmTitle + " running , please wait..." ); + + runProgress.setProgressDescription( "Writing input files." ); + + if ( model->fault() == nullptr ) + { + QMessageBox::critical( nullptr, frmTitle, "A fault has not selected. Please check your model settings." ); + return; + } + + // if ( !modelSettings->extractModelData() ) + //{ + // QMessageBox::critical( nullptr, + // frmTitle, + // "Unable to get necessary data from the defined model box. Is the model box center " + // "outside the reservoir?" ); + // return; + // } + + QString exportFile = model->inputFilename(); + auto [result, errText] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *model->model() ); + + if ( !result ) + { + outErrorText = QString( "Failed to export INP model to file %1.\n\n%2" ).arg( exportFile ).arg( QString::fromStdString( errText ) ); + QMessageBox::critical( nullptr, frmTitle, outErrorText ); + return; + } + + if ( RiaPreferencesGeoMech::current()->waitBeforeRun() ) + { + runProgress.setProgressDescription( "Waiting for input file modifications." ); + + QString infoText = "Input parameter files can now be found in the working folder:"; + infoText += " \"" + model->baseDir() + "\"\n"; + infoText += "\nClick OK to start the Abaqus modeling or Cancel to stop."; + + auto reply = QMessageBox::information( nullptr, frmTitle, infoText, QMessageBox::Ok | QMessageBox::Cancel ); + + if ( reply != QMessageBox::Ok ) return; + } + + runProgress.incrementProgress(); + runProgress.setProgressDescription( "Running Abaqus modeling." ); + + QString command = RiaPreferencesGeoMech::current()->geomechWIACommand(); + QStringList parameters = model->commandParameters(); + + RimProcess process; + process.setCommand( command ); + process.setParameters( parameters ); + + if ( !process.execute() ) + { + QMessageBox::critical( nullptr, frmTitle, "Failed to run modeling. Check log window for additional information." ); + return; + } + + runProgress.incrementProgress(); + runProgress.setProgressDescription( "Loading modeling results." ); + + RiaApplication* app = RiaApplication::instance(); + if ( !app->openOdbCaseFromFile( model->outputOdbFilename() ) ) + { + QMessageBox::critical( nullptr, + frmTitle, + "Failed to load modeling results from file \"" + model->outputOdbFilename() + + "\". Check log window for additional information." ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicRunFaultReactModelingFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/fault_react_24x24.png" ) ); + actionToSetup->setText( "Run..." ); +} diff --git a/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.h b/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.h new file mode 100644 index 00000000000..8a06d513b4f --- /dev/null +++ b/ApplicationLibCode/Commands/GeoMechCommands/RicRunFaultReactModelingFeature.h @@ -0,0 +1,35 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +#include + +//================================================================================================== +/// +//================================================================================================== +class RicRunFaultReactModelingFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp index 7283c9ce3d0..c5916f19552 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp @@ -526,3 +526,27 @@ std::vector RimFaultReactivationModel::selectedTimeSteps() const return selectedSteps; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QStringList RimFaultReactivationModel::commandParameters() const +{ + return QStringList(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFaultReactivationModel::outputOdbFilename() const +{ + return baseDir() + "faultreactivation.odb"; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFaultReactivationModel::inputFilename() const +{ + return baseDir() + "faultreactivation.inp"; +} diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h index 4c86e0732a4..5b8cf466f2d 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h @@ -32,6 +32,7 @@ #include "cvfVector3.h" #include +#include #include #include @@ -92,6 +93,10 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly std::vector selectedTimeSteps() const; + QStringList commandParameters() const; + QString outputOdbFilename() const; + QString inputFilename() const; + protected: caf::PdmFieldHandle* userDescriptionField() override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;