CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Some cells have disappeared (

cfdmarkus December 9, 2010 09:42

Some cells have disappeared
Hi all,

I have added two lines to pisoFoam to count the number of cells:

const cellList& cells = mesh.cells();
Info << " no cells: " << cells.size() << endl;

When I run it on a single processor it counts: 1278060 cells - which is correct.
But when I decompose the case and run it on 16 processsors, the number reduces to: 79043 cells. This is approx. 1/16 of the total number of cells.

Consequently, when I loop over all cells using "forAll(cells,cellI)" some cells are always missing :(

Does anyone know why mesh.cells() does not include all cells when run in parallel and how can the missing cells be accessed?


MartinB December 9, 2010 10:14

Hi Markus,

you must gather the information to the master:

const cellList& cells = mesh.cells();
label nCells = 0;
nCells = cells.size();
reduce(nCells, sumOp<label>());
Info << " no cells: " << nCells << endl;


cfdmarkus December 10, 2010 12:37

Thank you Martin!

impecca August 19, 2011 08:48

field manipulation with parallel computations
Thanks for the thread on this subject first.

I've managed to get number of cells in parallel computing as Martin suggested but I still have a problem with modifying 'field' itself. here is the code I use

const cellList& cells = mesh.cells();
label nCells = 0;
nCells= cells.size();
reduce(nCells, sumOp<label>());
scalar i = 0;

forAll(cells, celli){
Info<<"i= "<<i <<nl;
Info<<"nCells= " <<nCells<<nl;

with a single processor, it shows:
i= 336000
nCells= 336000

with 4 processors, it shows:
i= 84332
nCells= 336000

as you can see, nCells isn't affected by multi processing but the field loop number (i) is depending on the number of processors. So question is that is there any way that I can manipulate field (say velocity) with the parallel compuations ?
What I want to do is imposing artificial fluctuations on one plane in the middle of domain.

I also wrote same question in this forum but no response so far,

Thanks in advance


MartinB August 19, 2011 08:58

Hi Yusik,

you can manipulate the field within the loop:
forAll(cells, celli)
// your manipulation here, each processor will manipulate
// its part of the field.

Hmmhhh, not sure if I understand your problem correctly, maybe you can provide some code snippets of your intended algorithm...


impecca August 21, 2011 09:23

Yes, it works. you are right Martin. I was a different problem. I replied to other thread (link below). Thanks for your help. :D

All times are GMT -4. The time now is 16:55.