Skip to content

pyflightstream.workspace.actuator_profiles (provisional)

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

Actuator-disc radial thrust profiles of inputs/profiles/, built from loads or a shape.

Pipeline role: prepares an INPUT (FR-347). A matrix row loads an actuator disc either by its net thrust (ACTUATOR_THRUST, the solver's native ELLIPTICAL model) or by a radial profile (PROFILE: <stem>, the CUSTOM model), a file of the workspace's inputs/profiles/ named by its stem. This module writes that file, the way :mod:pyflightstream.workspace.fields writes a custom free stream: <stem>.csv beside a provenance record <stem>.provenance.json, previewing until applied.

THE FORM is the one the run's own copy of a profile is put in (:func:~pyflightstream.cases.workflows.read_actuator_profile, RPT-070): rows r,F, r the radius in metres and F the force per unit span in newtons per metre PER BLADE (the disc block states its blades, and the solver reads the file per blade), no header, no count line and no final newline. Every text written is read back through the same renderer the run uses, so a file this module writes is a file the plan accepts.

THREE SHAPES:

  • SECTIONS, from a POL's written sections: the sectional loads table a post writes (sections/<point>_sloads_<family>.csv), the thrust per unit span read as -Fx by default (the axial force of a blade whose rotor turns about x and pushes towards -x; Fx, -Fz or Fz are stated otherwise), a zero from the axis to the hub and a zero at the tip. The table of an unsteady run that averaged its last revolutions is one set of stations; a table holding several steps is averaged over its last K steps, stated. A station whose thrust is negative is set to zero, and the count is recorded.
  • UNI, a uniform pressure jump: F = c r from the hub to the tip.
  • BP, the Betz-Prandtl shape: F = c r f_tip f_hub with the Prandtl factors f = (2/pi) acos(exp(-B d / (2 r_ref sin(phi)))) for B blades, d the distance to the tip (r_ref = r) or to the hub (r_ref = r_hub), and the helix angle tan(phi) = J R / (pi r).

The ELLIPTICAL model is native in the solver and needs no file: a row states ACTUATOR_THRUST and nothing here is involved. Measured on 26.124 (RPT-137), it placed about 0.62 of the thrust asked in the wake, and the CUSTOM profiles 0.95 to 1.04 of it.

THE SCALE: every shape is multiplied by the one constant that makes B * integral(F dr) equal the target thrust, the integral taken by the trapezoid rule over the rows written. The target is a thrust in newtons or a thrust coefficient in the propeller convention CT = T / (rho n^2 D^4) (n in rev/s, D twice the tip radius), never both. The integral of the written text is taken again and stated in the record, and a text whose integral misses the target by more than :data:INTEGRAL_TOLERANCE (relative) is refused.

A disc of wake type RELAXED ignores a custom profile (RPT-137); the plan warns on a row that names one (FR-332), and pyfs-workspace profile says so when the disc it reads is RELAXED. pyfs-workspace profile is this module's command line.

Examples:

>>> from pyflightstream.workspace.actuator_profiles import (
...     DiscGeometry, blade_thrust, scale_profile, uniform_profile)
>>> disc = DiscGeometry(tip_radius_m=0.5, hub_radius_m=0.1, blades=3)
>>> shape = uniform_profile(disc, stations=5)
>>> shape.rows[0], shape.rows[-1]
((0.0, 0.0), (0.5, 0.5))
>>> scaled, _ = scale_profile(shape, blades=3, thrust_n=120.0)
>>> round(blade_thrust(scaled, blades=3), 9)
120.0

Used in the guides

pyflightstream.workspace.actuator_profiles.DiscGeometry dataclass

DiscGeometry(
    tip_radius_m: float, hub_radius_m: float, blades: int
)

The annulus a profile is built over and the blade count it is read per.

Attributes:

Name Type Description
tip_radius_m float

The disc's outer radius, in m.

hub_radius_m float

The disc's inner radius, in m, 0 <= hub < tip.

blades int

The blade count the file's force per unit span is read per.

Raises:

Type Description
WorkspaceError

A hub that is not inside the tip, or a blade count that is not a whole number of at least one.

Examples:

>>> DiscGeometry(tip_radius_m=0.5, hub_radius_m=0.1, blades=3).blades
3

pyflightstream.workspace.actuator_profiles.blade_thrust

blade_thrust(
    profile: RadialProfile, *, blades: int
) -> float

Return B * integral(F dr) by the trapezoid rule over the rows, in N.

Parameters:

Name Type Description Default
profile RadialProfile

The rows.

required
blades int

The blade count B.

required

Returns:

Type Description
float

The disc's thrust the rows state.

Examples:

>>> blade_thrust(RadialProfile(((0.0, 0.0), (1.0, 2.0))), blades=3)
3.0

pyflightstream.workspace.actuator_profiles.scale_profile

scale_profile(
    profile: RadialProfile, *, blades: int, thrust_n: float
) -> tuple[RadialProfile, float]

Return the profile scaled so that B * integral(F dr) is thrust_n, and the scale.

Parameters:

Name Type Description Default
profile RadialProfile

The shape.

required
blades int

The blade count.

required
thrust_n float

The target thrust, in N.

required

Returns:

Type Description
tuple of (RadialProfile, float)

The scaled profile and the factor applied.

Raises:

Type Description
WorkspaceError

The shape carries no positive thrust to scale.

Examples:

>>> scale_profile(RadialProfile(((0.0, 0.0), (1.0, 2.0))), blades=1, thrust_n=2.0)[1]
2.0

pyflightstream.workspace.actuator_profiles.uniform_profile

uniform_profile(
    disc: DiscGeometry, *, stations: int = DEFAULT_STATIONS
) -> RadialProfile

Return the uniform pressure jump: F = r from the hub to the tip, not yet scaled.

A uniform jump dp loads each blade with F = dp 2 pi r / B, a force per unit span proportional to the radius. Inside the hub the profile is zero: a row (0, 0) and one just inside the hub radius, at hub - 1e-4 m as in the profiles RPT-137 summarises, so the step at the hub is between two radii.

Parameters:

Name Type Description Default
disc DiscGeometry

The disc.

required
stations int

The stations from the hub to the tip, both included.

DEFAULT_STATIONS

Returns:

Type Description
RadialProfile

The shape.

Raises:

Type Description
WorkspaceError

Fewer than two stations.

Examples:

>>> uniform_profile(DiscGeometry(1.0, 0.0, 2), stations=3).rows
((0.0, 0.0), (0.5, 0.5), (1.0, 1.0))

Advanced

pyflightstream.workspace.actuator_profiles.DEFAULT_STATIONS module-attribute

DEFAULT_STATIONS = 61

pyflightstream.workspace.actuator_profiles.INTEGRAL_TOLERANCE module-attribute

INTEGRAL_TOLERANCE = 1e-09

pyflightstream.workspace.actuator_profiles.PROFILE_DIR module-attribute

PROFILE_DIR = 'profiles'

pyflightstream.workspace.actuator_profiles.PROFILE_PROVENANCE_SCHEMA module-attribute

PROFILE_PROVENANCE_SCHEMA = 'pyfs-actuator-profile/1'

pyflightstream.workspace.actuator_profiles.PROFILE_SHAPES module-attribute

PROFILE_SHAPES = ('SECTIONS', 'UNI', 'BP')

pyflightstream.workspace.actuator_profiles.PROFILE_SUFFIX module-attribute

PROFILE_SUFFIX = '.csv'

pyflightstream.workspace.actuator_profiles.ProfileWrite dataclass

ProfileWrite(
    target: Path,
    sidecar: Path,
    profile: RadialProfile,
    provenance: dict[str, object],
    applied: bool,
    overwritten: tuple[Path, ...],
)

What :func:write_profile wrote, or would write.

Attributes:

Name Type Description
target Path

inputs/profiles/<stem>.csv.

sidecar Path

inputs/profiles/<stem>.provenance.json.

profile RadialProfile

The scaled profile the file holds.

provenance dict

The record's content.

applied bool

Whether the files were written.

overwritten tuple of Path

The files a write replaced.

pyflightstream.workspace.actuator_profiles.RadialProfile dataclass

RadialProfile(rows: tuple[tuple[float, float], ...])

A radial thrust profile: rows (r, F), r in m and F in N/m per blade.

Attributes:

Name Type Description
rows tuple of (float, float)

The rows in increasing radius.

pyflightstream.workspace.actuator_profiles.SectionLoads dataclass

SectionLoads(
    stations: tuple[tuple[float, float], ...],
    steps: tuple[int | None, ...],
    clipped: int,
    component: str,
    source: Path,
)

The thrust per unit span a sectional loads table states at its stations.

Attributes:

Name Type Description
stations tuple of (float, float)

(r, thrust per unit span), r in m and the thrust in N/m, in increasing radius, a negative thrust set to zero.

steps tuple

The steps averaged, None for a table that states none.

clipped int

The stations whose thrust was negative and was set to zero.

component str

The column, with its sign, read as the thrust.

source Path

The table read.

pyflightstream.workspace.actuator_profiles.THRUST_COMPONENTS module-attribute

THRUST_COMPONENTS = ('-Fx', 'Fx', '-Fz', 'Fz')

pyflightstream.workspace.actuator_profiles.ThrustTarget dataclass

ThrustTarget(
    thrust_n: float,
    basis: str,
    parameters: dict[str, float],
)

The thrust a profile is scaled to, and how it was stated.

Attributes:

Name Type Description
thrust_n float

The disc's net thrust, in N.

basis str

"thrust" when stated in newtons, "ct" when worked out from a thrust coefficient.

parameters dict

What was stated: the thrust, or the coefficient with the density, the speed and the diameter it was worked out with.

pyflightstream.workspace.actuator_profiles.betz_prandtl_profile

betz_prandtl_profile(
    disc: DiscGeometry,
    *,
    advance_ratio: float,
    stations: int = DEFAULT_STATIONS,
) -> RadialProfile

Return the Betz-Prandtl shape F = r f_tip f_hub, not yet scaled.

f_tip and f_hub are Prandtl's factors for B blades, at the distance to the tip over r and to the hub over r_hub, with the helix angle tan(phi) = J R / (pi r); both are zero where their distance is, so the shape is zero at the hub and at the tip. A disc whose hub is the axis has no hub factor.

Parameters:

Name Type Description Default
disc DiscGeometry

The disc.

required
advance_ratio float

The advance ratio J = V / (n D), positive.

required
stations int

The stations from the hub to the tip, both included.

DEFAULT_STATIONS

Returns:

Type Description
RadialProfile

The shape.

Raises:

Type Description
WorkspaceError

An advance ratio that is not a finite positive number, or fewer than two stations.

Examples:

>>> shape = betz_prandtl_profile(DiscGeometry(1.0, 0.2, 4), advance_ratio=1.0, stations=5)
>>> shape.rows[2], shape.rows[-1]
((0.2, 0.0), (1.0, 0.0))

pyflightstream.workspace.actuator_profiles.disc_from_reference

disc_from_reference(
    root: str | Path, reference: str, disc: str
) -> tuple[DiscGeometry, dict[str, object]]

Read a disc's annulus and blade count from a reference of the workspace.

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
reference str

The reference id, the stem of inputs/references/<id>.toml.

required
disc str

The name of the reference's kind = "actuator" block.

required

Returns:

Type Description
tuple of (DiscGeometry, dict)

The disc, and what the record states of it: the reference, the disc, its wake type and the reference file with its sha256.

Raises:

Type Description
InputArtifactError

The reference does not exist or does not validate.

WorkspaceError

The reference declares no such disc, the disc states no blades, or its profile_units are not NEWTONS.

Examples:

>>> import tempfile
>>> from pathlib import Path
>>> root = Path(tempfile.mkdtemp())
>>> (root / "inputs" / "references").mkdir(parents=True)
>>> _ = (root / "inputs" / "references" / "r001.toml").write_text(
...     'area_m2 = 1.0\nchord_m = 1.0\nspan_m = 1.0\n\n[PROP]\nkind = "actuator"\n'
...     'frame = "MRP"\naxis = "X"\ntip_radius_m = 0.5\nhub_radius_m = 0.1\nblades = 3\n')
>>> disc_from_reference(root, "r001", "PROP")[0]
DiscGeometry(tip_radius_m=0.5, hub_radius_m=0.1, blades=3)

pyflightstream.workspace.actuator_profiles.find_pol_sections

find_pol_sections(
    root: str | Path, pol: str, *, family: str = "Blade1"
) -> Path

Return the one sectional loads table the post wrote for a POL and a family.

The post records each table it writes in post/<matrix>/products.json with its POL and its families; one level of post/ is read, and no link is followed.

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
pol str

The POL.

required
family str

The family of the sections distribution, Blade1 by default.

'Blade1'

Returns:

Type Description
Path

The table, post/<matrix>/sections/<point>_sloads_<family>.csv.

Raises:

Type Description
WorkspaceError

No table, or more than one (several points or matrices), naming each.

Examples:

>>> import json, tempfile
>>> from pathlib import Path
>>> root = Path(tempfile.mkdtemp())
>>> (root / "post" / "m" / "sections").mkdir(parents=True)
>>> _ = (root / "post" / "m" / "sections" / "P7-A_sloads_Blade1.csv").write_text("x")
>>> _ = (root / "post" / "m" / "products.json").write_text(json.dumps({"products": {
...     "sections/P7-A_sloads_Blade1.csv": {"sim_id": "7", "families": ["Blade1"]}}}))
>>> find_pol_sections(root, "7").name
'P7-A_sloads_Blade1.csv'

pyflightstream.workspace.actuator_profiles.read_section_loads

read_section_loads(
    path: str | Path,
    *,
    component: str = "-Fx",
    last: int | None = None,
) -> SectionLoads

Read the thrust per unit span of a sectional loads table the post wrote.

The radius is the Offset column, in m; the thrust is component (-Fx by default), in N/m. A table holding one step (or none stated) is read as it is; a table holding several is averaged over its last steps, station by station, and every averaged step states the same stations. A negative thrust is set to zero and counted.

Parameters:

Name Type Description Default
path str or Path

The table, sections/<point>_sloads_<family>.csv.

required
component str

One of :data:THRUST_COMPONENTS.

'-Fx'
last int

The steps averaged, counted from the last; required when the table holds several.

None

Returns:

Type Description
SectionLoads

The stations in increasing radius.

Raises:

Type Description
WorkspaceError

The table cannot be read; it has no Offset or no such column; it holds several clockings, or several steps and no last, or fewer steps than last; two rows of one step share a radius; the steps averaged state different stations; a value is not a finite number.

Examples:

>>> import tempfile
>>> from pathlib import Path
>>> table = Path(tempfile.mkdtemp()) / "P1_sloads_Blade1.csv"
>>> _ = table.write_text("POL,STEP,Offset,Fx\n1,4,0.3,-2.0\n1,4,0.2,-1.0\n1,4,0.4,0.5\n")
>>> loads = read_section_loads(table)
>>> loads.stations, loads.clipped
(((0.2, 1.0), (0.3, 2.0), (0.4, 0.0)), 1)

pyflightstream.workspace.actuator_profiles.render_profile

render_profile(profile: RadialProfile) -> str

Return the file text of a profile: rows r,F, no header and no final newline.

Each number is written in its shortest exact form, so the file holds the profile's values to the last bit and its integral is the one checked.

Parameters:

Name Type Description Default
profile RadialProfile

The rows.

required

Returns:

Type Description
str

The text, newline separated and NOT newline terminated (RPT-070).

Raises:

Type Description
WorkspaceError

The text is not one the run's profile reader takes as it is.

Examples:

>>> print(render_profile(RadialProfile(((0.0, 0.0), (0.5, 12.5), (1.0, 0.0)))))
0.0,0.0
0.5,12.5
1.0,0.0

pyflightstream.workspace.actuator_profiles.sections_profile

sections_profile(
    loads: SectionLoads, disc: DiscGeometry
) -> RadialProfile

Return the profile of a table's stations: a zero to the hub, the stations, a zero at the tip.

Parameters:

Name Type Description Default
loads SectionLoads

The stations, from :func:read_section_loads.

required
disc DiscGeometry

The disc the profile is for.

required

Returns:

Type Description
RadialProfile

(0, 0), (hub - 1e-4 m, 0) when that lies off the axis, the stations, then (tip, 0); not yet scaled.

Raises:

Type Description
WorkspaceError

A station at or inside the hub radius, or at or beyond the tip radius.

Examples:

>>> from pathlib import Path
>>> given = SectionLoads(((0.2, 1.0), (0.4, 2.0)), (None,), 0, "-Fx", Path("t.csv"))
>>> sections_profile(given, DiscGeometry(0.5, 0.1, 3)).rows
((0.0, 0.0), (0.0999, 0.0), (0.2, 1.0), (0.4, 2.0), (0.5, 0.0))

pyflightstream.workspace.actuator_profiles.thrust_target

thrust_target(
    *,
    tip_radius_m: float,
    thrust_n: float | None = None,
    ct: float | None = None,
    rho_kg_m3: float | None = None,
    rpm: float | None = None,
) -> ThrustTarget

Return the thrust a profile is scaled to, stated in newtons or by a CT.

Parameters:

Name Type Description Default
tip_radius_m float

The disc's tip radius, in m; the diameter of the CT is twice it.

required
thrust_n float

The net thrust, in N.

None
ct float

The thrust coefficient T / (rho n^2 D^4), the propeller convention.

None
rho_kg_m3 float

The density of the CT, in kg/m^3; required with ct.

None
rpm float

The speed of the CT, in rev/min; required with ct.

None

Returns:

Type Description
ThrustTarget

The thrust in N and what was stated.

Raises:

Type Description
WorkspaceError

Both or neither of thrust_n and ct stated; a CT without its density and speed, or a density or speed beside a thrust; a value that is not a finite positive number.

Examples:

>>> thrust_target(tip_radius_m=0.5, thrust_n=120.0).thrust_n
120.0
>>> round(thrust_target(tip_radius_m=0.5, ct=0.1, rho_kg_m3=1.2, rpm=3000.0).thrust_n, 6)
300.0

pyflightstream.workspace.actuator_profiles.write_profile

write_profile(
    root: str | Path,
    stem: str,
    profile: RadialProfile,
    *,
    disc: DiscGeometry,
    target: ThrustTarget,
    shape: str,
    parameters: Mapping[str, object],
    inputs: Sequence[Mapping[str, object]] = (),
    apply: bool = False,
    overwrite: bool = False,
) -> ProfileWrite

Scale a shape to its target and write it into <root>/inputs/profiles/, or preview it.

The file is <stem>.csv, the form the run's copy of a profile takes; the record <stem>.provenance.json names the shape, its parameters, the disc, the target, the scale, the integral of the written rows, every input with its sha256 and the written file's own sha256. Without apply nothing is written and the same refusals fire.

Parameters:

Name Type Description Default
root str or Path

The workspace root.

required
stem str

The name a row's PROFILE cites, a plain name.

required
profile RadialProfile

The shape, not yet scaled.

required
disc DiscGeometry

The disc; its blade count is the B of the integral.

required
target ThrustTarget

The thrust the profile is scaled to.

required
shape str

One of :data:PROFILE_SHAPES, recorded.

required
parameters mapping of str to object

The shape's parameters, recorded.

required
inputs sequence of mapping

The input files, each {"path": ..., "sha256": ...}, recorded.

()
apply bool

Write the files; without it nothing is written.

False
overwrite bool

Replace a file or record that already exists instead of refusing it.

False

Returns:

Type Description
ProfileWrite

The paths, the scaled profile, the record, whether it was written and the files it replaced.

Raises:

Type Description
WorkspaceError

The stem is not a plain name; the folder holds another file of that stem; the file or its record exists and overwrite is not set; the shape carries no positive thrust; the written integral misses.

Examples:

>>> import tempfile
>>> disc = DiscGeometry(0.5, 0.1, 3)
>>> done = write_profile(
...     tempfile.mkdtemp(), "prop_uni", uniform_profile(disc, stations=5), disc=disc,
...     target=thrust_target(tip_radius_m=0.5, thrust_n=120.0), shape="UNI",
...     parameters={"stations": 5}, apply=True)
>>> done.target.name, done.provenance["integral"]["relative_miss"] < 1e-12
('prop_uni.csv', True)