Skip to content

Commit

Permalink
minor changes, testing
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfunk committed Dec 4, 2024
1 parent 47793b2 commit ddcc735
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
6 changes: 3 additions & 3 deletions bluemira/base/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def __init__(
children: list[ComponentT] | None = None,
):
super().__init__(name, parent, children)
self.shape = shape
self.material = material
self._shape = shape
self._material = material

def copy(
self,
Expand Down Expand Up @@ -459,7 +459,7 @@ def shape(self, value: BluemiraGeoT):
self._shape = value

@property
def material(self) -> Material:
def material(self) -> Material | None:
"""
The material that the Component is built from.
"""
Expand Down
69 changes: 43 additions & 26 deletions bluemira/base/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
Tool function and classes for the bluemira base module.
"""

from __future__ import annotations

import time
from collections.abc import Callable, Iterable
from enum import Enum
from functools import wraps
from typing import TypeVar
from typing import TYPE_CHECKING, TypeVar

import bluemira.codes._freecadapi as cadapi
from bluemira.base.components import (
Component,
ComponentT,
Expand All @@ -25,15 +25,17 @@
from bluemira.builders.tools import (
circular_pattern_component,
compound_from_components,
connect_components,
)
from bluemira.display.displayer import ComponentDisplayer
from bluemira.display.plotter import ComponentPlotter
from bluemira.geometry.compound import BluemiraCompound
from bluemira.geometry.tools import save_cad, serialise_shape

# if TYPE_CHECKING:
# from bluemira.base.reactor import ComponentManager
if TYPE_CHECKING:
from collections.abc import Callable, Iterable

import bluemira.codes._freecadapi as cadapi
from bluemira.base.reactor import ComponentManager


_T = TypeVar("_T")
Expand Down Expand Up @@ -209,7 +211,7 @@ def plot_component_dim(


def build_comp_manager_save_xyz_cad_tree(
comp_manager,
comp_manager: ComponentManager,
component_filter: Callable[[ComponentT], bool] | None,
n_sectors: int,
sector_degrees: int,
Expand All @@ -225,34 +227,49 @@ def build_comp_manager_save_xyz_cad_tree(
component_filter:
Filter to apply to the components
"""
const_type = comp_manager.cad_construction_type()
if isinstance(const_type, PhysicalComponent):
# you will still need to extract and compunidfy per material
return const_type

manager_comp = comp_manager.component()
filtered_comp = copy_and_filter_component(
cad_const_type = comp_manager.cad_construction_type()
manager_comp = (
cad_const_type
if isinstance(cad_const_type, Component)
else comp_manager.component()
)
copy_and_filtered = copy_and_filter_component(
manager_comp,
"xyz",
component_filter,
)
filtered_comp = circular_pattern_xyz_components(
filtered_comp,
n_sectors,
degree=sector_degrees,
)
patterned = copy_and_filtered
if not isinstance(cad_const_type, Component):
patterned = circular_pattern_xyz_components(
copy_and_filtered,
n_sectors,
degree=sector_degrees,
)

match const_type:
case CADConstructionType.CONNECT:
filtered_comp = connect_components([filtered_comp], manager_comp.name)
case CADConstructionType.COMPOUND:
filtered_comp = compound_from_components([filtered_comp], manager_comp.name)
# now you have the full patterned xyz component of n_sectors,
# you want create a mapping between because unique material name
# and the PhysicalComponent's with that material

return filtered_comp
# is there a better way to get physical comps from the trree?
phy_comps = patterned.leaves
mat_to_comps_map = {}
for phy_comp in phy_comps:
mat_name = "no-mat" if phy_comp.material is None else phy_comp.material.name
if mat_name not in mat_to_comps_map:
mat_to_comps_map[mat_name] = []
mat_to_comps_map[mat_name].append(phy_comp)

return_comp = Component(name=manager_comp.name)
return_comp.children = [
compound_from_components(comps, f"{manager_comp.name}_{mat_name}")
for mat_name, comps in mat_to_comps_map.items()
]

return return_comp


def build_comp_manager_show_cad_tree(
comp_manager,
comp_manager: ComponentManager,
dim: str,
component_filter: Callable[[ComponentT], bool] | None,
n_sectors: int,
Expand Down
13 changes: 7 additions & 6 deletions bluemira/builders/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import numpy as np
from anytree import PreOrderIter

from bluemira.base.components import Component, PhysicalComponent
from bluemira.base.components import (
Component,
PhysicalComponent,
get_properties_from_components,
)
from bluemira.base.error import BuilderError, ComponentError
from bluemira.builders._varied_offset import varied_offset
from bluemira.display.palettes import ColorPalette
Expand Down Expand Up @@ -121,11 +125,8 @@ def compound_from_components(
-------
PhysicalComponent
"""
faux_parent_for_iter = Component(f"{name} X")
faux_parent_for_iter.children = components
itr = PreOrderIter(faux_parent_for_iter)
phy_comps_shape = [comp.shape for comp in itr if isinstance(comp, PhysicalComponent)]
comp = make_compound(phy_comps_shape, name)
shapes = get_properties_from_components(components, ("shape"))
comp = make_compound(shapes, name)
return PhysicalComponent(name, comp, material=material)


Expand Down
2 changes: 2 additions & 0 deletions eudemo/eudemo/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ def build_radiation_plugs(

reactor.save_cad()

exit()

if reactor_config.config_for("Neutronics").get("enabled", False):
reactor.neutronics = NeutronicsManager(
*run_neutronics(
Expand Down

0 comments on commit ddcc735

Please sign in to comment.