Skip to content

Commit

Permalink
[BUGFIX] Well1 position in SPE11C
Browse files Browse the repository at this point in the history
  • Loading branch information
daavid00 committed Feb 21, 2025
1 parent 956873e commit 0aa8eec
Show file tree
Hide file tree
Showing 19 changed files with 1,561 additions and 85 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,5 @@ playground
# Tests
tests/configs/check_format.py
tests/configs/is_notebook.py
**/tests/configs/*/
**/tests/configs/*/
**/tests/decks/*/
27 changes: 13 additions & 14 deletions src/pyopmspe11/core/pyopmspe11.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ def pyopmspe11():
"""Main function for the pyopmspe11 executable"""
cmdargs = load_parser()
file = cmdargs["input"].strip() # Name of the input file
dic = {"fol": cmdargs["output"].strip()} # Name for the output folder
dic = {"fol": os.path.abspath(cmdargs["output"])} # Name for the output folder
dic["generate"] = cmdargs["generate"].strip() # What data to write
dic["exe"] = os.getcwd() # Path to the folder of the input.txt file
dic["mode"] = cmdargs["mode"].strip() # Parts of the workflow to run
dic["pat"] = os.path.dirname(__file__)[:-5] # Path to the pyopmspe11 folder
dic["compare"] = cmdargs["compare"].strip() # Make common figures for comparison
Expand All @@ -43,12 +42,12 @@ def pyopmspe11():
process_input(dic, file)

# Make the output folders
if not os.path.exists(f"{dic['exe']}/{dic['fol']}"):
os.system(f"mkdir {dic['exe']}/{dic['fol']}")
if not os.path.exists(f"{dic['fol']}"):
os.system(f"mkdir {dic['fol']}")
for fil in ["deck", "flow" if dic["mode"] != "deck" else ""]:
if not os.path.exists(f"{dic['exe']}/{dic['fol']}/{fil}"):
os.system(f"mkdir {dic['exe']}/{dic['fol']}/{fil}")
os.chdir(f"{dic['exe']}/{dic['fol']}")
if not os.path.exists(f"{dic['fol']}/{fil}"):
os.system(f"mkdir {dic['fol']}/{fil}")
os.chdir(f"{dic['fol']}")

if dic["mode"] == "all" or "deck" in dic["mode"]:
# Check the generated deck, flow version, and chosen co2store implementation
Expand All @@ -58,7 +57,7 @@ def pyopmspe11():
# For corner-point grids, get the cell centers by executing flow
if dic["grid"] == "corner-point":
initial(dic)
os.chdir(f"{dic['exe']}/{dic['fol']}/deck")
os.chdir(f"{dic['fol']}/deck")
simulations(dic, "INITIAL", "flow", True)
print(
"Files used to generate the corner-point grid (INITIAL.* files).\n"
Expand All @@ -70,21 +69,21 @@ def pyopmspe11():
positions(dic)
# Write used opm related files
opm_files(dic)
print(f"The deck files have been written to {dic['exe']}/{dic['fol']}/deck.")
print(f"The deck files have been written to {dic['fol']}/deck.")
if dic["mode"] == "all" or "flow" in dic["mode"]:
# Run the simulations
simulations(dic, dic["fol"].upper(), "flow", False)
simulations(dic, dic["fol"].split("/")[-1].upper(), "flow", False)

if dic["mode"] == "all" or "data" in dic["mode"]:
# Write the data
if not os.path.exists(f"{dic['exe']}/{dic['fol']}/data"):
os.system(f"mkdir {dic['exe']}/{dic['fol']}/data")
if not os.path.exists(f"{dic['fol']}/data"):
os.system(f"mkdir {dic['fol']}/data")
data(dic)

if dic["mode"] == "all" or "plot" in dic["mode"]:
# Make some useful plots after the studies
if not os.path.exists(f"{dic['exe']}/{dic['fol']}/figures"):
os.system(f"mkdir {dic['exe']}/{dic['fol']}/figures")
if not os.path.exists(f"{dic['fol']}/figures"):
os.system(f"mkdir {dic['fol']}/figures")
plotting(dic)


Expand Down
2 changes: 1 addition & 1 deletion src/pyopmspe11/templates/common/saturation_functions.mako
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def safu_evaluation():
% endfor

with open(
"${dic['exe']}/${dic['fol']}/deck/TABLES.INC",
"${dic['fol']}/deck/TABLES.INC",
"w",
encoding="utf8",
) as file:
Expand Down
50 changes: 17 additions & 33 deletions src/pyopmspe11/utils/mapproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def structured_handling_spe11a(dic):
sensors(dic)
wells(dic)
with open(
f"{dic['exe']}/{dic['fol']}/deck/centers.txt",
f"{dic['fol']}/deck/centers.txt",
"w",
encoding="utf8",
) as file:
file.write("\n".join(centers))
with open(
f"{dic['exe']}/{dic['fol']}/deck/corners.txt",
f"{dic['fol']}/deck/corners.txt",
"w",
encoding="utf8",
) as file:
Expand Down Expand Up @@ -251,13 +251,13 @@ def structured_handling_spe11bc(dic):
sensors(dic)
wells(dic)
with open(
f"{dic['exe']}/{dic['fol']}/deck/centers.txt",
f"{dic['fol']}/deck/centers.txt",
"w",
encoding="utf8",
) as file:
file.write("\n".join(centers))
with open(
f"{dic['exe']}/{dic['fol']}/deck/corners.txt",
f"{dic['fol']}/deck/corners.txt",
"w",
encoding="utf8",
) as file:
Expand Down Expand Up @@ -406,13 +406,13 @@ def corner_point_handling_spe11a(dic):
dic["wellijk"][0] = [well1ijk[0] + 1, 1, well1ijk[2] + 1]
dic["wellijk"][1] = [well2ijk[0] + 1, 1, well2ijk[2] + 1]
with open(
f"{dic['exe']}/{dic['fol']}/deck/centers.txt",
f"{dic['fol']}/deck/centers.txt",
"w",
encoding="utf8",
) as file:
file.write("\n".join(centers))
with open(
f"{dic['exe']}/{dic['fol']}/deck/corners.txt",
f"{dic['fol']}/deck/corners.txt",
"w",
encoding="utf8",
) as file:
Expand Down Expand Up @@ -580,13 +580,13 @@ def corner_point_handling_spe11bc(dic):
dic["well2"] = pd.Series(well2).argmin()
locate_wells_sensors(dic)
with open(
f"{dic['exe']}/{dic['fol']}/deck/centers.txt",
f"{dic['fol']}/deck/centers.txt",
"w",
encoding="utf8",
) as file:
file.write("\n".join(centers))
with open(
f"{dic['exe']}/{dic['fol']}/deck/corners.txt",
f"{dic['fol']}/deck/corners.txt",
"w",
encoding="utf8",
) as file:
Expand Down Expand Up @@ -637,16 +637,9 @@ def locate_wells_sensors(dic):
get_cell_info(dic, well1ijk[0] + k * dic["noCells"][0])
z_centers.append(dic["xyz"][2])
for j in range(dic["wellijk"][0][1], dic["wellijkf"][0][1] + 1):
midpoints = z_centers - map_z(dic, j - 1)
midpoints = z_centers - map_z(dic, j - 1) - dic["maxelevation"]
dic["wellkh"].append(
pd.Series(
abs(
dic["wellCoord"][0][2]
- map_z(dic, dic["wellijk"][0][1] - 1)
- midpoints
)
).argmin()
+ 1
pd.Series(abs(dic["wellCoord"][0][2] - midpoints)).argmin() + 1
)
dic["fipnum"][
dic["sensorijk"][0][0]
Expand Down Expand Up @@ -741,8 +734,8 @@ def positions(dic):
dic[f"{names}"] = []
if dic["grid"] == "corner-point":
if dic["use"] == "opm":
dic["gridf"] = OpmGrid(f"{dic['exe']}/{dic['fol']}/flow/INITIAL.EGRID")
dic["initf"] = OpmFile(f"{dic['exe']}/{dic['fol']}/flow/INITIAL.INIT")
dic["gridf"] = OpmGrid(f"{dic['fol']}/flow/INITIAL.EGRID")
dic["initf"] = OpmFile(f"{dic['fol']}/flow/INITIAL.INIT")
dic["no_cells"] = (
dic["gridf"].dimension[0]
* dic["gridf"].dimension[1]
Expand All @@ -753,8 +746,8 @@ def positions(dic):
dic["d_z"] = np.array([0.0] * dic["no_cells"])
dic["d_z"][dic["actind"]] = list(dic["initf"]["DZ"])
else:
dic["gridf"] = Grid(f"{dic['exe']}/{dic['fol']}/flow/INITIAL.EGRID")
dic["initf"] = ResdataFile(f"{dic['exe']}/{dic['fol']}/flow/INITIAL.INIT")
dic["gridf"] = Grid(f"{dic['fol']}/flow/INITIAL.EGRID")
dic["initf"] = ResdataFile(f"{dic['fol']}/flow/INITIAL.INIT")
dic["actnum"] = list(dic["gridf"].export_actnum())
dic["no_cells"] = dic["gridf"].nx * dic["gridf"].ny * dic["gridf"].nz
dic["actind"] = list(i for i, act in enumerate(dic["actnum"]) if act == 1)
Expand All @@ -769,9 +762,7 @@ def positions(dic):
structured_handling_spe11a(dic)
else:
structured_handling_spe11bc(dic)
np.savetxt(
f"{dic['exe']}/{dic['fol']}/deck/ycenters.txt", dic["ymy_center"], fmt="%.8E"
)
np.savetxt(f"{dic['fol']}/deck/ycenters.txt", dic["ymy_center"], fmt="%.8E")


def sensors(dic):
Expand Down Expand Up @@ -847,16 +838,9 @@ def wells(dic):
if dic["spe11"] == "spe11c":
dic["wellkh"] = []
for j in range(dic["wellijk"][0][1], dic["wellijkf"][0][1] + 1):
midpoints = dic["zmz_center"] - map_z(dic, j - 1)
midpoints = dic["zmz_center"] - map_z(dic, j - 1) - dic["maxelevation"]
dic["wellkh"].append(
pd.Series(
abs(
dic["wellCoord"][0][2]
- map_z(dic, dic["wellijk"][0][1] - 1)
- midpoints
)
).argmin()
+ 1
pd.Series(abs(dic["wellCoord"][0][2] - midpoints)).argmin() + 1
)


Expand Down
6 changes: 2 additions & 4 deletions src/pyopmspe11/utils/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def simulations(dic, deck, folder, dryrun):
flow = dic["only_flow"]
flag = "--enable-dry-run=1"
os.system(
f"{flow} --output-dir={dic['exe']}/{dic['fol']}/{folder} "
f"{dic['exe']}/{dic['fol']}/deck/{deck}.DATA {flag} & wait\n"
f"{flow} --output-dir={dic['fol']}/{folder} "
f"{dic['fol']}/deck/{deck}.DATA {flag} & wait\n"
)


Expand All @@ -44,7 +44,6 @@ def plotting(dic):
None
"""
os.chdir(f"{dic['exe']}")
plot_exe = [
"python3",
f"{dic['pat']}/visualization/plotting.py",
Expand Down Expand Up @@ -72,7 +71,6 @@ def data(dic):
None
"""
os.chdir(f"{dic['exe']}")
data_exe = [
"python3",
f"{dic['pat']}/visualization/data.py",
Expand Down
24 changes: 11 additions & 13 deletions src/pyopmspe11/utils/writefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ def initial(dic):
mytemplate = Template(filename=f"{dic['pat']}/templates/common/grid_initial.mako")
filledtemplate = mytemplate.render(**var)
with open(
f"{dic['exe']}/{dic['fol']}/deck/GRID.INC",
f"{dic['fol']}/deck/GRID.INC",
"w",
encoding="utf8",
) as file:
file.write(filledtemplate)
mytemplate = Template(filename=f"{dic['pat']}/templates/common/deck_initial.mako")
var = {"dic": dic}
filledtemplate = mytemplate.render(**var)
with open(
f"{dic['exe']}/{dic['fol']}/deck/INITIAL.DATA", "w", encoding="utf8"
) as file:
with open(f"{dic['fol']}/deck/INITIAL.DATA", "w", encoding="utf8") as file:
file.write(filledtemplate)


Expand Down Expand Up @@ -87,7 +85,7 @@ def write_keywords(dic):
dic[f"{names}"].insert(0, "-- Copyright (C) 2023 NORCE")
dic[f"{names}"].append("/")
with open(
f"{dic['exe']}/{dic['fol']}/deck/{names.upper()}.INC",
f"{dic['fol']}/deck/{names.upper()}.INC",
"w",
encoding="utf8",
) as file:
Expand All @@ -111,7 +109,7 @@ def added_pv(dic, git):
dic["porv"].insert(0, "-- Copyright (C) 2023 NORCE")
dic["porv"].append("/")
with open(
f"{dic['exe']}/{dic['fol']}/deck/PVBOUNDARIES.INC",
f"{dic['fol']}/deck/PVBOUNDARIES.INC",
"w",
encoding="utf8",
) as file:
Expand All @@ -134,7 +132,7 @@ def opm_files(dic):
var = {"dic": dic}
filledtemplate = mytemplate.render(**var)
with open(
f"{dic['exe']}/{dic['fol']}/deck/{dic['fol'].upper()}.DATA",
f"{dic['fol']}/deck/{dic['fol'].split('/')[-1].upper()}.DATA",
"w",
encoding="utf8",
) as file:
Expand All @@ -150,7 +148,7 @@ def opm_files(dic):
)
filledtemplate = mytemplate.render(**var)
with open(
f"{dic['exe']}/{dic['fol']}/deck/GRID.INC",
f"{dic['fol']}/deck/GRID.INC",
"w",
encoding="utf8",
) as file:
Expand All @@ -160,19 +158,19 @@ def opm_files(dic):
)
filledtemplate = mytemplate.render(**var)
with open(
f"{dic['exe']}/{dic['fol']}/deck/saturation_functions.py",
f"{dic['fol']}/deck/saturation_functions.py",
"w",
encoding="utf8",
) as file:
file.write(filledtemplate)
os.system(f"chmod u+x {dic['exe']}/{dic['fol']}/deck/saturation_functions.py")
os.system(f"chmod u+x {dic['fol']}/deck/saturation_functions.py")
prosc = subprocess.run(
["python3", f"{dic['exe']}/{dic['fol']}/deck/saturation_functions.py"],
["python3", f"{dic['fol']}/deck/saturation_functions.py"],
check=True,
)
if prosc.returncode != 0:
raise ValueError(f"Invalid result: { prosc.returncode }")
os.system(f"rm -rf {dic['exe']}/{dic['fol']}/deck/saturation_functions.py")
os.system(f"rm -rf {dic['fol']}/deck/saturation_functions.py")
inj_t = 0.0
skip_unrst = 0
ini_count = 0
Expand All @@ -186,7 +184,7 @@ def opm_files(dic):
for _ in range(int(inj[0] / inj[1])):
times.append(f"{inj[1] + float(times[-1])}")
with open(
f"{dic['exe']}/{dic['fol']}/deck/dt.txt",
f"{dic['fol']}/deck/dt.txt",
"w",
encoding="utf8",
) as file:
Expand Down
14 changes: 8 additions & 6 deletions src/pyopmspe11/visualization/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Script to write the benchmark data
"""

import os
import argparse
import warnings
import csv
Expand Down Expand Up @@ -96,13 +95,12 @@ def main():
dig = {"path": cmdargs["path"].strip()}
dig["case"] = cmdargs["deck"].strip()
dig["mode"] = cmdargs["generate"].strip()
dig["exe"] = os.getcwd()
dig["where"] = f"{dig['exe']}/{dig['path']}/data"
dig["where"] = f"{dig['path']}/data"
dig["use"] = cmdargs["use"].strip()
dig["nxyz"] = np.genfromtxt(
StringIO(cmdargs["resolution"]), delimiter=",", dtype=int
)
dig["sim"] = "./" + dig["path"] + "/flow/" + f"{dig['path'].upper()}"
dig["sim"] = dig["path"] + "/flow/" + f"{dig['path'].split('/')[-1].upper()}"
if dig["case"] == "spe11a":
dig["dense_t"] = (
np.genfromtxt(StringIO(cmdargs["time"]), delimiter=",", dtype=float) * 3600
Expand Down Expand Up @@ -293,7 +291,9 @@ def performance(dig):
0, dig["times"][-1], round(dig["times"][-1] / dig["sparse_t"]) + 1
)
with open(
f"{dig['path']}/flow/{dig['path'].upper()}.INFOSTEP", "r", encoding="utf8"
f"{dig['path']}/flow/{dig['path'].split('/')[-1].upper()}.INFOSTEP",
"r",
encoding="utf8",
) as file:
for j, row in enumerate(csv.reader(file)):
if j > 0:
Expand Down Expand Up @@ -1148,7 +1148,9 @@ def static_map_to_report_grid_performance_spatial(dig, dil):
"""
dil["latest_dts"], infotimes, tsteps = [], [], []
with open(
f"{dig['path']}/flow/{dig['path'].upper()}.INFOSTEP", "r", encoding="utf8"
f"{dig['path']}/flow/{dig['path'].split('/')[-1].upper()}.INFOSTEP",
"r",
encoding="utf8",
) as file:
for j, row in enumerate(csv.reader(file)):
if j > 0:
Expand Down
Loading

0 comments on commit 0aa8eec

Please sign in to comment.