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

Boundary conditions for a surfaceScalarField

Register Blogs Community New Posts Updated Threads Search

 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old   September 28, 2022, 23:33
Default
  #4
New Member
 
Chen Xiaoxiao
Join Date: Jun 2018
Location: China
Posts: 6
Rep Power: 7
SmileMax is on a distinguished road
If you use OpenFOAM's built-in random number class, you can use the functions prefixed with global to ensure that the random numbers generated each time are kept in sync on all MPI nodes,such as Random::globalSample01(), Random::globalGaussNormal().

see src/OpenFOAM/primitives/random/Random/Random.C for these source codes:
Code:
Foam::scalar Foam::Random::globalSample01()
{
    scalar value(-GREAT);
 
    if (Pstream::master())
    {
        value = scalar01(); // generate random number on master MPI node.
    }
    Pstream::scatter(value); // broadcast this value to all MPI nodes.
    return value;
}
But in fact, the random numbers obtained by the built-in functions of OpenFOAM are always the same on different MPI nodes and even in different running stages if you give a fixed random seed. You can use Pout to output the value of each node to observe this phenomenon:

Code:
Random rndGen(<a fixed random seed>);

scalar a = rndGen.sample01<scalar>();
Pout << "random number: "<< a << endl;

scalar b = rndGen.globalSample01<scalar>();
Pout << "random number: "<< b << endl;

// a is always equal to b here, and each MPI node have the same value of a and b.
If you are using an external random number class, such as std:rand, You can refer to the implementation method of Random::globalSample01 above to manually complete random number synchronization between MPI nodes.
SmileMax is offline   Reply With Quote

 

Tags
correctboundaryconditions, cyclic boundary, surfacescalarfield


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
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 07:38
Radiation in semi-transparent media with surface-to-surface model? mpeppels CFX 11 August 22, 2019 07:30
Multiphase flow - incorrect velocity on inlet Mike_Tom CFX 6 September 29, 2016 01:27
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 08:44
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28


All times are GMT -4. The time now is 05:48.