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

Functionality to extract submodels #23

Merged
merged 1 commit into from
Feb 2, 2025
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
13 changes: 2 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,8 @@ cython_debug/
.DS_Store

# Tests
tests/configs/ert
tests/decks/coarser
tests/decks/finer
tests/configs/ert
tests/configs/jobs
tests/configs/logs
tests/configs/observations
tests/configs/parameters
tests/configs/output
tests/configs/postprocessing
tests/configs/preprocessing
**/tests/decks/*/
**/tests/configs/*/
tests/configs/.ert_runpath_list
tests/configs/ert.ert

Expand Down
19 changes: 17 additions & 2 deletions src/pycopm/core/pycopm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def pycopm():
dic["pvcorr"] = int(cmdargs["pvcorr"])
dic["fipcorr"] = int(cmdargs["fipcorr"])
dic["trans"] = int(cmdargs["trans"])
dic["vicinity"] = cmdargs["vicinity"].strip()
for label, name, tag in zip(["", "r"], ["coarsening", "gridding"], ["coar", "ref"]):
dic[f"{label}cijk"] = "yes"
for i in ["x", "y", "z"]:
Expand All @@ -67,7 +68,7 @@ def pycopm():
if not os.path.exists(f"{dic['exe']}/{dic['fol']}"):
os.system(f"mkdir {dic['exe']}/{dic['fol']}")

# When a deck is given, then we only generate the coarser/refined files
# When a deck is given, only coarser/refined/submodel files are generated
if "DATA" in file:
dic["deck"] = file.upper()[:-5]
create_deck(dic)
Expand Down Expand Up @@ -143,6 +144,15 @@ def load_parser():
default="flow",
help="OPM Flow path to executable or just 'flow' ('flow' by default).",
)
parser.add_argument(
"-v",
"--vicinity",
default="",
help="The location to extract the sub model. This can be assigned by a "
"region assignation, e.g., 'fipnum 2,4' extracts the cells with fipnums "
"equal to 2 or 4, or can be assigned by a polygon given the xy locations "
"in meters, e.g., 'xypolygon [0,0] [30,0] [30,30] [0,0]' ('' by default).",
)
parser.add_argument(
"-c",
"--coarsening",
Expand Down Expand Up @@ -226,7 +236,12 @@ def load_parser():
"-p",
"--pvcorr",
default=0,
help="Add the removed pore volume to the closest coarser cells ('0' by default).",
help="In coarsening, set to '1' to add the removed pore volume to the closest coarser "
"cells, while in submodels '1' adds the porv from outside on the boundary of the "
"submodel, '2' adds the corner regions (e.g., below the mini and minj from the input "
"model) to the corners in the submodel, '3' distributes the porv uniformly along the "
"boundary, and '4' distributes it on the whole submodel ('0' by default, i.e., no "
"porv correction).",
)
parser.add_argument(
"-q",
Expand Down
18 changes: 16 additions & 2 deletions src/pycopm/utils/generate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
from mako.template import Template
from pycopm.utils.parser_deck import process_the_deck
from pycopm.utils.mapping_methods import (
add_pv_bc,
chop_grid,
coarsening_dir,
handle_pv,
handle_cp_grid,
handle_refinement,
handle_clusters,
handle_vicinity,
map_ijk,
map_properties,
map_vicinity,
refine_grid,
)

Expand Down Expand Up @@ -104,6 +108,8 @@ def create_deck(dic):
dic["ini"] = ResdataFile(f"{dic['exe']}/" + dic["deck"] + ".INIT")
if dic["refinement"]:
print("\nInitializing pycopm to generate the refinned files, please wait")
elif dic["vicinity"]:
print("\nInitializing pycopm to generate the submodel files, please wait")
elif not dic["ijk"]:
print("\nInitializing pycopm to generate the coarsened files, please wait")
if dic["ini"].has_kw("SWATINIT"):
Expand Down Expand Up @@ -138,8 +144,12 @@ def create_deck(dic):
dic["regions"] += [name]
nc = dic["grid"].nx * dic["grid"].ny * dic["grid"].nz
dic["con"] = np.array([0 for _ in range(nc)])
dic["porv"] = np.array(dic["ini"].iget_kw("PORV")[0])
dic["actind"] = dic["porv"] > 0
if dic["refinement"]:
handle_refinement(dic)
elif dic["vicinity"]:
handle_vicinity(dic)
else:
handle_clusters(dic)
for name in dic["props"] + dic["regions"] + dic["grids"]:
Expand All @@ -152,7 +162,6 @@ def create_deck(dic):
dic["kc"][dic["ijk"][2]],
)
sys.exit()
dic["porv"] = np.array(dic["ini"].iget_kw("PORV")[0])
actnum = np.array([0 for _ in range(nc)])
for i in ["x", "y", "z"]:
dic[f"d_{i}"] = np.array([np.nan for _ in range(nc)])
Expand All @@ -162,7 +171,6 @@ def create_deck(dic):
z_b = np.array([np.nan for _ in range(nc)])
z_b_t = np.array([np.nan for _ in range(nc)])
if dic["refinement"]:
dic["actind"] = dic["porv"] > 0
for name in dic["props"] + dic["regions"] + dic["grids"] + ["porv"]:
dic[name] = np.zeros(nc)
if name == "porv":
Expand Down Expand Up @@ -191,6 +199,8 @@ def create_deck(dic):
)
n += 1
dic["actnum_c"] = ["1" if float(val) > 0 else "0" for val in dic["porv_c"]]
elif dic["vicinity"]:
map_vicinity(dic)
else:
n = 0
zti = [2, 5, 8, 11]
Expand Down Expand Up @@ -255,6 +265,10 @@ def create_deck(dic):
process_the_deck(dic)
if dic["refinement"]:
refine_grid(dic)
elif dic["vicinity"]:
chop_grid(dic)
if dic["pvcorr"] > 0:
add_pv_bc(dic)
else:
clusmin, clusmax, rmv = map_properties(dic, actnum, z_t, z_b, z_b_t, v_c)
if dic["pvcorr"] == 1:
Expand Down
Loading