Skip to content

Commit

Permalink
Apply extra Ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlero committed Apr 9, 2024
1 parent 7b0a85b commit 90b52ec
Show file tree
Hide file tree
Showing 33 changed files with 105 additions and 137 deletions.
4 changes: 1 addition & 3 deletions examples/1INFILTR/D.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
Diffusivity plot.
"""

import numpy as np
import matplotlib.pyplot as plt

import numpy as np
from fronts.D import van_genuchten

from validation import r_unit, t_unit

epsilon = 1e-6
Expand Down
4 changes: 1 addition & 3 deletions examples/1INFILTR/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"""1INFILTR case from Hydrus-1D, horizontal."""

import matplotlib.pyplot as plt

import validation
from fronts import solve
from fronts.D import van_genuchten

import validation

epsilon = 1e-6

Ks = 25 # cm/h
Expand Down
7 changes: 3 additions & 4 deletions examples/1INFILTR/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
1001 nodes, water content tolerance = 1e-6
"""

import sys
import os
import itertools
import os
import sys

import numpy as np
import matplotlib.pyplot as plt

import numpy as np

r_unit = "cm"
t_unit = "h"
Expand Down
4 changes: 1 addition & 3 deletions examples/HF135/D.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
Diffusivity plot.
"""

import numpy as np
import matplotlib.pyplot as plt

import numpy as np
from fronts.D import van_genuchten

from validation import r_unit, t_unit

epsilon = 1e-7
Expand Down
8 changes: 3 additions & 5 deletions examples/HF135/inverse1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
Warning: this example takes ~30 seconds to run to completion.
"""

import numpy as np
import matplotlib.pyplot as plt

from fronts import solve, inverse
from fronts.D import van_genuchten

import numpy as np
import validation
from fronts import inverse, solve
from fronts.D import van_genuchten

epsilon = 1e-7

Expand Down
4 changes: 1 addition & 3 deletions examples/HF135/inverse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
"""

import matplotlib.pyplot as plt

from fronts import solve, inverse, o

import validation
from fronts import inverse, o, solve

D_inverse = inverse(o=o(validation.r, validation.t)[::5], samples=validation.theta[::5])
# Using only a fifth of the points so that it does not run too slow
Expand Down
6 changes: 2 additions & 4 deletions examples/HF135/radial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
Radial flow in a HF135 nitrocellulose membrane.
"""

import numpy as np
import matplotlib.pyplot as plt

from math import pi

import matplotlib.pyplot as plt
import numpy as np
from fronts import solve_flowrate
from fronts.D import van_genuchten

from validation import r_unit, t_unit

epsilon = 1e-7
Expand Down
4 changes: 1 addition & 3 deletions examples/HF135/refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
"""

import matplotlib.pyplot as plt

import validation
from fronts import solve, solve_from_guess
from fronts.D import van_genuchten

import validation

epsilon = 1e-7

# Wetting of an HF135 membrane, Van Genuchten model
Expand Down
4 changes: 1 addition & 3 deletions examples/HF135/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
"""

import matplotlib.pyplot as plt

import validation
from fronts import solve
from fronts.D import van_genuchten

import validation

epsilon = 1e-7

# Wetting of an HF135 membrane, Van Genuchten model
Expand Down
4 changes: 2 additions & 2 deletions examples/HF135/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"""

import sys
import os
import sys

import numpy as np
import matplotlib.pyplot as plt
import numpy as np

_filename = os.path.join(sys.path[0], "groundwaterFoam_results.csv")

Expand Down
2 changes: 1 addition & 1 deletion examples/exact/D.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

"""Plot of D for the 'exact' validation case."""

import numpy as np
import matplotlib.pyplot as plt
import numpy as np


def D(theta):
Expand Down
3 changes: 1 addition & 2 deletions examples/exact/fromguess.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
`fronts.solve_from_guess`) and compares the solutions.
"""

import numpy as np
import matplotlib.pyplot as plt

import numpy as np
from fronts import solve_from_guess

o = np.linspace(0, 20, 100)
Expand Down
3 changes: 1 addition & 2 deletions examples/exact/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
and compares the solutions.
"""

import numpy as np
import matplotlib.pyplot as plt

import numpy as np
from fronts import solve

theta = solve(D="0.5*(1 - log(theta))", i=0, b=1, verbose=2)
Expand Down
3 changes: 1 addition & 2 deletions examples/powerlaw/D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
Plot of D in the powerlaw case.
"""

import numpy as np
import matplotlib.pyplot as plt

import numpy as np
from fronts.D import power_law

k = 4.0
Expand Down
5 changes: 2 additions & 3 deletions examples/powerlaw/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

"""Examples of usage of `fronts.solve` and `fronts.inverse`."""

import numpy as np
import matplotlib.pyplot as plt

from fronts import solve, inverse
import numpy as np
from fronts import inverse, solve
from fronts.D import power_law

k = 4.0
Expand Down
4 changes: 1 addition & 3 deletions examples/powerlaw/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

"""Example of usage of `fronts.solve`."""

import numpy as np
import matplotlib.pyplot as plt

import numpy as np
from fronts import solve
from fronts.D import power_law


k = 4.0
ci = 0.1
cb = 1.0
Expand Down
20 changes: 8 additions & 12 deletions fronts/D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""D functions."""

import functools
Expand Down Expand Up @@ -42,7 +40,6 @@ def constant(D0):
numerical solvers are necessary. However, it is provided here given that it
is the simplest supported function.
"""

if D0 <= 0:
raise ValueError("D0 must be positive")

Expand Down Expand Up @@ -103,7 +100,6 @@ def from_expr(expr, vectorized=True, max_derivatives=2):
Users will rarely need to call this function, as all built-in solver
functions already do so themselves when they receive an expression as `D`.
"""

expr = sympy.sympify(expr)

free = expr.free_symbols
Expand Down Expand Up @@ -181,7 +177,7 @@ def D(theta, derivatives=0):
return f01(theta)

if derivatives == 2 and max_derivatives == 2:
return f01(theta) + [f2(theta)]
return (*f01(theta), f2(theta))

raise ValueError(
f"derivatives must be one of {{{', '.join(str(n) for n in range(max_derivatives+1))}}}"
Expand Down Expand Up @@ -251,7 +247,9 @@ def D(theta, derivatives=0):

def _as_Ks(Ks=None, k=None, nu=1e-6, g=9.81):
r"""
Return the saturated hydraulic conductivity, computed from the instrinsic
Return the saturated hydraulic conductivity.
The saturated hydraulic conductivity is computed from the instrinsic
permeability if necessary.
Parameters
Expand Down Expand Up @@ -372,10 +370,9 @@ def brooks_and_corey(
References
----------
[1] BROOKS, R.; COREY, T. Hydraulic properties of porous media. Hydrology
[1] BROOKS, R.; COREY, T. Hydraulic properties of porous media. Hydrology
Papers, Colorado State University, 1964, vol. 24, p. 37.
"""

if alpha <= 0:
raise ValueError("alpha must be positive")

Expand Down Expand Up @@ -496,11 +493,10 @@ def van_genuchten(
References
----------
[1] VAN GENUCHTEN, M. Th. A closed-form equation for predicting the
[1] VAN GENUCHTEN, M. Th. A closed-form equation for predicting the
hydraulic conductivity of unsaturated soils. Soil Science Society of
America Journal, 1980, vol. 44, no 5, p. 892-898.
"""

if n is not None:
if m is not None:
raise TypeError("cannot pass both n and m")
Expand Down Expand Up @@ -605,6 +601,8 @@ def letxs(
theta_range=(0.0, 1.0),
):
r"""
Return a LETx + LETs diffusivity function.
Return a diffusivity function that combines the LETx relative permeability
correlation and the LETs capillary pressure correlation for spontaneous
imbibition. Both correlations are part of the LET family of hydraulic
Expand Down Expand Up @@ -699,7 +697,6 @@ def letxs(
capillary imbibition models in paper-based microfluidic applications.
Transport in Porous Media, 2022, vol. 141, no. 7, pp. 1-20.
"""

Ks = _as_Ks(Ks=Ks, k=k, nu=nu, g=g)

# - Code generated with functionstr() from ../symbolic/generate.py - #
Expand Down Expand Up @@ -997,7 +994,6 @@ def richards(C, kr, Ks=None, k=None, nu=1e-6, g=9.81):
In all cases, the argument ``theta`` may be a single float or a NumPy
array.
"""

Ks = _as_Ks(Ks=Ks, k=k, nu=nu, g=g)

def D(theta, derivatives=0):
Expand Down
9 changes: 3 additions & 6 deletions fronts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"""
Numerical library for nonlinear diffusion problems based on the Boltzmann
transformation.
"""
"""Numerical library for nonlinear diffusion problems based on the Boltzmann transformation."""

__version__ = "1.2.2"

from ._boltzmann import ode, BaseSolution, o, do_dr, do_dt, r, t, as_o
from ._semiinfinite import solve, solve_flowrate, solve_from_guess, Solution
from ._boltzmann import BaseSolution, as_o, do_dr, do_dt, o, ode, r, t
from ._inverse import inverse, sorptivity
from ._semiinfinite import Solution, solve, solve_flowrate, solve_from_guess

__all__ = [
"solve",
Expand Down
Loading

0 comments on commit 90b52ec

Please sign in to comment.