Source code for tracesuite.trace.block_groups

"""Contains the general representation of a Trace BlockGroup, derived classes and related methods."""
from __future__ import annotations

import typing

from tracesuite import RowType
from tracesuite import simulation_setup as setup

from . import communication as comm

if typing.TYPE_CHECKING:
    from tracesuite.trace import _trace

    from .block import Block


[docs] class BlockGroup(setup.BlockGroup, comm.CommunicatingEntity): """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 :class:`comm.CommunicatingEntity` to allow its usage within a focused communication context. """ def __init__(self, trace_block_group: _trace.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, all_blocks: typing.Iterator[Block]): """Create a new instance. :param trace_block_group: Uniquely links this class to a Trace c-struct of type `_trace.BlockGroup`. :param communicator: Communicator required to initialize the :class:`CommunicatingEntity` base class. :param cntl: Links this blockGroup to the associated Trace computation and allows convenient access to e.g. its global meta data. :param all_blocks: List of all blocks related to the computation handled by cntl. (Also the non-local blocks) """ comm.CommunicatingEntity.__init__(self, trace_block_group.comm, communicator, cntl) self._trace_block_group = trace_block_group self._blocks = [b for b in all_blocks if b.zone_id in self._trace_block_group.block_ids] assert len(self._trace_block_group.block_ids) == len(self._blocks), "Internal error setting up block group" self._local_blocks = [b for b in self._blocks if b.is_local] @property def name(self) -> str: """Return the name of the block group as stored in the Trace c-struct "BlockGroup".""" return self._trace_block_group.name @property def is_unsteady(self) -> bool: """Return 'True' if the block group is unsteady.""" return self._trace_block_group.is_unsteady @property def blocks(self): """Return a list of all blocks that are associated to this block group.""" return self._blocks @property def local_blocks(self): """Return a list of only the local blocks that are associated to this block group.""" return self._local_blocks
[docs] class Row(setup.Row, BlockGroup): """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. """ def __init__(self, trace_block_group: _trace.TraceBlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, blocks: dict[str, Block]): """Create a new Row from a TRACE block group. :param trace_block_group: Uniquely links this class to a Trace c-struct of type `BlockGroup` . :param communicator: Communicator required to initialize the :class:`CommunicatingEntity` base class. :param cntl: Links this blockGroup to the associated Trace computation and allows convenient access to e.g. its global metadata. :param blocks: List of all blocks related to the computation handled by cntl. (Also the non-local blocks) """ BlockGroup.__init__(self, trace_block_group, communicator, cntl, blocks) self._parent_stage = None self._parent_component = None @property def type(self): """Returns the type of the row (e.g. rotor or stator) as enum of type `_trace.RowType`.""" return self._trace_block_group.row_type @property def parent_stage(self) -> Stage: """Return the parent stage.""" return self._parent_stage @property def parent_component(self) -> Component: """Return the parent component.""" return self._parent_component @property def is_rotating(self): """Returns boolean flag indicating whether this row is a rotating entity.""" return self.type in (RowType.ROTOR, RowType.CAVITY_R, RowType.DUCT_R) @property def revolutions_per_minute(self): """Return the current rotational speed of this row in revolutions per minute.""" return self._trace_block_group.revolutions_per_minute @property def time_step_size(self) -> float: """Return the block groups time step size.""" return self._trace_block_group.time_step_size
[docs] class Stage(setup.Stage, BlockGroup): """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. """ def __init__(self, trace_block_group: _trace.TraceBlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl, blocks: dict[str, Block], member_rows: dict[str, Row]): """Create a new stage from a TRACE stage. :param trace_block_group: Uniquely links this class to a Trace c-struct of type `BlockGroup`. :param communicator: Communicator required to initialize the :class:`CommunicatingEntity` base class. :param cntl: Links this blockGroup to the associated Trace computation and allows convenient access to e.g. its global metadata. :param blocks: List of all blocks related to the computation handled by cntl. (Also the non-local blocks) :param member_rows: List of all rows this Stage consists off. """ BlockGroup.__init__(self, trace_block_group, communicator, cntl, blocks) self._rows = member_rows self._parent_component = None @property def parent_component(self) -> Component: """Return the parent component.""" return self._parent_component @property def rows(self): """Return the rows this stage consists of as list.""" return self._rows
[docs] class Component(setup.Component, BlockGroup): """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. """ def __init__(self, trace_block_group: _trace.TraceBlockGroup, # noqa: PLR0913 Number of parameters part of the interface communicator: comm.Communicator, cntl: _trace.SolverCntl, blocks: dict[str, Block], member_stages: dict[str, Stage], member_rows: dict[str, Row]): """Create a new component from a TRACE component. :param trace_block_group: Uniquely links this class to a Trace c-struct of type `BlockGroup`. :param communicator: Communicator required to initialize the :class:`CommunicatingEntity` base class. :param cntl: Links this blockGroup to the associated Trace computation and allows convenient access to e.g. its global metadata. :param blocks: List of all blocks related to the computation handled by cntl. (Also the non-local blocks) :param member_stages: List of all stages which belong to this component. :param member_rows: List of all rows which belong to this component. """ BlockGroup.__init__(self, trace_block_group, communicator, cntl, blocks) self._stages = member_stages self._rows = member_rows @property def rows(self): """Return the rows which belong to this component as list.""" return self._rows @property def stages(self): """Return the stages which belong to this component as list.""" return self._stages