Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/openmc_mcnp_adapter/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,9 @@ def sanitize(section: str) -> str:
# Remove end-of-line comments
section = re.sub(r'\$.*$', '', section, flags=re.MULTILINE)

# Remove comment cards
section = re.sub('^[ \t]*?[cC].*?$\n?', '', section, flags=re.MULTILINE)
# Remove comment cards: 'c' in first 5 columns followed by at least one
# blank, or 'c' as the only character on the line
section = re.sub(r'^[ \t]{0,4}[cC](?:[ \t]+.*)?$\n?', '', section, flags=re.MULTILINE)

# Turn continuation lines into single line
section = re.sub('&.*\n', ' ', section)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,27 @@ def test_material_without_keywords():
nd = m.get_nuclide_densities()
assert 'U235' in nd and nd['U235'].percent == approx(1.0)
assert 'U238' in nd and nd['U238'].percent == approx(0.5)

def test_material_with_code_keyword():
"""Test that keywords starting with 'c' are not treated as comment cards"""
# This tests the case where continuation line has keyword starting with 'c'
# The 'code=0' line should not be treated as a comment card
mcnp_model = textwrap.dedent("""
title
1 1 -1.0 1
2 2 -1.0 -1

1 px 0.0

m1 1001.70c 1.0 &
code=0
m2 1001.70c 1.0
""")
model = mcnp_str_to_model(mcnp_model)
# Should have two distinct materials
assert len(model.materials) == 2
# Both materials should have H1
for mat in model.materials:
nd = mat.get_nuclide_densities()
assert 'H1' in nd
assert nd['H1'].percent == approx(1.0)