Merge pull request #3642 from joakim-hove/remove-groupstate-dump

Remove debugging aid GroupState::dump
This commit is contained in:
Joakim Hove 2021-11-01 17:51:32 +01:00 committed by GitHub
commit 101b277bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 84 deletions

View File

@ -268,70 +268,4 @@ bool GroupState::has_gpmaint_target(const std::string& gname) const {
return (this->m_gpmaint_target.count(gname) > 0);
}
//-------------------------------------------------------------------------
namespace {
template <typename T>
void dump_vector(Json::JsonObject& root, const std::string& key, const std::vector<T>& data) {
auto data_obj = root.add_array(key);
for (const auto& rate : data)
data_obj.add(rate);
}
template <typename T>
void dump_groupmap(Json::JsonObject& root, const std::string& key, const std::map<std::string, std::vector<T>>& group_data) {
auto map_obj = root.add_object(key);
for (const auto& [gname, data] : group_data)
dump_vector(map_obj, gname, data);
}
template <typename T>
void dump_groupmap(Json::JsonObject& root, const std::string& key, const std::map<std::string, T>& group_data) {
auto map_obj = root.add_object(key);
for (const auto& [gname, value] : group_data)
map_obj.add_item(gname, value);
}
}
std::string GroupState::dump() const
{
Json::JsonObject root;
dump_groupmap(root, "production_rates", this->m_production_rates);
dump_groupmap(root, "prod_red_rates", this->prod_red_rates);
dump_groupmap(root, "inj_red_rates", this->inj_red_rates);
dump_groupmap(root, "inj_resv_rates", this->inj_resv_rates);
dump_groupmap(root, "inj_rein_rates", this->inj_rein_rates);
dump_groupmap(root, "vrep_rate", this->inj_vrep_rate);
dump_groupmap(root, "grat_sales_target", this->m_grat_sales_target);
{
std::map<std::string, int> int_controls;
for (const auto& [gname, control] : this->production_controls)
int_controls.insert({gname, static_cast<int>(control)});
dump_groupmap(root, "production_controls", int_controls);
}
{
std::map<std::string, std::vector<std::pair<Opm::Phase, Group::InjectionCMode>>> inj_cntrl;
for (const auto& [phase_name, cmode] : this->injection_controls) {
const auto& [phase, gname] = phase_name;
inj_cntrl[gname].emplace_back(phase, cmode);
}
auto map_obj = root.add_object("injection_controls");
for (const auto& [gname, phase_cmode] : inj_cntrl) {
auto group_array = map_obj.add_array(gname);
for (const auto& [phase, cmode] : phase_cmode) {
auto control_pair = group_array.add_array();
control_pair.add(static_cast<int>(phase));
control_pair.add(static_cast<int>(cmode));
}
}
}
return root.to_string();
}
}

View File

@ -159,8 +159,6 @@ public:
throw std::logic_error("Internal size mismatch when distributing groupData");
}
std::string dump() const;
private:
std::size_t num_phases;

View File

@ -237,20 +237,36 @@ public:
return this->wells_.well_index(well_name);
}
const SingleWellState& well(std::size_t well_index) const {
const SingleWellState& operator[](std::size_t well_index) const {
return this->wells_[well_index];
}
const SingleWellState& operator[](const std::string& well_name) const {
return this->wells_[well_name];
}
SingleWellState& operator[](std::size_t well_index) {
return this->wells_[well_index];
}
SingleWellState& operator[](const std::string& well_name) {
return this->wells_[well_name];
}
const SingleWellState& well(std::size_t well_index) const {
return this->operator[](well_index);
}
const SingleWellState& well(const std::string& well_name) const {
return this->wells_[well_name];
return this->operator[](well_name);
}
SingleWellState& well(std::size_t well_index) {
return this->wells_[well_index];
return this->operator[](well_index);
}
SingleWellState& well(const std::string& well_name) {
return this->wells_[well_name];
return this->operator[](well_name);
}
bool has(const std::string& well_name) const {

View File

@ -70,15 +70,3 @@ BOOST_AUTO_TEST_CASE(GroupStateCreate) {
}
BOOST_AUTO_TEST_CASE(GroupStateDump) {
std::size_t num_phases{3};
GroupState gs(num_phases);
std::vector<double> rates{0,1,2};
gs.update_production_rates("AGROUP", rates);
gs.update_injection_rein_rates("CGROUP", rates);
gs.injection_control("AGROUP", Phase::WATER, Group::InjectionCMode::RATE);
gs.injection_control("AGROUP", Phase::GAS, Group::InjectionCMode::RATE);
auto json_string = gs.dump();
Json::JsonObject json_gs(json_string);
}