bluemira.base.components

Module containing the base Component class.

Attributes

ComponentT

Classes

Component

The Component is the fundamental building block for a bluemira reactor design. It

PhysicalComponent

A physical component. It includes shape and materials.

MagneticComponent

A magnetic component. It includes a shape, a material, and a source conductor.

Functions

get_properties_from_components(→ tuple[list[Any], ...)

Get properties from Components

Module Contents

bluemira.base.components.ComponentT
class bluemira.base.components.Component(name: str, parent: ComponentT | None = None, children: list[ComponentT] | None = None)

Bases: anytree.NodeMixin, bluemira.display.plotter.Plottable, bluemira.display.displayer.DisplayableCAD

Inheritance diagram of bluemira.base.components.Component

The Component is the fundamental building block for a bluemira reactor design. It encodes the way that the corresponding part of the reactor will be built, along with any other derived properties that relate to that component.

Components define a tree structure, based on the parent and children properties. This allows the nodes on that tree to be passed around within bluemira so that operations can be performed on the child branches of that structure.

For example, a reactor design including just a TFCoilSystem may look as below:

digraph base_component_tree { "FusionPowerPlant" -> "TFCoilSystem" -> {"TFWindingPack" "TFCasing"} }

A Component cannot be used directly - only subclasses should be instantiated.

Parameters:
  • name (str)

  • parent (ComponentT | None)

  • children (list[ComponentT] | None)

name: str
parent = None

Parent Node.

On set, the node is detached from any previous parent node and attached to the new node.

>>> from anytree import Node, RenderTree
>>> udo = Node("Udo")
>>> marc = Node("Marc")
>>> lian = Node("Lian", parent=marc)
>>> print(RenderTree(udo))
Node('/Udo')
>>> print(RenderTree(marc))
Node('/Marc')
└── Node('/Marc/Lian')

Attach

>>> marc.parent = udo
>>> print(RenderTree(udo))
Node('/Udo')
└── Node('/Udo/Marc')
    └── Node('/Udo/Marc/Lian')

Detach

To make a node to a root node, just set this attribute to None.

>>> marc.is_root
False
>>> marc.parent = None
>>> marc.is_root
True
__repr__() str

The string representation of the instance.

Returns:

The name of the instance and its class name.

Return type:

str

filter_components(names: collections.abc.Iterable[str], component_filter: collections.abc.Callable[[ComponentT], bool] | None = None)

Removes all components from the tree, starting at this component, that are siblings of each component specified in names and that aren’t in names themselves.

Parameters:
  • names (collections.abc.Iterable[str]) – The list of names of each component to search for.

  • component_filter (collections.abc.Callable[[ComponentT], bool] | None) – A callable to filter Components from the Component tree, returning True keeps the node False removes it

Notes

This function mutates components in the subtree

tree() str

Get the tree of descendants of this instance.

Returns:

The tree of descendants of this instance as a string.

Return type:

str

copy(parent: ComponentT | None = None) ComponentT

Copies this component and its children (recursively) and sets parent as this copy’s parent. This only creates copies of each Component, the shape and material instances (for a PhysicalComponent for ex.) are shared (i.e. are the same instance).

Parameters:

parent (ComponentT | None) – The component to set as the copy’s parent

Return type:

The copied component

Notes

This function should be overridden by implementors

copy_children(parent: ComponentT) list[ComponentT]

Copies this component’s children (recursively) and sets parent as the copied children’s parent.

Parameters:

parent (ComponentT) – The component to set as the copied children’s parent

Return type:

The copied children components

Notes

This function should not be overridden by implementors

get_component(name: str, *, first: bool = True, full_tree: bool = False) ComponentT | tuple[ComponentT] | None

Find the components with the specified name.

Parameters:
  • name (str) – The name of the component to search for.

  • first (bool) – If True, only the first element is returned, by default True.

  • full_tree (bool) – If True, searches the tree from the root, else searches from this node, by default False.

Returns:

  • The first component of the search if first is True, else all components

  • matching the search.

Return type:

ComponentT | tuple[ComponentT] | None

Notes

This function is just a wrapper of the anytree.search.findall function.

get_component_properties(properties: collections.abc.Sequence[str] | str, *, first: bool = True, full_tree: bool = False) tuple[list[Any]] | list[Any] | Any

Get properties from a component

Parameters:
  • properties (collections.abc.Sequence[str] | str) – properties to extract from component tree

  • first (bool) – If True, only the first element is returned, by default True.

  • full_tree (bool) – If True, searches the tree from the root, else searches from this node, by default False.

Returns:

  • If multiple properties specified returns a tuple of the list of properties,

  • otherwise returns a list of the property.

  • If only one node has the property returns the value(s).

Return type:

tuple[list[Any]] | list[Any] | Any

Notes

This function is just a wrapper of the anytree.search.findall or find functions.

_get_thing(filter_: collections.abc.Callable[[ComponentT], bool] | None, *, first: bool, full_tree: bool) ComponentT | tuple[ComponentT] | None
Parameters:
  • filter_ (collections.abc.Callable[[ComponentT], bool] | None)

  • first (bool)

  • full_tree (bool)

Return type:

ComponentT | tuple[ComponentT] | None

add_child(child: Component)

Add a single child to this node

Parameters:

child (Component) – The child to be added

Raises:

ComponentError – Child already in tree

add_children(children: ComponentT | list[ComponentT] | None, *, merge_trees: bool = False)

Add multiple children to this node

Parameters:
  • children (ComponentT | list[ComponentT] | None) – The children to be added

  • merge_trees (bool)

Return type:

This component.

Raises:

ComponentError – Duplicate entries

prune_child(name: str)

Remove the child with the given name, and all its children.

Parameters:

name (str)

class bluemira.base.components.PhysicalComponent(name: str, shape: bluemira.geometry.base.BluemiraGeoT, material: matproplib.material.Material | None = None, parent: ComponentT | None = None, children: list[ComponentT] | None = None)

Bases: Component

Inheritance diagram of bluemira.base.components.PhysicalComponent

A physical component. It includes shape and materials.

Parameters:
  • name (str) – Name of the PhysicalComponent

  • shape (bluemira.geometry.base.BluemiraGeoT) – Geometry of the PhysicalComponent

  • material (matproplib.material.Material | None) – Material of the PhysicalComponent

  • parent (ComponentT | None) – Parent of the PhysicalComponent

  • children (list[ComponentT] | None) – Children of the PhysicalComponent

_shape
_material = None
copy(parent: ComponentT | None = None) ComponentT

Copies this component and its children (recursively) and sets parent as this copy’s parent. This only creates copies of each Component, the shape and material instances (for a PhysicalComponent for ex.) are shared (i.e. are the same instance).

Parameters:

parent (ComponentT | None) – The component to set as the copy’s parent

Returns:

The copied component

Return type:

self_copy

property shape: bluemira.geometry.base.BluemiraGeoT

The geometric shape of the Component.

Return type:

bluemira.geometry.base.BluemiraGeoT

property material: matproplib.material.Material | None

The material that the Component is built from.

Return type:

matproplib.material.Material | None

class bluemira.base.components.MagneticComponent(name: str, shape: bluemira.geometry.base.BluemiraGeoT, material: matproplib.material.Material | None = None, conductor: Any = None, parent: ComponentT | None = None, children: list[ComponentT] | None = None)

Bases: PhysicalComponent

Inheritance diagram of bluemira.base.components.MagneticComponent

A magnetic component. It includes a shape, a material, and a source conductor.

Parameters:
  • name (str)

  • shape (bluemira.geometry.base.BluemiraGeoT)

  • material (matproplib.material.Material | None)

  • conductor (Any)

  • parent (ComponentT | None)

  • children (list[ComponentT] | None)

property conductor

The conductor used by current-carrying filaments.

copy(parent: ComponentT | None = None) ComponentT

Copies this component and its children (recursively) and sets parent as this copy’s parent. This only creates copies of each Component, the shape and material instances (for a PhysicalComponent for ex.) are shared (i.e. are the same instance).

Parameters:

parent (ComponentT | None) – The component to set as the copy’s parent

Returns:

The copied component

Return type:

self_copy

bluemira.base.components.get_properties_from_components(comps: ComponentT | collections.abc.Iterable[ComponentT], properties: str | collections.abc.Sequence[str], *, extract: bool = True) tuple[list[Any], Ellipsis] | list[Any] | Any

Get properties from Components

Parameters:
  • comps (ComponentT | collections.abc.Iterable[ComponentT]) – A component or list of components

  • properties (str | collections.abc.Sequence[str]) – properties to collect

  • extract (bool)

Returns:

If multiple properties specified returns a tuple of the list of properties, otherwise returns a list of the property. If only one node has the property returns the value(s).

Return type:

property_lists