|
1 | 1 | """Tests for surface flux tallying via flux score + SurfaceFilter.""" |
2 | 2 |
|
3 | 3 | import math |
| 4 | +import numpy as np |
4 | 5 | import pytest |
5 | 6 |
|
6 | 7 | import openmc |
@@ -118,3 +119,44 @@ def test_cellfrom_filter_flux_directional(two_cell_model, run_in_tmpdir): |
118 | 119 | assert mean_from1 == pytest.approx(1.0) |
119 | 120 | # No particles cross xmid from cell2 → flux = 0 |
120 | 121 | assert mean_from2 == pytest.approx(0.0) |
| 122 | + |
| 123 | + |
| 124 | +def test_surface_filter_do_not_tally_virtual_surface_crossing(run_in_tmpdir): |
| 125 | + openmc.reset_auto_ids() |
| 126 | + model = openmc.Model() |
| 127 | + zmin = openmc.ZPlane(z0 = -1.0, surface_id=1, name="plane 1") |
| 128 | + zmax = openmc.ZPlane(z0 = 1.0, surface_id=2, name="plane 2") |
| 129 | + ymin = openmc.YPlane(y0 = -1.0, surface_id=3, name="plane 3") |
| 130 | + ymax = openmc.YPlane(y0 = 1.0, surface_id=4, name="plane 4") |
| 131 | + xmin = openmc.XPlane(x0 = -1.0, surface_id=5, name="plane 5") |
| 132 | + xmax = openmc.XPlane(x0 = 1.0, surface_id=6, name="plane 6") |
| 133 | + sph = openmc.Sphere(r=100.0, boundary_type='vacuum') |
| 134 | + |
| 135 | + cube = (+zmin & -zmax & +ymin & -ymax & +xmin & -xmax ) |
| 136 | + sphere = -sph&~(cube) |
| 137 | + |
| 138 | + cube_cell = openmc.Cell(region=cube) |
| 139 | + sphere_cell = openmc.Cell(region=sphere) |
| 140 | + |
| 141 | + univ = openmc.Universe(cells=[cube_cell, sphere_cell]) |
| 142 | + model.geometry = openmc.Geometry(univ) |
| 143 | + |
| 144 | + src = openmc.IndependentSource() |
| 145 | + src.space = openmc.stats.Point((0.0, 0.0, 0.0)) |
| 146 | + |
| 147 | + model.settings.run_mode = 'fixed source' |
| 148 | + model.settings.batches = 1 |
| 149 | + model.settings.particles = 100 |
| 150 | + model.settings.source = src |
| 151 | + |
| 152 | + surface_filter = openmc.SurfaceFilter([1,2,3,4,5,6]) |
| 153 | + tally = openmc.Tally() |
| 154 | + tally.scores = ["current"] |
| 155 | + tally.filters = [surface_filter] |
| 156 | + model.tallies = [tally] |
| 157 | + |
| 158 | + model.run(apply_tally_results=True) |
| 159 | + current_mean = np.abs(tally.mean.flatten()) |
| 160 | + |
| 161 | + # Every particle crosses exit the cube with weight 1, so current = 1.0 |
| 162 | + assert current_mean.sum() == pytest.approx(1.0, rel=1e-8) |
0 commit comments