CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Non-randomness in general distribution (particle diameter)

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By GerhardHolzinger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 26, 2019, 16:12
Default Non-randomness in general distribution (particle diameter)
  #1
New Member
 
Eduardo Cruz
Join Date: Oct 2018
Posts: 13
Rep Power: 8
ECruz is on a distinguished road
Hi everyone,

I'm running some LPT simulations with icoUncoupledKinematicParcelFoam. I want the particle diameters to follow a particular distribution, so I am using the distributionModel general. Everything works fine, and if you take the whole sample of particles, they indeed follow the desired distribution. The problem is if I run the same case twice, the result is exactly the same (i.e. every single particle has the same diameter in both runs). But from my understanding, looking at the source code, this should not happen. Specially because inside the Foam::distributionModels::general::sample() function there is a line

Code:
    scalar y = rndGen_.sample01<scalar>();
I'd really like to understand why. Any help is deeply appreciated.

Regards,

ECruz
ECruz is offline   Reply With Quote

Old   June 27, 2019, 05:03
Default
  #2
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
Computational randomness and randomness aren't the same thing.

If read on how computers generate random numbers, e.g. on Wikipedia, you will find that random number generators are refered to as pseudo random number generators, since computers are not very good at random behaviour.

A random number generator (RNG) is typically provided with a seed value, from which it starts to create a sequence of numbers, which has the statistical properties of a random distribution.
However, given the same seed value, different runs of the RNG will result in the same sequence of "random" numbers.

If you want to achive non-equal sequences, you need to provide a different seed value each time you run the RNG.

If you search OpenFOAM's code base for instances of calling the constructor of the RNG, you will find that OpenFOAM uses fixed seed values.

Running
Code:
git grep 'rndGen('
yields results similar to the following

Code:
rndGen_(0) // in the constructor of KinematicCloud
meshTools/triSurface/booleanOps/surfaceIntersection/edgeIntersections.C:    Random rndGen(356574);

So, why use fixed seed values?

First: debugging. You want your code to behave the same way each time you test it. Otherwise it's hard to distinguish a newly introduced bug from the inherent randomness.

Second: is it really necessary for your code to deliver different random numbers each time you run it? Sure, if you're in information security that's essential. But in CFD?



So, if you want to have different random numbers each time you run the code, provide something as seed value that's changing constantly, e.g. the time:

Code:
Random ranGen(clock::getTime());
or the time plus the process ID

Code:
Random ranGen(clock::getTime()+pid());
raptorishungry likes this.
GerhardHolzinger is offline   Reply With Quote

Old   June 27, 2019, 10:59
Default
  #3
New Member
 
Eduardo Cruz
Join Date: Oct 2018
Posts: 13
Rep Power: 8
ECruz is on a distinguished road
Thanks a lot, GerhardHolzinger,


I know a little bit about pseudo-randomness. I just didn't know that OpenFOAM used a fixed seed. But your explanation makes it very clear why it is so.


ECruz
ECruz is offline   Reply With Quote

Reply

Tags
distributionmodels, general distribution


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Particle tracking error alchem OpenFOAM Bugs 5 May 6, 2017 17:30
Particle distribution [ Length number density vs Particle diameter ] winkungzxl ANSYS 1 May 8, 2016 22:00
Monitor particle diameter and its frequency at a plane Lola27 STAR-CCM+ 1 December 19, 2013 06:33
injection problem Mark New FLUENT 0 August 4, 2013 02:30
forced to sticking of soot particle kmgraju CFX 0 November 27, 2012 10:08


All times are GMT -4. The time now is 22:30.