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

How to add random perturbation for velocity in Openfoam

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 1 Post By Tobi
  • 3 Post By Tobi
  • 2 Post By tomf

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 21, 2017, 04:29
Default How to add random perturbation for velocity in Openfoam
  #1
Member
 
Maria
Join Date: Jul 2013
Posts: 84
Rep Power: 12
marialhm is on a distinguished road
Hi dear all,

I have a model in which the inlet velocity is in x direction, while random perturbations in Y direction is needed. What kind of boundary condition or functions should I use, and how?

Thanks in advance!

Maria
marialhm is offline   Reply With Quote

Old   June 22, 2017, 03:14
Default
  #2
Senior Member
 
Tom Fahner
Join Date: Mar 2009
Location: Breda, Netherlands
Posts: 634
Rep Power: 32
tomf will become famous soon enoughtomf will become famous soon enough
Send a message via MSN to tomf Send a message via Skype™ to tomf
Hi Maria,

I think you should look at either groovyBC (from swak4Foam) or turbulentInlet. I guess the latter would do just fine. Please note that there may be some pressure fluctuations introduced and when the fluctuations are too large you may get problems with convergence..

Regards,
Tom
tomf is offline   Reply With Quote

Old   June 22, 2017, 03:24
Default
  #3
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi Maria and Tom,

I think Tom's idea is one of the easiest and simplest. For competence, you also could use a codedFixedBC, in which you define your x-value as a constant and the y-value could be build randomly using the Random class of OpenFOAM. However, using groovyBC should be more easier (depend on the point of view and your programming knowledge). I just wanted to mention this way too.

Cheers.
cryabroad likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   June 22, 2017, 05:18
Default
  #4
Member
 
Maria
Join Date: Jul 2013
Posts: 84
Rep Power: 12
marialhm is on a distinguished road
Thanks, Tom and Tobias,

I tried to use groovyBC, but I dont know which random function I should use. I tried random(), but it seems Openfoam does not recognize it.

Also, for turbulentInlet or codedFixedBC, should I install more subroutines?

Best,

Maria
marialhm is offline   Reply With Quote

Old   June 22, 2017, 05:34
Default
  #5
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

the random functionality within groovy is a function of groovy. So it should do the work. Right now I cannot test it - so I am sorry. The codedFixedBC is named codedFixedValue in OpenFOAM and is an boundary condition which already exists. In the header file (finiteVolume/fields/fvPatchFields/derived/codedFixedValue/) you will find an example of how to use it.

Out of the box an example which I did not tried but should give you some hints:

Code:
myPatch
{
    type codedFixedValue;
    value uniform (0 0 0);
    name myOwnBC;

    code
    #{
        const Random randObj(time(NULL));      
        const scalar Uy = randObj.scalar01()*10;
        const vector U = vector(1,Uy,0);

        operator==(U);
    #};
}
Here we build a Random function which is everytime different (after calling) based on time(NULL). Then we make the Uy value and after the U vector. Keep in mind that this will not make a perputation because Uy is on each face similar. So you have to make a scalarField which corresponds to the faces. Sourceflux made some nice example how to do that (http://www.sourceflux.de/blog/the-co...ary-condition/).

However, based on the fact that I am using the Random function too, I guess it is not the best idea using that code above because the initialization of the RandomObj is slow because we build some X vector etc. (http://pubs.opengroup.org/onlinepubs...h/drand48.html).

I think groovy is much faster here but I wanted to show you how to make it with the codedFixedValue boundary condition.

GroovyBC
Code:
type            groovyBC;
variables     "Uy=random(); Ux=10;";
valueExpression "vector(Ux,Uy,0)";
value           uniform (Ux 0 0);
But again, here I guess the Uy distribution is similar to each face. I guess there are possible ways to get rid of that and to make each face randomly. Sorry that I am limited in that kind of question.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   June 22, 2017, 05:39
Default
  #6
Member
 
Maria
Join Date: Jul 2013
Posts: 84
Rep Power: 12
marialhm is on a distinguished road
Quote:
Originally Posted by Tobi View Post
Hi,

the random functionality within groovy is a function of groovy. So it should do the work. Right now I cannot test it - so I am sorry. The codedFixedBC is named codedFixedValue in OpenFOAM and is an boundary condition which already exists. In the header file (finiteVolume/fields/fvPatchFields/derived/codedFixedValue/) you will find an example of how to use it.

Out of the box an example which I did not tried but should give you some hints:

Code:
myPatch
{
    type codedFixedValue;
    value uniform (0 0 0);
    name myOwnBC;

    code
    #{
        const Random randObj(time(NULL));      
        const scalar Uy = randObj.scalar01()*10;
        const vector U = vector(1,Uy,0);

        operator==(U);
    #};
}
Here we build a Random function which is everytime different (after calling) based on time(NULL). Then we make the Uy value and after the U vector. Keep in mind that this will not make a perputation because Uy is on each face similar. So you have to make a scalarField which corresponds to the faces. Sourceflux made some nice example how to do that (http://www.sourceflux.de/blog/the-co...ary-condition/).

However, based on the fact that I am using the Random function too, I guess it is not the best idea using that code above because the initialization of the RandomObj is slow because we build some X vector etc. (http://pubs.opengroup.org/onlinepubs...h/drand48.html).

I think groovy is much faster here but I wanted to show you how to make it with the codedFixedValue boundary condition.

GroovyBC
Code:
type            groovyBC;
variables     "Uy=random(); Ux=10;";
valueExpression "vector(Ux,Uy,0)";
value           uniform (Ux 0 0);
But again, here I guess the Uy distribution is similar to each face. I guess there are possible ways to get rid of that and to make each face randomly. Sorry that I am limited in that kind of question.
I used "Uy=random(); ", but it seems Openfoam doesnt recognize "random()", did I miss something?
Also, the codedFixedValue BC in your reply doesn not work in my case. Should I add some libs?
marialhm is offline   Reply With Quote

Old   June 22, 2017, 05:53
Default
  #7
Senior Member
 
Tom Fahner
Join Date: Mar 2009
Location: Breda, Netherlands
Posts: 634
Rep Power: 32
tomf will become famous soon enoughtomf will become famous soon enough
Send a message via MSN to tomf Send a message via Skype™ to tomf
Hi,

Just to complete the options, the turbulentInlet option would be like this (version 4.x). No additional libraries are needed.

Code:
    
    inlet
    {
        type            turbulentInlet;
        referenceField  uniform (10 0 0);
        fluctuationScale (0 0.01 0);
        value           uniform (10 0 0);
    }

The source code tells us that

Code:
fluctuationScale is RMS fluctuation scale (fraction of mean)
Regards,
Tom
beatlejuice and amolrajan like this.
tomf is offline   Reply With Quote

Old   June 22, 2017, 06:00
Default
  #8
Member
 
Maria
Join Date: Jul 2013
Posts: 84
Rep Power: 12
marialhm is on a distinguished road
Quote:
Originally Posted by tomf View Post
Hi,

Just to complete the options, the turbulentInlet option would be like this (version 4.x). No additional libraries are needed.

Code:
    
    inlet
    {
        type            turbulentInlet;
        referenceField  uniform (10 0 0);
        fluctuationScale (0 0.01 0);
        value           uniform (10 0 0);
    }

The source code tells us that

Code:
fluctuationScale is RMS fluctuation scale (fraction of mean)
Regards,
Tom
Thanks, It seems good. I will try this.
marialhm is offline   Reply With Quote

Old   December 4, 2019, 06:40
Default
  #9
Member
 
George Pichurov
Join Date: Jul 2010
Posts: 52
Rep Power: 15
jorkolino is on a distinguished road
Quote:
Originally Posted by tomf View Post
Hi,

Just to complete the options, the turbulentInlet option would be like this (version 4.x). No additional libraries are needed.

Code:
    
    inlet
    {
        type            turbulentInlet;
        referenceField  uniform (10 0 0);
        fluctuationScale (0 0.01 0);
        value           uniform (10 0 0);
    }

The source code tells us that

Code:
fluctuationScale is RMS fluctuation scale (fraction of mean)
Regards,
Tom
However this usage will use the same seed so the results will replicate if you make another run.
jorkolino is offline   Reply With Quote

Old   April 3, 2023, 04:48
Default
  #10
New Member
 
Stefan Zitz
Join Date: Dec 2022
Location: Denmark
Posts: 2
Rep Power: 0
Zitzeronion is on a distinguished road
Quote:
Originally Posted by Tobi View Post
Hi,

the random functionality within groovy is a function of groovy. So it should do the work. Right now I cannot test it - so I am sorry. The codedFixedBC is named codedFixedValue in OpenFOAM and is an boundary condition which already exists. In the header file (finiteVolume/fields/fvPatchFields/derived/codedFixedValue/) you will find an example of how to use it.

Out of the box an example which I did not tried but should give you some hints:

Code:
myPatch
{
    type codedFixedValue;
    value uniform (0 0 0);
    name myOwnBC;

    code
    #{
        const Random randObj(time(NULL));      
        const scalar Uy = randObj.scalar01()*10;
        const vector U = vector(1,Uy,0);

        operator==(U);
    #};
}
This solution works for me with minor modification, see below

Code:
myPatch
{
    type codedFixedValue;
    value uniform (0 0 0);
    name myOwnBC;

    code
    #{
        const Random randObj(1234);      
        const scalar Uy = randObj.sample01<scalar>()*10;
        const vector U = vector(1,Uy,0);

        operator==(U);
    #};


     codeInclude
     #{
         #include "Random.H"
     #};

 }
One thing is that scalar01 is now sample01 and it needs the <type>. The other thing is the codeInclude, which ensures that Random.H is linked properly (without it I couldn't make it work). The 1234 in randObj is just to set a fixed seed.
Zitzeronion is offline   Reply With Quote

Reply


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
OpenFOAM Training Jan-Jul 2017, Virtual, London, Houston, Berlin CFDFoundation OpenFOAM Announcements from Other Sources 0 January 4, 2017 06:15
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 03:18
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
OpenFOAM Debian packaging current status problems and TODOs oseen OpenFOAM Installation 9 August 26, 2007 13:50
Adding jpeg picture file in OpenFoam post in add a message window kumar2 OpenFOAM 1 March 22, 2006 22:17


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