On-the-fly tally creation by openmc.lib module

Hi everyone. I’ve seen that the Python bindings to C/C++ API offer a lot of Tally and Filter classes. I’m wondering if is it possible to create a tally during execution (i.e., initialize simulation, run a some batches, create a tally, run a few more batches, extract tally information acquired during these batches by openmc.lib,tallies[id] to use it somewhere else, then somehow interrupt the tallying process by deleting the tally object, to run again a few more batches). I’m asking this because I’m dealing with functional expansion tallies with high order in a relatively large volume of the core and using it to iteratively update some thermohydraulic calculations, but such tallies are computationally expensive, and I need them only in certain points of the criticality simulation.
I’ve tried to do such process in my code, but it throws an error saying something similar to “the tally is not yet allocated” when I try to extract the newly created tally’s mean, indicating that, if this is possible at all, the tally must be “registered” in an .xml file or something. I know that maybe this is too far-fetched and I could break the simulation in several smaller simulations where I could define tallies accordingly at settings, but it would be good to know if I could do this in a more “clean” way by using the .lib module.

Thanks in advance.

Right now, creation of tallies can be done without XML but it has to happen between openmc.lib.init and openmc.lib.simulation_init. Unfortunately it’s not designed to be able to create tallies after a simulation has already started.

Hello @MMG83, welcome to the community!

After read Paul’s answer, I think to myself, “What if we can add a timestep specifier for the tally, e.g. only tally X for the [22, 23, 35, 36] timesteps?”

Thanks @paulromano for the answer and thanks @cjwiguna for the reception.

About @cjwiguna idea, I think it could be a very good addition, especially if you’re dealing with the C/C++ API with partial simulation interruptions. Since tally is an incremental quantity, I guess this would allow the user to make the compromise to sacrifice tally accuracy with less tally registers in exchange for avoiding burdening the code with heavy tally computation when the simulation is taking care of other kind of calculation steps (for example, running a thermal-hydraulic module).

This is just something that I was thinking about. I don’t know, but I guess this can be currently done by slicing the actual simulation in several “sub-simulations” and saving the data at the end of a simulation to be carried over the beginning of next one, with the tallying being done only at certain of these sub-simulations, but I thought the code might have a more “encapsulated” way to do this.

1 Like