Source code for openairbearing.core.restrictor

"""The porous restrictor: its description, and two models of the flow in it.

``Porous`` describes the restrictor: permeability, thickness, surface
layer, slip at the face, and how it is fed. Two models of the flow in it
follow. Both see the restrictor from the film. ``film.solve_static`` uses
the one that ``Porous.model`` names (the column by default). A porous part
whose shape is not the film surface extended through a thickness is a body
of its own (porous_body.py), which then replaces both.

Units: permeability kappa in m², the flow potential phi(p) of gas.py in
kg/(m³·s), mass flux in kg/(m² s) of film area, depth and thickness in m.

Column model. Gas moves through the thickness only, under each point of the
film: the feed of film.py, kappa/hp·(phi_s - phi). Fast, and exact when the
whole back is fed and no gas moves along the face, which a restrictor thin
against the face approaches. Inertial (Forchheimer) resistance is in this
model only. A Knudsen skin (``Porous.knudsen_resistance``) is in both
models.

Knudsen skin. Grinding or lapping can smear the face of a sintered
restrictor shut but for pores so narrow that gas crosses them as free
molecules, without collisions between them. The molar flux through such a
skin of thickness delta, porosity eps and tortuosity tau with pores of
radius r is (eps/tau)·D_K·dp/(R_u·T·delta), with the Knudsen diffusivity
D_K = (2/3)·r·v and the mean molecular speed v = sqrt(8·R·T/pi) (R the
specific gas constant). Times the molar mass that is the mass flux

    m = c_K·(p_i - p_f)/R_K,   c_K = (2/3)·sqrt(8/(pi·R·T)),
    R_K = delta·tau/(eps·r),

linear in the pressure difference across the skin (p_i under it, p_f in the
film), not in phi. c_K (s/m) belongs to the gas (``knudsen_coefficient``)
and R_K (dimensionless) to the skin; one free flow measured at one pressure
sets R_K. In series with the Darcy bulk, kappa/L·(phi_s - phi_i) = m, the
pressure p_i under the skin is found point by point. A skin that carries
nearly all of the pressure drop gives a free flow linear in ps - pa, as
measured on ground inserts (Hosokawa et al. 2015, Fig. 12); a Darcy layer
cannot. Viscous flow through the skin in parallel (the dusty-gas model) is
left out: on a free flow that is linear to within the reading it adds a
constant that the measurement does not determine.

The form above is the free-molecular limit of the dusty-gas model, with
the Knudsen diffusivity D_K = (2/3)·r·v of a long straight pore (Mason
and Malinauskas, Gas Transport in Porous Media: The Dusty-Gas Model,
1983). It holds where the viscous flow that it leaves out is small at
the pressures in the skin, up to the supply pressure. Over the Knudsen
flow that viscous flow is 3·r·p/(16·mu·v) at mean pressure p in the pore:
for air at 2 to 4 bar 2-4.5 % at r = 5 nm, 22-45 % at 50 nm and 2 to 4.5
times the Knudsen flow at 500 nm. Outside that range
an R_K fitted to one free flow is a curve fit, right at the pressure it was
fitted at only: the viscous part grows with pressure, so at another supply
pressure the model gives too little flow above the fitted one and too much
below it, the more so the larger the pores. In terms of the Knudsen
number lambda/(2·r), with the mean free path lambda of air at 20 °C about
65 nm at 1 atm and 11 nm at 0.59 MPa, the pores of a few nm that keep the
viscous share small have Kn of order 1 or more at the supply pressure.

Volume model. The restrictor is a body: the film surface extended through
the thickness (``RestrictorVolume``). Gas enters where supply pressure acts
on the back face, moves in all three directions, and leaves into the film
through the film face (and through the sides, if the rim is open: each
side is then at the pressure of the film edge above it). This is
what partial feeds (rings, holes), thick restrictors and anisotropic
materials need; ``volume_unsupported`` says what it does not cover. Like
the column model, it takes a Knudsen skin on the face (below). Steady
Darcy flow of an isothermal gas is linear in the flow potential phi:

    div( K grad(phi) ) = 0,    K = diag(k_t, k_t, k_n)·kappa(x)·f(depth),

with k_n = 1 normal to the face, k_t = inplane_ratio parallel to it, kappa(x)
the permeability over the face and f the factor of each layer through the
depth (surface layer, bulk). On the film face the flux into the film is the
film's own mass balance, so the film equation becomes the boundary condition
of the volume there, with the film pressure equal to the pore pressure.

A Knudsen skin on the film face of the volume is a boundary layer of no
thickness between the face of the body, at p_i, and the film, at p_f:

    (flux leaving the body through the face) = c_K·(p_i - p_f)/R_K,

a Robin condition in the pressure. The face of the body then has unknowns
of its own apart from those of the film, and the skin is a conductance
between the two, linear in the pressures: one constant matrix in the
solve, so the Newton iteration of the film and the volume is as robust as
without it. The unknown there is the drop across the skin, y with
p_i/pa = p_f/pa + s·y. With p_i/pa itself as unknown, a skin far more
open than the bulk would hold its small drop as a difference of nearly
equal numbers, times its large conductance: the flux would then be lost
to rounding, as in the column model, where it is taken from the bulk side
(``_through_skin``). Making the unknown the drop is what removes that; the
scale s only improves the conditioning of the solve (with s = 1 it is at
rounding too): s = 1 where the skin is the larger resistance and s = b/c,
the bulk's conductance kappa/L (kappa the largest in the elements around
the node) over the skin's, where it conducts more. The skin joins the
body and the film node by node where the face is open, as the face is
shared without a skin, so that a vanishing skin tends to the volume
without one, a face seal included.
The skin may vary over the face (a function of x), but must be positive
wherever gas passes the face: a skin that is zero over part of it, which
would leave the face shared with the film there and separated elsewhere,
is refused. A skin on a film of several faces is
refused too. Where the whole back is fed, the rim is sealed and the
restrictor is thin against the face, this is the column model with the
skin (the tests compare them).

Discretisation of the volume. Tensor product of the film's finite elements
with quadratic elements through the depth, graded toward the film face in
every layer and toward the back face in the last. In the scaled variables
of film.py the unknown is Theta in the volume and P on the film face;
film.py solves the two together.

In a curved wall (a sleeve around a shaft) one in-plane coordinate bends
(``Porous.bent_axis``): the first, s = radius·theta, on a journal; the
second, theta, on the bore of a thrust bushing. At depth y lengths along it
are (1 + c·y) times those at the film, with c the curvature in 1/m,
positive for a wall outside the film. In a spherical seat both bend.

A film of several faces (the bonded thrust bushing) gets one volume per
face (``FaceVolumes``), each through its own restrictor; they share the
film and nothing else.

Partly open rim. A restrictor glued into its housing over the part of its
side next to the back is open from the film face down to
``Porous.rim_open_depth`` and sealed below it: the side is held at the
edge pressure down to that depth, which is a level of the depth mesh
(``depth_edges``, graded toward it from both sides), and carries no flow
below it. Assumptions: the same depth all round the rim, a glue line that
is tight (no flow along the joint between restrictor and housing), and
the housing face it is glued to otherwise impermeable. Where the seal
ends the pore pressure is singular, as at the edge of a feed, but its flow
is finite and converges with the mesh. The supply may then reach the rim
through the back, since the sealed part keeps the two pressures apart; a
sealed part that tends to nothing gives a flow without limit, the case of
the whole height open that is refused. A thin sealed part next to a
back fed up to the rim converges too, but only as the in-plane mesh along
the rim is refined: its error is set by the sealed part against the
in-plane element there (millimetres), not by the depth mesh, and grows
smoothly as the sealed part thins. Supply flow against an axisymmetric
reference (a disc 18.5 mm by 4.5 mm, the whole back fed, a gap of 1 mm),
at nrefs 3 / 4 / 5: sealed 750 µm +0.45 / +0.12 %, 300 µm +0.98 /
+0.26 %, 100 µm +2.5 / +0.64 %, 30 µm +10.2 / +1.8 / +0.62 %; the rim
flow errs about 1.6 times as much (tests/test_core_partly_open_rim.py).
A back fed only within a margin of the rim does not meet it there.

The split of the outflow between rim and film edge is set by the mesh,
not by the pad, for an open depth below about one element at the rim:
the first element of the depth mesh (40 µm at the face) and the in-plane
element of the film mesh along the rim (millimetres for a pad of usual
size), whichever is larger. The flow out is read from the residual at the
nodes held (``film._volume_state``): the node at the corner of film edge
and rim is the film edge's, and the rim node at the level of the seal
takes the gas of the element below it and of the whole in-plane element
around it, which a shallow open part does not resolve. Total supply and
load still converge, and tend to those of a sealed rim as the depth goes
to nothing; the rim flow alone, for such a depth, is a figure of the
mesh (tests/test_core_partly_open_rim.py).

Feed grooves. Supply pressure on part of the back face (``feed_area``) is a
groove in the metal behind the restrictor, or a hole: that is all this
model describes. A groove cut into the porous material changes its shape,
which is no longer an extrusion of the film; that is porous_body.py.

Which Darcy solver for what. This module and porous_body.py both solve
Darcy flow in the restrictor. The volume here is built from the film mesh
and a mesh through the depth, so it takes the film of every bearing the
geometry builders make; ``volume_unsupported`` says what it refuses (a
thickness that varies over a face, inertial flow). It cannot describe a part
of another shape. The body there takes any shape, meshed in
three dimensions, and costs far more per node, since it is solved directly
in three dimensions. Where both describe the same part they agree (the
tests compare them).
"""

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass, field, replace

import numpy as np
import scipy.sparse as sp
from scipy.sparse.linalg import splu
from skfem import Basis, BilinearForm, ElementLineP2, MeshLine
from skfem.helpers import grad

from .gas import AIR, Gas
from .params import param

__all__ = [
    "WALLS",
    "Layer",
    "Porous",
    "RestrictorVolume",
    "depth_edges",
    "factorise",
    "knudsen_coefficient",
    "restrictor_layers",
    "volume_unsupported",
]

# how a porous wall curves around the film of a cylindrical bearing
WALLS = ("flat", "outside", "inside")


[docs] def knudsen_coefficient(gas: Gas) -> float: """c_K = (2/3)·sqrt(8/(pi·R·T)) of a gas, s/m: Knudsen flux per unit pressure. The mass flux through a Knudsen skin is c_K·dp/R_K (module docstring), the free-molecular limit, valid where viscous flow in the pores is small. R·T, the specific gas constant times the temperature, is p/rho of the gas at 1 Pa, where every gas is ideal: free-molecular flow depends on the gas through its molar mass and temperature only. """ rt = 1.0 / float(gas.rho(1.0)) return (2.0 / 3.0) * np.sqrt(8.0 / (np.pi * rt))
def _field(value, xq): """A number or a function of x, as an array at the quadrature points.""" shape = xq.shape[1:] v = value(xq) if callable(value) else value return np.broadcast_to(np.asarray(v, dtype=float), shape).copy()
[docs] @dataclass(frozen=True) class Porous: """Description of a porous restrictor: material, thickness, face and feed. kappa and hp may be numbers or functions of the film coordinates x (shape (2, ...)). kappa = 0 over part of the face makes the restrictor solid there through its whole thickness; to seal the face only, with permeable material behind it, use face_seal. """ # permeability normal to the face, m², any surface layer included kappa: float | Callable = param( 1e-15, "Permeability", "m²", minimum=0.0, help="Darcy permeability of the restrictor normal to the face, any " "surface layer included.", ) # restrictor thickness, m hp: float | Callable = param( 4e-3, "Restrictor thickness", "m", "mm", 1e3, minimum=1e-6, help="Thickness of the porous material between the supply and the film.", ) # Constant slip factor Psi of the porous face: h³ -> h³(1 + Psi) at every # gap. It adds to the gap-dependent one of slip_coefficient. slip: float = param( 0.0, "Slip factor", minimum=0.0, help="Constant slip factor Ψ of the porous face: the film conductance " "h³ becomes h³(1 + Ψ) at every gap. 0 is no slip. For the " "Beavers-Joseph model, where the factor follows from the gap and the " "permeability, set the slip coefficient instead. The two add.", ) # Surface layer of lower permeability at the film face, left by machining. # layer_flow_reduction is the share of the bare-restrictor flow that the # layer takes away at the same supply pressure (0: no layer); kappa stays # the permeability of the restrictor as a whole, layer included. In the # column model the flow is therefore that of kappa over hp, whatever # the layer; in the volume model the layer changes how much gas moves # along the face. layer_flow_reduction: float = param( 0.0, "Layer flow reduction", minimum=0.0, maximum=0.99, help="A surface layer of lower permeability at the film face, left by " "machining: the share of the bare-restrictor flow that the layer " "takes away at the same supply pressure. 0 is no layer. The " "permeability stays that of the restrictor as a whole, layer included.", ) # thickness of the surface layer, m layer_thickness: float = param( 25e-6, "Layer thickness", "m", "µm", 1e6, minimum=1e-7, help="Thickness of the surface layer at the film face.", ) # Equivalent clearance, m: a constant thickness added to the gap in the # flow terms, for a film that is effectively thicker than the measured gap # (surface roughness, slip at the porous face; Kwan and Corbett 1998). # It has to be measured for the surface in question. It is not a free # parameter to make a calculation fit: state where the value comes from. equivalent_clearance: float = param( 0.0, "Equivalent clearance", "m", "µm", 1e6, minimum=0.0, help="Constant thickness added to the gap in the flow terms, for a " "film that is effectively thicker than the measured gap (surface " "roughness, slip at the porous face; Kwan and Corbett 1998). It has " "to be measured for the surface in question: it is not a parameter " "to make a calculation fit.", ) # Beavers-Joseph slip coefficient alpha of the porous face (0: no slip). # The film conductance h³ becomes h³(1 + 3(s + 2 alpha)/(s(1 + alpha s))) # with s = h/sqrt(kappa). Reported values range from 0.01 to 4; Kwan and # Corbett found this model too weak at gaps below about 30 µm. slip_coefficient: float = param( 0.0, "Slip coefficient", minimum=0.0, help="Beavers-Joseph slip coefficient α of the porous face. The film " "conductance h³ becomes h³(1 + 3(s + 2α)/(s(1 + αs))) with " "s = h/√κ, so the slip grows as the gap closes. 0 switches the model " "off. Reported values range from 0.01 to 4; Kwan and Corbett found " "the model too weak at gaps below about 30 µm.", ) # Inertial (Forchheimer) resistance beta in 1/m, the reciprocal of the # inertial permeability of ISO 4022: -dp/dz = mu v/kappa + beta rho v². # 0 is Darcy. Column model only; the volume model refuses it. inertial_resistance: float = param( 0.0, "Inertial resistance", "1/m", minimum=0.0, help="Forchheimer resistance β of the restrictor, the reciprocal of " "the inertial permeability of ISO 4022: -dp/dz = μv/κ + βρv². " "0 is Darcy flow.", ) # Knudsen (free-molecular) skin at the film face, in series with the # bulk: R_K = delta·tau/(eps·r), dimensionless (module docstring). 0 is # no skin. Column or volume model. knudsen_resistance: float | Callable = param( 0.0, "Knudsen skin resistance", minimum=0.0, help="Dimensionless: a skin at the film face, smeared shut by " "grinding but for pores of a few nm, which gas crosses as free " "molecules: its thickness over (porosity / tortuosity × pore radius), " "e.g. 6e3 for 1 µm, 0.1, 3 and 5 nm. Its flow is proportional to the " "pressure difference across it, not to the difference of squares as " "in the bulk. Fitted to one free flow; valid at other supply pressures " "only for pores of a few nm. 0 is no skin.", ) # Curvature of the wall, 1/m: set by ``curved`` (the journal builders do # this), not by hand. Positive when the flow area grows away from the # film (a wall outside the film). curvature: float = field(default=0.0, metadata={"internal": True}) # Which film coordinate bends with depth in a curved wall: 0 for a # journal, whose first coordinate runs round the bore (s = radius·theta), # 1 for the bore of a thrust bushing, whose film runs (s along the # meridian, theta). Set by the geometry. A spherical wall bends both. bent_axis: int = field(default=0, metadata={"internal": True}) # How the solution models the restrictor. "column": flow through # the thickness only, under each point of the film (fast; exact when the # whole back is fed, in the limit of a restrictor thin against the face). # "volume": Darcy flow in the whole restrictor body, which adds flow # parallel to the face and is needed for partial feeds and thick # restrictors. model: str = param( "column", "Restrictor model", choices=("column", "volume"), help="column: gas moves through the thickness only, under each point " "of the film. Fast, and exact when the whole back is fed and the " "restrictor is thin against the face. volume: Darcy flow in the " "whole restrictor body, which adds flow parallel to the face and is " "what a thick restrictor needs.", ) # In-plane permeability over the permeability normal to the face (the # "volume" model only; 1 is isotropic). inplane_ratio: float = param( 1.0, "In-plane / normal permeability", minimum=0.0, help="Permeability parallel to the face over the permeability normal " "to it. Used by the volume model only; 1 is isotropic.", ) # Sides of the restrictor body open instead of sealed (the "volume" model # only): the side under each film edge with a given pressure is held at # that pressure, because the gas outside that edge is what the side is # exposed to. That is ambient for most edges, and the bore pressure under # the inner edge of an annular pad whose bore is a chamber. Under a # symmetry line of the film the body has one too. Open from the film face # down to rim_open_depth, sealed below it. Supply and edge pressure must # not meet along an edge: with the whole back fed (feed_area None, the # default) and the rim open over its whole height they do, and the solve # is refused. A feed_area with a sealed margin of the back along every # open side, or a rim sealed next to the back, keeps them apart. rim_open: bool = param( False, "Rim open (sides not sealed)", help="The sides of the restrictor body are open instead of sealed: " "each is at the pressure of the film edge above it, which is ambient " "unless that edge sees another pressure (the bore of an annular " "pad). Used by the volume model only. The supply must not reach the " "open part: it needs a sealed margin, either of the rim, open only " "down to a depth less than the thickness (Rim open depth), or of the " "back, fed only within a margin of the rim (Porous.feed_area, in " "the Python interface). With the whole back fed, which is the " "default and what a case form gives, and the rim open over its " "whole height, an open rim is refused.", ) # Depth from the film face down to which an open rim is open, m: the rim # is sealed below it, towards the back, where the restrictor is glued # into its housing. Not given (None), it is the thickness: the rim is # open over its whole height. Uniform, (0, hp]. The "volume" model only, # and only with rim_open; a mark of the depth mesh is put at it # (depth_edges), so that the seal ends on a level and not between two. rim_open_depth: float | None = param( None, "Rim open depth", "m", "mm", 1e3, minimum=1e-6, help="With an open rim: the depth from the film face down to which " "the sides are open. Below it, towards the back, they are sealed, as " "where the restrictor is glued into its housing. Not given, the " "whole thickness is open. Used by the volume model only: the column " "model has no rim and ignores it, as it does Rim open. Less than the " "thickness, the whole back may be fed. A thin sealed part next to it " "converges as the elements of the film along the rim get smaller: " "for 30 µm the supply flow is about 10 % high at 3 refinements and " "2 % at 4, the rim flow more. For a depth below about one element at " "the rim (40 µm through the thickness, or the element of the film " "along the rim, whichever is larger) the elements, not the pad, set " "how the outflow divides between rim and film edge; total supply and " "load are still right.", follows="hp", ) # Part of the back face that is fed: a function of the film coordinates x # that is true where supply pressure acts, or None for the whole back. # The rest of the back is sealed. The "volume" model only: the column # model refuses a partial feed. feed_area: Callable | None = field(default=None, metadata={"internal": True}) # Part of the film face that is sealed (lacquered, smeared shut): a # function of x that is true where no gas passes between the body and # the film. Unlike kappa = 0 there, which makes the whole thickness under # that part of the face solid, the body behind a sealed face still # carries gas sideways (in the "volume" model; in the column model # nothing reaches the film there either way). face_seal: Callable | None = field(default=None, metadata={"internal": True}) # The wall curves in both directions (a spherical seat), set by ``curved``. spherical: bool = field(default=False, metadata={"internal": True}) # options that a bearing with several faces gives face by face, as # functions of the film coordinates (the thrust bushing) _BY_FACE = ( "curvature", "equivalent_clearance", "slip_coefficient", "inertial_resistance", "knudsen_resistance", ) # fmt: skip
[docs] def at(self, x) -> Porous: """This restrictor with its face-by-face options evaluated at x.""" local = { name: _field(getattr(self, name), x) for name in self._BY_FACE if callable(getattr(self, name)) } return replace(self, **local) if local else self
[docs] def area_factor(self, y): """Area the gas passes through at depth y (m), per unit of film area.""" factor = 1.0 + self.curvature * y return factor**2 if self.spherical else factor
[docs] def face_open(self, x): """True where gas can pass between the body and the film.""" if self.face_seal is None: return np.ones(np.shape(x)[1:], dtype=bool) return ~np.asarray(_field(self.face_seal, x), dtype=bool)
[docs] def path_length(self, y_from, y_to): """Length of the flow path between two depths, as seen from the film, m. Depth y is measured from the film face into the restrictor, in m. In a curved wall the area the gas passes through changes with depth (``area_factor``), and the flux per unit of area with it, so the resistance of a slice is that of a flat one of this length: the integral of dy / area_factor. Without curvature it is the plain distance. """ c = self.curvature if not np.any(c): return y_to - y_from flat = np.asarray(c) == 0.0 # where the wall is not curved c = np.where(flat, 1.0, c) if self.spherical: curved = (1.0 / (1.0 + c * y_from) - 1.0 / (1.0 + c * y_to)) / c else: curved = (np.log1p(c * y_to) - np.log1p(c * y_from)) / c return np.where(flat, y_to - y_from, curved)[()]
def _inertial_length(self, thickness): """Integral of dy / area_factor² over the thickness, m.""" c = self.curvature if not np.any(c): return thickness flat = np.asarray(c) == 0.0 c = np.where(flat, 1.0, c) if self.spherical: curved = (1.0 - (1.0 + c * thickness) ** -3) / (3.0 * c) else: curved = thickness / (1.0 + c * thickness) return np.where(flat, thickness, curved)[()]
[docs] def equivalent_thickness(self, hp=None): """Thickness of the flat slab with the same Darcy resistance, m.""" hp = self.hp if hp is None else hp return self.path_length(0.0, hp)
[docs] def mass_flux(self, dphi, mu, kappa=None, hp=None, *, gas=None, p_supply=None): """Mass flux through the restrictor into the film, kg/(m² s) of film. dphi: difference of the gas flow potential across it, supply minus film, kg/(m³·s). mu: gas viscosity, Pa·s, taken as uniform through the thickness; used with inertial resistance only. kappa, hp: permeability (m²) and thickness (m) to use instead of those of this restrictor, as arrays over the film. gas, p_supply: the gas model and the absolute supply pressure (Pa); needed with a Knudsen skin only, whose flow follows the pressure and not phi. Darcy flow gives m = kappa/L·dphi with L the equivalent thickness. With inertial resistance beta the flux solves beta·Li·m·|m| + (mu·L/kappa)·m = mu·dphi, where Li, the integral of dy / area_factor², accounts for the flux per unit of area changing with depth in a curved wall. With a Knudsen skin the flux is that of the bulk and the skin in series (``_through_skin``). Returns (flux, d(flux)/d(dphi)), the slope in m. Raises NotImplementedError for inertial resistance and a Knudsen skin together. """ kappa = self.kappa if kappa is None else kappa thickness = self.hp if hp is None else hp hp = self.equivalent_thickness(thickness) dphi = np.asarray(dphi, dtype=float) darcy = kappa / hp skin = self.knudsen_resistance if np.any(skin): if np.any(self.inertial_resistance): raise NotImplementedError( "A Knudsen skin together with inertial (Forchheimer) " "resistance in the bulk is not implemented." ) if gas is None or p_supply is None: raise ValueError( "The flux through a Knudsen skin needs the gas and the " "supply pressure." ) return _through_skin(darcy + 0.0 * dphi, dphi, skin, gas, p_supply) if not np.any(self.inertial_resistance): return darcy * dphi, darcy + 0.0 * dphi with np.errstate(divide="ignore", invalid="ignore"): b = np.where( kappa > 0.0, mu * hp / np.where(kappa > 0.0, kappa, 1.0), np.inf ) a = self.inertial_resistance * self._inertial_length(thickness) root = np.sqrt(b**2 + 4.0 * a * mu * np.abs(dphi)) flux = np.where(np.isfinite(b), 2.0 * mu * dphi / (b + root), 0.0) slope = np.where(np.isfinite(b), mu / root, 0.0) return flux, slope
[docs] def curved(self, radius: float, wall: str, spherical: bool = False) -> Porous: """This restrictor as the curved wall of a cylindrical or spherical bearing. A porous sleeve is a cylindrical shell: the area the gas passes through changes with depth. radius is that of the film, m. wall is "outside" (a sleeve around the film: a bushing on a shaft, area growing away from the film), "inside" (a porous shaft or liner inside the film, area shrinking) or "flat" (a slab: no change). A spherical seat curves in both directions, so its area changes with the square of the radius (spherical=True). Thickness and permeability stay those of the material; the curvature is carried along, and the flow resistance and the inertial resistance each use it in their own way. A curved wall needs a uniform thickness, smaller than the radius for an inside wall (ValueError otherwise). """ if wall not in WALLS: raise ValueError(f"wall must be one of {WALLS}") if wall == "flat": return self if callable(self.hp): raise ValueError("A curved wall needs a uniform restrictor thickness.") if wall == "inside" and self.hp >= radius: raise ValueError("The restrictor is thicker than the film radius.") return replace( self, curvature=(1.0 if wall == "outside" else -1.0) / radius, spherical=spherical, )
[docs] def free_flow( self, area, p_supply, pa=101325.0, gas: Gas = AIR, *, radius: float | None = None, wall: str = "flat", spherical: bool = False, ) -> float: """Free-gas volume flow through the bare restrictor, m³/s at pa. The restrictor of face area ``area`` (m²) vents straight to ambient (pa) from p_supply, both absolute, Pa, with no film in front of it. Uniform kappa and hp only; gas moves through the thickness only, as in the column model. For a sleeve, give the film radius (m) and the wall ("outside" or "inside"); area is then the bore area 2·pi·radius·length. For a spherical seat, spherical=True and the area of the seat. Raises ValueError for a Knudsen skin given as a function of x: without a film there is no face to evaluate it on. """ if callable(self.knudsen_resistance): raise ValueError( "The free flow of a bare restrictor needs a uniform Knudsen " "skin: knudsen_resistance is a function of x, and without a " "film there is no face to evaluate it on." ) porous = self if radius is None else self.curved(radius, wall, spherical) flux, _ = porous.mass_flux( gas.phi(p_supply) - gas.phi(pa), float(gas.mu(p_supply)), gas=gas, p_supply=p_supply, ) return float(flux * area / gas.rho(pa))
[docs] @classmethod def from_free_flow( cls, flow, area, p_supply, hp, pa=101325.0, gas: Gas = AIR, slip=0.0, *, radius: float | None = None, wall: str = "flat", spherical: bool = False, ) -> Porous: """Restrictor whose bare free-gas flow at p_supply is ``flow`` (m³/s at pa). This is how permeability is usually measured. Arguments as in ``free_flow``; hp is the uniform thickness in m. The flow is taken as Darcy flow, and the restrictor returned has kappa, hp and slip only, all else at its default. For a sleeve, give the film radius and the wall: the permeability then comes out as that of the material, to be used with the same wall in the bearing model. For the resistance of a Knudsen skin on a known bulk, see ``with_knudsen_skin``. """ unit = cls(kappa=1.0, hp=hp).free_flow( area, p_supply, pa, gas, radius=radius, wall=wall, spherical=spherical ) return cls(kappa=flow / unit, hp=hp, slip=slip)
[docs] def with_knudsen_skin( self, flow, area, p_supply, pa=101325.0, gas: Gas = AIR, *, radius: float | None = None, wall: str = "flat", spherical: bool = False, ) -> Porous: """This restrictor with the Knudsen skin that makes its free flow ``flow``. flow is the measured free flow, m³/s of free gas at pa, at the absolute supply pressure p_supply (Pa); the other arguments are those of ``free_flow``. The bulk (kappa, hp, curvature) is kept and the skin takes the rest of the pressure drop: the bulk passes the measured mass flux m from p_supply down to the pressure p_i under the skin, and the skin R_K = c_K·(p_i - pa)/m (module docstring). Exact, no iteration. The skin is free-molecular, which holds for pores of a few nm (a small viscous share at p_supply, module docstring); for wider ones the R_K returned fits this one free flow and does not carry over to another supply pressure. A bulk much more open than the skin (a large kappa) leaves the skin all of the drop. Uniform kappa and hp only. Raises ValueError where the bulk alone passes less than ``flow``, and NotImplementedError with inertial resistance. """ if callable(self.kappa) or callable(self.hp): raise ValueError("A Knudsen skin from a free flow needs uniform kappa, hp.") if np.any(self.inertial_resistance): raise NotImplementedError( "A Knudsen skin together with inertial (Forchheimer) " "resistance in the bulk is not implemented." ) flow = float(flow) if not flow > 0.0: raise ValueError("The free flow must be positive.") porous = self if radius is None else self.curved(radius, wall, spherical) m = flow * float(gas.rho(pa)) / area # mass flux, kg/(m² s) darcy = self.kappa / porous.equivalent_thickness() phi_i = float(gas.phi(p_supply)) - m / darcy if phi_i <= float(gas.phi(pa)): raise ValueError( "The bulk alone passes less than this free flow at this " "pressure: no skin can make up for it." ) p_i = float(gas.p_from_phi(phi_i)) return replace( self, knudsen_resistance=knudsen_coefficient(gas) * (p_i - pa) / m )
[docs] def slip_factor(self, h, kappa=None): """(Psi, dPsi/dh): the total slip factor on h³ at gap h (m), and its slope. The constant ``slip`` plus the Beavers-Joseph factor of ``slip_coefficient`` at the permeability kappa (m², default that of this restrictor). The slope is in 1/m. """ kappa = self.kappa if kappa is None else kappa h = np.asarray(h, dtype=float) if not np.any(self.slip_coefficient): return self.slip + 0.0 * h, 0.0 * h alpha = self.slip_coefficient root = np.sqrt(np.where(kappa > 0.0, kappa, 1.0)) sigma = h / root denominator = sigma * (1.0 + alpha * sigma) psi = 3.0 * (sigma + 2.0 * alpha) / denominator dpsi = ( 3.0 * (denominator - (sigma + 2.0 * alpha) * (1.0 + 2.0 * alpha * sigma)) / denominator**2 / root ) # a sealed face is a solid wall, and so is one without a coefficient on = (np.asarray(kappa) > 0.0) & (np.asarray(alpha) > 0.0) return self.slip + np.where(on, psi, 0.0), np.where(on, dpsi, 0.0)
def _through_skin(darcy, dphi, skin, gas, p_supply): """(flux, d(flux)/d(dphi)) through a Darcy bulk and a Knudsen skin in series. darcy: kappa/L of the bulk, m, an array; dphi: phi_s - phi_f, as in ``Porous.mass_flux``; skin: R_K, a number or an array, 0 for no skin. The pressure p_i under the skin solves g(p_i) = darcy·(phi_s - phi(p_i)) - c·(p_i - p_f) = 0, c = c_K/R_K. g falls with p_i and is concave (phi'' > 0), so Newton from the larger of p_s and p_f approaches the root from one side and cannot overshoot. The slope follows from the two conductances in series, c and b = darcy·phi'(p_i), as d(flux)/d(p_f) = -c·b/(c + b), over d(dphi)/d(p_f) = -phi'(p_f), whichever side the flux is taken from. The flux is c·(p_i - p_f) where the skin is the larger resistance (c <= b) and darcy·(phi_s - phi(p_i)) where the bulk is: the side with the larger drop, so that a skin of R_K -> 0 tends to the bulk alone without cancellation. Where darcy is 0 nothing passes; where the skin is 0 the flux is that of the bulk alone. Free-molecular flow through the skin is assumed: valid where the viscous share is small at the supply pressure, pores of a few nm for air at bearing pressures (module docstring). """ darcy = np.asarray(darcy, dtype=float) skin = np.broadcast_to(np.asarray(skin, dtype=float), darcy.shape) phi_s = float(gas.phi(p_supply)) p_f = np.asarray(gas.p_from_phi(phi_s - dphi), dtype=float) bare = skin <= 0.0 c = knudsen_coefficient(gas) / np.where(bare, 1.0, skin) low, high = np.minimum(p_f, p_supply), np.maximum(p_f, p_supply) p_i = high.copy() for _ in range(100): g = darcy * (phi_s - gas.phi(p_i)) - c * (p_i - p_f) step = g / (darcy * gas.dphi_dp(p_i) + c) p_i = np.clip(p_i + step, low, high) # g falls with p_i # 1e-14 of the pressure: the root to rounding of p_i if np.all(np.abs(step) <= 1e-14 * high): break else: raise RuntimeError("The pressure under the Knudsen skin did not converge.") b = darcy * gas.dphi_dp(p_i) # Each side gives the flux at the root; take it from the larger # resistance, whose pressure drop is the larger. A skin that conducts # far more than the bulk leaves p_i - p_f a difference of nearly equal # numbers, which c then multiplies. skin_side = c * (p_i - p_f) bulk_side = darcy * (phi_s - gas.phi(p_i)) flux = np.where(bare, darcy * dphi, np.where(c > b, bulk_side, skin_side)) slope = np.where(bare, darcy, c * b / (c + b) / gas.dphi_dp(p_f)) return flux, slope # ---------------------------------------------------------------------- column model
[docs] @dataclass(frozen=True) class Layer: """One layer of the restrictor. Fields may be arrays over the film.""" thickness: object # m kappa: object # m² start: object = 0.0 # depth of its film-side face below the film face, m
[docs] def restrictor_layers(porous, x) -> list: """Layers from the film face to the supply face at the points x. One ``Layer`` without a surface layer, otherwise the surface layer and the bulk, with fields of the shape of x[0]. Their series flow is that of porous.kappa over the restrictor, so a surface layer redistributes the resistance without changing the static column model. In a curved wall the resistance of a slice is its path length (porous.path_length) over its permeability. Where the face is sealed, or kappa is 0, the permeability of every layer is 0. """ porous = porous.at(x) kappa, hp = _field(porous.kappa, x) * porous.face_open(x), _field(porous.hp, x) reduction = _field(porous.layer_flow_reduction, x) if not np.any(reduction > 0.0): return [Layer(hp, kappa)] d = _field(porous.layer_thickness, x) if np.any(d >= hp) or np.any(reduction >= 1.0): raise ValueError( "Surface layer: need thickness < restrictor thickness and " "flow reduction < 1." ) passed = 1.0 - reduction # flow that still passes, relative to the bare bulk whole, top = porous.path_length(0.0, hp), porous.path_length(0.0, d) bulk = kappa / passed # The layer takes whatever resistance the bulk below it does not supply: # top/layer = whole/kappa - rest/bulk. Written without dividing by kappa, # so that it is 0 and not inf - inf where nothing passes (kappa = 0, a # sealed face). The bracket is positive: rest < whole and passed <= 1. rest = porous.path_length(d, hp) layer = kappa * top / (whole - rest * passed) return [ Layer(d, layer), Layer(hp - d, bulk, start=d), ]
# ---------------------------------------------------------------------- volume model @BilinearForm def _d0(u, v, w): return w.c * grad(u)[0] * grad(v)[0] @BilinearForm def _d1(u, v, w): return w.c * grad(u)[1] * grad(v)[1] @BilinearForm def _mass(u, v, w): return w.c * u * v
[docs] def depth_edges( layers, first: float = 40e-6, ratio: float = 2.0, back: float | None = 300e-6, *, marks=(), mark: float = 40e-6, ) -> np.ndarray: """Element edges through the thickness in m, 0 at the film face. layers: thicknesses from the film face to the back, m. In each layer the elements grow geometrically by ``ratio`` from about ``first`` (m) on its film side, with an edge at every layer interface: the pore pressure varies most next to the film face, where the gas turns along it. The last layer is graded from the back face too, from about ``back`` (m; None: not at all), where the edge of a partial feed is. The sizes are scaled to fill each layer, at least two elements in each. marks: depths, m, that get an edge of their own, with the elements graded toward them from both sides from about ``mark`` (m): the depth where a partly open rim (``Porous.rim_open_depth``) is sealed, at whose corner the flow is singular. A mark at a layer interface or at either face changes nothing. ``mark`` 40 µm: on a disc 4.5 mm thick open down to 3.75 mm, with 300 µm the flows stayed 0.3 % (supply) and 0.7 % (rim) off an axisymmetric reference however fine the film mesh, with 40 µm they fell to 0.06 % and 0.15 % at nrefs 5, and 20 µm moved them by 0.005 % (tests/test_core_partly_open_rim.py). The mark takes that disc from 9 to 16 elements through the thickness. ratio 2 keeps the elements in the middle of a thick restrictor small. """ # pieces of the thickness: (thickness, element at the top, at the bottom) pieces, top = [], 0.0 for k, thickness in enumerate(layers): bottom = back if k == len(layers) - 1 else None cuts = [top] # a mark on an interface is that interface. 1e-9 of the layer: far # above the roundoff of the sums that place marks and interfaces # (1e-16 of the thickness), far below any element (micrometres) tol = 1e-9 * thickness cuts += [m for m in sorted(marks) if top + tol < m < top + thickness - tol] cuts += [top + thickness] for j, (a, b) in enumerate(zip(cuts[:-1], cuts[1:], strict=True)): pieces.append( ( b - a, first if j == 0 else mark, bottom if j == len(cuts) - 2 else mark, ) ) top += thickness edges = [0.0] for thickness, near, far in pieces: near = min(near, thickness / 2.0) far = None if far is None else min(far, thickness / 2.0) front, behind, total = [], [], 0.0 while total < thickness or len(front) + len(behind) < 2: if far is None or near <= far: front.append(near) total, near = total + near, near * ratio else: behind.append(far) total, far = total + far, far * ratio h = np.array(front + behind[::-1]) edges.extend(edges[-1] + thickness * np.cumsum(h) / h.sum()) return np.array(edges)
[docs] def factorise(A): """Sparse LU of a matrix of the volume problem. These matrices have a symmetric pattern and a strong diagonal (diffusion in the body and in the film), so the ordering is chosen for A + Aᵀ and a diagonal entry is kept as pivot unless it is below 1 % of its column. That is about ten times faster than partial pivoting and gives the same solution to rounding. Returns the SuperLU object. """ return splu( A.tocsc(), permc_spec="MMD_AT_PLUS_A", diag_pivot_thresh=0.01, options={"SymmetricMode": True}, )
[docs] def volume_unsupported(film) -> str | None: """Why the volume model cannot be used for this film, or None if it can. A film of several faces (``Film.regions``, the thrust bushing) gets one volume per face, each with its own restrictor description, which must then be uniform over that face but for its permeability. """ if film.regions: for name, inside in film.regions.items(): try: porous = _region_porous(film, inside) except ValueError as error: return f"Face {name!r}: {error}" reason = _uniform_unsupported(porous) if reason: return f"Face {name!r}: {reason}" return None return _uniform_unsupported(film.porous)
def _uniform_unsupported(porous) -> str | None: if callable(porous.hp): return "The volume model needs a uniform restrictor thickness." if callable(porous.inertial_resistance) or porous.inertial_resistance: return "Inertial (Forchheimer) flow is not implemented in the volume model." return None # restrictor options that a face of several takes as one value over the face _PER_FACE = ( "hp", "layer_flow_reduction", "layer_thickness", "curvature", "equivalent_clearance", "slip_coefficient", "inertial_resistance", "inplane_ratio", ) # fmt: skip def _region_porous(film, inside): """The restrictor of one face of a film of several faces (Film.regions). Every option given as a function of the film coordinates is taken at the nodes of that face, where it must be one value; the permeability stays a function, zero outside the face. Raises ValueError where an option varies over the face. """ porous, x = film.porous, film.basis.doflocs mine = np.asarray(inside(x), dtype=bool) if not mine.any(): raise ValueError("the face has no node") values = {} for name in _PER_FACE: value = getattr(porous, name) if not callable(value): continue here = np.asarray(_field(value, x[:, mine]), dtype=float) if np.ptp(here) > 1e-12 * max(np.abs(here).max(), 1e-300): raise ValueError(f"{name} varies over the face") values[name] = float(here.flat[0]) kappa = porous.kappa def on_face(x): return _field(kappa, x) * np.asarray(inside(x), dtype=bool) return replace(porous, kappa=on_face, **values) def restrictor_volume(film, sc, first: float = 40e-6): """The extruded volume of a film: one ``RestrictorVolume``, or one per face for a film of several faces (``FaceVolumes``).""" if film.regions: return FaceVolumes(film, sc, first) return RestrictorVolume(film, sc, first)
[docs] class RestrictorVolume: """The restrictor body of a film: its mesh, its Darcy operator and its state. film: the film (film.py), with a uniform restrictor thickness. sc: its scaled coefficient fields at the position to solve. first: size of the depth element at the film face, m (``depth_edges``). The unknowns are Theta, the scaled flow potential of film.py, at the nodes of the body, and P = p/pa where the film shares a node with the face. They are numbered depth level by depth level: index = level·n + node, with n the number of film nodes; ``depth`` is the depth of each level in m, and the levels are not in order of depth. Where the face is sealed the film has unknowns of its own after those of the body. ``film_index`` is the unknown of each film node, ``face`` the unknowns of the body on the film face, ``supply`` those on the fed part of the back, ``rim`` those on an open rim, at ``rim_pressure`` (Pa), and ``sealed`` those left out of the solve because nothing flows there. ``K`` is the Darcy operator on Theta, scaled like the film residual. With a Knudsen skin (``Porous.knudsen_resistance``) the film has unknowns of its own, P after those of the body, and the unknowns of the body on its face are its pressure p_i/pa there; ``S`` is the scaled conductance of the skin between the two (module docstring), None without a skin. ``pressure`` lists the unknowns of the body that are a pressure P and not Theta, ``is_pressure`` marks them. Behind a skin the unknowns of the body on its face (``drop``, marked by ``is_drop``) are the drop across it, scaled: P_i = P_f + drop_scale·y (``face_pressure``). Raises NotImplementedError where the model does not apply (``volume_unsupported``, and a Knudsen skin that is zero over part of the open face) and ValueError for a feed that covers no part of the back or meets an open rim, which the whole back fed always does with the rim open down to the back, and for an open depth of the rim (``Porous.rim_open_depth``) that is not one number in (0, hp] or that is given with a sealed rim. """ def __init__(self, film, sc, first: float = 40e-6): porous, basis = film.porous, film.basis reason = volume_unsupported(film) if reason: raise NotImplementedError(reason) self.film, self.porous = film, porous hp, c = float(porous.hp), porous.curvature # layers through the depth: thickness, factor on kappa self.layers = self._layers(porous, hp) bounds = np.cumsum([t for t, _ in self.layers]) # the rim open down to this depth and sealed below it, m open_depth = self._rim_open_depth(porous, hp) marks = (open_depth,) if open_depth is not None and open_depth < hp else () b1 = Basis( MeshLine(depth_edges([t for t, _ in self.layers], first, marks=marks)), ElementLineP2(), ) yq = b1.mapping.F(b1.X)[0] # depth at the quadrature points, (elements, points) centre = b1.mapping.F(np.array([[0.5]]))[0, :, 0] which = np.minimum(np.searchsorted(bounds, centre), len(self.layers) - 1) factor = np.array([f for _, f in self.layers])[which][:, None] * np.ones_like( yq ) widen = 1.0 + c * yq # lengths along a bent direction at depth y area = porous.area_factor(yq) # area per unit of film area # in-plane operators on the film mesh, with the film metric g1, g2 = sc.g kappa = _field(porous.kappa, sc.xq) A0 = _d0.assemble(basis, c=kappa * sc.area / g1**2) A1 = _d1.assemble(basis, c=kappa * sc.area / g2**2) M2 = _mass.assemble(basis, c=kappa * sc.area) # Depth operators. Along a bent direction the gradient shortens by # 1/widen while the volume per unit of film area is area: an # in-plane term gets area/widen² along a bent direction and area # along a straight one. In a cylinder (one direction bent) that is # 1/widen and widen, in a sphere (both bent) 1 and 1. ratio = porous.inplane_ratio def along(axis): bent = porous.spherical or axis == porous.bent_axis return ratio * factor * area / (widen**2 if bent else 1.0) Y0 = _mass.assemble(b1, c=along(0)) Y1 = _mass.assemble(b1, c=along(1)) Yn = _d0.assemble(b1, c=factor * area) self.scale = 12.0 / film.h_ref**3 K = self.scale * (sp.kron(Y0, A0) + sp.kron(Y1, A1) + sp.kron(Yn, M2)) self.b1, self.n1, self.n2 = b1, b1.N, basis.N yd = b1.doflocs[0] self.depth = yd face_level = int(np.argmin(np.abs(yd))) back_level = int(np.argmin(np.abs(yd - hp))) self.face = face_level * self.n2 + np.arange(self.n2) fed = np.ones(self.n2, dtype=bool) if porous.feed_area is not None: fed = np.asarray(_field(porous.feed_area, basis.doflocs), dtype=bool) if not fed.any(): raise ValueError("The feed area does not cover any part of the back face.") self.supply = back_level * self.n2 + np.flatnonzero(fed) # The film pressure is the pore pressure at the face, one unknown for # both, except where the face is sealed: there the film gets an # unknown of its own after those of the body, and nothing ties the # two together. n_body = self.n1 * self.n2 self.coupled = np.asarray(porous.face_open(basis.doflocs), dtype=bool) skin = _skin_conductance(porous, sc) self.film_index = self.face.copy() if skin is None: self.film_index[~self.coupled] = n_body + np.arange(np.sum(~self.coupled)) self.n_total = n_body + int(np.sum(~self.coupled)) else: # behind a skin the film has unknowns of its own everywhere self.film_index = n_body + np.arange(self.n2) self.n_total = n_body + self.n2 self.n_body = n_body self.K = self._padded(K) # An open rim is the side of the body under an edge of the film that # is a real edge (one with a pressure), at that pressure: the side is # exposed to the same gas as the film edge above it, ambient or a # chamber. A symmetry line of the film is one of the body too. rim, rim_p = [], [] if porous.rim_open: # the levels of the open part of the side; the seal begins at a # level of its own (a mark of the depth mesh), so this is exact. # 1e-9·hp: far above the roundoff of the cumulative sum that # places that level (1e-16·hp), far below the smallest element # (half the open depth at the least) levels = np.flatnonzero(yd <= open_depth + 1e-9 * hp) for dofs, p in film.boundaries.values(): nodes = (levels[:, None] * self.n2 + np.asarray(dofs)[None, :]).ravel() # the film's own unknowns there are set with the film if skin is None: nodes = np.setdiff1d(nodes, self.face[self.coupled]) rim.append(nodes) rim_p.append(np.full(nodes.size, float(p))) self.rim = np.concatenate(rim) if rim else np.array([], dtype=np.int64) self.rim_pressure = np.concatenate(rim_p) if rim_p else np.array([]) if np.intersect1d(self.rim, self.supply).size: whole = " (the whole back is fed)" if porous.feed_area is None else "" raise ValueError( "With an open rim (Porous.rim_open) open down to the back, the " f"fed part of the back must stop short of the rim{whole}. Seal " "the rim next to the back (Porous.rim_open_depth less than the " "thickness), give Porous.feed_area a function of the film " "coordinates that is false within a margin of every film edge " "with a pressure, or leave the rim sealed (rim_open=False). " "Where supply pressure and the pressure of the open side meet " "along one edge the flow through that edge has no limit: it " "keeps growing as the mesh is refined." ) # Where the restrictor is impermeable (kappa = 0 over part of the # face, or all of it) no gas moves and the pore pressure is not # defined: those unknowns are left out of the solve. sealed = self.K.diagonal()[:n_body] == 0.0 if skin is None: sealed[self.face[self.coupled]] = False self.sealed = np.flatnonzero(sealed) # unknowns of the body that are a pressure: the face shared with the # film; behind a skin the face has the drop across it instead self.is_pressure = np.zeros(self.n_total, dtype=bool) self.is_drop = np.zeros(self.n_total, dtype=bool) if skin is None: self.pressure = self.face[self.coupled] self.is_pressure[self.pressure] = True self.S = None else: self.pressure = np.array([], dtype=np.int64) # The unknown on the face is y with P_i = P_f + s·y, the drop # across the skin. That is what removes the cancellation: P_i # itself would hold a small drop as a difference of nearly equal # numbers, which a large c then multiplies. The scale s only # improves the conditioning (with s = 1 throughout the solve is # at rounding too): s = 1 where the skin is the larger # resistance, and b/c where it conducts more, so that y is of # the order of the drop in the bulk. b = kappa/L·phi'(ps) of the # bulk and c = c_K/R_K of the skin at the node, with kappa the # largest in the elements around it: a node where kappa is 0 # next to a permeable element takes that element's. # # The skin joins the body and the film node by node where the # face is open (``coupled``), as the face is shared without a # skin: a vanishing skin then tends to the volume without one, # a face seal included. kept = ~np.isin(self.face, self.sealed) self.drop = self.face[kept] self.drop_film = self.film_index[kept] M = _mass.assemble(basis, c=skin).tocoo() on = self.coupled[M.row] & self.coupled[M.col] M = sp.coo_matrix((M.data[on], (M.row[on], M.col[on])), shape=M.shape) dofs = basis.element_dofs near = np.zeros(self.n2) np.maximum.at(near, dofs, np.max(kappa, axis=1)[None, :]) x = basis.doflocs[:, kept] b = near[kept] / porous.equivalent_thickness() b = b * float(film.gas.dphi_dp(film.ps)) resistance = _field(porous.at(x).knudsen_resistance, x) c = knudsen_coefficient(film.gas) / np.where(resistance > 0, resistance, 1) on = (c > b) & (b > 0.0) & (resistance > 0) & self.coupled[kept] self.drop_scale = np.where(on, b / c, 1.0) self.is_drop[self.drop] = True # mass flux c·pa·(P_i - P_f) = c·pa·s·y through the skin, scaled # like K: it leaves the body at its face and enters the film scale = np.zeros(self.n2) scale[kept] = self.drop_scale data = M.data * scale[M.col] i, f = self.face, self.film_index rows = np.concatenate([i[M.row], f[M.row]]) cols = np.concatenate([i[M.col], i[M.col]]) vals = np.concatenate([data, -data]) N = self.n_total self.S = sp.csr_matrix((vals, (rows, cols)), shape=(N, N)) self.X = None # the solved state: Theta in the volume, P on the face
[docs] def face_pressure(self, X): """P_i = p_i/pa on the face of the body behind a Knudsen skin.""" return X[self.drop_film] + self.drop_scale * X[self.drop]
@staticmethod def _rim_open_depth(porous, hp): """Depth down to which the rim is open, m, or None for a sealed rim. ValueError for a depth that is not a number in (0, hp]: the open part runs from the film face and cannot reach below the back; and for a depth given with a sealed rim (rim_open False), other than the thickness it follows. """ depth = porous.rim_open_depth if not porous.rim_open: # The thickness, which the depth follows when not given, is what # a form may send for it (1e-9·hp: a value typed in mm and # scaled back to m); any other depth asks for an open part that # a sealed rim does not have. if depth is not None and ( callable(depth) or np.ndim(depth) != 0 or abs(float(depth) - hp) > 1e-9 * hp ): raise ValueError( f"Porous.rim_open_depth is given ({depth!r}) but the rim " "is sealed (rim_open False): the depth is how far down an " "open rim is open, so it needs rim_open=True. Set " "rim_open=True for a rim open down to that depth, or leave " "rim_open_depth None for a sealed one." ) return None if depth is None: return hp if callable(depth) or np.ndim(depth) != 0: raise ValueError( "Porous.rim_open_depth must be one number: the open part of " "the rim is the same all round in the volume model." ) depth = float(depth) if not 0.0 < depth <= hp * (1.0 + 1e-12): raise ValueError( f"Porous.rim_open_depth is {depth} m: it must be above 0 and " f"at most the restrictor thickness {hp} m, as it is measured " "from the film face into the restrictor. For a sealed rim " "leave rim_open False." ) return min(depth, hp) @staticmethod def _layers(porous, hp): """[(thickness, factor on kappa)] from the film face to the back.""" unit = type(porous)( kappa=1.0, hp=hp, layer_flow_reduction=porous.layer_flow_reduction, layer_thickness=porous.layer_thickness, curvature=porous.curvature, spherical=porous.spherical, ) point = np.zeros((2, 1)) return [ (float(L.thickness[0]), float(L.kappa[0])) for L in restrictor_layers(unit, point) ] # ------------------------------------------------------------ unknowns def _padded(self, A): """A matrix of the body, widened by the film's own unknowns.""" extra = self.n_total - self.n_body return sp.block_diag([A, sp.csr_matrix((extra, extra))], format="csr")
[docs] def theta(self, X, sc): """Theta at every node of the body from the unknowns. P at ``pressure``, and behind a Knudsen skin P_i from the drop across it (``face_pressure``). """ T = X.copy() shared = self.pressure T[shared] = sc.theta(self.film.pa * X[shared]) if self.S is not None: T[self.drop] = sc.theta(self.film.pa * self.face_pressure(X)) return T
[docs] def flow(self, X, sc): """Residual of the flow in the body: what each node gives to it. Scaled mass flow (kg/s over the mass scale of film.py): zero at a free node, and at a node held at a pressure the flow that enters the body there. """ if self.S is None: return self.K @ self.theta(X, sc) return self.K @ self.theta(X, sc) + self.S @ X
[docs] def flow_jacobian(self, X, sc): """Derivative of ``flow`` with respect to the unknowns.""" if self.S is None: return self.K @ self.dtheta(X, sc) return self.K @ self.dtheta(X, sc) + self.S
[docs] def dtheta(self, X, sc): """d(Theta)/d(unknown): 1 except where it is P or a drop across a skin. Diagonal, but for a skin: Theta on the face of the body then follows the film pressure too (``face_pressure``). """ d = np.ones_like(X) shared = self.pressure p = self.film.pa * X[shared] d[shared] = self.film.gas.dphi_dp(p) / sc.dphi_a if self.S is None: return sp.diags(d) slope = self.film.gas.dphi_dp(self.film.pa * self.face_pressure(X)) / sc.dphi_a d[self.drop] = slope * self.drop_scale N = X.size off = sp.csr_matrix((slope, (self.drop, self.drop_film)), shape=(N, N)) return sp.diags(d) + off
[docs] def embed(self, A2): """A film matrix placed on the film's unknowns.""" A2 = A2.tocoo() index, N = self.film_index, self.n_total return sp.csr_matrix((A2.data, (index[A2.row], index[A2.col])), shape=(N, N))
[docs] def column_start(self, P1, sc): """Unknowns from a film pressure P1 = p/pa, with the column profile below. Behind a Knudsen skin the profile starts from the pressure under the skin of the column model at P1, which the face of the body takes. """ porous = self.porous film = self.film theta_f = sc.theta(film.pa * P1) if self.S is not None: p_f = film.pa * np.asarray(P1, dtype=float) x = film.basis.doflocs at = porous.at(x) darcy = _field(at.kappa, x) / at.equivalent_thickness(_field(at.hp, x)) dphi = film.gas.phi(film.ps) - film.gas.phi(p_f) skin = _field(at.knudsen_resistance, x) flux, _ = _through_skin(darcy, dphi, skin, film.gas, film.ps) c = knudsen_coefficient(film.gas) / np.where(skin > 0.0, skin, 1.0) drop = np.where(skin > 0.0, flux / c, 0.0) # p_i - p_f, Pa theta_f = sc.theta(p_f + drop) tops = np.concatenate([[0.0], np.cumsum([t for t, _ in self.layers])[:-1]]) resistance = np.zeros_like(self.depth) total = 0.0 for (thickness, factor), top in zip(self.layers, tops, strict=True): inside = np.clip(self.depth, top, top + thickness) resistance += porous.path_length(top, inside) / factor total += porous.path_length(top, top + thickness) / factor share = resistance / total # 0 at the film face, 1 at the back body = theta_f[None, :] + (sc.theta_s - theta_f[None, :]) * share[:, None] X = np.zeros(self.n_total) X[: self.n_body] = body.ravel() if self.S is not None: kept = self.is_drop[self.face] X[self.drop] = drop[kept] / film.pa / self.drop_scale X[self.film_index] = P1 return X
def _skin_conductance(porous, sc): """Scaled conductance c_K·pa/R_K of a Knudsen skin at the quadrature points. Per unit of the film coordinates and of the mass scale of film.py, and zero where the restrictor is solid (kappa = 0); a face seal is taken node by node where the skin is assembled (``RestrictorVolume``). None without a skin, which is also where it is zero over all of the open face. Raises NotImplementedError for a skin that is zero over part of the open face and not over the rest. """ resistance = porous.knudsen_resistance if not (callable(resistance) or resistance): return None film, xq = sc.film, sc.xq open_ = (_field(porous.kappa, xq) > 0.0) & porous.face_open(xq) resistance = _field(resistance, xq) on = resistance[open_] if not np.any(on > 0.0): return None if np.any(on <= 0.0): raise NotImplementedError( "A Knudsen skin that is zero over part of the face is not " "implemented in the volume model: the face of the body would be " "shared with the film there and separated from it elsewhere. Give " "it a positive resistance over all of the face, or use the column " "model." ) passes = (_field(porous.kappa, xq) > 0.0) & (resistance > 0.0) c = knudsen_coefficient(film.gas) / np.where(passes, resistance, 1.0) return np.where(passes, c * film.pa / sc.mass_scale * sc.area, 0.0) class FaceVolumes: """One extruded volume per face of a film of several faces (the bushing). Each face (an entry of ``Film.regions``) is extruded through its own restrictor: its thickness, layers, curvature and the direction that bends with it. The volumes share only the film: the pore pressure of each at its face is the film pressure, so the film connects them where the faces meet. Inside the material they are separate pieces sealed against each other, as the two parts of a bonded bushing are: where their extrusions overlap behind the corner each counts its own material, as the column model of the same bushing does. Same interface as ``RestrictorVolume``. The unknowns are the film pressures first (the shared face), then those of each volume below its face. """ def __init__(self, film, sc, first: float = 40e-6): reason = volume_unsupported(film) if reason: raise NotImplementedError(reason) self.film = film n2 = film.basis.N self.parts, self.index = [], [] offset = n2 for inside in film.regions.values(): part_film = replace(film, porous=_region_porous(film, inside), regions=None) if _skin_conductance(part_film.porous, sc) is not None: raise NotImplementedError( "A Knudsen skin on a film of several faces is not " "implemented in the volume model." ) part = RestrictorVolume(part_film, sc, first) if not part.coupled.all(): raise NotImplementedError("A sealed face on a film of several faces.") # local unknown -> global: the face onto the film nodes, the rest # after those of the volumes before to_global = -np.ones(part.n_total, dtype=np.int64) to_global[part.face] = np.arange(n2) rest = np.flatnonzero(to_global < 0) to_global[rest] = offset + np.arange(rest.size) offset += rest.size self.parts.append(part) self.index.append(to_global) self.n_total = offset self.film_index = np.arange(n2) self.face = self.film_index self.coupled = np.ones(n2, dtype=bool) self.K = self._gather(lambda part: part.K) def union(name): pieces = [ g[getattr(p, name)] for p, g in zip(self.parts, self.index, strict=True) ] return np.unique(np.concatenate(pieces)) if pieces else np.array([], int) self.supply = union("supply") self.rim = np.array([], dtype=np.int64) self.rim_pressure = np.array([]) self.sealed = np.setdiff1d(union("sealed"), self.supply) self.X = None def _gather(self, matrix_of): """The sum of a matrix of each volume, on the global unknowns.""" total = sp.csr_matrix((self.n_total, self.n_total)) for part, g in zip(self.parts, self.index, strict=True): A = matrix_of(part).tocoo() total = total + sp.csr_matrix( (A.data, (g[A.row], g[A.col])), shape=total.shape ) return total.tocsr() def theta(self, X, sc): T = X.copy() T[self.face] = sc.theta(self.film.pa * X[self.face]) return T def dtheta(self, X, sc): d = np.ones_like(X) p = self.film.pa * X[self.face] d[self.face] = self.film.gas.dphi_dp(p) / sc.dphi_a return sp.diags(d) def flow(self, X, sc): return self.K @ self.theta(X, sc) def flow_jacobian(self, X, sc): return self.K @ self.dtheta(X, sc) def embed(self, A2): A2 = A2.tocoo() index, N = self.film_index, self.n_total return sp.csr_matrix((A2.data, (index[A2.row], index[A2.col])), shape=(N, N)) def column_start(self, P1, sc): X = np.zeros(self.n_total) for part, g in zip(self.parts, self.index, strict=True): X[g] = part.column_start(P1, sc) return X