|
| 1 | +# SPDX-FileCopyrightText: 2025 UChicago Argonne, LLC and contributors |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +from textwrap import dedent |
| 5 | + |
| 6 | +from openmc_mcnp_adapter import mcnp_str_to_model, parse_cell |
| 7 | + |
| 8 | + |
| 9 | +def test_multiparticle_importance(): |
| 10 | + """Test that multi-particle importance keywords (e.g., imp:n,p) are parsed correctly.""" |
| 11 | + mcnp_str = dedent(""" |
| 12 | + title |
| 13 | + 1 1 -1.0 -1 imp:n,p=1 |
| 14 | + 2 0 1 imp:n,p=0 |
| 15 | +
|
| 16 | + 1 so 1.0 |
| 17 | +
|
| 18 | + m1 1001.80c 1.0 |
| 19 | + mode n p |
| 20 | + """) |
| 21 | + model = mcnp_str_to_model(mcnp_str) |
| 22 | + |
| 23 | + # Get cells |
| 24 | + cells = model.geometry.get_all_cells() |
| 25 | + cell1 = cells[1] |
| 26 | + cell2 = cells[2] |
| 27 | + |
| 28 | + # Check that cells exist and have correct IDs |
| 29 | + assert cell1.id == 1 |
| 30 | + assert cell2.id == 2 |
| 31 | + |
| 32 | + # Test parse_cell directly |
| 33 | + line1 = "1 1 -1.0 -1 imp:n,p=1" |
| 34 | + cell_dict1 = parse_cell(line1) |
| 35 | + assert 'imp:n,p' in cell_dict1['parameters'] |
| 36 | + assert cell_dict1['parameters']['imp:n,p'] == '1' |
| 37 | + |
| 38 | + line2 = "2 0 1 imp:n,p=0" |
| 39 | + cell_dict2 = parse_cell(line2) |
| 40 | + assert 'imp:n,p' in cell_dict2['parameters'] |
| 41 | + assert cell_dict2['parameters']['imp:n,p'] == '0' |
| 42 | + |
| 43 | + |
| 44 | +def test_multiparticle_importance_three_particles(): |
| 45 | + line = "1 1 -1.0 -1 imp:n,|,e=1" |
| 46 | + cell_dict = parse_cell(line) |
| 47 | + assert 'imp:n,|,e' in cell_dict['parameters'] |
| 48 | + assert cell_dict['parameters']['imp:n,|,e'] == '1' |
| 49 | + |
| 50 | + |
| 51 | +def test_multiparticle_importance_with_other_params(): |
| 52 | + """Test that multi-particle importance works with other cell parameters.""" |
| 53 | + line = "1 1 -1.0 -1 imp:n,p=1 vol=5.0 u=2" |
| 54 | + cell_dict = parse_cell(line) |
| 55 | + assert 'imp:n,p' in cell_dict['parameters'] |
| 56 | + assert cell_dict['parameters']['imp:n,p'] == '1' |
| 57 | + assert cell_dict['parameters']['vol'] == '5.0' |
| 58 | + assert cell_dict['parameters']['u'] == '2' |
| 59 | + |
| 60 | + |
| 61 | +def test_single_particle_importance_still_works(): |
| 62 | + """Ensure single-particle importance still works correctly.""" |
| 63 | + line = "1 1 -1.0 -1 imp:n=1" |
| 64 | + cell_dict = parse_cell(line) |
| 65 | + assert 'imp:n' in cell_dict['parameters'] |
| 66 | + assert cell_dict['parameters']['imp:n'] == '1' |
0 commit comments