* Fully internalized JFUNC
* Added JFunc.cpp, throw on wrong FLAG/DIR in JFUNC kw
* added tests for JFUNC in TableManagerTests
* added protected member m_jfunc to SimpleTable
* Added getJFuncColumn to accompany getPcowColumn
* Throws if pressure or jfunc is accessed inappropriately
* ... meaning if getPcowColumn is called when JFUNC is in deck, or
* getJFuncColumn is called when JFUNC is not in deck
* added tests for throwing and for getJFuncColumn
* SimpleTable.getColumn("PCOW/PCOG") throws if JFUNC
* In the event that one tries to get "PCOW" or "PCOG" via getColumn
* ... this will throw if JFUNC is present in the deck.
* Added tests.
158 lines
5.0 KiB
C++
158 lines
5.0 KiB
C++
/*
|
|
Copyright (C) 2013 by Andreas Lauser
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include <utility>
|
|
#include <iostream>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Tables/SimpleTable.hpp>
|
|
#include <opm/parser/eclipse/EclipseState/Tables/TableSchema.hpp>
|
|
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
|
|
|
namespace Opm {
|
|
|
|
SimpleTable::SimpleTable( TableSchema schema, const DeckItem& deckItem) :
|
|
m_schema( std::move( schema ) ),
|
|
m_jfunc (false)
|
|
{
|
|
init( deckItem );
|
|
}
|
|
|
|
|
|
SimpleTable::SimpleTable( TableSchema schema ) :
|
|
m_schema( std::move( schema ) ),
|
|
m_jfunc (false)
|
|
{
|
|
addColumns();
|
|
}
|
|
|
|
|
|
void SimpleTable::addRow( const std::vector<double>& row) {
|
|
if (row.size() == numColumns()) {
|
|
for (size_t colIndex = 0; colIndex < numColumns(); colIndex++) {
|
|
auto& col = getColumn( colIndex );
|
|
col.addValue( row[colIndex] );
|
|
}
|
|
} else
|
|
throw std::invalid_argument("Size mismatch");
|
|
}
|
|
|
|
|
|
void SimpleTable::addColumns() {
|
|
for (size_t colIdx = 0; colIdx < m_schema.size(); ++colIdx) {
|
|
const auto& schemaColumn = m_schema.getColumn( colIdx );
|
|
TableColumn column(schemaColumn); // Some move trickery here ...
|
|
m_columns.insert( schemaColumn.name() , column );
|
|
}
|
|
}
|
|
|
|
|
|
double SimpleTable::get(const std::string& column , size_t row) const {
|
|
const auto& col = getColumn( column );
|
|
return col[row];
|
|
}
|
|
|
|
|
|
double SimpleTable::get(size_t column , size_t row) const {
|
|
const auto& col = getColumn( column );
|
|
return col[row];
|
|
}
|
|
|
|
void SimpleTable::init( const DeckItem& deckItem ) {
|
|
this->addColumns();
|
|
|
|
if ( (deckItem.size() % numColumns()) != 0)
|
|
throw std::runtime_error("Number of columns in the data file is"
|
|
"inconsistent with the ones specified");
|
|
|
|
size_t rows = deckItem.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 ));
|
|
}
|
|
}
|
|
|
|
size_t SimpleTable::numColumns() const {
|
|
return m_schema.size();
|
|
}
|
|
|
|
size_t SimpleTable::numRows() const {
|
|
return getColumn( 0 ).size();
|
|
}
|
|
|
|
const TableColumn& SimpleTable::getColumn( const std::string& name) const {
|
|
if (!this->m_jfunc)
|
|
return m_columns.get( name );
|
|
|
|
if (name == "PCOW" || name == "PCOG")
|
|
assertJFuncPressure(false); // this will throw since m_jfunc=true
|
|
return m_columns.get( name );
|
|
}
|
|
|
|
const TableColumn& SimpleTable::getColumn( size_t columnIndex ) const {
|
|
return m_columns.get( columnIndex );
|
|
}
|
|
|
|
|
|
TableColumn& SimpleTable::getColumn( const std::string& name) {
|
|
if (!this->m_jfunc)
|
|
return m_columns.get( name );
|
|
|
|
if (name == "PCOW" || name == "PCOG")
|
|
assertJFuncPressure(false); // this will throw since m_jfunc=true
|
|
return m_columns.get( name );
|
|
}
|
|
|
|
TableColumn& SimpleTable::getColumn( size_t columnIndex ) {
|
|
return m_columns.get( columnIndex );
|
|
}
|
|
|
|
|
|
bool SimpleTable::hasColumn(const std::string& name) const {
|
|
return m_schema.hasColumn( name );
|
|
}
|
|
|
|
double SimpleTable::evaluate(const std::string& columnName, double xPos) const
|
|
{
|
|
const auto& argColumn = getColumn( 0 );
|
|
const auto& valueColumn = getColumn( columnName );
|
|
|
|
const auto index = argColumn.lookup( xPos );
|
|
return valueColumn.eval( index );
|
|
}
|
|
|
|
void SimpleTable::assertJFuncPressure(const bool jf) const {
|
|
if (jf == m_jfunc)
|
|
return;
|
|
if (m_jfunc)
|
|
throw std::invalid_argument("Cannot get pressure column with JFUNC in deck");
|
|
else
|
|
throw std::invalid_argument("Cannot get JFUNC column when JFUNC not in deck");
|
|
}
|
|
}
|