changed: avoid duplicating code

This commit is contained in:
Arne Morten Kvarving 2022-06-13 12:13:01 +02:00
parent d032078634
commit 3af1d464eb
2 changed files with 10 additions and 29 deletions

View File

@ -42,8 +42,10 @@ namespace Opm {
static SimpleTable serializeObject();
void addColumns();
void init(const DeckItem& deckItem );
void init( const DeckItem& deckItem, double scaling_factor);
//! \brief Initialize deck item.
//! \param deckItem item to initialize
//! \param scaling_factor If zero use SI value, else use value scaled by scaling factor
void init( const DeckItem& deckItem, double scaling_factor = 0.0);
size_t numColumns() const;
size_t numRows() const;
void addRow( const std::vector<double>& row);

View File

@ -82,31 +82,6 @@ namespace Opm {
return col[row];
}
void SimpleTable::init( const DeckItem& deckItem ) {
this->addColumns();
if ( (deckItem.data_size() % numColumns()) != 0)
throw std::runtime_error("Number of columns in the data file is"
"inconsistent with the ones specified");
size_t rows = deckItem.data_size() / numColumns();
for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) {
auto& column = getColumn( colIdx );
for (size_t rowIdx = 0; rowIdx < rows; rowIdx++) {
size_t deckItemIdx = rowIdx*numColumns() + colIdx;
if (deckItem.defaultApplied(deckItemIdx))
column.addDefault( );
else if (m_jfunc) {
column.addValue( deckItem.getData<double>()[deckItemIdx] );
}
else
column.addValue( deckItem.getSIDouble(deckItemIdx) );
}
if (colIdx > 0)
column.applyDefaults(getColumn( 0 ));
}
}
void SimpleTable::init( const DeckItem& deckItem, double scaling_factor) {
this->addColumns();
@ -124,8 +99,12 @@ namespace Opm {
else if (m_jfunc) {
column.addValue( deckItem.getData<double>()[deckItemIdx] );
}
else
column.addValue( scaling_factor * deckItem.get<double>(deckItemIdx) );
else {
if (scaling_factor > 0.0)
column.addValue( scaling_factor * deckItem.get<double>(deckItemIdx) );
else
column.addValue( deckItem.getSIDouble(deckItemIdx) );
}
}
if (colIdx > 0)
column.applyDefaults(getColumn( 0 ));