Skip to content

Commit

Permalink
Support defaulted I and J in COMPDAT
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Oct 29, 2020
1 parent 3ba94d2 commit d382427
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ecl2df/compdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
def deck2dfs(deck, start_date=None, unroll=True):
"""Loop through the deck and pick up information found
The loop over the deck is a state machine, as it has to pick up dates
The loop over the deck is a state machine, as it has to pick up dates and
potential information from the WELSPECS keyword.
Args:
deck (opm.libopmcommon_python.Deck): A deck representing the schedule
Expand All @@ -69,6 +70,7 @@ def deck2dfs(deck, start_date=None, unroll=True):
compsegsrecords = []
welopenrecords = []
welsegsrecords = []
welspecs = {}
date = start_date # DATE column will always be there, but can contain NaN/None
for idx, kword in enumerate(deck):
if kword.name == "DATES" or kword.name == "START":
Expand All @@ -87,13 +89,35 @@ def deck2dfs(deck, start_date=None, unroll=True):
logger.info(
"Advancing %s days to %s through TSTEP", str(days), str(date)
)
elif kword.name == "WELSPECS":
# Information from WELSPECS are to be used in case
# 0 or 1* is used in the I or J column in COMPDAT
# Only the latest information pr. well is stored.
for wellrec in kword:
welspecs_rec_dict = parse_opmio_deckrecord(wellrec, "WELSPECS")
welspecs[welspecs_rec_dict["WELL"]] = {
"I": welspecs_rec_dict["HEAD_I"],
"J": welspecs_rec_dict["HEAD_J"],
}
elif kword.name == "COMPDAT":
for rec in kword: # Loop over the lines inside COMPDAT record
rec_data = parse_opmio_deckrecord(
rec, "COMPDAT", renamer=COMPDAT_RENAMER
)
rec_data["DATE"] = date
rec_data["KEYWORD_IDX"] = idx
if rec_data["I"] == 0:
if rec_data["WELL"] not in welspecs:
raise ValueError(
"WELSPECS must be provided when I is defaulted in COMPDAT"
)
rec_data["I"] = welspecs[rec_data["WELL"]]["I"]
if rec_data["J"] == 0:
if rec_data["WELL"] not in welspecs:
raise ValueError(
"WELSPECS must be provided when J is defaulted in COMPDAT"
)
rec_data["J"] = welspecs[rec_data["WELL"]]["J"]
compdatrecords.append(rec_data)
elif kword.name == "COMPSEGS":
wellname = parse_opmio_deckrecord(
Expand Down
85 changes: 85 additions & 0 deletions tests/test_compdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,88 @@ def test_main_subparsers(tmpdir):
assert "FIPNUM" in disk_df
assert "EQLNUM" in disk_df
assert not disk_df.empty


def test_defaulted_compdat_i_j(tmpdir):
"""I and J can be defaulted (that is 1* or 0) in COMPDAT records, then
that information should be fetched from the most recent WELSPECS keyword
"""

welspecs_str = """
WELSPECS
OP1 OPWEST 20 30 1000 /
/
"""
compdat_str = """
COMPDAT
'OP1' 1* 0 10 11 /
/
"""
compdat_str_nodefaults = """
COMPDAT
'OP1' 55 66 80 80 /
/
"""

with pytest.raises(ValueError, match="WELSPECS must be provided"):
compdat.deck2dfs(EclFiles.str2deck(compdat_str))["COMPDAT"]

with pytest.raises(ValueError, match="WELSPECS must be provided"):
# Wrong order:
compdat.deck2dfs(EclFiles.str2deck(compdat_str + welspecs_str))["COMPDAT"]

# Simplest example:
compdat_df = compdat.deck2dfs(EclFiles.str2deck(welspecs_str + compdat_str))[
"COMPDAT"
]
assert compdat_df["I"].unique() == [20]
assert compdat_df["J"].unique() == [30]

# Two wells:
compdat_df = compdat.deck2dfs(
EclFiles.str2deck(
welspecs_str.replace("OP1", "OP2").replace("30", "99")
+ welspecs_str
+ compdat_str
)
)["COMPDAT"]

# Partial defaulting
compdat_df = compdat.deck2dfs(
EclFiles.str2deck(welspecs_str + compdat_str + compdat_str_nodefaults)
)["COMPDAT"]

assert set(compdat_df["I"].unique()) == {20, 55}
assert set(compdat_df["J"].unique()) == {30, 66}

compdat_df = compdat.deck2dfs(
EclFiles.str2deck(
welspecs_str.replace("OP1", "OP2").replace("30", "99")
+ welspecs_str
+ compdat_str
+ compdat_str.replace("OP1", "OP2")
)
)["COMPDAT"]

assert compdat_df[compdat_df["WELL"] == "OP1"]["I"].unique() == [20]
assert compdat_df[compdat_df["WELL"] == "OP2"]["I"].unique() == [20]
assert compdat_df[compdat_df["WELL"] == "OP1"]["J"].unique() == [30]
assert compdat_df[compdat_df["WELL"] == "OP2"]["J"].unique() == [99]

# Same well redrilled to new location
compdat_df = compdat.deck2dfs(
EclFiles.str2deck(
"DATES\n 1 JAN 2030 /\n/\n"
+ welspecs_str
+ compdat_str
+ "DATES\n 1 JAN 2040 /\n/\n"
+ welspecs_str.replace("30", "33")
+ compdat_str
)
)["COMPDAT"]
assert compdat_df[compdat_df["DATE"].astype(str) == "2030-01-01"]["J"].unique() == [
30
]
assert compdat_df[compdat_df["DATE"].astype(str) == "2040-01-01"]["J"].unique() == [
33
]

0 comments on commit d382427

Please sign in to comment.