Support for a single model.xml file#2291
Conversation
|
This looks like the way to go, nice work Patrick. Perhaps this closes #1906? |
paulromano
left a comment
There was a problem hiding this comment.
Thanks for putting this together @pshriwise!
|
With the additional changes to exec.py to support custom file names, I’d like to add a couple more tests to ensure that works correctly. |
paulromano
left a comment
There was a problem hiding this comment.
Thanks for the updates @pshriwise! Another round of comments:
openmc/model/model.py
Outdated
| directory : str | ||
| Directory to write XML files to. If it doesn't exist already, it | ||
| will be created. |
There was a problem hiding this comment.
Rather than having separate directory and filename arguments, perhaps we should have a single path argument. When exporting separate XMLs, it would expect a directory. When exporting a single model.xml, the path could either be a directory (in which case 'model.xml' will be appended) or an explicit filename.
src/initialize.cpp
Outdated
| auto other_inputs = {"materials.xml", "geometry.xml", "settings.xml", "tallies.xml", "plots.xml"}; | ||
| for (const auto& input : other_inputs) { | ||
| if (file_exists(settings::path_input + input)) { | ||
| warning(("Other XML file input(s) are present. These file will be ignored in favor of the model.xml file.")); |
There was a problem hiding this comment.
Comment remains about need for clang-formatting
… to make sure I don't break stuff.
Incorporating suggestions from @paulromano Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
openmc/model/model.py
Outdated
|
|
||
| def export_to_xml(self, directory='.', remove_surfs=False): | ||
| """Export model to XML files. | ||
| def export_to_xml(self, directory='.', remove_surfs=False, separate_xmls=True, path='model.xml'): |
There was a problem hiding this comment.
@paulromano I'm wondering if we should take the same approach here as we did for from_xml (i.e. maintain the current export_to_xml method and add an export_to_model_xml method alongside it for now). Thoughts?
There was a problem hiding this comment.
Yeah, in light of the changes for from_xml, I think it would make sense to keep this as two separate methods as well. Thanks!
|
A couple of changes related to filesystem functions are worth noting in the latest set of updates:
|
openmc/model/model.py
Outdated
| if model.settings.entropy_mesh is not None: | ||
| meshes[model.settings.entropy_mesh.id] = model.settings.entropy_mesh |
There was a problem hiding this comment.
There's also the UFS mesh (this feels a little brittle -- wondering if there's a better way we can capture all the meshes from settings.xml)
| if model.settings.entropy_mesh is not None: | |
| meshes[model.settings.entropy_mesh.id] = model.settings.entropy_mesh | |
| if model.settings.entropy_mesh is not None: | |
| meshes[model.settings.entropy_mesh.id] = model.settings.entropy_mesh | |
| if model.settings.ufs_mesh is not None: | |
| meshes[model.settings.ufs_mesh.id] = model.settings.ufs_mesh |
There was a problem hiding this comment.
Yeah maybe we should consolidate all of the mesh writing into a single method?
☝🏻 misunderstanding on my part
How about an internal attribute on the class that tracks meshes used (updated inside the property setters). Then this would become:
meshes = {mesh.id: for mesh in model.settings._meshes}| subelement.text = str(value) | ||
|
|
||
| def _create_entropy_mesh_subelement(self, root): | ||
| def _create_entropy_mesh_subelement(self, root, mesh_memo=None): |
There was a problem hiding this comment.
Need similar changes for _create_ufs_mesh_subelement
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Several small fixes
This PR adds the ability to read a single input XML,
model.xmlas input.If this file is present, OpenMC will read the settings, materials, geometry, tallies, and plots from this file and ignore any other XML files present in the directory -- a warning will be displayed if those additional XMLs are present. If a
model.xmlfile is absent, OpenMC will fall back to using the current set of separate XML files we rely on for input.In the Python API, a
separate_xmlskeyword argument has been added to theopenmc.Modelexport_to_xmlandfrom_xmlmethods to support both reading and writing a single XML file or separate XML files. This should make it easy to either stick with the current workflow for input generation with multiple XML files or convert old inputs into a singlemodel.xmlfile.This PR is still a little rough (needs a fresh look in the morning and several tests), so I'm marking it as a draft for now.