DeckKeyword: constr. with records takes unitsystem args.
Deckkeyword constr w/ records also takes unit_systems. DeckKeyword w/ records uses input args to get dims. DeckValue unit system works w/ records. Deckkeyword w/ records: rearranged default/active unit args. .. python deckkeywords: workable. python deckkeyword: testing rewrite. python deckkeyword w/units: most test work. ... python support for deckkeyword w/ dimensions.
This commit is contained in:
committed by
Joakim Hove
parent
1a05f2fcd1
commit
d05b3323b3
@@ -1,5 +1,7 @@
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckValue.hpp>
|
||||
@@ -20,6 +22,9 @@ namespace {
|
||||
const DeckRecord& (DeckKeyword::*getRecord)(size_t index) const = &DeckKeyword::getRecord;
|
||||
|
||||
|
||||
const DeckItem& getItem(const DeckRecord& record, size_t index) {
|
||||
return record.getItem(index);
|
||||
}
|
||||
|
||||
py::list item_to_pylist( const DeckItem& item )
|
||||
{
|
||||
@@ -29,7 +34,7 @@ py::list item_to_pylist( const DeckItem& item )
|
||||
return iterable_to_pylist( item.getData< int >() );
|
||||
break;
|
||||
case type_tag::fdouble:
|
||||
return iterable_to_pylist( item.getData< double >() );
|
||||
throw py::type_error("Double list access must be specified by either 'get_raw_data_list' or 'get_SI_data_list'.");
|
||||
break;
|
||||
case type_tag::string:
|
||||
return iterable_to_pylist( item.getData< std::string >() );
|
||||
@@ -40,24 +45,15 @@ py::list item_to_pylist( const DeckItem& item )
|
||||
}
|
||||
}
|
||||
|
||||
struct DeckRecordIterator
|
||||
{
|
||||
DeckRecordIterator(const DeckRecord* record) {
|
||||
this->record = record;
|
||||
this->it = this->record->begin();
|
||||
}
|
||||
|
||||
const DeckRecord* record;
|
||||
DeckRecord::const_iterator it;
|
||||
py::list raw_data_to_pylist( const DeckItem& item) {
|
||||
return iterable_to_pylist( item.getData<double>() );
|
||||
}
|
||||
|
||||
py::list next() {
|
||||
if (it == record->end()) {
|
||||
PyErr_SetString(PyExc_StopIteration, "At end.");
|
||||
throw py::error_already_set();
|
||||
}
|
||||
return item_to_pylist(*(it++));
|
||||
}
|
||||
};
|
||||
|
||||
py::list SI_data_to_pylist( const DeckItem& item) {
|
||||
return iterable_to_pylist( item.getSIDoubleData() );
|
||||
}
|
||||
|
||||
|
||||
bool is_int(const std::string& s)
|
||||
@@ -107,7 +103,7 @@ void python::common::export_DeckKeyword(py::module& module) {
|
||||
py::class_< DeckKeyword >( module, "DeckKeyword")
|
||||
.def(py::init<const ParserKeyword& >())
|
||||
|
||||
.def(py::init([](const ParserKeyword& parser_keyword, py::list record_list) {
|
||||
.def(py::init([](const ParserKeyword& parser_keyword, py::list record_list, UnitSystem& active_system, UnitSystem& default_system) {
|
||||
|
||||
std::vector< std::vector<DeckValue> > value_record_list;
|
||||
|
||||
@@ -143,7 +139,7 @@ void python::common::export_DeckKeyword(py::module& module) {
|
||||
}
|
||||
value_record_list.push_back( value_record );
|
||||
}
|
||||
return DeckKeyword(parser_keyword, value_record_list);
|
||||
return DeckKeyword(parser_keyword, value_record_list, active_system, default_system);
|
||||
} ) )
|
||||
|
||||
.def( "__repr__", &DeckKeyword::name )
|
||||
@@ -157,22 +153,22 @@ void python::common::export_DeckKeyword(py::module& module) {
|
||||
|
||||
py::class_< DeckRecord >( module, "DeckRecord")
|
||||
.def( "__repr__", &str<DeckRecord> )
|
||||
.def( "__iter__", +[](const DeckRecord& record){
|
||||
return DeckRecordIterator(&record);
|
||||
})
|
||||
.def( "__getitem__", +[](const DeckRecord& record, size_t index){
|
||||
return item_to_pylist( record.getItem(index) );
|
||||
})
|
||||
.def( "__getitem__", +[](const DeckRecord& record, const std::string& name){
|
||||
return item_to_pylist( record.getItem(name) );
|
||||
})
|
||||
.def( "__iter__", +[] (const DeckRecord& record) { return py::make_iterator(record.begin(), record.end()); }, py::keep_alive<0,1>())
|
||||
.def( "__getitem__", &getItem, ref_internal)
|
||||
.def( "__len__", &DeckRecord::size )
|
||||
;
|
||||
|
||||
|
||||
py::class_< DeckRecordIterator >( module, "DeckRecordIterator")
|
||||
.def( "__next__", &DeckRecordIterator::next )
|
||||
.def( "next", &DeckRecordIterator::next )
|
||||
py::class_< DeckItem >(module, "DeckItem")
|
||||
.def( "__len__", &DeckItem::size )
|
||||
.def("get_str", &DeckItem::get<std::string>)
|
||||
.def("get_int", &DeckItem::get<int>)
|
||||
.def("get_raw", &DeckItem::get<double>)
|
||||
.def("get_SI", &DeckItem::getSIDouble)
|
||||
.def("get_data_list", &item_to_pylist)
|
||||
.def("get_raw_data_list", &raw_data_to_pylist)
|
||||
.def("get_SI_data_list", &SI_data_to_pylist)
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user