From c00e23c74e66953d9eb407edb502d86943dd71a7 Mon Sep 17 00:00:00 2001 From: David Landa Marban Date: Thu, 31 Oct 2024 13:11:28 +0100 Subject: [PATCH] [FUNC] Set -g single for deck and results in same folder --- src/pyopmnearwell/core/pyopmnearwell.py | 15 +++++-- src/pyopmnearwell/ml/ensemble.py | 4 +- src/pyopmnearwell/utils/runs.py | 52 ++++++++++++++----------- src/pyopmnearwell/utils/writefile.py | 27 +++++-------- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/pyopmnearwell/core/pyopmnearwell.py b/src/pyopmnearwell/core/pyopmnearwell.py index 41c156b..d151121 100644 --- a/src/pyopmnearwell/core/pyopmnearwell.py +++ b/src/pyopmnearwell/core/pyopmnearwell.py @@ -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( @@ -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) diff --git a/src/pyopmnearwell/ml/ensemble.py b/src/pyopmnearwell/ml/ensemble.py index 20412bc..ddd7c6f 100644 --- a/src/pyopmnearwell/ml/ensemble.py +++ b/src/pyopmnearwell/ml/ensemble.py @@ -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) diff --git a/src/pyopmnearwell/utils/runs.py b/src/pyopmnearwell/utils/runs.py index d5be790..a83cb6e 100644 --- a/src/pyopmnearwell/utils/runs.py +++ b/src/pyopmnearwell/utils/runs.py @@ -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): diff --git a/src/pyopmnearwell/utils/writefile.py b/src/pyopmnearwell/utils/writefile.py index 0b8abdf..7f230f5 100644 --- a/src/pyopmnearwell/utils/writefile.py +++ b/src/pyopmnearwell/utils/writefile.py @@ -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( @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -394,7 +387,7 @@ 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: @@ -402,7 +395,7 @@ def d3_grids(dic, 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: