bluemira.base.tools
Tool function and classes for the bluemira base module.
Attributes
Classes
Filter nodes by material |
|
Enum for construction types for components |
|
Parameters for the construction of CAD. |
|
Parameters for the construction of CAD. |
Functions
|
Time a function and push to logging. |
Creates a BluemiraCompound from the shapes at the root of the component's |
|
Create a circular pattern of components in the XY plane. |
|
Copies a component (deeply) then filters |
|
|
Save the CAD build of the component. |
|
Show the CAD build of the component. |
|
Plot the component in the specified dimension. |
Construct the compoent using the construction type |
|
|
Group the physical components by material name. |
Build the compounds from the material to components map. |
|
Build the CAD of the component manager's components. |
|
Build the CAD of the component manager's components |
|
|
Serialise a Component object. |
Module Contents
- bluemira.base.tools._T
- class bluemira.base.tools.FilterMaterial(keep_material: type[matproplib.material.Material] | tuple[type[matproplib.material.Material]] | None = None, reject_material: type[matproplib.material.Material] | tuple[type[matproplib.material.Material]] | None = Void)
Filter nodes by material
- Parameters:
keep_material (type[matproplib.material.Material] | tuple[type[matproplib.material.Material]] | None) – materials to include
reject_material (type[matproplib.material.Material] | tuple[type[matproplib.material.Material]] | None) – materials to exclude
- __slots__ = ('keep_material', 'reject_material')
- __call__(node: bluemira.base.components.ComponentT) bool
Filter node based on material include and exclude rules.
- Parameters:
node (bluemira.base.components.ComponentT) – The node to filter.
- Returns:
True if the node should be kept, False otherwise.
- Return type:
bool
- __setattr__(name: str, value: Any)
Override setattr to force immutability
This method makes the class nearly immutable as no new attributes can be modified or added by standard methods.
See #2236 discussion_r1191246003 for further details
- Raises:
AttributeError – FilterMaterial is immutable
- Parameters:
name (str)
value (Any)
- _apply_filters(material: matproplib.material.Material | tuple[matproplib.material.Material]) bool
- Parameters:
material (matproplib.material.Material | tuple[matproplib.material.Material])
- Return type:
bool
- class bluemira.base.tools.CADConstructionType(*args, **kwds)
Bases:
enum.EnumEnum for construction types for components
- PATTERN_RADIAL = 'PATTERN_RADIAL'
- REVOLVE_XZ = 'REVOLVE_XZ'
- NO_OP = 'NO_OP'
- class bluemira.base.tools.ConstructionParams
Bases:
TypedDictParameters for the construction of CAD.
- with_components: NotRequired[list[bluemira.base.reactor.ComponentManager] | None]
- without_components: NotRequired[list[bluemira.base.reactor.ComponentManager] | None]
- component_filter: NotRequired[collections.abc.Callable[[bluemira.base.components.Component], bool] | None]
- n_sectors: NotRequired[int | None]
- total_sectors: NotRequired[int | None]
- group_by_materials: NotRequired[bool]
- disable_composite_grouping: NotRequired[bool]
- class bluemira.base.tools.ConstructionParamValues
Parameters for the construction of CAD.
- with_components: list[bluemira.base.reactor.ComponentManager] | None
- without_components: list[bluemira.base.reactor.ComponentManager] | None
- component_filter: collections.abc.Callable[[bluemira.base.components.Component], bool] | None
- n_sectors: int
- total_sectors: int
- group_by_materials: bool
- disable_composite_grouping: bool
- classmethod empty() ConstructionParamValues
Create an empty ConstructionParamValues object.
- Returns:
The empty ConstructionParamValues object
- Return type:
- classmethod from_construction_params(construction_params: ConstructionParams | None)
Create the ConstructionParamValues from the ConstructionParams.
- Parameters:
construction_params (ConstructionParams | None) – Construction parameters to extract values from.
- Returns:
The ConstructionParamValues object
- bluemira.base.tools._timing(func: collections.abc.Callable[Ellipsis, _T], timing_prefix: str, info_str: str = '', *, debug_info_str: bool = False) collections.abc.Callable[Ellipsis, _T]
Time a function and push to logging.
- Parameters:
func (collections.abc.Callable[Ellipsis, _T]) – Function to time
timing_prefix (str) – Prefix to print before time duration
info_str (str) – information to print before running function
debug_info_str (bool) – send info_str to debug logger instead of info logger
- Returns:
Wrapped function
- Return type:
collections.abc.Callable[Ellipsis, _T]
- bluemira.base.tools.create_compound_from_component(comp: bluemira.base.components.Component) bluemira.geometry.compound.BluemiraCompound
Creates a BluemiraCompound from the shapes at the root of the component’s component tree.
- Parameters:
comp (bluemira.base.components.Component) – Component to create the compound from
- Returns:
The BluemiraCompound component
- Return type:
- bluemira.base.tools.circular_pattern_xyz_components(comp: bluemira.base.components.Component, n_sectors: int, degree: float) bluemira.base.components.Component
Create a circular pattern of components in the XY plane.
- Parameters:
comp (bluemira.base.components.Component) – Component to pattern
n_sectors (int) – Number of sectors to pattern
degree (float) – Degree of the pattern
- Returns:
The component with the circular pattern applied
- Raises:
ValueError – If no xyz components are found in the component.
- Return type:
- bluemira.base.tools.copy_and_filter_component(comp: bluemira.base.components.Component, dim: str, component_filter: collections.abc.Callable[[bluemira.base.components.ComponentT], bool] | None) bluemira.base.components.Component
Copies a component (deeply) then filters and returns the resultant component tree.
- Parameters:
comp (bluemira.base.components.Component) – Component to copy and filter
dim (str) – Dimension to filter (to keep)
component_filter (collections.abc.Callable[[bluemira.base.components.ComponentT], bool] | None) – Filter to apply to the components
- Returns:
The copied and filtered component
- Return type:
- bluemira.base.tools.save_components_cad(components: bluemira.base.components.ComponentT | collections.abc.Iterable[bluemira.base.components.ComponentT], filename: pathlib.Path, cad_format: str | bluemira.codes._freecadapi.CADFileType = 'stp', **kwargs)
Save the CAD build of the component.
- Parameters:
components (bluemira.base.components.ComponentT | collections.abc.Iterable[bluemira.base.components.ComponentT]) – Components to save
filename (pathlib.Path) – The full filename path to save the CAD to
cad_format (str | bluemira.codes._freecadapi.CADFileType) – CAD file format
- bluemira.base.tools.show_components_cad(components: bluemira.base.components.ComponentT | collections.abc.Iterable[bluemira.base.components.ComponentT], **kwargs)
Show the CAD build of the component.
- Parameters:
components (bluemira.base.components.ComponentT | collections.abc.Iterable[bluemira.base.components.ComponentT])
- bluemira.base.tools.plot_component_dim(dim: str, component: bluemira.base.components.ComponentT, *, show: bool = True, **kwargs)
Plot the component in the specified dimension.
- Parameters:
dim (str)
component (bluemira.base.components.ComponentT)
show (bool)
- bluemira.base.tools._construct_comp_manager_physical_comps(comp_manager: bluemira.base.reactor.ComponentManager, construction_params: ConstructionParamValues) tuple[list[bluemira.base.components.PhysicalComponent], str]
Construct the compoent using the construction type and return the PhysicalComponents.
- Returns:
A List of constructed PhysicalComponent’s and the name to associate with them
- Raises:
ValueError – If no components were constructed
- Parameters:
comp_manager (bluemira.base.reactor.ComponentManager)
construction_params (ConstructionParamValues)
- Return type:
tuple[list[bluemira.base.components.PhysicalComponent], str]
- bluemira.base.tools._group_physical_components_by_material(phy_comps: list[bluemira.base.components.PhysicalComponent]) dict[str, list[bluemira.base.components.PhysicalComponent]]
Group the physical components by material name.
- Returns:
A dictionary of material name to list of physical components
- Parameters:
phy_comps (list[bluemira.base.components.PhysicalComponent])
- Return type:
dict[str, list[bluemira.base.components.PhysicalComponent]]
- bluemira.base.tools._build_compounds_from_mat_map(mat_to_comps_map: dict[str, list[bluemira.base.components.PhysicalComponent]], manager_name: str) list[bluemira.base.components.PhysicalComponent]
Build the compounds from the material to components map.
- Returns:
A list of compounds
- Parameters:
mat_to_comps_map (dict[str, list[bluemira.base.components.PhysicalComponent]])
manager_name (str)
- Return type:
- bluemira.base.tools.build_comp_manager_save_xyz_cad_tree(comp_manager: bluemira.base.reactor.ComponentManager, construction_params: ConstructionParamValues) bluemira.base.components.Component
Build the CAD of the component manager’s components.
- Parameters:
comp_manager (bluemira.base.reactor.ComponentManager) – Component manager
construction_params (ConstructionParamValues) – Construction parameters to use for CAD building.
- Returns:
The constructed component manager component for CAD saving
- Return type:
- bluemira.base.tools.build_comp_manager_show_cad_tree(comp_manager: bluemira.base.reactor.ComponentManager, dim: str, construction_params: ConstructionParamValues) bluemira.base.components.Component
Build the CAD of the component manager’s components and save the CAD to a file.
- Parameters:
comp_manager (bluemira.base.reactor.ComponentManager) – Component manager
dim (str) – Dimension to build the CAD in
construction_params (ConstructionParamValues) – Parameters for the construction of CAD.
- Returns:
The constructed component manager component for CAD showing
- Return type:
- bluemira.base.tools.serialise_component(comp: bluemira.base.components.Component) dict
Serialise a Component object.
- Parameters:
comp (bluemira.base.components.Component) – The Component object to serialise
- Returns:
The serialised Component object as a dictionary
- Return type:
dict