CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Faces of a cell (

Andrea_85 March 14, 2011 11:04

Faces of a cell
Hi all,

probably a very simple question. How can i access the faces of a particular cell?
I would like to loop over all the cell and for every cell[i] over all the face.


ngj March 14, 2011 11:20

Hi Andrea

You can get the information as:


const labelListList & cellFaces = mesh.cellFaces();
Be aware that if you will access some surface<Type>Field given the faces, you need to check whether or not the face label is internal. If not, then you need to access the value of this boundary face through the boundary field.

Best regards,


Andrea_85 March 14, 2011 11:44

Hi Niels,

thanks for the answer. I need to know the values ​​of a variable (alpha1 using interFoam) belonging to the faces of a particular cell, and then loop for all the cell. Something like that:

alpha[celli] = sum(alpha[facei]*Sf[facei])/sum(Sf[facei])

this does not work of course. I dont know where to put the loop on the correct faces belonging to the cell[i].

many thanks for any help


Bernhard March 14, 2011 12:00

Isn't fvc able to calculate what you want? I suppose fvc:div does something similar you what you want? I cannot give you the correct syntax though, but maybe someone else can help you out.

Andrea_85 March 14, 2011 12:25


basically a need to smooth alpha on every cell and i would like to do that by using alpha on the face times area divided by the total area. So i need to sum alpha on the 4 faces. The divergence is a difference between values on the faces divided by deltax and i dont know if is the same that i need.


duongquaphim March 14, 2011 13:35

Hi Andrea,

Take a look at src/finiteVolume/finiteVolume/fvc/fvcSurfaceIntegrate.C and what they do is very similar to what you want.

I also did the smoothed alpha1, but I did not include the boundary value at all.

kuczmas June 8, 2011 09:56

Dear forumers,

I decided to post my question inside this thread, as it is also somehow connected with looping over faces in a given cell. What I try to achieve is to get the face normal vector at every face in the cell, regardless it is a boundary cell or internal.
I produced the following code...:


    const cell& faces = mesh_.cells()[cellI];

    forAll( faces, i )        // loop over all faces in cellID
        vector faceINormal = mesh_.Sf()[i] / mesh_.magSf()[i] ;
        Info << " i = " << i << ", faceINormal = " << faceINormal << endl ;

...but the values of normal vectors I received are all of positive sign, all the components are of positive sign (on hexahedral mesh). I think in three normal vectors there should be at least one component of negative sign... Do you have any ideas?

Anne Lincke April 29, 2013 11:36

have you solved your problem? I also would like to access the face normal vectors of internal faces....

Kind Regards

kuczmas April 30, 2013 02:23

Yes, I solved the problem. The solution I got was correct. I.e. the components of normal vectors for an arbitrary cell can be in general of the same sign.

The reason for this are the normal vector direction rules. In OpenFoam mesh normal vectors:
- at boundary faces point out of the domain
- at internal faces they point from the cell of lower global ID number to higher.

Hope this helps,

Best regards,

Lieven April 30, 2013 07:16

Just a small note, I think


vector faceINormal = mesh_.Sf()[i] / mesh_.magSf()[i];
should be

vector faceINormal = mesh_.Sf()[faces[i]] / mesh_.magSf()[faces[i]] ;



Anne Lincke April 30, 2013 08:36

Thank you for this hint. I will keep on trying.
Kind Regards

t.oliveira May 29, 2016 19:25

Dear Niels,

Could you please elaborate more on how to access the value of a surface<Type>Field given face label if the face is not internal?

I manage to acess the boundary field but I can't find out how to obtain a certain value from it knowing the face label.

Best regards,


ashish.svm May 12, 2017 18:04

How to identify that a particular facelabel is internal or boundary?

I want to find out the face normal vectors irrespective of whether they are internal or at the boundary

alexeym May 13, 2017 03:59



Guess, you have already tried:, and failed. Could you describe difficulties, which using this method?

ashish.svm May 14, 2017 00:57


Originally Posted by alexeym (Post 648732)


Guess, you have already tried:, and failed. Could you describe difficulties, which using this method?

Thanks. "isInternalFace" helped.

All times are GMT -4. The time now is 00:49.