Skip to content

Commit a4efd54

Browse files
committed
STY: make code CI compliant
1 parent a7ea44b commit a4efd54

File tree

7 files changed

+152
-80
lines changed

7 files changed

+152
-80
lines changed

src/porepy/models/compositional_flow.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,10 @@ class EnthalpyBasedEnergyBalanceEquations(
399399
]
400400
"""See :class:`~porepy.models.fluid_property_library.FluidMobility`."""
401401

402-
enthalpy_buoyancy: Callable[
403-
[pp.Subdomains], pp.ad.Operator
404-
]
402+
enthalpy_buoyancy: Callable[[pp.SubdomainsOrBoundaries], pp.ad.Operator]
405403
"""See :class:`~porepy.models.fluid_property_library.FluidBuoyancy`."""
406404

407-
enthalpy_buoyancy_jump: Callable[
408-
[pp.Subdomains], pp.ad.Operator
409-
]
405+
enthalpy_buoyancy_jump: Callable[[pp.SubdomainsOrBoundaries], pp.ad.Operator]
410406
"""See :class:`~porepy.models.fluid_property_library.FluidBuoyancy`."""
411407

412408
bc_data_fractional_flow_energy_key: str
@@ -483,14 +479,16 @@ def enthalpy_flux(self, subdomains: pp.SubdomainsOrBoundaries) -> pp.ad.Operator
483479
)
484480
else:
485481
flux = super().enthalpy_flux(subdomains)
486-
buoyancy_condition: bool = self.params.get("buoyancy_on", True) and not all([isinstance(g, pp.BoundaryGrid) for g in subdomains])
482+
buoyancy_condition: bool = self.params.get(
483+
"enable_buoyancy_effects", False
484+
) and not all([isinstance(g, pp.BoundaryGrid) for g in subdomains])
487485
if buoyancy_condition:
488486
flux += self.enthalpy_buoyancy(subdomains)
489487
return flux
490488

491489
def energy_source(self, subdomains: list[pp.Grid]) -> pp.ad.Operator:
492490
source = super().energy_source(subdomains)
493-
buoyancy_condition: bool = self.params.get("buoyancy_on", True)
491+
buoyancy_condition: bool = self.params.get("enable_buoyancy_effects", False)
494492
if buoyancy_condition:
495493
source += self.enthalpy_buoyancy_jump(subdomains)
496494
return source
@@ -635,7 +633,7 @@ def component_mass_balance_equation(
635633
self.component_mass(component, subdomains), subdomains, dim=1
636634
)
637635
flux = self.component_flux(component, subdomains)
638-
if self.params.get("buoyancy_on", True):
636+
if self.params.get("enable_buoyancy_effects", False):
639637
flux += self.component_buoyancy(component, subdomains)
640638
source = self.component_source(component, subdomains)
641639

@@ -908,7 +906,7 @@ def component_source(
908906
source = projection.mortar_to_secondary_int() @ self.interface_component_flux(
909907
component, interfaces
910908
)
911-
if self.params.get("buoyancy_on", True):
909+
if self.params.get("enable_buoyancy_effects", False):
912910
source += self.component_buoyancy_jump(component, subdomains)
913911

914912
source.set_name(f"interface_component_flux_source_{component.name}")

src/porepy/models/fluid_property_library.py

Lines changed: 123 additions & 48 deletions
Large diffs are not rendered by default.

src/porepy/numerics/nonlinear/nonlinear_solvers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ def newton_step() -> None:
137137
if not is_diverged:
138138
solver_progressbar.update(n=1)
139139
# Ignore the long line; fixing it would require an extra variable.
140-
if len(model.nonlinear_solver_statistics.nonlinear_increment_norms) != 0:
140+
if (
141+
len(model.nonlinear_solver_statistics.nonlinear_increment_norms)
142+
!= 0
143+
):
141144
solver_progressbar.set_postfix_str(
142145
f"Increment {model.nonlinear_solver_statistics.nonlinear_increment_norms[-1]:.2e}" # noqa: E501
143146
)

tests/functional/setups/buoyancy_flow_model.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
- 2-phase, 2-component systems (e.g., water and methane)
77
- 3-phase, 3-component systems (e.g., water, oil, and methane)
88
9-
The module defines 2D and 3D geometry setup, equations of state, initial and boundary conditions,
10-
and solution procedures for compositional fluid flow problems with gravitational effects.
9+
The module defines 2D and 3D geometry setup, equations of state, initial and boundary
10+
conditions, and solution procedures for compositional fluid flow problems with
11+
gravitational effects.
12+
1113
Fixed- and mixed-dimensional meshes are defined on cartesian grids.
1214
1315
"""
@@ -287,15 +289,13 @@ def h(
287289
def rho_func(
288290
self, *thermodynamic_dependencies: np.ndarray
289291
) -> tuple[np.ndarray, np.ndarray]:
290-
291292
nc = len(thermodynamic_dependencies[0])
292293
vals = rho_w * np.ones(nc)
293294
return vals, np.zeros((len(thermodynamic_dependencies), nc))
294295

295296
def mu_func(
296297
self, *thermodynamic_dependencies: np.ndarray
297298
) -> tuple[np.ndarray, np.ndarray]:
298-
299299
nc = len(thermodynamic_dependencies[0])
300300
vals = mu_w * np.ones(nc) * to_Mega
301301
return vals, np.zeros((len(thermodynamic_dependencies), nc))
@@ -314,7 +314,6 @@ def h(
314314
def rho_func(
315315
self, *thermodynamic_dependencies: np.ndarray
316316
) -> tuple[np.ndarray, np.ndarray]:
317-
318317
nc = len(thermodynamic_dependencies[0])
319318
vals = rho_o * np.ones(nc)
320319
diffs = np.zeros((len(thermodynamic_dependencies), nc))
@@ -341,7 +340,6 @@ def h(
341340
def rho_func(
342341
self, *thermodynamic_dependencies: np.ndarray
343342
) -> tuple[np.ndarray, np.ndarray]:
344-
345343
nc = len(thermodynamic_dependencies[0])
346344
vals = rho_g * np.ones(nc)
347345
diffs = np.zeros((len(thermodynamic_dependencies), nc))
@@ -358,7 +356,6 @@ def mu_func(
358356
class BaseFlowModel(
359357
FlowTemplate,
360358
):
361-
362359
def __init__(self, params: dict):
363360
"""Initialize flow model."""
364361
super().__init__(params)
@@ -404,7 +401,6 @@ def check_convergence(
404401
"""Check nonlinear convergence."""
405402

406403
if self._is_nonlinear_problem():
407-
408404
total_volume = 0.0
409405
for sd in self.mdg.subdomains():
410406
total_volume += np.sum(
@@ -678,7 +674,6 @@ def ic_values_overall_fraction(
678674
class FlowModel2N(
679675
BaseFlowModel,
680676
):
681-
682677
def after_nonlinear_convergence(self) -> None:
683678
"""Post-convergence diagnostics."""
684679
super().after_nonlinear_convergence()
@@ -1174,7 +1169,6 @@ def ic_values_overall_fraction(
11741169
class FlowModel3N(
11751170
BaseFlowModel,
11761171
):
1177-
11781172
def after_nonlinear_convergence(self) -> None:
11791173
"""Post-convergence diagnostics."""
11801174
super().after_nonlinear_convergence()

tests/functional/test_buoyancy_flow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
77
It covers two multicomponent fluid systems:
88
- N = 2: Two phases (aqueous liquid, gas) and two components (e.g., H₂O, CH₄).
9-
- N = 3: Three phases (aqueous liquid, oleic liquid, gas) and three components (e.g., H₂O, CO₂, CH₄).
9+
- N = 3: Three phases (aqueous liquid, oleic liquid, gas) and
10+
three components (e.g., H₂O, CO₂, CH₄).
1011
1112
Simulations are run in 2D and 3D for several conservation tolerances, and
1213
the observed conservation is checked to be of the expected order. After each
@@ -88,7 +89,7 @@ def _run_buoyancy_model(
8889
)
8990
params = {
9091
"fractional_flow": True,
91-
"buoyancy_on": True,
92+
"enable_buoyancy_effects": True,
9293
"material_constants": {"solid": solid_constants},
9394
"time_manager": time_manager,
9495
"apply_schur_complement_reduction": False,
@@ -112,6 +113,7 @@ class Model3D(geometry3d, model_class):
112113
model = Model3D(params)
113114
pp.run_time_dependent_model(model, params)
114115

116+
115117
@pytest.mark.skipped # reason: slow
116118
@pytest.mark.parametrize(
117119
"model_class, mesh_2d_Q, expected_order_loss", Parameterization
@@ -120,6 +122,7 @@ def test_buoyancy_fd_model(model_class, mesh_2d_Q, expected_order_loss):
120122
"""Test buoyancy-driven flow model (FD)."""
121123
_run_buoyancy_model(model_class, mesh_2d_Q, expected_order_loss, md=False)
122124

125+
123126
@pytest.mark.skipped # reason: slow
124127
@pytest.mark.parametrize(
125128
"model_class, mesh_2d_Q, expected_order_loss", Parameterization

tests/functional/test_buoyancy_flow_benchmark.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ def test_buoyancy_flow_benchmark(
6767
rho_g = rho_l - delta_rho
6868
to_Mega = 1.0e-6
6969

70-
# --- All class and function definitions from the original script are placed here ---
71-
7270
# geometry description
7371
class Geometry(pp.PorePyModel):
7472
@abstractmethod
@@ -503,7 +501,7 @@ def check_convergence(
503501
material_constants = {"solid": solid_constants}
504502
params = {
505503
"fractional_flow": True,
506-
"buoyancy_on": True,
504+
"enable_buoyancy_effects": True,
507505
"material_constants": material_constants,
508506
"time_manager": time_manager,
509507
"prepare_simulation": False,
@@ -584,7 +582,8 @@ def check_convergence(
584582
plt.xlabel("Distance [m]")
585583
plt.ylabel("Saturation [-]")
586584
plt.title(
587-
f"Saturation Profile at $t = 5$ days for $\\Delta \\rho = {delta_rho}$ kg/m$^3$"
585+
f"Saturation Profile at $t = 5$ days for "
586+
f"$\\Delta \\rho = {delta_rho}$ kg/m$^3$"
588587
)
589588
plt.grid(True)
590589
plt.legend()

tests/models/test_fluid_property_library.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212

1313
# Test suite for FluidBuoyancy class functionality.
14-
# Validates buoyancy operators by instantiating models and evaluating computed operators.
14+
# Validates buoyancy operators by instantiating models and evaluating
15+
# computed operators.
1516

1617
# Parameterization for testing both 2-component and 3-component models
1718
Parameterization = [
1819
(BuoyancyFlowModel2N), # 2-component buoyancy flow model
1920
(BuoyancyFlowModel3N), # 3-component buoyancy flow model
2021
]
2122

23+
2224
def _build_buoyancy_model(
2325
model_class: type,
2426
md: bool = False,
@@ -57,7 +59,7 @@ def _build_buoyancy_model(
5759
)
5860
params = {
5961
"fractional_flow": True,
60-
"buoyancy_on": True,
62+
"enable_buoyancy_effects": True,
6163
"material_constants": {"solid": solid_constants},
6264
"time_manager": time_manager,
6365
"apply_schur_complement_reduction": False,
@@ -456,9 +458,7 @@ def __subdomains_assertions(model):
456458
0.0,
457459
]
458460
)
459-
assert np.allclose(
460-
h_buoyancy_flux, h_buoyancy_flux_expected
461-
)
461+
assert np.allclose(h_buoyancy_flux, h_buoyancy_flux_expected)
462462

463463

464464
def __interface_assertions(model):

0 commit comments

Comments
 (0)