openairbearing.plots

Matplotlib plots of solver results, in the units people read.

import matplotlib.pyplot as plt
from openairbearing import core, plots

film = core.circular_pad(18.5e-3, porous=core.Porous(), ps=0.5e6)
state = core.solve_static(film, [5e-6, 1e-4, 0.0])
plots.plot_field(state, gauge=True)       # map of the pressure
plots.plot_profile(state, gauge=True)     # the same along a line
plt.show()

Every function draws into the axes it is given (a new figure otherwise) and returns them, so the figure stays ordinary matplotlib: lay it out, add curves and annotate as usual. Keywords that a function does not name go to the matplotlib call that draws the data.

plot_field and plot_profile take a solved state (core.solve_static) or a field document (study.field); plot_geometry takes a film; plot_output takes a study result (study.run), fresh or loaded from JSON, and draws it in display units or, with normalise, in a named dimensionless scheme of openairbearing.normalise.

Inputs are in SI units. What is drawn is in the display units of openairbearing.display, which also converts curves drawn by hand: pressure in MPa, film thickness in µm, the film coordinates in mm and degrees, stiffness in N/µm and flow in L/min of free gas.

plot_field(source, what: str = 'p', ax=None, *, gauge: bool = False, colorbar: bool = True, **mesh)[source]

Map of the pressure or the film thickness over the film.

source is a solved state or a field document. what is “p” (absolute pressure, in MPa) or “h” (film thickness, in µm); gauge subtracts the ambient pressure. The film is drawn in its own coordinates (mm, degrees), seen from above, in the jet colour scale. colorbar=False leaves the colour bar out, for one bar shared by several maps (the image is ax.collections[-1]). Other keywords go to tripcolor. Returns the axes. Raises ValueError for another what.

plot_geometry(film, ax=None, *, mesh: bool = True, legend: bool = True)[source]

The film as the solver sees it, from above: mesh, feed and edges.

Shows what a result rests on before looking at the result:

  • the elements of the mesh (mesh=False leaves their edges out);

  • what is behind each element, in one of three colours: blue where the restrictor is porous and the supply acts on its back, grey where it is porous without supply behind it (the rest of the back of a restrictor fed over a part of it, Porous.feed_area), white where nothing passes into the film (zero permeability, or a sealed face). An element that the edge of such an area passes through takes the colour of most of it. A film on a porous body is porous and grey: the body takes its supply on faces of its own;

  • the edges where the pressure is prescribed, each in its own colour, with its name and absolute pressure (MPa) in the legend. An edge without a colour is a symmetry line, with no flow across it.

film is a core.Film, from any geometry builder. It is drawn in its own coordinates (mm, degrees), so a journal is unrolled; a face meshed in radius and angle (coordinates r and theta) is drawn as the disc it is. legend=False leaves the legend below the axes out. Returns the axes.

plot_output(result: dict, output: str, ax=None, *, x_axis: int = 0, sign: float = 1.0, label: str | None = None, cases: list | None = None, normalise=None, x_normalise=None, **line)[source]

Plot one output of a study against a swept quantity, one line per case.

With two swept quantities, x_axis picks the one on the horizontal axis and every value of the other one gets its own line. Values are shown in display units, taken from the result. sign = -1 flips the output (a restoring force plotted as positive), label replaces the axis label, cases restricts the plot to the named cases, and any other keyword goes to matplotlib’s plot (color, linestyle, marker, …). Returns the axes. Raises ValueError for a result without a swept quantity, and if a case lacks the output or none of the named cases is in the result.

normalise draws the output in a scheme of openairbearing.normalise instead of display units, and x_normalise the swept quantity on the horizontal axis. Each is a function f(values, at) called once for every drawn line, which returns a normalise.Normalised whose label becomes the axis label with the unit [-]. values are the SI values of that line (the output after sign, or the swept quantity), one per point along the horizontal axis; at maps the path of every swept quantity (“position.h”, “ps”, …) to its SI value at each of those points, so a reference that is itself swept is taken point by point. A scheme takes its reference quantities explicitly, so bind the rest, for example:

plot_output(result, "stiffness.h.h", sign=-1.0,
            normalise=lambda k, at: normalise.stiffness_over_gauge_supply(
                k, gap=at["position.h"], ps=at.get("ps", ps), pa=pa,
                area=area),
            x_normalise=lambda h, at: normalise.feeding_parameter(
                h, kappa=kappa, hp=hp, radius=radius))

Either may also be a dict from case name to such a function, for cases whose reference quantities differ (another size); a plotted case missing from it raises ValueError, and so do lines whose schemes give different labels for the same axis. Left out, nothing changes: display units and the labels of the result.

plot_profile(source, what: str = 'p', ax=None, *, along: str | None = None, at: float | None = None, gauge: bool = False, n: int = 201, **line)[source]

Pressure or film thickness along a straight line in the film coordinates.

source and what are as in plot_field. along names the film coordinate that runs along the line (the first one by default: x of a pad, the axial coordinate of a journal); at is the value of the other coordinate, in SI units (m or rad), by default the middle of its range, which is a diameter of a round pad. The line is drawn through n equally spaced points over the range of the film and is interrupted where it leaves the film. Other keywords go to matplotlib’s plot. Returns the axes. Raises ValueError if along is not a film coordinate.