Revert throw, write warning to stderr

* no throw on JFUNC abuse, std::cerr
* removed 'get' from function names
This commit is contained in:
Pål Grønås Drange
2016-11-28 13:48:30 +01:00
committed by Pål Grønås Drange
parent 172725aef8
commit e5de0ca8d1
5 changed files with 77 additions and 75 deletions

View File

@@ -32,61 +32,61 @@ namespace Opm {
const auto& rec = kw.getRecord(0);
const auto& kw_flag = rec.getItem("FLAG").get<std::string>(0);
if (kw_flag == "BOTH")
flag = Flag::BOTH;
m_flag = Flag::BOTH;
else if (kw_flag == "WATER")
flag = Flag::WATER;
m_flag = Flag::WATER;
else if (kw_flag == "GAS")
flag = Flag::GAS;
m_flag = Flag::GAS;
else
throw std::invalid_argument("Illegal JFUNC FLAG, must be BOTH, WATER, or GAS. Was \"" + kw_flag + "\".");
if (flag != Flag::WATER)
goSurfaceTension = rec.getItem("GO_SURFACE_TENSION").get<double>(0);
if (m_flag != Flag::WATER)
m_goSurfaceTension = rec.getItem("GO_SURFACE_TENSION").get<double>(0);
if (flag != Flag::GAS)
owSurfaceTension = rec.getItem("OW_SURFACE_TENSION").get<double>(0);
if (m_flag != Flag::GAS)
m_owSurfaceTension = rec.getItem("OW_SURFACE_TENSION").get<double>(0);
alphaFactor = rec.getItem("ALPHA_FACTOR").get<double>(0);
betaFactor = rec.getItem("BETA_FACTOR").get<double>(0);
m_alphaFactor = rec.getItem("ALPHA_FACTOR").get<double>(0);
m_betaFactor = rec.getItem("BETA_FACTOR").get<double>(0);
const auto kw_dir = rec.getItem("DIRECTION").get<std::string>(0);
if (kw_dir == "XY")
direction = Direction::XY;
m_direction = Direction::XY;
else if (kw_dir == "X")
direction = Direction::X;
m_direction = Direction::X;
else if (kw_dir == "Y")
direction = Direction::Y;
m_direction = Direction::Y;
else if (kw_dir == "Z")
direction = Direction::Z;
m_direction = Direction::Z;
else
throw std::invalid_argument("Illegal JFUNC DIRECTION, must be XY, X, Y, or Z. Was \"" + kw_dir + "\".");
}
double JFunc::getAlphaFactor() const {
return alphaFactor;
double JFunc::alphaFactor() const {
return m_alphaFactor;
}
double JFunc::getBetaFactor() const {
return betaFactor;
double JFunc::betaFactor() const {
return m_betaFactor;
}
double JFunc::getgoSurfaceTension() const {
if (flag == JFunc::Flag::WATER)
double JFunc::goSurfaceTension() const {
if (m_flag == JFunc::Flag::WATER)
throw std::invalid_argument("Cannot get gas-oil with WATER JFUNC");
return goSurfaceTension;
return m_goSurfaceTension;
}
double JFunc::getowSurfaceTension() const {
if (flag == JFunc::Flag::GAS)
double JFunc::owSurfaceTension() const {
if (m_flag == JFunc::Flag::GAS)
throw std::invalid_argument("Cannot get oil-water with GAS JFUNC");
return owSurfaceTension;
return m_owSurfaceTension;
}
const JFunc::Flag& JFunc::getJFuncFlag() const {
return flag;
const JFunc::Flag& JFunc::flag() const {
return m_flag;
}
const JFunc::Direction& JFunc::getDirection() const {
return direction;
const JFunc::Direction& JFunc::direction() const {
return m_direction;
}
} // Opm::

View File

@@ -33,21 +33,21 @@ public:
enum class Direction { XY, X, Y, Z };
JFunc(const Deck& deck);
double getAlphaFactor() const;
double getBetaFactor() const;
double getgoSurfaceTension() const;
double getowSurfaceTension() const;
const Flag& getJFuncFlag() const;
const Direction& getDirection() const;
double alphaFactor() const;
double betaFactor() const;
double goSurfaceTension() const;
double owSurfaceTension() const;
const Flag& flag() const;
const Direction& direction() const;
operator bool() const { return m_exists; }
private:
Flag flag; // JFUNC flag: WATER, GAS, or BOTH. Default BOTH
double owSurfaceTension; // oil-wat surface tension. Required if flag is BOTH or WATER
double goSurfaceTension; // gas-oil surface tension. Required if flag is BOTH or GAS
double alphaFactor; // alternative porosity term. Default 0.5
double betaFactor; // alternative permeability term. Default 0.5
Direction direction; // XY, X, Y, Z. Default XY
Flag m_flag; // JFUNC flag: WATER, GAS, or BOTH. Default BOTH
double m_owSurfaceTension; // oil-wat surface tension. Required if flag is BOTH or WATER
double m_goSurfaceTension; // gas-oil surface tension. Required if flag is BOTH or GAS
double m_alphaFactor; // alternative porosity term. Default 0.5
double m_betaFactor; // alternative permeability term. Default 0.5
Direction m_direction; // XY, X, Y, Z. Default XY
const bool m_exists; // will be true if JFunc is specified in the deck
};
} // Opm::

View File

@@ -1,5 +1,5 @@
/*
Copyright (C) 2013 by Andreas Lauser
Copyright (C) 2013 by Andreas Lauser, 2016 Statoil ASA
This file is part of the Open Porous Media project (OPM).
@@ -149,9 +149,12 @@ namespace Opm {
void SimpleTable::assertJFuncPressure(const bool jf) const {
if (jf == m_jfunc)
return;
// if we reach here, wrong values are read from the deck! (JFUNC is used
// incorrectly.) This function writes to std err for now, but will
// after a grace period be rewritten to throw (std::invalid_argument).
if (m_jfunc)
throw std::invalid_argument("Cannot get pressure column with JFUNC in deck");
std::cerr << "Developer warning: Pressure column is read with JFUNC in deck." << std::endl;
else
throw std::invalid_argument("Cannot get JFUNC column when JFUNC not in deck");
std::cerr << "Developer warning: Raw values from JFUNC column is read, but JFUNC not provided in deck." << std::endl;
}
}

View File

@@ -629,29 +629,29 @@ GasvisctTable::GasvisctTable( const Deck& deck, const DeckItem& deckItem ) {
if ( deckItem.size() % numColumns() != 0)
throw std::runtime_error("Number of columns in the data file is inconsistent "
"with the expected number for keyword GASVISCT");
"with the expected number for keyword GASVISCT");
size_t rows = deckItem.size() / m_schema.size();
for (size_t columnIndex=0; columnIndex < m_schema.size(); columnIndex++) {
auto& column = getColumn( columnIndex );
for (size_t rowIdx = 0; rowIdx < rows; rowIdx++) {
size_t deckIndex = rowIdx * m_schema.size() + columnIndex;
size_t rows = deckItem.size() / m_schema.size();
for (size_t columnIndex=0; columnIndex < m_schema.size(); columnIndex++) {
auto& column = getColumn( columnIndex );
for (size_t rowIdx = 0; rowIdx < rows; rowIdx++) {
size_t deckIndex = rowIdx * m_schema.size() + columnIndex;
if (deckItem.defaultApplied( deckIndex ))
column.addDefault();
else {
double rawValue = deckItem.get< double >( deckIndex );
double SIValue;
if (deckItem.defaultApplied( deckIndex ))
column.addDefault();
else {
double rawValue = deckItem.get< double >( deckIndex );
double SIValue;
if (columnIndex == 0)
SIValue = temperatureDimension.convertRawToSi(rawValue);
else
SIValue = viscosityDimension.convertRawToSi(rawValue);
if (columnIndex == 0)
SIValue = temperatureDimension.convertRawToSi(rawValue);
else
SIValue = viscosityDimension.convertRawToSi(rawValue);
column.addValue( SIValue );
}
column.addValue( SIValue );
}
}
}
}
const TableColumn& GasvisctTable::getTemperatureColumn() const {

View File

@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE( CreateTablesWithJFunc ) {
for (size_t tab = 0; tab < swfnTab.size(); tab++) {
const auto& t = swfnTab.getTable(tab);
BOOST_CHECK_THROW( t.getColumn("PCOW"), std::invalid_argument );
//TODO uncomment BOOST_CHECK_THROW( t.getColumn("PCOW"), std::invalid_argument );
for (size_t c_idx = 0; c_idx < t.numColumns(); c_idx++) {
const auto& col = t.getColumn(c_idx);
@@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE( CreateTablesWithJFunc ) {
}
const auto& tt = swfnTab.getTable<Opm::SwfnTable>(0);
BOOST_CHECK_THROW(tt.getPcowColumn(), std::invalid_argument);
//TODO uncomment BOOST_CHECK_THROW(tt.getPcowColumn(), std::invalid_argument);
const auto& col = tt.getJFuncColumn();
for (size_t i = 0; i < col.size(); i++) {
@@ -688,9 +688,8 @@ BOOST_AUTO_TEST_CASE(JFuncTestThrowingOnBrokenData) {
BOOST_AUTO_TEST_CASE(JFuncTestThrowingGalore) {
auto deck = createSingleRecordDeckWithVd();
Opm::TableManager tables(deck);
auto tabdims = tables.getTabdims();
BOOST_CHECK(!tables.useJFunc());
BOOST_CHECK_THROW(tables.getJFunc(), std::invalid_argument);
//TODO uncomment BOOST_CHECK_THROW(tables.getJFunc(), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(JFuncTest) {
@@ -699,12 +698,12 @@ BOOST_AUTO_TEST_CASE(JFuncTest) {
BOOST_CHECK(tables.useJFunc());
const Opm::JFunc& jt = tables.getJFunc();
BOOST_CHECK(jt.getJFuncFlag() == Opm::JFunc::Flag::BOTH);
BOOST_CHECK_CLOSE(jt.getowSurfaceTension(), 55.0, epsilon());
BOOST_CHECK_CLOSE(jt.getgoSurfaceTension(), 88.0, epsilon());
BOOST_CHECK_CLOSE(jt.getAlphaFactor(), 0.5, epsilon()); // default
BOOST_CHECK_CLOSE(jt.getBetaFactor(), 0.5, epsilon()); // default
BOOST_CHECK(jt.getDirection() == Opm::JFunc::Direction::XY); // default
BOOST_CHECK(jt.flag() == Opm::JFunc::Flag::BOTH);
BOOST_CHECK_CLOSE(jt.owSurfaceTension(), 55.0, epsilon());
BOOST_CHECK_CLOSE(jt.goSurfaceTension(), 88.0, epsilon());
BOOST_CHECK_CLOSE(jt.alphaFactor(), 0.5, epsilon()); // default
BOOST_CHECK_CLOSE(jt.betaFactor(), 0.5, epsilon()); // default
BOOST_CHECK(jt.direction() == Opm::JFunc::Direction::XY); // default
// full specification = WATER 2.7182 3.1416 0.6 0.7 Z
const auto deck2 = createSingleRecordDeckWithFullJFunc();
@@ -712,12 +711,12 @@ BOOST_AUTO_TEST_CASE(JFuncTest) {
BOOST_CHECK(tables2.useJFunc());
const auto& jt2 = tables2.getJFunc();
BOOST_CHECK(jt2.getJFuncFlag() == Opm::JFunc::Flag::WATER);
BOOST_CHECK_CLOSE(jt2.getowSurfaceTension(), 2.7182, epsilon());
BOOST_CHECK_THROW(jt2.getgoSurfaceTension(), std::invalid_argument);
BOOST_CHECK_CLOSE(jt2.getAlphaFactor(), 0.6, epsilon()); // default
BOOST_CHECK_CLOSE(jt2.getBetaFactor(), 0.7, epsilon()); // default
BOOST_CHECK(jt2.getDirection() == Opm::JFunc::Direction::Z); // default
BOOST_CHECK(jt2.flag() == Opm::JFunc::Flag::WATER);
BOOST_CHECK_CLOSE(jt2.owSurfaceTension(), 2.7182, epsilon());
BOOST_CHECK_THROW(jt2.goSurfaceTension(), std::invalid_argument);
BOOST_CHECK_CLOSE(jt2.alphaFactor(), 0.6, epsilon()); // default
BOOST_CHECK_CLOSE(jt2.betaFactor(), 0.7, epsilon()); // default
BOOST_CHECK(jt2.direction() == Opm::JFunc::Direction::Z); // default
}