def test_stl_filename_duplication_rotate_spline(): """Checks ValueError is raised when RotateSplineShapes with duplicate stl filenames are added.""" test_shape = paramak.RotateSplineShape(points=[(0, 0), (0, 20), (20, 20)], stl_filename="filename.stl") test_shape2 = paramak.RotateSplineShape( points=[(0, 0), (0, 20), (20, 20)], stl_filename="filename.stl") test_shape.rotation_angle = 360 test_shape.create_solid() my_reactor = paramak.Reactor([test_shape, test_shape2]) my_reactor.export_stl()
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 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_string_color_value(): """Tries to make a paramak.RotateSplineShape is string values for color""" paramak.RotateSplineShape( points=[(200, 100), (200, 200), (500, 200), (500, 100)], azimuth_placement_angle=np.linspace(0, 90, 2), color=('1', '0', '1') )
def test_shape_azimuth_placement_angles_iterabel(self): """checks that azimuth_placement_angle can take an Iterable """ test_shape = paramak.RotateSplineShape( points=[(200, 100), (200, 200), (500, 200), (500, 100)], rotation_angle=20, azimuth_placement_angle=[0, 180]) test_shape.solid assert test_shape.solid is not None
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_absolute_shape_volume(self): """creates a rotated shape using spline connections and checks the volume is correct""" test_shape = paramak.RotateSplineShape( points=[(0, 0), (0, 20), (20, 20), (20, 0)]) test_shape.rotation_angle = 360 test_shape.create_solid() assert test_shape.solid is not None assert test_shape.volume > 100
def test_cut_volume(self): """creates a rotated shape using spline connections with another shape cut out and checks that the volume is correct""" inner_shape = paramak.RotateSplineShape( points=[(5, 5), (5, 10), (10, 10), (10, 5)], rotation_angle=180 ) outer_shape = paramak.RotateSplineShape( points=[(3, 3), (3, 12), (12, 12), (12, 3)], rotation_angle=180 ) outer_shape_with_cut = paramak.RotateSplineShape( points=[(3, 3), (3, 12), (12, 12), (12, 3)], cut=inner_shape, rotation_angle=180, ) assert inner_shape.volume == pytest.approx(900.88, abs=0.1) assert outer_shape.volume == pytest.approx(2881.76, abs=0.1) assert outer_shape_with_cut.volume == pytest.approx( 2881.76 - 900.88, abs=0.2)
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()
def test_offset_from_graveyard_sets_attribute(self): """Creates a graveyard for a reactor and sets the graveyard_offset. Checks that the Reactor.graveyard_offset property is set""" 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.make_graveyard(graveyard_offset=101) assert test_reactor.graveyard_offset == 101
def test_export_h5m_without_extension(self): """Tests that the code appends .h5m to the end of the filename""" os.system('rm out.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='out', tolerance=0.01) assert Path("out.h5m").exists() is True os.system('rm out.h5m')
def test_adding_multiple_shapes_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_shape2 = paramak.RotateSplineShape(points=[(0, 0), (0, 20), (20, 20)], material_tag='mat2') test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape, test_shape2]) assert len(test_reactor.material_tags) == 2 assert test_reactor.material_tags[0] == 'mat1' assert test_reactor.material_tags[1] == 'mat2'
def test_adding_multiple_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_shape2 = paramak.RotateSplineShape(points=[(0, 0), (0, 20), (20, 20)], stp_filename='filename2.stp') test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape, test_shape2]) assert len(test_reactor.stp_filenames) == 2 assert test_reactor.stp_filenames[0] == 'filename.stp' assert test_reactor.stp_filenames[1] == 'filename2.stp'
def test_adding_multiple_shape_with_stp_filename_to_reactor(self): """Checks that multiple shape objects can be added to a Reactor object with the correct stp filename properties.""" 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="filename2.stp") test_shape.rotation_angle = 360 test_shape.create_solid() test_reactor = paramak.Reactor([test_shape, test_shape2]) assert len(test_reactor.stp_filenames) == 2 assert test_reactor.stp_filenames[0] == "filename.stp" assert test_reactor.stp_filenames[1] == "filename2.stp"
def test_adding_multiple_shapes_with_material_tag_to_reactor(self): """Checks that multiple shape objects can be added to a Reactor object with the correct material tag properties.""" 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_shape.create_solid() test_reactor = paramak.Reactor([test_shape, test_shape2]) assert len(test_reactor.material_tags) == 2 assert "mat1" in test_reactor.material_tags assert "mat2" in test_reactor.material_tags
def test_reactor_from_shapes_2d_mesh_tallies(self): """Makes a reactor from two shapes, then mades a neutronics model and tests the TBR simulation value""" os.system('rm *_on_2D_mesh_*.png') 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 }, mesh_tally_2d=['(n,Xt)', 'heating', 'flux'], simulation_batches=2, simulation_particles_per_batch=10, ) # starts the neutronics simulation using trelis neutronics_model.simulate(verbose=False, method='pymoab') assert Path("n-Xt_on_2D_mesh_xz.png").exists() is True assert Path("n-Xt_on_2D_mesh_xy.png").exists() is True assert Path("n-Xt_on_2D_mesh_yz.png").exists() is True assert Path("heating_on_2D_mesh_xz.png").exists() is True assert Path("heating_on_2D_mesh_xy.png").exists() is True assert Path("heating_on_2D_mesh_yz.png").exists() is True assert Path("flux_on_2D_mesh_xz.png").exists() is True assert Path("flux_on_2D_mesh_xy.png").exists() is True assert Path("flux_on_2D_mesh_yz.png").exists() is True
def main(): # rotate examples # this makes a rectangle and rotates it to make a solid rotated_straights = paramak.RotateStraightShape(rotation_angle=180, points=[(400, 100), (400, 200), (600, 200), (600, 100)]) rotated_straights.export_stp("rotated_straights.stp") rotated_straights.export_html("rotated_straights.html") # this makes a banana shape and rotates it to make a solid rotated_spline = paramak.RotateSplineShape(rotation_angle=180, points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ]) rotated_spline.export_stp("rotated_spline.stp") rotated_spline.export_html("rotated_spline.html") # this makes a shape with straight, spline and circular edges and rotates # it to make a solid rotated_mixed = paramak.RotateMixedShape(rotation_angle=180, points=[ (100, 0, "straight"), (200, 0, "circle"), (250, 50, "circle"), (200, 100, "straight"), (150, 100, "spline"), (140, 75, "spline"), (110, 45, "spline"), ]) rotated_mixed.export_stp("rotated_mixed.stp") rotated_mixed.export_html("rotated_mixed.html") # this makes a circular shape and rotates it to make a solid rotated_circle = paramak.RotateCircleShape(rotation_angle=180, points=[(50, 0)], radius=5, workplane="XZ") rotated_circle.export_stp("rotated_circle.stp") rotated_circle.export_html("rotated_circle.html") # extrude examples # this makes a banana shape with straight edges and rotates it to make a # solid extruded_straight = paramak.ExtrudeStraightShape(distance=200, points=[ (300, -300), (400, 0), (300, 300), (400, 300), (500, 0), (400, -300), ]) extruded_straight.export_stp("extruded_straight.stp") extruded_straight.export_html("extruded_straight.html") # this makes a banana shape and rotates it to make a solid extruded_spline = paramak.ExtrudeSplineShape(distance=200, points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ]) extruded_spline.export_stp("extruded_spline.stp") extruded_spline.export_html("extruded_spline.html") # this makes a banana shape straight top and bottom edges and extrudes it # to make a solid extruded_mixed = paramak.ExtrudeMixedShape( distance=100, points=[ (100, 0, "straight"), (200, 0, "circle"), (250, 50, "circle"), (200, 100, "straight"), (150, 100, "spline"), (140, 75, "spline"), (110, 45, "spline"), ], ) extruded_mixed.export_stp("extruded_mixed.stp") extruded_mixed.export_html("extruded_mixed.html") # this makes a circular shape and extrudes it to make a solid extruded_circle = paramak.ExtrudeCircleShape(points=[(20, 0)], radius=20, distance=200) extruded_circle.export_stp("extruded_circle.stp") extruded_circle.export_html("extruded_circle.html") # sweep examples # this makes a banana shape with straight edges and sweeps it along a # spline to make a solid sweep_straight = paramak.SweepStraightShape(points=[(-150, 300), (-50, 300), (50, 0), (-50, -300), (-150, -300), (-50, 0)], path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_straight.export_stp("sweep_straight.stp") sweep_straight.export_html("sweep_straight.html") # this makes a banana shape with spline edges and sweeps it along a spline # to make a solid sweep_spline = paramak.SweepSplineShape(points=[(50, 0), (50, -20), (-50, -300), (-150, -300), (-50, 0), (-150, 300), (-50, 300), (50, 20)], path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_spline.export_stp("sweep_spline.stp") sweep_spline.export_html("sweep_spline.html") # this makes a shape with straight, spline and circular edges and sweeps # it along a spline to make a solid sweep_mixed = paramak.SweepMixedShape(points=[(-80, -50, "straight"), (20, -50, "circle"), (70, 0, "circle"), (20, 50, "straight"), (-30, 50, "spline"), (-40, 25, "spline"), (-70, -5, "spline")], path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_mixed.export_stp("sweep_mixed.stp") sweep_mixed.export_html("sweep_mixed.html") # this makes a circular shape and sweeps it to make a solid sweep_circle = paramak.SweepCircleShape(radius=40, path_points=[(50, 0), (150, 400), (400, 500), (650, 600), (750, 1000)], workplane="XY", path_workplane="XZ") sweep_circle.export_stp("sweep_circle.stp") sweep_circle.export_html("sweep_circle.html")
def main(): # rotate examples # this makes a rectangle and rotates it to make a solid rotated_straights = paramak.RotateStraightShape( points=[(400, 100), (400, 200), (600, 200), (600, 100)]) rotated_straights.rotation_angle = 180 rotated_straights.export_stp("rotated_straights.stp") rotated_straights.export_html("rotated_straights.html") # this makes a banana shape and rotates it to make a solid rotated_spline = paramak.RotateSplineShape(points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ]) rotated_spline.rotation_angle = 180 rotated_spline.export_stp("rotated_spline.stp") rotated_spline.export_html("rotated_spline.html") # this makes a shape with straight, spline and circular edges and rotates it to make a solid rotated_mixed = paramak.RotateMixedShape(points=[ (100, 0, 'straight'), (200, 0, 'circle'), (250, 50, 'circle'), (200, 100, 'straight'), (150, 100, 'spline'), (140, 75, 'spline'), (110, 45, 'spline'), ]) rotated_mixed.rotation_angle = 180 rotated_mixed.export_stp("rotated_mixed.stp") rotated_mixed.export_html("rotated_mixed.html") # this makes a circular shape and rotates it to make a solid rotated_circle = paramak.RotateCircleShape(points=[(50, 0)], radius=5, workplane="XZ") rotated_circle.rotation_angle = 180 rotated_circle.export_stp("rotated_circle.stp") rotated_circle.export_html("rotated_circle.html") # extrude examples # this makes a banana shape with straight edges and rotates it to make a solid extruded_straight = paramak.ExtrudeStraightShape( points=[ (300, -300), (400, 0), (300, 300), (400, 300), (500, 0), (400, -300), ], distance=200, ) extruded_straight.export_stp("extruded_straight.stp") extruded_straight.export_html("extruded_straight.html") # this makes a banana shape and rotates it to make a solid extruded_spline = paramak.ExtrudeSplineShape( points=[ (500, 0), (500, -20), (400, -300), (300, -300), (400, 0), (300, 300), (400, 300), (500, 20), ], distance=200, ) extruded_spline.export_stp("extruded_spline.stp") extruded_spline.export_html("extruded_spline.html") # this makes a banana shape straight top and bottom edges and extrudes it to make a solid extruded_mixed = paramak.ExtrudeMixedShape( points=[ (100, 0, 'straight'), (200, 0, 'circle'), (250, 50, 'circle'), (200, 100, 'straight'), (150, 100, 'spline'), (140, 75, 'spline'), (110, 45, 'spline'), ], distance=100, ) extruded_mixed.export_stp("extruded_mixed.stp") extruded_mixed.export_html("extruded_mixed.html") # this makes a circular shape and extrudes it to make a solid extruded_circle = paramak.ExtrudeCircleShape(points=[(20, 0)], radius=20, distance=200) extruded_circle.export_stp("extruded_circle.stp") extruded_circle.export_html("extruded_circle.html")