mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Create new class GroupState to maintain runtime state of groups
This commit is contained in:
parent
c8db0d1090
commit
7fecd9f433
@ -40,6 +40,7 @@ list (APPEND MAIN_SOURCE_FILES
|
|||||||
opm/simulators/utils/DeferredLogger.cpp
|
opm/simulators/utils/DeferredLogger.cpp
|
||||||
opm/simulators/utils/gatherDeferredLogger.cpp
|
opm/simulators/utils/gatherDeferredLogger.cpp
|
||||||
opm/simulators/utils/ParallelRestart.cpp
|
opm/simulators/utils/ParallelRestart.cpp
|
||||||
|
opm/simulators/wells/GroupState.cpp
|
||||||
opm/simulators/wells/ParallelWellInfo.cpp
|
opm/simulators/wells/ParallelWellInfo.cpp
|
||||||
opm/simulators/wells/VFPProdProperties.cpp
|
opm/simulators/wells/VFPProdProperties.cpp
|
||||||
opm/simulators/wells/VFPInjProperties.cpp
|
opm/simulators/wells/VFPInjProperties.cpp
|
||||||
@ -106,6 +107,7 @@ list (APPEND TEST_SOURCE_FILES
|
|||||||
tests/test_parallelwellinfo.cpp
|
tests/test_parallelwellinfo.cpp
|
||||||
tests/test_glift1.cpp
|
tests/test_glift1.cpp
|
||||||
tests/test_keyword_validator.cpp
|
tests/test_keyword_validator.cpp
|
||||||
|
tests/test_GroupState.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(MPI_FOUND)
|
if(MPI_FOUND)
|
||||||
@ -253,6 +255,7 @@ list (APPEND PUBLIC_HEADER_FILES
|
|||||||
opm/simulators/wells/TargetCalculator.hpp
|
opm/simulators/wells/TargetCalculator.hpp
|
||||||
opm/simulators/wells/WellConnectionAuxiliaryModule.hpp
|
opm/simulators/wells/WellConnectionAuxiliaryModule.hpp
|
||||||
opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp
|
opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp
|
||||||
|
opm/simulators/wells/GroupState.hpp
|
||||||
opm/simulators/wells/VFPProperties.hpp
|
opm/simulators/wells/VFPProperties.hpp
|
||||||
opm/simulators/wells/VFPHelpers.hpp
|
opm/simulators/wells/VFPHelpers.hpp
|
||||||
opm/simulators/wells/VFPInjProperties.hpp
|
opm/simulators/wells/VFPInjProperties.hpp
|
||||||
|
237
opm/simulators/wells/GroupState.cpp
Normal file
237
opm/simulators/wells/GroupState.cpp
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 Equinor
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OPM is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <opm/simulators/wells/GroupState.hpp>
|
||||||
|
|
||||||
|
namespace Opm {
|
||||||
|
|
||||||
|
GroupState::GroupState(std::size_t np) :
|
||||||
|
num_phases(np)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool GroupState::operator==(const GroupState& other) const {
|
||||||
|
return this->m_production_rates == other.m_production_rates &&
|
||||||
|
this->production_controls == other.production_controls &&
|
||||||
|
this->prod_red_rates == other.prod_red_rates &&
|
||||||
|
this->inj_red_rates == other.inj_red_rates &&
|
||||||
|
this->inj_resv_rates == other.inj_resv_rates &&
|
||||||
|
this->inj_potentials == other.inj_potentials &&
|
||||||
|
this->inj_rein_rates == other.inj_rein_rates &&
|
||||||
|
this->inj_vrep_rate == other.inj_vrep_rate &&
|
||||||
|
this->m_grat_sales_target == other.m_grat_sales_target &&
|
||||||
|
this->injection_controls == other.injection_controls;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GroupState::has_production_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->m_production_rates.find(gname);
|
||||||
|
return (group_iter != this->m_production_rates.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupState::update_production_rates(const std::string& gname, const std::vector<double>& rates) {
|
||||||
|
if (rates.size() != this->num_phases)
|
||||||
|
throw std::logic_error("Wrong number of phases");
|
||||||
|
|
||||||
|
this->m_production_rates[gname] = rates;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<double>& GroupState::production_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->m_production_rates.find(gname);
|
||||||
|
if (group_iter == this->m_production_rates.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GroupState::has_production_reduction_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->prod_red_rates.find(gname);
|
||||||
|
return (group_iter != this->prod_red_rates.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupState::update_production_reduction_rates(const std::string& gname, const std::vector<double>& rates) {
|
||||||
|
if (rates.size() != this->num_phases)
|
||||||
|
throw std::logic_error("Wrong number of phases");
|
||||||
|
|
||||||
|
this->prod_red_rates[gname] = rates;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<double>& GroupState::production_reduction_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->prod_red_rates.find(gname);
|
||||||
|
if (group_iter == this->prod_red_rates.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GroupState::has_injection_reduction_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_red_rates.find(gname);
|
||||||
|
return (group_iter != this->inj_red_rates.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupState::update_injection_reduction_rates(const std::string& gname, const std::vector<double>& rates) {
|
||||||
|
if (rates.size() != this->num_phases)
|
||||||
|
throw std::logic_error("Wrong number of phases");
|
||||||
|
|
||||||
|
this->inj_red_rates[gname] = rates;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<double>& GroupState::injection_reduction_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_red_rates.find(gname);
|
||||||
|
if (group_iter == this->inj_red_rates.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GroupState::has_injection_reservoir_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_resv_rates.find(gname);
|
||||||
|
return (group_iter != this->inj_resv_rates.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupState::update_injection_reservoir_rates(const std::string& gname, const std::vector<double>& rates) {
|
||||||
|
if (rates.size() != this->num_phases)
|
||||||
|
throw std::logic_error("Wrong number of phases");
|
||||||
|
|
||||||
|
this->inj_resv_rates[gname] = rates;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<double>& GroupState::injection_reservoir_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_resv_rates.find(gname);
|
||||||
|
if (group_iter == this->inj_resv_rates.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GroupState::update_injection_rein_rates(const std::string& gname, const std::vector<double>& rates) {
|
||||||
|
if (rates.size() != this->num_phases)
|
||||||
|
throw std::logic_error("Wrong number of phases");
|
||||||
|
|
||||||
|
this->inj_rein_rates[gname] = rates;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<double>& GroupState::injection_rein_rates(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_rein_rates.find(gname);
|
||||||
|
if (group_iter == this->inj_rein_rates.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GroupState::update_injection_vrep_rate(const std::string& gname, double rate) {
|
||||||
|
this->inj_vrep_rate[gname] = rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
double GroupState::injection_vrep_rate(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_vrep_rate.find(gname);
|
||||||
|
if (group_iter == this->inj_vrep_rate.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GroupState::update_grat_sales_target(const std::string& gname, double target) {
|
||||||
|
this->m_grat_sales_target[gname] = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
double GroupState::grat_sales_target(const std::string& gname) const {
|
||||||
|
auto group_iter = this->m_grat_sales_target.find(gname);
|
||||||
|
if (group_iter == this->m_grat_sales_target.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GroupState::has_grat_sales_target(const std::string& gname) const {
|
||||||
|
return (this->m_grat_sales_target.count(gname) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void GroupState::update_injection_potentials(const std::string& gname, const std::vector<double>& potentials) {
|
||||||
|
if (potentials.size() != this->num_phases)
|
||||||
|
throw std::logic_error("Wrong number of phases");
|
||||||
|
|
||||||
|
this->inj_potentials[gname] = potentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<double>& GroupState::injection_potentials(const std::string& gname) const {
|
||||||
|
auto group_iter = this->inj_potentials.find(gname);
|
||||||
|
if (group_iter == this->inj_potentials.end())
|
||||||
|
throw std::logic_error("No such group");
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GroupState::has_production_control(const std::string& gname) const {
|
||||||
|
auto group_iter = this->production_controls.find(gname);
|
||||||
|
if (group_iter == this->production_controls.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupState::production_control(const std::string& gname, Group::ProductionCMode cmode) {
|
||||||
|
this->production_controls[gname] = cmode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Group::ProductionCMode GroupState::production_control(const std::string& gname) const {
|
||||||
|
auto group_iter = this->production_controls.find(gname);
|
||||||
|
if (group_iter == this->production_controls.end())
|
||||||
|
throw std::logic_error("Could not find any control for production group: " + gname);
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool GroupState::has_injection_control(const std::string& gname, Phase phase) const {
|
||||||
|
return this->injection_controls.count(std::make_pair(phase, gname)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupState::injection_control(const std::string& gname, Phase phase, Group::InjectionCMode cmode) {
|
||||||
|
this->injection_controls[ std::make_pair(phase, gname) ] = cmode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Group::InjectionCMode GroupState::injection_control(const std::string& gname, Phase phase) const {
|
||||||
|
auto key = std::make_pair(phase, gname);
|
||||||
|
auto group_iter = this->injection_controls.find( key );
|
||||||
|
if (group_iter == this->injection_controls.end())
|
||||||
|
throw std::logic_error("Could not find ontrol for injection group: " + gname);
|
||||||
|
|
||||||
|
return group_iter->second;
|
||||||
|
}
|
||||||
|
}
|
168
opm/simulators/wells/GroupState.hpp
Normal file
168
opm/simulators/wells/GroupState.hpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 Equinor
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OPM is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OPM_GROUPSTATE_HEADER_INCLUDED
|
||||||
|
#define OPM_GROUPSTATE_HEADER_INCLUDED
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <opm/core/props/BlackoilPhases.hpp>
|
||||||
|
#include <opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
|
||||||
|
|
||||||
|
namespace Opm {
|
||||||
|
|
||||||
|
class GroupState {
|
||||||
|
public:
|
||||||
|
explicit GroupState(std::size_t num_phases);
|
||||||
|
bool operator==(const GroupState& other) const;
|
||||||
|
|
||||||
|
bool has_production_rates(const std::string& gname) const;
|
||||||
|
void update_production_rates(const std::string& gname, const std::vector<double>& rates);
|
||||||
|
const std::vector<double>& production_rates(const std::string& gname) const;
|
||||||
|
|
||||||
|
bool has_production_reduction_rates(const std::string& gname) const;
|
||||||
|
void update_production_reduction_rates(const std::string& gname, const std::vector<double>& rates);
|
||||||
|
const std::vector<double>& production_reduction_rates(const std::string& gname) const;
|
||||||
|
|
||||||
|
bool has_injection_reduction_rates(const std::string& gname) const;
|
||||||
|
void update_injection_reduction_rates(const std::string& gname, const std::vector<double>& rates);
|
||||||
|
const std::vector<double>& injection_reduction_rates(const std::string& gname) const;
|
||||||
|
|
||||||
|
bool has_injection_reservoir_rates(const std::string& gname) const;
|
||||||
|
void update_injection_reservoir_rates(const std::string& gname, const std::vector<double>& rates);
|
||||||
|
const std::vector<double>& injection_reservoir_rates(const std::string& gname) const;
|
||||||
|
|
||||||
|
void update_injection_rein_rates(const std::string& gname, const std::vector<double>& rates);
|
||||||
|
const std::vector<double>& injection_rein_rates(const std::string& gname) const;
|
||||||
|
|
||||||
|
void update_injection_potentials(const std::string& gname, const std::vector<double>& potentials);
|
||||||
|
const std::vector<double>& injection_potentials(const std::string& gname) const;
|
||||||
|
|
||||||
|
void update_injection_vrep_rate(const std::string& gname, double rate);
|
||||||
|
double injection_vrep_rate(const std::string& gname) const;
|
||||||
|
|
||||||
|
void update_grat_sales_target(const std::string& gname, double target);
|
||||||
|
double grat_sales_target(const std::string& gname) const;
|
||||||
|
bool has_grat_sales_target(const std::string& gname) const;
|
||||||
|
|
||||||
|
bool has_production_control(const std::string& gname) const;
|
||||||
|
void production_control(const std::string& gname, Group::ProductionCMode cmode);
|
||||||
|
Group::ProductionCMode production_control(const std::string& gname) const;
|
||||||
|
|
||||||
|
bool has_injection_control(const std::string& gname, Phase phase) const;
|
||||||
|
void injection_control(const std::string& gname, Phase phase, Group::InjectionCMode cmode);
|
||||||
|
Group::InjectionCMode injection_control(const std::string& gname, Phase phase) const;
|
||||||
|
|
||||||
|
std::size_t data_size() const;
|
||||||
|
std::size_t collect(double * data) const;
|
||||||
|
std::size_t distribute(const double * data);
|
||||||
|
|
||||||
|
|
||||||
|
template<class Comm>
|
||||||
|
void communicate_rates(const Comm& comm)
|
||||||
|
{
|
||||||
|
// Note that injection_group_vrep_rates is handled separate from
|
||||||
|
// the forAllGroupData() function, since it contains single doubles,
|
||||||
|
// not vectors.
|
||||||
|
|
||||||
|
// Create a function that calls some function
|
||||||
|
// for all the individual data items to simplify
|
||||||
|
// the further code.
|
||||||
|
auto iterateContainer = [](auto& container, auto& func) {
|
||||||
|
for (auto& x : container) {
|
||||||
|
func(x.second);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
auto forAllGroupData = [&](auto& func) {
|
||||||
|
iterateContainer(m_production_rates, func);
|
||||||
|
iterateContainer(prod_red_rates, func);
|
||||||
|
iterateContainer(inj_red_rates, func);
|
||||||
|
iterateContainer(inj_resv_rates, func);
|
||||||
|
iterateContainer(inj_rein_rates, func);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Compute the size of the data.
|
||||||
|
std::size_t sz = 0;
|
||||||
|
auto computeSize = [&sz](const auto& v) {
|
||||||
|
sz += v.size();
|
||||||
|
};
|
||||||
|
forAllGroupData(computeSize);
|
||||||
|
sz += this->inj_vrep_rate.size();
|
||||||
|
|
||||||
|
// Make a vector and collect all data into it.
|
||||||
|
std::vector<double> data(sz);
|
||||||
|
std::size_t pos = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// That the collect function mutates the vector v is an artifact for
|
||||||
|
// testing.
|
||||||
|
auto collect = [&data, &pos](auto& v) {
|
||||||
|
for (auto& x : v) {
|
||||||
|
data[pos++] = x;
|
||||||
|
x = -1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
forAllGroupData(collect);
|
||||||
|
for (const auto& x : this->inj_vrep_rate) {
|
||||||
|
data[pos++] = x.second;
|
||||||
|
}
|
||||||
|
if (pos != sz)
|
||||||
|
throw std::logic_error("Internal size mismatch when collecting groupData");
|
||||||
|
|
||||||
|
// Communicate it with a single sum() call.
|
||||||
|
comm.sum(data.data(), data.size());
|
||||||
|
|
||||||
|
// Distribute the summed vector to the data items.
|
||||||
|
pos = 0;
|
||||||
|
auto distribute = [&data, &pos](auto& v) {
|
||||||
|
for (auto& x : v) {
|
||||||
|
x = data[pos++];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
forAllGroupData(distribute);
|
||||||
|
for (auto& x : this->inj_vrep_rate) {
|
||||||
|
x.second = data[pos++];
|
||||||
|
}
|
||||||
|
if (pos != sz)
|
||||||
|
throw std::logic_error("Internal size mismatch when distributing groupData");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::size_t num_phases;
|
||||||
|
std::map<std::string, std::vector<double>> m_production_rates;
|
||||||
|
std::map<std::string, Group::ProductionCMode> production_controls;
|
||||||
|
std::map<std::string, std::vector<double>> prod_red_rates;
|
||||||
|
std::map<std::string, std::vector<double>> inj_red_rates;
|
||||||
|
std::map<std::string, std::vector<double>> inj_resv_rates;
|
||||||
|
std::map<std::string, std::vector<double>> inj_potentials;
|
||||||
|
std::map<std::string, std::vector<double>> inj_rein_rates;
|
||||||
|
std::map<std::string, double> inj_vrep_rate;
|
||||||
|
std::map<std::string, double> m_grat_sales_target;
|
||||||
|
|
||||||
|
|
||||||
|
std::map<std::pair<Opm::Phase, std::string>, Group::InjectionCMode> injection_controls;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -22,6 +22,7 @@
|
|||||||
#define OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|
#define OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|
||||||
|
|
||||||
#include <opm/simulators/wells/WellState.hpp>
|
#include <opm/simulators/wells/WellState.hpp>
|
||||||
|
#include <opm/simulators/wells/GroupState.hpp>
|
||||||
#include <opm/core/props/BlackoilPhases.hpp>
|
#include <opm/core/props/BlackoilPhases.hpp>
|
||||||
|
|
||||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||||
@ -69,7 +70,8 @@ namespace Opm
|
|||||||
using BaseType :: updateStatus;
|
using BaseType :: updateStatus;
|
||||||
|
|
||||||
explicit WellStateFullyImplicitBlackoil(int num_phases) :
|
explicit WellStateFullyImplicitBlackoil(int num_phases) :
|
||||||
WellState(num_phases)
|
WellState(num_phases),
|
||||||
|
group_state(num_phases)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -412,39 +414,29 @@ namespace Opm
|
|||||||
const std::vector<Well::ProducerCMode>& currentProductionControls() const { return current_production_controls_; }
|
const std::vector<Well::ProducerCMode>& currentProductionControls() const { return current_production_controls_; }
|
||||||
|
|
||||||
bool hasProductionGroupControl(const std::string& groupName) const {
|
bool hasProductionGroupControl(const std::string& groupName) const {
|
||||||
return current_production_group_controls_.count(groupName) > 0;
|
return this->group_state.has_production_control(groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasInjectionGroupControl(const Opm::Phase& phase, const std::string& groupName) const {
|
bool hasInjectionGroupControl(const Opm::Phase& phase, const std::string& groupName) const {
|
||||||
return current_injection_group_controls_.count(std::make_pair(phase, groupName)) > 0;
|
return this->group_state.has_injection_control(groupName, phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One current control per group.
|
/// One current control per group.
|
||||||
void setCurrentProductionGroupControl(const std::string& groupName, const Group::ProductionCMode& groupControl ) {
|
void setCurrentProductionGroupControl(const std::string& groupName, const Group::ProductionCMode& groupControl ) {
|
||||||
current_production_group_controls_[groupName] = groupControl;
|
this->group_state.production_control(groupName, groupControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Group::ProductionCMode& currentProductionGroupControl(const std::string& groupName) const {
|
Group::ProductionCMode currentProductionGroupControl(const std::string& groupName) const {
|
||||||
auto it = current_production_group_controls_.find(groupName);
|
return this->group_state.production_control(groupName);
|
||||||
|
|
||||||
if (it == current_production_group_controls_.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any control for production group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One current control per group.
|
/// One current control per group.
|
||||||
void setCurrentInjectionGroupControl(const Opm::Phase& phase, const std::string& groupName, const Group::InjectionCMode& groupControl ) {
|
void setCurrentInjectionGroupControl(const Opm::Phase& phase, const std::string& groupName, const Group::InjectionCMode& groupControl ) {
|
||||||
current_injection_group_controls_[std::make_pair(phase, groupName)] = groupControl;
|
this->group_state.injection_control(groupName, phase, groupControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Group::InjectionCMode& currentInjectionGroupControl(const Opm::Phase& phase, const std::string& groupName) const {
|
Group::InjectionCMode currentInjectionGroupControl(const Opm::Phase& phase, const std::string& groupName) const {
|
||||||
auto it = current_injection_group_controls_.find(std::make_pair(phase, groupName));
|
return this->group_state.injection_control(groupName, phase);
|
||||||
|
|
||||||
if (it == current_injection_group_controls_.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any control for " << phase << " injection group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentWellRates(const std::string& wellName, const std::vector<double>& rates ) {
|
void setCurrentWellRates(const std::string& wellName, const std::vector<double>& rates ) {
|
||||||
@ -465,117 +457,76 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentProductionGroupRates(const std::string& groupName, const std::vector<double>& rates ) {
|
void setCurrentProductionGroupRates(const std::string& groupName, const std::vector<double>& rates ) {
|
||||||
production_group_rates[groupName] = rates;
|
this->group_state.update_production_rates(groupName, rates);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double>& currentProductionGroupRates(const std::string& groupName) const {
|
const std::vector<double>& currentProductionGroupRates(const std::string& groupName) const {
|
||||||
auto it = production_group_rates.find(groupName);
|
return this->group_state.production_rates(groupName);
|
||||||
|
|
||||||
if (it == production_group_rates.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any rates for productino group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasProductionGroupRates(const std::string& groupName) const {
|
bool hasProductionGroupRates(const std::string& groupName) const {
|
||||||
return this->production_group_rates.find(groupName) != this->production_group_rates.end();
|
return this->group_state.has_production_rates(groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setCurrentProductionGroupReductionRates(const std::string& groupName, const std::vector<double>& target ) {
|
void setCurrentProductionGroupReductionRates(const std::string& groupName, const std::vector<double>& target ) {
|
||||||
production_group_reduction_rates[groupName] = target;
|
this->group_state.update_production_reduction_rates(groupName, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double>& currentProductionGroupReductionRates(const std::string& groupName) const {
|
const std::vector<double>& currentProductionGroupReductionRates(const std::string& groupName) const {
|
||||||
auto it = production_group_reduction_rates.find(groupName);
|
return this->group_state.production_reduction_rates(groupName);
|
||||||
|
|
||||||
if (it == production_group_reduction_rates.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any reduction rates for production group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentInjectionGroupReductionRates(const std::string& groupName, const std::vector<double>& target ) {
|
void setCurrentInjectionGroupReductionRates(const std::string& groupName, const std::vector<double>& target ) {
|
||||||
injection_group_reduction_rates[groupName] = target;
|
this->group_state.update_injection_reduction_rates(groupName, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double>& currentInjectionGroupReductionRates(const std::string& groupName) const {
|
const std::vector<double>& currentInjectionGroupReductionRates(const std::string& groupName) const {
|
||||||
auto it = injection_group_reduction_rates.find(groupName);
|
return this->group_state.injection_reduction_rates(groupName);
|
||||||
|
|
||||||
if (it == injection_group_reduction_rates.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any reduction rates for injection group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentInjectionGroupReservoirRates(const std::string& groupName, const std::vector<double>& target ) {
|
void setCurrentInjectionGroupReservoirRates(const std::string& groupName, const std::vector<double>& target ) {
|
||||||
injection_group_reservoir_rates[groupName] = target;
|
this->group_state.update_injection_reservoir_rates(groupName, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double>& currentInjectionGroupReservoirRates(const std::string& groupName) const {
|
const std::vector<double>& currentInjectionGroupReservoirRates(const std::string& groupName) const {
|
||||||
auto it = injection_group_reservoir_rates.find(groupName);
|
return this->group_state.injection_reservoir_rates(groupName);
|
||||||
|
|
||||||
if (it == injection_group_reservoir_rates.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any reservoir rates for injection group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentInjectionVREPRates(const std::string& groupName, const double& target ) {
|
void setCurrentInjectionVREPRates(const std::string& groupName, const double& target ) {
|
||||||
injection_group_vrep_rates[groupName] = target;
|
this->group_state.update_injection_vrep_rate(groupName, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
const double& currentInjectionVREPRates(const std::string& groupName) const {
|
double currentInjectionVREPRates(const std::string& groupName) const {
|
||||||
auto it = injection_group_vrep_rates.find(groupName);
|
return this->group_state.injection_vrep_rate(groupName);
|
||||||
|
|
||||||
if (it == injection_group_vrep_rates.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any VREP rates for group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentInjectionREINRates(const std::string& groupName, const std::vector<double>& target ) {
|
void setCurrentInjectionREINRates(const std::string& groupName, const std::vector<double>& target ) {
|
||||||
injection_group_rein_rates[groupName] = target;
|
this->group_state.update_injection_rein_rates(groupName, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double>& currentInjectionREINRates(const std::string& groupName) const {
|
const std::vector<double>& currentInjectionREINRates(const std::string& groupName) const {
|
||||||
auto it = injection_group_rein_rates.find(groupName);
|
return this->group_state.injection_rein_rates(groupName);
|
||||||
|
|
||||||
if (it == injection_group_rein_rates.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any REIN rates for group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentGroupGratTargetFromSales(const std::string& groupName, const double& target ) {
|
void setCurrentGroupGratTargetFromSales(const std::string& groupName, const double& target ) {
|
||||||
group_grat_target_from_sales[groupName] = target;
|
this->group_state.update_grat_sales_target(groupName, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasGroupGratTargetFromSales(const std::string& groupName) const {
|
bool hasGroupGratTargetFromSales(const std::string& groupName) const {
|
||||||
auto it = group_grat_target_from_sales.find(groupName);
|
return this->group_state.has_grat_sales_target(groupName);
|
||||||
return it != group_grat_target_from_sales.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const double& currentGroupGratTargetFromSales(const std::string& groupName) const {
|
double currentGroupGratTargetFromSales(const std::string& groupName) const {
|
||||||
auto it = group_grat_target_from_sales.find(groupName);
|
return this->group_state.grat_sales_target(groupName);
|
||||||
|
|
||||||
if (it == group_grat_target_from_sales.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any grat target from sales for group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentGroupInjectionPotentials(const std::string& groupName, const std::vector<double>& pot ) {
|
void setCurrentGroupInjectionPotentials(const std::string& groupName, const std::vector<double>& pot ) {
|
||||||
injection_group_potentials[groupName] = pot;
|
this->group_state.update_injection_potentials(groupName, pot);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double>& currentGroupInjectionPotentials(const std::string& groupName) const {
|
const std::vector<double>& currentGroupInjectionPotentials(const std::string& groupName) const {
|
||||||
auto it = injection_group_potentials.find(groupName);
|
return this->group_state.injection_potentials(groupName);
|
||||||
|
|
||||||
if (it == injection_group_potentials.end())
|
|
||||||
OPM_THROW(std::logic_error, "Could not find any potentials for group " << groupName);
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data::Wells
|
data::Wells
|
||||||
@ -1141,11 +1092,6 @@ namespace Opm
|
|||||||
// Create a function that calls some function
|
// Create a function that calls some function
|
||||||
// for all the individual data items to simplify
|
// for all the individual data items to simplify
|
||||||
// the further code.
|
// the further code.
|
||||||
auto iterateContainer = [](auto& container, auto& func) {
|
|
||||||
for (auto& x : container) {
|
|
||||||
func(x.second);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
auto iterateRatesContainer = [](auto& container, auto& func) {
|
auto iterateRatesContainer = [](auto& container, auto& func) {
|
||||||
for (auto& x : container) {
|
for (auto& x : container) {
|
||||||
if (x.second.first)
|
if (x.second.first)
|
||||||
@ -1163,22 +1109,13 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto forAllGroupData = [&](auto& func) {
|
|
||||||
iterateContainer(injection_group_rein_rates, func);
|
|
||||||
iterateContainer(production_group_reduction_rates, func);
|
|
||||||
iterateContainer(injection_group_reduction_rates, func);
|
|
||||||
iterateContainer(injection_group_reservoir_rates, func);
|
|
||||||
iterateContainer(production_group_rates, func);
|
|
||||||
iterateRatesContainer(well_rates, func);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Compute the size of the data.
|
// Compute the size of the data.
|
||||||
std::size_t sz = 0;
|
std::size_t sz = 0;
|
||||||
auto computeSize = [&sz](const auto& v) {
|
auto computeSize = [&sz](const auto& v) {
|
||||||
sz += v.size();
|
sz += v.size();
|
||||||
};
|
};
|
||||||
forAllGroupData(computeSize);
|
iterateRatesContainer(this->well_rates, computeSize);
|
||||||
sz += injection_group_vrep_rates.size();
|
|
||||||
sz += current_alq_.size();
|
sz += current_alq_.size();
|
||||||
|
|
||||||
// Make a vector and collect all data into it.
|
// Make a vector and collect all data into it.
|
||||||
@ -1189,10 +1126,7 @@ namespace Opm
|
|||||||
data[pos++] = x;
|
data[pos++] = x;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
forAllGroupData(collect);
|
iterateRatesContainer(this->well_rates, collect);
|
||||||
for (const auto& x : injection_group_vrep_rates) {
|
|
||||||
data[pos++] = x.second;
|
|
||||||
}
|
|
||||||
for (const auto& x : current_alq_) {
|
for (const auto& x : current_alq_) {
|
||||||
data[pos++] = x.second;
|
data[pos++] = x.second;
|
||||||
}
|
}
|
||||||
@ -1208,14 +1142,13 @@ namespace Opm
|
|||||||
x = data[pos++];
|
x = data[pos++];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
forAllGroupData(distribute);
|
iterateRatesContainer(this->well_rates, distribute);
|
||||||
for (auto& x : injection_group_vrep_rates) {
|
|
||||||
x.second = data[pos++];
|
|
||||||
}
|
|
||||||
for (auto& x : current_alq_) {
|
for (auto& x : current_alq_) {
|
||||||
x.second = data[pos++];
|
x.second = data[pos++];
|
||||||
}
|
}
|
||||||
assert(pos == sz);
|
assert(pos == sz);
|
||||||
|
|
||||||
|
this->group_state.communicate_rates(comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Comm>
|
template<class Comm>
|
||||||
@ -1391,19 +1324,10 @@ namespace Opm
|
|||||||
std::vector<int> globalIsInjectionGrup_;
|
std::vector<int> globalIsInjectionGrup_;
|
||||||
std::vector<int> globalIsProductionGrup_;
|
std::vector<int> globalIsProductionGrup_;
|
||||||
std::map<std::string, int> wellNameToGlobalIdx_;
|
std::map<std::string, int> wellNameToGlobalIdx_;
|
||||||
|
|
||||||
std::map<std::string, Group::ProductionCMode> current_production_group_controls_;
|
|
||||||
std::map<std::pair<Opm::Phase, std::string>, Group::InjectionCMode> current_injection_group_controls_;
|
|
||||||
|
|
||||||
std::map<std::string, std::pair<bool, std::vector<double>>> well_rates;
|
std::map<std::string, std::pair<bool, std::vector<double>>> well_rates;
|
||||||
std::map<std::string, std::vector<double>> production_group_rates;
|
|
||||||
std::map<std::string, std::vector<double>> production_group_reduction_rates;
|
GroupState group_state;
|
||||||
std::map<std::string, std::vector<double>> injection_group_reduction_rates;
|
|
||||||
std::map<std::string, std::vector<double>> injection_group_reservoir_rates;
|
|
||||||
std::map<std::string, std::vector<double>> injection_group_potentials;
|
|
||||||
std::map<std::string, double> injection_group_vrep_rates;
|
|
||||||
std::map<std::string, std::vector<double>> injection_group_rein_rates;
|
|
||||||
std::map<std::string, double> group_grat_target_from_sales;
|
|
||||||
std::map<std::string, double> current_alq_;
|
std::map<std::string, double> current_alq_;
|
||||||
std::map<std::string, double> default_alq_;
|
std::map<std::string, double> default_alq_;
|
||||||
std::map<std::string, int> alq_increase_count_;
|
std::map<std::string, int> alq_increase_count_;
|
||||||
|
69
tests/test_GroupState.cpp
Normal file
69
tests/test_GroupState.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 Equinor.
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OPM is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <opm/simulators/wells/GroupState.hpp>
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE GroupStateTest
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
using namespace Opm;
|
||||||
|
|
||||||
|
class TestCommunicator {
|
||||||
|
public:
|
||||||
|
void sum(const double *, std::size_t) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(GroupStateCreate) {
|
||||||
|
std::size_t num_phases{3};
|
||||||
|
GroupState gs(num_phases);
|
||||||
|
|
||||||
|
BOOST_CHECK(!gs.has_production_rates("AGROUP"));
|
||||||
|
BOOST_CHECK_THROW( gs.update_production_rates("AGROUP", {0}), std::exception);
|
||||||
|
|
||||||
|
std::vector<double> rates{0,1,2};
|
||||||
|
gs.update_production_rates("AGROUP", rates);
|
||||||
|
BOOST_CHECK(gs.has_production_rates("AGROUP"));
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW( gs.production_rates("NO_SUCH_GROUP"), std::exception );
|
||||||
|
auto r2 = gs.production_rates("AGROUP");
|
||||||
|
BOOST_CHECK( r2 == rates );
|
||||||
|
|
||||||
|
gs.update_injection_rein_rates("CGROUP", rates);
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_CHECK(!gs.has_production_control("NO_SUCH_GROUP"));
|
||||||
|
BOOST_CHECK(!gs.has_production_control("AGROUP"));
|
||||||
|
|
||||||
|
gs.production_control("AGROUP", Group::ProductionCMode::GRAT);
|
||||||
|
BOOST_CHECK(gs.has_production_control("AGROUP"));
|
||||||
|
BOOST_CHECK(gs.production_control("AGROUP") == Group::ProductionCMode::GRAT);
|
||||||
|
BOOST_CHECK_THROW(gs.production_control("BGROUP"), std::exception);
|
||||||
|
|
||||||
|
|
||||||
|
auto gs2 = gs;
|
||||||
|
BOOST_CHECK(gs2 == gs);
|
||||||
|
TestCommunicator comm;
|
||||||
|
gs.communicate_rates(comm);
|
||||||
|
BOOST_CHECK(gs2 == gs);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user