bluemira.base.reactor ===================== .. py:module:: bluemira.base.reactor .. autoapi-nested-parse:: Base class for a bluemira reactor. Attributes ---------- .. autoapisummary:: bluemira.base.reactor.DIM_2D bluemira.base.reactor.DIM_3D Classes ------- .. autoapisummary:: bluemira.base.reactor.BaseManager bluemira.base.reactor.ComponentManager bluemira.base.reactor.Reactor Module Contents --------------- .. py:data:: DIM_2D .. py:data:: DIM_3D .. py:class:: BaseManager Bases: :py:obj:`abc.ABC` .. autoapi-inheritance-diagram:: bluemira.base.reactor.BaseManager :parts: 1 :private-bases: A base wrapper around a component tree or component trees. The purpose of the classes deriving from this is to abstract away the structure of the component tree and provide access to a set of its features. This way a reactor build procedure can be completely agnostic of the structure of component trees. .. py:method:: component() -> bluemira.base.components.ComponentT :abstractmethod: Return the component tree wrapped by this manager. .. py:method:: save_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, *, filename: str | None = None, cad_format: str | bluemira.codes._freecadapi.CADFileType = 'stp', directory: str | os.PathLike = '', **kwargs) :abstractmethod: Save the CAD build of the component. :param components: components to save :param filename: the filename to save :param cad_format: CAD file format .. py:method:: show_cad(dim: DIM_3D | DIM_2D, construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs) :abstractmethod: Show the CAD build of the component. :param \*dims: The dimension of the reactor to show, typically one of 'xz', 'xy', or 'xyz'. (default: 'xyz') :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it .. py:method:: plot(dim: DIM_2D, construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs) :abstractmethod: Plot the component. :param \*dims: The dimension(s) of the reactor to show, 'xz' and/or 'xy'. (default: 'xz') :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it .. py:method:: tree() -> str Get the component tree. :returns: The component tree as a string. .. py:property:: materials Get all materials in the Manager .. py:method:: _validate_cad_dim(dim: DIM_3D | DIM_2D) -> None :staticmethod: Validate showable CAD dimensions. :raises ComponentError: Unknown plot dimension .. py:method:: _validate_plot_dims(dim: DIM_2D) -> None :staticmethod: Validate showable plot dimensions. :raises ComponentError: Unknown plot dimension .. py:class:: ComponentManager(component: bluemira.base.components.ComponentT) Bases: :py:obj:`BaseManager` .. autoapi-inheritance-diagram:: bluemira.base.reactor.ComponentManager :parts: 1 :private-bases: A wrapper around a component tree. The purpose of the classes deriving from this is to abstract away the structure of the component tree and provide access to a set of its features. This way a reactor build procedure can be completely agnostic of the structure of component trees, relying instead on a set of methods implemented on concrete `ComponentManager` instances. This class can also be used to hold 'construction geometry' that may not be part of the component tree, but was useful in construction of the tree, and could be subsequently useful (e.g., an equilibrium can be solved to get a plasma shape, the equilibrium is not derivable from the plasma component tree, but can be useful in other stages of a reactor build procedure). :param component_tree: The component tree this manager should wrap. .. py:attribute:: _component .. py:method:: _init_construction_param_values(c_params: bluemira.base.tools.ConstructionParams | None, kwargs: dict[str, Any]) -> bluemira.base.tools.ConstructionParamValues .. py:method:: cad_construction_type() -> bluemira.base.tools.CADConstructionType :staticmethod: Returns the construction type of the component tree wrapped by this manager. .. py:method:: component() -> bluemira.base.components.ComponentT Return the component tree wrapped by this manager. :returns: The underlying component, with all descendants. .. py:method:: _build_save_cad_component(dim: str, cp_values: bluemira.base.tools.ConstructionParamValues) -> bluemira.base.components.Component .. py:method:: _build_show_cad_component(dim: str, cp_values: bluemira.base.tools.ConstructionParamValues) -> bluemira.base.components.Component .. py:method:: save_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, *, filename: str | None = None, cad_format: str | bluemira.codes._freecadapi.CADFileType = 'stp', directory: str | os.PathLike = '', **kwargs) Save the CAD build of the component. :param \*dims: The dimension of the reactor to show, typically one of 'xz', 'xy', or 'xyz'. (default: 'xyz') :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it :param filename: the filename to save, will default to the component name :param cad_format: CAD file format :param directory: Directory to save into, defaults to the current directory :param kwargs: passed to the :func:`bluemira.geometry.tools.save_cad` function .. py:method:: show_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs) Show the CAD build of the component. :param \*dims: The dimension of the reactor to show, typically one of 'xz', 'xy', or 'xyz'. (default: 'xyz') :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it :param kwargs: passed to the `~bluemira.display.displayer.show_cad` function .. py:method:: plot(dim: DIM_2D = 'xz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs) Plot the component. :param \*dims: The dimension(s) of the reactor to show, 'xz' and/or 'xy'. (default: 'xz') :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it .. py:class:: Reactor(name: str, n_sectors: int) Bases: :py:obj:`BaseManager` .. autoapi-inheritance-diagram:: bluemira.base.reactor.Reactor :parts: 1 :private-bases: Base class for reactor definitions. Assign :obj:`bluemira.base.builder.ComponentManager` instances to fields defined on the reactor, and this class acts as a container to group those components' trees. It is also a place to define any methods to calculate/derive properties that require information about multiple reactor components. Components should be defined on the reactor as class properties annotated with a type (similar to a ``dataclass``). A type that subclasses ``ComponentManager`` must be given, or it will not be recognised as part of the reactor tree. Note that a declared component is not required to be set for the reactor to be valid. So it is possible to just add a reactor's plasma, but not its TF coils, for example. :param name: The name of the reactor. This will be the label for the top level :obj:`bluemira.base.components.Component` in the reactor tree. :param n_sectors: Number of sectors in a reactor .. rubric:: Example .. code-block:: python class MyReactor(Reactor): '''An example of how to declare a reactor structure.''' plasma: MyPlasma tf_coils: MyTfCoils def get_ripple(self): '''Calculate the ripple in the TF coils.''' reactor = MyReactor("My Reactor", n_sectors=1) reactor.plasma = build_plasma() reactor.tf_coils = build_tf_coils() reactor.show_cad() .. py:attribute:: name .. py:attribute:: n_sectors .. py:attribute:: start_time .. py:method:: _init_construction_param_values(c_params: bluemira.base.tools.ConstructionParams | None, kwargs: dict[str, Any]) -> bluemira.base.tools.ConstructionParamValues .. py:method:: component() -> bluemira.base.components.Component Return the component tree. :returns: The reactor component tree. .. py:method:: time_since_init() -> float Get time since initialisation. :returns: The time since initialisation. .. py:method:: _component_managers(with_components: ComponentManager | list[ComponentManager] | None = None, without_components: list[ComponentManager] | None = None) -> list[ComponentManager] Get the component managers for the reactor. :param with_components: The components to include. Defaults to None, which means include all components. :param without_components: The components to exclude. Defaults to None, which means exclude no components. :returns: A list of initialised component managers. :raises ComponentError: Initialising Reactor directly .. py:method:: _build_component_tree(dim: str | None, cp_values: bluemira.base.tools.ConstructionParamValues, *, for_save: bool = False) -> bluemira.base.components.Component .. py:method:: save_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, *, filename: str | None = None, cad_format: str | bluemira.codes._freecadapi.CADFileType = 'stp', directory: str | os.PathLike = '', **kwargs) Save the CAD build of the reactor. :param \*dims: The dimension of the reactor to show, typically one of 'xz', 'xy', or 'xyz'. (default: 'xyz') :param with_components: The components to construct when displaying CAD for xyz. Defaults to None, which means show "all" components. :param n_sectors: The number of sectors to construct when displaying CAD for xyz Defaults to None, which means show "all" sectors. :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it :param filename: the filename to save, will default to the component name :param cad_format: CAD file format :param directory: Directory to save into, defaults to the current directory :param kwargs: passed to the :func:`bluemira.geometry.tools.save_cad` function .. py:method:: show_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs) Show the CAD build of the reactor. :param dim: The dimension of the reactor to show, typically one of 'xz', 'xy', or 'xyz'. (default: 'xyz') :param with_components: The components to construct when displaying CAD for xyz. Defaults to None, which means show "all" components. :param n_sectors: The number of sectors to construct when displaying CAD for xyz Defaults to None, which means show "all" sectors. :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it :param kwargs: passed to the `~bluemira.display.displayer.show_cad` function .. py:method:: plot(dim: DIM_2D = 'xz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs) Plot the reactor. :param \*dims: The dimension(s) of the reactor to show, 'xz' and/or 'xy'. (default: 'xz') :param with_components: The components to construct when displaying CAD for xyz. Defaults to None, which means show "all" components. :param component_filter: A callable to filter Components from the Component tree, returning True keeps the node False removes it :param show: Whether or not to immediately display the plot