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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 22, 2022, 05:50
Default Boundary conditions for a surfaceScalarField
  #1
New Member
 
Sreehari Perumanath
Join Date: Jun 2022
Posts: 28
Rep Power: 4
sreehahaha is on a distinguished road
Dear Foamers,

I'm new to use OF and I'm developing my own solver for my problem. I have a simple cubic geometry. In it, I have to define a 'surfaceScalarField payal' and I want to give pre-calculated values to it at every time step.

It is easy to give values to the internal faces, so I'll skip that here. I give values to the boundary patches with:
Code:
// to loop over all boundary faces
forAll(payal.boundaryFieldRef(), patchID)
{
	forAll(payal.boundaryFieldRef()[patchID],facei) 
   {
   	payal.boundaryFieldRef()[patchID][facei]=<aPre-calculatedValue>;
   }
}
But I use cyclicBC, so I have to do something like below for two neighbourPatches with patchIDs 0,1:
Code:
// set values on patchID=1 same as patchID=0, because cyclicBC between patches 0,1
forAll(payal.boundaryFieldRef()[1],facei)
{
	payal.boundaryFieldRef()[1][facei]=payal.boundaryFieldRef()[0][facei];
}
and likewise for other pairs of neighbourPatches. This works fine in a serial run. But, I imagine this would be problematic in a parallel run, as both patches may be dealt with by different processes. Can somebody please suggest an elegant way which works for both serial and parallel runs? It would be very helpful.

Many thanks and have a great day/weekend!
sreehahaha is offline   Reply With Quote

Old   September 26, 2022, 08:04
Default
  #2
New Member
 
Chen Xiaoxiao
Join Date: Jun 2018
Location: China
Posts: 6
Rep Power: 8
SmileMax is on a distinguished road
you can use decomposePar -no-sets(.com) or decomposePar -noSets(.org) to skip decomposing specified cellSets, faceSets, pointSets.
SmileMax is offline   Reply With Quote

Old   September 28, 2022, 11:30
Default
  #3
New Member
 
Sreehari Perumanath
Join Date: Jun 2022
Posts: 28
Rep Power: 4
sreehahaha is on a distinguished road
Thank you for the reply, SmileMax, and sorry for my late reply.

The <aPre-calculatedValue> that I have written in my original question contains a random number. So, I think, not decomposing the surfaceScalarField Payal will give its copies to all processors. And, since there is a random number involved, each processor will end up having different versions of Payal. Please correct me if I'm wrong, I'm new to OF programming.

If I'm correct above, can you please think of another way to solve the issue.

Many thanks and have a nice day,
S
sreehahaha is offline   Reply With Quote

Old   September 29, 2022, 00:33
Default
  #4
New Member
 
Chen Xiaoxiao
Join Date: Jun 2018
Location: China
Posts: 6
Rep Power: 8
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

Reply

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


All times are GMT -4. The time now is 19:47.