bluemira.base.tools =================== .. py:module:: bluemira.base.tools .. autoapi-nested-parse:: Tool function and classes for the bluemira base module. Attributes ---------- .. autoapisummary:: bluemira.base.tools._T Classes ------- .. autoapisummary:: bluemira.base.tools.FilterMaterial bluemira.base.tools.CADConstructionType bluemira.base.tools.ConstructionParams bluemira.base.tools.ConstructionParamValues Functions --------- .. autoapisummary:: bluemira.base.tools._timing bluemira.base.tools.create_compound_from_component bluemira.base.tools.circular_pattern_xyz_components bluemira.base.tools.copy_and_filter_component bluemira.base.tools.save_components_cad bluemira.base.tools.show_components_cad bluemira.base.tools.plot_component_dim bluemira.base.tools._construct_comp_manager_physical_comps bluemira.base.tools._group_physical_components_by_material bluemira.base.tools._build_compounds_from_mat_map bluemira.base.tools.build_comp_manager_save_xyz_cad_tree bluemira.base.tools.build_comp_manager_show_cad_tree bluemira.base.tools.serialise_component Module Contents --------------- .. py:data:: _T .. py:class:: 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 :param keep_material: materials to include :param reject_material: materials to exclude .. py:attribute:: __slots__ :value: ('keep_material', 'reject_material') .. py:method:: __call__(node: bluemira.base.components.ComponentT) -> bool Filter node based on material include and exclude rules. :param node: The node to filter. :returns: True if the node should be kept, False otherwise. .. py:method:: __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 .. py:method:: _apply_filters(material: matproplib.material.Material | tuple[matproplib.material.Material]) -> bool .. py:class:: CADConstructionType(*args, **kwds) Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: bluemira.base.tools.CADConstructionType :parts: 1 :private-bases: Enum for construction types for components .. py:attribute:: PATTERN_RADIAL :value: 'PATTERN_RADIAL' .. py:attribute:: REVOLVE_XZ :value: 'REVOLVE_XZ' .. py:attribute:: NO_OP :value: 'NO_OP' .. py:class:: ConstructionParams Bases: :py:obj:`TypedDict` .. autoapi-inheritance-diagram:: bluemira.base.tools.ConstructionParams :parts: 1 :private-bases: Parameters for the construction of CAD. .. py:attribute:: with_components :type: NotRequired[list[bluemira.base.reactor.ComponentManager] | None] .. py:attribute:: without_components :type: NotRequired[list[bluemira.base.reactor.ComponentManager] | None] .. py:attribute:: component_filter :type: NotRequired[collections.abc.Callable[[bluemira.base.components.Component], bool] | None] .. py:attribute:: n_sectors :type: NotRequired[int | None] .. py:attribute:: total_sectors :type: NotRequired[int | None] .. py:attribute:: group_by_materials :type: NotRequired[bool] .. py:attribute:: disable_composite_grouping :type: NotRequired[bool] .. py:class:: ConstructionParamValues Parameters for the construction of CAD. .. py:attribute:: with_components :type: list[bluemira.base.reactor.ComponentManager] | None .. py:attribute:: without_components :type: list[bluemira.base.reactor.ComponentManager] | None .. py:attribute:: component_filter :type: collections.abc.Callable[[bluemira.base.components.Component], bool] | None .. py:attribute:: n_sectors :type: int .. py:attribute:: total_sectors :type: int .. py:attribute:: group_by_materials :type: bool .. py:attribute:: disable_composite_grouping :type: bool .. py:method:: empty() -> ConstructionParamValues :classmethod: Create an empty ConstructionParamValues object. :returns: The empty ConstructionParamValues object .. py:method:: from_construction_params(construction_params: ConstructionParams | None) :classmethod: Create the ConstructionParamValues from the ConstructionParams. :param construction_params: Construction parameters to extract values from. :returns: The ConstructionParamValues object .. py:function:: _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. :param func: Function to time :param timing_prefix: Prefix to print before time duration :param info_str: information to print before running function :param debug_info_str: send info_str to debug logger instead of info logger :returns: Wrapped function .. py:function:: 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. :param comp: Component to create the compound from :returns: The BluemiraCompound component .. py:function:: 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. :param comp: Component to pattern :param n_sectors: Number of sectors to pattern :param degree: Degree of the pattern :returns: The component with the circular pattern applied :raises ValueError: If no xyz components are found in the component. .. py:function:: 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. :param comp: Component to copy and filter :param dim: Dimension to filter (to keep) :param component_filter: Filter to apply to the components :returns: The copied and filtered component .. py:function:: 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. :param components: Components to save :param filename: The full filename path to save the CAD to :param cad_format: CAD file format .. py:function:: show_components_cad(components: bluemira.base.components.ComponentT | collections.abc.Iterable[bluemira.base.components.ComponentT], **kwargs) Show the CAD build of the component. .. py:function:: plot_component_dim(dim: str, component: bluemira.base.components.ComponentT, *, show: bool = True, **kwargs) Plot the component in the specified dimension. .. py:function:: _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 .. py:function:: _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 .. py:function:: _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 .. py:function:: 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. :param comp_manager: Component manager :param construction_params: Construction parameters to use for CAD building. :returns: The constructed component manager component for CAD saving .. py:function:: 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. :param comp_manager: Component manager :param dim: Dimension to build the CAD in :param construction_params: Parameters for the construction of CAD. :returns: The constructed component manager component for CAD showing .. py:function:: serialise_component(comp: bluemira.base.components.Component) -> dict Serialise a Component object. :param comp: The Component object to serialise :returns: The serialised Component object as a dictionary