diff --git a/tests/regression_tests/periodic/test.py b/tests/regression_tests/periodic/test.py index f9d26392f2..51a70a6aa7 100644 --- a/tests/regression_tests/periodic/test.py +++ b/tests/regression_tests/periodic/test.py @@ -1,58 +1,53 @@ import openmc +import pytest from tests.testing_harness import PyAPITestHarness -class PeriodicTest(PyAPITestHarness): - def _build_inputs(self): - # Define materials - water = openmc.Material(1) - water.add_nuclide('H1', 2.0) - water.add_nuclide('O16', 1.0) - water.add_s_alpha_beta('c_H_in_H2O') - water.set_density('g/cc', 1.0) +@pytest.fixture +def box_model(): + model = openmc.model.Model() + # Define materials + water = openmc.Material() + water.add_nuclide('H1', 2.0) + water.add_nuclide('O16', 1.0) + water.add_s_alpha_beta('c_H_in_H2O') + water.set_density('g/cc', 1.0) - fuel = openmc.Material(2) - fuel.add_nuclide('U235', 1.0) - fuel.set_density('g/cc', 4.5) + fuel = openmc.Material() + fuel.add_nuclide('U235', 1.0) + fuel.set_density('g/cc', 4.5) - materials = openmc.Materials((water, fuel)) - materials.default_temperature = '294K' - materials.export_to_xml() + # Define geometry + x_min = openmc.XPlane(surface_id=1, x0=0., boundary_type='periodic') + x_max = openmc.XPlane(surface_id=2, x0=5., boundary_type='reflective') - # Define geometry - x_min = openmc.XPlane(surface_id=1, x0=0., boundary_type='periodic') - x_max = openmc.XPlane(surface_id=2, x0=5., boundary_type='reflective') + y_min = openmc.YPlane(surface_id=3, y0=0., boundary_type='periodic') + y_max = openmc.YPlane(surface_id=4, y0=5., boundary_type='reflective') + y_min.periodic_surface = x_min - y_min = openmc.YPlane(surface_id=3, y0=0., boundary_type='periodic') - y_max = openmc.YPlane(surface_id=4, y0=5., boundary_type='reflective') - y_min.periodic_surface = x_min + z_min = openmc.ZPlane(surface_id=5, z0=-5., boundary_type='periodic') + z_max = openmc.Plane(surface_id=6, a=0, b=0, c=1, d=5., + boundary_type='periodic') + z_cyl = openmc.ZCylinder(surface_id=7, x0=2.5, y0=0., r=2.0) - z_min = openmc.ZPlane(surface_id=5, z0=-5., boundary_type='periodic') - z_max = openmc.Plane(surface_id=6, a=0, b=0, c=1, d=5., - boundary_type='periodic') - z_cyl = openmc.ZCylinder(surface_id=7, x0=2.5, y0=0., r=2.0) + outside_cyl = openmc.Cell(1, fill=water, region=( + +x_min & -x_max & +y_min & -y_max & +z_min & -z_max & +z_cyl)) + inside_cyl = openmc.Cell(2, fill=fuel, region=( + +y_min & +z_min & -z_max & -z_cyl)) + root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) + model.geometry = openmc.Geometry(root_universe) - outside_cyl = openmc.Cell(1, fill=water, region=( - +x_min & -x_max & +y_min & -y_max & +z_min & -z_max & +z_cyl)) - inside_cyl = openmc.Cell(2, fill=fuel, region=( - +y_min & +z_min & -z_max & -z_cyl)) - root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) - - geometry = openmc.Geometry() - geometry.root_universe = root_universe - geometry.export_to_xml() - - # Define settings - settings = openmc.Settings() - settings.particles = 1000 - settings.batches = 4 - settings.inactive = 0 - settings.source = openmc.Source(space=openmc.stats.Box( - (0, 0, 0), (5, 5, 0))) - settings.export_to_xml() + # Define settings + model.settings.particles = 1000 + model.settings.batches = 4 + model.settings.inactive = 0 + model.settings.source = openmc.Source(space=openmc.stats.Box( + (0, 0, 0), (5, 5, 0)) + ) + return model -def test_periodic(): - harness = PeriodicTest('statepoint.4.h5') +def test_periodic(box_model): + harness = PyAPITestHarness('statepoint.4.h5', box_model) harness.main() diff --git a/tests/regression_tests/periodic_6fold/inputs_true.dat b/tests/regression_tests/periodic_6fold/inputs_true.dat index 46c2a6ff55..35bbcc0475 100644 --- a/tests/regression_tests/periodic_6fold/inputs_true.dat +++ b/tests/regression_tests/periodic_6fold/inputs_true.dat @@ -1,11 +1,11 @@ - - - - - - + + + + + + diff --git a/tests/regression_tests/periodic_6fold/test.py b/tests/regression_tests/periodic_6fold/test.py index 1f8efdbf71..555ab24f9f 100644 --- a/tests/regression_tests/periodic_6fold/test.py +++ b/tests/regression_tests/periodic_6fold/test.py @@ -1,62 +1,59 @@ import openmc import numpy as np +import pytest from tests.testing_harness import PyAPITestHarness -class Periodic6FoldTest(PyAPITestHarness): - def _build_inputs(self): - # Define materials - water = openmc.Material(1) - water.add_nuclide('H1', 2.0) - water.add_nuclide('O16', 1.0) - water.add_s_alpha_beta('c_H_in_H2O') - water.set_density('g/cc', 1.0) +@pytest.fixture +def model(): + model = openmc.model.Model() - fuel = openmc.Material(2) - fuel.add_nuclide('U235', 1.0) - fuel.set_density('g/cc', 4.5) + # Define materials + water = openmc.Material() + water.add_nuclide('H1', 2.0) + water.add_nuclide('O16', 1.0) + water.add_s_alpha_beta('c_H_in_H2O') + water.set_density('g/cc', 1.0) - materials = openmc.Materials((water, fuel)) - materials.default_temperature = '294K' - materials.export_to_xml() + fuel = openmc.Material() + fuel.add_nuclide('U235', 1.0) + fuel.set_density('g/cc', 4.5) - # Define the geometry. Note that this geometry is somewhat non-sensical - # (it essentially defines a circle of half-cylinders), but it is - # designed so that periodic and reflective BCs will give different - # answers. - theta1 = (-1/6 + 1/2) * np.pi - theta2 = (1/6 - 1/2) * np.pi - plane1 = openmc.Plane(a=np.cos(theta1), b=np.sin(theta1), - boundary_type='periodic') - plane2 = openmc.Plane(a=np.cos(theta2), b=np.sin(theta2), - boundary_type='periodic') + # Define the geometry. Note that this geometry is somewhat non-sensical + # (it essentially defines a circle of half-cylinders), but it is + # designed so that periodic and reflective BCs will give different + # answers. + theta1 = (-1/6 + 1/2) * np.pi + theta2 = (1/6 - 1/2) * np.pi + plane1 = openmc.Plane(a=np.cos(theta1), b=np.sin(theta1), + boundary_type='periodic') + plane2 = openmc.Plane(a=np.cos(theta2), b=np.sin(theta2), + boundary_type='periodic') - x_max = openmc.XPlane(x0=5., boundary_type='reflective') + x_max = openmc.XPlane(x0=5., boundary_type='reflective') - z_cyl = openmc.ZCylinder(x0=3*np.cos(np.pi/6), y0=3*np.sin(np.pi/6), - r=2.0) + z_cyl = openmc.ZCylinder(x0=3*np.cos(np.pi/6), y0=3*np.sin(np.pi/6), + r=2.0) - outside_cyl = openmc.Cell(1, fill=water, region=( - +plane1 & +plane2 & -x_max & +z_cyl)) - inside_cyl = openmc.Cell(2, fill=fuel, region=( - +plane1 & +plane2 & -z_cyl)) - root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) + outside_cyl = openmc.Cell(1, fill=water, region=( + +plane1 & +plane2 & -x_max & +z_cyl)) + inside_cyl = openmc.Cell(2, fill=fuel, region=( + +plane1 & +plane2 & -z_cyl)) + root_universe = openmc.Universe(0, cells=(outside_cyl, inside_cyl)) + model.geometry = openmc.Geometry(root_universe) - geometry = openmc.Geometry() - geometry.root_universe = root_universe - geometry.export_to_xml() - - # Define settings - settings = openmc.Settings() - settings.particles = 1000 - settings.batches = 4 - settings.inactive = 0 - settings.source = openmc.Source(space=openmc.stats.Box( - (0, 0, 0), (5, 5, 0))) - settings.export_to_xml() + # Define settings + model.settings = openmc.Settings() + model.settings.particles = 1000 + model.settings.batches = 4 + model.settings.inactive = 0 + model.settings.source = openmc.Source(space=openmc.stats.Box( + (0, 0, 0), (5, 5, 0)) + ) + return model -def test_periodic(): - harness = Periodic6FoldTest('statepoint.4.h5') +def test_periodic(model): + harness = PyAPITestHarness('statepoint.4.h5', model) harness.main()