CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Accessing neighbor cells fields (

antoniofct December 11, 2012 16:11

Accessing neighbor cells fields
Hello all,

I am trying to do an average of cells neighbors. For instance, if I want to get an average of Temperature in the internal field I can easily type



What could be the function to do it just in cell neighbors? Could it be inside geometricField.C?



duongquaphim December 11, 2012 16:37

I think you need to do a bit more for that:

const labelList& neighbour = mesh.cellCells()[celli]

scalar sum = scalar(0);

sum += T[neighbour[i]];

sum /= neighbour.size();

And loop over all the cells with that will give you an average of cell neighbours.

You can find more of functions relating to the mesh information in primitiveMesh class.


antoniofct December 11, 2012 16:41

thanks a lot, I will give it a try!

Antonio May 13, 2015 17:53

This a nice implementation, but, in parallel, it does not recognize neighbour cells if they are in subdomains different from the one of the central cell. Is there a simple implementation to address this problem?

tom_flint2012 January 20, 2018 15:45

find neighbours in parallel
I think if you use field.correctBoundaryConditions(); it will work OK. Where field is the new neighbour field you assign.

This works fine for me

All the best

All times are GMT -4. The time now is 14:57.