turbo_moc.api module#

turbo_moc.api – computational API layer.

Mirrors the pattern used by turbodash’s core.py: one plain function that takes primitive arguments (no MOCSolver/FluidManager objects, no UI concerns) and returns a single flat, JSON-safe dict. A Dash (or any other) UI layer can sit on top of this exactly like turbodash’s app.py sits on top of core.py’s compute_stage_meanline() – call design_nozzle() inside a callback, fan its returned dict out into plot/table builders.

This module owns no state itself: FluidManager caching (turbo_moc.core.classes. get_fluid_manager) already lives one level down and is reused as-is, so repeated calls at the same operating point (the common case while a UI sweeps geometry) stay cheap.

exception turbo_moc.api.NozzleDesignError[source]#

Bases: Exception

Raised when a nozzle design request is invalid or the solve fails before reaching a usable result (as opposed to the solver’s own graceful early-stop, which still returns a partial-but-usable design – see the ‘converged’ flag in design_nozzle’s returned dict).

turbo_moc.api.design_nozzle(fluid_name: str, P0: float, T0: float = None, Q0: float = nan, p_back: float = None, Noz_Mach: float = None, solver: str = 'conventional', y_t: float = 0.01, n: int = 15, rho_t: float = 0.2, rho_d: float = 0.1, delta_flow: float = 0.0, tau_max: float = 90.0, tau_step: float = 1.0, n_tau_mln: int = 60, use_true_sauer_line: bool = False, backend: str = 'HEOS', show_plot: bool = False, progress_callback=None, auto_nudge_q0: bool = True) → dict[source]#

Run every stage of a method-of-characteristics nozzle design.

The function accepts ordinary values and returns no solver or fluid-manager objects, so its result can be passed directly to a UI callback or HTTP handler.

Parameters:
fluid_namestr

CoolProp fluid name.

P0float

Stagnation pressure in pascals.

T0float, optional

Stagnation temperature in kelvin for a single-phase or flashing inlet.

Q0float, optional

Inlet quality for a saturated two-phase state. Leave as NaN when using T0.

p_backfloat, optional

Back pressure in pascals. This is the recommended design target and is required by the minimum-length solver.

Noz_Machfloat, optional

Direct nozzle Mach-number target. At least one of p_back and Noz_Mach is required.

solver{“conventional”, “mln”}

Rounded-arc conventional solver or sharp-corner minimum-length solver.

y_tfloat

Throat half-height.

nint

Number of points used to discretize the initial characteristic line.

rho_t, rho_dfloat

Geometric radii used by the nozzle construction.

delta_flowfloat

Axisymmetric-flow switch or coefficient passed to the solver.

tau_max, tau_stepfloat

Angular extent and increment for the conventional solver.

n_tau_mlnint

Number of angular samples for the minimum-length expansion fan.

use_true_sauer_linebool

Use the classical parabolic Sauer sonic line instead of the default flat post-jump throat front.

backendstr

Thermodynamic backend passed to the fluid manager.

show_plotbool

Enable the solver’s diagnostic plotting.

progress_callbackcallable, optional

Called as progress_callback(fraction, stage_label) throughout the solver stages.

auto_nudge_q0bool

If a saturated-liquid classical Sauer solve fails, retry with small positive inlet qualities and retain the first converged result.

Returns:
dict

JSON-safe solver data. It includes wall, kernel, Sauer-line, mesh, and axis data together with the resolved inputs, convergence state, and runtime.

turbo_moc.api.list_supported_fluids() → list[source]#

CoolProp’s fluid list, for populating a fluid-selection UI control.