Skip to content

Commit

Permalink
Make sure we create unique templates
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 8, 2023
1 parent 8a9e3fc commit a02ef5f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( templateColl->valveTemplates().size() );
auto newTemplate = RimValveTemplate::createAicdTemplate( aicdValue, number );
templateColl->addValveTemplate( newTemplate );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#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 @@ -174,51 +172,45 @@ 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 );

QString name;
if ( aicdParameters.contains( RiaOpmParserTools::aicdTemplateId() ) )
{
auto id = std::get<double>( 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<std::string, AICDParameters> 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<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 );
if ( std::holds_alternative<double>( incomingValue ) )
{
double doubleValue = std::get<double>( incomingValue );
aicdTemplate->m_aicdParameters()->setValue( parameter.second, doubleValue );
}
aicdTemplate->m_aicdParameters()->setValue( parameter.second, incomingValue );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
Expand Down
25 changes: 19 additions & 6 deletions ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include <QFile>

#include <set>

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -227,6 +229,21 @@ std::vector<RiaOpmParserTools::AicdTemplateValues> RiaOpmParserTools::extractWse
auto keywordList = deck.getKeywordList( keyword );
if ( keywordList.empty() ) return {};

using namespace Opm::ParserKeywords;
std::set<std::string> 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<RiaOpmParserTools::AicdTemplateValues> aicdData;
for ( const auto& kw : keywordList )
{
Expand All @@ -242,14 +259,10 @@ std::vector<RiaOpmParserTools::AicdTemplateValues> 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<double>( 0 );
aicdTemplate[deckItem.name()] = doubleValue;
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/ProjectDataModel/RiaOpmParserTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RiaOpmParserTools

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>>;
using AicdTemplateValues = std::map<std::string, double>;
static std::vector<AicdTemplateValues> extractWsegAicd( const std::string& filename );
static std::vector<AicdTemplateValues> extractWsegAicdCompletor( const std::string& filename );

Expand Down

0 comments on commit a02ef5f

Please sign in to comment.