pyflightstream.cases.freestream (stable)¶
Generated from the docstrings at build time: every one of the 7 names in the __all__ of pyflightstream.cases.freestream has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
Prepare explicitly declared custom fields for the solver's measured file units.
Advanced¶
pyflightstream.cases.freestream.MEASURED_FIELD_UNITS
module-attribute
¶
MEASURED_FIELD_UNITS = ('METER', 'MILLIMETER')
pyflightstream.cases.freestream.PreparedField
dataclass
¶
PreparedField(
path: str,
payload: bytes | None,
provenance: dict[str, object],
)
Effective solver input and the separate source/effective byte identities.
pyflightstream.cases.freestream.field_rows_in_metres
¶
field_rows_in_metres(
path: Path,
*,
form: str,
source_units: str | None,
native_unit: str | None,
data: bytes | None = None,
) -> tuple[str | None, list[list[float]]]
Return a custom field's rows in metres and metres per second (qsteady_rotor).
SI and an undeclared file are read as the manual states the form, in
metres and metres per second; NATIVE is converted from the simulation's
measured unit. An undeclared file on a simulation whose unit is not the
metre is refused, because nothing then says which of the two it is written
in, and the rotational velocity the quasi-steady rotor removes from it,
composing the relative free stream the fixed blades see, is in metres per
second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The custom field file. |
required |
form
|
str
|
The field's form, |
required |
source_units
|
str or None
|
The row's |
required |
native_unit
|
str or None
|
The simulation's measured length unit, |
required |
data
|
bytes
|
The file's bytes where the caller already holds them; see :func: |
None
|
Returns:
| Type | Description |
|---|---|
tuple of (str or None, list of list of float)
|
The header line (None for an unstructured field) and the rows, positions in metres and velocities in metres per second. |
Raises:
| Type | Description |
|---|---|
CampaignConfigError
|
If a NATIVE field's simulation unit is neither the metre nor the millimetre, an undeclared
field sits on a simulation not in metres, or :func: |
pyflightstream.cases.freestream.prepare_field
¶
prepare_field(
path: Path,
*,
form: str,
source_units: str | None,
native_unit: str | None,
) -> PreparedField
Convert an explicit SI declaration only; undeclared inputs retain their bytes.
The six file columns carry global XYZ and velocity components. In the measured METER/MILLIMETER custom-file boundary, all six use native length units (seconds are unchanged). Multiplication changes representation only. It never rotates vectors or coordinates, and never writes the source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The custom field file. |
required |
form
|
str
|
The field's form, |
required |
source_units
|
str or None
|
The row's |
required |
native_unit
|
str or None
|
The simulation's measured length unit, |
required |
Returns:
| Type | Description |
|---|---|
PreparedField
|
The file the solver reads (the source itself where nothing is converted, otherwise a converted copy and its bytes) and the provenance of both. |
Raises:
| Type | Description |
|---|---|
CampaignConfigError
|
If |
Examples:
>>> import tempfile
>>> from pathlib import Path
>>> path = Path(tempfile.mkdtemp()) / "field.dat"
>>> with path.open("w", encoding="utf-8") as stream:
... print("0 0 0 10 0 0", file=stream)
... print("1 0 0 10 0 0", file=stream)
>>> kept = prepare_field(path, form="UNSTRUCTURED", source_units=None,
... native_unit="MILLIMETER")
>>> kept.path == str(path), kept.payload
(True, None)
>>> converted = prepare_field(path, form="UNSTRUCTURED", source_units="SI",
... native_unit="MILLIMETER")
>>> converted.payload.decode().splitlines()
['0 0 0 10000 0 0', '1000 0 0 10000 0 0']
pyflightstream.cases.freestream.prepare_rotating_field
¶
prepare_rotating_field(
path: Path,
*,
form: str,
source_units: str | None,
native_unit: str | None,
hub_m: tuple[float, float, float],
axis: tuple[float, float, float],
omega_rad_s: float,
) -> PreparedField
Write the field a blade held still meets: the user's inflow less the rotational velocity.
The user's file is the TOTAL velocity of the air at the disc, in the global
frame, and this composes the RELATIVE free stream the fixed blades see: the
rotational velocity of each point is removed, never added. A blade turning
at omega (right-hand about the unit axis, signed by the rotor's
hand) moves at omega axis x (p - hub), so the air relative to it, which
is what a blade held still must meet, is::
v_rel(p) = v(p) - omega axis x (p - hub)
Computed in metres and metres per second and written in the simulation's
unit, as :func:prepare_field writes an SI field. The source is never
written; the effective file is a new one named by its own digest, and its
provenance says what was added. The rotation is the free stream's meaning
applied to the file (the air seen from the turning blade); no licensed run
has compared this field with SET_FREESTREAM ROTATION yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The custom field file. |
required |
form
|
str
|
The field's form, |
required |
source_units
|
str or None
|
The row's |
required |
native_unit
|
str or None
|
The simulation's measured length unit, |
required |
hub_m
|
tuple of float
|
A point of the shaft, (x, y, z) in metres, in the field's frame. |
required |
axis
|
tuple of float
|
The shaft's direction, a unit vector in the field's frame. |
required |
omega_rad_s
|
float
|
The rotor's angular speed in radians per second, right-hand about |
required |
Returns:
| Type | Description |
|---|---|
PreparedField
|
The new field file named by its own digest, its bytes in the simulation's unit, and its provenance. |
Raises:
| Type | Description |
|---|---|
CampaignConfigError
|
If |
pyflightstream.cases.freestream.read_field_rows
¶
read_field_rows(
path: Path, *, form: str, data: bytes | None = None
) -> tuple[str | None, list[list[float]]]
Return a custom field's header line (STRUCTURED) and its rows of six numbers.
The form was checked by the builder's reader before this is asked; this reads the numbers and refuses only what would make them unusable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The custom field file. |
required |
form
|
str
|
The field's form, |
required |
data
|
bytes
|
The file's bytes where the caller already holds them, so one read serves both the rows
and a hash of them; read from |
None
|
Returns:
| Type | Description |
|---|---|
tuple of (str or None, list of list of float)
|
The header line (None for an unstructured field) and the rows, six numbers each, as written. |
Raises:
| Type | Description |
|---|---|
CampaignConfigError
|
If the form is unknown, the file is not UTF-8 text, a structured field has no header, the file holds no row, a value is not numeric, or a row is not six finite columns. |
pyflightstream.cases.freestream.require_measured_unit
¶
require_measured_unit(native_unit: str | None) -> str
Return the simulation's unit when a custom field is measured in it, else refuse.
The one home of the whitelist (PFS-2119.002): :func:prepare_field,
:func:field_rows_in_metres and :func:prepare_rotating_field all write or
read a field in the simulation's unit, and the solver's reading of a custom
file is measured for the metre and the millimetre only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_unit
|
str or None
|
The simulation's length unit, or None where the caller states none. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The unit, |
Raises:
| Type | Description |
|---|---|
CampaignConfigError
|
If the unit is neither |
Examples:
>>> require_measured_unit("MILLIMETER")
'MILLIMETER'