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

[FUNC] Set -g single for deck and results in same folder #9

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
15 changes: 11 additions & 4 deletions src/pyopmnearwell/core/pyopmnearwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def pyopmnearwell():
"--generate",
default="all",
help="Run the whole framework ('all'), only run flow ('flow'), "
", only write the deck and run flow together in the output folder ('single'), "
"or only create plots ('plot') ('all' by default).",
)
parser.add_argument(
Expand Down Expand Up @@ -101,12 +102,18 @@ def pyopmnearwell():
# Make the output folders
if not os.path.exists(os.path.join(dic["exe"], dic["fol"])):
os.makedirs(os.path.join(dic["exe"], dic["fol"]))
for fil in ["preprocessing", "jobs", "output", "postprocessing"]:
if not os.path.exists(os.path.join(dic["exe"], dic["fol"], fil)):
os.makedirs(os.path.join(dic["exe"], dic["fol"], fil))
if dic["generate"] == "single":
dic["fprep"] = f"{dic['exe']}/{dic['fol']}"
dic["foutp"] = f"{dic['exe']}/{dic['fol']}"
else:
dic["fprep"] = f"{dic['exe']}/{dic['fol']}/preprocessing"
dic["foutp"] = f"{dic['exe']}/{dic['fol']}/output"
for fil in ["preprocessing", "jobs", "output", "postprocessing"]:
if not os.path.exists(os.path.join(dic["exe"], dic["fol"], fil)):
os.makedirs(os.path.join(dic["exe"], dic["fol"], fil))
os.chdir(os.path.join(dic["exe"], dic["fol"]))

if dic["generate"] in ["all", "flow"]:
if dic["generate"] in ["all", "flow", "single"]:
# Write used opm related files
reservoir_files(dic)

Expand Down
4 changes: 3 additions & 1 deletion src/pyopmnearwell/ml/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ def setup_ensemble(
"fol": pathlib.Path(ensemble_path.name) / f"runfiles_{i}",
},
)
dic = readthesecondpart(lol, dic, index)
readthesecondpart(lol, dic, index)
dic.update({"runname": f"RUN_{i}"})
dic["fprep"] = f"{dic['exe']}/{dic['fol']}/preprocessing"
dic["foutp"] = f"{dic['exe']}/{dic['fol']}/output"
# Always calculate geology, grid, tables, etc. for the first ensemble member.
if i == 0:
reservoir_files(dic)
Expand Down
52 changes: 29 additions & 23 deletions src/pyopmnearwell/utils/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,37 @@ def simulations(dic):
dic (dict): Global dictionary with required parameters

"""
os.chdir(f"{dic['exe']}/{dic['fol']}/output")
if not "foutp" in dic:
dic["foutp"] = f"{dic['exe']}/{dic['fol']}/output"
if not "generate" in dic:
dic["generate"] = "all"
os.chdir(dic["foutp"])
os.system(
f"{dic['flow']} --output-dir={dic['exe']}/{dic['fol']}/output "
f"{dic['exe']}/{dic['fol']}/preprocessing/{dic['runname'].upper()}.DATA & wait\n"
f"{dic['flow']} --output-dir={dic['foutp']} "
f"{dic['fprep']}/{dic['runname'].upper()}.DATA & wait\n"
)
# We save few variables for the plotting methods
np.save("xspace", dic["xcor"])
np.save("zspace", dic["zcor"])
np.save("ny", dic["noCells"][1])
schedule = [0]
for nrst in dic["inj"]:
for _ in range(round(nrst[0] / nrst[1])):
schedule.append(schedule[-1] + nrst[1] * 86400.0)
np.save("schedule", schedule)
np.save("radius", 0.5 * dic["diameter"])
if dic["grid"] in ["cartesian2d", "cartesian"]:
np.save("angle", 360.0)
else:
np.save("angle", dic["dims"][1])
if dic["grid"] == "cartesian":
np.save(
"position", (dic["noCells"][0] - 1) * (mt.floor(dic["noCells"][0] / 2) + 1)
)
else:
np.save("position", 0)
if dic["generate"] in ["all", "plot"]:
# We save few variables for the plotting methods
np.save("xspace", dic["xcor"])
np.save("zspace", dic["zcor"])
np.save("ny", dic["noCells"][1])
schedule = [0]
for nrst in dic["inj"]:
for _ in range(round(nrst[0] / nrst[1])):
schedule.append(schedule[-1] + nrst[1] * 86400.0)
np.save("schedule", schedule)
np.save("radius", 0.5 * dic["diameter"])
if dic["grid"] in ["cartesian2d", "cartesian"]:
np.save("angle", 360.0)
else:
np.save("angle", dic["dims"][1])
if dic["grid"] == "cartesian":
np.save(
"position",
(dic["noCells"][0] - 1) * (mt.floor(dic["noCells"][0] / 2) + 1),
)
else:
np.save("position", 0)


def plotting(dic):
Expand Down
27 changes: 10 additions & 17 deletions src/pyopmnearwell/utils/writefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def reservoir_files(
"regions_file": "REGIONS.INC",
}
)

if not "fprep" in dic:
dic["fprep"] = f"{dic['exe']}/{dic['fol']}/preprocessing"
# Generation of the x-dir spatial discretization using a telescopic function.
if dic["x_fac"] != 0:
dic["xcor"] = np.flip(
Expand Down Expand Up @@ -138,11 +139,8 @@ def reservoir_files(
dic["pat"], "templates", dic["model"], f"{dic['template']}.mako"
),
)

with open(
os.path.join(
dic["exe"], dic["fol"], "preprocessing", f"{dic['runname'].upper()}.DATA"
),
os.path.join(dic["fprep"], f"{dic['runname'].upper()}.DATA"),
"w",
encoding="utf-8",
) as file:
Expand Down Expand Up @@ -176,12 +174,7 @@ def manage_sections(dic):
filename=os.path.join(dic["pat"], "templates", "common", f"{section}.mako"),
)
with open(
os.path.join(
dic["exe"],
dic["fol"],
"preprocessing",
f"{section.upper()}.INC",
),
os.path.join(dic["fprep"], f"{section.upper()}.INC"),
"w",
encoding="utf-8",
) as file:
Expand Down Expand Up @@ -244,7 +237,7 @@ def manage_grid(dic):
dxarray.insert(0, "DX")
dxarray.append("/")
with open(
os.path.join(dic["exe"], dic["fol"], "preprocessing", "DX.INC"),
os.path.join(dic["fprep"], "DX.INC"),
"w",
encoding="utf8",
) as file:
Expand All @@ -256,7 +249,7 @@ def manage_grid(dic):
dxarray.insert(0, "DRV")
dxarray.append("/")
with open(
os.path.join(dic["exe"], dic["fol"], "preprocessing", "DRV.INC"),
os.path.join(dic["fprep"], "DRV.INC"),
"w",
encoding="utf8",
) as file:
Expand All @@ -277,7 +270,7 @@ def manage_grid(dic):
var = {"dic": dic}
filledtemplate: str = fill_template(var, text="\n".join(lol))
with open(
os.path.join(dic["exe"], dic["fol"], "preprocessing", "GRID.INC"),
os.path.join(dic["fprep"], "GRID.INC"),
"w",
encoding="utf8",
) as file:
Expand Down Expand Up @@ -375,7 +368,7 @@ def d3_grids(dic, dxarray):
var = {"dic": dic}
filledtemplate: str = fill_template(var, text="\n".join(lol))
with open(
f"{dic['exe']}/{dic['fol']}/preprocessing/GRID.INC",
f"{dic['fprep']}/GRID.INC",
"w",
encoding="utf8",
) as file:
Expand All @@ -394,15 +387,15 @@ def d3_grids(dic, dxarray):
dxarray.insert(0, "DX")
dxarray.append("/")
with open(
f"{dic['exe']}/{dic['fol']}/preprocessing/DX.INC",
f"{dic['fprep']}/DX.INC",
"w",
encoding="utf8",
) as file:
file.write("\n".join(dxarray))
dyarray.insert(0, "DY")
dyarray.append("/")
with open(
f"{dic['exe']}/{dic['fol']}/preprocessing/DY.INC",
f"{dic['fprep']}/DY.INC",
"w",
encoding="utf8",
) as file:
Expand Down
Loading