Skip to content

Commit

Permalink
2D maps support for multi-slide projections
Browse files Browse the repository at this point in the history
  • Loading branch information
daavid00 committed Sep 25, 2024
1 parent 129295e commit 9b552ed
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 123 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ examples/spe11b_xco2l.gif
examples/fgip.png
examples/SPE11B-*.vtu
examples/SPE11B.pvd
examples/pres_diff.png
examples/pres_incr.png
examples/tco2m_alongx.png
examples/tco2m_alongz.png
tests/generic_deck

# Python environment
Expand Down
8 changes: 5 additions & 3 deletions src/plopm/core/plopm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def load_parser():
help="Specify the name of the vairable to plot, e.g., 'pressure', in "
"addition to special variables such as 'grid', 'wells', "
"'gasm', 'dism', 'liqm', 'vapm', 'co2m', 'h2om', 'xco2l', 'xh2ov', "
"'xco2v', 'xh2ol', 'fwcdm', and 'fgipm' "
"'xco2v', 'xh2ol', 'fwcdm', and 'fgipm', as well as operations, e.g "
"'pressure - 0pressure' to plot the pressure increase "
"('poro,permx,permz,porv,fipnum,satnum' by default.",
)
parser.add_argument(
Expand All @@ -74,7 +75,8 @@ def load_parser():
"--slide",
default=",1,",
help="The slide in the 3D model to plot the 2D maps, e.g,"
" '10,,' to plot the xz plane on all cells with i=10 (',1,' "
" '10,,' to plot the xz plane on all cells with i=10, or "
" ',,5:10' to plot the pv average weighted quantity (',1,' "
" by default, i.e., the xz surface at j=1).",
)
parser.add_argument(
Expand Down Expand Up @@ -169,7 +171,7 @@ def load_parser():
parser.add_argument(
"-tunits",
"--tunits",
default="s",
default="d",
help="For the x axis in the summary use seconds 's', minutes 'm', "
"hours 'h', days 'd', weeks 'w', years 'y', or dates 'dates' ('s' "
"by default).",
Expand Down
26 changes: 21 additions & 5 deletions src/plopm/utils/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,18 @@ def ini_dic(cmdargs):
dic["restart"] = [int(i) for i in dic["restart"]]
dic["slide"] = (cmdargs["slide"]).split(" ")
dic["slide"] = [
[int(val) - 1 if val else -2 for val in var.split(",")] for var in dic["slide"]
[val if val else [-2, -2] for val in var.split(",")] for var in dic["slide"]
]
for i, var in enumerate(dic["slide"]):
for j, val in enumerate(var):
if val[0] != -2:
if ":" in val:
dic["slide"][i][j] = [
int(val.split(":")[0]) - 1,
int(val.split(":")[1]),
]
else:
dic["slide"][i][j] = [int(val) - 1, int(val)]
dic["mass"] = ["gasm", "dism", "liqm", "vapm", "co2m", "h2om"]
dic["smass"] = ["FWCDM", "FGIPM"]
dic["xmass"] = ["xco2l", "xh2ov", "xco2v", "xh2ol"]
Expand Down Expand Up @@ -188,13 +198,19 @@ def ini_dic(cmdargs):
dic["save"] = [dic["save"][0]] * len(dic["vrs"])
if len(dic["bounds"]) < len(dic["vrs"]):
dic["bounds"] = [dic["bounds"][0]] * len(dic["vrs"])
if len(dic["rotate"]) < len(dic["names"][0]):
if dic["diff"] and len(dic["rotate"]) < 2:
dic["rotate"] = [dic["rotate"][0]] * 2
elif len(dic["rotate"]) < len(dic["names"][0]):
dic["rotate"] = [dic["rotate"][0]] * len(dic["names"][0])
if dic["diff"] and len(dic["translate"]) < 2:
dic["translate"] = [dic["translate"][0]] * 2
if len(dic["translate"]) < len(dic["names"][0]):
dic["translate"] = [dic["translate"][0]] * len(dic["names"][0])
if len(dic["titles"]) < max(len(dic["names"][0]), len(dic["vrs"])):
dic["titles"] = [dic["titles"][0]] * max(len(dic["names"][0]), len(dic["vrs"]))
if len(dic["slide"]) < max(len(dic["names"][0]), len(dic["vrs"])):
if dic["diff"] and len(dic["slide"]) < 2:
dic["slide"] = [dic["slide"][0]] * 2
elif len(dic["slide"]) < max(len(dic["names"][0]), len(dic["vrs"])):
dic["slide"] = [dic["slide"][0]] * max(len(dic["names"][0]), len(dic["vrs"]))
for val in [
"xformat",
Expand Down Expand Up @@ -326,10 +342,10 @@ def ini_slides(dic, n):
dic (dict): Modified global dictionary
"""
if dic["slide"][n][0] > -1:
if dic["slide"][n][0][0] > -1:
dic["mx"], dic["my"] = 2 * dic["ny"] - 1, 2 * dic["nz"] - 1
dic["xmeaning"], dic["ymeaning"] = "y", "z"
elif dic["slide"][n][1] > -1:
elif dic["slide"][n][1][0] > -1:
dic["mx"], dic["my"] = 2 * dic["nx"] - 1, 2 * dic["nz"] - 1
dic["xmeaning"], dic["ymeaning"] = "x", "z"
else:
Expand Down
143 changes: 100 additions & 43 deletions src/plopm/utils/mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: 2024 NORCE
# SPDX-License-Identifier: GPL-3.0
# pylint: disable=R1702,R0912

"""
Utiliy function for the grid and locations in the geological models.
Expand Down Expand Up @@ -27,10 +28,14 @@ def handle_slide_x(dic, n):
dic (dict): Modified global dictionary
"""
dic["tslide"] = f", slide i={dic['slide'][n][0]+1}"
dic["nslide"] = f"{dic['slide'][n][0]+1},*,*"
if dic["slide"][n][0][0] == dic["slide"][n][0][1] - 1:
dic["tslide"] = f", slide i={dic['slide'][n][0][0]+1}"
dic["nslide"] = f"{dic['slide'][n][0][0]+1},*,*"
else:
dic["tslide"] = f", slide i={dic['slide'][n][0][0]+1}:{dic['slide'][n][0][1]}"
dic["nslide"] = f"{dic['slide'][n][0][0]+1}:{dic['slide'][n][0][1]},*,*"
for well in reversed(dic["wells"]):
if well[0] != dic["slide"][n][0]:
if well[0] != dic["slide"][n][0][0]:
dic["wells"].remove(well)
if dic["use"] == "resdata":
get_yzcoords_resdata(dic, n)
Expand All @@ -49,10 +54,14 @@ def handle_slide_y(dic, n):
dic (dict): Modified global dictionary
"""
dic["tslide"] = f", slide j={dic['slide'][n][1]+1}"
dic["nslide"] = f"*,{dic['slide'][n][1]+1},*"
if dic["slide"][n][1][0] == dic["slide"][n][1][1] - 1:
dic["tslide"] = f", slide j={dic['slide'][n][1][0]+1}"
dic["nslide"] = f"*,{dic['slide'][n][1][0]+1},*"
else:
dic["tslide"] = f", slide j={dic['slide'][n][1][0]+1}:{dic['slide'][n][1][1]}"
dic["nslide"] = f"*,{dic['slide'][n][1][0]+1}:{dic['slide'][n][1][1]},*"
for well in reversed(dic["wells"]):
if well[1] != dic["slide"][n][1]:
if well[1] != dic["slide"][n][1][0]:
dic["wells"].remove(well)
if dic["use"] == "resdata":
get_xzcoords_resdata(dic, n)
Expand All @@ -71,10 +80,14 @@ def handle_slide_z(dic, n):
dic (dict): Modified global dictionary
"""
dic["tslide"] = f", slide k={dic['slide'][n][2]+1}"
dic["nslide"] = f"*,*,{dic['slide'][n][2]+1}"
if dic["slide"][n][2][0] == dic["slide"][n][2][1] - 1:
dic["tslide"] = f", slide k={dic['slide'][n][2][0]+1}"
dic["nslide"] = f"*,*,{dic['slide'][n][2][0]+1}"
else:
dic["tslide"] = f", slide k={dic['slide'][n][2][0]+1}:{dic['slide'][n][2][1]}"
dic["nslide"] = f"*,*,{dic['slide'][n][2][0]+1}:{dic['slide'][n][2][1]}"
for well in reversed(dic["wells"]):
if dic["slide"][n][2] not in range(well[2], well[3] + 1):
if dic["slide"][n][2][0] not in range(well[2], well[3] + 1):
dic["wells"].remove(well)
if dic["use"] == "resdata":
get_xycoords_resdata(dic, n)
Expand Down Expand Up @@ -132,26 +145,40 @@ def map_xzcoords(dic, var, quan, n):
"""
for k in range(dic["nz"]):
for i in range(dic["nx"]):
ind = i + dic["slide"][n][1] * dic["nx"] + k * dic["nx"] * dic["ny"]
if dic["porv"][ind] > 0:
if var.lower() == "grid":
ind = i + dic["slide"][n][1][0] * dic["nx"] + k * dic["nx"] * dic["ny"]
if var.lower() == "grid":
if dic["porv"][ind] > 0:
dic["grida"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = 1
elif var.lower() == "wells":
elif var.lower() == "wells":
if dic["porv"][ind] > 0:
dic["wellsa"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = len(
dic["wells"]
)
elif var.lower() == "index_i":
elif var.lower() == "index_i":
if dic["porv"][ind] > 0:
dic["index_ia"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = i
elif var.lower() == "index_j":
elif var.lower() == "index_j":
if dic["porv"][ind] > 0:
dic["index_ja"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = dic[
"slide"
][n][1]
elif var.lower() == "index_k":
][n][1][0]
elif var.lower() == "index_k":
if dic["porv"][ind] > 0:
dic["index_ka"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = k
else:
dic[var + "a"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = quan[
dic["actind"][ind]
]
else:
p_v, val = 0.0, 0.0
for sld in range(dic["slide"][n][1][0], dic["slide"][n][1][1]):
ind = i + sld * dic["nx"] + k * dic["nx"] * dic["ny"]
if dic["porv"][ind] > 0:
if var.lower() in dic["mass"]:
p_v = 1.0
val += quan[dic["actind"][ind]]
else:
p_v += dic["porv"][ind]
val += quan[dic["actind"][ind]] * dic["porv"][ind]
dic[var + "a"][2 * i + 2 * (dic["nz"] - k - 1) * dic["mx"]] = (
np.nan if p_v == 0 else val / p_v
)
for i, well in enumerate(dic["wells"]):
for k in range(well[2], well[3] + 1):
dic["wellsa"][2 * well[0] + 2 * (dic["nz"] - k - 1) * dic["mx"]] = i
Expand All @@ -170,26 +197,40 @@ def map_yzcoords(dic, var, quan, n):
"""
for k in range(dic["nz"]):
for j in range(dic["ny"]):
ind = dic["slide"][n][0] + j * dic["nx"] + k * dic["nx"] * dic["ny"]
if dic["porv"][ind] > 0:
if var.lower() == "grid":
ind = dic["slide"][n][0][0] + j * dic["nx"] + k * dic["nx"] * dic["ny"]
if var.lower() == "grid":
if dic["porv"][ind] > 0:
dic["grida"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = 1
elif var.lower() == "wells":
elif var.lower() == "wells":
if dic["porv"][ind] > 0:
dic["wellsa"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = len(
dic["wells"]
)
elif var.lower() == "index_i":
elif var.lower() == "index_i":
if dic["porv"][ind] > 0:
dic[var + "a"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = dic[
"slide"
][n][0]
elif var.lower() == "index_j":
][n][0][0]
elif var.lower() == "index_j":
if dic["porv"][ind] > 0:
dic[var + "a"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = j
elif var.lower() == "index_k":
elif var.lower() == "index_k":
if dic["porv"][ind] > 0:
dic[var + "a"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = k
else:
dic[var + "a"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = quan[
dic["actind"][ind]
]
else:
p_v, val = 0.0, 0.0
for sld in range(dic["slide"][n][0][0], dic["slide"][n][0][1]):
ind = sld + j * dic["nx"] + k * dic["nx"] * dic["ny"]
if dic["porv"][ind] > 0:
if var.lower() in dic["mass"]:
p_v = 1.0
val += quan[dic["actind"][ind]]
else:
p_v += dic["porv"][ind]
val += quan[dic["actind"][ind]] * dic["porv"][ind]
dic[var + "a"][2 * j + 2 * (dic["nz"] - k - 1) * dic["mx"]] = (
np.nan if p_v == 0 else val / p_v
)
for i, well in enumerate(dic["wells"]):
for k in range(well[2], well[3] + 1):
dic["wellsa"][2 * well[1] + 2 * (dic["nz"] - k - 1) * dic["mx"]] = i
Expand All @@ -208,19 +249,35 @@ def map_xycoords(dic, var, quan, n):
"""
for j in range(dic["ny"]):
for i in range(dic["nx"]):
ind = i + j * dic["nx"] + dic["slide"][n][2] * dic["nx"] * dic["ny"]
if dic["porv"][ind] > 0:
if var.lower() == "grid":
ind = i + j * dic["nx"] + dic["slide"][n][2][0] * dic["nx"] * dic["ny"]
if var.lower() == "grid":
if dic["porv"][ind] > 0:
dic["grida"][2 * i + 2 * j * dic["mx"]] = 1
elif var.lower() == "wells":
elif var.lower() == "wells":
if dic["porv"][ind] > 0:
dic["wellsa"][2 * i + 2 * j * dic["mx"]] = len(dic["wells"])
elif var.lower() == "index_i":
elif var.lower() == "index_i":
if dic["porv"][ind] > 0:
dic[var + "a"][2 * i + 2 * j * dic["mx"]] = i
elif var.lower() == "index_j":
elif var.lower() == "index_j":
if dic["porv"][ind] > 0:
dic[var + "a"][2 * i + 2 * j * dic["mx"]] = j
elif var.lower() == "index_k":
dic[var + "a"][2 * i + 2 * j * dic["mx"]] = dic["slide"][n][2]
else:
dic[var + "a"][2 * i + 2 * j * dic["mx"]] = quan[dic["actind"][ind]]
elif var.lower() == "index_k":
if dic["porv"][ind] > 0:
dic[var + "a"][2 * i + 2 * j * dic["mx"]] = dic["slide"][n][2][0]
else:
p_v, val = 0.0, 0.0
for sld in range(dic["slide"][n][2][0], dic["slide"][n][2][1]):
ind = i + j * dic["nx"] + sld * dic["nx"] * dic["ny"]
if dic["porv"][ind] > 0:
if var.lower() in dic["mass"]:
p_v = 1.0
val += quan[dic["actind"][ind]]
else:
p_v += dic["porv"][ind]
val += quan[dic["actind"][ind]] * dic["porv"][ind]
dic[var + "a"][2 * i + 2 * j * dic["mx"]] = (
np.nan if p_v == 0 else val / p_v
)
for i, well in enumerate(dic["wells"]):
dic["wellsa"][2 * well[0] + 2 * well[1] * dic["mx"]] = i
Loading

0 comments on commit 9b552ed

Please sign in to comment.