Skip to content

Commit

Permalink
Require definition at first report step
Browse files Browse the repository at this point in the history
Require slaves and master groups to be defined at the first report
step
  • Loading branch information
hakonhagland committed Jun 28, 2024
1 parent 50f5759 commit 67fcbd6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
11 changes: 10 additions & 1 deletion opm/input/eclipse/Schedule/ResCoup/GrupSlav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,22 @@ ReservoirCoupling::GrupSlav::FilterFlag getFilterFlag(const DeckItem& keyword, H

void handleGRUPSLAV(HandlerContext& handlerContext)
{
auto rescoup = handlerContext.state().rescoup();
auto schedule_state = handlerContext.state();
auto rescoup = schedule_state.rescoup();
const auto& keyword = handlerContext.keyword;
bool slave_mode = handlerContext.static_schedule().slave_mode;
if (!slave_mode) {
std::string msg = fmt::format("GRUPSLAV is only allowed in slave mode.");
throw OpmInputError(msg, handlerContext.keyword.location());
}
if (schedule_state.sim_step() != 0) {
// Currently, I cannot see any reason why GRUPSLAV should be allowed at
// any other report step than the first one. So to keep it simple, we throw
// an error if it is used in any other step. This will also simplify the
// implementation details of MPI communication between master and slave for now..
std::string msg = fmt::format("GRUPSLAV is only allowed in the first simulation step.");
throw OpmInputError(msg, handlerContext.keyword.location());
}
for (const auto& record : keyword) {
const std::string& group_name =
record.getItem<ParserKeywords::GRUPSLAV::SLAVE_GROUP>().getTrimmedString(0);
Expand Down
16 changes: 15 additions & 1 deletion opm/input/eclipse/Schedule/ResCoup/MasterGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,27 @@ void checkValidSlaveName(const std::string& name, HandlerContext& handlerContext

void handleGRUPMAST(HandlerContext& handlerContext)
{
auto rescoup = handlerContext.state().rescoup();
auto schedule_state = handlerContext.state();
auto rescoup = schedule_state.rescoup();
const auto& keyword = handlerContext.keyword;
bool slave_mode = handlerContext.static_schedule().slave_mode;
if (slave_mode) {
std::string msg = fmt::format("GRUPMAST keyword is not allowed in slave mode.");
throw OpmInputError(msg, handlerContext.keyword.location());
}
if (schedule_state.sim_step() != 0) {
// Currently, I cannot see any reason why GRUPMAST should be allowed at
// any other report step than the first one. So to keep it simple, we throw
// an error if it is used in any other step. This will also simplify the
// implementation details of MPI communication between master and slave for now..
std::string msg = fmt::format(
"GRUPMAST keyword is only allowed in the first schedule report step.");
throw OpmInputError(msg, handlerContext.keyword.location());
}
if (rescoup.slaveCount() > 0) {
// Since SLAVES has been defined, we are now certain that we are in master mode
rescoup.masterMode(true);
}
for (const auto& record : keyword) {
const std::string& name =
record.getItem<ParserKeywords::GRUPMAST::MASTER_GROUP>().getTrimmedString(0);
Expand Down
3 changes: 2 additions & 1 deletion opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace ReservoirCoupling {
bool CouplingInfo::operator==(const CouplingInfo& rhs) const {
return this->m_slaves == rhs.m_slaves &&
this->m_master_groups == rhs.m_master_groups &&
this->m_grup_slavs == rhs.m_grup_slavs;
this->m_grup_slavs == rhs.m_grup_slavs &&
this->m_master_mode == rhs.m_master_mode;
}

CouplingInfo CouplingInfo::serializationTestObject()
Expand Down
25 changes: 24 additions & 1 deletion opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ class CouplingInfo {
CouplingInfo() = default;

static CouplingInfo serializationTestObject();
const std::map<std::string, Slave>& slaves() const {
return this->m_slaves;
}
std::map<std::string, Slave>& slaves() {
return this->m_slaves;
}
const std::map<std::string, MasterGroup>& masterGroups() const {
return this->m_master_groups;
}
std::map<std::string, MasterGroup>& masterGroups() {
return this->m_master_groups;
}
const std::map<std::string, GrupSlav>& grupSlavs() const {
return this->m_grup_slavs;
}
std::map<std::string, GrupSlav>& grupSlavs() {
return this->m_grup_slavs;
}
Expand All @@ -53,6 +62,9 @@ class CouplingInfo {
const Slave& slave(const std::string& name) const {
return m_slaves.at(name);
}
int slaveCount() const {
return m_slaves.size();
}
bool hasGrupSlav(const std::string& name) const {
return m_grup_slavs.find(name) != m_grup_slavs.end();
}
Expand All @@ -65,19 +77,30 @@ class CouplingInfo {
const MasterGroup& masterGroup(const std::string& name) const {
return m_master_groups.at(name);
}
int masterGroupCount() const {
return m_master_groups.size();
}
bool masterMode() const {
return m_master_mode;
}
void masterMode(bool master_mode) {
m_master_mode = master_mode;
}
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(m_slaves);
serializer(m_master_groups);
serializer(m_grup_slavs);
serializer(m_master_mode);
}
private:
std::map<std::string, Slave> m_slaves;
std::map<std::string, MasterGroup> m_master_groups;
std::map<std::string, GrupSlav> m_grup_slavs;
bool m_master_mode{false};
};

} // namespace ReservoirCoupling
} // namespace Opm
#endif // RESERVOIR_COUPLING_INFO_HPP
#endif // RESERVOIR_COUPLING_INFO_HPP
15 changes: 14 additions & 1 deletion opm/input/eclipse/Schedule/ResCoup/Slaves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,26 @@ bool Slave::operator==(const Slave& rhs) const {

void handleSLAVES(HandlerContext& handlerContext)
{
auto rescoup = handlerContext.state().rescoup();
auto schedule_state = handlerContext.state();
auto rescoup = schedule_state.rescoup();
const auto& keyword = handlerContext.keyword;
bool slave_mode = handlerContext.static_schedule().slave_mode;
if (slave_mode) {
std::string msg = fmt::format("SLAVES keyword is not allowed in slave mode.");
throw OpmInputError(msg, handlerContext.keyword.location());
}
if (schedule_state.sim_step() != 0) {
// Currently, I cannot see any reason why SLAVES should be allowed at
// any other report step than the first one. So to keep it simple, we throw
// an error if it is used in any other step. This will also simplify the
// implementation details of MPI communication between master and slave for now..
std::string msg = fmt::format("SLAVES is only allowed in the first simulation step.");
throw OpmInputError(msg, handlerContext.keyword.location());
}
if (rescoup.masterGroupCount() > 0) {
// Since GRUPMAST has been defined, we are now certain that we are in master mode
rescoup.masterMode(true);
}
for (const auto& record : keyword) {
const std::string& slave_name =
record.getItem<ParserKeywords::SLAVES::SLAVE_RESERVOIR>().getTrimmedString(0);
Expand Down

0 comments on commit 67fcbd6

Please sign in to comment.