CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   How to iterate over all cells in decomposed mesh (

tehache October 23, 2007 06:08

Hi everybody, Could someone
Hi everybody,

Could someone give me a hint on how to iterate over all cells of a decomposed mesh?

After naively using it for quite some time, I just found out that mesh.cells() gives me only the cells of one partition

Thank you!


gschaider October 23, 2007 07:14

Hi Thomas! That's the whole
Hi Thomas!

That's the whole point of parallelizing: every processor is responsible for "his" cells. If one processor could loop over all cells it would no longer be parallel.

What do you want to do? If it is something like counting cells with a specific property (that's one of the reasons why you might want to do this), then you should do it as usual and use something like


to calculate the sum over all processors and distribute it to all processors


tehache October 23, 2007 07:44

Hi Bernhard, Actually, I wa
Hi Bernhard,

Actually, I was looking for a cell at a specific location to set a reference value there (fvMatrix::setReference).
I think I ran into a trap with that idea ... now apperently every processor is setting reference at a different cell..
Isn't there some way, even doing communication, to globally find a cell?
Just tried findNearestCell(), but seems to work also ony within one processors cells...

gschaider October 23, 2007 09:26

Hi Thomas! Something like t
Hi Thomas!

Something like this?

label cellI=mesh.findCell(location);
if(cellI>=0) {

That'd set the reference only on the processor that has the cell in question, I guess.


tehache October 23, 2007 10:06

Thx a lot! Thats it. And s
Thx a lot!

Thats it.
And so easy.... shame on me

All times are GMT -4. The time now is 22:30.