5. Making User Input Changes¶
Users are encouraged to use OpenMC’s Python API to build XML files that the OpenMC solver then reads during the initialization phase. Thus, to modify, add, or remove user input options, changes must be made both within the Python API and the C++ source that reads XML files produced by the Python API. The following steps should be followed to make changes to user input:
Determine the Python class you need to change. For example, if you are adding a new setting, you probably want to change the
openmc.Settingsclass. If you are adding a new surface type, you would need to create a subclass of
To add a new option, the class will need a property attribute. For example, if you wanted to add a “fast_mode” setting, you would need two methods that look like:
@property def fast_mode(self): ... @fast_mode.setter def fast_mode(self, fast_mode): ...
Make sure that when an instance of the class is exported to XML (usually through a
to_xml_element()method), a new element is written to the appropriate file. OpenMC uses the
xml.etree.ElementTreeAPI, so refer to the documentation of that module for guidance on creating elements/attributes.
Make sure that your input can be categorized as one of the datatypes from XML Schema Part 2 and that parsing of the data appropriately reflects this. For example, for a boolean value, true can be represented either by “true” or by “1”.
Now that you’re done with the Python side, you need to make modifications to the C++ codebase. Make appropriate changes in source files (e.g., settings.cpp). You should use convenience functions defined by xml_interface.cpp.
Finally, a set of RELAX NG schemas exists that enables validation of input files. You should modify the RELAX NG schema for the file you changed. The easiest way to do this is to change the compact syntax file (e.g.
src/relaxng/geometry.rnc) and then convert it to regular XML syntax using trang:
trang geometry.rnc geometry.rng
For most user input additions and changes, it is simple enough to follow a “monkey see, monkey do” approach. When in doubt, contact your nearest OpenMC developer or send a message to the developers mailing list.