Add operator[] to UDQConfig class
This commit is contained in:
committed by
Jostein Alvestad
parent
1caca2df4a
commit
1a79e811dd
@@ -56,6 +56,8 @@ namespace Opm {
|
||||
// from input().
|
||||
size_t size() const;
|
||||
|
||||
const UDQInput operator[](const std::string& keyword) const;
|
||||
|
||||
std::vector<UDQAssign> assignments() const;
|
||||
std::vector<UDQAssign> assignments(UDQVarType var_type) const;
|
||||
const UDQParams& params() const;
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace Opm {
|
||||
|
||||
/*
|
||||
That a keyword is mentioned with UNITS is enough to consider it
|
||||
as a keyword which is present.
|
||||
as a keyword which is present.
|
||||
*/
|
||||
if (this->units.count(keyword) > 0)
|
||||
return true;
|
||||
@@ -212,6 +212,25 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
const UDQInput UDQConfig::operator[](const std::string& keyword) const {
|
||||
const auto index_iter = this->input_index.find(keyword);
|
||||
if (index_iter == this->input_index.end())
|
||||
throw std::invalid_argument("Keyword: " + keyword + " not recognized as ASSIGN/DEFINE UDQ");
|
||||
|
||||
std::string u;
|
||||
if (this->has_unit(keyword))
|
||||
u = this->unit(keyword);
|
||||
|
||||
if (index_iter->second.action == UDQAction::ASSIGN)
|
||||
return UDQInput(this->input_index.at(keyword), this->m_assignments.at(keyword), u);
|
||||
|
||||
if (index_iter->second.action == UDQAction::DEFINE)
|
||||
return UDQInput(this->input_index.at(keyword), this->m_definitions.at(keyword), u);
|
||||
|
||||
throw std::logic_error("Internal error - should not be here");
|
||||
}
|
||||
|
||||
|
||||
const UDQFunctionTable& UDQConfig::function_table() const {
|
||||
return this->udqft;
|
||||
}
|
||||
|
||||
@@ -1198,6 +1198,8 @@ UDQ
|
||||
BOOST_CHECK_EQUAL( input[6].get<UDQDefine>().keyword(), "FUOPRX");
|
||||
|
||||
BOOST_CHECK( udq.has_keyword("FUXXX") );
|
||||
const auto wubhp1 = udq["WUBHP1"];
|
||||
BOOST_CHECK( wubhp1.is<UDQAssign>() );
|
||||
}
|
||||
|
||||
|
||||
@@ -1232,6 +1234,10 @@ UDQ
|
||||
BOOST_CHECK_EQUAL(udq.size(), 5);
|
||||
|
||||
BOOST_CHECK( input[0].is<UDQDefine>());
|
||||
BOOST_CHECK_EQUAL( input[0].keyword(), "WUBHP1");
|
||||
|
||||
const auto wubhp1 = udq["WUBHP1"];
|
||||
BOOST_CHECK( wubhp1.is<UDQDefine>() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user