def test_density_of_mixed_two_packed_crystals(self): test_material_1 = nmm.Material(material_name="Li4SiO4") test_material_packed_1 = nmm.Material(material_name="Li4SiO4", packing_fraction=0.65) assert (test_material_1.openmc_material.density * 0.65 == test_material_packed_1.openmc_material.density) test_material_2 = nmm.Material(material_name="Be12Ti") test_material_packed_2 = nmm.Material(material_name="Be12Ti", packing_fraction=0.35) assert (test_material_2.openmc_material.density * 0.35 == test_material_packed_2.openmc_material.density) mixed_packed_crystals = nmm.MultiMaterial( material_tag="mixed_packed_crystals", materials=[test_material_packed_1, test_material_packed_2], fracs=[0.75, 0.25], percent_type="vo", ) assert mixed_packed_crystals.openmc_material.density == pytest.approx( (test_material_1.openmc_material.density * 0.65 * 0.75) + (test_material_2.openmc_material.density * 0.35 * 0.25), rel=0.01, )
def setUp(self): # makes the 3d geometry self.my_reactor = paramak.BallReactor( inner_bore_radial_thickness=1, inboard_tf_leg_radial_thickness=30, center_column_shield_radial_thickness=60, divertor_radial_thickness=50, inner_plasma_gap_radial_thickness=30, plasma_radial_thickness=300, outer_plasma_gap_radial_thickness=30, firstwall_radial_thickness=3, blanket_radial_thickness=100, blanket_rear_wall_radial_thickness=3, elongation=2.75, triangularity=0.5, rotation_angle=360, ) # makes a homogenised material for the blanket from lithium lead and # eurofer self.blanket_material = nmm.MultiMaterial( fracs=[0.8, 0.2], materials=[ nmm.Material('SiC'), nmm.Material('eurofer') ]) self.source = openmc.Source() # sets the location of the source to x=0 y=0 z=0 self.source.space = openmc.stats.Point((0, 0, 0)) # sets the direction to isotropic self.source.angle = openmc.stats.Isotropic() # sets the energy distribution to 100% 14MeV neutrons self.source.energy = openmc.stats.Discrete([14e6], [1])
def test_multimaterial_attributes_from_material_objects_and_openmc_materials( self): # tests that multimaterials made from material objects and neutronics # materials have the same properties test_material_1 = nmm.MultiMaterial( "test_material_1", materials=[nmm.Material("Li4SiO4"), nmm.Material("Be12Ti")], fracs=[0.5, 0.5], percent_type="vo", ).openmc_material test_material_2 = nmm.MultiMaterial( "test_material_2", materials=[ nmm.Material("Li4SiO4").openmc_material, nmm.Material("Be12Ti").openmc_material, ], fracs=[0.5, 0.5], percent_type="vo", ).openmc_material assert test_material_1.density == test_material_2.density assert test_material_1.nuclides == test_material_2.nuclides
def test_mutlimaterial_material_tag_setting(self): test_material = nmm.MultiMaterial(materials=[ nmm.Material('Pb842Li158', temperature_in_K=500), nmm.Material('SiC') ], fracs=[0.5, 0.5]) assert test_material.material_tag is None test_material.material_tag = 'tag_set_after_creation' assert test_material.material_tag == 'tag_set_after_creation' test_material.openmc_material assert test_material.openmc_material.name == 'tag_set_after_creation' test_material = nmm.MultiMaterial(materials=[ nmm.Material('Pb842Li158', temperature_in_K=500), nmm.Material('SiC') ], fracs=[0.5, 0.5], material_tag='tag_set_on_creation') assert test_material.material_tag == 'tag_set_on_creation' test_material.openmc_material assert test_material.openmc_material.name == 'tag_set_on_creation'
def test_density_of_packed_crystals(self): test_mat = nmm.Material(material_name="Li4SiO4") test_mat_packed = nmm.Material( material_name="Li4SiO4", packing_fraction=0.35) assert ( test_mat.openmc_material.density * 0.35 == test_mat_packed.openmc_material.density )
def test_json_dump_works(self): test_material = nmm.MultiMaterial( "test_material", materials=[ nmm.Material("tungsten", packing_fraction=0.6), nmm.Material("eurofer", packing_fraction=0.8), ], fracs=[0.3, 0.7], ) assert isinstance(json.dumps(test_material), str)
def test_density_of_enriched_crystals(self): test_mat = nmm.Material(material_name="Li4SiO4") test_mat_enriched = nmm.Material( material_name="Li4SiO4", enrichment=50.0, enrichment_target="Li6", enrichment_type="ao", ) assert (test_mat.openmc_material.density > test_mat_enriched.openmc_material.density)
def too_small_fracs(): """checks a ValueError is raised when the fracs are above 1""" nmm.MultiMaterial( "test_material", materials=[ nmm.Material("tungsten", packing_fraction=0.6), nmm.Material("eurofer", packing_fraction=0.8), ], fracs=[0.3, 0.65], )
def test_serpent_multimaterial_type(self): test_material = nmm.MultiMaterial( "test_material", materials=[nmm.Material("Li4SiO4"), nmm.Material("Be12Ti")], fracs=[0.50, 0.50], percent_type="vo", ) assert len(test_material.serpent_material) > 100 assert isinstance(test_material.serpent_material, str)
def test_too_small_packing_fraction(): """checks a ValueError is raised when the packing_fraction is the too large""" nmm.MultiMaterial("test_material", materials=[ nmm.Material("tungsten", packing_fraction=0.6), nmm.Material("eurofer", packing_fraction=0.8), ], fracs=[0.3, 0.7], packing_fraction=-0.1)
def test_incorrect_packing_fraction(): """checks a ValueError is raised when the packing_fraction is the wrong type""" nmm.MultiMaterial("test_material", materials=[ nmm.Material("tungsten", packing_fraction=0.6), nmm.Material("eurofer", packing_fraction=0.8), ], fracs=[0.3, 0.7], packing_fraction="1")
def test_make_multimaterial_from_material_objects(self): # tests that a multimaterial can be created by passing Material objects # into the MultiMaterial function test_material = nmm.MultiMaterial( "test_material", materials=[nmm.Material("Li4SiO4"), nmm.Material("Be12Ti")], fracs=[0.50, 0.50], percent_type="vo", ) assert isinstance(test_material, openmc.Material) is False assert isinstance(test_material.openmc_material, openmc.Material)
def test_iron_density(self): a = nmm.Material("Iron") assert a.openmc_material.density == 7.874 a = nmm.Material("Iron") serpent_density = a.serpent_material.split("\n")[0].split()[2] assert float(serpent_density) == pytest.approx(7.874) a = nmm.Material("Iron", material_id=45) mcnp_density = a.mcnp_material.split("\n")[0].split()[3] assert float(mcnp_density) == pytest.approx(7.874) a = nmm.Material("Iron", volume_in_cm3=100) fispact_density = a.fispact_material.split("\n")[0].split()[1] assert float(fispact_density) == pytest.approx(7.874)
def test_serpent_material_suffix(self): test_material1 = nmm.Material( "Nb3Sn", material_tag="Nb3Sn", zaid_suffix=".21c") serpent_material1 = test_material1.serpent_material test_material2 = nmm.Material( "Nb3Sn", material_tag="Nb3Sn", zaid_suffix=".30c") serpent_material2 = test_material2.serpent_material test_material3 = nmm.Material("Nb3Sn", material_tag="Nb3Sn") serpent_material3 = test_material3.serpent_material assert len(serpent_material3) < len(serpent_material2) assert len(serpent_material1) == len(serpent_material2) assert serpent_material1.count("21c") == serpent_material2.count("30c")
def test_serpent_material_lines_contain_underscore(self): test_material = nmm.Material( chemical_equation="Nb3Sn", material_tag="test2", density=3.2, density_unit="g/cm3", material_id=1, percent_type="wo", ) line_by_line_material = test_material.serpent_material.split("\n") assert len(line_by_line_material) == 12 assert line_by_line_material[0].split()[0] == "mat" assert line_by_line_material[0].split()[1] == "test2" assert float(line_by_line_material[0].split()[2]) == pytest.approx(3.2) assert "-" in line_by_line_material[1] assert "-" in line_by_line_material[2] assert "-" in line_by_line_material[3] assert "-" in line_by_line_material[4] assert "-" in line_by_line_material[5] assert "-" in line_by_line_material[6] assert "-" in line_by_line_material[7] assert "-" in line_by_line_material[8] assert "-" in line_by_line_material[9] assert "-" in line_by_line_material[10] assert "-" in line_by_line_material[11]
def test_incorrect_density_unit_type(): """checks a ValueError is raised when the temperature is not set""" nmm.Material( "eurofer", density=1., density_unit='grams per cm3')
def test_json_dump_contains_correct_values(self): test_material = nmm.MultiMaterial( "test_material", materials=[ nmm.Material("tungsten", packing_fraction=0.6), nmm.Material("eurofer", packing_fraction=0.8), ], fracs=[0.3, 0.7], ) test_material_in_json_form = test_material.to_json() assert test_material_in_json_form["material_tag"] == "test_material" assert len(test_material_in_json_form["materials"]) == 2 assert test_material_in_json_form["fracs"] == [0.3, 0.7] assert test_material_in_json_form["percent_type"] == "vo" assert test_material_in_json_form["packing_fraction"] == 1.0
def test_json_dump_contains_correct_keys(self): test_material = nmm.MultiMaterial( "test_material", materials=[ nmm.Material("tungsten", packing_fraction=0.6), nmm.Material("eurofer", packing_fraction=0.8), ], fracs=[0.3, 0.7], ) test_material_in_json_form = test_material.to_json() assert "material_tag" in test_material_in_json_form.keys() assert "materials" in test_material_in_json_form.keys() assert "fracs" in test_material_in_json_form.keys() assert "percent_type" in test_material_in_json_form.keys() assert "packing_fraction" in test_material_in_json_form.keys()
def test_missing_temperature_CO2(): """checks a ValueError is raised when the temperature is not set""" nmm.Material( material_name="CO2", pressure_in_Pa=1e6, )
def test_incorrect_material_name_type(): """checks a ValueError is raised when the temperature is not set""" test_material = nmm.Material("H2O", temperature_in_C=10, pressure_in_Pa=-1e6) test_material.material_name = 1
def test_mcnp_material_suffix(self): test_material1 = nmm.Material( "Nb3Sn", material_tag="Nb3Sn", zaid_suffix=".21c", material_id=27 ) mcnp_material1 = test_material1.mcnp_material test_material2 = nmm.Material( "Nb3Sn", material_tag="Nb3Sn", zaid_suffix=".30c", material_id=27 ) mcnp_material2 = test_material2.mcnp_material test_material3 = nmm.Material( "Nb3Sn", material_tag="Nb3Sn", material_id=27) mcnp_material3 = test_material3.mcnp_material assert len(mcnp_material3) < len(mcnp_material2) assert len(mcnp_material1) == len(mcnp_material2) assert mcnp_material1.count("21c") == mcnp_material2.count("30c")
def test_incorrect_enrichment_type_type(): """checks a ValueError is raised when the temperature is not set""" nmm.Material( "eurofer", density=1., enrichment_type='weight percent')
def test_mcnp_material_lines_with_decimal_places(self): test_material = nmm.Material( "Nb3Sn", material_tag="test", density=3, zaid_suffix=".30c", material_id=27, decimal_places=3, ) line_by_line_material = test_material.mcnp_material.split("\n") assert len(line_by_line_material) == 12 assert line_by_line_material[0].split()[0] == "c" assert line_by_line_material[0].split()[1] == "test" assert line_by_line_material[0].split()[2] == "density" assert float(line_by_line_material[0].split()[3]) == pytest.approx(3) assert line_by_line_material[0].split()[4] == "g/cm3" assert line_by_line_material[1] == "M27 041093.30c 7.500e-01" assert " 050120.30c 8.145e-02" in line_by_line_material assert " 050119.30c 2.148e-02" in line_by_line_material # rounded up assert " 050115.30c 8.500e-04" in line_by_line_material assert " 050112.30c 2.425e-03" in line_by_line_material assert " 050118.30c 6.055e-02" in line_by_line_material assert " 050122.30c 1.158e-02" in line_by_line_material # rounded up assert " 050124.30c 1.448e-02" in line_by_line_material # rounded up assert " 050114.30c 1.650e-03" in line_by_line_material assert " 050117.30c 1.920e-02" in line_by_line_material assert " 050116.30c 3.635e-02" in line_by_line_material
def test_serpent_material_lines_with_decimal_places(self): test_material = nmm.Material( "Nb3Sn", material_tag="test", density=3.3333, zaid_suffix=".30c", decimal_places=4, ) line_by_line_material = test_material.serpent_material.split("\n") assert len(line_by_line_material) == 12 assert line_by_line_material[0].split()[0] == "mat" assert line_by_line_material[0].split()[1] == "test" assert float(line_by_line_material[0].split()[ 2]) == pytest.approx(3.3333) assert " 041093.30c 7.5000e-01" in line_by_line_material assert " 050120.30c 8.1450e-02" in line_by_line_material assert " 050119.30c 2.1475e-02" in line_by_line_material assert " 050115.30c 8.5000e-04" in line_by_line_material assert " 050112.30c 2.4250e-03" in line_by_line_material assert " 050118.30c 6.0550e-02" in line_by_line_material assert " 050122.30c 1.1575e-02" in line_by_line_material assert " 050124.30c 1.4475e-02" in line_by_line_material assert " 050114.30c 1.6500e-03" in line_by_line_material assert " 050117.30c 1.9200e-02" in line_by_line_material assert " 050116.30c 3.6350e-02" in line_by_line_material
def test_density_of_mixed_two_packed_and_non_packed_crystals(self): test_material_1 = nmm.Material(material_name="Li4SiO4") test_material_1_packed = nmm.Material(material_name="Li4SiO4", packing_fraction=0.65) mixed_material = nmm.MultiMaterial( material_tag="mixed_material", materials=[test_material_1, test_material_1_packed], fracs=[0.2, 0.8], percent_type="vo", ) assert mixed_material.openmc_material.density == pytest.approx( (test_material_1.openmc_material.density * 0.2) + (test_material_1.openmc_material.density * 0.65 * 0.8))
def test_json_dump_contains_correct_values(self): test_material = nmm.Material( "H2O", temperature_in_C=100, pressure_in_Pa=1e6) test_material_in_json_form = test_material.to_json() assert test_material_in_json_form["pressure_in_Pa"] == 1e6 assert test_material_in_json_form["temperature_in_C"] == 100 assert test_material_in_json_form["material_name"] == "H2O"
def test_material_id_wrong_type(): """checks a ValueError is raised when the material_id is the not an int""" nmm.Material( "Li4SiO4", material_id='one' )
def test_reference_wrong_type(): """checks a ValueError is raised when the reference is the not a string""" nmm.Material( "Li4SiO4", reference=-1 )
def test_pressure_in_Pa_too_low(): """checks a ValueError is raised when the pressure_in_Pa is the too small""" nmm.Material( "Li4SiO4", pressure_in_Pa=-1 )
def test_chemical_equation_wrong_type(): """checks a ValueError is raised when the chemical_equation is the not a str""" nmm.Material( "eurofer", chemical_equation=-0.1 )