Skip to content

pyflightstream.workspace.flight_condition (stable)

Generated from the docstrings at build time: every one of the 8 names in the __all__ of pyflightstream.workspace.flight_condition has an entry below. The names a guide or an example uses come first; the others follow under Advanced.

Resolving a flight condition into one flow state (PFS-2027.02, .04).

Pipeline role: the workspace layer, beside :func:resolve_matrix, which is where a matrix row is bound to the input library.

The resolver imports :mod:pyflightstream._atmosphere and :mod:pyflightstream._errors. Reference length arrives as a float; the module does not read artifacts. It defines :class:FlightConditionError, which the public exception catalog re-exports.

The resolver is placed with its caller, downstream of reference binding, so that no layer below the workspace can resolve a Reynolds constraint before a reference exists to measure it against. That guarantee is structural rather than asserted: a caller in a lower layer cannot import this module.

The physics/resolution split is a separate and independent argument, and it stands: the physics can be checked against published tables with no case and no matrix, and the resolution against a trivial atmosphere. In one module neither half is testable on its own.

THE WHOLE DESIGN, in one sentence. A flight condition is a SET OF CONSTRAINTS on one flow state, and the keys given decide WHICH QUANTITY IS SOLVED FOR. It is not a record with optional fields and it is not a lookup: the same resolver answers MACH:0.20, REmi:5.5 and TASmps:68.08, ALTFT:10000, dISA:5 by solving for a different unknown each time.

WHAT EACH KEY DOES TO THE STATE:

  • ALTFT and dISA fix TEMPERATURE, and therefore the speed of sound and the viscosity. Both have defaults, sea level and zero, and those defaults are what make a short constraint set legal at all. A TK pin replaces that temperature, and the speed of sound (sqrt(gamma R T)), the Sutherland viscosity, the Mach conversion and the density follow the pinned value exactly as they follow a dISA; only an ASMPS or MUPas pin of its own replaces them.
  • MACH or TASmps fixes VELOCITY. Exactly one of them, always: none leaves the state under-determined, both is a contradiction the resolver refuses rather than silently preferring one.
  • REmi fixes DENSITY, by solving the Reynolds definition for it. If it is absent, density is the equation of state at the altitude's pressure (or a PPA pin) and the state's temperature, which is the atmosphere's own value when nothing is pinned, and the Reynolds number becomes an OUTCOME instead.

THE SOLVED-DENSITY STATE IS NOT A POINT IN ANY ATMOSPHERE, and that is the design rather than a defect. Holding Mach and Reynolds together at a fixed temperature is what a wind tunnel does and what a validation case needs. With MACH:0.20, REmi:5.5 against a one-metre reference the solved density is about 1.446 kg/m3 against a sea-level 1.225, so the pressure is not sea level's: the state carries p = rho R T, about 119.6 kPa at the sea-level temperature (PFS-2104.050).

THE EMITTED TRIPLE IS CONSISTENT. Whenever the density is solved (REmi) or pinned (RHOkgm3), pressure_pa is the ideal-gas pressure of that density at the state's temperature, unless a PPA pin states the pressure itself; whenever the density is not, it is the ideal-gas density of the pressure and temperature. So density, pressure and temperature satisfy p = rho R T unless the writer pinned all three, and whichever two of them the solver reads it meets the same state. Pins are emitted as written: a writer who pins all three owns their agreement, and the plan and the post WARN when the three disagree with p = rho R T by more than half a percent (:func:pinned_state_mismatch); nothing is refused or withheld.

A solved state is still not an altitude, and a consumer that reads it as one is misled, which is why :attr:ResolvedCondition.density_source exists, and why the run record carries both it and the inputs as written, in density_source and flight_condition.

WHERE A PIN MAY LIVE (PFS-2030.08). The five pins state constants of the fluid, and a constant of the fluid is usually a constant of the CAMPAIGN rather than of the point: one campaign's thirteen-point polar would otherwise repeat the same four numbers thirteen times down the FLIGHT_CONDITION column, where a single mistyped digit on one row is a physics nobody selected on that row alone. So a setup artifact may carry them, and this resolver takes them as defaults: a row that states a pin overrides the setup's, key by key. Setup pins are only defaults: a row stating ALTFT or dISA supersedes all five; a Reynolds-only row supersedes density and pressure but keeps the tunnel temperature, viscosity and sonic velocity. A row stating none of these constraints inherits every pin.

WHAT MAY NOT BE DEFAULTED, and the line is the design rather than caution. The velocity keys and REmi are what the resolver solves FOR, and a preset several rows share cannot state them: a row inheriting a Mach number would be a case nobody wrote, and it would look exactly like a row that stated one. ALTFT and dISA select a point IN the atmosphere, which the pins exist to replace rather than to locate. So the defaults table holds pins and nothing else, and anything else in it is refused naming where it came from.

SETUP DEFAULTS CAN BE SUPERSEDED WITHOUT CONTRADICTING ANYTHING. ALTFT or dISA drops all five setup pins so the row resolves at its own atmosphere point. REmi without either drops RHOkgm3 and PPA: density is solved and pressure follows p = rho R T. The other three setup pins remain. Row-stated pins are never dropped by this rule; a ROW stating both RHOkgm3 and REmi is still refused. The omitted defaults are recorded in :attr:ResolvedCondition.dropped_defaults, so planning can name every affected POL in one campaign warning.

WHY A REYNOLDS CONSTRAINT NEEDS THE REFERENCE (PFS-2027.04). A Reynolds number is meaningless without a length, and the dependency is not academic: the same MACH:0.20, REmi:5.5 against a unit chord gives a density about 18 percent above sea level, and against a rotor's mean face length of about 0.15 m gives nearly eight times sea level, at an implied pressure near 797 kPa. Both figures are computed at sea level from the constants in _atmosphere; the ratio BETWEEN those two states is neither of those numbers, it is the ratio of the two lengths, because on this branch density is inversely proportional to the length and to nothing else. Same inputs, same resolver, a state that is ordinary or absurd depending on a number that comes from somewhere else entirely. So a condition carrying REmi on a row carrying no reference is REFUSED naming both, the length actually used is recorded beside the resolved state, and the resolver runs AFTER reference resolution.

Advanced

pyflightstream.workspace.flight_condition.DENSITY_KEY module-attribute

DENSITY_KEY = 'REmi'

pyflightstream.workspace.flight_condition.FlightConditionError

Bases: PyflightstreamError, ValueError

A flight condition does not determine exactly one flow state.

Catalogued (SRS FR-39) rather than a bare :class:ValueError, and raised BEFORE any script is emitted and before any solver exists, which is the whole point of stating a condition declaratively.

pyflightstream.workspace.flight_condition.PINNED_KEYS module-attribute

PINNED_KEYS = {
    "RHOkgm3": "density_kg_m3",
    "MUPas": "viscosity_pa_s",
    "ASMPS": "sonic_velocity_m_per_s",
    "TK": "temperature_k",
    "PPA": "pressure_pa",
}

pyflightstream.workspace.flight_condition.PINNED_STATE_TOLERANCE module-attribute

PINNED_STATE_TOLERANCE = 0.005

pyflightstream.workspace.flight_condition.ResolvedCondition dataclass

ResolvedCondition(
    velocity_m_per_s: float,
    density_kg_m3: float,
    temperature_k: float,
    viscosity_pa_s: float,
    pressure_pa: float,
    sonic_velocity_m_per_s: float,
    heat_capacity_ratio: float,
    mach: float,
    altitude_ft: float,
    delta_isa_c: float,
    density_source: str,
    reynolds: float | None = None,
    reference_length_m: float | None = None,
    stated: dict[str, float] = dict(),
    pinned: tuple[str, ...] = (),
    defaulted: dict[str, float] = dict(),
    defaults_origin: str | None = None,
    dropped_defaults: dict[str, float] = dict(),
)

Hold one flow state, and enough of its provenance to recompute it.

Every field carries its unit in its name. stated is the condition AS WRITTEN, kept so a reader can recompute the resolution rather than trust it (PFS-2027.05).

pyflightstream.workspace.flight_condition.canonical_condition_defaults

canonical_condition_defaults(
    defaults: Mapping[str, float] | None, origin: str
) -> dict[str, float]

Judge a defaults table's VOCABULARY, and answer in canonical keys.

Validate pins when reading the file, independently of the rows that later resolve a flight condition.

Parameters:

Name Type Description Default
defaults mapping or None

The table as written, keys in whatever case its writer typed.

required
origin str

Where it came from, named in every refusal, for example "setup 's001' (inputs/setups/s001.toml)".

required

Returns:

Type Description
dict

Canonical pin key to float, in the order written.

Raises:

Type Description
FlightConditionError

A key that states the POINT rather than the fluid, a key that is no pin at all, the same pin twice in two spellings, or a pin that is not positive.

pyflightstream.workspace.flight_condition.pinned_state_mismatch

pinned_state_mismatch(
    resolved: ResolvedCondition, *, pol: str
) -> str | None

Return the warning a fully pinned, inconsistent state earns, else None.

Checked when density, temperature and pressure are ALL pinned (by the row or by its setup's defaults), and when the pressure is pinned beside a density solved from a Reynolds number; a state with any of the three derived from the others satisfies p = rho R T by construction and is never checked. The one check the plan and the post both call, so the two cannot disagree. Nothing is refused: the pins are emitted as written.

Parameters:

Name Type Description Default
resolved ResolvedCondition

The resolved state of one point.

required
pol str

The POL (or simulation) the message names.

required

Returns:

Type Description
str or None

The message naming the three values, the gas constant and the relative mismatch, or None when the state is not fully pinned or agrees within :data:PINNED_STATE_TOLERANCE.

pyflightstream.workspace.flight_condition.resolve_flight_condition

resolve_flight_condition(
    stated: dict[str, float],
    *,
    pol: str,
    reference_length_m: float | None = None,
    defaults: Mapping[str, float] | None = None,
    defaults_origin: str | None = None,
) -> ResolvedCondition

Resolve a parsed flight condition into one flow state.

Parameters:

Name Type Description Default
stated dict

The parsed condition, canonical key to value, in the units the keys name. An empty mapping is not resolvable and is refused; deciding whether a row is ALLOWED to state none belongs to the caller, which knows whether the workflow needs a state.

required
pol str

The row's POL, named in every refusal so the reader knows which cell to edit.

required
reference_length_m float or None

The reference length the row's REF artifact carries. Required only when REmi is stated, and refused-for by name when it is stated and this is None.

None
defaults mapping or None

Pins the row's SETUP artifact supplies, applied to the keys the row does not state (PFS-2030.08). Only the five pins may appear; anything else is refused naming defaults_origin. A row stating ALTFT or dISA drops all setup pins. A row stating only REmi drops density and pressure defaults. Row-stated pins stay.

None
defaults_origin str or None

Where those defaults came from, in words a reader can act on, for example "setup s001". Named in every refusal about the table, and recorded on the resolved state. Required in practice whenever defaults is given: this module never reaches an artifact, so without it a refusal cannot say which file to edit.

None

Returns:

Type Description
ResolvedCondition

Raises:

Type Description
FlightConditionError

The set is under-determined, over-determined, states nothing at all, or states a Reynolds number with no reference length to measure it against.

AtmosphereError

The set is well formed and the atmosphere has no answer for it: an ALTFT outside the modelled range, or a dISA driving the temperature to or below absolute zero. Named here because a caller writing except FlightConditionError from this docstring alone would not catch a refusal the documentation elsewhere tells them to expect; except PyflightstreamError catches both.

Examples:

The first documented example: no altitude, so sea-level temperature, and the DENSITY is what moves to meet the Reynolds number.

>>> state = resolve_flight_condition(
...     {"MACH": 0.20, "REmi": 5.5}, pol="P1", reference_length_m=1.0
... )
>>> round(state.velocity_m_per_s, 4)
68.0588
>>> state.density_source
'solved-from-reynolds'

The second: an atmosphere point, with Reynolds derived.

>>> point = resolve_flight_condition(
...     {"TASmps": 68.08, "ALTFT": 10000, "dISA": 5},
...     pol="P1",
...     reference_length_m=1.0,
... )
>>> round(point.mach, 4)
0.2054
>>> point.density_source
'atmosphere'