CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

About Random perturbation

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By gschaider

Reply
 
LinkBack Thread Tools Display Modes
Old   July 13, 2005, 11:58
Default I want to obtain a random valu
  #1
Member
 
zoujianfeng
Join Date: Mar 2009
Location: Hangzhou, China
Posts: 30
Rep Power: 7
zou_mo is on a distinguished road
Send a message via MSN to zou_mo
I want to obtain a random value at each 'imode' loop:
for(int imode=1;imode<=10;imode++)
{
Random pertA(1234567);
ampA=pertA.GaussNormal(); Info<<"ampA:"<<ampA<<endl;
}

But, it is strange that I got the same value for all 'imode' loop! Why?

By the way, some of the random values will be great than unit? Is something wrong?
zou_mo is offline   Reply With Quote

Old   July 13, 2005, 12:05
Default Move Random pertA(1234567)
  #2
Senior Member
 
Join Date: Mar 2009
Posts: 854
Rep Power: 12
henry is on a distinguished road
Move

Random pertA(1234567);

to before the loop.
henry is offline   Reply With Quote

Old   July 13, 2005, 23:52
Default Thank you, Henry. The result i
  #3
Member
 
zoujianfeng
Join Date: Mar 2009
Location: Hangzhou, China
Posts: 30
Rep Power: 7
zou_mo is on a distinguished road
Send a message via MSN to zou_mo
Thank you, Henry. The result is nice. But some of the random values are big than 1 or less than -1. Why?

I cannot find the implementation file Random.C of the class Random. In the sub-directory 'src/OpenFOAM/primitives/random/', I found a file called Random.C which is not the right one. I use OpenFOAM1.1.
zou_mo is offline   Reply With Quote

Old   July 14, 2005, 05:34
Default Random.C is the right one, Gau
  #4
Senior Member
 
Join Date: Mar 2009
Posts: 854
Rep Power: 12
henry is on a distinguished road
Random.C is the right one, GaussNormal() is the last function in that file:

// return a normal Gaussian randon number
// with zero mean and unity variance N(0, 1)

scalar Random::GaussNormal()
{
static int iset = 0;
static scalar gset;
scalar fac, rsq, v1, v2;

if (iset == 0)
{
do
{
v1 = 2.0*scalar01() - 1.0;
v2 = 2.0*scalar01() - 1.0;
rsq = v1*v1 + v2*v2;
} while (rsq >= 1.0 || rsq == 0.0);

fac = sqrt(-2.0 * log(rsq)/rsq);
gset = v1*fac;
iset = 1;

return v2*fac;
}
else
{
iset = 0;

return gset;
}
}


I am not sure if this method is required to limit the values between -1 and 1. If it is an issue for you I suggest you clip the values although this will probably distort the Gaussian distribution slightly.
henry is offline   Reply With Quote

Old   July 14, 2005, 06:08
Default That file is random.c not Rand
  #5
Senior Member
 
Join Date: Mar 2009
Posts: 854
Rep Power: 12
henry is on a distinguished road
That file is random.c not Random.C, do you have a case-insensitive filing system?
henry is offline   Reply With Quote

Old   July 14, 2005, 06:18
Default Sorry, I have found the right
  #6
Member
 
zoujianfeng
Join Date: Mar 2009
Location: Hangzhou, China
Posts: 30
Rep Power: 7
zou_mo is on a distinguished road
Send a message via MSN to zou_mo
Sorry, I have found the right Random.C file in my cluster machines where I have installed the full package. Maybe when I transfer the source files from the cluster machines to my local PC, the file random.C overrided Random.C.

Sorry for time wasting.
zou_mo is offline   Reply With Quote

Old   May 18, 2006, 06:22
Default Dear Zou Mo Gauss distributio
  #7
Senior Member
 
Mieszko Młody
Join Date: Mar 2009
Location: POLAND, USA
Posts: 118
Rep Power: 7
ziemowitzima is on a distinguished road
Dear Zou Mo
Gauss distribution with mean 0 and variance 1 , can give values less than -1 or higer than 1.
ziemowitzima is offline   Reply With Quote

Old   December 4, 2007, 04:05
Default Hello everybody I want to o
  #8
Senior Member
 
Marhamat Zeinali
Join Date: Mar 2009
Location: Tehran, Tehran, iran
Posts: 107
Rep Power: 7
marhamat is on a distinguished road
Hello everybody

I want to obtain n random values for use at each runtime , by using OF Random-class.
But prooduced random values are similar in all runtime.

Is something wrong?
Regards
Marhamat
marhamat is offline   Reply With Quote

Old   December 4, 2007, 08:26
Default In Random points(1234567) wh
  #9
Senior Member
 
Marhamat Zeinali
Join Date: Mar 2009
Location: Tehran, Tehran, iran
Posts: 107
Rep Power: 7
marhamat is on a distinguished road
In Random points(1234567) what does mean (1234567)?And what does happen when i change 7 to 8? Why?

Thanks alot
Marhamat
marhamat is offline   Reply With Quote

Old   December 4, 2007, 09:06
Default I guess it is the seed of the
  #10
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,862
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
I guess it is the seed of the (pseudo)random sequence of numbers that is produced by the random-number-generator. By changing it you get a different sequence. But by fixing the seed you make sure that every simulation runs with the same sequence thus making the results reproducible.
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   December 5, 2007, 09:15
Default Thanks alot Bernhard I want t
  #11
Senior Member
 
Marhamat Zeinali
Join Date: Mar 2009
Location: Tehran, Tehran, iran
Posts: 107
Rep Power: 7
marhamat is on a distinguished road
Thanks alot Bernhard
I want to use different sequence in different time steps;So i think i must change the number or arrangement of digits in Random points(1234567).
After testing some case,for example:
Random points(1234567);
Random points(1234568);
Random points(1434568);
Random points(1111);
Random points(3);
I get different sequance.
But i don't know the governing rules that change random sequence of numbers by changing the number or arrangement of digits.
Q1)What Does mean the number or arrangement of these digits?
Q2)How do i controll random-number-generator for producing different sequence in different time steps?
Is any references available in this field?
Please explan me more details.

With kind regards
Marhamat
marhamat is offline   Reply With Quote

Old   December 5, 2007, 13:59
Default A random number generator gene
  #12
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,862
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
A random number generator generates a "pseudo"-random number from the previous number. The number you give to the constructor is the start of the sequence (the predescessor of your first random number)

Have a look at http://en.wikipedia.org/wiki/Random_number_generator or "The Art of computer programming" Volume 2 by Donald E. Knuth (http://en.wikipedia.org/wiki/The_Art...er_Programming) if you REALLY want to know it in detail
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   January 30, 2013, 16:59
Default
  #13
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Posts: 124
Rep Power: 7
anishtain4 is on a distinguished road
I have a problem with this Random class, I pass the seed 0 which should make random numbers on each run but the numbers are getting repeated!!! How should I force it to generate different numbers at each run time?
anishtain4 is offline   Reply With Quote

Old   January 31, 2013, 17:30
Default
  #14
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,862
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anishtain4 View Post
I have a problem with this Random class, I pass the seed 0 which should make random numbers on each run but the numbers are getting repeated!!! How should I force it to generate different numbers at each run time?
Who says that a seed 0 should give different random sequences?

Just use different seeds if you want different results. The advantage of the behaviour you describe is that results are reproducible. Which is a good thing
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 3, 2013, 07:49
Default
  #15
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Posts: 124
Rep Power: 7
anishtain4 is on a distinguished road
Guess I read it somewhere that I can't remember it. By looking at Random.C I understand you are right, but what should I do if I want to have different seeds at every run automatically? I want to make a statistical study and changing the seed manually does not look so helpful.
anishtain4 is offline   Reply With Quote

Old   February 3, 2013, 09:45
Default
  #16
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,862
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anishtain4 View Post
Guess I read it somewhere that I can't remember it. By looking at Random.C I understand you are right, but what should I do if I want to have different seeds at every run automatically? I want to make a statistical study and changing the seed manually does not look so helpful.
The way non-scientific libraries do it when no seed is provided: the get the current time via the time()-function (see "man 3 time") and use it as a seed.

OR you read the seed from a dictionary. That dictionary is manipulated with a script that changes the seed ... using a pseudo-random value ... that has a fixed seed. That way you have a statistical study ... that is reproducible
anishtain4 likes this.
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pressure perturbation Hao CFX 0 September 25, 2008 11:04
Perturbation\Disturbance, Please Guide Colin FLUENT 0 June 25, 2004 10:59
Perturbation/Disturbance , Please Guide Colin FLUENT 0 June 25, 2004 00:49
Inlet perturbation Linfeng Main CFD Forum 0 March 10, 2004 05:49
LES+initial perturbation RajaniKumar Main CFD Forum 13 December 17, 2001 15:25


All times are GMT -4. The time now is 17:38.