Skip to content

Commit

Permalink
Added JFUNC in TableManager and getJFuncColumn()
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Pål Grønås Drange committed Dec 28, 2016
1 parent 848d701 commit 172725a
Show file tree
Hide file tree
Showing 18 changed files with 475 additions and 36 deletions.
2 changes: 2 additions & 0 deletions opm/parser/eclipse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ EclipseState/Schedule/GroupTree.cpp
EclipseState/Schedule/Tuning.cpp
EclipseState/Schedule/Events.cpp
#
EclipseState/Tables/JFunc.cpp
EclipseState/Tables/SimpleTable.cpp
EclipseState/Tables/VFPProdTable.cpp
EclipseState/Tables/VFPInjTable.cpp
Expand Down Expand Up @@ -227,6 +228,7 @@ EclipseState/IOConfig/RestartConfig.hpp
EclipseState/IOConfig/IOConfig.hpp
#
EclipseState/Tables/FlatTable.hpp
EclipseState/Tables/JFunc.hpp
EclipseState/Tables/Tabdims.hpp
EclipseState/Tables/Eqldims.hpp
EclipseState/Tables/Regdims.hpp
Expand Down
92 changes: 92 additions & 0 deletions opm/parser/eclipse/EclipseState/Tables/JFunc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2016 Statoil ASA.
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 <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/JFunc.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/J.hpp>

namespace Opm {

JFunc::JFunc(const Deck& deck) :
m_exists(deck.hasKeyword("JFUNC"))
{
if (!m_exists)
return;
const auto& kw = *deck.getKeywordList<ParserKeywords::JFUNC>()[0];
const auto& rec = kw.getRecord(0);
const auto& kw_flag = rec.getItem("FLAG").get<std::string>(0);
if (kw_flag == "BOTH")
flag = Flag::BOTH;
else if (kw_flag == "WATER")
flag = Flag::WATER;
else if (kw_flag == "GAS")
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 (flag != Flag::GAS)
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);

const auto kw_dir = rec.getItem("DIRECTION").get<std::string>(0);
if (kw_dir == "XY")
direction = Direction::XY;
else if (kw_dir == "X")
direction = Direction::X;
else if (kw_dir == "Y")
direction = Direction::Y;
else if (kw_dir == "Z")
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::getBetaFactor() const {
return betaFactor;
}

double JFunc::getgoSurfaceTension() const {
if (flag == JFunc::Flag::WATER)
throw std::invalid_argument("Cannot get gas-oil with WATER JFUNC");
return goSurfaceTension;
}

double JFunc::getowSurfaceTension() const {
if (flag == JFunc::Flag::GAS)
throw std::invalid_argument("Cannot get oil-water with GAS JFUNC");
return owSurfaceTension;
}

const JFunc::Flag& JFunc::getJFuncFlag() const {
return flag;
}

const JFunc::Direction& JFunc::getDirection() const {
return direction;
}
} // Opm::
55 changes: 55 additions & 0 deletions opm/parser/eclipse/EclipseState/Tables/JFunc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2016 Statoil ASA.
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/>.
*/

#ifndef OPM_JFUNC_HPP_
#define OPM_JFUNC_HPP_

#include <opm/parser/eclipse/Deck/Deck.hpp>


namespace Opm {

class JFunc
{
public:

enum class Flag { BOTH, WATER, GAS };
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;
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
const bool m_exists; // will be true if JFunc is specified in the deck
};
} // Opm::

#endif /* OPM_JFUNC_HPP_ */
4 changes: 3 additions & 1 deletion opm/parser/eclipse/EclipseState/Tables/SgfnTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ namespace Opm {
class SgfnTable : public SimpleTable {

public:
SgfnTable( const DeckItem& item );
SgfnTable( const DeckItem& item, const bool jfunc );

const TableColumn& getSgColumn() const;
const TableColumn& getKrgColumn() const;
const TableColumn& getPcogColumn() const;

const TableColumn& getJFuncColumn() const;
};
}

Expand Down
4 changes: 3 additions & 1 deletion opm/parser/eclipse/EclipseState/Tables/SgofTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Opm {
class SgofTable : public SimpleTable {

public:
SgofTable( const DeckItem& item );
SgofTable( const DeckItem& item, const bool jfunc );

const TableColumn& getSgColumn() const;
const TableColumn& getKrgColumn() const;
Expand All @@ -38,6 +38,8 @@ namespace Opm {
// is inconsistent, but it is the one used in the Eclipse
// manual...)
const TableColumn& getPcogColumn() const;

const TableColumn& getJFuncColumn() const;
};
}

Expand Down
31 changes: 27 additions & 4 deletions opm/parser/eclipse/EclipseState/Tables/SimpleTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
namespace Opm {

SimpleTable::SimpleTable( TableSchema schema, const DeckItem& deckItem) :
m_schema( std::move( schema ) ) {

m_schema( std::move( schema ) ),
m_jfunc (false)
{
init( deckItem );
}


SimpleTable::SimpleTable( TableSchema schema ) :
m_schema( std::move( schema ) ) {

m_schema( std::move( schema ) ),
m_jfunc (false)
{
addColumns();
}

Expand Down Expand Up @@ -84,6 +86,9 @@ namespace Opm {
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) );
}
Expand All @@ -101,6 +106,11 @@ namespace Opm {
}

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 );
}

Expand All @@ -110,6 +120,11 @@ namespace Opm {


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 );
}

Expand All @@ -131,4 +146,12 @@ namespace Opm {
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");
}
}
6 changes: 5 additions & 1 deletion opm/parser/eclipse/EclipseState/Tables/SimpleTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Opm {
SimpleTable(TableSchema, const DeckItem& deckItem);
explicit SimpleTable( TableSchema );
void addColumns();
void init(const DeckItem& deckItem);
void init(const DeckItem& deckItem );
size_t numColumns() const;
size_t numRows() const;
void addRow( const std::vector<double>& row);
Expand All @@ -60,11 +60,15 @@ namespace Opm {
*/
double evaluate(const std::string& columnName, double xPos) const;

/// throws std::invalid_argument if jf != m_jfunc
void assertJFuncPressure(const bool jf) const;

protected:
std::map<std::string, size_t> m_columnNames;
std::vector<std::vector<bool> > m_valueDefaulted;
TableSchema m_schema;
OrderedMap<TableColumn> m_columns;
bool m_jfunc = false;
};
}

Expand Down
4 changes: 3 additions & 1 deletion opm/parser/eclipse/EclipseState/Tables/SlgofTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Opm {
class SlgofTable : public SimpleTable {

public:
SlgofTable( const DeckItem& item );
SlgofTable( const DeckItem& item, const bool jfunc );
const TableColumn& getSlColumn() const;
const TableColumn& getKrgColumn() const;
const TableColumn& getKrogColumn() const;
Expand All @@ -38,6 +38,8 @@ namespace Opm {
// is inconsistent, but it is the one used in the Eclipse
// manual...)
const TableColumn& getPcogColumn() const;

const TableColumn& getJFuncColumn() const;
};
}

Expand Down
9 changes: 6 additions & 3 deletions opm/parser/eclipse/EclipseState/Tables/SwfnTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ namespace Opm {
class SwfnTable : public SimpleTable {

public:
SwfnTable( const DeckItem& item );
SwfnTable( const DeckItem& item, const bool jfunc );

const TableColumn& getSwColumn() const;
const TableColumn& getKrwColumn() const;

// this column is p_o - p_w (non-wetting phase pressure minus
// wetting phase pressure for a given water saturation)
/// this column is p_o - p_w (non-wetting phase pressure minus
/// wetting phase pressure for a given water saturation)
const TableColumn& getPcowColumn() const;

/// use this function if JFUNC is set in the deck
const TableColumn& getJFuncColumn() const;
};
}

Expand Down
5 changes: 4 additions & 1 deletion opm/parser/eclipse/EclipseState/Tables/SwofTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ namespace Opm {

class SwofTable : public SimpleTable {
public:
SwofTable( const DeckItem& item );
SwofTable( const DeckItem& item, const bool jfunc );
const TableColumn& getSwColumn() const;
const TableColumn& getKrwColumn() const;
const TableColumn& getKrowColumn() const;

// this column is p_o - p_w (non-wetting phase pressure minus
// wetting phase pressure for a given water saturation)
const TableColumn& getPcowColumn() const;

/// use this function if JFUNC is set in the deck
const TableColumn& getJFuncColumn() const;
};
}

Expand Down
Loading

0 comments on commit 172725a

Please sign in to comment.