Skip to content

Commit

Permalink
♻️ ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
frank1010111 committed Sep 24, 2024
1 parent 6f0ceb6 commit 5c88da1
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 189 deletions.
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black-jupyter

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand Down Expand Up @@ -51,6 +46,7 @@ repos:
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.950
Expand Down
8 changes: 2 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def docs(session: nox.Session) -> None:
"""Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links."""
parser = argparse.ArgumentParser()
parser.add_argument("--serve", action="store_true", help="Serve after building")
parser.add_argument(
"-b", dest="builder", default="html", help="Build target (default: html)"
)
parser.add_argument("-b", dest="builder", default="html", help="Build target (default: html)")
args, posargs = parser.parse_known_args(session.posargs)

if args.builder != "html" and args.serve:
Expand All @@ -50,9 +48,7 @@ def docs(session: nox.Session) -> None:
session.chdir("docs")

if args.builder == "linkcheck":
session.run(
"sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs
)
session.run("sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs)
return

shared_args = (
Expand Down
85 changes: 24 additions & 61 deletions src/bluebonnet/flow/flowproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, pvt_props: Mapping[str, ndarray], p_i: float):
compressibility and viscosity.
Parameters
-----------
----------
pvt_props : Mapping
has accessors for pseudopressure, alpha (optional), compressibility, viscosity,
z-factor
Expand All @@ -77,9 +77,7 @@ def __init__(self, pvt_props: Mapping[str, ndarray], p_i: float):
):
raise ValueError("Need pvt_props to have: " + ", ".join(need_cols_short))
if "alpha" in pvt_props:
m_scale_func = interp1d(
pvt_props["pressure"], 1 / pvt_props["pseudopressure"]
)
m_scale_func = interp1d(pvt_props["pressure"], 1 / pvt_props["pseudopressure"])
warnings.warn(
"warning: scaling pseudopressure, using user's hydraulic diffusivity",
RuntimeWarning,
Expand Down Expand Up @@ -131,7 +129,7 @@ def __init__(self, pvt_props: Mapping[str, ndarray], p_i: float):
compressibility and viscosity.
Parameters
-----------
----------
pvt_props : Mapping
has accessors for pressure, compressibility, viscosity
Expand Down Expand Up @@ -234,23 +232,14 @@ def from_table(
msg = f"df_kr needs all of {need_cols_kr}"
raise ValueError(msg)
pvt = {
prop: interp1d(
pvt_props["pressure"], pvt_props[prop], fill_value="extrapolate"
)
prop: interp1d(pvt_props["pressure"], pvt_props[prop], fill_value="extrapolate")
for prop in need_cols_pvt
}
pvt.update(reference_densities)
# pvt.update({"rho_o0": rho_o0, "rho_g0": rho_g0, "rho_w0": rho_w0})
kr = {
fluid: interp1d(kr_props["So"], kr_props[fluid])
for fluid in ("kro", "krg", "krw")
}
alpha_calc = alpha_multiphase(
pvt_props["pressure"], pvt_props["So"], phi, Sw, pvt, kr
)
pseudopressure = pseudopressure_threephase(
pvt_props["pressure"], pvt_props["So"], pvt, kr
)
kr = {fluid: interp1d(kr_props["So"], kr_props[fluid]) for fluid in ("kro", "krg", "krw")}
alpha_calc = alpha_multiphase(pvt_props["pressure"], pvt_props["So"], phi, Sw, pvt, kr)
pseudopressure = pseudopressure_threephase(pvt_props["pressure"], pvt_props["So"], pvt, kr)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
object = cls(
Expand Down Expand Up @@ -287,9 +276,9 @@ def rescale_pseudopressure(
"""
df_pvt = df_pvt.copy() if hasattr(df_pvt, "copy") else copy.deepcopy(df_pvt)
pseudopressure = interp1d(df_pvt.pressure, df_pvt.pseudopressure)
df_pvt["pseudopressure"] = (
pseudopressure(df_pvt["pressure"]) - pseudopressure(p_frac)
) / (pseudopressure(p_i) - pseudopressure(p_frac))
df_pvt["pseudopressure"] = (pseudopressure(df_pvt["pressure"]) - pseudopressure(p_frac)) / (
pseudopressure(p_i) - pseudopressure(p_frac)
)
return df_pvt


Expand Down Expand Up @@ -331,9 +320,7 @@ def alpha_multiphase(
return lambda_combined / compressibility_combined


def lambda_combined_func(
pressure: ndarray, So: ndarray, pvt: dict, kr: dict
) -> ndarray:
def lambda_combined_func(pressure: ndarray, So: ndarray, pvt: dict, kr: dict) -> ndarray:
"""Calculate mobility for three phase system.
Args
Expand Down Expand Up @@ -362,15 +349,11 @@ def lambda_combined_func(
mobility for the cells
"""
lambda_oil = pvt["rho_o0"] * (
pvt["Rv"](pressure)
* kr["krg"](So)
/ (pvt["mu_g"](pressure) * pvt["Bg"](pressure))
pvt["Rv"](pressure) * kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure))
+ kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure))
)
lambda_gas = pvt["rho_g0"] * (
pvt["Rs"](pressure)
* kr["kro"](So)
/ (pvt["mu_o"](pressure) * pvt["Bo"](pressure))
pvt["Rs"](pressure) * kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure))
+ kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure))
)
lambda_water = pvt["rho_w0"] * (
Expand Down Expand Up @@ -431,16 +414,12 @@ def compressibility_combined_func(
)
)
water_cp = (
phi
* pvt["rho_w0"]
* (Sw / pvt["Bw"](pressure + 0.5) - Sw / pvt["Bw"](pressure - 0.5))
phi * pvt["rho_w0"] * (Sw / pvt["Bw"](pressure + 0.5) - Sw / pvt["Bw"](pressure - 0.5))
)
return oil_cp + gas_cp + water_cp


def pseudopressure_threephase(
pressure: ndarray, So: ndarray, pvt: dict, kr: dict
) -> ndarray:
def pseudopressure_threephase(pressure: ndarray, So: ndarray, pvt: dict, kr: dict) -> ndarray:
"""Calculate pseudopressure over pressure for three-phase fluid.
Args
Expand Down Expand Up @@ -468,20 +447,14 @@ def pseudopressure_threephase(
pseudopressure : ndarray
"""
lambda_oil = pvt["rho_o0"] * (
pvt["Rv"](pressure)
* kr["krg"](So)
/ (pvt["mu_g"](pressure) * pvt["Bg"](pressure))
pvt["Rv"](pressure) * kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure))
+ kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure))
)
lambda_gas = pvt["rho_g0"] * (
pvt["Rs"](pressure)
* kr["kro"](So)
/ (pvt["mu_o"](pressure) * pvt["Bo"](pressure))
pvt["Rs"](pressure) * kr["kro"](So) / (pvt["mu_o"](pressure) * pvt["Bo"](pressure))
+ kr["krg"](So) / (pvt["mu_g"](pressure) * pvt["Bg"](pressure))
)
lambda_water = pvt["rho_w0"] * (
kr["krw"](So) / (pvt["mu_w"](pressure) * pvt["Bw"](pressure))
)
lambda_water = pvt["rho_w0"] * (kr["krw"](So) / (pvt["mu_w"](pressure) * pvt["Bw"](pressure)))
integrand = lambda_oil + lambda_gas + lambda_water
pseudopressure = cumulative_trapezoid(pressure, integrand, initial=0)
return pseudopressure
Expand Down Expand Up @@ -515,7 +488,8 @@ def __init__(self, df: Mapping[str, ndarray]):
Args:
df (Mapping[str, ndarray]): table, including pseudopressure, So, Sg, Sw
Raises:
Raises
------
ValueError: Table columns are missing
"""
need_cols = {"pseudopressure", "alpha", "So", "Sg", "Sw"}
Expand Down Expand Up @@ -611,18 +585,9 @@ def relative_permeabilities(
raise ValueError(msg)

denominator = 1 - params.S_or - params.S_wc - params.S_gc
kro = (
params.k_ro_max
* ((saturations["So"] - params.S_or) / denominator) ** params.n_o
)
krw = (
params.k_rw_max
* ((saturations["Sw"] - params.S_wc) / denominator) ** params.n_w
)
krg = (
params.k_rg_max
* ((saturations["Sg"] - params.S_gc) / denominator) ** params.n_g
)
kro = params.k_ro_max * ((saturations["So"] - params.S_or) / denominator) ** params.n_o
krw = params.k_rw_max * ((saturations["Sw"] - params.S_wc) / denominator) ** params.n_w
krg = params.k_rg_max * ((saturations["Sg"] - params.S_gc) / denominator) ** params.n_g
k_rel = np.array(
list(zip(kro, krw, krg)),
dtype=[(i, np.float64) for i in ("kro", "krw", "krg")],
Expand All @@ -632,9 +597,7 @@ def relative_permeabilities(
return k_rel


def relative_permeabilities_twophase(
params: RelPermParams, Sw: float = 0.1
) -> pd.DataFrame:
def relative_permeabilities_twophase(params: RelPermParams, Sw: float = 0.1) -> pd.DataFrame:
"""Make two-phase relative permeability curves from Brooks-Corey.
Parameters
Expand Down
8 changes: 2 additions & 6 deletions src/bluebonnet/flow/reservoir.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ def fvf_scale(self) -> float:
"""
return 1

def simulate(
self, time: ndarray[float], pressure_fracface: ndarray[float] | None = None
):
def simulate(self, time: ndarray[float], pressure_fracface: ndarray[float] | None = None):
"""Calculate simulation pressure over time.
Args
Expand Down Expand Up @@ -300,9 +298,7 @@ def simulate(self, time: ndarray):
alpha_scaled = self.alpha_scaled(b, sat)
kt_h2 = mesh_ratio * alpha_scaled
a_matrix = _build_matrix(kt_h2)
pseudopressure[i + 1], info = sparse.linalg.bicgstab(
a_matrix, b, atol=_ATOL
)
pseudopressure[i + 1], info = sparse.linalg.bicgstab(a_matrix, b, atol=_ATOL)
saturations[i + 1] = self._step_saturation(sat, b, pseudopressure[i + 1])
self.time = time
self.pseudopressure = pseudopressure
Expand Down
18 changes: 7 additions & 11 deletions src/bluebonnet/fluids/fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def build_pvt_gas(
"""Build a table of PVT properties for use in the flow module.
Parameters
-----------
----------
gas_values : dictionary
keys include 'N2','H2S','CO2', 'Gas Specific Gravity',
'Reservoir Temperature (deg F)'
Expand Down Expand Up @@ -91,10 +91,7 @@ def build_pvt_gas(
]
)
compressibility = np.array(
[
compressibility_DAK(temperature, p, temperature_pc, pressure_pc)
for p in pressure
]
[compressibility_DAK(temperature, p, temperature_pc, pressure_pc) for p in pressure]
)
pvt_gas = pd.DataFrame(
data={
Expand Down Expand Up @@ -148,17 +145,16 @@ class Fluid:
water_saturation_initial: float = 0.0
"""Initial water saturation"""

def water_FVF(
self, pressure: NDArray[np.float] | float
) -> NDArray[np.float] | float:
def water_FVF(self, pressure: NDArray[float] | float) -> NDArray[float] | float:
"""Water formation volume factor (B-factor) from McCain.
Parameters
----------
pressure: np.ndarray
water pressure in psia
Returns
----------
-------
b_w: ndarray
b-factor in reservoir bbl / standard bbl
"""
Expand Down Expand Up @@ -238,7 +234,7 @@ def gas_viscosity(
viscosity_gas (centipoise)
Examples
-------
--------
>>> Fluid(400, 35, 0.65, 0).viscosity_gas(100, -102, 649)
0.01652719692109309
"""
Expand Down Expand Up @@ -307,7 +303,7 @@ def pressure_bubblepoint(
Bubble point pressure in psia.
Examples
-------
--------
>>> Fluid(200, 35, 0.8, 650).pressure_bubblepoint()
2627.2017021875276
"""
Expand Down
Loading

0 comments on commit 5c88da1

Please sign in to comment.