def _make_divertor(self): if self.divertor_position == "upper": divertor_height = self._blanket_rear_wall_end_height elif self.divertor_position == "lower": divertor_height = -self._blanket_rear_wall_end_height # # used as an intersect when making the divertor self._blanket_fw_rear_wall_envelope = paramak.BlanketFP( plasma=self._plasma, thickness=self.firstwall_radial_thickness + self.blanket_radial_thickness + self.blanket_rear_wall_radial_thickness, offset_from_plasma=[ self.major_radius - self.minor_radius, self.plasma_gap_vertical_thickness, self.outer_plasma_gap_radial_thickness, self.plasma_gap_vertical_thickness, # self.inner_plasma_gap_radial_thickness], self.major_radius - self.minor_radius ], start_angle=-179, stop_angle=179, rotation_angle=self.rotation_angle, ) self._divertor = paramak.RotateStraightShape( points=[(self._divertor_start_radius, 0), (self._divertor_end_radius, 0), (self._divertor_end_radius, divertor_height), (self._divertor_start_radius, divertor_height)], intersect=self._blanket_fw_rear_wall_envelope, stp_filename="divertor.stp", stl_filename="divertor.stl", name="divertor", material_tag="divertor_mat", rotation_angle=self.rotation_angle) self.shapes_and_components.append(self._divertor) blanket_cutter = paramak.RotateStraightShape( points=[(self._divertor_start_radius, 0), (self._divertor_end_radius, 0), (self._divertor_end_radius, divertor_height), (self._divertor_start_radius, divertor_height)], stp_filename="divertor.stp", stl_filename="divertor.stl", name="divertor", material_tag="divertor_mat", rotation_angle=self.rotation_angle) self._firstwall.solid = self._firstwall.solid.cut(blanket_cutter.solid) self._blanket.solid = self._blanket.solid.cut(blanket_cutter.solid) self._blanket_rear_wall.solid = self._blanket_rear_wall.solid.cut( blanket_cutter.solid) self.shapes_and_components.append(self._firstwall) self.shapes_and_components.append(self._blanket) self.shapes_and_components.append(self._blanket_rear_wall)
def _make_rear_blanket_wall(self): self._outboard_rear_blanket_wall_upper = paramak.RotateStraightShape( points=[ (self._center_column_shield_end_radius, self._blanket_rear_wall_start_height), (self._center_column_shield_end_radius, self._blanket_rear_wall_end_height), ( max(self._inboard_firstwall.points)[0], self._blanket_rear_wall_end_height, ), ( max(self._inboard_firstwall.points)[0], self._blanket_rear_wall_start_height, ), ], rotation_angle=self.rotation_angle, ) self._outboard_rear_blanket_wall_lower = paramak.RotateStraightShape( points=[ (self._center_column_shield_end_radius, -self._blanket_rear_wall_start_height), (self._center_column_shield_end_radius, -self._blanket_rear_wall_end_height), ( max(self._inboard_firstwall.points)[0], -self._blanket_rear_wall_end_height, ), ( max(self._inboard_firstwall.points)[0], -self._blanket_rear_wall_start_height, ), ], rotation_angle=self.rotation_angle, ) self._outboard_rear_blanket_wall = paramak.BlanketFP( plasma=self._plasma, start_angle=90, stop_angle=-90, offset_from_plasma=self.outer_plasma_gap_radial_thickness + self.firstwall_radial_thickness + self.outboard_blanket_radial_thickness, thickness=self.blanket_rear_wall_radial_thickness, rotation_angle=self.rotation_angle, stp_filename="outboard_rear_blanket_wall.stp", stl_filename="outboard_rear_blanket_wall.stl", name="outboard_rear_blanket_wall", material_tag="blanket_rear_wall_mat", union=[ self._outboard_rear_blanket_wall_upper, self._outboard_rear_blanket_wall_lower ], ) return self._outboard_rear_blanket_wall
def test_compound_in_shapes(self): shape1 = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)]) shape2 = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)]) shape3 = paramak.Shape() shape3.solid = cq.Compound.makeCompound( [a.val() for a in [shape1.solid, shape2.solid]]) test_reactor = paramak.Reactor([shape3]) assert test_reactor.solid is not None
def test_largest_dimention(self): test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_reactor = paramak.Reactor([test_shape]) assert pytest.approx(test_reactor.largest_dimension, rel=0.1 == 20) test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (30, 20)]) test_shape.rotation_angle = 360 test_reactor = paramak.Reactor([test_shape]) assert pytest.approx(test_reactor.largest_dimension, rel=0.1 == 30)
def test_stl_filename_duplication_rotate_straight(): """checks ValueError is raised when RotateStraightShapes with duplicate stl filenames (defaults) are added""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) test_shape2 = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_shape.create_solid() my_reactor = paramak.Reactor([test_shape, test_shape2]) my_reactor.export_stl()
def simulate_cylinder_cask_cad(self, material, source, height, outer_radius, thickness, batches, particles): """Makes a CAD cask geometry runs a simulation and returns the result""" top_cap_cell = paramak.RotateStraightShape( stp_filename='top_cap_cell.stp', material_tag='test_mat', points=[ (outer_radius, height * 0.5), (outer_radius, (height * 0.5) + thickness), (0, (height * 0.5) + thickness), (0, height * 0.5), ], ) bottom_cap_cell = paramak.RotateStraightShape( stp_filename='bottom_cap_cell.stp', material_tag='test_mat', points=[ (outer_radius, -height * 0.5), (outer_radius, (-height * 0.5) - thickness), (0, (-height * 0.5) - thickness), (0, -height * 0.5), ]) cylinder_cell = paramak.CenterColumnShieldCylinder( height=height, inner_radius=outer_radius - thickness, outer_radius=outer_radius, material_tag='test_mat', ) my_geometry = paramak.Reactor( [cylinder_cell, bottom_cap_cell, top_cap_cell]) my_model = paramak.NeutronicsModel( geometry=my_geometry, source=source, simulation_batches=batches, simulation_particles_per_batch=particles, materials={'test_mat': material}, cell_tallies=['heating']) my_model.simulate(method='pymoab') # scaled from MeV to eV return my_model.results['test_mat_heating']['MeV per source particle'][ 'result'] * 1e6
def test_shapes_and_components(self): test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) def incorrect_shapes_and_components(): paramak.Reactor(test_shape) self.assertRaises(ValueError, incorrect_shapes_and_components)
def test_moab_instance_creation(self): """passes three points on a circle to the function and checks that the radius and center of the circle is calculated correctly""" moab_core, moab_tags = define_moab_core_and_tags() test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20), (20, 0)]) test_shape.export_stl('test_file.stl') new_moab_core = add_stl_to_moab_core(moab_core=moab_core, surface_id=1, volume_id=1, material_name='test_mat', tags=moab_tags, stl_filename='test_file.stl') all_sets = new_moab_core.get_entities_by_handle(0) file_set = new_moab_core.create_meshset() new_moab_core.add_entities(file_set, all_sets) new_moab_core.write_file('test_file.h5m') assert Path('test_file.stl').exists() is True assert Path('test_file.h5m').exists() is True
def test_export_h5m(self): """creates a Reactor object consisting of two shapes and checks a h5m file of the reactor can be exported using the export_h5m method""" os.system('rm small_dagmc.h5m') os.system('rm small_dagmc_without_graveyard.h5m') os.system('rm small_dagmc_with_graveyard.h5m') os.system('rm large_dagmc.h5m') test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)], material_tag='mat1') test_shape2 = paramak.RotateSplineShape(points=[(0, 0), (0, 20), (20, 20)], material_tag='mat2') test_shape.rotation_angle = 360 test_reactor = paramak.Reactor([test_shape, test_shape2]) test_reactor.export_h5m(filename='small_dagmc.h5m', tolerance=0.01) test_reactor.export_h5m(filename='small_dagmc_without_graveyard.h5m', tolerance=0.01, skip_graveyard=True) test_reactor.export_h5m(filename='small_dagmc_with_graveyard.h5m', tolerance=0.01, skip_graveyard=False) test_reactor.export_h5m(filename='large_dagmc.h5m', tolerance=0.001) assert Path("small_dagmc.h5m").exists() is True assert Path("small_dagmc_with_graveyard.h5m").exists() is True assert Path("large_dagmc.h5m").exists() is True assert Path("large_dagmc.h5m").stat().st_size > Path( "small_dagmc.h5m").stat().st_size assert Path("small_dagmc_without_graveyard.h5m").stat().st_size < Path( "small_dagmc.h5m").stat().st_size
def make_cad_model_with_paramak(): """ Makes a reactor object from two parametric shapes. Exports the neutronics description and stp files for the reactor """ width = 500 # creates a parametric shape pf_coil = paramak.RotateStraightShape(points=[(width, width), (550, width), (550, 550), (500, 550)], stp_filename='pf_coil.stp', material_tag='pf_coil_material') pf_coil.export_html('test.html') # creates another parametric shape blanket = paramak.RotateMixedShape( points=[(538, 305, "straight"), (538, -305, "straight"), (322, -305, "spline"), (470, 0, "spline"), (322, 305, "straight")], rotation_angle=40, azimuth_placement_angle=[0, 45, 90, 135, 180, 225, 270, 315], stp_filename='blanket.stp', material_tag='blanket_material') blanket.solid # creates a reactor object from the two components my_reactor = paramak.Reactor([blanket, pf_coil]) # exports neutronics description and stp files my_reactor.export_neutronics_description() my_reactor.export_stp()
def test_tet_meshes_error(self): test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_reactor = paramak.Reactor([test_shape]) assert test_reactor.tet_meshes is not None
def _make_supports(self): blanket_enveloppe = paramak.BlanketFP( plasma=self._plasma, start_angle=90, stop_angle=-90, offset_from_plasma=self.outer_plasma_gap_radial_thickness + self.firstwall_radial_thickness, thickness=self.outboard_blanket_radial_thickness, rotation_angle=self.rotation_angle, union=self._inboard_blanket, ) support_height = self._blanket_rear_wall_end_height support_height_top = support_height support_height_bottom = -support_height if self.support_position == "lower": support_height_top = 0 elif self.support_position == "upper": support_height_bottom = 0 self._supports = paramak.RotateStraightShape( points=[(self._support_start_radius, support_height_bottom), (self._support_end_radius, support_height_bottom), (self._support_end_radius, support_height_top), (self._support_start_radius, support_height_top)], rotation_angle=self.rotation_angle, stp_filename="supports.stp", stl_filename="supports.stl", name="supports", material_tag="supports_mat", intersect=blanket_enveloppe, ) self._blanket.cut = self._supports return self._supports
def test_reactor_from_shapes_cell_tallies(self): """Makes a reactor from two shapes, then mades a neutronics model and tests the TBR simulation value""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)], material_tag='mat1', ) test_shape2 = paramak.RotateSplineShape( points=[(100, 100), (100, -100), (200, -100), (200, 100)], material_tag='blanket_mat', rotation_angle=180 ) test_reactor = paramak.Reactor([test_shape, test_shape2]) neutronics_model = paramak.NeutronicsModel( geometry=test_reactor, source=self.source, materials={ 'mat1': 'copper', 'blanket_mat': 'FLiNaK', # used as O18 is not in nndc nuc data }, cell_tallies=['TBR', 'heating', 'flux'], simulation_batches=2, simulation_particles_per_batch=10, ) # starts the neutronics simulation using trelis neutronics_model.simulate(verbose=False, method='pymoab')
def test_export_neutronics_description(self): """Creates a Reactor object and checks that the neutronics description is exported to a json file with the correct material_name and stp_filename.""" os.system("rm manifest_test.json") test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_shape.material_tag = "test_material" test_shape.stp_filename = "test.stp" test_shape.tet_mesh = "size 60" test_reactor = paramak.Reactor([test_shape]) returned_filename = test_reactor.export_neutronics_description( filename="manifest_test.json") with open("manifest_test.json") as json_file: neutronics_description = json.load(json_file) assert returned_filename == "manifest_test.json" assert Path("manifest_test.json").exists() is True assert len(neutronics_description) == 2 assert "stp_filename" in neutronics_description[0].keys() assert "material" in neutronics_description[0].keys() assert "tet_mesh" in neutronics_description[0].keys() assert neutronics_description[0]["material"] == "test_material" assert neutronics_description[0]["stp_filename"] == "test.stp" assert neutronics_description[0]["tet_mesh"] == "size 60" assert neutronics_description[1]["material"] == "Graveyard" assert neutronics_description[1]["stp_filename"] == "Graveyard.stp" os.system("rm manifest_test.json")
def test_export_neutronics_description_without_plasma(self): """Creates a Reactor object and checks that the neutronics description is exported to a json file with the correct entires, exluding the optional plasma.""" os.system("rm manifest_test.json") test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)], rotation_angle=360, material_tag="test_material", stp_filename="test.stp", ) test_shape.tet_mesh = "size 60" test_plasma = paramak.Plasma(major_radius=500, minor_radius=100) test_reactor = paramak.Reactor([test_shape, test_plasma]) returned_filename = test_reactor.export_neutronics_description() with open("manifest.json") as json_file: neutronics_description = json.load(json_file) assert returned_filename == "manifest.json" assert Path("manifest.json").exists() is True assert len(neutronics_description) == 2 assert "stp_filename" in neutronics_description[0].keys() assert "material" in neutronics_description[0].keys() assert "tet_mesh" in neutronics_description[0].keys() assert neutronics_description[0]["material"] == "test_material" assert neutronics_description[0]["stp_filename"] == "test.stp" assert neutronics_description[0]["tet_mesh"] == "size 60" assert neutronics_description[1]["material"] == "Graveyard" assert neutronics_description[1]["stp_filename"] == "Graveyard.stp" os.system("rm manifest.json")
def test_neutronics_description_without_material_tag(): """Checks ValueError is raised when the neutronics description is exported without material_tag.""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_shape.stp_filename = "test.stp" test_reactor = paramak.Reactor([test_shape]) test_reactor.neutronics_description()
def test_adding_component_to_reactor(self): """creates a Reactor object and checks that shapes can be added to it""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([]) assert len(test_reactor.shapes_and_components) == 0 test_reactor = paramak.Reactor([test_shape]) assert len(test_reactor.shapes_and_components) == 1
def test_adding_shape_with_material_tag_to_reactor(self): """adds a shape to the reactor and checks that the material_tag property works as designed""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)], material_tag='mat1') test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape]) assert len(test_reactor.material_tags) == 1 assert test_reactor.material_tags[0] == 'mat1'
def test_stp_filename_duplication(): """checks ValueError is raised when an elongation < 0 is specified""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)], stp_filename='filename.stp') test_shape2 = paramak.RotateSplineShape( points=[(0, 0), (0, 20), (20, 20)], stp_filename='filename.stp') test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape, test_shape2])
def test_adding_shape_with_stp_filename_to_reactor(self): """adds a shape to the reactor and checks that the stp_filename property works as designed""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)], stp_filename='filename.stp') test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape]) assert len(test_reactor.stp_filenames) == 1 assert test_reactor.stp_filenames[0] == 'filename.stp'
def test_adding_shape_with_stp_filename_to_reactor(self): """Checks that a shape object can be added to a Reactor object with the correct stp filename property.""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)], stp_filename="filename.stp") test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape]) assert len(test_reactor.stp_filenames) == 1 assert test_reactor.stp_filenames[0] == "filename.stp"
def test_export_html_view_planes(self): """Checks a plotly figure of the Shape is exported by the export_html method with a range of different view_plane options.""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20), (20, 0)], rotation_angle=180) for view_plane in ['XZ', 'XY', 'YZ', 'YX', 'ZY', 'ZX', 'RZ', 'XYZ']: os.system("rm *.html") test_shape.export_html(filename='filename', view_plane=view_plane) assert Path("filename.html").exists() is True
def test_Graveyard_exists(self): """creates a Reactor object with one shape and checks that a graveyard can be produced using the make_graveyard method""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape]) test_reactor.make_graveyard() assert isinstance(test_reactor.graveyard, paramak.Shape)
def test_adding_shape_with_material_tag_to_reactor(self): """Checks that a shape object can be added to a Reactor object with the correct material tag property.""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)], material_tag="mat1") test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape]) assert len(test_reactor.material_tags) == 1 assert test_reactor.material_tags[0] == "mat1"
def test_initial_solid_construction(self): """Creates a shape and checks that a cadquery solid with a unique hash value is created when .solid is called.""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20), (20, 0)], rotation_angle=360) assert test_shape.hash_value is None assert test_shape.solid is not None assert type(test_shape.solid).__name__ == "Workplane" assert test_shape.hash_value is not None
def test_neutronics_description_without_stp_filename(): """checks that a ValueError is raised when the neutronics description \ is exported without stp_filename""" test_shape = paramak.RotateStraightShape(points=[(0, 0), (0, 20), (20, 20)]) test_shape.rotation_angle = 360 test_shape.material_tag = "test_material" test_shape.stp_filename = None test_reactor = paramak.Reactor([test_shape]) neutronics_description = test_reactor.neutronics_description()
def test_export_3d_image(self): """checks that export_3d_image() exports png files with the correct suffix""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20), (20, 0)]) test_shape.rotation_angle = 360 os.system("rm filename.png") test_shape.export_3d_image("filename") assert Path("filename.png").exists() is True os.system("rm filename.png") test_shape.export_3d_image("filename.png") assert Path("filename.png").exists() is True os.system("rm filename.png")
def test_EdgeLengthSelector_with_fillet_areas(self): """tests the filleting of a RotateStraightShape results in an extra surface area""" test_shape = paramak.RotateStraightShape(points=[(1, 1), (2, 1), (2, 2)]) assert len(test_shape.areas) == 3 test_shape.solid = test_shape.solid.edges( EdgeLengthSelector(6.28)).fillet(0.1) assert len(test_shape.areas) == 4
def test_stp_filename_duplication(): """Checks ValueError is raised when shapes with the same stp filenames are added to a reactor object""" test_shape_1 = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)], stp_filename="filename.stp") test_shape_2 = paramak.RotateSplineShape( points=[(0, 0), (0, 20), (20, 20)], stp_filename="filename.stp") test_shape_1.rotation_angle = 90 my_reactor = paramak.Reactor([test_shape_1, test_shape_2]) my_reactor.export_stp()
def test_stp_filename_None(): """checks ValueError is raised when RotateStraightShapes with duplicate stp filenames are added""" test_shape = paramak.RotateStraightShape( points=[(0, 0), (0, 20), (20, 20)], stp_filename="filename.stp") test_shape2 = paramak.RotateSplineShape(points=[(0, 0), (0, 20), (20, 20)], stp_filename=None) test_shape.create_solid() my_reactor = paramak.Reactor([test_shape, test_shape2]) my_reactor.export_stp()