Sampling from Random Number Distributions
Many particle tracing physics features define expressions based on random numbers:
For all physics interfaces, when particles hit a Wall, certain types of wall condition such as Diffuse scattering can reflect or transmit the particles in a random direction. In addition, it is possible to assign two different wall conditions with some probability of each. The emission of additional particles using the Secondary Emission attribute can also be based on a probability or expression.
For The Charged Particle Tracing Interface, ions or electrons can interact with a rarefied background gas using built-in Monte Carlo collision models. The Collisions node depends on random number generation to determine which model particles undergo collisions with the background gas during each time step.
For The Particle Tracing for Fluid Flow Interface, the Brownian Force has components that are randomly generated for each particle at each time. The Drag Force may include a turbulent dispersion term that points in a random direction.
To be more specific, most of the time the above features depend on pseudorandom number generation (PRNG) rather than truly random number generation (RNG). The key difference is that RNG is based on a real source of entropy, such as radioactive decay, whereas in PRNG the numbers are obtained according to an algorithm.
Pseudorandom Number Generation
Even though pseudorandomly generated numbers are not truly random, in the sense that an observer with a perfect knowledge of the algorithm could predict the next number in a sequence given the previous numbers, from a practical standpoint PRNG is usually sufficient.
Most of the pseudorandom numbers used in particle tracing simulation will look somewhat like the following in the Equation View:
random(sin(pt.pidx),t[1/s],sin(8),sin(3))
Sometimes randomnormal is used instead of random.
The built-in random function returns a uniformly distributed pseudorandom number between -0.5 and +0.5.
The built-in randomnormal function returns a normally distributed pseudorandom number with zero mean and unit variance.
These functions are called with several arguments in order to avoid unwanted correlations that may occur for different particles, at different times, for different physics features, or for different variables within the same physics feature.
Before listing the meaning of each input argument and its purpose in avoiding unwanted correlations, a general comment is needed to explain why sin(n) is used instead of just n for some integer value of n. Because of the way in which the random and randomnormal functions work, pseudorandom numbers generated in succession are less likely to display unwanted correlations if many bits differ in their respective input arguments. In comparing the double-precision numeric values of sin(1) and sin(2), many bits differ. In contrast, most bits of the double-precision representations of 1 and 2 are exactly the same.
The first argument to the PRNG, sin(pt.pidx) in the above example, is to ensure that different particles get different values from the random or randomnormal function. The variable pidx is an integer-valued index that is unique for each model particle. If this input argument were excluded, then (for example) the Brownian Force would cause all particles to move in the same direction at any given time, which would badly distort the statistics for particle diffusion.
The second argument, t[1/s], is to ensure that the same particle is assigned different pseudorandom numbers at different time steps taken by the solver. The Drag Force with turbulent dispersion sometimes uses a different form of this argument because the discrete random walk model of turbulent dispersion assumes finite eddy lifetime.
The third input argument, sin(8) in the above example, is the sine of a unique integer for each variable used by the same physics feature, or each uncorrelated vector component for random vectors. For instance, the Brownian Force may define the following expressions to use in the force components:
randomnormal(sin(fpt.pidx),t[1/s],sin(1),sin(5))
randomnormal(sin(fpt.pidx),t[1/s],sin(2),sin(5))
randomnormal(sin(fpt.pidx),t[1/s],sin(3),sin(5))
If the same third argument were used for all force components, then the force would only be capable of moving particles diagonally along a line x = y = z cutting through the particle’s initial position, which would obviously be nonphysical.
The fourth input argument, sin(3) in the previous example, is to ensure that different nodes in the Model Builder generate uncorrelated numbers. For example, a Wall node might be given two or more Secondary Emission subnodes, each with probability-based release of a secondary particle. If the same random function arguments were used in each subnode, then either all subnodes would release a secondary particle for a given particle-wall collision, or none of them would, leaving out the possibility that only some of the secondary particles would be released.
The fourth and final input argument has the most direct mechanism for user control out of the four input arguments listed above. If you adjust the settings in the Model Builder to view Advanced Physics Options, then you can find the Arguments for random number generation list in the physics interface Advanced Settings section. The following options are available:
Generate unique arguments is the default option. When this option is selected, the fourth argument to the random and randomnormal function calls is the sine of an integer that is determined by the positioning of each node in the Model Builder. Nodes farther down in the Model Builder will have larger integer values.
When Generate random arguments is selected, the fourth input argument to the PRNG is itself randomly generated every time the study is run. This will ensure that the solution is not reproducible when running a study multiple times.
When User defined is selected, additional text fields appear in the settings windows for all nodes that use random numbers. The number entered in this text field is used as an additional argument for random number generation. A set of distinct solutions can be obtained by running a Parametric Sweep over several values of this argument.
For simple models, the Generate unique arguments and User defined options may make the solution reproducible when rerunning the study multiple times. Reproducibility is somewhat easier to achieve when using a manual time step size. However, the results may not be 100% reproducible because even the slightest change in the time step size, down to machine precision, will cause different pseudorandom numbers to be generated. This can have a snowballing effect where the different solution values cause subsequent time steps to take on different sizes, leading to different pseudorandom numbers in all ensuing time steps. The Generate random arguments option is never expected to make the solution reproducible across multiple runs of the study.
For more information about the available options, see Particle Release and Propagation in The Mathematical Particle Tracing Interface.
In the Brownian Motion tutorial, several different values of the User defined input argument are run in a Parametric Sweep. The results show similar global quantities such as transmission probability, but the paths of individual particles are uncorrelated for each parameter value.
Brownian Motion: Application Library path Particle_Tracing_Module/Verification_Examples/brownian_motion
In any model that depends on PRNG, statistical convergence of some average quantities over all particles should be considered when evaluating whether a sufficient number of model particles is released. This is analogous to the mesh refinement studies that are usually recommended to validate finite element models. For example, after running a study with 10,000 particles, consider recomputing with 20,000 particles and observe whether the difference in the average particle position at the final time is acceptably small.