From a02ef5f38b38cb27db4c5c87fd2f9becc47d9f57 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Sep 2023 14:56:08 +0200 Subject: [PATCH] Make sure we create unique templates --- .../RicImportValveTemplatesFeature.cpp | 8 +++- .../Completions/RimValveTemplate.cpp | 44 ++++++++----------- .../Completions/RimValveTemplate.h | 2 +- .../ProjectDataModel/RiaOpmParserTools.cpp | 25 ++++++++--- .../ProjectDataModel/RiaOpmParserTools.h | 2 +- 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp b/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp index 5b0712e3c99..adaceb40245 100644 --- a/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp +++ b/ApplicationLibCode/Commands/CompletionCommands/RicImportValveTemplatesFeature.cpp @@ -67,9 +67,15 @@ void RicImportValveTemplatesFeature::onActionTriggered( bool isChecked ) 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 ) ); + for ( const auto& aicdValue : aicdTemplates ) { - auto newTemplate = RimValveTemplate::createAicdTemplate( aicdValue ); + int number = static_cast( templateColl->valveTemplates().size() ); + auto newTemplate = RimValveTemplate::createAicdTemplate( aicdValue, number ); templateColl->addValveTemplate( newTemplate ); } } diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp index 5fb61cfb014..1d5f57a4c10 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.cpp @@ -26,8 +26,6 @@ #include "opm/input/eclipse/Parser/ParserKeyword.hpp" #include "opm/input/eclipse/Parser/ParserKeywords/W.hpp" -#include - CAF_PDM_SOURCE_INIT( RimValveTemplate, "ValveTemplate" ); //-------------------------------------------------------------------------------------------------- @@ -174,7 +172,7 @@ void RimValveTemplate::setUserLabel( const QString& userLabel ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimValveTemplate* RimValveTemplate::createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters ) +RimValveTemplate* RimValveTemplate::createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters, int templateNumber ) { RimValveTemplate* aicdTemplate = new RimValveTemplate; aicdTemplate->setType( RiaDefines::WellPathComponentType::AICD ); @@ -182,43 +180,37 @@ RimValveTemplate* RimValveTemplate::createAicdTemplate( const RiaOpmParserTools: QString name; if ( aicdParameters.contains( RiaOpmParserTools::aicdTemplateId() ) ) { - auto id = std::get( aicdParameters.at( RiaOpmParserTools::aicdTemplateId() ) ); + auto id = aicdParameters.at( RiaOpmParserTools::aicdTemplateId() ); name = QString::number( id ); } else { - name = "undefined"; + name = QString::number( templateNumber ); } aicdTemplate->setUserLabel( name ); - std::map parameterMap = - { { Opm::ParserKeywords::WSEGAICD::STRENGTH::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 } }; + using namespace Opm::ParserKeywords; + std::map 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 ); - if ( std::holds_alternative( incomingValue ) ) - { - double doubleValue = std::get( incomingValue ); - aicdTemplate->m_aicdParameters()->setValue( parameter.second, doubleValue ); - } + aicdTemplate->m_aicdParameters()->setValue( parameter.second, incomingValue ); } } diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h index f85b6897d0b..e5526fd20e4 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimValveTemplate.h @@ -49,7 +49,7 @@ class RimValveTemplate : public RimNamedObject QString fullLabel() const; void setUserLabel( const QString& userLabel ); - static RimValveTemplate* createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters ); + static RimValveTemplate* createAicdTemplate( const RiaOpmParserTools::AicdTemplateValues& aicdParameters, int templateNumber ); protected: QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; diff --git a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp index 1bb43506c58..355130f95b2 100644 --- a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp @@ -35,6 +35,8 @@ #include +#include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -227,6 +229,21 @@ std::vector RiaOpmParserTools::extractWse auto keywordList = deck.getKeywordList( keyword ); if ( keywordList.empty() ) return {}; + using namespace Opm::ParserKeywords; + std::set keywordsToExtract = { WSEGAICD::STRENGTH::itemName, + WSEGAICD::DENSITY_CALI::itemName, + WSEGAICD::VISCOSITY_CALI::itemName, + WSEGAICD::FLOW_RATE_EXPONENT::itemName, + WSEGAICD::VISC_EXPONENT::itemName, + WSEGAICD::CRITICAL_VALUE::itemName, + WSEGAICD::MAX_ABS_RATE::itemName, + WSEGAICD::OIL_FLOW_FRACTION::itemName, + WSEGAICD::WATER_FLOW_FRACTION::itemName, + WSEGAICD::GAS_FLOW_FRACTION::itemName, + WSEGAICD::OIL_VISC_FRACTION::itemName, + WSEGAICD::WATER_VISC_FRACTION::itemName, + WSEGAICD::GAS_VISC_FRACTION::itemName }; + std::vector aicdData; for ( const auto& kw : keywordList ) { @@ -242,14 +259,10 @@ std::vector RiaOpmParserTools::extractWse { auto deckItem = deckRecord.getItem( i ); if ( !deckItem.hasValue( 0 ) ) continue; + if (!keywordsToExtract.contains(deckItem.name())) 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 ) + if ( typeTag == Opm::type_tag::fdouble ) { double doubleValue = deckItem.get( 0 ); aicdTemplate[deckItem.name()] = doubleValue; diff --git a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h index e1d78cd73a8..1aef4735ac6 100644 --- a/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h +++ b/ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h @@ -37,7 +37,7 @@ class RiaOpmParserTools static std::map>> extractWseglink( const std::string& filename ); - using AicdTemplateValues = std::map>; + using AicdTemplateValues = std::map; static std::vector extractWsegAicd( const std::string& filename ); static std::vector extractWsegAicdCompletor( const std::string& filename );