|
[Sponsors] |
[swak4Foam] how to initialize a random velocity field with funkySetFields |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 30, 2012, 07:57 |
how to initialize a random velocity field with funkySetFields
|
#1 |
Senior Member
Andrea
Join Date: Feb 2012
Location: Leeds, UK
Posts: 179
Rep Power: 16 |
Hi,
I would like to inizialize a random velocity field with funkySetFields. Is it possible? I've tried something like { field U; expression "vector (0.005*rand(), 0.005*rand(), 0.005*rand())"; } Do you think this should work? Thanks in advance Andrea |
|
January 1, 2013, 06:37 |
|
#2 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
Well, you can just test whether it will work or not, right? Try to search the forum for "perturbu", this make give you some lead.
|
|
January 1, 2013, 09:51 |
|
#3 |
Senior Member
Andrea
Join Date: Feb 2012
Location: Leeds, UK
Posts: 179
Rep Power: 16 |
Hi Bernard,
I was pretty sure that the formulation in my previous post is wrong because rand() generates a scalar random field, so it has a defined and unique value in each cell of the domain. In fact I tried to test it, obtaining a velocity field which looks like (0.000208152 0.000208152 0.000208152) (0.00227246 0.00227246 0.00227246) (0.00417409 0.00417409 0.00417409) ... Furthermore rand() generates random numbers between 0 and 1, while I would like to have velocity components randomly distributed between -0.005 and 0.005. I will give a look to perturbU, even if I would like to know if it's possible to obtain the goal using funkySetFields. Thank you for your reply (and, of course, happy 2013), Andrea |
|
January 5, 2013, 19:01 |
|
#4 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
__________________
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 |
||
January 9, 2013, 12:10 |
|
#5 |
Senior Member
Andrea
Join Date: Feb 2012
Location: Leeds, UK
Posts: 179
Rep Power: 16 |
Obtaining the desired range starting from [0,1) it's not a problem; my problem is how to have three different random scalar fields (one for each velocity component).
I've also tried to use Random::vector01() but it's not recognized by swak4foam. |
|
January 9, 2013, 17:49 |
|
#6 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
To create reproducible results random always uses the same seed. But you can change that by simply supplying an integer "random(42)" for instance. If you do that for every component they are "independent" BTW: if the seed value is bigger than 0 then it will stay the same with every timestep. If it is smaller than 0 it will change at every time. But I think that is mentioned in the README The same is true for randomNormal
__________________
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 |
||
January 10, 2013, 06:10 |
|
#7 |
Senior Member
Andrea
Join Date: Feb 2012
Location: Leeds, UK
Posts: 179
Rep Power: 16 |
Bernhard,
Thank you very much for your tips, now I have a wonderful (pseudo-)random velocity field! If anyone else is interested, the expression i used is: "vector (0.01*rand(12)-0.005, 0.01*rand(4)-0.005, 0.01*rand(47)-0.005)" Regards, Andrea |
|
January 10, 2013, 07:23 |
|
#8 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
__________________
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 |
||
January 10, 2013, 10:10 |
|
#9 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Great. If everyone who got his question answered did this then there wouldn't be a documentation problem
__________________
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 |
||
February 19, 2013, 21:25 |
|
#10 | |
Member
Albert Tong
Join Date: Dec 2010
Location: Perth, WA, Australia
Posts: 76
Blog Entries: 1
Rep Power: 16 |
Quote:
An interesting thread. Just wonder if I would like to see a random velocity distribution different(to the most) from each other at every cell in a zone and changes with time, then how to realize? It seems, as Bernhard pointed out, just change the no. in rand() to a value smaller than 0 to make it changeable with time. But how to make the random velocity also change with space? Cheers.
__________________
Kind regards, Albert Last edited by tfuwa; February 19, 2013 at 23:33. Reason: "If seed value is smaller than 0 it will change at every time" |
||
February 20, 2013, 00:15 |
|
#11 | ||
Member
Albert Tong
Join Date: Dec 2010
Location: Perth, WA, Australia
Posts: 76
Blog Entries: 1
Rep Power: 16 |
Hi All,
To answer my own question. If the position is given, then velocity will change with space. For example, Quote:
However, why the swak4Foam on my computer does not recognize rand(Nn) and gives the following error message? (which disappears after deleting the number in rand() ) Quote:
__________________
Kind regards, Albert |
|||
February 20, 2013, 12:46 |
|
#12 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Which version of swak do you use?
__________________
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 |
||
February 21, 2013, 04:41 |
|
#13 | |
Member
Albert Tong
Join Date: Dec 2010
Location: Perth, WA, Australia
Posts: 76
Blog Entries: 1
Rep Power: 16 |
Quote:
Hi Bernhard, 1, Sorry for the ambiguity. Your anticipation is right. I downloaded the latest version of swak and recompiled, then the error was gone. Thanks for your time. Great help. 2, But it seems the seed value cannot be smaller than 0 in rand(), Code:
--> FOAM FATAL ERROR: Parser Error for driver FieldValueExpressionDriver at "1.6" :"invalid character when only an integer parameter is expected" "rand(-21)" ^ -------| Context of the error: - From dictionary: /home/tfuwa/OpenFOAM/tfuwa-1.7.x/run/applications/swak4Foam_1.x_release_0.2.1/Examples/IcoFoamWithSources/cavityWithSource-2/constant/momentumSourceDict Evaluating expression "rand(-21)" From function parsingValue in file lnInclude/CommonValueExpressionDriverI.H at line 876. FOAM exiting Code:
--> FOAM FATAL ERROR: request for volScalarField randField from objectRegistry region0 failed available objects of type volScalarField are 1 ( p )
__________________
Kind regards, Albert |
||
February 21, 2013, 12:23 |
|
#14 | |||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Quote:
Quote:
__________________
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 |
||||
March 6, 2013, 04:42 |
Bernhard
|
#15 |
Member
Albert Tong
Join Date: Dec 2010
Location: Perth, WA, Australia
Posts: 76
Blog Entries: 1
Rep Power: 16 |
Hi Bernhard,
Come to bother you again I managed to add a random source term to icoFoam through swak4Foam, and generate the source term in a specific area. The source term is defined as S = [0, 0, 2*A*(rand()-0.5) ], where A is a fixed amplitude of the source term.Basically, S only depends on rand() function and only has values in z-direction. Several lines in the source term area along z-direction are investigated to see whether S is random. I plot the changes of S with time for those lines, and disappointedly find some of them seemingly not random at all as shown in the attached figure. For the probe lines 5 and 7, S is random, but for lines 6 and 8, S is not. Those lines are extracted with sample utility of OF. I have tried to change the value in rand(n) or with no seed, but got similar results. What do you think the reason for the problem? Is there a way to output the rand() values at each time-step for every cell in the source generated area? Thanks.
__________________
Kind regards, Albert |
|
March 6, 2013, 06:41 |
|
#16 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Just to clarify: this is from the same calculation from the same time only the plane where you sample is different? To get a "full" field for postprocessing (I guess that is what you want in the last paragraph) you could add a functionObject (typos and missing parameters may be there. I only wrote that stuff. This doesn't mean that I know how to use it properly): Code:
myRandomField { type expressionField; autoWrite true; fieldName myRandomField; expression "rand()"; }
__________________
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 |
||
March 6, 2013, 09:58 |
|
#17 | |||
Member
Albert Tong
Join Date: Dec 2010
Location: Perth, WA, Australia
Posts: 76
Blog Entries: 1
Rep Power: 16 |
Hi Bernhard,
Thanks for your quick reply. Quote:
Quote:
Quote:
Thanks agian. Really helpful. Kind regards, Albert |
||||
March 7, 2013, 15:09 |
|
#18 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
That is always assuming that the system random is to blame
__________________
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 |
||
August 2, 2016, 07:02 |
|
#19 |
New Member
fluidflow
Join Date: Dec 2015
Posts: 5
Rep Power: 11 |
Hi Andrea1984,
I am using openfoam 2.2.0 to generate random number. in the scalar transport foam, i just added rand() as an extra term to the right hand side of the equation to generate random number between 0 and 1 as you said. while compiling i am getting error. can u help about how can i generate random number between -1 and +1 and put it as a source term with regards |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Having problems getting the mean vorticity field from mean velocity field | Martin1 | Fluent UDF and Scheme Programming | 1 | June 18, 2015 09:20 |
''unknown radialModelType type Gidaspow'' PROBLEM WITH THE BED TUTORIAL | AndoniBM | OpenFOAM Running, Solving & CFD | 2 | March 25, 2015 19:44 |
change velocity field | LM4112 | OpenFOAM Running, Solving & CFD | 12 | February 5, 2014 12:56 |
Initial velocity field in StarCCM+ | Subhadeep | Siemens | 3 | December 21, 2008 04:40 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |