-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4114 from hakonhagland/slaves
Add support for SLAVES keyword
- Loading branch information
Showing
9 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
111
opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
68 changes: 68 additions & 0 deletions
68
opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingKeywordHandlers.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
35 changes: 35 additions & 0 deletions
35
opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingKeywordHandlers.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.