-
Notifications
You must be signed in to change notification settings - Fork 3
Tallies
In PINSPEC it is possible to create tallies by region, material, and isotope. These tallies are defined and registered before the command to run the Monte Carlo simulation. The tally types available in PINSPEC, followed by their keyword, are:
- flux, FLUX
- elastic scattering rate, ELASTIC_RATE
- capture rate, CAPTURE_RATE
- fission rate, FISSION_RATE
- absorption rate, ABSORPTION_RATE
- transport rate, TRANSPORT_RATE
- diffusion rate, DIFFUSION_RATE
- collision rate, COLLISION_RATE
Tallies are created using the createTally() function from the TallyFactory() module. The createTally() function takes two required arguments and an optional argument. The first argument is the focus of the tally, be it material, region, or isotope. The second argument is a keyword denoting the type of tally, which are listed above.
>>> flux = TallyFactory.createTally(region_mix, FLUX)
It is possible to tally over the entire problem's geometry by using the "geometry" keyword, as shown below in the example.
>>> elastic_rate = TallyFactory.createTally(geometry, ELASTIC_RATE)
>>> capture_rate = TallyFactory.createTally(geometry, CAPTURE_RATE)
>>> fission_rate = TallyFactory.createTally(geometry, FISSION_RATE)
A third (optional) argument is the name of the tally, which is used for plot descriptions. This is demonstrated below, in which it is assumed that materials with the handles 'moderator' and 'fuel' have already been created.
>>> total_flux = TallyFactory.createTally(geometry, FLUX, 'total')
>>> moderator_flux = TallyFactory.createTally(moderator, FLUX, 'moderator')
>>> fuel_flux = TallyFactory.createTally(fuel, FLUX, 'fuel')
###Tally Options Once the tallies have been created, the energy bins for them must be designated. There are two functions available for setting up energy bins: generateBinEdges() and setBinEdges(). The arguments for generateBinEdges() in order are the lower bound, the upper bound, the number of bins, and the keyword for either a log scale or linear scale (LOGARITHMIC, LINEAR).
>>> flux = TallyFactory.createTally(region_mix, FLUX)
>>> flux.generateBinEdges(1E-2, 1E7, 10000, LOGARITHMIC)
setBinEdges() allows for a numpy array to be created so that users can designate bins at different widths:
>>> moderator_flux_ratio = TallyFactory.createTally(moderator, FLUX,'Moderator Flux')
>>> flux_bin_edges = numpy.array([0., 0.1, 0.5, 1., 6., 10., 25., 50., 1E2, 1E3, 1E4, 1E5, 5E5, 1E7])
>>> moderator_flux_ratio.setBinEdges(flux_bin_edges)
Another nifty tally option is setPrecisionTrigger(). This command allows the user to end a simulation only after a set precision has been reached on a tally. The first argument is the trigger type(VARIANCE, STANDARD_DEVIATION, or RELATIVE_ERROR), and the second argument is a float representing the precision at which the type should reach:
>>> elastic_rate.setPrecisionTrigger(VARIANCE, 0.001)
After creating tallies and setting up the energy grid, each tally must be registered. It should be noted that derived tally types do not need to be registered.
>>> TallyBank.registerTally(elastic_rate)
>>> TallyBank.registerTally(capture_rate)
>>> TallyBank.registerTally(fission_rate)
After the tallies have been set and registered, the command to run the simulation is:
>>> geometry.runMonteCarloSimulation()
An important thing to note is that each time the simulation is run, the tallies are zeroed out. This means that if a loop is put over the simulations, the tally values do not need to be reset.
After the simulation has run and tallies have been updated, there are a couple of tally output options available. The outputBatchStatistics() command causes the tallies and their statistics to be written to an output file. If it is called from the Tallybank, like below, the command calls each tally object to write to files. If it is called by a certain tally, only that tally will write to file and the command takes an argument that is the filename of the output.
>>> TallyBank.outputBatchStatistics()
or
>>> flux.outputBatchStatistics()
Another option is printTallies(). This command prints the tallies to the screen. It takes an argument of True or False, and its default is False.
>>> flux.printXS(uncertainties=True)
Post-simulation, it is also possible to do simple arithmetic with tallies using the tally operators. These operations actually create a new tally that automatically updates the statistics. Addition, subtraction, multiplication, and division are all possible between tallies and constants.
A new tally can be created as a result of basic arithmetic between two tallies using the operands '+', '-', '*', and '/'. The only requirement is that the tallies are the same size and have the same bin spacing. Some basic examples are below:
>>> new_tally = tally1 + tally2
>>> new_tally = tally1 - tally2
>>> new_tally = tally1 * tally2
>>> new_tally = tally1 / tally2
It is also possible to multiply, divide, add, or subtract a constant from a tally. Aside from the operands, the only necessary format for the operation is that the tally be on the left side of the operand. The constants themselves can be integers, floats, or doubles, as shown in the examples below:
>>> new_tally = tally * int(3)
>>> new_tally = tally * float(3.5)
>>> new_tally = tally * double(3.5)
>>> new_tally = tally + int(3)
>>> new_tally = tally + float(3.5)
>>> new_tally = tally + double(3.5)
>>> new_tally = tally - int(3)
>>> new_tally = tally - float(3.5)
>>> new_tally = tally - double(3.5)
>>> new_tally = tally1 / int(3)
>>> new_tally = tally1 / float(3.5)
>>> new_tally = tally1 / double(3.5)
It's also possible to do the same operations with arrays of numbers, as long as they are the same size as the tally.
>>> array = numpy.array([1.2, 3.5, 4.7, 8.2], dtype=numpy.float64)
>>> new_flux_tally = flux.multiplyDoubles(array)
The other operations follow the same format: multiplyDoubles(), multiplyFloats(), multiplyIntegers() divideDoubles(), divideFloats(), divideIntegers() addDoubles(), addFloats(), addIntegers() subtractDoubles(), subtractFloats(), subtractIntegers()
Other tally operations can be found in the documentation, under the Tally(), TallyBank(), and TallyFactory() classes.