Combine volume calculations into a single unit test

This commit is contained in:
Paul Romano 2018-02-01 10:00:50 -06:00
parent 1a93883b67
commit 347243876f
4 changed files with 98 additions and 45 deletions

View file

@ -94,20 +94,6 @@ def test_rotation():
])
def test_volume(run_in_tmpdir, sphere_model):
"""Test adding volume information from a volume calculation."""
ll, ur = sphere_model.geometry.bounding_box
cells = list(sphere_model.geometry.root_universe.cells.values())
sphere_model.settings.volume_calculations = [
openmc.VolumeCalculation(domains=cells, samples=1000,
lower_left=ll, upper_right=ur)
]
sphere_model.export_to_xml()
openmc.calculate_volumes()
volume_calc = openmc.VolumeCalculation.from_hdf5('volume_1.h5')
cells[0].add_volume_information(volume_calc)
def test_get_nuclides(uo2):
c = openmc.Cell(fill=uo2)
nucs = c.get_nuclides()

View file

@ -4,6 +4,104 @@ import openmc
import pytest
def test_volume(uo2):
"""Test adding volume information from a volume calculation."""
# Create model with nested spheres
model = openmc.model.Model()
model.materials.append(uo2)
inner = openmc.Sphere(R=1.)
outer = openmc.Sphere(R=2., boundary_type='vacuum')
c1 = openmc.Cell(fill=uo2, region=-inner)
c2 = openmc.Cell(region=+inner & -outer)
u = openmc.Universe(cells=[c1, c2])
model.geometry.root_universe = u
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 = model.geometry.bounding_box
assert ll == pytest.approx((-outer.r, -outer.r, -outer.r))
assert ur == pytest.approx((outer.r, outer.r, outer.r))
model.settings.volume_calculations
for domain in (c1, uo2, u):
# Run stochastic volume calculation
volume_calc = openmc.VolumeCalculation(
domains=[domain], samples=1000, lower_left=ll, upper_right=ur)
model.settings.volume_calculations = [volume_calc]
model.export_to_xml()
openmc.calculate_volumes()
# Load results and add volume information
volume_calc.load_results('volume_1.h5')
model.geometry.add_volume_information(volume_calc)
# get_nuclide_densities relies on volume information
nucs = set(domain.get_nuclide_densities())
assert not (nucs ^ {'U235', 'O16'})
def test_export_xml():
pass
def test_find():
pass
def test_get_instances():
pass
def test_get_all_universes():
pass
def test_get_all_materials():
pass
def test_get_all_material_cells():
pass
def test_get_all_material_universes():
pass
def test_get_all_lattices():
pass
def test_get_all_surfaces():
pass
def test_get_materials_by_name():
pass
def test_get_cells_by_name():
pass
def test_get_cells_by_fill_name():
pass
def test_get_universes_by_name():
pass
def test_get_lattices_by_name():
pass
def test_clone():
pass
def test_determine_paths(cell_with_lattice):
cells, mats, univ, lattice = cell_with_lattice
u = openmc.Universe(cells=[cells[-1]])

View file

@ -106,19 +106,6 @@ def test_isotropic():
assert m2.isotropic == ['H1']
def test_volume(run_in_tmpdir, sphere_model):
"""Test adding volume information from a volume calculation."""
ll, ur = sphere_model.geometry.bounding_box
sphere_model.settings.volume_calculations = [
openmc.VolumeCalculation(domains=sphere_model.materials, samples=1000,
lower_left=ll, upper_right=ur)
]
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():

View file

@ -67,24 +67,6 @@ def test_find(uo2):
assert seq[-1] == c4
def test_volume(run_in_tmpdir, sphere_model):
"""Test adding volume information from a volume calculation."""
univ = sphere_model.geometry.root_universe
ll, ur = univ.bounding_box
sphere_model.settings.volume_calculations = [
openmc.VolumeCalculation(domains=[univ], samples=1000,
lower_left=ll, upper_right=ur)
]
sphere_model.export_to_xml()
openmc.calculate_volumes()
volume_calc = openmc.VolumeCalculation.from_hdf5('volume_1.h5')
univ.add_volume_information(volume_calc)
# get_nuclide_densities relies on volume information
nucs = set(univ.get_nuclide_densities())
assert not (nucs ^ {'U235'})
def test_plot(run_in_tmpdir, sphere_model):
m = sphere_model.materials[0]
univ = sphere_model.geometry.root_universe