Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ApplicationLibCode/FileInterface/RifOpmDeckTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,4 +136,18 @@ Opm::DeckItem optionalItem( std::string name, std::optional<float> value )
return defaultItem( name );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Opm::DeckRecord createRecord( std::initializer_list<NamedValue> namedValues )
{
std::vector<Opm::DeckItem> 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
43 changes: 43 additions & 0 deletions ApplicationLibCode/FileInterface/RifOpmDeckTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

#pragma once

#include <initializer_list>
#include <optional>
#include <string>
#include <variant>

namespace Opm
{
class DeckItem;
class DeckRecord;
} // namespace Opm

namespace RifOpmDeckTools
Expand All @@ -39,4 +42,44 @@ Opm::DeckItem optionalItem( std::string name, std::optional<float> value );
Opm::DeckItem optionalItem( std::string name, std::optional<double> value );
Opm::DeckItem defaultItem( std::string name );

struct NamedValue
{
// Test
std::string name;
std::variant<std::string, int, double> 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<NamedValue> items );

} // namespace RifOpmDeckTools
14 changes: 6 additions & 8 deletions ApplicationLibCode/ProjectDataModel/Jobs/RimKeywordFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,12 @@ Opm::DeckKeyword complumpKeyword( const std::vector<RigCompletionData>& compdata
{
continue;
}
std::vector<Opm::DeckItem> 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;
}
Expand Down