Skip to content

Commit

Permalink
#10107 : Import of AICD from Eclipse text file
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 6, 2023
1 parent 76b8e69 commit c14732c
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 0 deletions.
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,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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,
"Text Files (*.txt);;All Files (*.*)" );

RimValveTemplateCollection* templateColl = RimProject::current()->allValveTemplateCollections().front();
for ( const auto& fileName : fileNames )
{
auto values = RiaOpmParserTools::extractWsegaicd( fileName.toStdString() );
for ( const auto value : values )
{
auto newTemplate = RimValveTemplate::createAicdTemplate( value );
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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

#include "cafPdmUiTreeOrdering.h"

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

#include <variant>

CAF_PDM_SOURCE_INIT( RimValveTemplate, "ValveTemplate" );

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

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimValveTemplate* RimValveTemplate::createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters )
{
RimValveTemplate* aicdTemplate = new RimValveTemplate;
aicdTemplate->setType( RiaDefines::WellPathComponentType::AICD );
aicdTemplate->setUserLabel( QString( "AICD" ) );

std::map<std::string, AICDParameters> parameterMap =
{ { Opm::ParserKeywords::WSEGAICD::LENGTH::itemName, AICD_STRENGTH },
{ Opm::ParserKeywords::WSEGAICD::DENSITY_CALI::itemName, AICD_DENSITY_CALIB_FLUID },
{ Opm::ParserKeywords::WSEGAICD::VISCOSITY_CALI::itemName, AICD_VISCOSITY_CALIB_FLUID },
{ Opm::ParserKeywords::WSEGAICD::FLOW_RATE_EXPONENT::itemName, AICD_VOL_FLOW_EXP },
{ Opm::ParserKeywords::WSEGAICD::VISC_EXPONENT::itemName, AICD_VISOSITY_FUNC_EXP },
{ Opm::ParserKeywords::WSEGAICD::CRITICAL_VALUE::itemName, AICD_CRITICAL_WATER_IN_LIQUID_FRAC },
//{ Opm::ParserKeywords::WSEGAICD::vis::itemName, AICD_EMULSION_VISC_TRANS_REGION },
//{ Opm::ParserKeywords::WSEGAICD::vis::itemName, AICD_MAX_RATIO_EMULSION_VISC },
{ Opm::ParserKeywords::WSEGAICD::MAX_ABS_RATE::itemName, AICD_MAX_FLOW_RATE },
{ Opm::ParserKeywords::WSEGAICD::OIL_FLOW_FRACTION::itemName, AICD_EXP_OIL_FRAC_DENSITY },
{ Opm::ParserKeywords::WSEGAICD::WATER_FLOW_FRACTION::itemName, AICD_EXP_WATER_FRAC_DENSITY },
{ Opm::ParserKeywords::WSEGAICD::GAS_FLOW_FRACTION::itemName, AICD_EXP_GAS_FRAC_DENSITY },
{ Opm::ParserKeywords::WSEGAICD::OIL_VISC_FRACTION::itemName, AICD_EXP_OIL_FRAC_VISCOSITY },
{ Opm::ParserKeywords::WSEGAICD::WATER_VISC_FRACTION::itemName, AICD_EXP_WATER_FRAC_VISCOSITY },
{ Opm::ParserKeywords::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 );
if ( std::holds_alternative<double>( incomingValue ) )
{
double doubleValue = std::get<double>( incomingValue );
aicdTemplate->m_aicdParameters()->setValue( parameter.second, doubleValue );
}
}
}

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 );

protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ bool RimWellPathAicdParameters::isValid() const
return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathAicdParameters::setValue( AICDParameters parameter, double value )
{
m_aicdParameterFields[parameter].setValue( QString::number( value ) );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class RimWellPathAicdParameters : public caf::PdmObject
~RimWellPathAicdParameters() override;
bool isValid() const;

void setValue( AICDParameters parameter, double value );

bool isOpen() const;
std::array<double, AICD_NUM_PARAMS> doubleValues() const;

Expand Down
71 changes: 71 additions & 0 deletions ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////

#include "RiaOpmParserTools.h"
#include "RiaLogging.h"

#include "cafPdmUiItem.h"
#include "cafUtils.h"
Expand Down Expand Up @@ -193,3 +194,73 @@ std::map<std::string, std::vector<std::pair<int, int>>> RiaOpmParserTools::extra

return wseglink;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RiaOpmParserTools::AicdTemplateValues> RiaOpmParserTools::extractWsegaicd( const std::string& filename )
{
if ( !std::filesystem::exists( filename ) ) return {};

try
{
Opm::Parser parser( false );

const Opm::ParserKeywords::WSEGAICD kw1;
const Opm::ParserKeywords::INCLUDE kw2;
const Opm::ParserKeywords::PATHS kw3;

parser.addParserKeyword( kw1 );
parser.addParserKeyword( kw2 );
parser.addParserKeyword( kw3 );

std::stringstream ss;
Opm::ParseContext parseContext( Opm::InputError::Action::WARN );
auto deck = parser.parseFile( filename, parseContext );

std::string keyword = "WSEGAICD";
auto keywordList = deck.getKeywordList( keyword );
if ( keywordList.empty() ) return {};

std::vector<RiaOpmParserTools::AicdTemplateValues> aicdData;
for ( auto kw : keywordList )
{
auto name = kw->name();

for ( size_t i = 0; i < kw->size(); i++ )
{
RiaOpmParserTools::AicdTemplateValues aicdTemplate;

auto deckRecord = kw->getRecord( i );
auto numItems = deckRecord.size();
for ( size_t i = 0; i < numItems; i++ )
{
auto deckItem = deckRecord.getItem( i );
if ( !deckItem.hasValue( 0 ) ) continue;

auto typeTag = deckItem.getType();
if ( typeTag == Opm::type_tag::string )
{
auto stringValue = deckItem.getTrimmedString( 0 );
aicdTemplate[deckItem.name()] = stringValue;
}
else if ( typeTag == Opm::type_tag::fdouble )
{
double doubleValue = deckItem.get<double>( 0 );
aicdTemplate[deckItem.name()] = doubleValue;
}
}

aicdData.push_back( aicdTemplate );
}
}

return aicdData;
}
catch ( std::exception& e )
{
RiaLogging::error( e.what() );
}

return {};
}
4 changes: 4 additions & 0 deletions ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <map>
#include <string>
#include <variant>
#include <vector>

#include "opm/input/eclipse/Schedule/VFPInjTable.hpp"
Expand All @@ -35,4 +36,7 @@ class RiaOpmParserTools
static std::vector<Opm::VFPProdTable> extractVfpProductionTables( const std::string& filename );

static std::map<std::string, std::vector<std::pair<int, int>>> extractWseglink( const std::string& filename );

using AicdTemplateValues = std::map<std::string, std::variant<std::string, double>>;
static std::vector<AicdTemplateValues> extractWsegaicd( const std::string& filename );
};
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if ( dynamic_cast<RimValveTemplateCollection*>( firstUiItem ) )
{
menuBuilder << "RicNewValveTemplateFeature";
menuBuilder << "RicImportValveTemplatesFeature";
}
else if ( dynamic_cast<RimValveTemplate*>( firstUiItem ) )
{
Expand Down

0 comments on commit c14732c

Please sign in to comment.