UAD usage hashing based on udqstring and controltype
This commit is contained in:
committed by
Jostein Alvestad
parent
79da1ba5eb
commit
44ddd382a3
@@ -36,17 +36,28 @@ class UDQActive {
|
||||
public:
|
||||
|
||||
struct Record{
|
||||
std::size_t input_index;
|
||||
public:
|
||||
Record(const std::string& udq_arg, std::size_t input_index_arg, const std::string& wgname_arg, UDAControl control_arg) :
|
||||
udq(udq_arg),
|
||||
input_index(input_index_arg),
|
||||
wgname(wgname_arg),
|
||||
control(control_arg),
|
||||
uad_code(UDQ::uadCode(control_arg)),
|
||||
active(true),
|
||||
use_count(1)
|
||||
{}
|
||||
|
||||
std::string udq;
|
||||
std::size_t input_index;
|
||||
std::string wgname;
|
||||
UDAControl control;
|
||||
bool active;
|
||||
|
||||
// The three elements below are not used internally, but only filled in
|
||||
// when a record is returned from operator[] or get().
|
||||
std::size_t use_count;
|
||||
std::size_t use_index;
|
||||
int uad_code;
|
||||
bool active;
|
||||
std::size_t use_count;
|
||||
|
||||
// The elements below are not used internally, but only filled in
|
||||
// when a record is returned from operator[] or get().
|
||||
std::size_t use_index;
|
||||
};
|
||||
|
||||
|
||||
@@ -54,11 +65,9 @@ public:
|
||||
|
||||
std::size_t active_size() const;
|
||||
std::size_t size() const;
|
||||
std::size_t use_count(const std::string& udq) const;
|
||||
std::size_t use_index(const std::string& udq) const;
|
||||
explicit operator bool() const;
|
||||
Record operator[](std::size_t index) const;
|
||||
UDQActive::Record get(const std::string& wgname, UDAControl control);
|
||||
UDQActive::Record get(const std::string& udq, UDAControl control);
|
||||
private:
|
||||
std::string hash(const std::string& wgname, UDAControl control);
|
||||
int add(const UDQConfig& udq_config, const std::string& udq, const std::string& wgname, UDAControl control);
|
||||
@@ -66,7 +75,6 @@ private:
|
||||
|
||||
std::vector<Record> data;
|
||||
std::unordered_map<std::string, std::size_t> keys;
|
||||
std::unordered_map<std::string, std::size_t> m_use_count;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -41,46 +41,41 @@ UDQActive::operator bool() const {
|
||||
return this->data.size() > 0;
|
||||
}
|
||||
|
||||
std::string UDQActive::hash(const std::string& wgname, UDAControl control) {
|
||||
return wgname + std::to_string(static_cast<int64_t>(control));
|
||||
std::string UDQActive::hash(const std::string& udq, UDAControl control) {
|
||||
return udq + std::to_string(static_cast<int64_t>(control));
|
||||
}
|
||||
|
||||
|
||||
int UDQActive::add(const UDQConfig& udq_config, const std::string& udq, const std::string& wgname, UDAControl control) {
|
||||
auto hash_key = this->hash(wgname, control);
|
||||
auto hash_key = this->hash(udq, control);
|
||||
const auto iter = this->keys.find( hash_key );
|
||||
if (iter == this->keys.end()) {
|
||||
const auto& udq_input = udq_config[udq];
|
||||
auto index = udq_input.index.insert_index;
|
||||
//Record rec(udq, index, wgname, control);
|
||||
|
||||
this->data.push_back( {index, udq, wgname, control, true} );
|
||||
this->data.emplace_back( udq, index, wgname, control);
|
||||
this->keys.insert( std::make_pair(hash_key, index) );
|
||||
} else {
|
||||
auto& record = this->data[iter->second];
|
||||
this->m_use_count[record.udq] -= 1;
|
||||
record.udq = udq;
|
||||
record.use_count += 1;
|
||||
}
|
||||
|
||||
this->m_use_count[udq] += 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int UDQActive::drop(const std::string& wgname, UDAControl control) {
|
||||
if (this->data.empty())
|
||||
return 0;
|
||||
|
||||
auto hash_key = this->hash(wgname, control);
|
||||
int UDQActive::drop(const std::string& udq, UDAControl control) {
|
||||
auto hash_key = this->hash(udq, control);
|
||||
const auto iter = this->keys.find( hash_key );
|
||||
if (iter != this->keys.end()) {
|
||||
auto index = iter->second;
|
||||
auto& record = this->data[index];
|
||||
|
||||
if (record.active)
|
||||
record.active = false;
|
||||
|
||||
if (this->m_use_count[record.udq] > 0)
|
||||
this->m_use_count[record.udq] -= 1;
|
||||
if (record.use_count > 0) {
|
||||
record.use_count -= 1;
|
||||
if (record.use_count == 0)
|
||||
record.active = false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -92,13 +87,19 @@ int UDQActive::drop(const std::string& wgname, UDAControl control) {
|
||||
int UDQActive::update(const UDQConfig& udq_config, const UDAValue& uda, const std::string& wgname, UDAControl control) {
|
||||
if (uda.is<std::string>())
|
||||
return this->add(udq_config, uda.get<std::string>(), wgname, control);
|
||||
else
|
||||
return this->drop(wgname, control);
|
||||
else {
|
||||
if (this->data.empty())
|
||||
return 0;
|
||||
|
||||
// Can not drop a UDQ - do not know which name it used to have.
|
||||
std::string udq = "UNKNWON";
|
||||
return this->drop(udq, control);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UDQActive::Record UDQActive::get(const std::string& wgname, UDAControl control) {
|
||||
auto hash_key = this->hash(wgname, control);
|
||||
UDQActive::Record UDQActive::get(const std::string& udq, UDAControl control) {
|
||||
auto hash_key = this->hash(udq, control);
|
||||
auto index = this->keys.at(hash_key);
|
||||
return this->operator[](index);
|
||||
}
|
||||
@@ -106,14 +107,13 @@ UDQActive::Record UDQActive::get(const std::string& wgname, UDAControl control)
|
||||
UDQActive::Record UDQActive::operator[](std::size_t index) const {
|
||||
Record data_record = this->data[index];
|
||||
|
||||
data_record.use_count = this->use_count(data_record.udq);
|
||||
data_record.uad_code = UDQ::uadCode(data_record.control);
|
||||
data_record.use_index = 1;
|
||||
if (index > 0) {
|
||||
for (std::size_t i=0; i < (index - 1); i++) {
|
||||
const auto& prev_record = this->data[i];
|
||||
if (prev_record.active)
|
||||
data_record.use_index += this->use_count(prev_record.udq);
|
||||
data_record.use_index += prev_record.use_count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,21 +121,6 @@ UDQActive::Record UDQActive::operator[](std::size_t index) const {
|
||||
return data_record;
|
||||
}
|
||||
|
||||
std::size_t UDQActive::use_count(const std::string& udq) const {
|
||||
const auto iter = this->m_use_count.find(udq);
|
||||
if (iter == this->m_use_count.end())
|
||||
return 0;
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
std::size_t UDQActive::use_index(const std::string& udq) const {
|
||||
const auto iter = this->m_use_count.find(udq);
|
||||
if (iter == this->m_use_count.end())
|
||||
return 0;
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1249,20 +1249,19 @@ BOOST_AUTO_TEST_CASE(UDQ_USAGE) {
|
||||
UDQParams params;
|
||||
UDQConfig conf(params);
|
||||
BOOST_CHECK_EQUAL( usage.active_size(), 0 );
|
||||
BOOST_CHECK_EQUAL( usage.use_count("UDQ"), 0);
|
||||
|
||||
UDAValue uda1("WUX");
|
||||
conf.add_assign(uda1.get<std::string>(), {}, 100);
|
||||
|
||||
usage.update(conf, uda1, "W1", UDAControl::WCONPROD_ORAT);
|
||||
BOOST_CHECK_EQUAL( usage.active_size(), 1 );
|
||||
BOOST_CHECK_EQUAL( usage.use_count("WUX"), 1);
|
||||
BOOST_CHECK_EQUAL( usage.get(uda1.get<std::string>(), UDAControl::WCONPROD_ORAT).use_count, 1);
|
||||
|
||||
usage.update(conf, uda1, "W1", UDAControl::WCONPROD_GRAT);
|
||||
BOOST_CHECK_EQUAL( usage.active_size(), 2 );
|
||||
BOOST_CHECK_EQUAL( usage.use_count("WUX"), 2);
|
||||
BOOST_CHECK_EQUAL( usage.get(uda1.get<std::string>(), UDAControl::WCONPROD_GRAT).use_count, 1);
|
||||
|
||||
const auto& rec = usage.get("W1", UDAControl::WCONPROD_ORAT);
|
||||
const auto& rec = usage.get(uda1.get<std::string>(), UDAControl::WCONPROD_ORAT);
|
||||
BOOST_CHECK_EQUAL(rec.wgname, "W1");
|
||||
BOOST_CHECK_EQUAL(rec.udq, "WUX");
|
||||
BOOST_CHECK(rec.control == UDAControl::WCONPROD_ORAT);
|
||||
@@ -1282,13 +1281,6 @@ BOOST_AUTO_TEST_CASE(UDQ_USAGE) {
|
||||
index += 1;
|
||||
}
|
||||
|
||||
|
||||
UDAValue uda2(100);
|
||||
usage.update(conf, uda2, "W1", UDAControl::WCONPROD_ORAT);
|
||||
BOOST_CHECK_EQUAL(usage[0].active, false);
|
||||
BOOST_CHECK_EQUAL(usage[1].active, true);
|
||||
BOOST_CHECK_EQUAL( usage.use_count("WUX"), 1);
|
||||
BOOST_CHECK_EQUAL( 1, usage.active_size());
|
||||
}
|
||||
|
||||
|
||||
@@ -1324,44 +1316,9 @@ BOOST_AUTO_TEST_CASE(IntegrationTest) {
|
||||
BOOST_CHECK(active[2].active == true);
|
||||
BOOST_CHECK(active[3].active == true);
|
||||
|
||||
BOOST_CHECK(active.use_count("WUOPRL") == 1);
|
||||
BOOST_CHECK(active.use_count("WULPRL") == 1);
|
||||
BOOST_CHECK(active.use_count("WUOPRU") == 1);
|
||||
BOOST_CHECK(active.use_count("WULPRU") == 1);
|
||||
}
|
||||
|
||||
{
|
||||
const auto& active = schedule.udqActive(6);
|
||||
BOOST_CHECK_EQUAL(active.size(), 4);
|
||||
|
||||
BOOST_CHECK(active[0].control == UDAControl::WCONPROD_ORAT);
|
||||
BOOST_CHECK(active[1].control == UDAControl::WCONPROD_LRAT);
|
||||
BOOST_CHECK(active[2].control == UDAControl::WCONPROD_ORAT);
|
||||
BOOST_CHECK(active[3].control == UDAControl::WCONPROD_LRAT);
|
||||
|
||||
BOOST_CHECK(active[0].wgname == "OPL02");
|
||||
BOOST_CHECK(active[1].wgname == "OPL02");
|
||||
BOOST_CHECK(active[2].wgname == "OPU02");
|
||||
BOOST_CHECK(active[3].wgname == "OPU02");
|
||||
|
||||
BOOST_CHECK(active[0].udq == "WUOPRL");
|
||||
BOOST_CHECK(active[1].udq == "WULPRL");
|
||||
BOOST_CHECK(active[2].udq == "WUOPRU");
|
||||
BOOST_CHECK(active[3].udq == "WULPRU");
|
||||
|
||||
BOOST_CHECK(active[0].input_index == 0);
|
||||
BOOST_CHECK(active[1].input_index == 1);
|
||||
BOOST_CHECK(active[2].input_index == 2);
|
||||
BOOST_CHECK(active[3].input_index == 3);
|
||||
|
||||
BOOST_CHECK(active[0].active == false);
|
||||
BOOST_CHECK(active[1].active == false);
|
||||
BOOST_CHECK(active[2].active == true);
|
||||
BOOST_CHECK(active[3].active == true);
|
||||
|
||||
BOOST_CHECK_EQUAL(active.use_count("WUOPRL"), 0);
|
||||
BOOST_CHECK_EQUAL(active.use_count("WULPRL"), 0);
|
||||
BOOST_CHECK_EQUAL(active.use_count("WUOPRU"), 1);
|
||||
BOOST_CHECK_EQUAL(active.use_count("WULPRU"), 1);
|
||||
BOOST_CHECK(active[0].use_count == 1);
|
||||
BOOST_CHECK(active[1].use_count == 1);
|
||||
BOOST_CHECK(active[2].use_count == 1);
|
||||
BOOST_CHECK(active[3].use_count == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ END
|
||||
Opm::UDAValue uda4("WULPRU");
|
||||
update_count += udq_act.update(conf, uda4, "PROD2", Opm::UDAControl::WCONPROD_LRAT);
|
||||
|
||||
for (std::size_t index=0; index < udq_act.size(); index++)
|
||||
for (std::size_t index=0; index < udq_act.size(); index++)
|
||||
{
|
||||
const auto & record = udq_act[index];
|
||||
auto ind = record.input_index;
|
||||
@@ -464,7 +464,6 @@ END
|
||||
}
|
||||
|
||||
|
||||
|
||||
//int main(int argc, char* argv[])
|
||||
struct SimulationCase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user