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

Option to write and use coarse transmissibilities #13

Merged
merged 1 commit into from
Sep 25, 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
1 change: 1 addition & 0 deletions docs/_sources/introduction.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where
-s Use `min`, `max`, or `mean` to scale permx, permy, permz, poro, swatinit, and all mult(-)xyz ('' by default, i.e., using the arithmetic average for permx/permy, harmonic average for permz, volume weighted mean for mult(-)xyz, and the pore volume weighted mean for the rest).
-p Add the removed pore volume to the closest coarser cells (`0` by default, `1` to enable).
-q Adjust the pv to the initial FGIP and FOIP from the input deck (`0` by default, `1` to enable).
-t Write and use upscaled transmissibilities (`0` by default, it is advice to use only with z-coarsening).
-r Remove CONFACT and KH from COMPDAT (`1`) and also remove PEQVR (`2`) (ITEM 13, the last entry) to compute the well transmisibility connections internally in OPM Flow using the grid properties (`2` by default; `0` to not remove).
-j Tuning parameter to avoid creation of neighbouring connections in the coarser model where there are discontinuities between cells along the z direction, e.g., around faults ('' by default, i.e., nothing corrected; if need it, try with values of the order of 1).
-m Execute a dry run on the input deck to generate the static properties ('prep'), generate only the coarse files ('deck'), only exectute a dry run on the generated coarse model ('dry'), 'prep_deck', 'deck_dry', or do all ('all') (`prep_deck` by default).
Expand Down
3 changes: 3 additions & 0 deletions docs/introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ <h2>Roadmap<a class="headerlink" href="#roadmap" title="Link to this heading">
<dt><kbd><span class="option">-q</span></kbd></dt>
<dd><p>Adjust the pv to the initial FGIP and FOIP from the input deck (<cite>0</cite> by default, <cite>1</cite> to enable).</p>
</dd>
<dt><kbd><span class="option">-t</span></kbd></dt>
<dd><p>Write and use upscaled transmissibilities (<cite>0</cite> by default, it is advice to use only with z-coarsening).</p>
</dd>
<dt><kbd><span class="option">-r</span></kbd></dt>
<dd><p>Remove CONFACT and KH from COMPDAT (<cite>1</cite>) and also remove PEQVR (<cite>2</cite>) (ITEM 13, the last entry) to compute the well transmisibility connections internally in OPM Flow using the grid properties (<cite>2</cite> by default; <cite>0</cite> to not remove).</p>
</dd>
Expand Down
2 changes: 1 addition & 1 deletion docs/pycopm.utils.generate_coarser_files.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@

<dl class="py function">
<dt class="sig sig-object py" id="pycopm.utils.generate_coarser_files.map_properties">
<span class="sig-prename descclassname"><span class="pre">pycopm.utils.generate_coarser_files.</span></span><span class="sig-name descname"><span class="pre">map_properties</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dic</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">actnum</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d_z</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z_b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z_b_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">v_c</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pycopm.utils.generate_coarser_files.map_properties" title="Link to this definition"></a></dt>
<span class="sig-prename descclassname"><span class="pre">pycopm.utils.generate_coarser_files.</span></span><span class="sig-name descname"><span class="pre">map_properties</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dic</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">actnum</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d_z</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z_b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z_b_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">v_c</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d_az</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pycopm.utils.generate_coarser_files.map_properties" title="Link to this definition"></a></dt>
<dd><p>Mapping to the coarse properties</p>
<dl>
<dt>Args:</dt><dd><p>dic (dict): Global dictionary</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/text/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where
-s Use `min`, `max`, or `mean` to scale permx, permy, permz, poro, swatinit, and all mult(-)xyz ('' by default, i.e., using the arithmetic average for permx/permy, harmonic average for permz, volume weighted mean for mult(-)xyz, and the pore volume weighted mean for the rest).
-p Add the removed pore volume to the closest coarser cells (`0` by default, `1` to enable).
-q Adjust the pv to the initial FGIP and FOIP from the input deck (`0` by default, `1` to enable).
-t Write and use upscaled transmissibilities (`0` by default, it is advice to use only with z-coarsening).
-r Remove CONFACT and KH from COMPDAT (`1`) and also remove PEQVR (`2`) (ITEM 13, the last entry) to compute the well transmisibility connections internally in OPM Flow using the grid properties (`2` by default; `0` to not remove).
-j Tuning parameter to avoid creation of neighbouring connections in the coarser model where there are discontinuities between cells along the z direction, e.g., around faults ('' by default, i.e., nothing corrected; if need it, try with values of the order of 1).
-m Execute a dry run on the input deck to generate the static properties ('prep'), generate only the coarse files ('deck'), only exectute a dry run on the generated coarse model ('dry'), 'prep_deck', 'deck_dry', or do all ('all') (`prep_deck` by default).
Expand Down
8 changes: 8 additions & 0 deletions src/pycopm/core/pycopm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def pycopm():
dic["encoding"] = cmdargs["encoding"].strip()
dic["pvcorr"] = int(cmdargs["pvcorr"])
dic["fipcorr"] = int(cmdargs["fipcorr"])
dic["trans"] = int(cmdargs["trans"])
dic["cijk"] = "yes"
for i in ["x", "y", "z"]:
dic[f"{i}coar"] = []
Expand Down Expand Up @@ -194,6 +195,13 @@ def load_parser():
default=0,
help="Adjust the pv to the initial FGIP and FOIP from the input deck ('0' by default).",
)
parser.add_argument(
"-t",
"--trans",
default=0,
help="Write and use upscaled transmissibilities ('0' by default, it is advice to use "
"only with z-coarsening).",
)
parser.add_argument(
"-r",
"--remove",
Expand Down
37 changes: 29 additions & 8 deletions src/pycopm/utils/generate_coarser_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2024 NORCE
# SPDX-License-Identifier: GPL-3.0
# pylint: disable=R0912,R0913,R0914,R0915,C0302
# pylint: disable=R0912,R0913,R0914,R0915,C0302,R0917

"""
Utiliy methods to only create the coarser files by pycopm.
Expand Down Expand Up @@ -101,6 +101,9 @@ def create_deck(dic):
if dic["ini"].has_kw(name.upper()):
if max(dic["ini"].iget_kw(name.upper())[0]) > 1:
dic["grids"] += [name]
if dic["trans"] == 1:
for name in ["tranx", "trany", "tranz"]:
dic["props"] += [name]
for name in [
"endnum",
"eqlnum",
Expand All @@ -119,6 +122,7 @@ def create_deck(dic):
dic["porv"] = np.array(dic["ini"].iget_kw("PORV")[0])
actnum = np.array([0 for _ in range(nc)])
d_z = np.array([np.nan for _ in range(nc)])
d_az = np.array([np.nan for _ in range(nc)])
v_c = np.array([np.nan for _ in range(nc)])
z_t = np.array([np.nan for _ in range(nc)])
z_b = np.array([np.nan for _ in range(nc)])
Expand All @@ -135,11 +139,12 @@ def create_deck(dic):
z_b[cell.global_index] = max(cxyz[cell.global_index][i] for i in zti)
tmp = max(cxyz[cell.global_index][i] for i in zbi)
z_b_t[cell.global_index] = tmp - z_t[cell.global_index]
d_z[cell.global_index] = dic["grid"].cell_dz(ijk=(cell.i, cell.j, cell.k))
v_c[cell.global_index] = dic["grid"].cell_volume(
ijk=(cell.i, cell.j, cell.k)
)
if cell.active == 1:
d_z[cell.global_index] = dic["grid"].cell_dz(
ijk=(cell.i, cell.j, cell.k)
)
v_c[cell.global_index] = dic["grid"].cell_volume(
d_az[cell.global_index] = dic["grid"].cell_dz(
ijk=(cell.i, cell.j, cell.k)
)
for name in dic["props"] + dic["regions"] + dic["grids"]:
Expand Down Expand Up @@ -172,7 +177,9 @@ def create_deck(dic):
dic["kc"][dic["ijk"][2]],
)
sys.exit()
clusmin, clusmax, rmv = map_properties(dic, actnum, d_z, z_t, z_b, z_b_t, v_c)
clusmin, clusmax, rmv = map_properties(
dic, actnum, d_z, z_t, z_b, z_b_t, v_c, d_az
)
if dic["pvcorr"] == 1:
handle_pv(dic, clusmin, clusmax, rmv)
handle_cp_grid(dic)
Expand Down Expand Up @@ -262,7 +269,7 @@ def create_deck(dic):
print("\nThe dry run of the coarse model succeeded\n")


def map_properties(dic, actnum, d_z, z_t, z_b, z_b_t, v_c):
def map_properties(dic, actnum, d_z, z_t, z_b, z_b_t, v_c, d_az):
"""
Mapping to the coarse properties

Expand All @@ -281,6 +288,7 @@ def map_properties(dic, actnum, d_z, z_t, z_b, z_b_t, v_c):
freq = pd.Series(actnum).groupby(dic["con"]).sum()
dz_c = pd.Series(z_b_t).groupby(dic["con"]).mean()
h_tot = pd.Series(d_z).groupby(dic["con"]).sum()
ha_tot = pd.Series(d_az).groupby(dic["con"]).sum()
v_tot = pd.Series(v_c).groupby(dic["con"]).sum()
if dic["how"] == "min":
clusmin = pd.Series(actnum).groupby(dic["con"]).min()
Expand Down Expand Up @@ -317,10 +325,19 @@ def map_properties(dic, actnum, d_z, z_t, z_b, z_b_t, v_c):
f"{val/h_t}" if h_t * val > 0 else "0"
for val, h_t in zip(c_c, h_tot)
]
elif name in ["tranx", "trany"]:
dic[f"{name}_c"] = [f"{val}" if val > 0 else "0" for val in c_c]
elif name == "tranz":
d_l = pd.Series(d_z).groupby(dic["con"]).last()
c_c = pd.Series(dic[name]).groupby(dic["con"]).last()
dic["tranz_c"] = [
f"{val*d_h/h_t}" if h_t * val > 0 else "0"
for val, h_t, d_h in zip(c_c, h_tot, d_l)
]
elif name == "permz":
dic["permz_c"] = [
f"{h_t/val}" if h_t * val > 0 else "0"
for val, h_t in zip(c_c, h_tot)
for val, h_t in zip(c_c, ha_tot)
]
elif name in ["poro", "swatinit"]:
dic[f"{name}_c"] = [
Expand Down Expand Up @@ -904,6 +921,10 @@ def handle_grid_props(dic, nrwo):
dic["lol"].append("EDIT\n")
dic["lol"].append("INCLUDE")
dic["lol"].append(f"'{dic['label']}PORV.INC' /\n")
if dic["trans"] == 1:
for name in ["tranx", "trany", "tranz"]:
dic["lol"].append("INCLUDE")
dic["lol"].append(f"'{dic['label']}{name.upper()}.INC' /\n")
else:
return True
return False
Expand Down
20 changes: 20 additions & 0 deletions tests/test_generic_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,24 @@ def test_generic_deck():
)
assert os.path.exists(f"{cwd}/tests/decks/coarser/HELLO_WORLD_PYCOPM.INIT")
assert os.path.exists(f"{cwd}/tests/decks/coarser/HELLO_WORLD_PYCOPM.EGRID")
subprocess.run(
[
"pycopm",
"-i",
"HELLO_WORLD.DATA",
"-o",
"coarser",
"-c",
"1,1,5",
"-m",
"deck_dry",
"-t",
"1",
"-w",
"TRANS",
],
check=True,
)
assert os.path.exists(f"{cwd}/tests/decks/coarser/TRANS.INIT")
assert os.path.exists(f"{cwd}/tests/decks/coarser/TRANS.EGRID")
os.chdir(cwd)
Loading