implemented table lookup for eclipse_state
This commit is contained in:
@@ -22,6 +22,10 @@ class EclipseState(object):
|
||||
def cfg(self):
|
||||
return EclipseConfig(self._cfg())
|
||||
|
||||
@property
|
||||
def table(self):
|
||||
return Tables(self._tables())
|
||||
|
||||
def faults(self):
|
||||
"""Returns a map from fault names to list of (i,j,k,D) where D ~ 'X+'"""
|
||||
fs = {}
|
||||
@@ -43,6 +47,29 @@ class Tables(object):
|
||||
def __repr__(self):
|
||||
return 'Tables()'
|
||||
|
||||
def _eval(self, x, table, col_name, tab_idx = 0):
|
||||
return self._evaluate(table, tab_idx, col_name, x)
|
||||
|
||||
def __getitem__(self, tab_name):
|
||||
col_name = None
|
||||
if isinstance(tab_name, tuple):
|
||||
tab_name, col_name = tab_name
|
||||
|
||||
tab_name = tab_name.upper()
|
||||
if not tab_name in self:
|
||||
raise ValueError('Table "%s" not in deck.' % tab_name)
|
||||
|
||||
if col_name is None:
|
||||
def t_eval(col_name, x, tab_idx = 0):
|
||||
return self._eval(x, tab_name, col_name.upper(), tab_idx)
|
||||
return t_eval
|
||||
|
||||
col_name = col_name.upper()
|
||||
def t_eval(x, tab_idx = 0):
|
||||
return self._eval(x, tab_name, col_name, tab_idx)
|
||||
return t_eval
|
||||
|
||||
|
||||
|
||||
@delegate(lib.EclipseGrid)
|
||||
class EclipseGrid(object):
|
||||
|
||||
@@ -230,6 +230,17 @@ py::list get_groups( const Schedule& sch ) {
|
||||
|
||||
}
|
||||
|
||||
namespace tables {
|
||||
double evaluate( const TableManager& tab,
|
||||
std::string tab_name,
|
||||
int tab_idx,
|
||||
std::string col_name, double x ) try {
|
||||
return tab[tab_name].getTable(tab_idx).evaluate(col_name, x);
|
||||
} catch( std::invalid_argument& e ) {
|
||||
throw key_error( e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
EclipseState (*parse)( const std::string&, const ParseContext& ) = &Parser::parse;
|
||||
EclipseState (*parseData) (const std::string &data, const ParseContext& context) = &Parser::parseData;
|
||||
void (ParseContext::*ctx_update)(const std::string&, InputError::Action) = &ParseContext::update;
|
||||
@@ -262,7 +273,7 @@ py::class_< EclipseState >( "EclipseState", py::no_init )
|
||||
.def( "_props", &EclipseState::get3DProperties, ref() )
|
||||
.def( "_grid", &EclipseState::getInputGrid, ref() )
|
||||
.def( "_cfg", &EclipseState::cfg, ref() )
|
||||
.def( "tables", &EclipseState::getTableManager, ref() )
|
||||
.def( "_tables", &EclipseState::getTableManager, ref() )
|
||||
.def( "has_input_nnc", &EclipseState::hasInputNNC )
|
||||
.def( "input_nnc", state::getNNC )
|
||||
.def( "faultNames", state::faultNames )
|
||||
@@ -286,6 +297,7 @@ py::class_< Eclipse3DProperties >( "Eclipse3DProperties", py::no_init )
|
||||
|
||||
py::class_< TableManager >( "Tables", py::no_init )
|
||||
.def( "__contains__", &TableManager::hasTables )
|
||||
.def("_evaluate", tables::evaluate )
|
||||
;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user