Skip to content

Commit

Permalink
Fault reactivation (#10624)
Browse files Browse the repository at this point in the history
Update result to generate well paths based on information from model generator. Store settings in JSON file.
Add method to access local coordinate system definition
  • Loading branch information
jonjenssen authored Sep 19, 2023
1 parent 9b797fd commit 5d3fb8c
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "RifFaultReactivationModelExporter.h"

#include "RimFaultReactivationModel.h"
#include "RimGeoMechCase.h"
#include "RimGeoMechView.h"
#include "RimProcess.h"
#include "RimProject.h"

Expand Down Expand Up @@ -66,9 +68,9 @@ void RicRunFaultReactModelingFeature::onActionTriggered( bool isChecked )
return;
}

if ( !model->extractModelData() )
if ( !model->extractAndExportModelData() )
{
QMessageBox::critical( nullptr, frmTitle, "Unable to get necessary data from the input model." );
QMessageBox::critical( nullptr, frmTitle, "Unable to get necessary data from the input case." );
return;
}

Expand Down Expand Up @@ -115,6 +117,24 @@ void RicRunFaultReactModelingFeature::onActionTriggered( bool isChecked )
runProgress.incrementProgress();
runProgress.setProgressDescription( "Loading modeling results." );

for ( auto gCase : RimProject::current()->geoMechCases() )
{
if ( model->outputOdbFilename() == gCase->gridFileName() )
{
gCase->reloadDataAndUpdate();
auto& views = gCase->geoMechViews();
if ( views.size() > 0 )
{
Riu3DMainWindowTools::selectAsCurrentItem( views[0] );
}
else
{
Riu3DMainWindowTools::selectAsCurrentItem( gCase );
}
return;
}
}

RiaApplication* app = RiaApplication::instance();
if ( !app->openOdbCaseFromFile( model->outputOdbFilename() ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,8 @@ void RiuWellImportWizard::updateFieldsModel()
QStringList fields;
QStringList edmIds;

ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile( fileName );
QVariantList variantList = ResInsightInternalJson::JsonReader::getVariantList( jsonMap );
QMap<QString, QVariant> jsonMap = ResInsightInternalJson::JsonReader::decodeFile( fileName );
QVariantList variantList = ResInsightInternalJson::JsonReader::getVariantList( jsonMap );
for ( const auto& listItem : variantList )
{
QMap<QString, QVariant> fieldMap = listItem.toMap();
Expand Down Expand Up @@ -632,9 +631,8 @@ void RiuWellImportWizard::parseWellsResponse( RimOilFieldEntry* oilFieldEntry )

if ( caf::Utils::fileExists( oilFieldEntry->wellsFilePath ) )
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile( oilFieldEntry->wellsFilePath );
QVariantList variantList = ResInsightInternalJson::JsonReader::getVariantList( jsonMap );
QMap<QString, QVariant> jsonMap = ResInsightInternalJson::JsonReader::decodeFile( oilFieldEntry->wellsFilePath );
QVariantList variantList = ResInsightInternalJson::JsonReader::getVariantList( jsonMap );
for ( const auto& listItem : variantList )
{
QMap<QString, QVariant> rootMap = listItem.toMap();
Expand Down
32 changes: 28 additions & 4 deletions ApplicationLibCode/FileInterface/RifJsonEncodeDecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QString>
#include <QtCore/QTextStream>

namespace ResInsightInternalJson
{
QMap<QString, QVariant> JsonReader::decodeFile( QString filePath )
{
QFile file;
file.setFileName( filePath );
file.open( QIODevice::ReadOnly );
QByteArray byteArray = file.readAll();
file.close();
return Json::decode( byteArray );
if ( file.open( QIODevice::ReadOnly ) )
{
QByteArray byteArray = file.readAll();
file.close();
return Json::decode( byteArray );
}

return QMap<QString, QVariant>();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -53,6 +58,25 @@ QString JsonReader::rootKeyText()
return "root";
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool JsonWriter::encodeFile( QString filePath, QMap<QString, QVariant> map )
{
QFile file;
file.setFileName( filePath );
if ( file.open( QIODevice::ReadWrite | QIODevice::Text ) )
{
QString content = Json::encode( map, true );
QTextStream out( &file );
out << content;
file.close();
return true;
}

return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
14 changes: 13 additions & 1 deletion ApplicationLibCode/FileInterface/RifJsonEncodeDecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ namespace ResInsightInternalJson
class JsonReader
{
public:
QMap<QString, QVariant> decodeFile( QString filePath );
static QMap<QString, QVariant> decodeFile( QString filePath );

// Get a variant list from a map
static QVariantList getVariantList( const QMap<QString, QVariant>& map );

static QString rootKeyText();

private:
JsonReader(){};
};

class JsonWriter
{
public:
static bool encodeFile( QString filePath, QMap<QString, QVariant> map );

private:
JsonWriter(){};
};

class Json
Expand Down
8 changes: 3 additions & 5 deletions ApplicationLibCode/FileInterface/RifWellPathImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ bool RifWellPathImporter::isJsonFile( const QString& filePath )
//--------------------------------------------------------------------------------------------------
RifWellPathImporter::WellMetaData RifWellPathImporter::readJsonWellMetaData( const QString& filePath )
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile( filePath );
WellMetaData metadata;
QMap<QString, QVariant> jsonMap = ResInsightInternalJson::JsonReader::decodeFile( filePath );
WellMetaData metadata;

metadata.m_id = jsonMap["id"].toString();
metadata.m_name = jsonMap["name"].toString();
Expand All @@ -151,8 +150,7 @@ RifWellPathImporter::WellMetaData RifWellPathImporter::readJsonWellMetaData( con
//--------------------------------------------------------------------------------------------------
RifWellPathImporter::WellData RifWellPathImporter::readJsonWellData( const QString& filePath )
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile( filePath );
QMap<QString, QVariant> jsonMap = ResInsightInternalJson::JsonReader::decodeFile( filePath );

double datumElevation = jsonMap["datumElevation"].toDouble();
QList<QVariant> pathList = jsonMap["path"].toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimFaultInViewCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationModel.h
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationModelCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationTools.h
)

set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimFaultInView.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultInViewCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationModel.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationModelCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationTools.cpp
)

list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "RiaPreferencesGeoMech.h"
#include "RiaQDateTimeTools.h"

#include "RifJsonEncodeDecode.h"

#include "RigBasicPlane.h"
#include "RigFaultReactivationModel.h"
#include "RigPolyLinesData.h"
Expand All @@ -39,6 +41,7 @@
#include "RimEclipseView.h"
#include "RimFaultInView.h"
#include "RimFaultInViewCollection.h"
#include "RimFaultReactivationTools.h"
#include "RimPolylineTarget.h"
#include "RimTimeStepFilter.h"
#include "RimTools.h"
Expand All @@ -52,6 +55,8 @@

#include <QDateTime>
#include <QDir>
#include <QMap>
#include <QVariant>

CAF_PDM_SOURCE_INIT( RimFaultReactivationModel, "FaultReactivationModel" );

Expand Down Expand Up @@ -364,6 +369,17 @@ bool RimFaultReactivationModel::showModel() const
return m_showModelPlane;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<cvf::Vec3d, cvf::Vec3d> RimFaultReactivationModel::localCoordSysNormalsXY() const
{
cvf::Vec3d yNormal = m_modelPlane->normal();
cvf::Vec3d xNormal = yNormal ^ cvf::Vec3d::Z_AXIS;

return std::make_pair( xNormal, yNormal );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -503,9 +519,7 @@ void RimFaultReactivationModel::updateTimeSteps()
{
m_availableTimeSteps.clear();
const auto eCase = eclipseCase();
if ( eCase == nullptr ) return;

m_availableTimeSteps = eCase->timeStepDates();
if ( eCase != nullptr ) m_availableTimeSteps = eCase->timeStepDates();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -548,6 +562,15 @@ QString RimFaultReactivationModel::inputFilename() const
return directory.absoluteFilePath( baseFilename() + ".inp" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimFaultReactivationModel::settingsFilename() const
{
QDir directory( baseDir() );
return directory.absoluteFilePath( baseFilename() + ".settings.json" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -568,8 +591,32 @@ QString RimFaultReactivationModel::baseFilename() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultReactivationModel::extractModelData()
bool RimFaultReactivationModel::exportModelSettings()
{
if ( m_faultPlane.isNull() ) return false;

QMap<QString, QVariant> settings;

auto [topPosition, bottomPosition] = m_faultPlane->intersectTopBottomLine();
auto faultNormal = m_faultPlane->normal();

// make sure we move horizontally
faultNormal.z() = 0.0;
faultNormal.normalize();

RimFaultReactivationTools::addSettingsToMap( settings, faultNormal, topPosition, bottomPosition );

QDir directory( baseDir() );
return ResInsightInternalJson::JsonWriter::encodeFile( settingsFilename(), settings );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultReactivationModel::extractAndExportModelData()
{
exportModelSettings();

// TODO - get values from eclipse and geomech models here
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly
cvf::ref<RigFaultReactivationModel> model() const;
bool showModel() const;

bool extractModelData();
std::pair<cvf::Vec3d, cvf::Vec3d> localCoordSysNormalsXY() const;

bool extractAndExportModelData();

QString baseDir() const;
void setBaseDir( QString path );

std::vector<QDateTime> selectedTimeSteps() const;

QStringList commandParameters() const;
QString outputOdbFilename() const;
QString inputFilename() const;

QString outputOdbFilename() const;
QString inputFilename() const;
QString settingsFilename() const;

void updateTimeSteps();

Expand All @@ -119,6 +123,8 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly

QString baseFilename() const;

bool exportModelSettings();

private:
std::shared_ptr<RicPolylineTargetsPickEventHandler> m_pickTargetsEventHandler;

Expand Down
Loading

0 comments on commit 5d3fb8c

Please sign in to comment.