|
1 | 1 | import math |
2 | 2 |
|
3 | 3 | import numpy as np |
| 4 | +import pytest |
4 | 5 | from uncertainties import unumpy |
5 | 6 |
|
6 | 7 | import openmc |
@@ -112,6 +113,105 @@ def test_cylindrical_mesh_estimators(run_in_tmpdir): |
112 | 113 | std_dev = unumpy.std_devs(delta) |
113 | 114 | assert np.all(diff < 3*std_dev) |
114 | 115 |
|
| 116 | + |
| 117 | +@pytest.mark.parametrize("scale", [0.1, 1.0, 1e2, 1e4, 1e5]) |
| 118 | +def test_cylindrical_mesh_coincident(scale, run_in_tmpdir): |
| 119 | + """Test for cylindrical mesh boundary being coincident with a cell boundary""" |
| 120 | + |
| 121 | + fuel = openmc.Material() |
| 122 | + fuel.add_nuclide('U235', 1.) |
| 123 | + fuel.set_density('g/cm3', 4.5) |
| 124 | + |
| 125 | + zcyl = openmc.ZCylinder(r=1.25*scale) |
| 126 | + box = openmc.rectangular_prism(4*scale, 4*scale, boundary_type='reflective') |
| 127 | + cell1 = openmc.Cell(fill=fuel, region=-zcyl) |
| 128 | + cell2 = openmc.Cell(fill=None, region=+zcyl & box) |
| 129 | + model = openmc.Model() |
| 130 | + model.geometry = openmc.Geometry([cell1, cell2]) |
| 131 | + |
| 132 | + model.settings.particles = 100 |
| 133 | + model.settings.batches = 10 |
| 134 | + model.settings.inactive = 0 |
| 135 | + |
| 136 | + cyl_mesh = openmc.CylindricalMesh() |
| 137 | + cyl_mesh.r_grid = [0., 1.25*scale] |
| 138 | + cyl_mesh.phi_grid = [0., 2*math.pi] |
| 139 | + cyl_mesh.z_grid = [-1e10, 1e10] |
| 140 | + cyl_mesh_filter = openmc.MeshFilter(cyl_mesh) |
| 141 | + cell_filter = openmc.CellFilter([cell1]) |
| 142 | + |
| 143 | + tally1 = openmc.Tally() |
| 144 | + tally1.filters = [cyl_mesh_filter] |
| 145 | + tally1.scores = ['flux'] |
| 146 | + tally2 = openmc.Tally() |
| 147 | + tally2.filters = [cell_filter] |
| 148 | + tally2.scores = ['flux'] |
| 149 | + model.tallies = openmc.Tallies([tally1, tally2]) |
| 150 | + |
| 151 | + # Run OpenMC |
| 152 | + sp_filename = model.run() |
| 153 | + |
| 154 | + # Get flux for each of the two tallies |
| 155 | + with openmc.StatePoint(sp_filename) as sp: |
| 156 | + t1 = sp.tallies[tally1.id] |
| 157 | + t2 = sp.tallies[tally2.id] |
| 158 | + mean1 = t1.mean.ravel()[0] |
| 159 | + mean2 = t2.mean.ravel()[0] |
| 160 | + |
| 161 | + # The two tallies should be exactly the same |
| 162 | + assert mean1 == pytest.approx(mean2) |
| 163 | + |
| 164 | + |
| 165 | +@pytest.mark.parametrize("scale", [0.1, 1.0, 1e2, 1e4, 1e5]) |
| 166 | +def test_spherical_mesh_coincident(scale, run_in_tmpdir): |
| 167 | + """Test for spherical mesh boundary being coincident with a cell boundary""" |
| 168 | + |
| 169 | + fuel = openmc.Material() |
| 170 | + fuel.add_nuclide('U235', 1.) |
| 171 | + fuel.set_density('g/cm3', 4.5) |
| 172 | + |
| 173 | + sph = openmc.Sphere(r=1.25*scale) |
| 174 | + rcc = openmc.model.RectangularParallelepiped( |
| 175 | + -2*scale, 2*scale, -2*scale, 2*scale, -2*scale, 2*scale, |
| 176 | + boundary_type='reflective') |
| 177 | + cell1 = openmc.Cell(fill=fuel, region=-sph) |
| 178 | + cell2 = openmc.Cell(fill=None, region=+sph & -rcc) |
| 179 | + model = openmc.Model() |
| 180 | + model.geometry = openmc.Geometry([cell1, cell2]) |
| 181 | + |
| 182 | + model.settings.particles = 100 |
| 183 | + model.settings.batches = 10 |
| 184 | + model.settings.inactive = 0 |
| 185 | + |
| 186 | + sph_mesh = openmc.SphericalMesh() |
| 187 | + sph_mesh.r_grid = [0., 1.25*scale] |
| 188 | + sph_mesh.phi_grid = [0., 2*math.pi] |
| 189 | + sph_mesh.theta_grid = [0., math.pi] |
| 190 | + sph_mesh_filter = openmc.MeshFilter(sph_mesh) |
| 191 | + cell_filter = openmc.CellFilter([cell1]) |
| 192 | + |
| 193 | + tally1 = openmc.Tally() |
| 194 | + tally1.filters = [sph_mesh_filter] |
| 195 | + tally1.scores = ['flux'] |
| 196 | + tally2 = openmc.Tally() |
| 197 | + tally2.filters = [cell_filter] |
| 198 | + tally2.scores = ['flux'] |
| 199 | + model.tallies = openmc.Tallies([tally1, tally2]) |
| 200 | + |
| 201 | + # Run OpenMC |
| 202 | + sp_filename = model.run() |
| 203 | + |
| 204 | + # Get flux for each of the two tallies |
| 205 | + with openmc.StatePoint(sp_filename) as sp: |
| 206 | + t1 = sp.tallies[tally1.id] |
| 207 | + t2 = sp.tallies[tally2.id] |
| 208 | + mean1 = t1.mean.ravel()[0] |
| 209 | + mean2 = t2.mean.ravel()[0] |
| 210 | + |
| 211 | + # The two tallies should be exactly the same |
| 212 | + assert mean1 == pytest.approx(mean2) |
| 213 | + |
| 214 | + |
115 | 215 | def test_get_reshaped_data(run_in_tmpdir): |
116 | 216 | """Test that expanding MeshFilter dimensions works as expected""" |
117 | 217 |
|
|
0 commit comments