diff --git a/ApplicationLibCode/FileInterface/RifOpmDeckTools.cpp b/ApplicationLibCode/FileInterface/RifOpmDeckTools.cpp index 5cbd77a6e79..df1a3723250 100644 --- a/ApplicationLibCode/FileInterface/RifOpmDeckTools.cpp +++ b/ApplicationLibCode/FileInterface/RifOpmDeckTools.cpp @@ -19,6 +19,7 @@ #include "RifOpmDeckTools.h" #include "opm/input/eclipse/Deck/DeckItem.hpp" +#include "opm/input/eclipse/Deck/DeckRecord.hpp" #include "opm/input/eclipse/Units/Dimension.hpp" namespace RifOpmDeckTools @@ -135,4 +136,18 @@ Opm::DeckItem optionalItem( std::string name, std::optional value ) return defaultItem( name ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +Opm::DeckRecord createRecord( std::initializer_list namedValues ) +{ + std::vector items; + items.reserve( namedValues.size() ); + for ( const auto& nv : namedValues ) + { + items.push_back( std::visit( [&nv]( const auto& val ) { return RifOpmDeckTools::item( nv.name, val ); }, nv.value ) ); + } + return Opm::DeckRecord{ std::move( items ) }; +} + } // namespace RifOpmDeckTools diff --git a/ApplicationLibCode/FileInterface/RifOpmDeckTools.h b/ApplicationLibCode/FileInterface/RifOpmDeckTools.h index 30dd9b2c00e..2d57415b3e0 100644 --- a/ApplicationLibCode/FileInterface/RifOpmDeckTools.h +++ b/ApplicationLibCode/FileInterface/RifOpmDeckTools.h @@ -18,12 +18,15 @@ #pragma once +#include #include #include +#include namespace Opm { class DeckItem; +class DeckRecord; } // namespace Opm namespace RifOpmDeckTools @@ -39,4 +42,44 @@ Opm::DeckItem optionalItem( std::string name, std::optional value ); Opm::DeckItem optionalItem( std::string name, std::optional value ); Opm::DeckItem defaultItem( std::string name ); +struct NamedValue +{ + // Test + std::string name; + std::variant value; + + NamedValue( std::string n, std::string v ) + : name( std::move( n ) ) + , value( std::move( v ) ) + { + } + NamedValue( std::string n, const char* v ) + : name( std::move( n ) ) + , value( std::string( v ) ) + { + } + NamedValue( std::string n, int v ) + : name( std::move( n ) ) + , value( v ) + { + } + NamedValue( std::string n, size_t v ) + : name( std::move( n ) ) + , value( (int)v ) + { + } + NamedValue( std::string n, double v ) + : name( std::move( n ) ) + , value( v ) + { + } + NamedValue( std::string n, float v ) + : name( std::move( n ) ) + , value( (double)v ) + { + } +}; + +Opm::DeckRecord createRecord( std::initializer_list items ); + } // namespace RifOpmDeckTools diff --git a/ApplicationLibCode/ProjectDataModel/Jobs/RimKeywordFactory.cpp b/ApplicationLibCode/ProjectDataModel/Jobs/RimKeywordFactory.cpp index 97bc35138d4..f0ffa53c05b 100644 --- a/ApplicationLibCode/ProjectDataModel/Jobs/RimKeywordFactory.cpp +++ b/ApplicationLibCode/ProjectDataModel/Jobs/RimKeywordFactory.cpp @@ -209,14 +209,12 @@ Opm::DeckKeyword complumpKeyword( const std::vector& compdata { continue; } - std::vector items; - items.push_back( RifOpmDeckTools::item( C::WELL::itemName, wellName ) ); - items.push_back( RifOpmDeckTools::item( C::I::itemName, cd.completionDataGridCell().localCellIndexI() + 1 ) ); - items.push_back( RifOpmDeckTools::item( C::J::itemName, cd.completionDataGridCell().localCellIndexJ() + 1 ) ); - items.push_back( RifOpmDeckTools::item( C::K1::itemName, cd.completionDataGridCell().localCellIndexK() + 1 ) ); - items.push_back( RifOpmDeckTools::item( C::K2::itemName, cd.completionDataGridCell().localCellIndexK() + 1 ) ); - items.push_back( RifOpmDeckTools::item( C::N::itemName, cd.completionNumber().value() ) ); - kw.addRecord( Opm::DeckRecord{ std::move( items ) } ); + kw.addRecord( RifOpmDeckTools::createRecord( { { C::WELL::itemName, wellName }, + { C::I::itemName, cd.completionDataGridCell().localCellIndexI() + 1 }, + { C::J::itemName, cd.completionDataGridCell().localCellIndexJ() + 1 }, + { C::K1::itemName, cd.completionDataGridCell().localCellIndexK() + 1 }, + { C::K2::itemName, cd.completionDataGridCell().localCellIndexK() + 1 }, + { C::N::itemName, cd.completionNumber().value() } } ) ); } return kw; }