Skip to content

Commit

Permalink
interp_relperm Allow two phase interpolation (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
alifbe authored May 24, 2024
1 parent b4a7737 commit 9f70d93
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/subscript/interp_relperm/interp_relperm.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ def make_wateroilgas(dframe: pd.DataFrame, delta_s: float) -> pyscal.WaterOilGas
The data must be restricted to only one SATNUM.
"""
dframe = dframe.copy() # Copy since we will modify it.
wog = pyscal.WaterOilGas(swl=dframe["SW"].min(), h=delta_s)
wog = pyscal.WaterOilGas(
swl=dframe["SW"].min() if "SW" in dframe.columns else 1.0 - dframe["SG"].max(),
h=delta_s,
)
if "PCOW" not in dframe:
dframe = dframe.assign(PCOW=0)
if "PCOG" not in dframe:
Expand All @@ -191,6 +194,7 @@ def make_wateroilgas(dframe: pd.DataFrame, delta_s: float) -> pyscal.WaterOilGas
.drop_duplicates()
.reset_index()
)
wog.wateroil.add_fromtable(wo_dframe)
go_dframe = (
dframe[["SG", "KRG", "KROG", "PCOG"]]
.set_index("SG")
Expand All @@ -202,23 +206,33 @@ def make_wateroilgas(dframe: pd.DataFrame, delta_s: float) -> pyscal.WaterOilGas
.drop_duplicates()
.reset_index()
)
wog.gasoil.add_fromtable(go_dframe)
else:
wo_dframe = dframe[["SW", "KRW", "KROW", "PCOW"]].dropna().reset_index()
go_dframe = dframe[["SG", "KRG", "KROG", "PCOG"]].dropna().reset_index()

wog.wateroil.add_fromtable(wo_dframe)
wog.gasoil.add_fromtable(go_dframe)
if {"SW", "KRW", "KROW", "PCOW"}.issubset(dframe.columns):
wog.wateroil.add_fromtable(
dframe[["SW", "KRW", "KROW", "PCOW"]].dropna().reset_index()
)
else:
wog.wateroil = None
if {"SG", "KRG", "KROG", "PCOG"}.issubset(dframe.columns):
wog.gasoil.add_fromtable(
dframe[["SG", "KRG", "KROG", "PCOG"]].dropna().reset_index()
)
else:
wog.gasoil = None

# socr can for floating point reasons become estimated to be larger than
# sorw, which means we are in an oil paleo zone setting. This is not
# supported by interp_relperm. Reset the property to ensure interpolation
# is not affected:
wog.wateroil.socr = wog.wateroil.sorw
if wog.wateroil:
wog.wateroil.socr = wog.wateroil.sorw

# If sgro > 0, it is a gas condensate object, which cannot be
# mixed with non-gas condensate (during interpolation). Avoid pitfalls
# in the estimated sgro by always setting it to zero:
wog.gasoil.sgro = 0.0
if wog.gasoil:
wog.gasoil.sgro = 0.0
return wog


Expand Down Expand Up @@ -248,7 +262,9 @@ def make_interpolant(
high = make_wateroilgas(high_df.loc[satnum], delta_s)
rec = pyscal.SCALrecommendation(low, base, high, "SATNUM " + str(satnum), h=delta_s)

return rec.interpolate(interp_param["param_w"], interp_param["param_g"], h=delta_s)
return rec.interpolate(
interp_param.get("param_w", 0.0), interp_param.get("param_g", 0), h=delta_s
)


def get_parser() -> argparse.ArgumentParser:
Expand Down
116 changes: 116 additions & 0 deletions tests/test_interp_relperm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,52 @@
],
).set_index("CASE")

OIL_WATER_PYSCAL_MOCK = pd.DataFrame(
columns=[
"CASE",
"SATNUM",
"Nw",
"Now",
"swl",
"a",
"b",
"poro_ref",
"perm_ref",
"drho",
],
data=[
["low", 1, 1.1, 1, 0.1, 2, -2, 0.25, 100, 150],
["low", 2, 1.1, 1, 0.1, 2, -2, 0.25, 100, 150],
["base", 1, 2, 2, 0.1, 2, -2, 0.25, 200, 150],
["base", 2, 2, 2, 0.1, 2, -2, 0.25, 200, 150],
["high", 1, 3, 3, 0.1, 2, -2, 0.25, 300, 150],
["high", 2, 3, 3, 0.1, 2, -2, 0.25, 300, 150],
],
).set_index("CASE")

OIL_GAS_PYSCAL_MOCK = pd.DataFrame(
columns=[
"CASE",
"SATNUM",
"Ng",
"Nog",
"swl",
"a",
"b",
"poro_ref",
"perm_ref",
"drho",
],
data=[
["low", 1, 1, 1, 0.1, 2, -2, 0.25, 100, 150],
["low", 2, 1, 1, 0.1, 2, -2, 0.25, 100, 150],
["base", 1, 2, 2, 0.1, 2, -2, 0.25, 200, 150],
["base", 2, 2, 2, 0.1, 2, -2, 0.25, 200, 150],
["high", 1, 3, 3, 0.1, 2, -2, 0.25, 300, 150],
["high", 2, 3, 3, 0.1, 2, -2, 0.25, 300, 150],
],
).set_index("CASE")


def test_prepend_root_path():
"""Test that we need to prepend with root-path"""
Expand Down Expand Up @@ -179,6 +225,76 @@ def test_parse_satfunc_files():
assert not tables_df.empty


def test_two_phase_oil_water(tmp_path):
"""Test initializing interp_relperm from a pyscal xlsx file"""
os.chdir(tmp_path)
OIL_WATER_PYSCAL_MOCK.reset_index().to_excel("scal_input_ow.xlsx")
config = {
"pyscalfile": "scal_input_ow.xlsx",
"result_file": "outfile_ow.inc",
"interpolations": [{"param_w": -0.5}],
"delta_s": 0.1,
}

interp_relperm.process_config(config)
outfile_str = Path("outfile_ow.inc").read_text(encoding="utf8")
assert "SCAL recommendation interpolation to -0.5" in outfile_str

"""Test that we are able to make an interpolant from inc files"""
swoffn = TESTDATA / "swof_base.inc"

base_df = interp_relperm.parse_satfunc_files([swoffn])

swoffn = TESTDATA / "swof_pes.inc"

low_df = interp_relperm.parse_satfunc_files([swoffn])

swoffn = TESTDATA / "swof_opt.inc"

high_df = interp_relperm.parse_satfunc_files([swoffn])

interpolant = interp_relperm.make_interpolant(
base_df, low_df, high_df, {"param_w": 0.1}, 1, 0.1
)

assert "SWOF" in interpolant.wateroil.SWOF()


def test_two_phase_oil_gas(tmp_path):
"""Test initializing interp_relperm from a pyscal xlsx file"""
os.chdir(tmp_path)
OIL_GAS_PYSCAL_MOCK.reset_index().to_excel("scal_input_og.xlsx")
config = {
"pyscalfile": "scal_input_og.xlsx",
"result_file": "outfile_og.inc",
"interpolations": [{"param_g": 0.5}],
"delta_s": 0.1,
}

interp_relperm.process_config(config)
outfile_str = Path("outfile_og.inc").read_text(encoding="utf8")
assert "SCAL recommendation interpolation to 0.5" in outfile_str

"""Test that we are able to make an interpolant from inc files"""
sgoffn = TESTDATA / "sgof_base.inc"

base_df = interp_relperm.parse_satfunc_files([sgoffn])

sgoffn = TESTDATA / "sgof_pes.inc"

low_df = interp_relperm.parse_satfunc_files([sgoffn])

sgoffn = TESTDATA / "sgof_opt.inc"

high_df = interp_relperm.parse_satfunc_files([sgoffn])

interpolant = interp_relperm.make_interpolant(
base_df, low_df, high_df, {"param_g": -0.5}, 1, 0.1
)

assert "SGOF" in interpolant.gasoil.SGOF()


def test_make_interpolant():
"""Test that we are able to make an interpolant from inc files"""
swoffn = TESTDATA / "swof_base.inc"
Expand Down

0 comments on commit 9f70d93

Please sign in to comment.