Skip to content

Conversation

@tjlaboss
Copy link
Contributor

Closes #29

Where a READ card is found, recursively insert the contents of the target FILE=.... Other keywords (ECHO, NOECHO, ENCODE=..., and DECODE=...) are ignored.


Example:

testRead.imcnp:

Testing read card
C this is a comment
read echo file=testReadTarget.imcnp encode

1 so 0.5

mode n

testReadTarget.imcnp:

1 0 -1
read file=testReadRecursive.imcnp
c

testReadRecursive.imcnp:

2 0 +1  $ lowest level

This becomes:

Testing read card
C this is a comment
1 0 -1
2 0 +1  $ lowest level
c

1 so 0.5

mode n

And thereby:

<?xml version='1.0' encoding='utf-8'?>
<model>
  <materials>
  </materials>
  <geometry>
    <cell id="1" material="void" region="-1" universe="0"/>
    <cell id="2" material="void" region="1" universe="0"/>
    <surface coeffs="0.0 0.0 0.0 0.5" id="1" type="sphere"/>
  </geometry>
  <settings>
    <run_mode>eigenvalue</run_mode>
    <particles>100</particles>
    <batches>40</batches>
    <inactive>20</inactive>
    <source particle="neutron" strength="1.0" type="independent">
      <space type="point">
        <parameters>0.0 0.0 0.0</parameters>
      </space>
    </source>
    <output>
      <summary>true</summary>
    </output>
  </settings>
  </model>

Comment on lines 28 to 35
_READ_RE = re.compile(r"""
\s*read # Keyword
\s.*?file # Everything up to filename
\s*=\s* # = sign (required) with optional spaces
(\S+) # The file name is anything without whitespace
.* # Anything else until end-of-line
""", re.IGNORECASE | re.VERBOSE
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to be perfectly robust in that it may be overly generous with what counts as a read, but I think it's probably robust enough.

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjlaboss Thanks for this addition! I've started to add proper tests on this repo so it would be prudent to have a test for this as well. Can you put together a test?

@MicahGale
Copy link

@tjlaboss want any help with tests?

@tjlaboss tjlaboss requested a review from paulromano May 29, 2025 16:13
@tjlaboss
Copy link
Contributor Author

Added tests. I included a new tests/inputs/ directory. It necessarily breaks from the convention of the other tests including the MCNP decks as strings because the target of read file=... must be a file path.

Copy link

@MicahGale MicahGale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

What's your patch coverage though?

@tjlaboss
Copy link
Contributor Author

@paulromano, are these tests acceptable?

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made two small updates: 1) use pathlib over os.path, and 2) make the regex multiline and add ^, which makes it about 4× faster in my testing. Good to go now!

@paulromano paulromano merged commit fc1ceb3 into openmc-dev:main Sep 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support READ cards

3 participants