"""Closed-form solutions for flat, parallel porous faces without sliding.
With a uniform gap, no sliding and the column restrictor model (Darcy flow
through the thickness, the whole back fed) the film equation of film.py is
linear in the gas flow potential phi (gas.py):
laplace(phi) = m² (phi - phi_s), m² = 12 kappa / (hp h³ (1 + Psi)),
so the classic p² solutions for an ideal gas hold for any gas once written
in phi. h is the gap plus the equivalent clearance of the restrictor. These
are exact and fast, and serve two purposes: checking the finite-element
solver, and sweeps over thousands of designs where only a flat face is
needed.
Each function returns a ``Flat`` with the load, the supply flow and the
pressure profile, for one film thickness or an array of them at once.
``stiffness`` differentiates any of them in the gap. Their shared arguments:
h: gap in m, one value or an array.
porous: the restrictor, with uniform permeability and thickness and no
inertial resistance (ValueError otherwise).
ps, pa: absolute supply and ambient pressure, Pa.
gas: the gas model.
What the closed forms cover: a flat restrictor wall, fed over its whole back,
open to the film over its whole face, in the column model. A restrictor
that asks for anything else is refused with a ValueError that names the
option: a partial feed (``feed_area``), a sealed part of the face
(``face_seal``), a curved wall (``curvature``, set by ``Porous.curved``) and
``model="volume"``. The last is refused although it is a choice of model and
not a property of the restrictor: a restrictor marked for the volume model
would otherwise get a column-model answer without a word. To compare the two
on purpose, pass ``dataclasses.replace(porous, model="column")``. The options
that only the volume model uses (``inplane_ratio``, ``rim_open``,
``rim_open_depth``, the surface layer) change nothing in the column model
and are accepted.
"""
from __future__ import annotations
from dataclasses import dataclass
import numpy as np
from scipy.special import ive, kve
from .film import Porous
from .gas import AIR, Gas
__all__ = ["Flat", "annular_pad", "circular_pad", "stiffness", "strip"]
_N = 4001 # points of the profile; the integrands are smooth
[docs]
@dataclass(frozen=True)
class Flat:
"""Solution on a flat parallel face.
For an array of n film thicknesses, load and the flows are arrays of n
and p has shape (n, len(x)).
"""
load: float # force on the runner, N (per metre of length for a strip)
flow_supply: float # mass flow through the restrictor, kg/s (per metre)
flow_normal: float # the same as free gas at pa, m³/s (per metre)
x: np.ndarray # radius, or position across a strip, m
p: np.ndarray # absolute pressure at x, Pa
def _feed_number(h, porous: Porous):
"""m for one film thickness or a column of them (shape (n, 1) for an array).
The film the gas flows in is the gap plus the equivalent clearance, with
the slip factor of the porous face at that film thickness. Raises
ValueError for a restrictor the closed forms do not cover (module
docstring).
"""
if callable(porous.kappa) or callable(porous.hp):
raise ValueError("Closed forms need uniform permeability and thickness.")
if callable(porous.inertial_resistance) or porous.inertial_resistance:
raise ValueError("Closed forms hold for Darcy flow only; use the solver.")
if callable(porous.knudsen_resistance) or porous.knudsen_resistance:
raise ValueError(
"Closed forms hold for Darcy flow only: a Knudsen skin is not "
"covered. Use the solver."
)
for name in ("equivalent_clearance", "slip_coefficient", "curvature"):
if callable(getattr(porous, name)):
raise ValueError(
f"Closed forms need one value of {name} for the whole face, "
"not a function of position; use the solver."
)
if porous.feed_area is not None:
raise ValueError(
"Closed forms hold for a restrictor fed over its whole back: "
"feed_area is not covered. Use the solver with the volume model."
)
if porous.face_seal is not None:
raise ValueError(
"Closed forms hold for a face that is open to the film everywhere: "
"face_seal is not covered. Use the solver."
)
if porous.curvature:
raise ValueError(
"Closed forms hold for a flat restrictor wall: curvature (set by "
"Porous.curved) is not covered. Use the solver."
)
if porous.model != "column":
raise ValueError(
f"Closed forms are column-model solutions: model={porous.model!r} is "
"not covered. Use the solver, or pass dataclasses.replace(porous, "
"model='column') to get the column-model answer on purpose."
)
film = np.asarray(h, dtype=float) + porous.equivalent_clearance
if np.any(film <= 0.0):
raise ValueError("Film thickness must be positive.")
psi, _ = porous.slip_factor(film)
m = np.sqrt(12.0 * porous.kappa / (porous.hp * film**3 * (1.0 + psi)))
return m[:, None] if m.ndim else float(m)
def _finish(x, phi, weight, porous, ps, pa, gas) -> Flat:
"""Integrate phi profiles along x; weight is the area per unit x."""
p = gas.p_from_phi(phi)
load = np.trapezoid((p - pa) * weight, x, axis=-1)
feed = porous.kappa / porous.hp * (gas.phi(ps) - phi)
flow = np.trapezoid(feed * weight, x, axis=-1)
if np.ndim(load) == 0:
load, flow = float(load), float(flow)
return Flat(load, flow, flow / float(gas.rho(pa)), x, p)
def _graded(a: float, b: float) -> np.ndarray:
"""Points from a to b packed toward both ends, where the profile is steep."""
t = 0.5 * (1.0 - np.cos(np.linspace(0.0, np.pi, _N)))
return a + (b - a) * t
[docs]
def circular_pad(
radius: float,
h: float,
*,
porous: Porous,
ps: float,
pa: float = 101325.0,
gas: Gas = AIR,
) -> Flat:
"""Circular pad of the given radius (m), ambient pressure at the rim."""
m = _feed_number(h, porous)
r = _graded(0.0, radius)
phi_s, phi_a = gas.phi(ps), gas.phi(pa)
# I0(m r) / I0(m R) with exponentially scaled Bessel functions, so that
# it stays finite for thin films (large m R)
ratio = ive(0, m * r) / ive(0, m * radius) * np.exp(m * (r - radius))
phi = phi_s - (phi_s - phi_a) * ratio
return _finish(r, phi, 2.0 * np.pi * r, porous, ps, pa, gas)
[docs]
def annular_pad(
r_in: float,
r_out: float,
h: float,
*,
porous: Porous,
ps: float,
pa: float = 101325.0,
p_inner: float | None = None,
gas: Gas = AIR,
) -> Flat:
"""Annular pad: p_inner (default ambient) at the bore, ambient outside.
r_in and r_out are the two radii in m, p_inner an absolute pressure in Pa.
"""
m = _feed_number(h, porous)
r = _graded(r_in, r_out)
phi_s = gas.phi(ps)
rhs = [phi_s - gas.phi(pa if p_inner is None else p_inner), phi_s - gas.phi(pa)]
# I0 grows and K0 decays; scale each to 1 at the edge where it is largest
# so the two-by-two system stays well conditioned for thin films.
def grow(x):
return ive(0, m * x) * np.exp(m * (x - r_out))
def decay(x):
return kve(0, m * x) * np.exp(-m * (x - r_in))
# two-by-two solve written out, so it works for a column of film thicknesses
a11, a12, a21, a22 = grow(r_in), decay(r_in), grow(r_out), decay(r_out)
det = a11 * a22 - a12 * a21
A = (rhs[0] * a22 - a12 * rhs[1]) / det
B = (a11 * rhs[1] - rhs[0] * a21) / det
phi = phi_s - (A * grow(r) + B * decay(r))
return _finish(r, phi, 2.0 * np.pi * r, porous, ps, pa, gas)
[docs]
def strip(
width: float,
h: float,
*,
porous: Porous,
ps: float,
pa: float = 101325.0,
gas: Gas = AIR,
) -> Flat:
"""Infinitely long strip of the given width (m), ambient on both sides.
Load and flows are per metre of length.
"""
m = _feed_number(h, porous)
x = _graded(-width / 2.0, width / 2.0)
phi_s, phi_a = gas.phi(ps), gas.phi(pa)
# cosh(m x) / cosh(m w/2), written to stay finite for thin films
half = m * width / 2.0
ratio = (np.exp(m * np.abs(x) - half) + np.exp(-m * np.abs(x) - half)) / (
1.0 + np.exp(-2.0 * half)
)
phi = phi_s - (phi_s - phi_a) * ratio
return _finish(x, phi, np.ones_like(x), porous, ps, pa, gas)
[docs]
def stiffness(solution, h, *args, rel_step: float = 1e-4, **kwargs):
"""-d(load)/dh of one of the functions above, by central difference, N/m.
For a strip it is per metre of length. The arguments after h are those
of the function before its h:
stiffness(circular_pad, 5e-6, radius, porous=..., ps=...)
differentiates circular_pad(radius, h, ...) at h = 5e-6 m. h may be an
array. The step is rel_step times the gap plus the equivalent clearance.
"""
h = np.asarray(h, dtype=float)
_feed_number(h, kwargs["porous"]) # refuses a restrictor that is not covered
dh = rel_step * (h + kwargs["porous"].equivalent_clearance)
up = solution(*args, h + dh, **kwargs).load
down = solution(*args, h - dh, **kwargs).load
k = -(up - down) / (2.0 * dh)
return k if h.ndim else float(k)