bluemira.base.reactor

Base class for a bluemira reactor.

Attributes

DIM_2D

DIM_3D

Classes

BaseManager

A base wrapper around a component tree or component trees.

ComponentManager

A wrapper around a component tree.

Reactor

Base class for reactor definitions.

Module Contents

bluemira.base.reactor.DIM_2D
bluemira.base.reactor.DIM_3D
class bluemira.base.reactor.BaseManager

Bases: abc.ABC

Inheritance diagram of bluemira.base.reactor.BaseManager

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.

abstract component() bluemira.base.components.ComponentT

Return the component tree wrapped by this manager.

Return type:

bluemira.base.components.ComponentT

abstract 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.

Parameters:
abstract show_cad(dim: DIM_3D | DIM_2D, construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs)

Show the CAD build of the component.

Parameters:
  • *dims – The dimension of the reactor to show, typically one of ‘xz’, ‘xy’, or ‘xyz’. (default: ‘xyz’)

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • dim (DIM_3D | DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)

abstract plot(dim: DIM_2D, construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs)

Plot the component.

Parameters:
  • *dims – The dimension(s) of the reactor to show, ‘xz’ and/or ‘xy’. (default: ‘xz’)

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • dim (DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)

tree() str

Get the component tree.

Returns:

The component tree as a string.

Return type:

str

property materials

Get all materials in the Manager

static _validate_cad_dim(dim: DIM_3D | DIM_2D) None

Validate showable CAD dimensions.

Raises:

ComponentError – Unknown plot dimension

Parameters:

dim (DIM_3D | DIM_2D)

Return type:

None

static _validate_plot_dims(dim: DIM_2D) None

Validate showable plot dimensions.

Raises:

ComponentError – Unknown plot dimension

Parameters:

dim (DIM_2D)

Return type:

None

class bluemira.base.reactor.ComponentManager(component: bluemira.base.components.ComponentT)

Bases: BaseManager

Inheritance diagram of bluemira.base.reactor.ComponentManager

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).

Parameters:
  • component_tree – The component tree this manager should wrap.

  • component (bluemira.base.components.ComponentT)

_component
_init_construction_param_values(c_params: bluemira.base.tools.ConstructionParams | None, kwargs: dict[str, Any]) bluemira.base.tools.ConstructionParamValues
Parameters:
Return type:

bluemira.base.tools.ConstructionParamValues

static cad_construction_type() bluemira.base.tools.CADConstructionType

Returns the construction type of the component tree wrapped by this manager.

Return type:

bluemira.base.tools.CADConstructionType

component() bluemira.base.components.ComponentT

Return the component tree wrapped by this manager.

Returns:

The underlying component, with all descendants.

Return type:

bluemira.base.components.ComponentT

_build_save_cad_component(dim: str, cp_values: bluemira.base.tools.ConstructionParamValues) bluemira.base.components.Component
Parameters:
Return type:

bluemira.base.components.Component

_build_show_cad_component(dim: str, cp_values: bluemira.base.tools.ConstructionParamValues) bluemira.base.components.Component
Parameters:
Return type:

bluemira.base.components.Component

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.

Parameters:
  • *dims – The dimension of the reactor to show, typically one of ‘xz’, ‘xy’, or ‘xyz’. (default: ‘xyz’)

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • filename (str | None) – the filename to save, will default to the component name

  • cad_format (str | bluemira.codes._freecadapi.CADFileType) – CAD file format

  • directory (str | os.PathLike) – Directory to save into, defaults to the current directory

  • kwargs – passed to the bluemira.geometry.tools.save_cad() function

  • dim (DIM_3D | DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)

show_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs)

Show the CAD build of the component.

Parameters:
  • *dims – The dimension of the reactor to show, typically one of ‘xz’, ‘xy’, or ‘xyz’. (default: ‘xyz’)

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • kwargs – passed to the ~bluemira.display.displayer.show_cad function

  • dim (DIM_3D | DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)

plot(dim: DIM_2D = 'xz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs)

Plot the component.

Parameters:
  • *dims – The dimension(s) of the reactor to show, ‘xz’ and/or ‘xy’. (default: ‘xz’)

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • dim (DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)

class bluemira.base.reactor.Reactor(name: str, n_sectors: int)

Bases: BaseManager

Inheritance diagram of bluemira.base.reactor.Reactor

Base class for reactor definitions.

Assign 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.

Parameters:
  • name (str) – The name of the reactor. This will be the label for the top level bluemira.base.components.Component in the reactor tree.

  • n_sectors (int) – Number of sectors in a reactor

Example

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()
name
n_sectors
start_time
_init_construction_param_values(c_params: bluemira.base.tools.ConstructionParams | None, kwargs: dict[str, Any]) bluemira.base.tools.ConstructionParamValues
Parameters:
Return type:

bluemira.base.tools.ConstructionParamValues

component() bluemira.base.components.Component

Return the component tree.

Returns:

The reactor component tree.

Return type:

bluemira.base.components.Component

time_since_init() float

Get time since initialisation.

Returns:

The time since initialisation.

Return type:

float

_component_managers(with_components: ComponentManager | list[ComponentManager] | None = None, without_components: list[ComponentManager] | None = None) list[ComponentManager]

Get the component managers for the reactor.

Parameters:
  • with_components (ComponentManager | list[ComponentManager] | None) – The components to include. Defaults to None, which means include all components.

  • without_components (list[ComponentManager] | None) – The components to exclude. Defaults to None, which means exclude no components.

Returns:

A list of initialised component managers.

Raises:

ComponentError – Initialising Reactor directly

Return type:

list[ComponentManager]

_build_component_tree(dim: str | None, cp_values: bluemira.base.tools.ConstructionParamValues, *, for_save: bool = False) bluemira.base.components.Component
Parameters:
Return type:

bluemira.base.components.Component

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.

Parameters:
  • *dims – The dimension of the reactor to show, typically one of ‘xz’, ‘xy’, or ‘xyz’. (default: ‘xyz’)

  • with_components – The components to construct when displaying CAD for xyz. Defaults to None, which means show “all” components.

  • n_sectors – The number of sectors to construct when displaying CAD for xyz Defaults to None, which means show “all” sectors.

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • filename (str | None) – the filename to save, will default to the component name

  • cad_format (str | bluemira.codes._freecadapi.CADFileType) – CAD file format

  • directory (str | os.PathLike) – Directory to save into, defaults to the current directory

  • kwargs – passed to the bluemira.geometry.tools.save_cad() function

  • dim (DIM_3D | DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)

show_cad(dim: DIM_3D | DIM_2D = 'xyz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs)

Show the CAD build of the reactor.

Parameters:
  • dim (DIM_3D | DIM_2D) – The dimension of the reactor to show, typically one of ‘xz’, ‘xy’, or ‘xyz’. (default: ‘xyz’)

  • with_components – The components to construct when displaying CAD for xyz. Defaults to None, which means show “all” components.

  • n_sectors – The number of sectors to construct when displaying CAD for xyz Defaults to None, which means show “all” sectors.

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • kwargs – passed to the ~bluemira.display.displayer.show_cad function

  • construction_params (bluemira.base.tools.ConstructionParams | None)

plot(dim: DIM_2D = 'xz', construction_params: bluemira.base.tools.ConstructionParams | None = None, **kwargs)

Plot the reactor.

Parameters:
  • *dims – The dimension(s) of the reactor to show, ‘xz’ and/or ‘xy’. (default: ‘xz’)

  • with_components – The components to construct when displaying CAD for xyz. Defaults to None, which means show “all” components.

  • component_filter – A callable to filter Components from the Component tree, returning True keeps the node False removes it

  • show – Whether or not to immediately display the plot

  • dim (DIM_2D)

  • construction_params (bluemira.base.tools.ConstructionParams | None)