CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   .boundary() in parallel (

nlinder January 8, 2013 08:50

.boundary() in parallel

in my solver I have a loop through all my boundaries to extract those of type wall. This is realised by

forAll (mesh.boundary(), patchI)
    if (mesh.boundary()[patchI].type() == "wall")
        wallPatchID = patchI;
        Info << "U.boundaryField()[wallPatchID].size(): " << U.boundaryField()[wallPatchID].size() << endl;

The output of the Info statement on a single core is correct:

U.boundaryField()[wallPatchID].size(): 2500
If I run it in parallel with two domains the output is

U.boundaryField()[wallPatchID].size(): 0
How can I make that work in parallel? What changes when I run this in parallel concerning the numbering of the boundary-patches?

Thanks in advance!

nlinder January 11, 2013 09:18

After playing around with the decomposition methods, I looks as if the code only "runs" on the processor0. Anyone knows what to do?


MartinB January 11, 2013 09:26

Hi Nicklas,

use "Pout<< " instead of "Info<< ", then each processor will output its local size.

With "Info<< " only processor0 will print its value, and you must use a gSum command to gather the information from all processors to processor0 first.


nlinder January 11, 2013 09:33

Hi Martin,

thanks for the hint.. Ok, for the output it is clear. But if i e.g. want to set U as U^2 on a boundary I first have to "gSum" the velocity fields, then square them, and redistribute?


MartinB January 11, 2013 09:36

Since every processor calls the gSum, too, the sum is distributed already, I think. So every processor can calculate the U^2 value and set it locally.
You can check it with the Pout command again.


nlinder January 11, 2013 09:37

Allright, I'll try that, thanks for your help!

nlinder January 11, 2013 09:59

Sorry to bother again, but...
gSum returns only the sum.. I actually want a vector(or scalar)Field of a patch which is split to several processors. That seems to be sth different?!


MartinB January 11, 2013 10:25

May be you can find the answer in this code snippet, where slave processors are sending data to the master processor with Pstream:


nlinder January 11, 2013 11:00

Hi Martin,

I think I now understood what was going wrong. I just added a condition, that the operations on the boundary are only performed, if it's size is greater than 0. No all warnings and Errors disappeared and it seems to work!
Thanks for your help!


All times are GMT -4. The time now is 15:29.