Import of AICD valve definition from text file

* Add readKeywordContentFromFile
* Add import of AICD values from Completor and Eclipse
This commit is contained in:
Magne Sjaastad authored and GitHub committed 2023-09-12 19:45:32 +02:00
1 parent 2e94bd8e5e
commit 13b4c19bbb
14 files changed
+462 -87

No files matched your search

@@ -23,6 +23,8 @@
#include "cafPdmUiTreeOrdering.h"
#include "opm/input/eclipse/Parser/ParserKeywords/W.hpp"
CAF_PDM_SOURCE_INIT( RimValveTemplate, "ValveTemplate" );
//--------------------------------------------------------------------------------------------------
@@ -166,6 +168,65 @@ void RimValveTemplate::setUserLabel( const QString& userLabel )
m_userLabel = userLabel;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimValveTemplate::setAicdParameter( AICDParameters parameter, double value )
{
if ( m_aicdParameters() )
{
m_aicdParameters()->setValue( parameter, value );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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->setAicdParameter( parameter.second, incomingValue );
}
}
return aicdTemplate;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -19,8 +19,10 @@
#pragma once
#include "RiaDefines.h"
#include "RiaOpmParserTools.h"
#include "RimCheckableNamedObject.h"
#include "RimWellPathAicdParameters.h"
#include "cafPdmChildField.h"
@@ -48,6 +50,10 @@ public:
QString fullLabel() const;
void setUserLabel( const QString& userLabel );
void setAicdParameter( AICDParameters parameter, double value );
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;
@@ -114,6 +114,14 @@ bool RimWellPathAicdParameters::isValid() const
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathAicdParameters::setValue( AICDParameters parameter, double value )
{
m_aicdParameterFields[parameter].setValue( QString::number( value ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -53,6 +53,8 @@ public:
~RimWellPathAicdParameters() override;
bool isValid() const;
void setValue( AICDParameters parameter, double value );
bool isOpen() const;
std::array<double, AICD_NUM_PARAMS> doubleValues() const;
@@ -17,6 +17,10 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RiaOpmParserTools.h"
#include "RiaLogging.h"
#include "RiaTextStringTools.h"
#include "RifEclipseInputFileTools.h"
#include "cafPdmUiItem.h"
#include "cafUtils.h"
@@ -29,6 +33,10 @@
#include "opm/input/eclipse/Parser/ParserKeywords/V.hpp"
#include "opm/input/eclipse/Parser/ParserKeywords/W.hpp"
#include <QFile>
#include <set>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -193,3 +201,147 @@ 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 );
const std::string keyword = "WSEGAICD";
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 )
{
auto name = kw->name();
for ( size_t kwIndex = 0; kwIndex < kw->size(); kwIndex++ )
{
RiaOpmParserTools::AicdTemplateValues aicdTemplate;
auto deckRecord = kw->getRecord( kwIndex );
auto numItems = deckRecord.size();
for ( size_t deckIndex = 0; deckIndex < numItems; deckIndex++ )
{
auto deckItem = deckRecord.getItem( deckIndex );
if ( !deckItem.hasValue( 0 ) ) continue;
if ( !keywordsToExtract.contains( deckItem.name() ) ) continue;
auto typeTag = deckItem.getType();
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 {};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RiaOpmParserTools::AicdTemplateValues> RiaOpmParserTools::extractWsegAicdCompletor( const std::string& filename )
{
QFile file( QString::fromStdString( filename ) );
if ( !file.open( QFile::ReadOnly ) ) return {};
std::vector<RiaOpmParserTools::AicdTemplateValues> aicdTemplates;
const QString keyword( "WSEGAICD" );
const QString keywordToStopParsing;
auto keywordContent = RifEclipseInputFileTools::readKeywordContentFromFile( keyword, keywordToStopParsing, file );
for ( const auto& s : keywordContent )
{
auto wordsInLine = RiaTextStringTools::splitSkipEmptyParts( s );
std::vector<double> values;
for ( const auto& word : wordsInLine )
{
bool ok = false;
auto doubleValue = word.toDouble( &ok );
if ( ok ) values.push_back( doubleValue );
}
// Completor exports the values in the following format, 12 values per row
// WSEGAICD
// --Number Alpha x y a b c d e f rhocal viscal
// 1 0.000017253 3.05 0.67 1 1 1 2.43 1.18 10.0 1000 1
// 2 0.000027253 5.05 0.53 1 1 1 2.43 1.28 7.02 1000 1
//
if ( values.size() == 12 )
{
RiaOpmParserTools::AicdTemplateValues aicdValues;
aicdValues[aicdTemplateId()] = values[0];
aicdValues[Opm::ParserKeywords::WSEGAICD::STRENGTH::itemName] = values[1]; // Alpha
aicdValues[Opm::ParserKeywords::WSEGAICD::FLOW_RATE_EXPONENT::itemName] = values[2]; // x
aicdValues[Opm::ParserKeywords::WSEGAICD::VISC_EXPONENT::itemName] = values[3]; // y
aicdValues[Opm::ParserKeywords::WSEGAICD::OIL_FLOW_FRACTION::itemName] = values[4]; // a
aicdValues[Opm::ParserKeywords::WSEGAICD::WATER_FLOW_FRACTION::itemName] = values[5]; // b
aicdValues[Opm::ParserKeywords::WSEGAICD::GAS_FLOW_FRACTION::itemName] = values[6]; // c
aicdValues[Opm::ParserKeywords::WSEGAICD::OIL_VISC_FRACTION::itemName] = values[7]; // d
aicdValues[Opm::ParserKeywords::WSEGAICD::WATER_VISC_FRACTION::itemName] = values[8]; // e
aicdValues[Opm::ParserKeywords::WSEGAICD::GAS_VISC_FRACTION::itemName] = values[9]; // f
aicdValues[Opm::ParserKeywords::WSEGAICD::DENSITY_CALI::itemName] = values[10]; // rhocal
aicdValues[Opm::ParserKeywords::WSEGAICD::VISCOSITY_CALI::itemName] = values[11]; // viscal
aicdTemplates.push_back( aicdValues );
}
}
return aicdTemplates;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RiaOpmParserTools::aicdTemplateId()
{
return "ID_NUMBER";
}
@@ -35,4 +35,10 @@ public:
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, double>;
static std::vector<AicdTemplateValues> extractWsegAicd( const std::string& filename );
static std::vector<AicdTemplateValues> extractWsegAicdCompletor( const std::string& filename );
static std::string aicdTemplateId();
};
@@ -959,6 +959,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if ( dynamic_cast<RimValveTemplateCollection*>( firstUiItem ) )
{
menuBuilder << "RicNewValveTemplateFeature";
menuBuilder << "RicImportValveTemplatesFeature";
}
else if ( dynamic_cast<RimValveTemplate*>( firstUiItem ) )
{