Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjenssen committed Sep 18, 2023
1 parent cc59eba commit 4042a88
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 101 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
31 changes: 27 additions & 4 deletions ApplicationLibCode/FileInterface/RifJsonEncodeDecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ 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 +57,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 @@ -548,6 +553,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 +582,28 @@ QString RimFaultReactivationModel::baseFilename() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultReactivationModel::extractModelData()
bool RimFaultReactivationModel::exportModelSettings()
{
if ( m_faultPlane.isNull() ) return false;

QMap<QString, QVariant> settings;

auto [topInt, bottomInt] = m_faultPlane->intersectTopBottomLine();
auto planeNormal = m_faultPlane->normal();

RimFaultReactivationTools::addSettingsToMap( settings, planeNormal, topInt, bottomInt );

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,18 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly
cvf::ref<RigFaultReactivationModel> model() const;
bool showModel() const;

bool extractModelData();
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 +121,8 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly

QString baseFilename() const;

bool exportModelSettings();

private:
std::shared_ptr<RicPolylineTargetsPickEventHandler> m_pickTargetsEventHandler;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#include "RimFaultReactivationTools.h"

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RimFaultReactivationTools::normalVector( QMap<QString, QVariant> settings )
{
double x = settings.value( "faultNormal_X", 0.0 ).toDouble();
double y = settings.value( "faultNormal_Y", 0.0 ).toDouble();
double z = settings.value( "faultNormal_Z", 0.0 ).toDouble();

return cvf::Vec3d( x, y, z );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RimFaultReactivationTools::topFaultPosition( QMap<QString, QVariant> settings )
{
double x = settings.value( "faultTop_X", 0.0 ).toDouble();
double y = settings.value( "faultTop_Y", 0.0 ).toDouble();
double z = settings.value( "faultTop_Z", 0.0 ).toDouble();

return cvf::Vec3d( x, y, z );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RimFaultReactivationTools::bottomFaultPosition( QMap<QString, QVariant> settings )
{
double x = settings.value( "faultBottom_X", 0.0 ).toDouble();
double y = settings.value( "faultBottom_Y", 0.0 ).toDouble();
double z = settings.value( "faultBottom_Z", 0.0 ).toDouble();

return cvf::Vec3d( x, y, z );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFaultReactivationTools::addSettingsToMap( QMap<QString, QVariant>& map,
cvf::Vec3d normalVector,
cvf::Vec3d topFaultPosition,
cvf::Vec3d bottomFaultPosition )
{
map["faultTop_X"] = topFaultPosition.x();
map["faultTop_Y"] = topFaultPosition.y();
map["faultTop_Z"] = topFaultPosition.z();

map["faultBottom_X"] = bottomFaultPosition.x();
map["faultBottom_Y"] = bottomFaultPosition.y();
map["faultBottom_Z"] = bottomFaultPosition.z();

map["faultNormal_X"] = normalVector.x();
map["faultNormal_Y"] = normalVector.y();
map["faultNormal_Z"] = normalVector.z();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <QMap>
#include <QString>
#include <QVariant>

#include "cvfVector3.h"

class RimFaultReactivationTools
{
public:
static cvf::Vec3d normalVector( QMap<QString, QVariant> settings );
static cvf::Vec3d topFaultPosition( QMap<QString, QVariant> settings );
static cvf::Vec3d bottomFaultPosition( QMap<QString, QVariant> settings );

static void
addSettingsToMap( QMap<QString, QVariant>& map, cvf::Vec3d normalVector, cvf::Vec3d topFaultPosition, cvf::Vec3d bottomFaultPosition );

private:
RimFaultReactivationTools(){};
};
Loading

0 comments on commit 4042a88

Please sign in to comment.