|
| 1 | +from textwrap import dedent |
| 2 | + |
| 3 | +from pytest import mark, approx, param |
| 4 | +from openmc_mcnp_adapter import mcnp_str_to_model |
| 5 | + |
| 6 | + |
| 7 | +@mark.parametrize("whitespace", ["", " ", "\t"]) |
| 8 | +def test_cell_complement(whitespace): |
| 9 | + # Cell 2 corresponds to r < 2 intersected with z > 0 |
| 10 | + mcnp_str = dedent(f""" |
| 11 | + title |
| 12 | + 100 1 1.0 +1 : -2 |
| 13 | + 2 1 1.0 #{whitespace}100 |
| 14 | +
|
| 15 | + 1 so 2.0 |
| 16 | + 2 pz 0.0 |
| 17 | +
|
| 18 | + m1 1001.80c 1.0 |
| 19 | + """) |
| 20 | + model = mcnp_str_to_model(mcnp_str) |
| 21 | + cell = model.geometry.get_all_cells()[2] |
| 22 | + |
| 23 | + # Check various points |
| 24 | + assert (0., 0., 0.1) in cell.region |
| 25 | + assert (0., 0., -0.1) not in cell.region |
| 26 | + assert (0., 0., 1.99) in cell.region |
| 27 | + assert (0., 0., 2.01) not in cell.region |
| 28 | + assert (1., 1., 1.) in cell.region |
| 29 | + assert (2., 0., 1.) not in cell.region |
| 30 | + |
| 31 | + |
| 32 | +def test_likenbut(): |
| 33 | + mcnp_str = dedent(""" |
| 34 | + title |
| 35 | + 1 1 -1.0 -1 |
| 36 | + 2 LIKE 1 BUT MAT=2 RHO=-2.0 TRCL=(2.0 0.0 0.0) |
| 37 | +
|
| 38 | + 1 so 1.0 |
| 39 | +
|
| 40 | + m1 1001.80c 1.0 |
| 41 | + m2 1002.80c 1.0 |
| 42 | + """) |
| 43 | + model = mcnp_str_to_model(mcnp_str) |
| 44 | + cell = model.geometry.get_all_cells()[2] |
| 45 | + |
| 46 | + # Material should be changed to m2 |
| 47 | + mat = cell.fill |
| 48 | + assert 'H2' in mat.get_nuclide_densities() |
| 49 | + |
| 50 | + # Density should be 2.0 g/cm3 |
| 51 | + assert mat.get_mass_density() == approx(2.0) |
| 52 | + |
| 53 | + # Points should correspond to sphere of r=1 centered at (2, 0, 0) |
| 54 | + assert (2.0, 0.0, 0.0) in cell.region |
| 55 | + assert (0.0, 0.0, 0.0) not in cell.region |
| 56 | + assert (2.0, 0.9, 0.0) in cell.region |
| 57 | + assert (2.0, 1.1, 0.0) not in cell.region |
| 58 | + |
| 59 | + |
| 60 | +@mark.parametrize( |
| 61 | + "cell_card, surface_cards, points_inside, points_outside", |
| 62 | + [ |
| 63 | + ( |
| 64 | + "1 1 -1.0 -1 TRCL=(2.0 0.0 0.0)", |
| 65 | + ("1 so 1.0",), |
| 66 | + [ |
| 67 | + (2.0, 0.0, 0.0), |
| 68 | + (2.0, 0.9, 0.0), |
| 69 | + (2.0, 0.0, 0.9), |
| 70 | + ], |
| 71 | + [ |
| 72 | + (0.9, 0.0, 0.0), |
| 73 | + (2.0, 1.1, 0.0), |
| 74 | + (2.0, 0.0, 1.1), |
| 75 | + ], |
| 76 | + ), |
| 77 | + ( |
| 78 | + "1 0 -1 TRCL=(1.0 0.0 0.0 0.0 -1.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0)", |
| 79 | + ("1 rpp -0.5 0.5 -0.25 0.25 -0.1 0.1",), |
| 80 | + [ |
| 81 | + (1.0, 0.0, 0.0), |
| 82 | + (1.2, 0.0, 0.0), |
| 83 | + (1.0, 0.4, 0.0), |
| 84 | + (1.0, -0.4, 0.0), |
| 85 | + ], |
| 86 | + [ |
| 87 | + (0.7, 0.0, 0.0), |
| 88 | + (1.3, 0.0, 0.0), |
| 89 | + (1.0, 0.6, 0.0), |
| 90 | + (1.0, 0.0, 0.2), |
| 91 | + ], |
| 92 | + ), |
| 93 | + ( |
| 94 | + "1 0 -1 *TRCL=(1.0 0.0 0.0 90.0 180.0 90.0 0.0 90.0 90.0 90.0 90.0 0.0)", |
| 95 | + ("1 rpp -0.5 0.5 -0.25 0.25 -0.1 0.1",), |
| 96 | + [ |
| 97 | + (1.0, 0.0, 0.0), |
| 98 | + (1.2, 0.0, 0.0), |
| 99 | + (1.0, 0.4, 0.0), |
| 100 | + (1.0, -0.4, 0.0), |
| 101 | + ], |
| 102 | + [ |
| 103 | + (0.7, 0.0, 0.0), |
| 104 | + (1.3, 0.0, 0.0), |
| 105 | + (1.0, 0.6, 0.0), |
| 106 | + (1.0, 0.0, 0.2), |
| 107 | + ], |
| 108 | + ), |
| 109 | + param( |
| 110 | + "1 0 -1 TRCL=(0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 -1)", |
| 111 | + ("1 rpp -0.5 0.5 -0.25 0.25 -0.1 0.1",), |
| 112 | + [], |
| 113 | + [], |
| 114 | + marks=mark.xfail(reason="13-parameter TRCL not yet supported"), |
| 115 | + ), |
| 116 | + ], |
| 117 | +) |
| 118 | +def test_trcl(cell_card, surface_cards, points_inside, points_outside): |
| 119 | + surface_block = "\n".join(surface_cards) |
| 120 | + mcnp_str = dedent(f""" |
| 121 | + title |
| 122 | + {cell_card} |
| 123 | +
|
| 124 | + {surface_block} |
| 125 | +
|
| 126 | + m1 1001.80c 1.0 |
| 127 | + """) |
| 128 | + model = mcnp_str_to_model(mcnp_str) |
| 129 | + cell = model.geometry.get_all_cells()[1] |
| 130 | + |
| 131 | + for point in points_inside: |
| 132 | + assert point in cell.region |
| 133 | + |
| 134 | + for point in points_outside: |
| 135 | + assert point not in cell.region |
| 136 | + |
| 137 | + |
| 138 | +def test_trcl_fill(): |
| 139 | + mcnp_str = dedent(""" |
| 140 | + title |
| 141 | + 1 0 -1 FILL=10 TRCL=(2.0 0.0 0.0) |
| 142 | + 2 0 -2 U=10 |
| 143 | + 3 0 +2 U=10 |
| 144 | +
|
| 145 | + 1 so 10.0 |
| 146 | + 2 so 1.0 |
| 147 | +
|
| 148 | + m1 1001.80c 1.0 |
| 149 | + """) |
| 150 | + model = mcnp_str_to_model(mcnp_str) |
| 151 | + geometry = model.geometry |
| 152 | + cells = geometry.get_all_cells() |
| 153 | + |
| 154 | + # Make sure that the cells in universe 10 were shifted |
| 155 | + assert geometry.find((2.0, 0.0, 0.0))[-1] is cells[2] |
| 156 | + assert geometry.find((4.0, 0.0, 0.0))[-1] is cells[3] |
| 157 | + assert geometry.find((0.0, 0.0, 0.0))[-1] is cells[3] |
0 commit comments