From 3eeb13171351fc25a72a1ab54e97f7d729e21fac Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 16 Jun 2023 15:18:12 -0500 Subject: [PATCH] Add support for import of wwinp files using cylindrical and spherical meshes. (#2556) Co-authored-by: Paul Romano --- openmc/weight_windows.py | 52 ++++++----- tests/regression_tests/weightwindows/test.py | 62 +++++++++++++ .../weightwindows/ww_n_cyl.txt | 88 ++++++++++++++++++ .../weightwindows/ww_n_sph.txt | 89 +++++++++++++++++++ 4 files changed, 270 insertions(+), 21 deletions(-) create mode 100644 tests/regression_tests/weightwindows/ww_n_cyl.txt create mode 100644 tests/regression_tests/weightwindows/ww_n_sph.txt diff --git a/openmc/weight_windows.py b/openmc/weight_windows.py index 2411b83f80..bbc5c2f183 100644 --- a/openmc/weight_windows.py +++ b/openmc/weight_windows.py @@ -11,7 +11,7 @@ import h5py import openmc from openmc.filter import _PARTICLES -from openmc.mesh import MeshBase, RectilinearMesh, UnstructuredMesh +from openmc.mesh import MeshBase, RectilinearMesh, CylindricalMesh, SphericalMesh, UnstructuredMesh import openmc.checkvalue as cv from openmc.checkvalue import PathLike @@ -494,10 +494,6 @@ def wwinp_to_wws(path: PathLike) -> List[WeightWindows]: else: nt = ni * [1] - if nr == 16: - raise NotImplementedError('Cylindrical and spherical mesh ' - 'types are not yet supported') - # read number of energy bins for each particle, 'ne(1...ni)' ne = np.fromstring(wwinp.readline(), sep=' ', dtype=int) @@ -512,14 +508,18 @@ def wwinp_to_wws(path: PathLike) -> List[WeightWindows]: line_arr = np.fromstring(wwinp.readline(), sep=' ') ncx, ncy, ncz = line_arr[:3].astype(int) # read polar vector (x1, y1, z1) - xyz1 = line_arr[3:] - xyz0 - polar_vec = xyz1 / np.linalg.norm(xyz1) + xyz1 = line_arr[3:] # read azimuthal vector (x2, y2, z2) line_arr = np.fromstring(wwinp.readline(), sep=' ') - xyz2 = line_arr[:3] - xyz0 - azimuthal_vec = xyz2 / np.linalg.norm(xyz2) + xyz2 = line_arr[:3] + + # oriented polar and azimuthal vectors aren't yet supported + if np.count_nonzero(xyz1) or np.count_nonzero(xyz2): + raise NotImplementedError('Custom sphere/cylinder orientations are not supported') + # read geometry type nwg = int(line_arr[-1]) + elif nr == 10: # read rectilinear data: # number of coarse mesh bins and mesh type @@ -537,39 +537,40 @@ def wwinp_to_wws(path: PathLike) -> List[WeightWindows]: # first values in the mesh definition arrays are the first # coordinate of the grid end_idx = start_idx + 1 + 3 * ncx - x0, x_vals = ww_data[start_idx], ww_data[start_idx+1:end_idx] + i0, i_vals = ww_data[start_idx], ww_data[start_idx+1:end_idx] start_idx = end_idx end_idx = start_idx + 1 + 3 * ncy - y0, y_vals = ww_data[start_idx], ww_data[start_idx+1:end_idx] + j0, j_vals = ww_data[start_idx], ww_data[start_idx+1:end_idx] start_idx = end_idx end_idx = start_idx + 1 + 3 * ncz - z0, z_vals = ww_data[start_idx], ww_data[start_idx+1:end_idx] + k0, k_vals = ww_data[start_idx], ww_data[start_idx+1:end_idx] start_idx = end_idx # mesh consistency checks - if nr == 16 and nwg == 1: + if nr == 16 and nwg == 1 or nr == 10 and nwg != 1: raise ValueError(f'Mesh description in header ({nr}) ' f'does not match the mesh type ({nwg})') - if (xyz0 != (x0, y0, z0)).any(): + if nr == 10 and (xyz0 != (i0, j0, k0)).any(): raise ValueError(f'Mesh origin in the header ({xyz0}) ' f' does not match the origin in the mesh ' - f' description ({x0, y0, z0})') + f' description ({i0, j0, k0})') # create openmc mesh object grids = [] - mesh_definition = [(x0, x_vals, nfx), (y0, y_vals, nfy), (z0, z_vals, nfz)] + mesh_definition = [(i0, i_vals, nfx), (j0, j_vals, nfy), (k0, k_vals, nfz)] for grid0, grid_vals, n_pnts in mesh_definition: # file spec checks for the mesh definition if (grid_vals[2::3] != 1.0).any(): raise ValueError('One or more mesh ratio value, qx, ' 'is not equal to one') - if grid_vals[::3].sum() != n_pnts: - raise ValueError('Sum of the fine bin entries, s, does ' - 'not match the number of fine bins') + s = int(grid_vals[::3].sum()) + if s != n_pnts: + raise ValueError(f'Sum of the fine bin entries, {s}, does ' + f'not match the number of fine bins, {n_pnts}') # extend the grid based on the next coarse bin endpoint, px # and the number of fine bins in the coarse bin, sx @@ -580,8 +581,17 @@ def wwinp_to_wws(path: PathLike) -> List[WeightWindows]: grids.append(np.array(coords)) - mesh = RectilinearMesh() - mesh.x_grid, mesh.y_grid, mesh.z_grid = grids + if nwg == 1: + mesh = RectilinearMesh() + mesh.x_grid, mesh.y_grid, mesh.z_grid = grids + elif nwg == 2: + mesh = CylindricalMesh() + mesh.r_grid, mesh.z_grid, mesh.phi_grid = grids + mesh.origin = xyz0 + elif nwg == 3: + mesh = SphericalMesh() + mesh.r_grid, mesh.theta_grid, mesh.phi_grid = grids + mesh.origin = xyz0 # extract weight window values from array wws = [] diff --git a/tests/regression_tests/weightwindows/test.py b/tests/regression_tests/weightwindows/test.py index 3d3cf9d7ae..b7a0e4fe1d 100644 --- a/tests/regression_tests/weightwindows/test.py +++ b/tests/regression_tests/weightwindows/test.py @@ -110,3 +110,65 @@ def model(): def test_weightwindows(model): test = HashedPyAPITestHarness('statepoint.2.h5', model) test.main() + + +def test_wwinp_cylindrical(): + + ww = openmc.wwinp_to_wws('ww_n_cyl.txt')[0] + + mesh = ww.mesh + + assert mesh.dimension == (8, 8, 7) + + # make sure that the mesh grids are correct + exp_r_grid = np.hstack((np.linspace(0.0, 3.02, 3, endpoint=False), + np.linspace(3.02, 6.0001, 6))).flatten() + + exp_phi_grid = np.hstack((np.linspace(0.0, 0.25, 2, endpoint=False), + np.linspace(0.25, 1.5707, 1, endpoint=False), + np.linspace(1.5707, 3.1415, 2, endpoint=False), + np.linspace(3.1415, 4.7124, 4))).flatten() + + exp_z_grid = np.hstack((np.linspace(0.0, 8.008, 4, endpoint=False), + np.linspace(8.008, 14.002, 4))).flatten() + + assert isinstance(mesh, openmc.CylindricalMesh) + + np.testing.assert_equal(mesh.r_grid, exp_r_grid) + np.testing.assert_equal(mesh.phi_grid, exp_phi_grid) + np.testing.assert_equal(mesh.z_grid, exp_z_grid) + np.testing.assert_equal(mesh.origin, (0, 0, -9.0001)) + assert ww.lower_ww_bounds.flat[0] == 0.0 + assert ww.lower_ww_bounds.flat[-1] == np.prod(mesh.dimension) - 1 + + +def test_wwinp_spherical(): + + ww = openmc.wwinp_to_wws('ww_n_sph.txt')[0] + + mesh = ww.mesh + + assert mesh.dimension == (8, 7, 8) + + # make sure that the mesh grids are correct + exp_r_grid = np.hstack((np.linspace(0.0, 3.02, 3, endpoint=False), + np.linspace(3.02, 6.0001, 6))).flatten() + + exp_theta_grid = np.hstack((np.linspace(0.0, 0.25, 2, endpoint=False), + np.linspace(0.25, 0.5, 1, endpoint=False), + np.linspace(0.5, 0.75, 2, endpoint=False), + np.linspace(0.75, 1.5707, 3))).flatten() + + exp_phi_grid = np.hstack((np.linspace(0.0, 0.25, 2, endpoint=False), + np.linspace(0.25, 0.5, 1, endpoint=False), + np.linspace(0.5, 1.5707, 2, endpoint=False), + np.linspace(1.5707, 3.1415, 4))).flatten() + + assert isinstance(mesh, openmc.SphericalMesh) + + np.testing.assert_equal(mesh.r_grid, exp_r_grid) + np.testing.assert_equal(mesh.theta_grid, exp_theta_grid) + np.testing.assert_equal(mesh.phi_grid, exp_phi_grid) + np.testing.assert_equal(mesh.origin, (0, 0, -9.0001)) + assert ww.lower_ww_bounds.flat[0] == 0.0 + assert ww.lower_ww_bounds.flat[-1] == np.prod(mesh.dimension) - 1 diff --git a/tests/regression_tests/weightwindows/ww_n_cyl.txt b/tests/regression_tests/weightwindows/ww_n_cyl.txt new file mode 100644 index 0000000000..89232628fa --- /dev/null +++ b/tests/regression_tests/weightwindows/ww_n_cyl.txt @@ -0,0 +1,88 @@ +1 1 1 16 +1 +8.0000 7.0000 8.0000 0.0000 0.0000 -9.0001 +2.0000 2.0000 4.0000 0.0000 0.0000 0.0000 +0.0000 0.0000 0.0000 2.0000 +0.0000 3.0000 3.0200 1.0000 5.0000 6.0001 +1.0000 +0.0000 4.0000 8.0080 1.0000 3.0000 14.002 +1.0000 +0.0000 2.0000 0.25000 1.0000 1.0000 1.57070 +1.0000 2.0000 3.1415 1.0000 3.0000 4.7124 +1.0000 +100.00 +0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 +6.000000 7.000000 8.000000 9.000000 10.000000 11.000000 +12.000000 13.000000 14.000000 15.000000 16.000000 17.000000 +18.000000 19.000000 20.000000 21.000000 22.000000 23.000000 +24.000000 25.000000 26.000000 27.000000 28.000000 29.000000 +30.000000 31.000000 32.000000 33.000000 34.000000 35.000000 +36.000000 37.000000 38.000000 39.000000 40.000000 41.000000 +42.000000 43.000000 44.000000 45.000000 46.000000 47.000000 +48.000000 49.000000 50.000000 51.000000 52.000000 53.000000 +54.000000 55.000000 56.000000 57.000000 58.000000 59.000000 +60.000000 61.000000 62.000000 63.000000 64.000000 65.000000 +66.000000 67.000000 68.000000 69.000000 70.000000 71.000000 +72.000000 73.000000 74.000000 75.000000 76.000000 77.000000 +78.000000 79.000000 80.000000 81.000000 82.000000 83.000000 +84.000000 85.000000 86.000000 87.000000 88.000000 89.000000 +90.000000 91.000000 92.000000 93.000000 94.000000 95.000000 +96.000000 97.000000 98.000000 99.000000 100.000000 101.000000 +102.000000 103.000000 104.000000 105.000000 106.000000 107.000000 +108.000000 109.000000 110.000000 111.000000 112.000000 113.000000 +114.000000 115.000000 116.000000 117.000000 118.000000 119.000000 +120.000000 121.000000 122.000000 123.000000 124.000000 125.000000 +126.000000 127.000000 128.000000 129.000000 130.000000 131.000000 +132.000000 133.000000 134.000000 135.000000 136.000000 137.000000 +138.000000 139.000000 140.000000 141.000000 142.000000 143.000000 +144.000000 145.000000 146.000000 147.000000 148.000000 149.000000 +150.000000 151.000000 152.000000 153.000000 154.000000 155.000000 +156.000000 157.000000 158.000000 159.000000 160.000000 161.000000 +162.000000 163.000000 164.000000 165.000000 166.000000 167.000000 +168.000000 169.000000 170.000000 171.000000 172.000000 173.000000 +174.000000 175.000000 176.000000 177.000000 178.000000 179.000000 +180.000000 181.000000 182.000000 183.000000 184.000000 185.000000 +186.000000 187.000000 188.000000 189.000000 190.000000 191.000000 +192.000000 193.000000 194.000000 195.000000 196.000000 197.000000 +198.000000 199.000000 200.000000 201.000000 202.000000 203.000000 +204.000000 205.000000 206.000000 207.000000 208.000000 209.000000 +210.000000 211.000000 212.000000 213.000000 214.000000 215.000000 +216.000000 217.000000 218.000000 219.000000 220.000000 221.000000 +222.000000 223.000000 224.000000 225.000000 226.000000 227.000000 +228.000000 229.000000 230.000000 231.000000 232.000000 233.000000 +234.000000 235.000000 236.000000 237.000000 238.000000 239.000000 +240.000000 241.000000 242.000000 243.000000 244.000000 245.000000 +246.000000 247.000000 248.000000 249.000000 250.000000 251.000000 +252.000000 253.000000 254.000000 255.000000 256.000000 257.000000 +258.000000 259.000000 260.000000 261.000000 262.000000 263.000000 +264.000000 265.000000 266.000000 267.000000 268.000000 269.000000 +270.000000 271.000000 272.000000 273.000000 274.000000 275.000000 +276.000000 277.000000 278.000000 279.000000 280.000000 281.000000 +282.000000 283.000000 284.000000 285.000000 286.000000 287.000000 +288.000000 289.000000 290.000000 291.000000 292.000000 293.000000 +294.000000 295.000000 296.000000 297.000000 298.000000 299.000000 +300.000000 301.000000 302.000000 303.000000 304.000000 305.000000 +306.000000 307.000000 308.000000 309.000000 310.000000 311.000000 +312.000000 313.000000 314.000000 315.000000 316.000000 317.000000 +318.000000 319.000000 320.000000 321.000000 322.000000 323.000000 +324.000000 325.000000 326.000000 327.000000 328.000000 329.000000 +330.000000 331.000000 332.000000 333.000000 334.000000 335.000000 +336.000000 337.000000 338.000000 339.000000 340.000000 341.000000 +342.000000 343.000000 344.000000 345.000000 346.000000 347.000000 +348.000000 349.000000 350.000000 351.000000 352.000000 353.000000 +354.000000 355.000000 356.000000 357.000000 358.000000 359.000000 +360.000000 361.000000 362.000000 363.000000 364.000000 365.000000 +366.000000 367.000000 368.000000 369.000000 370.000000 371.000000 +372.000000 373.000000 374.000000 375.000000 376.000000 377.000000 +378.000000 379.000000 380.000000 381.000000 382.000000 383.000000 +384.000000 385.000000 386.000000 387.000000 388.000000 389.000000 +390.000000 391.000000 392.000000 393.000000 394.000000 395.000000 +396.000000 397.000000 398.000000 399.000000 400.000000 401.000000 +402.000000 403.000000 404.000000 405.000000 406.000000 407.000000 +408.000000 409.000000 410.000000 411.000000 412.000000 413.000000 +414.000000 415.000000 416.000000 417.000000 418.000000 419.000000 +420.000000 421.000000 422.000000 423.000000 424.000000 425.000000 +426.000000 427.000000 428.000000 429.000000 430.000000 431.000000 +432.000000 433.000000 434.000000 435.000000 436.000000 437.000000 +438.000000 439.000000 440.000000 441.000000 442.000000 443.000000 +444.000000 445.000000 446.000000 447.000000 diff --git a/tests/regression_tests/weightwindows/ww_n_sph.txt b/tests/regression_tests/weightwindows/ww_n_sph.txt new file mode 100644 index 0000000000..3f9b8dab6d --- /dev/null +++ b/tests/regression_tests/weightwindows/ww_n_sph.txt @@ -0,0 +1,89 @@ +1 1 1 16 +1 +8.0000 7.0000 8.0000 0.0000 0.0000 -9.0001 +2.0000 4.0000 4.0000 0.0000 0.0000 0.0000 +0.0000 0.0000 0.0000 3.0000 +0.0000 3.0000 3.0200 1.0000 5.0000 6.0001 +1.0000 +0.0000 2.0000 0.25000 1.0000 1.0000 0.50000 +1.0000 2.0000 0.75000 1.0000 2.0000 1.5707 +1.0000 +0.0000 2.0000 0.25000 1.0000 1.0000 0.50000 +1.0000 2.0000 1.5707 1.0000 3.0000 3.1415 +1.0000 +100.00 +0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 +6.000000 7.000000 8.000000 9.000000 10.000000 11.000000 +12.000000 13.000000 14.000000 15.000000 16.000000 17.000000 +18.000000 19.000000 20.000000 21.000000 22.000000 23.000000 +24.000000 25.000000 26.000000 27.000000 28.000000 29.000000 +30.000000 31.000000 32.000000 33.000000 34.000000 35.000000 +36.000000 37.000000 38.000000 39.000000 40.000000 41.000000 +42.000000 43.000000 44.000000 45.000000 46.000000 47.000000 +48.000000 49.000000 50.000000 51.000000 52.000000 53.000000 +54.000000 55.000000 56.000000 57.000000 58.000000 59.000000 +60.000000 61.000000 62.000000 63.000000 64.000000 65.000000 +66.000000 67.000000 68.000000 69.000000 70.000000 71.000000 +72.000000 73.000000 74.000000 75.000000 76.000000 77.000000 +78.000000 79.000000 80.000000 81.000000 82.000000 83.000000 +84.000000 85.000000 86.000000 87.000000 88.000000 89.000000 +90.000000 91.000000 92.000000 93.000000 94.000000 95.000000 +96.000000 97.000000 98.000000 99.000000 100.000000 101.000000 +102.000000 103.000000 104.000000 105.000000 106.000000 107.000000 +108.000000 109.000000 110.000000 111.000000 112.000000 113.000000 +114.000000 115.000000 116.000000 117.000000 118.000000 119.000000 +120.000000 121.000000 122.000000 123.000000 124.000000 125.000000 +126.000000 127.000000 128.000000 129.000000 130.000000 131.000000 +132.000000 133.000000 134.000000 135.000000 136.000000 137.000000 +138.000000 139.000000 140.000000 141.000000 142.000000 143.000000 +144.000000 145.000000 146.000000 147.000000 148.000000 149.000000 +150.000000 151.000000 152.000000 153.000000 154.000000 155.000000 +156.000000 157.000000 158.000000 159.000000 160.000000 161.000000 +162.000000 163.000000 164.000000 165.000000 166.000000 167.000000 +168.000000 169.000000 170.000000 171.000000 172.000000 173.000000 +174.000000 175.000000 176.000000 177.000000 178.000000 179.000000 +180.000000 181.000000 182.000000 183.000000 184.000000 185.000000 +186.000000 187.000000 188.000000 189.000000 190.000000 191.000000 +192.000000 193.000000 194.000000 195.000000 196.000000 197.000000 +198.000000 199.000000 200.000000 201.000000 202.000000 203.000000 +204.000000 205.000000 206.000000 207.000000 208.000000 209.000000 +210.000000 211.000000 212.000000 213.000000 214.000000 215.000000 +216.000000 217.000000 218.000000 219.000000 220.000000 221.000000 +222.000000 223.000000 224.000000 225.000000 226.000000 227.000000 +228.000000 229.000000 230.000000 231.000000 232.000000 233.000000 +234.000000 235.000000 236.000000 237.000000 238.000000 239.000000 +240.000000 241.000000 242.000000 243.000000 244.000000 245.000000 +246.000000 247.000000 248.000000 249.000000 250.000000 251.000000 +252.000000 253.000000 254.000000 255.000000 256.000000 257.000000 +258.000000 259.000000 260.000000 261.000000 262.000000 263.000000 +264.000000 265.000000 266.000000 267.000000 268.000000 269.000000 +270.000000 271.000000 272.000000 273.000000 274.000000 275.000000 +276.000000 277.000000 278.000000 279.000000 280.000000 281.000000 +282.000000 283.000000 284.000000 285.000000 286.000000 287.000000 +288.000000 289.000000 290.000000 291.000000 292.000000 293.000000 +294.000000 295.000000 296.000000 297.000000 298.000000 299.000000 +300.000000 301.000000 302.000000 303.000000 304.000000 305.000000 +306.000000 307.000000 308.000000 309.000000 310.000000 311.000000 +312.000000 313.000000 314.000000 315.000000 316.000000 317.000000 +318.000000 319.000000 320.000000 321.000000 322.000000 323.000000 +324.000000 325.000000 326.000000 327.000000 328.000000 329.000000 +330.000000 331.000000 332.000000 333.000000 334.000000 335.000000 +336.000000 337.000000 338.000000 339.000000 340.000000 341.000000 +342.000000 343.000000 344.000000 345.000000 346.000000 347.000000 +348.000000 349.000000 350.000000 351.000000 352.000000 353.000000 +354.000000 355.000000 356.000000 357.000000 358.000000 359.000000 +360.000000 361.000000 362.000000 363.000000 364.000000 365.000000 +366.000000 367.000000 368.000000 369.000000 370.000000 371.000000 +372.000000 373.000000 374.000000 375.000000 376.000000 377.000000 +378.000000 379.000000 380.000000 381.000000 382.000000 383.000000 +384.000000 385.000000 386.000000 387.000000 388.000000 389.000000 +390.000000 391.000000 392.000000 393.000000 394.000000 395.000000 +396.000000 397.000000 398.000000 399.000000 400.000000 401.000000 +402.000000 403.000000 404.000000 405.000000 406.000000 407.000000 +408.000000 409.000000 410.000000 411.000000 412.000000 413.000000 +414.000000 415.000000 416.000000 417.000000 418.000000 419.000000 +420.000000 421.000000 422.000000 423.000000 424.000000 425.000000 +426.000000 427.000000 428.000000 429.000000 430.000000 431.000000 +432.000000 433.000000 434.000000 435.000000 436.000000 437.000000 +438.000000 439.000000 440.000000 441.000000 442.000000 443.000000 +444.000000 445.000000 446.000000 447.000000