Skip to content

Small Fixes to Allow Random Ray to Work with DAGMC - #3374

Merged
pshriwise merged 6 commits into
openmc-dev:developfrom
jtramm:dagmc_fixes
Apr 22, 2025
Merged

pshriwise merged 6 commits into
openmc-dev:developfrom
jtramm:dagmc_fixes

Conversation

@jtramm

@jtramm jtramm commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

Problem

Currently there are a few small issues with running DAGMC geometries in random ray mode:

  • DAGMC materials can fail to have MGXS data generated due to a lack of synchronization between the DAGMC model and the cells.
  • A "negative transport distance" error can be reported, due to embedded surfaces in the DAGMC model.
  • The code can hit a fatal error at launch due to a temperature data being embedded into the DAGMC model.

Fixes

This PR makes a few small tweaks to avoid the above issues:

  • The following snippet is added to the model.convert_to_multigroup() function:
        for univ in self.geometry.get_all_universes().values():
            if isinstance(univ, openmc.DAGMCUniverse):
                self.init_lib()
                self.sync_dagmc_universes()
                self.finalize_lib()
                break

which ensures that all materials are registered properly. It would be nice in the future to not have to call init_lib() and finalize_lib(), so as to avoid generating all the extra .xml files. @pshriwise - any other options?

  • Previously the random ray transport code considered a "distance to boundary" of 0.0 to be an error. We now only consider a negative number an error. This seems to fix the issues and several CAD test models are running cleanly now.

  • The fatal error at launch regarding multiple temperatures being detected has been downgraded to a warning. If using the model.convert_to_multigroup() function, the data will be isothermal anyway, even if there are multiple temperatures in the model. Notably, the MGXS data is always material-wise currently, so if you have the same material at multiple different temperatures in different cells, then the MC solve will be combining all those regions into one material tally. If you created different materials each with a different temperature, then they will remain different when moving to MGXS. The MGXS library is not universally isothermal over all materials, it is just isothermal for each material. In summary, we will just pick the first temperature now and warn the user about the issue.

Results

We're now able to run some pretty cool DAGMC geometries with random ray & FW-CADIS, e.g. an unconverged stellarator:

Screenshot 2025-04-11 at 4 18 47 PM

Screenshot 2025-04-11 at 2 58 50 PM

Just a few iterations of results here, so pretty noisy, but good to see DAGMC working as expected for random ray.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@jtramm
jtramm requested a review from paulromano April 11, 2025 21:20
@pshriwise

Copy link
Copy Markdown
Contributor

Fantastic @jtramm!!! Can't wait to try this out!

It would be nice in the future to not have to call init_lib() and finalize_lib(), so as to avoid generating all the extra .xml files. @pshriwise - any other options?

I'd say we should adopt some of the same mechanics as the plotting methods and perform the whole multi-group conversion in a tmpdir context like the Model.plot method does, but write the mgxs.h5 file in the current directory of course. Would that be feasible?

with TemporaryDirectory() as tmpdir:

Previously the random ray transport code considered a "distance to boundary" of 0.0 to be an error. We now only consider a negative number an error. This seems to fix the issues and several CAD test models are running cleanly now.

Ah yeah there are sometimes zero distance intersections at times in DAGMC when crossing through geometric curves.

As for the second bullet, the issue with temperatures applies to a CSG model as well right? Or is this a DAGMC-specific problem?

@jtramm

jtramm commented Apr 11, 2025

Copy link
Copy Markdown
Contributor Author

Good thinking on the with TemporaryDirectory() as tmpdir: -- that should make things a good deal cleaner for the whole process.

The temperature issue does affect CSG geometries as well. For CSG, the user at least has the ability to easily edit any cell/material temperatures, so the fatal warning didn't seem as big of an issue. In the case of CAD though, I'm thinking that not everyone running a model may be able to edit the .h5m, which may have temperatures embedded, so it makes sense to have this be just a warning instead.

@pshriwise

Copy link
Copy Markdown
Contributor

The temperature issue does affect CSG geometries as well. For CSG, the user at least has the ability to easily edit any cell/material temperatures, so the fatal warning didn't seem as big of an issue. In the case of CAD though, I'm thinking that not everyone running a model may be able to edit the .h5m, which may have temperatures embedded, so it makes sense to have this be just a warning instead.

Ahhh I see. It's a matter of changing the temperatures, not just reading them. Yeah, we'd need to extend the current capability related to materials to apply to temperatures as well in this case. 👍🏻

@jtramm

jtramm commented Apr 15, 2025

Copy link
Copy Markdown
Contributor Author

I've made the necessary changes to allow for model.convert_to_multigroup() to run in a temp directory, so that XML files generated by the MGXS generation solve and the model.init_lib() call if using dagmc do not pollute the user's CWD.

@pshriwise pshriwise left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good @jtramm! Thanks for sorting these items out so we can use CAD!

Just a couple of tiny comments.

Comment thread openmc/model/model.py Resolved
Comment thread openmc/model/model.py

# Determine if this is a DAGMC geometry. If so, we need to syncronize
# the dagmc materials with cells.
# TODO: Can this be done without having to init/finalize?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not at the moment. Detecting the current material assignments and DAGMC cell IDs as used during transport requires loading the file with the DAGMC library in C++.

Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
@pshriwise
pshriwise enabled auto-merge (squash) April 22, 2025 16:51
@pshriwise
pshriwise merged commit a113440 into openmc-dev:develop Apr 22, 2025
yardasol pushed a commit to yardasol/openmc that referenced this pull request Dec 25, 2025
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
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.

2 participants