CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Counting non-zero values in a volScalarField (https://www.cfd-online.com/Forums/openfoam/118537-counting-non-zero-values-volscalarfield.html)

javier_motta May 29, 2013 10:29

Counting non-zero values in a volScalarField
 
Hi all,

I'm running a custom pisoFoam solver in parallel (16 processors) and I'm having some issues with what I think should be a simple task. I have a mesh of about 460k cells, and have a volScalarField with lots of zeros. I would like to use an if statement inside of a for loop that loops through all the cells in the mesh, and checks to see if the ith value in the volScalarField is zero. If its zero, than it should increment a counter; if its not than do nothing. However, every time I've tried it I only manage to loop through one processor. If I remove the if statement and just have it increase the counter, I get back the total number of cells after I use reduce(counter, sumOp<int>()). Any ideas on how to make the if statement work? The relevant part of code is below

Code:

            forAll(mesh.cells(),celli)
            {

                if (bodyForceOld[celli] == 0)
                {
                  counter_one++;
                }
            }
           
            reduce(counter_one, sumOp<int>());




Thanks,

Javier

javier_motta May 29, 2013 10:30

That title should read counting zero values in volScalarField, my apologies for the confusion


All times are GMT -4. The time now is 04:02.