Merge pull request #3045 from akva2/improve_error_logging

Improve error logging
This commit is contained in:
Arne Morten Kvarving 2022-06-13 15:11:02 +02:00 committed by GitHub
commit e3f97e45d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 34 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

@ -23,6 +23,8 @@
#include <opm/input/eclipse/EclipseState/Tables/TableSchema.hpp>
#include <opm/input/eclipse/Deck/DeckItem.hpp>
#include <fmt/format.h>
namespace Opm {
SimpleTable::SimpleTable( TableSchema schema, const DeckItem& deckItem) :
@ -82,37 +84,17 @@ 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();
if ( (deckItem.data_size() % numColumns()) != 0)
throw std::runtime_error("Number of columns in the data file is"
"inconsistent with the ones specified");
if ( (deckItem.data_size() % numColumns()) != 0) {
throw std::runtime_error {
fmt::format("Number of input table elements ({}) is "
"not a multiple of table's specified number "
"of columns ({})",
deckItem.data_size(), this->numColumns())
};
}
size_t rows = deckItem.data_size() / numColumns();
for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) {
@ -124,8 +106,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 ));

View File

@ -1562,8 +1562,12 @@ DensityTable make_density_table(const GravityTable& gravity) {
for (size_t tableIdx = 0; tableIdx < tableKeyword.size(); ++tableIdx) {
const auto& dataItem = tableKeyword.getRecord( tableIdx ).getItem("DATA");
if (dataItem.data_size() > 0) {
std::shared_ptr<TableType> table = std::make_shared<TableType>( dataItem, useJFunc() );
container.addTable( tableIdx , table );
try {
std::shared_ptr<TableType> table = std::make_shared<TableType>( dataItem, useJFunc() );
container.addTable( tableIdx , table );
} catch (const std::runtime_error& err) {
throw OpmInputError(err, tableKeyword.location());
}
}
}
}