Source code for tracesuite.trace.panel_groups

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

from __future__ import annotations

import typing

from tracesuite import SpatialAveraging
from tracesuite import simulation_setup as setup

from . import communication as comm

if typing.TYPE_CHECKING:
    from tracesuite import TemporalAveraging
    from tracesuite.trace import _trace, block_groups


[docs] class PanelGroup(setup.PanelGroup, comm.CommunicatingEntity): """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 :class:`comm.CommunicatingEntity` to allow its usage within a focused communication context. """ def __init__(self, trace_panel_group: _trace.PanelGroup, block_group: block_groups.BlockGroup, communicator: comm.Communicator, cntl: _trace.SolverCntl): """Create a new panel group from a panel group. :param trace_panel_group: Uniquely links this class to a c-struct of type `PanelGroup`. :param block_group: Uniquely links this class to a c-struct of type `BlockGroup`. :param communicator: Communicator required to initialize the :class:`CommunicatingEntity` base class. :param cntl: Links this panelGroup to the associated TRACE computation and allows convenient access to e.g. its global meta data. """ comm.CommunicatingEntity.__init__(self, trace_panel_group.comm, communicator, cntl) self._trace_panel_group = trace_panel_group self._block_group = block_group @property def name(self): """Return the name of the panel group as stored in the c-struct "PanelGroup".""" return self._trace_panel_group.name @property def boundary_type(self): """Return the boundary type.""" return self._trace_panel_group.boundary_type @property def n_bands(self) -> int: """Return the number of bands.""" return self._trace_panel_group.n_bands @property def block_group(self): """Return the panel groups block group.""" return self._block_group @property @comm.broadcast_from_master def variable_names(self) -> list[dict]: """Boundary variables on panel groups.""" return self._trace_panel_group.variable_names @comm.only_on_member def _set_boundary_value(self, variable_name: str, value: float) -> None: """Set boundary value. Sets the boundary value for a certain variable specified by string `variable_name`. This function is not part of the user interface, since calls to certain variables are invalid depending on the PanelType. The user is advised to use the specific functionality defined in classes Inlet and Outlet. The decorator comm.onlyOnMember ensures that this function is only executed on ranks that participate in this PanelGroup. **Boundary values have to be specified in absolute frame of reference.** @param variable_name: Name of the variable to set the boundary value for. (E.g. "PressureStagnationAbs", ...) """ self._trace_panel_group.set_boundary_value(variable_name, value)
[docs] @comm.broadcast_from_master def interface_data_1d(self, time_average: TemporalAveraging, spatial_average : SpatialAveraging) -> _trace.OutputBufferRadialDistribution | None: """Get band-wise radial distribution of the panel group. Only the panel groups master process returns the values, other processes return 'None'. :param time_average: Time averaging to use. :param spatial_average: Spatial averaging type to use. :return: Collected radial distribution or 'None'. """ return self._trace_panel_group.interface_data_1d(self._cntl, time_average, spatial_average)
[docs] @comm.broadcast_from_master def interface_data_0d(self, time_average: TemporalAveraging, spatial_average : SpatialAveraging) -> _trace.OutputBufferRadialDistribution | None: """Get integral data of the panel group. Only the panel groups master process returns the values, other processes return 'None'. :param time_average: Time averaging to use. :param spatial_average: Spatial averaging type to use. :return: Collected integral data or 'None'. """ return self._trace_panel_group.interface_data_0d(self._cntl, time_average, spatial_average)
[docs] class Solid(PanelGroup): """Specific panel groups representing solid boundary."""
[docs] class Periodic(PanelGroup): """Specific panel groups representing periodic boundary."""
[docs] class Inlet(PanelGroup): """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. """
[docs] def set_total_pressure(self, pressure): """Set the total pressure on this inlet. **Specify in absolute frame of reference**.""" self._set_boundary_value("PressureStagnationAbs", pressure)
[docs] def set_total_temperature(self, pressure): """Set the total temperature on this inlet. **Specify in absolute frame of reference**.""" self._set_boundary_value("TemperatureStagnationAbs", pressure)
[docs] def set_flow_direction(self, flow_direction: list) -> None: """Set the flow direction vector at this inlet. **Specify in absolute frame of reference**.""" assert len(flow_direction) == 3 # noqa: PLR2004 Considered and decided against replacing '3' by constant value norm = (flow_direction[0] ** 2 + flow_direction[1] ** 2 + flow_direction[2] ** 2) ** 0.5 flow_direction_normalized = [item / norm for item in flow_direction] self._set_boundary_value("FlowDirectionX", flow_direction_normalized[0]) self._set_boundary_value("FlowDirectionYAbs", flow_direction_normalized[1]) self._set_boundary_value("FlowDirectionZ", flow_direction_normalized[2])
[docs] class Outlet(PanelGroup): """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 @comm.broadcast_from_master def boundary_condition_pressure(self): """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. """ return self._trace_panel_group.boundary_condition_pressure
[docs] def set_static_pressure(self, pressure): """Set the boundary value for the static pressure.""" self._set_boundary_value("Pressure", pressure)