Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/sample_blanket.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class": "HCPB_blanket",
"class": "HCPBBlanket",
"geometry": {
"pin spacing": 135,
"pin vertical offset": 0,
Expand All @@ -23,7 +23,7 @@
},
"components": {
"pin": {
"class": "pin",
"class": "PinAssembly",
"material": {
"cladding": "EUROFER",
"pressure tube": "EUROFER",
Expand Down Expand Up @@ -57,7 +57,7 @@
}
},
"first_wall": {
"class": "first_wall",
"class": "FirstWallComponent",
"material": "Tungsten",
"geometry": {
"inner width": 1480,
Expand All @@ -78,7 +78,7 @@
}
},
"front_rib": {
"class": "front_rib",
"class": "FrontRib",
"geometry": {
"thickness": 30,
"side channel width": 10,
Expand All @@ -87,7 +87,7 @@
}
},
"back_rib": {
"class": "back_rib",
"class": "BackRib",
"geometry": {
"thickness": 60,
"side channel width": 10,
Expand All @@ -96,7 +96,7 @@
}
},
"coolant_outlet_plenum": {
"class": "coolant_outlet_plenum",
"class": "CoolantOutletPlenum",
"geometry": {
"length": 120,
"width": 1000,
Expand Down
2 changes: 1 addition & 1 deletion examples/sample_blanket_ring.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class": "blanket_ring",
"class": "BlanketRingAssembly",
"geometry": {
"minimum radius": 580
},
Expand Down
2 changes: 1 addition & 1 deletion examples/sample_blanket_shell.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class": "blanket_shell",
"class": "BlanketShellAssembly",
"geometry": {
"pin spacing": 135,
"vertical offset": 0,
Expand Down
2 changes: 1 addition & 1 deletion examples/sample_first_wall.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class": "first_wall",
"class": "FirstWallComponent",
"material": "Tungsten",
"geometry": {
"inner width": 1480,
Expand Down
6 changes: 3 additions & 3 deletions examples/sample_mini_blanket.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"class": "blanket_shell",
"class": "BlanketShellAssembly",
"geometry": {
"pin spacing": 135,
"vertical offset": 0,
"horizontal offset": 0
},
"components": {
"first_wall": {
"class": "first_wall",
"class": "FirstWallComponent",
"material": "Tungsten",
"geometry": {
"inner width": 480,
Expand All @@ -19,7 +19,7 @@
}
},
"pin": {
"class": "pin",
"class": "PinAssembly",
"material": {
"cladding": "Steel",
"pressure tube": "Steel",
Expand Down
10 changes: 5 additions & 5 deletions examples/sample_morphology.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"class": "neutron_test_facility",
"class": "NeutronTestFacility",
"morphology": "overlap",
"components": [
{
"class" : "source",
"class" : "SourceAssembly",
"filepath": "./dummy_source.stp",
"group": "neutron_source",
"manufacturer": "blobcorp",
Expand All @@ -15,10 +15,10 @@
},

{
"class": "room",
"class": "RoomAssembly",
"components": [
{
"class": "surrounding_walls",
"class": "SurroundingWallsComponent",
"material": "SS",
"air": "some_gas",
"geometry": {
Expand All @@ -28,7 +28,7 @@

},
{
"class": "wall",
"class": "WallComponent",
"material": "SS",
"geometry": {
"thickness": 5,
Expand Down
2 changes: 1 addition & 1 deletion examples/sample_pin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class": "pin",
"class": "PinAssembly",
"material": {
"cladding": "EUROFER",
"pressure tube": "EUROFER",
Expand Down
41 changes: 27 additions & 14 deletions src/hypnos/assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from hypnos.geometry import Vertex, arctan
from hypnos.cubit_functions import to_bodies
from hypnos.constants import (
CLASS_MAPPING,
NEUTRON_TEST_FACILITY_REQUIREMENTS,
ROOM_REQUIREMENTS,
BLANKET_REQUIREMENTS,
Expand Down Expand Up @@ -177,7 +176,7 @@ def get_components_of_class(self, classes: list) -> list:
return component_list

def set_mesh_size(self, component_classes: list, size: int):
component_classes = [globals()[CLASS_MAPPING[classname]] for classname in component_classes]
component_classes = [classdict()[classname] for classname in component_classes]
components = self.get_components_of_class(component_classes)
for component in components:
if isinstance(component, SimpleComponent):
Expand Down Expand Up @@ -412,7 +411,7 @@ def __init__(self, json_object):
# Take out any walls from component list
json_walls = []
for json_component in component_list:
if json_component["class"] == "wall":
if json_component["class"] == "WallComponent":
json_walls.append(json_component)
component_list.remove(json_component)
json_object["components"] = component_list
Expand Down Expand Up @@ -869,17 +868,17 @@ def setup_assembly(self):

def __add_component_attributes(self):
for component in self.component_list:
if component["class"] == "first_wall":
if component["class"] == "FirstWallComponent":
self.first_wall_geometry = component["geometry"]
self.first_wall_material = component["material"]
elif component["class"] == "pin":
elif component["class"] == "PinAssembly":
self.breeder_materials = component["material"]
self.breeder_geometry = component["geometry"]
elif component["class"] == "front_rib":
elif component["class"] == "FrontRib":
self.front_ribs_geometry = component["geometry"]
elif component["class"] == "back_rib":
elif component["class"] == "BackRib":
self.back_ribs_geometry = component["geometry"]
elif component["class"] == "coolant_outlet_plenum":
elif component["class"] == "CoolantOutletPlenum":
self.cop_geometry = component["geometry"]

def __dict_with_height(self):
Expand Down Expand Up @@ -1129,10 +1128,8 @@ def get_all_geometries_from_components(component_list) -> list[CubitInstance]:
for component in component_list:
if isinstance(component, CubitInstance):
instances.append(component)
elif isinstance(component, SimpleComponent):
instances += component.subcomponents
elif isinstance(component, GenericComponentAssembly):
instances += component.get_all_geometries()
elif isinstance(component, ComponentBase):
instances += component.get_geometries()
return instances


Expand Down Expand Up @@ -1187,8 +1184,24 @@ def construct(json_object: dict, *args):

Returns
-------
SimpleComponent | GenericComponentAssembly
ComponentBase
Instantiated python class
'''
constructor = globals()[CLASS_MAPPING[json_object["class"]]]
constructor = classdict(ComponentBase)[json_object["class"]]
return constructor(json_object, *args)


# it take so long to run :(
def classdict(cls):
'''Find all subclasses recursively.

Returns
-------
dict
{"Class": Class}
'''
return_dict = {}
for subcls in cls.__subclasses__():
return_dict[subcls.__name__] = subcls
return_dict.update(classdict(subcls))
return return_dict
Comment on lines +1194 to +1207
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is taking a long time to run, maybe let's put in an issue to consider ways to make it more efficient. Python for loops are notoriously slow, but that said it's unlikely to be the bottleneck in the high fidelity simulation workflows hypnos is supporting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure it's that slow, it just feels inefficient. Will add an issue just to keep note though.

7 changes: 0 additions & 7 deletions src/hypnos/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ def classname(self, new_classname):
def classname(self):
del self._classname

@classmethod
def from_classname(cls, classname, params):
for toplvl in cls.__subclasses__():
for construct_lvl in toplvl.__subclasses__():
if construct_lvl.classname == classname:
return construct_lvl(params)

def check_sanity(self):
'''Check whether the parameters supplied to this instance are physical
'''
Expand Down
44 changes: 9 additions & 35 deletions src/hypnos/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,17 @@
'''

# required components for assemblies to be generated
NEUTRON_TEST_FACILITY_REQUIREMENTS = ["room", "source"]
BLANKET_REQUIREMENTS = ["breeder", "structure"]
ROOM_REQUIREMENTS = ["blanket", "surrounding_walls"]
BLANKET_SHELL_REQUIREMENTS = ["first_wall", "pin"]
NEUTRON_TEST_FACILITY_REQUIREMENTS = ["RoomAssembly", "SourceAssembly"]
BLANKET_REQUIREMENTS = ["BreederComponent", "StructureComponent"]
ROOM_REQUIREMENTS = ["BlanketComponent", "SurroundingWallsComponent"]
BLANKET_SHELL_REQUIREMENTS = ["FirstWallComponent", "PinAssembly"]
HCPB_BLANKET_REQUIREMENTS = [
"first_wall",
"pin",
"front_rib",
"back_rib",
"coolant_outlet_plenum"
"FirstWallComponent",
"PinAssembly",
"FrontRib",
"BackRib",
"CoolantOutletPlenum"
]

# LEGACY - classes according to what make_geometry subfunction(?) needs to be called
BLOB_CLASSES = ["complex", "breeder", "structure", "air"]
ROOM_CLASSES = ["surrounding_walls"]
WALL_CLASSES = ["wall"]

# LEGACY - currently only supports exclusive, inclusive, and overlap
FACILITY_MORPHOLOGIES = ["exclusive", "inclusive", "overlap", "wall"]

# mapping from json class names to python class names
CLASS_MAPPING = {
"complex": "ComplexComponent",
"external": "ExternalComponentAssembly",
"source": "SourceAssembly",
"neutron_test_facility": "NeutronTestFacility",
"blanket": "BlanketAssembly",
"room": "RoomAssembly",
"surrounding_walls": "SurroundingWallsComponent",
"breeder": "BreederComponent",
"structure": "StructureComponent",
"pin": "PinAssembly",
"cladding": "CladdingComponent",
"pressure_tube": "PressureTubeComponent",
"multiplier": "MultiplierComponent",
"first_wall": "FirstWallComponent",
"blanket_shell": "BlanketShellAssembly",
"blanket_ring": "BlanketRingAssembly",
"HCPB_blanket": "HCPBBlanket"
}
Loading