trace – Run TRACE

pyTrace offers a collection of a Python interface to interact with the TRACE solver.

To interface with the solver, this module implements multiple python classes that interact with TRACE data structures. The main class is called TRACE and wraps the complete solver environment. It provides methods to read and modify the internal state of TRACE.

Usage

The TRACE class can be setup in the same way as calling TRACE on the command line. You simply pass the desired command line to the constructor:

1from tracesuite.trace import TRACE
2
3if __name__ == '__main__':
4
5    trace = TRACE("-cgns TRACE.cgns")
6    trace.run()
7    trace.kill()

In the above example, the pyTRACE script behaves exactly as it would on the command line: TRACE is initialized and the executed by using TRACE.run() until the simulation is stopped, for example because it reached convergence or an error occurred. Finally, the solver instance is finalized by using the TRACE.kill() method. This is required to cleanly exit the MPI environment.

One important advantage of using the Python interface instead of the native TRACE executable is that the solver can be paused and analyzed or even modified during the execution. For example, the TRACE.run() method accepts a parameter controlling the number of iterations that are performed:

trace.run(5)

In this case only five iterations are executed. After that the solver state can be changed and the solver can be restarted by another subsequent call to TRACE.run().

Accessing Data

The parent class of TRACE is Setup. Therefore, it provides the same interface as POST to access the simulation data. For example, to access flow data stored on blocks in TRACE, you can use the TRACE.blocks which maps each block with its name:

for block_name, block in trace.blocks.items():
    print(f"Block '{block_name}' has {len(block.cells)} cells!")

For more Information on how to access data, see the documentation of Setup or TRACE.

Note

The actual classes of TRACE like trace.Block offer more attributes than the abstract base class from setup which only defines relations and iterator interfaces!

Classes

trace.py

Contains general classes and enums to manage simulations and turbomachinery setups.

class tracesuite.trace.trace.TRACE(command_line: str, trace_root_communicator: MPI.Comm = <mpi4py.MPI.Intracomm object>, trace_cntl: _trace.SolverCntl | None = None, *, stop_before_simulation_setup: bool = False)[source]

Main Trace simulation handle.

This class is used to control one Trace simulation that would be started via a console command for one cgns-file. Currently only one simulation can exist in a python context. A simulation can be initialized, configured and started in distinct steps using the given methods. It further provides functionality to focus the communication context on subsets of e.g. panel or block groups to reduce communication overhead.

Developers should note that this class essentially uses _trace.SolverCntl as interfacing class to interact with the underlying Trace c-struct SolverCntl.

apply_changed_metadata()[source]

Execute Trace meta data setup with input parameters changed by previous user commands.

property block_groups: ChainMap[str, BlockGroup]

Returns dictionary of all blocks groups.

property blocks: list[Block]

Returns a list of all blocks.

property boundaries: dict[str, setup.Boundary]

Returns dictionary of all boundaries.

property components: dict[str, Component]

Returns dictionary of all components.

property eigenmodes

Returns list of all eigenmodes in this Trace simulation.

focus_on(*args)[source]

Select TRACE entities (block or panel groups) to focus on to improve parallel execution of the python script.

This method can only be used in a ‘with’ context, e.g.:

with trace.focus_on(inlet, outlet) as focus:
    if focus:
        CODEBLOCK

Here, only the MPI ranks that own parts of the inlet or outlet panel groups will execute the CODEBLOCK. Note that due to restrictions in the python language the return value ‘focus’ must be checked explicitly, i.e. the CODEBLOCK must be executed only if ‘focus’ is True. ‘focus_on’ can be nested, but inner nests can focus on a subset of the focused entities of the outer nests.

get_block(zone_id: int) → Block[source]

Return the block with the given zoneID as python class Block.

Parameters:

zone_id – ID of the block (i.e. zone) as specified in the cgns file.

Returns:

Reference to the Trace block with the zoneID zoneID.

get_cgns_output_data_file(output_type: OutputType) → Path[source]

Return the path of the cgns output file for the given output type as string.

increase_maximum_timestep_by_adding_value(n_timesteps)[source]

Add ‘n_timesteps’ to the current number of maximum (pseudo) time steps.

static initialize()[source]

Wrap an already initialized simulation.

Note that this function is meant to be used in a TRACE-calls-python context and should be avoided when implementing python-calls-TRACE functionality.

Returns:

New instance of python class TRACE wrapping an already existing Simulation.

Return type:

TRACE

kill()[source]

Cleanup TRACE object by disposing all allocated memory and decrement the number of TRACE instances.

message(*args, **kwargs)[source]

Print a unique message to stdout, i.e. only one rank will print in an MPI environment.

property n_pseudo_time_steps: int

Returns the total number of the Trace pseudo time steps in one physical time step.

property online_analysis

Get list of online analysis probes.

property outlets: list[Outlet]

Return a list containing panel groups of type Outlet.

property pseudo_time_step: int

Returns the number of the current Trace pseudo time step.

reset_finished_flags()[source]

Reset (multiple) Trace solver finish flags to suppress an immediate stop in a (new) call to run().

reset_iteration_counter_to_beginning_of_time_step()[source]

Reset the pseudo time step and stage both to 1 in order to recompute a physical time step instead of advancing the next one.

reset_maximum_timestep(n_timesteps)[source]

Set the number of maximum time steps to n_timesteps.

property rows: dict[str, Row]

Returns dictionary of all rows.

run(n_steps=-1)[source]

Perform n_steps pseudo time steps (steady/harmonic balance mode) or physical time steps (unsteady mode).

Return the status as enum SimulationState. If no argument is given, Trace will continue until convergence or end of the simulation.

Parameters:

n_steps – number of pseudo/physical time steps to run

set_ascii_output(ascii_output_type: AsciiOutputType, path: Path, *, is_active: bool = True, interleave: int = 1, sub_iteration_output_on: bool = False, binary_hdf5: bool = False) → None[source]

Set output for the given output ascii type.

set_cgns_output_data_file(output_type: OutputType, path: pathlib.Path, *, isActive: bool = True, interleave: int | None = None) → None[source]

Set cgns output for the given output type.

set_reynolds_stress_uq(uq_method, *, limit_state_turbulence=None, target_delta_b=0.0, tke_production_update=False, rotation_angle=nan, rotation_angle_fraction=nan, delta_b_ramp=(nan, nan))[source]

Set up uncertainty quantification method in order to disturb reynolds stresses.

setup_simulation()[source]

Allocate cpp structures and create python wrappers.

property solver_step

Returns the number of the current Trace (pseudo) time step.

property stages: dict[str, Stage]

Returns dictionary of all stages.

write_output_files() → None[source]

Write the current solution into the output files as specified (before) in the output settings.

panel_groups.py

Contains the general representation of a PanelGroup, derived classes and related methods.

class tracesuite.trace.panel_groups.PanelGroup(trace_panel_group: _trace.PanelGroup, block_group: block_groups.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl)[source]

Base class that represents a general PanelGroup in the TRACE context.

It uses an instance of the c-interfacing class trace_panel_group to interact with one associated TRACE c-struct PanelGroup. Functionality that is specific to a certain group type shall be located into the appropriate derived python classes e.g. Inlet, Outlet, … Since Panel groups might be located on multiple ranks this class inherits from comm.CommunicatingEntity to allow its usage within a focused communication context.

property block_group

Return the panel groups block group.

property boundary_type

Return the boundary type.

interface_data_0d(time_average: TemporalAveraging, spatial_average: SpatialAveraging) → _trace.OutputBufferRadialDistribution | None[source]

Get integral data of the panel group.

Only the panel groups master process returns the values, other processes return ‘None’.

Parameters:
  • time_average – Time averaging to use.

  • spatial_average – Spatial averaging type to use.

Returns:

Collected integral data or ‘None’.

interface_data_1d(time_average: TemporalAveraging, spatial_average: SpatialAveraging) → _trace.OutputBufferRadialDistribution | None[source]

Get band-wise radial distribution of the panel group.

Only the panel groups master process returns the values, other processes return ‘None’.

Parameters:
  • time_average – Time averaging to use.

  • spatial_average – Spatial averaging type to use.

Returns:

Collected radial distribution or ‘None’.

property n_bands: int

Return the number of bands.

property name

Return the name of the panel group as stored in the c-struct “PanelGroup”.

property variable_names: list[dict]

Boundary variables on panel groups.

class tracesuite.trace.panel_groups.Solid(trace_panel_group: _trace.PanelGroup, block_group: block_groups.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl)[source]

Specific panel groups representing solid boundary.

class tracesuite.trace.panel_groups.Periodic(trace_panel_group: _trace.PanelGroup, block_group: block_groups.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl)[source]

Specific panel groups representing periodic boundary.

class tracesuite.trace.panel_groups.Inlet(trace_panel_group: _trace.PanelGroup, block_group: block_groups.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl)[source]

Specific PanelGroup representing an Inlet of a flow domain.

It provides (user) functionality to set the total pressure and the total temperature on the Inlet to a desired value.

set_flow_direction(flow_direction: list) → None[source]

Set the flow direction vector at this inlet. Specify in absolute frame of reference.

set_total_pressure(pressure)[source]

Set the total pressure on this inlet. Specify in absolute frame of reference.

set_total_temperature(pressure)[source]

Set the total temperature on this inlet. Specify in absolute frame of reference.

class tracesuite.trace.panel_groups.Outlet(trace_panel_group: _trace.PanelGroup, block_group: block_groups.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl)[source]

Specific PanelGroup representing an Outlet of a flow domain.

It provides (user)functionality to set the static pressure on the Outlet and to get the actual pressure.

property boundary_condition_pressure

Get the boundary value for the static pressure.

The decorator comm.broadcast_from_master ensures that the value is communicated from the panel groups master rank to all participating ranks of the current focus.

set_static_pressure(pressure)[source]

Set the boundary value for the static pressure.

communication.py

Contains infrastructure for communication within python.

NOT part of the user interface!.

block_groups.py

Contains the general representation of a Trace BlockGroup, derived classes and related methods.

class tracesuite.trace.block_groups.BlockGroup(trace_block_group: _trace.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, all_blocks: Iterator[Block])[source]

Base class that represents a general BlockGroup in the Trace context.

It uses an instance of the c-interfacing class _trace.BlockGroup to interact with one associated Trace c-struct BlockGroup. Functionality that is specific to a certain group type shall be located into the appropriate derived python classes Row, Stage or Component. Since block groups might be located on multiple ranks this class inherits from comm.CommunicatingEntity to allow its usage within a focused communication context.

property blocks

Return a list of all blocks that are associated to this block group.

property is_unsteady: bool

Return ‘True’ if the block group is unsteady.

property local_blocks

Return a list of only the local blocks that are associated to this block group.

property name: str

Return the name of the block group as stored in the Trace c-struct “BlockGroup”.

class tracesuite.trace.block_groups.Row(trace_block_group: _trace.TraceBlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, blocks: dict[str, Block])[source]

Specific BlockGroup representing a single row in turbomachinery context.

As a derivation of CommunicatingEntity, objects of this class can be focused within a focused communication context.

property is_rotating

Returns boolean flag indicating whether this row is a rotating entity.

property parent_component: Component

Return the parent component.

property parent_stage: Stage

Return the parent stage.

property revolutions_per_minute

Return the current rotational speed of this row in revolutions per minute.

property time_step_size: float

Return the block groups time step size.

property type

Returns the type of the row (e.g. rotor or stator) as enum of type _trace.RowType.

class tracesuite.trace.block_groups.Stage(trace_block_group: _trace.TraceBlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, blocks: dict[str, Block], member_rows: dict[str, Row])[source]

Specific BlockGroup representing a single stage in turbomachinery context.

It further contains the rows it consists of as dictionary. As derivation of CommunicatingEntity objects of this class can be focused within a focused communication context.

property parent_component: Component

Return the parent component.

property rows

Return the rows this stage consists of as list.

class tracesuite.trace.block_groups.Component(trace_block_group: _trace.TraceBlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, blocks: dict[str, Block], member_stages: dict[str, Stage], member_rows: dict[str, Row])[source]

Specific BlockGroup representing a single component in turbomachinery context.

It further contains the rows and the stages it consists of as dictionaries. As derivation of CommunicatingEntity objects of this class can be focused within a focused communication context.

property rows

Return the rows which belong to this component as list.

property stages

Return the stages which belong to this component as list.

block.py

Contains the general representation of a Trace Block as well as related classes and methods.

class tracesuite.trace.block.Block(cntl: SolverCntl, trace_block: Block)[source]

Python class representing a general block in the Trace context.

I.e. a structured or unstructured part of the computational domain handled by an instance of SolverCntl. Note that Trace holds meta information of all blocks on each rank but only allocates actual (e.g. solution) data on blocks that are assigned to its own rank (i.e. local blocks).

If this is a local block, dimensionalized access to the underlying data fields is provided. Furthermore, iterators can be used to loop over all cells in a single loop. All methods and properties are valid on each rank. Nevertheless, if the block is not local, fields will be empty and iterators loop length will be zero.

property cells

Return an iterator that loops only over all cells of a block including ghost cells.

property dim

Return the dimension of this block including the ghost cell layers as CellIndex.

property family: block_groups.BlockGroup

Return the block family.

property inner_cells

Return an iterator that loops only over the inner cells of a block omitting the ghost cells.

property is_local

Return a boolean flag indicating whether this block is associated to this rank.

Note that Trace holds meta information of all blocks on each rank but only allocates actual (e.g. solution) data on blocks that are assigned to its own rank (i.e. local blocks).

property name: str

Return the name of this block as specified by the cgns-file.

property zone_id: int

Return the zone_id of this block as specified by the cgns-file. Enumeration starts with 1.

eigenmode.py

Contains the general representation of an Eigenmode as well as related classes and methods.

class tracesuite.trace.eigenmode.Eigenmode(cntl, trace_eigenmode)[source]

Python class representing a general eigenmode in the Trace context, handled by an instance of SolverCntl.

property acceleration

The modal acceleration at the next time step. Is readable and writeable.

property current_acceleration

The modal acceleration at the current time step. Is only readable.

property current_displacement

The modal displacement at the current time step. Is only readable.

property current_force

The modal force at the current time step. Is only readable.

property current_velocity

The modal velocity at the current time step. Is only readable.

property displacement

The modal displacement at the next time step. Is readable and writeable.

property force

The modal force at the next time step. Is only readable.

property name

Return the name of this eigenmode.

property velocity

The modal velocity at the next time step. Is readable and writeable.