From b81cbc29fb054353742c564c4d5d3b69b07d4b0e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 24 Jan 2018 13:41:41 -0600 Subject: [PATCH] Add test for Material.add_volume_information --- src/volume_calc.F90 | 2 +- tests/unit_tests/test_material.py | 48 +++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/volume_calc.F90 b/src/volume_calc.F90 index 07dc5b4184..15c0497699 100644 --- a/src/volume_calc.F90 +++ b/src/volume_calc.F90 @@ -194,7 +194,7 @@ contains if (this % domain_type == FILTER_MATERIAL) then i_material = p % material do i_domain = 1, size(this % domain_id) - if (i_material == materials(i_domain) % id) then + if (materials(i_material) % id == this % domain_id(i_domain)) then call check_hit(i_domain, i_material, indices, hits, n_mat) end if end do diff --git a/tests/unit_tests/test_material.py b/tests/unit_tests/test_material.py index 46241e83df..2da3c797f9 100644 --- a/tests/unit_tests/test_material.py +++ b/tests/unit_tests/test_material.py @@ -1,4 +1,6 @@ import openmc +import openmc.model +import openmc.stats import pytest @@ -12,6 +14,40 @@ def uo2(): return m +@pytest.fixture(scope='module') +def sphere_model(): + model = openmc.model.Model() + + m = openmc.Material() + m.add_nuclide('U235', 1.0) + m.set_density('g/cm3', 1.0) + model.materials.append(m) + + sph = openmc.Sphere(boundary_type='vacuum') + c = openmc.Cell(fill=m, region=-sph) + model.geometry.root_universe = openmc.Universe(cells=[c]) + + model.settings.particles = 100 + model.settings.batches = 10 + model.settings.run_mode = 'fixed source' + model.settings.source = openmc.Source(space=openmc.stats.Point()) + ll, ur = c.region.bounding_box + model.settings.volume_calculations = [ + openmc.VolumeCalculation(domains=[m], samples=1000, + lower_left=ll, upper_right=ur) + ] + return model + + +@pytest.fixture +def run_in_tmpdir(tmpdir): + orig = tmpdir.chdir() + try: + yield + finally: + orig.chdir() + + def test_attributes(uo2): assert uo2.name == 'UO2' assert uo2.id == 100 @@ -93,6 +129,14 @@ def test_isotropic(): assert m.isotropic == ['O16'] +def test_volume(run_in_tmpdir, sphere_model): + """Test adding volume information from a volume calculation.""" + sphere_model.export_to_xml() + openmc.calculate_volumes() + volume_calc = openmc.VolumeCalculation.from_hdf5('volume_1.h5') + sphere_model.materials[0].add_volume_information(volume_calc) + + def test_get_nuclide_densities(uo2): nucs = uo2.get_nuclide_densities() for nuc, density, density_type in nucs.values(): @@ -108,7 +152,7 @@ def test_get_nuclide_atom_densities(uo2): assert density > 0 -def test_materials(tmpdir): +def test_materials(run_in_tmpdir): m1 = openmc.Material() m1.add_nuclide('U235', 1.0, 'wo') m1.add_nuclide('O16', 2.0, 'wo') @@ -125,4 +169,4 @@ def test_materials(tmpdir): mats = openmc.Materials([m1, m2]) mats.cross_sections = '/some/fake/cross_sections.xml' mats.multipole_library = '/some/awesome/mp_lib/' - mats.export_to_xml(str(tmpdir.join('materials.xml'))) + mats.export_to_xml()