Skip to content

Commit

Permalink
Merge pull request #4114 from hakonhagland/slaves
Browse files Browse the repository at this point in the history
Add support for SLAVES keyword
  • Loading branch information
totto82 authored Jun 24, 2024
2 parents 875d819 + 4900fba commit 41bd16f
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ if(ENABLE_ECL_INPUT)
opm/input/eclipse/Schedule/Network/ExtNetwork.cpp
opm/input/eclipse/Schedule/Network/NetworkKeywordHandlers.cpp
opm/input/eclipse/Schedule/Network/Node.cpp
opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.cpp
opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingKeywordHandlers.cpp
opm/input/eclipse/Schedule/UDQ/UDQKeywordHandlers.cpp
opm/input/eclipse/Schedule/UDQ/UDQActive.cpp
opm/input/eclipse/Schedule/UDQ/UDQAssign.cpp
Expand Down Expand Up @@ -553,6 +555,7 @@ if(ENABLE_ECL_INPUT)
tests/parser/PAvgTests.cpp
tests/parser/PYACTION.cpp
tests/parser/RawKeywordTests.cpp
tests/parser/ReservoirCouplingTests.cpp
tests/parser/test_ReportConfig.cpp
tests/parser/ResinsightTest.cpp
tests/parser/RestartConfigTests.cpp
Expand Down
2 changes: 2 additions & 0 deletions opm/input/eclipse/Schedule/KeywordHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "MixingRateControlKeywordHandlers.hpp"
#include "MSW/MSWKeywordHandlers.hpp"
#include "Network/NetworkKeywordHandlers.hpp"
#include "ResCoup/ReservoirCouplingKeywordHandlers.hpp"
#include "RXXKeywordHandlers.hpp"
#include "UDQ/UDQKeywordHandlers.hpp"
#include "Well/WellCompletionKeywordHandlers.hpp"
Expand Down Expand Up @@ -371,6 +372,7 @@ KeywordHandlers::KeywordHandlers()
getMSWHandlers,
getNetworkHandlers,
getUDQHandlers,
getReservoirCouplingHandlers,
getRXXHandlers,
getWellCompletionHandlers,
getWellHandlers,
Expand Down
47 changes: 47 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2024 Equinor ASA.
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/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp>

namespace Opm {
namespace ReservoirCoupling {
Slave Slave::serializationTestObject()
{
return Slave{"RES-1", "RC-01_MOD1_PRED", "../mod1", 1};
}

bool Slave::operator==(const Slave& rhs) const {
return this->m_name == rhs.m_name;
}

bool CouplingInfo::operator==(const CouplingInfo& rhs) const {
return this->m_slaves == rhs.m_slaves;
}

CouplingInfo CouplingInfo::serializationTestObject()
{
CouplingInfo info;
info.m_slaves = {{"SLAVE1", Slave::serializationTestObject()}};
return info;
}

} // namespace ReservoirCoupling
} // namespace Opm
111 changes: 111 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
Copyright 2024 Equinor ASA.
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 RESERVOIR_COUPLING_SLAVES_HPP
#define RESERVOIR_COUPLING_SLAVES_HPP

#include <optional>
#include <string>
#include <map>
#include <opm/io/eclipse/rst/well.hpp>
#include <opm/io/eclipse/rst/group.hpp>

namespace Opm {
namespace ReservoirCoupling {

class Slave {
public:
Slave() = default;

explicit Slave(const std::string& name, const std::string& data_filename, const std::string& directory_path, unsigned int numprocs) :
m_name{name},
m_data_filename{data_filename},
m_directory_path{directory_path},
m_numprocs{numprocs}
{}
static Slave serializationTestObject();

const std::string& name() const {
return this->m_name;
}
const std::string& dataFilename() const {
return this->m_data_filename;
}
const std::string& directoryPath() const {
return this->m_directory_path;
}
unsigned int numprocs() const {
return this->m_numprocs;
}

void name(const std::string& value) {
this->m_name = value;
}
void dataFilename(const std::string& value) {
this->m_data_filename = value;
}
void directoryPath(const std::string& value) {
this->m_directory_path = value;
}
void numprocs(unsigned int value) {
this->m_numprocs = value;
}
bool operator==(const Slave& other) const;

template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(m_name);
serializer(m_data_filename);
serializer(m_directory_path);
serializer(m_numprocs);
}
private:
std::string m_name;
std::string m_data_filename;
std::string m_directory_path;
unsigned int m_numprocs;
};

class CouplingInfo {
public:
CouplingInfo() = default;

static CouplingInfo serializationTestObject();
std::map<std::string, Slave>& slaves() {
return this->m_slaves;
}
bool operator==(const CouplingInfo& other) const;
bool has_slave(const std::string& name) const {
return m_slaves.find(name) != m_slaves.end();
}
const Slave& slave(const std::string& name) const {
return m_slaves.at(name);
}
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(m_slaves);
}
private:
std::map<std::string, Slave> m_slaves;
};

} // namespace ReservoirCoupling
} // namespace Opm
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2024 Equinor ASA.
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 "ReservoirCouplingKeywordHandlers.hpp"
#include "ReservoirCouplingInfo.hpp"
#include "../HandlerContext.hpp"

#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/utility/OpmInputError.hpp>

#include <opm/input/eclipse/Parser/ParserKeywords/S.hpp>

#include <opm/input/eclipse/Schedule/ScheduleState.hpp>

#include <fmt/format.h>

namespace Opm {

namespace {

void handleSLAVES(HandlerContext& handlerContext)
{
auto rescoup = handlerContext.state().rescoup();
const auto& keyword = handlerContext.keyword;

for (const auto& record : keyword) {
const std::string& slave_name = record.getItem<ParserKeywords::SLAVES::SLAVE_RESERVOIR>().getTrimmedString(0);
const std::string& data_filename = record.getItem<ParserKeywords::SLAVES::SLAVE_ECLBASE>().getTrimmedString(0);
const std::string& directory_path = record.getItem<ParserKeywords::SLAVES::DIRECTORY>().getTrimmedString(0);
const int numprocs_int = record.getItem<ParserKeywords::SLAVES::NUM_PE>().get<int>(0);
if (numprocs_int <= 0) {
std::string msg = fmt::format("Number of processors must be positive. Got: {}.", numprocs_int);
throw OpmInputError(msg, handlerContext.keyword.location());
}
const unsigned int numprocs = static_cast<unsigned int>(numprocs_int);
ReservoirCoupling::Slave slave{ slave_name, data_filename, directory_path, numprocs};
rescoup.slaves().emplace( slave_name, std::move( slave ));
}

handlerContext.state().rescoup.update( std::move( rescoup ));
}
} // anonymous namespace

std::vector<std::pair<std::string,KeywordHandlers::handler_function>>
getReservoirCouplingHandlers()
{
return {
{ "SLAVES", &handleSLAVES },
};
}

} // namespace Opm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2024 Equinor ASA.
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 RESERVOIR_COUPLING_KEYWORD_HANDLERS_HPP
#define RESERVOIR_COUPLING_KEYWORD_HANDLERS_HPP

#include "../KeywordHandlers.hpp"

#include <string>
#include <utility>
#include <vector>

namespace Opm {

//! \brief Obtain a list of reservoir coupling keyword handlers.
std::vector<std::pair<std::string,KeywordHandlers::handler_function>> getReservoirCouplingHandlers();

}

#endif
2 changes: 2 additions & 0 deletions opm/input/eclipse/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
#include <opm/input/eclipse/Schedule/Network/Node.hpp>
#include <opm/input/eclipse/Schedule/OilVaporizationProperties.hpp>
#include <opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp>
#include <opm/input/eclipse/Schedule/RFTConfig.hpp>
#include <opm/input/eclipse/Schedule/RPTConfig.hpp>
#include <opm/input/eclipse/Schedule/ScheduleGrid.hpp>
Expand Down Expand Up @@ -2325,6 +2326,7 @@ void Schedule::create_first(const time_point& start_time, const std::optional<ti
sched_state.gecon.update( GroupEconProductionLimits() );
sched_state.wlist_manager.update( WListManager() );
sched_state.network.update( Network::ExtNetwork() );
sched_state.rescoup.update( ReservoirCoupling::CouplingInfo() );
sched_state.rpt_config.update( RPTConfig() );
sched_state.actions.update( Action::Actions() );
sched_state.udq_active.update( UDQActive() );
Expand Down
4 changes: 4 additions & 0 deletions opm/input/eclipse/Schedule/ScheduleState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ namespace Opm {
class Balance;
class ExtNetwork;
}
namespace ReservoirCoupling {
class CouplingInfo;
}
class RFTConfig;
class RPTConfig;
class UDQActive;
Expand Down Expand Up @@ -398,6 +401,7 @@ namespace Opm {
ptr_member<GasLiftOpt> glo;
ptr_member<Network::ExtNetwork> network;
ptr_member<Network::Balance> network_balance;
ptr_member<ReservoirCoupling::CouplingInfo> rescoup;

ptr_member<RPTConfig> rpt_config;
ptr_member<RFTConfig> rft_config;
Expand Down
Loading

0 comments on commit 41bd16f

Please sign in to comment.