Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for the DUMPCUPL keyword #4276

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ if(ENABLE_ECL_INPUT)
opm/input/eclipse/Schedule/ResCoup/GrupSlav.cpp
opm/input/eclipse/Schedule/ResCoup/MasterGroup.cpp
opm/input/eclipse/Schedule/ResCoup/Slaves.cpp
opm/input/eclipse/Schedule/ResCoup/MasterMinimumTimeStep.cpp
opm/input/eclipse/Schedule/ResCoup/CouplingFile.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 @@ -1310,6 +1312,8 @@ if(ENABLE_ECL_INPUT)
opm/input/eclipse/Schedule/ResCoup/GrupSlav.hpp
opm/input/eclipse/Schedule/ResCoup/MasterGroup.hpp
opm/input/eclipse/Schedule/ResCoup/Slaves.hpp
opm/input/eclipse/Schedule/ResCoup/MasterMinimumTimeStep.hpp
opm/input/eclipse/Schedule/ResCoup/CouplingFile.hpp
opm/input/eclipse/Schedule/VFPInjTable.hpp
opm/input/eclipse/Schedule/VFPProdTable.hpp
opm/input/eclipse/Schedule/Well/Connection.hpp
Expand Down
63 changes: 63 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/CouplingFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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 <opm/input/eclipse/Schedule/ResCoup/CouplingFile.hpp>
#include <opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp>
#include <opm/input/eclipse/Schedule/ScheduleState.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/D.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include "../HandlerContext.hpp"


namespace Opm {

ReservoirCoupling::CouplingInfo::CouplingFileFlag couplingFileFlagFromString(
const std::string& flag_str, const DeckKeyword& keyword
)
{
if (flag_str == "F") {
return ReservoirCoupling::CouplingInfo::CouplingFileFlag::FORMATTED;
} else if (flag_str == "U") {
return ReservoirCoupling::CouplingInfo::CouplingFileFlag::UNFORMATTED;
} else {
throw OpmInputError("Invalid DUMPCUPL value: " + flag_str, keyword.location());
}
}

void handleDUMPCUPL(HandlerContext& handlerContext)
{
auto& schedule_state = handlerContext.state();
auto rescoup = schedule_state.rescoup();
const auto& keyword = handlerContext.keyword;
// Opm::Parser::parseFile() (see readDeck.cpp in opm-simulators) will throw an exception if there
// is more than one record for this keyword, so we can assume that there is exactly one record here.
auto record = keyword[0];
auto deck_item = record.getItem<ParserKeywords::DUMPCUPL::VALUE>();
if (deck_item.defaultApplied(0)) {
throw OpmInputError("DUMPCUPL keyword cannot be defaulted.", keyword.location());
}
auto flag_str = deck_item.getTrimmedString(0);
auto coupling_file_flag = couplingFileFlagFromString(flag_str, keyword);
rescoup.couplingFileFlag(coupling_file_flag);
schedule_state.rescoup.update( std::move( rescoup ));
}

} // namespace Opm
28 changes: 28 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/CouplingFile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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_FILE_HPP
#define RESERVOIR_COUPLING_FILE_HPP
namespace Opm {

class HandlerContext;

extern void handleDUMPCUPL(HandlerContext& handlerContext);

} // namespace Opm
#endif // RESERVOIR_COUPLING_FILE_HPP
58 changes: 58 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/MasterMinimumTimeStep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
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 <opm/input/eclipse/Schedule/ResCoup/MasterMinimumTimeStep.hpp>
#include <opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp>
#include <opm/input/eclipse/Schedule/ScheduleState.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/R.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include "../HandlerContext.hpp"


namespace Opm {

void handleRCMASTS(HandlerContext& handlerContext)
{
auto& schedule_state = handlerContext.state();
auto rescoup = schedule_state.rescoup();
auto tuning = schedule_state.tuning();
const auto& keyword = handlerContext.keyword;
if (keyword.size() != 1) {
throw OpmInputError("RCMASTS keyword requires exactly one record.", keyword.location());
}
auto record = keyword[0];
auto deck_item = record.getItem<ParserKeywords::RCMASTS::MIN_TSTEP>();
if (deck_item.defaultApplied(0)) {
// The default value is the current value TSMINZ
rescoup.masterMinTimeStep(tuning.TSMINZ);
}
else {
auto tstep = deck_item.getSIDouble(0);
if (tstep < 0.0) {
throw OpmInputError("Negative value for RCMASTS is not allowed.", keyword.location());
}
rescoup.masterMinTimeStep(tstep);
}
schedule_state.rescoup.update( std::move( rescoup ));
}

} // namespace Opm

28 changes: 28 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/MasterMinimumTimeStep.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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_MASTER_MINIMUM_TIMESTEP_HPP
#define RESERVOIR_COUPLING_MASTER_MINIMUM_TIMESTEP_HPP
namespace Opm {

class HandlerContext;

extern void handleRCMASTS(HandlerContext& handlerContext);

} // namespace Opm
#endif // RESERVOIR_COUPLING_MASTER_MINIMUM_TIMESTEP_HPP
4 changes: 3 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,9 @@ 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_min_time_step == rhs.m_master_min_time_step &&
this->m_coupling_file_flag == rhs.m_coupling_file_flag;
}

CouplingInfo CouplingInfo::serializationTestObject()
Expand Down
27 changes: 27 additions & 0 deletions opm/input/eclipse/Schedule/ResCoup/ReservoirCouplingInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,24 @@ namespace Opm::ReservoirCoupling {

class CouplingInfo {
public:
enum class CouplingFileFlag {
NONE,
FORMATTED,
UNFORMATTED
};

CouplingInfo() = default;

static CouplingInfo serializationTestObject();
bool operator==(const CouplingInfo& other) const;

void couplingFileFlag(CouplingFileFlag flag) {
m_coupling_file_flag = flag;
}
CouplingFileFlag couplingFileFlag() const {
return m_coupling_file_flag;
}

const GrupSlav& grupSlav(const std::string& name) const {
return m_grup_slavs.at(name);
}
Expand All @@ -53,6 +66,7 @@ class CouplingInfo {
bool hasGrupSlav(const std::string& name) const {
return m_grup_slavs.find(name) != m_grup_slavs.end();
}

bool hasMasterGroup(const std::string& name) const {
return m_master_groups.find(name) != m_master_groups.end();
}
Expand All @@ -69,10 +83,18 @@ class CouplingInfo {
const MasterGroup& masterGroup(const std::string& name) const {
return m_master_groups.at(name);
}

int masterGroupCount() const {
return m_master_groups.size();
}

double masterMinTimeStep() const {
return m_master_min_time_step;
}
void masterMinTimeStep(double tstep) {
m_master_min_time_step = tstep;
}

const std::map<std::string, Slave>& slaves() const {
return this->m_slaves;
}
Expand All @@ -93,11 +115,16 @@ class CouplingInfo {
serializer(m_slaves);
serializer(m_master_groups);
serializer(m_grup_slavs);
serializer(m_master_min_time_step);
serializer(m_coupling_file_flag);
}

private:
std::map<std::string, Slave> m_slaves;
std::map<std::string, MasterGroup> m_master_groups;
std::map<std::string, GrupSlav> m_grup_slavs;
double m_master_min_time_step{0.0};
CouplingFileFlag m_coupling_file_flag{CouplingFileFlag::NONE};
};

} // namespace Opm::ReservoirCoupling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
#include "GrupSlav.hpp"
#include "Slaves.hpp"
#include "MasterGroup.hpp"
#include "MasterMinimumTimeStep.hpp"
#include "CouplingFile.hpp"

#include <fmt/format.h>

namespace Opm {

namespace {

} // anonymous namespace

std::vector<std::pair<std::string,KeywordHandlers::handler_function>>
getReservoirCouplingHandlers()
{
return {
{ "SLAVES", &handleSLAVES },
{ "GRUPMAST", &handleGRUPMAST},
{ "GRUPSLAV", &handleGRUPSLAV}
{ "GRUPSLAV", &handleGRUPSLAV},
{ "RCMASTS", &handleRCMASTS},
{ "DUMPCUPL", &handleDUMPCUPL},
};
}

Expand Down
Loading