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

implementation of COMPDATL and WELSPECL keywords #4201

Draft
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion opm/input/eclipse/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ bool parseState( ParserState& parserState, const Parser& parser ) {

Deck Parser::parseString(const std::string &data, const ParseContext& parseContext) const {
ErrorGuard errors;
return this->parseString(data, parseContext, errors);
return this->parseString(data, parseContext, errors);
}

Deck Parser::parseString(const std::string &data) const {
Expand Down
6 changes: 6 additions & 0 deletions opm/input/eclipse/Schedule/HandlerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ void HandlerContext::addGroup(const std::string& groupName)
schedule_.addGroup(groupName, currentStep);
}

void HandlerContext::addGroupLGR(const std::string& lgrGroup)
{
schedule_.addGroupLGR(lgrGroup);
}


void HandlerContext::addGroupToGroup(const std::string& parent_group,
const std::string& child_group)
{
Expand Down
6 changes: 6 additions & 0 deletions opm/input/eclipse/Schedule/HandlerContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class HandlerContext

//! \brief Adds a group to the schedule.
void addGroup(const std::string& groupName);

//! \brief Adds a group to the LGR group set.
void addGroupLGR(const std::string& lgrGroup);


//! \brief Adds a group to a group.
void addGroupToGroup(const std::string& parent_group,
const std::string& child_group);
Expand Down Expand Up @@ -166,6 +171,7 @@ class HandlerContext
private:
const std::unordered_map<std::string, double>* target_wellpi{nullptr};
WelSegsSet* welsegs_wells{nullptr};
std::set<std::string> lgr_groups;
std::set<std::string>* compsegs_wells{nullptr};
SimulatorUpdate* sim_update{nullptr};
Schedule& schedule_;
Expand Down
6 changes: 6 additions & 0 deletions opm/input/eclipse/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,12 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
field.updateInjection(new_group.injectionProperties(phase));
}

void Schedule::addGroupLGR(const std::string& lgr_group_key) {
if (lgr_groups.count(lgr_group_key) == 0) {
lgr_groups.insert(lgr_group_key);
}
}


void Schedule::addGroupToGroup( const std::string& parent_name, const std::string& child_name) {
auto parent_group = this->snapshots.back().groups.get(parent_name);
Expand Down
4 changes: 4 additions & 0 deletions opm/input/eclipse/Schedule/Schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ namespace Opm
// For parallel runs, this unordered_map is retrieved by the grid partitioner to ensure these connections
// end up on the same partition.
std::unordered_map<std::string, std::set<std::array<int,3>>> possibleFutureConnections;

// Set of labels for each LGR group
std::set<std::string> lgr_groups;

// The current_report_step is set to the current report step when a PYACTION call is executed.
// This is needed since the Schedule object does not know the current report step of the simulator and
Expand Down Expand Up @@ -526,6 +529,7 @@ namespace Opm
void addGroup(const std::string& groupName , std::size_t timeStep);
void addGroup(Group group);
void addGroup(const RestartIO::RstGroup& rst_group, std::size_t timeStep);
void addGroupLGR(const std::string& lgrGroup);
void addWell(const std::string& wellName, const DeckRecord& record,
std::size_t timeStep, ConnectionOrder connection_order);
void checkIfAllConnectionsIsShut(std::size_t currentStep);
Expand Down
68 changes: 68 additions & 0 deletions opm/input/eclipse/Schedule/Well/WellCompletionKeywordHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,73 @@ Well {} is not connected to grid - will remain SHUT)",
}
}

void handleCOMPDATL(HandlerContext& handlerContext)
// handleWCOMPDATL copies msot of the structure handleWCOMPDAT and add
// the support for LGR. handling LGR group has not been implemented yet.
{
std::unordered_set<std::string> wells;
for (const auto& record : handlerContext.keyword) {
const auto wellNamePattern = record.getItem("WELL").getTrimmedString(0);
const auto wellnames = handlerContext.wellNames(wellNamePattern);
const auto lgr_group = record.getItem("LGR").getTrimmedString(0);


for (const auto& name : wellnames) {
auto well2 = handlerContext.state().wells.get(name);

auto connections = std::make_shared<WellConnections>(well2.getConnections());
const auto origWellConnSetIsEmpty = connections->empty();

connections->loadCOMPDATL(record, handlerContext.grid, name,
well2.getWDFAC(), handlerContext.keyword.location(), lgr_group);
const auto newWellConnSetIsEmpty = connections->empty();

if (well2.updateConnections(std::move(connections), handlerContext.grid)) {
auto wdfac = std::make_shared<WDFAC>(well2.getWDFAC());
wdfac->updateWDFACType(well2.getConnections());

well2.updateWDFAC(std::move(wdfac));
handlerContext.state().wells.update( well2 );

wells.insert(name);
}

if (origWellConnSetIsEmpty && newWellConnSetIsEmpty) {
const auto& location = handlerContext.keyword.location();

const auto msg = fmt::format(R"(Problem with COMPDATL/{}
In {} line {}
Well {} is not connected to grid - will remain SHUT)",
name, location.filename,
location.lineno, name);

OpmLog::warning(msg);
}

handlerContext.state().wellgroup_events()
.addEvent(name, ScheduleEvents::COMPLETION_CHANGE);
}
}

handlerContext.state().events().addEvent(ScheduleEvents::COMPLETION_CHANGE);

// In the case the wells reference depth has been defaulted in the
// WELSPECS keyword we need to force a calculation of the wells
// reference depth exactly when the COMPDAT keyword has been completely
// processed.
for (const auto& wname : wells) {
auto well = handlerContext.state().wells.get( wname );
well.updateRefDepth();

handlerContext.state().wells.update(std::move(well));
}

if (! wells.empty()) {
handlerContext.record_well_structure_change();
}
}


void handleCOMPLUMP(HandlerContext& handlerContext)
{
for (const auto& record : handlerContext.keyword) {
Expand Down Expand Up @@ -219,6 +286,7 @@ getWellCompletionHandlers()
{
return {
{ "COMPDAT" , &handleCOMPDAT },
{ "COMPDATL", &handleCOMPDATL },
{ "COMPLUMP", &handleCOMPLUMP },
{ "COMPORD" , &handleCOMPORD },
{ "COMPTRAJ", &handleCOMPTRAJ },
Expand Down
21 changes: 20 additions & 1 deletion opm/input/eclipse/Schedule/Well/WellConnections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ namespace Opm {
for (int k = K1; k <= K2; ++k) {
const auto& cell = grid.get_cell(I, J, k);
if (!cell.is_active()) {
auto msg = fmt::format(R"(Problem with COMPDAT keyword
auto msg = fmt::format(R"(Problem with COMPDATX keyword
In {} line {}
The cell ({},{},{}) in well {} is not active and the connection will be ignored)",
location.filename, location.lineno,
Expand Down Expand Up @@ -544,6 +544,19 @@ The cell ({},{},{}) in well {} is not active and the connection will be ignored)
}
}


void WellConnections::loadCOMPDATL(const DeckRecord& record,
const ScheduleGrid& grid,
const std::string& wname,
const WDFAC& wdfac,
const KeywordLocation& location,
const std::string& lgr_group)
{
this->lgr_well = true;
loadCOMPDAT(record, grid, wname, wdfac, location);

}

void WellConnections::loadCOMPTRAJ(const DeckRecord& record,
const ScheduleGrid& grid,
const std::string& wname,
Expand Down Expand Up @@ -1006,6 +1019,12 @@ CF and Kh items for well {} must both be specified or both defaulted/negative)",
return this->headJ;
}

bool WellConnections::isLGR() const
{
return this->lgr_well;
}


const std::vector<double>& WellConnections::getMD() const
{
return this->md;
Expand Down
9 changes: 9 additions & 0 deletions opm/input/eclipse/Schedule/Well/WellConnections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ namespace Opm {
const WDFAC& wdfac,
const KeywordLocation& location);

void loadCOMPDATL(const DeckRecord& record,
const ScheduleGrid& grid,
const std::string& wname,
const WDFAC& wdfac,
const KeywordLocation& location,
const std::string& lgr_group);

void loadCOMPTRAJ(const DeckRecord& record,
const ScheduleGrid& grid,
const std::string& wname,
Expand All @@ -108,6 +115,7 @@ namespace Opm {

int getHeadI() const;
int getHeadJ() const;
bool isLGR() const;
const std::vector<double>& getMD() const;
std::size_t size() const;
bool empty() const;
Expand Down Expand Up @@ -180,6 +188,7 @@ namespace Opm {
Connection::Order m_ordering { Connection::Order::TRACK };
int headI{0};
int headJ{0};
bool lgr_well = false;
std::vector<Connection> m_connections{};

std::array<std::vector<double>, 3> coord{};
Expand Down
117 changes: 117 additions & 0 deletions opm/input/eclipse/Schedule/Well/WellKeywordHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,122 @@ Well{0} entered with 'FIELD' parent group:
}
}

void handleWELSPECL(HandlerContext& handlerContext)
// handleWELSPECL copies msot of the structure handleWELSPEC and add
// the support for LGR. handling LGR group has not been implemented yet.
{
using Kw = ParserKeywords::WELSPECL;

auto getTrimmedName = [&handlerContext](const auto& item)
{
return trim_wgname(handlerContext.keyword,
item.template get<std::string>(0),
handlerContext.parseContext,
handlerContext.errors);
};

auto fieldWells = std::vector<std::string>{};
for (const auto& record : handlerContext.keyword) {
if (const auto fip_region_number = record.getItem<Kw::FIP_REGION>().get<int>(0);
fip_region_number != Kw::FIP_REGION::defaultValue)
{
const auto& location = handlerContext.keyword.location();
const auto msg = fmt::format("Non-defaulted FIP region {} in WELSPECL keyword "
"in file {} line {} is not supported. "
"Reset to default value {}.",
fip_region_number,
location.filename,
location.lineno,
Kw::FIP_REGION::defaultValue);
OpmLog::warning(msg);
}

if (const auto& density_calc_type = record.getItem<Kw::DENSITY_CALC>().get<std::string>(0);
density_calc_type != Kw::DENSITY_CALC::defaultValue)
{
const auto& location = handlerContext.keyword.location();
const auto msg = fmt::format("Non-defaulted density calculation method '{}' "
"in WELSPECL keyword in file {} line {} is "
"not supported. Reset to default value {}.",
density_calc_type,
location.filename,
location.lineno,
Kw::DENSITY_CALC::defaultValue);
OpmLog::warning(msg);
}

const auto wellName = getTrimmedName(record.getItem<Kw::WELL>());
const auto groupName = getTrimmedName(record.getItem<Kw::GROUP>());
const auto lgrGroup = getTrimmedName(record.getItem<Kw::LOCAL_GRID>()) ;
handlerContext.addGroupLGR(lgrGroup);



// We might get here from an ACTIONX context, or we might get
// called on a well (list) template, to reassign certain well
// properties--e.g, the well's controlling group--so check if
// 'wellName' matches any existing well names through pattern
// matching before treating the wellName as a simple well name.
//
// An empty list of well names is okay since that means we're
// creating a new well in this case.
const auto allowEmptyWellList = true;
const auto existingWells = handlerContext.wellNames(wellName, allowEmptyWellList);

if (groupName == "FIELD") {
if (existingWells.empty()) {
fieldWells.push_back(wellName);
}
else {
for (const auto& existingWell : existingWells) {
fieldWells.push_back(existingWell);
}
}
}

if (! handlerContext.state().groups.has(groupName)) {
handlerContext.addGroup(groupName);
}

if (existingWells.empty()) {
// 'wellName' does not match any existing wells. Create a
// new Well object for this well.
handlerContext.welspecsCreateNewWell(record,
wellName,
groupName);
}
else {
// 'wellName' matches one or more existing wells. Assign
// new properties for those wells.
handlerContext.welspecsUpdateExistingWells(record,
existingWells,
groupName);
}
}

if (! fieldWells.empty()) {
std::sort(fieldWells.begin(), fieldWells.end());
fieldWells.erase(std::unique(fieldWells.begin(), fieldWells.end()),
fieldWells.end());

const auto* plural = (fieldWells.size() == 1) ? "" : "s";

const auto msg_fmt = fmt::format(R"(Well{0} parented directly to 'FIELD'; this is allowed but discouraged.
Well{0} entered with 'FIELD' parent group:
* {1})", plural, fmt::join(fieldWells, "\n * "));

handlerContext.parseContext.handleError(ParseContext::SCHEDULE_WELL_IN_FIELD_GROUP,
msg_fmt,
handlerContext.keyword.location(),
handlerContext.errors);
}

if (! handlerContext.keyword.empty()) {
handlerContext.record_well_structure_change();
}
}


/*
The documentation for the WELTARG keyword says that the well
must have been fully specified and initialized using one of the
Expand Down Expand Up @@ -887,6 +1003,7 @@ getWellHandlers()
{ "WCONPROD", &handleWCONPROD },
{ "WELOPEN" , &handleWELOPEN },
{ "WELSPECS", &handleWELSPECS },
{ "WELSPECL", &handleWELSPECL},
{ "WELTARG" , &handleWELTARG },
{ "WELTRAJ" , &handleWELTRAJ },
{ "WHISTCTL", &handleWHISTCTL },
Expand Down
Loading