Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import of AICD valve definition from text file #10525

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicWellPathImportPerforationIntervalsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewStimPlanModelPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportEnsembleFractureStatisticsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportValveTemplatesFeature.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand All @@ -28,6 +29,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicWellPathImportPerforationIntervalsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewStimPlanModelPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportEnsembleFractureStatisticsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportValveTemplatesFeature.cpp
)

list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicImportValveTemplatesFeature.h"

#include "RiaApplication.h"
#include "RiaOpmParserTools.h"

#include "RimProject.h"
#include "RimValveTemplate.h"
#include "RimValveTemplateCollection.h"

#include "Riu3DMainWindowTools.h"
#include "RiuFileDialogTools.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicImportValveTemplatesFeature, "RicImportValveTemplatesFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportValveTemplatesFeature::isCommandEnabled() const
{
return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportValveTemplatesFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory( "BINARY_GRID" );

QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
"Import Valve Templates",
defaultDir,
"Valve Files (*.sch *.case);;All Files (*.*)" );

RimValveTemplateCollection* templateColl = RimProject::current()->allValveTemplateCollections().front();
magnesj marked this conversation as resolved.
Show resolved Hide resolved
for ( const auto& fileName : fileNames )
{
std::vector<RiaOpmParserTools::AicdTemplateValues> aicdTemplates;

if ( fileName.contains( ".case" ) )
{
aicdTemplates = RiaOpmParserTools::extractWsegAicdCompletor( fileName.toStdString() );
}
else
{
aicdTemplates = RiaOpmParserTools::extractWsegAicd( fileName.toStdString() );
}

// There can be multiple items of the same template, make sure we have unique templates
std::sort( aicdTemplates.begin(), aicdTemplates.end() );
auto it = std::unique( aicdTemplates.begin(), aicdTemplates.end() );
aicdTemplates.resize( std::distance( aicdTemplates.begin(), it ) );

int number = 1;
for ( const auto& aicdValue : aicdTemplates )
{
auto newTemplate = RimValveTemplate::createAicdTemplate( aicdValue, number++ );
templateColl->addValveTemplate( newTemplate );
}
}

templateColl->updateConnectedEditors();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportValveTemplatesFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/ICDValve16x16.png" ) );
actionToSetup->setText( "Import Valve Templates" );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafCmdFeature.h"

//==================================================================================================
///
//==================================================================================================
class RicImportValveTemplatesFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

protected:
bool isCommandEnabled() const override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};
48 changes: 36 additions & 12 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,16 +1181,15 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively( Q
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
const QString& keyword,
const QString& keywordToStopParsing,
QFile& file,
qint64 startPos,
const std::vector<std::pair<QString, QString>>& pathAliasDefinitions,
QStringList* keywordDataContent,
std::vector<QString>* filenamesContainingKeyword,
bool* isStopParsingKeywordDetected,
const QString& faultIncludeFileAbsolutePathPrefix /* rename to includeStatementAbsolutePathPrefix */ )
bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( const QString& keyword,
const QString& keywordToStopParsing,
QFile& file,
qint64 startPos,
const std::vector<std::pair<QString, QString>>& pathAliasDefinitions,
QStringList* keywordDataContent,
std::vector<QString>* filenamesContainingKeyword,
bool* isStopParsingKeywordDetected,
const QString& includeStatementAbsolutePathPrefix )
magnesj marked this conversation as resolved.
Show resolved Hide resolved
{
QString line;

Expand Down Expand Up @@ -1256,7 +1255,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
if ( includeFilename.startsWith( '/' ) )
{
// Absolute UNIX path, prefix on Windows
includeFilename = faultIncludeFileAbsolutePathPrefix + includeFilename;
includeFilename = includeStatementAbsolutePathPrefix + includeFilename;
}
#endif

Expand All @@ -1277,7 +1276,7 @@ bool RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively(
keywordDataContent,
filenamesContainingKeyword,
isStopParsingKeywordDetected,
faultIncludeFileAbsolutePathPrefix ) )
includeStatementAbsolutePathPrefix ) )
{
qDebug() << "Error when parsing include file : " << absoluteFilename;
}
Expand Down Expand Up @@ -1437,6 +1436,31 @@ bool RifEclipseInputFileTools::hasGridData( const QString& fileName )
return coordKeywordItr != keywordAndValues.end();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RifEclipseInputFileTools::readKeywordContentFromFile( const QString& keyword, const QString& keywordToStopParsing, QFile& file )
{
const qint64 startPositionInFile = 0;
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
QStringList keywordContent;
std::vector<QString> fileNamesContainingKeyword;
bool isStopParsingKeywordDetected = false;
const QString includeStatementAbsolutePathPrefix;

RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword,
keywordToStopParsing,
file,
startPositionInFile,
pathAliasDefinitions,
&keywordContent,
&fileNamesContainingKeyword,
&isStopParsingKeywordDetected,
includeStatementAbsolutePathPrefix );

return keywordContent;
}

//--------------------------------------------------------------------------------------------------
/// The file pointer is pointing at the line following the FAULTS keyword.
/// Parse content of this keyword until end of file or
Expand Down
7 changes: 4 additions & 3 deletions ApplicationLibCode/FileInterface/RifEclipseInputFileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class RifEclipseInputFileTools : public cvf::Object

static void parseAndReadPathAliasKeyword( const QString& fileName, std::vector<std::pair<QString, QString>>* pathAliasDefinitions );

static QStringList readKeywordContentFromFile( const QString& keyword, const QString& keywordToStopParsing, QFile& file );

// Public for unit testing, use readKeywordContentFromFile()
static bool readKeywordAndParseIncludeStatementsRecursively( const QString& keyword,
const QString& keywordToStopParsing,
QFile& file,
Expand All @@ -114,9 +117,7 @@ class RifEclipseInputFileTools : public cvf::Object
QStringList* keywordDataContent,
std::vector<QString>* filenamesContainingKeyword,
bool* isEditKeywordDetected,
const QString& faultIncludeFileAbsolutePathPrefix // rename to
// includeStatementAbsolutePathPrefix
);
const QString& includeStatementAbsolutePathPrefix );

static RiaDefines::EclipseUnitSystem readUnitSystem( QFile& file, qint64 gridunitPos );

Expand Down
27 changes: 7 additions & 20 deletions ApplicationLibCode/FileInterface/RifReaderEclipseOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,26 +648,13 @@ void RifReaderEclipseOutput::importEquilData( const QString& deckFileName,
const QString& includeStatementAbsolutePathPrefix,
RigEclipseCaseData* eclipseCase )
{
QFile data( deckFileName );
if ( data.open( QFile::ReadOnly ) )
{
const QString keyword( "EQUIL" );
const QString keywordToStopParsing( "SCHEDULE" );
const qint64 startPositionInFile = 0;
std::vector<std::pair<QString, QString>> pathAliasDefinitions;
QStringList keywordContent;
std::vector<QString> fileNamesContainingKeyword;
bool isStopParsingKeywordDetected = false;

RifEclipseInputFileTools::readKeywordAndParseIncludeStatementsRecursively( keyword,
keywordToStopParsing,
data,
startPositionInFile,
pathAliasDefinitions,
&keywordContent,
&fileNamesContainingKeyword,
&isStopParsingKeywordDetected,
includeStatementAbsolutePathPrefix );
QFile file( deckFileName );
if ( file.open( QFile::ReadOnly ) )
{
const QString keyword( "EQUIL" );
const QString keywordToStopParsing( "SCHEDULE" );
auto keywordContent = RifEclipseInputFileTools::readKeywordContentFromFile( keyword, keywordToStopParsing, file );

std::vector<RigEquil> equilItems;
for ( const auto& s : keywordContent )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "cafPdmUiTreeOrdering.h"

#include "opm/input/eclipse/Parser/ParserKeywords/W.hpp"

CAF_PDM_SOURCE_INIT( RimValveTemplate, "ValveTemplate" );

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -166,6 +168,54 @@ void RimValveTemplate::setUserLabel( const QString& userLabel )
m_userLabel = userLabel;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimValveTemplate* RimValveTemplate::createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters, int templateNumber )
{
RimValveTemplate* aicdTemplate = new RimValveTemplate;
aicdTemplate->setType( RiaDefines::WellPathComponentType::AICD );

QString name;
if ( aicdParameters.contains( RiaOpmParserTools::aicdTemplateId() ) )
{
auto id = aicdParameters.at( RiaOpmParserTools::aicdTemplateId() );
name = QString::number( id );
}
else
{
name = QString::number( templateNumber );
}

aicdTemplate->setUserLabel( name );

using namespace Opm::ParserKeywords;
std::map<std::string, AICDParameters> parameterMap = { { WSEGAICD::STRENGTH::itemName, AICD_STRENGTH },
{ WSEGAICD::DENSITY_CALI::itemName, AICD_DENSITY_CALIB_FLUID },
{ WSEGAICD::VISCOSITY_CALI::itemName, AICD_VISCOSITY_CALIB_FLUID },
{ WSEGAICD::FLOW_RATE_EXPONENT::itemName, AICD_VOL_FLOW_EXP },
{ WSEGAICD::VISC_EXPONENT::itemName, AICD_VISOSITY_FUNC_EXP },
{ WSEGAICD::CRITICAL_VALUE::itemName, AICD_CRITICAL_WATER_IN_LIQUID_FRAC },
{ WSEGAICD::MAX_ABS_RATE::itemName, AICD_MAX_FLOW_RATE },
{ WSEGAICD::OIL_FLOW_FRACTION::itemName, AICD_EXP_OIL_FRAC_DENSITY },
{ WSEGAICD::WATER_FLOW_FRACTION::itemName, AICD_EXP_WATER_FRAC_DENSITY },
{ WSEGAICD::GAS_FLOW_FRACTION::itemName, AICD_EXP_GAS_FRAC_DENSITY },
{ WSEGAICD::OIL_VISC_FRACTION::itemName, AICD_EXP_OIL_FRAC_VISCOSITY },
{ WSEGAICD::WATER_VISC_FRACTION::itemName, AICD_EXP_WATER_FRAC_VISCOSITY },
{ WSEGAICD::GAS_VISC_FRACTION::itemName, AICD_EXP_GAS_FRAC_VISCOSITY } };

for ( const auto& parameter : parameterMap )
{
if ( aicdParameters.contains( parameter.first ) )
{
auto incomingValue = aicdParameters.at( parameter.first );
aicdTemplate->m_aicdParameters()->setValue( parameter.second, incomingValue );
}
magnesj marked this conversation as resolved.
Show resolved Hide resolved
}

return aicdTemplate;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "RiaDefines.h"
#include "RiaOpmParserTools.h"

#include "RimCheckableNamedObject.h"

Expand Down Expand Up @@ -48,6 +49,8 @@ class RimValveTemplate : public RimNamedObject
QString fullLabel() const;
void setUserLabel( const QString& userLabel );

static RimValveTemplate* createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters, int templateNumber );

protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
Expand Down
Loading