|
[Sponsors] |
February 23, 2016, 03:39 |
random number generation
|
#1 | |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Hi
I am trying to generate random numbers using fluent macros from random.h. I am using Code:
uniform_random(); For example Particle A will have 0.05 and B will have 0.75 generated but this will be the same every time the simulation is run. So added Code:
set_random_seed(long newseed) Quote:
Code:
uniform_random() That is, if it generated 0.567 for particle A, that for particle B will also be 0.567. I want random numbers which are different every time for different particles. Now there is also another macro listed which I think I need to use but I dont know how. It is Code:
getUniformRandom(uniform_random_seed *seed); Also, I have tried using Code:
srand Code:
rand() So anyone knows how to put this right? |
||
February 24, 2016, 06:47 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
I never worked with the Fluent macros for random numbers, for me the following gives a uniform distribution between zero and one:
Code:
((float) rand()/RAND_MAX) |
|
February 24, 2016, 08:19 |
|
#3 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
With this one and the fluent macros, it gives the same random numbers every time you track the particles.
So if I am tracking particles A and B, they will be given random numbers say 0.1 0.2 but if I track them again they will get the same numbers again. Adding srand(time(NULL)) gives them all the same random number. So both A and B will have a random number say 0.5 which will change when I track them again to say 0.7 but both will have the same random number. I want to generate random numbers which are different overtime for all the particles. |
|
February 24, 2016, 08:53 |
|
#4 | ||
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
Quote:
Maybe you use srand in the wrong way? Your code should call srand only one time, and rand many times. So don't do this pseudo-code: Code:
for all particles { srand(time(NULL)); A=rand(); } But do this: Code:
srand(time(NULL)); for all particles { A=rand(); } |
|||
February 24, 2016, 20:32 |
|
#5 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
I was wrong, it was actually generating random numbers for the particles,which changed once every second.(makes sense).
The reason for printing the message (which i was printing to make sure the UDF was doing what I wanted) multiple times was because in my UDF i am considering particles to be trapped if they come across a water droplet based on (random number < particle collection efficiency criterion). Since a water droplet may occupy multiple cells the UDF is called again every time the particle position updates and the particle is not collected (random number > particle collection efficiency criterion) but is still in a cell where there is a water droplet. Can you think of a way, where the particle if not collected as it comes into the first cell the water droplet occupies, does not interact with the water phase anymore. Since in reality the particle if not trapped by the water will actually follow a streamline around the droplet. But in my UDF the particle gets a chance to be captured by the droplet in every cell a single droplet occupies. (droplet occupies multiple cells) |
|
February 25, 2016, 03:56 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Add a particle-UDM that is initially 0.
If the particle is in a water cell, check if this particle-UDM is zero; if and only if it is zero, do your random thing and set the particle-UDM to one. If the particle is not in a water cell, set the particle-UDM to zero. (This is not the most memory-efficient method, since you will be using a float for one bit of information, but unless you have more than hundreds of millions of particles, it won't really matter.) |
|
February 28, 2016, 21:53 |
|
#7 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
Thanks for that idea.
I am trying to learn UDM's and going through the DEFINE_DPM_EROSION udf in the manual. Code:
/* Average diameter of particles that hit the particular wall face:*/ F_UDMI(f,t,AVG_DIAMETER) = (P_DIAM(p) + num_in_data * F_UDMI(f,t,AVG_DIAMETER)) / (num_in_data + 1); Thanks Last edited by hwet; February 28, 2016 at 23:08. |
|
February 29, 2016, 19:38 |
|
#8 | |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Quote:
Code:
enum /* Enumeration of used User-Defined Memory Locations. */ { NUM_OF_HITS, /* Number of particle hits into wall face considered.*/ AVG_DIAMETER, /* Average diameter of particles that hit the wall. */ AVG_RADI_VELO, /* Average radial velocity of "" "" ------------ */ NUM_OF_USED_UDM }; |
||
February 29, 2016, 20:11 |
|
#9 |
Senior Member
Join Date: Mar 2014
Posts: 375
Rep Power: 13 |
So it is just an example and the average diameter is not actually calculated?
Sorry, I know I sound totally dumb... |
|
February 29, 2016, 20:35 |
|
#10 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
No, the average diameter of the particle parcels (they're using the DPM here) are stored in user-defined memory both at faces (with F_UDMI) and at cell centres (with C_UDMI).
Code:
/* Average diameter of particles that hit the particular wall face:*/ F_UDMI(f,t,AVG_DIAMETER) = (P_DIAM(p) + num_in_data * F_UDMI(f,t,AVG_DIAMETER)) / (num_in_data + 1); C_UDMI(c0,t0,AVG_DIAMETER) = F_UDMI(f,t,AVG_DIAMETER); |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[snappyHexMesh] snappyHexMesh sticking point | natty_king | OpenFOAM Meshing & Mesh Conversion | 11 | February 20, 2024 10:12 |
AMI speed performance | danny123 | OpenFOAM | 21 | October 24, 2020 05:13 |
[snappyHexMesh] SnappyHexMesh for internal Flow | vishwa | OpenFOAM Meshing & Mesh Conversion | 24 | June 27, 2016 09:54 |
SigFpe when running ANY application in parallel | Pj. | OpenFOAM Running, Solving & CFD | 3 | April 23, 2015 15:53 |