Skip to content

pyflightstream.results.surface (stable)

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

The surface solution: read from the solver's VTK, written as Tecplot (G45).

Pipeline role: the ONE route to a Tecplot surface of a campaign point. The script exports the surface as VTK (EXPORT_SOLVER_ANALYSIS_VTK) and this module writes the .dat from it, at the name the solver's own Tecplot had. The time-averaged surface of G25 is written by the same writer.

WHAT THE VTK IS, measured on 26.124 (RPT-074). Legacy ASCII polydata: POINTS n, POLYGONS m, a POINT_DATA section repeating the coordinates as the scalars X, Y and Z, and a CELL_DATA section of one value per polygon for every variable the export selected, nineteen of them in its all-variables form. The points and the velocity components Vx, Vy, Vz are written in the ANALYSIS LOADS FRAME, the frame SET_SOLVER_ANALYSIS_LOADS_FRAME names: p' = R (p - o), R's rows the frame's axes in the reference frame and o its origin. Scalars (Cp, speed) do not change with the frame.

THE VELOCITY IS WRITTEN AS A POINT IS, ORIGIN INCLUDED: v' = R (v - o). Measured on RPT-074's recorded files (frame 2 at x = 9.152 m): put the origin back, v = R^T v' + o, and the norm of the three components equals the panel's own Velocity to 7e-15 at the median, on 6867 of 7167 panels of both the plain and the turned frame; turn them back as a vector alone and it misses by 9.0 m/s at the median, the origin's 9.152 m read as a speed. So the components are undone exactly as the points are. The solver's own Tecplot is written in the reference frame, per NODE, by a cell-to-node rule of the solver's that is neither a plain nor an area-weighted mean.

WHAT THE TRANSLATION WRITES. One FEPolygon zone in BLOCK packing: the nodes as X, Y, Z in the REFERENCE frame, then every cell variable of the VTK CELL-CENTRED (VARLOCATION), exactly the values the solver computed per panel, the velocity components written back in the reference frame and nothing interpolated to a node. Each polygon's edges are its faces, with the polygon on the left and no neighbour on the right, which is how the solver writes its own zone. Singularity_strength, the panel strength the solver's Tecplot carries, is not in the VTK. A same-step native auxiliary export provides nodal values after a unique coordinate and topology match; the run exports it only where the row's pproc sets singularity_strength = true. A run without it, by that key or by its release, declares this variable not carried. The file names its source VTK and that file's sha256 in its DATASETAUXDATA records.

Nothing here decides WHICH frame: the caller passes the loads frame the script itself set (:class:SurfaceFrame), because the package emitted the frames and the loads-frame command and so knows R and o.

Advanced

pyflightstream.results.surface.NOT_CARRIED_BY_THE_VTK module-attribute

NOT_CARRIED_BY_THE_VTK: tuple[str, ...] = (
    "Singularity_strength",
)

pyflightstream.results.surface.REFERENCE_FRAME module-attribute

REFERENCE_FRAME = SurfaceFrame(
    origin=(0.0, 0.0, 0.0),
    axes=(
        (1.0, 0.0, 0.0),
        (0.0, 1.0, 0.0),
        (0.0, 0.0, 1.0),
    ),
    index=1,
)

pyflightstream.results.surface.SurfaceFrame dataclass

SurfaceFrame(
    origin: _Vector,
    axes: tuple[_Vector, _Vector, _Vector],
    index: int = 1,
)

Where the frame a VTK was written in stands in the reference frame.

Attributes:

Name Type Description
origin tuple of float

The frame's origin in the reference frame, in the simulation's length unit, as the script's EDIT_COORDINATE_SYSTEM placed it.

axes tuple of tuple of float

The frame's X, Y and Z axes as unit vectors in the reference frame, one per row: the rows of R in p' = R (p - o).

index int

The frame's index in the script; 1 is the reference frame.

Examples:

>>> import numpy as np
>>> turned = SurfaceFrame(origin=(9.152, 0.0, 0.0),
...     axes=((0.0, 1.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, 1.0)), index=2)
>>> turned.to_reference(np.array([[-1.0, -0.5, 0.2]])).round(3).tolist()
[[9.652, -1.0, 0.2]]

rotation property

rotation: ndarray

The matrix R whose rows are the frame's axes, shape (3, 3).

turns property

turns: bool

Whether the frame's axes differ from the reference frame's.

case property

case: str

Which kind of placement this frame is, for the record of what was verified.

reference (no turn, no shift), translation (no turn), z-turn or z-turn and translation (a turn about the z axis alone), or tilted (any turn that moves the z axis). RPT-074 measured the second to fourth and none other.

verified property

verified: bool

Whether this frame's case is one RPT-074 measured (everything but tilted).

to_reference

to_reference(points: ndarray) -> np.ndarray

Return rows written in this frame as rows of the reference frame.

p = R^T p' + o, the inverse of how the solver wrote them. The solver writes the velocity components the same way, origin included, so they are undone by this too (the module's docstring gives the measurement).

record

record() -> dict[str, object]

Return the frame as a run record states it.

from_record classmethod

from_record(stated: Mapping[str, object]) -> SurfaceFrame

Rebuild a frame from :meth:record's mapping.

Raises:

Type Description
MalformedOutputError

If the mapping states no origin or no axes (a frame whose placement the script did not know cannot undo anything), or a value of it is not a number.

describe

describe() -> str

Return one line naming the frame, its origin and its axes.

pyflightstream.results.surface.VELOCITY_COMPONENTS module-attribute

VELOCITY_COMPONENTS: tuple[str, str, str] = (
    "Vx",
    "Vy",
    "Vz",
)

pyflightstream.results.surface.VtkSurface dataclass

VtkSurface(
    points: ndarray,
    offsets: ndarray,
    connectivity: ndarray,
    point_data: dict[str, ndarray] = dict(),
    cell_data: dict[str, ndarray] = dict(),
    title: str = "",
    field_data: dict[str, float | str] = dict(),
)

One surface solution: its nodes, its polygons and their values.

Attributes:

Name Type Description
points ndarray

Node coordinates, shape (n_points, 3), in the simulation's length unit and in whatever frame the file was written in.

offsets ndarray

Where each polygon starts in connectivity, shape (n_cells + 1,); polygon i is connectivity[offsets[i]:offsets[i + 1]].

connectivity ndarray

The 0-based node indices of every polygon, one after another.

point_data dict of str to numpy.ndarray

One value per node for each point scalar, in the file's order.

cell_data dict of str to numpy.ndarray

One value per polygon for each cell scalar, in the file's order.

title str

The file's title line.

field_data dict of str to float or str

The dataset's FIELD arrays of one value each, by name: a number, NaN where the file writes nan, or a text (the run block the package writes into an averaged surface, design of the post outputs section 3).

Examples:

>>> import numpy as np
>>> quad = VtkSurface(
...     points=np.array([[0.0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]),
...     offsets=np.array([0, 4]),
...     connectivity=np.array([0, 1, 2, 3]),
...     cell_data={"Cp": np.array([0.25])},
... )
>>> quad.n_points, quad.n_cells
(4, 1)

n_points property

n_points: int

Number of nodes.

n_cells property

n_cells: int

Number of polygons.

topology_differs

topology_differs(other: VtkSurface) -> str | None

Say how other's nodes and polygons differ from these, or None when they agree.

One topology is one node count, one polygon count and the same node indices around every polygon; where the nodes stand is not part of it.

pyflightstream.results.surface.read_vtk_surface

read_vtk_surface(source: str | Path) -> VtkSurface

Read a surface solution the solver exported as VTK legacy ASCII polydata.

Parameters:

Name Type Description Default
source str or Path

The .vtk file EXPORT_SOLVER_ANALYSIS_VTK wrote.

required

Returns:

Type Description
VtkSurface

Its nodes, polygons and scalars, in the frame the file was written in.

Raises:

Type Description
MalformedOutputError

If the file is not ASCII polydata of polygons carrying one-component scalars, which is what the solver's surface export writes (RPT-074), or if a count, an index or a value contradicts the file.

IncompleteOutputError

If the file ends inside a block it declared.

Examples:

>>> import pathlib, tempfile
>>> text = (
...     "# vtk DataFile Version 3.0\nFlightStream vtk output\nASCII\nDATASET POLYDATA\n"
...     "POINTS 3 float\n0 0 0\n1 0 0\n0 1 0\nPOLYGONS 1 4\n3 0 1 2\n"
...     "CELL_DATA 1\nSCALARS Cp_reference FLOAT\nLOOKUP_TABLE default\n-0.5\n"
... )
>>> path = pathlib.Path(tempfile.mkdtemp()) / "solution.vtk"
>>> _ = path.write_text(text)
>>> surface = read_vtk_surface(path)
>>> surface.n_points, surface.n_cells, surface.cell_data["Cp_reference"].tolist()
(3, 1, [-0.5])

pyflightstream.results.surface.stamped_translation

stamped_translation(
    vtk: str, dat: str, step: int
) -> tuple[str, str]

Return the names one step's VTK and its Tecplot carry (RPT-041 finding 3).

Parameters:

Name Type Description Default
vtk str

The VTK file name.

required
dat str

The Tecplot file name.

required
step int

The solver step the files belong to.

required

Returns:

Type Description
tuple of (str, str)

The VTK and Tecplot names with _iteration=<step> before the suffix.

Examples:

>>> stamped_translation("P1-AL+000.vtk", "P1-AL+000.dat", 37)
('P1-AL+000_iteration=37.vtk', 'P1-AL+000_iteration=37.dat')

pyflightstream.results.surface.surface_in_reference

surface_in_reference(
    surface: VtkSurface, frame: SurfaceFrame
) -> VtkSurface

Return the surface with its nodes and velocity components in the reference frame.

Parameters:

Name Type Description Default
surface VtkSurface

A surface as the solver wrote it, in the analysis loads frame.

required
frame SurfaceFrame

That frame, as the script placed it.

required

Returns:

Type Description
VtkSurface

The same polygons, the nodes turned and moved back, the point scalars X, Y, Z written as those nodes, and Vx, Vy, Vz undone as the solver wrote them, as a point is; every other value as the solver computed it.

Raises:

Type Description
MalformedOutputError

If the frame is not the reference frame and the surface carries some of the velocity components and not all three: each component was written from all three, so one alone cannot be undone.

pyflightstream.results.surface.translate_surface_exports

translate_surface_exports(
    folder: str | Path,
    translations: Sequence[Mapping[str, object]],
    *,
    frame: Mapping[str, object] | None = None,
) -> list[dict[str, object]]

Translate one point's surface batch and record elapsed time and problems.

Parameters:

Name Type Description Default
folder str or Path

Where the solver wrote the VTK files, the point's working directory.

required
translations sequence of mapping

What the script recorded: vtk, dat and frame for each.

required
frame mapping

The frame to use where a translation states no placement.

None

Returns:

Type Description
list of dict

Each translation as recorded, with written, the .dat names written or found written, and problems, one sentence per file that could not be written.

pyflightstream.results.surface.translate_vtk_surface

translate_vtk_surface(
    vtk: str | Path,
    dat: str | Path,
    *,
    frame: SurfaceFrame,
    overwrite: bool = False,
    native_tecplot: str | Path | None = None,
    periodic_copies: int | None = None,
) -> dict[str, object]

Write exact VTK cell values plus optional matched native nodal strength.

Native strength is read from the same point/step's auxiliary Tecplot export, never interpolated from Cp or substituted from the final step. A run without that auxiliary source, a legacy one or one whose pproc leaves singularity_strength false (the default), keeps an explicit not-carried declaration.

periodic_copies is the copy count of a row under SYMMETRY PERIODIC. Its native export holds one zone per copy, and the VTK holds the modelled surface first and then its images (RPT-080), so zone k is joined to the k-th copy of the VTK (native_surface.attach_native_strength_by_copy); a native file holding another number of zones is refused naming both counts. None, or 1, is the one-zone export of every other row.

Parameters:

Name Type Description Default
vtk str or Path

The VTK surface export to translate.

required
dat str or Path

The Tecplot file to write, in the reference frame.

required
frame SurfaceFrame

Where the frame the VTK was written in stands in the reference frame.

required
overwrite bool

Whether an existing dat may be replaced. False by default.

False
native_tecplot str or Path

The same point's native Tecplot export, whose nodal strength is matched to the VTK. None carries no native strength.

None
periodic_copies int

Copy count of a SYMMETRY PERIODIC row, the zones the native file must hold. None or 1 is a one-zone export.

None

Returns:

Type Description
dict

What was done: the source and its digest, the frame, the location of the values, the variables, what is not carried, the native record when one was matched, and output_sha256 of the file written.

Raises:

Type Description
ProductError

If the native source and the destination are the same file.

IncompleteOutputError

If the native source named is not a file.

MalformedOutputError

If the VTK or the native source changed during translation, or the native zones cannot be matched to the VTK. A frame with left-handed axes is refused when it is built (det R < 0).

Examples:

>>> import tempfile
>>> from pathlib import Path
>>> import numpy as np
>>> quad = VtkSurface(
...     points=np.array([[0.0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]),
...     offsets=np.array([0, 4]),
...     connectivity=np.array([0, 1, 2, 3]),
...     cell_data={"Cp": np.array([0.25])},
... )
>>> frame = SurfaceFrame(origin=(0.0, 0.0, 0.0),
...     axes=((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)))
>>> with tempfile.TemporaryDirectory() as folder:
...     vtk = write_vtk_surface(Path(folder) / "a.vtk", quad, title="demo")
...     record = translate_vtk_surface(vtk, Path(folder) / "a.dat", frame=frame)
...     written = (Path(folder) / "a.dat").is_file()
>>> written, record["variables"], record["not_carried"]
(True, ['Cp'], ['Singularity_strength'])

pyflightstream.results.surface.write_tecplot_surface

write_tecplot_surface(
    path: str | Path,
    surface: VtkSurface,
    *,
    title: str,
    auxdata: Mapping[str, str] | None = None,
    zone: str = "Surface",
    overwrite: bool = False,
) -> Path

Write a surface as one Tecplot FEPolygon zone, its cell values cell-centred.

Parameters:

Name Type Description Default
path str or Path

The .dat to write; its folder must exist.

required
surface VtkSurface

The surface, in the frame the file should state (the reference frame).

required
title str

The file's TITLE.

required
auxdata mapping of str to str

DATASETAUXDATA records, name to value: where the numbers came from. A name is letters, digits and underscores.

None
zone str

The zone's title.

'Surface'
overwrite bool

Whether an existing file may be replaced. False by default.

False

Returns:

Type Description
Path

The file written.

Raises:

Type Description
ProductExistsError

If the file exists and overwrite is False.

ProductError

If an auxiliary record's name is not a Tecplot name, or a variable name repeats.

pyflightstream.results.surface.write_vtk_surface

write_vtk_surface(
    path: str | Path,
    surface: VtkSurface,
    *,
    title: str,
    overwrite: bool = False,
) -> Path

Write a surface as VTK legacy ASCII polydata, in the layout the solver writes.

Parameters:

Name Type Description Default
path str or Path

The .vtk to write; its folder must exist.

required
surface VtkSurface

The surface.

required
title str

The title line; one line, at most 256 characters as the format allows.

required
overwrite bool

Whether an existing file may be replaced. False by default.

False

Returns:

Type Description
Path

The file written.

Raises:

Type Description
ProductExistsError

If the file exists and overwrite is False.

ProductError

If a point or cell field name is empty or holds whitespace, which the VTK SCALARS line cannot carry; nothing is written.