|
[Sponsors] |
July 31, 2016, 10:09 |
Random number generation
|
#1 |
New Member
fluidflowsteel
Join Date: Jun 2016
Posts: 21
Rep Power: 10 |
Hi all,
I want to generate random numbers in OF 2.2.0 between -1 and +1 for the whole mesh initially which will remain same for all time steps. Can you advice how to do this ? with regards, |
|
August 12, 2016, 11:29 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Simple task,
there is a class called Random. An example is in my Gray-Scott-Solver ... https://bitbucket.org/shor-ty/graysc...e-view-default
__________________
Keep foaming, Tobias Holzmann |
|
December 4, 2019, 06:43 |
|
#3 | |
Member
George Pichurov
Join Date: Jul 2010
Posts: 52
Rep Power: 16 |
Quote:
|
||
December 11, 2019, 00:31 |
|
#5 | |
New Member
Ramkumar
Join Date: Nov 2014
Location: pondicherry, India
Posts: 16
Rep Power: 12 |
Hi, is it possible to generate random list of "N" numbers between given range (a,b)? using that class? Like i need some 10 numbers between say 0 to 100.
And it gives following error when i run that script. Quote:
|
||
April 14, 2020, 22:17 |
Example to generate a random number between 0 and 1
|
#6 |
New Member
Vitor Geraldes
Join Date: Dec 2009
Location: Lisbon, Portugal
Posts: 26
Rep Power: 17 |
#include <iostream>
#include "fvCFD.H" #include "Random.H" #include "Time.H" int main () { Random randObj(clock::getTime()); Info << randObj.scalar01()<< endl; } |
|
December 1, 2020, 11:19 |
|
#7 | |
New Member
Ramkumar
Join Date: Nov 2014
Location: pondicherry, India
Posts: 16
Rep Power: 12 |
Quote:
i am getting following error when i use your code. Code:
testCode.C: In function ‘int main(int, char**)’: testCode.C:50:29: error: ‘Foam::scalar Foam::Random::scalar01()’ is private within this context Info << ranObj.scalar01(); |
||
December 5, 2020, 04:54 |
|
#8 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Code:
Random rng; rng.sample01<scalar>(); Code:
Random::uniformGeneratorOp<scalar> randVal(0,10); scalarField fld(1000); std::generate (fld.begin(), fld.end(), randVal); // the same, as a loop for (scalar& val : fld) { val = randVal(); } |
||
|
|
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 |
[snappyHexMesh] Error snappyhexmesh - Multiple outside loops | avinashjagdale | OpenFOAM Meshing & Mesh Conversion | 53 | March 8, 2019 10:42 |
random number generation | hwet | Fluent UDF and Scheme Programming | 9 | February 29, 2016 20:35 |
MPI run run fails of quadcore openfoam2.4 | Priya Somasundaran | OpenFOAM Running, Solving & CFD | 3 | January 25, 2016 09:50 |
[blockMesh] --> foam fatal error: | lillo763 | OpenFOAM Meshing & Mesh Conversion | 0 | March 5, 2014 11:27 |