Question about “percent_type” argument of the new method “add_elements_from_formula()” introduced in version 0.12

Hi, developpers of OpenMC,

The “percent_type” argument of “add_element_from_formula” confuses me a little, since it seems that it should not be “wo”. Thus, it may be better to remove this argument and force “percent_type” as “ao”?

Another choice is adding “percent” argument for this method and adding the following modification:

  • If “percent_type” is “ao”, the atom percent of each element in formula is “percent” arg multiplied by atom number of this element in formula.
    (e.g. call add_element(percent = percent * atom_number, percent_type = “ao”, …) in the last part of the implementation of “add_element_from_formula()”))
  • If “percent_type” is “wo”, each element’s weight percent is “percent” arg multiplied by weight percent of this element in the chemical formula.
    (e.g. call add_element(percent = percent * element_weight_percent, percent_type = “wo”, …) in the last part of the implementation of “add_element_from_formula()”)

Then users can easily define a material composed of several compounds with different weight or molecule percent. For example, UO2-Gd2O3 fuel with a density a of 10.3g/cm3 can be defined as below:




This modification can also make the arguments of this method similar to “add_element” and enables users to call both “add_element_from_formula” and “add_element” for the same openmc.Material object. Just my litte recommendation.

PS: why can’t I log in with my “staged” account?

Best regards,

Nice idea. I agree that by itself, using add_elements_from_formula along with a weight percent doesn’t seem to make much sense. You are always welcome to make a pull request proposing a change to this function, which can be found in openmc/

Regarding this login issue, I have merged your previous staged account with the one you created, so all your prior posts should now be attributed to your new account.

Thanks, Paul

I have another question. Can users add the same nuclide multiple times into a material? If so, will this lead to longer time in simulation?

For example, does
fuel.add_nuclide("U235", "ao"=1)
fuel.add_nuclide("U235", "ao"=3)
have the same effect as
fuel.add_nuclide("U235", "ao"=4)?

I tried a simple example. If I add U235 to a material twice, the result seems still correct. However, if I add H1 twice to a moderator with “c_H_in_H2O”, openmc will raise the error below during simulation:
terminate called after throwing an instance of 'std::runtime_error'
what(): Did not sample any nuclide during collision.

If it works, it is by accident because materials were not really designed to have duplicate nuclides in them. I’ve had similar discussions with others about this and it is probably something we should fix. I can see two possible resolutions: 1) check for this at the time add_nuclide is called and combine the densities or 2) check for this at the time the material is exported to XML.