# Perform calculations using neighbouring cell data

 Register Blogs Members List Search Today's Posts Mark Forums Read

 July 26, 2021, 08:14 Perform calculations using neighbouring cell data #1 New Member   Elliott Sutton Join Date: Dec 2019 Posts: 5 Rep Power: 5 Hi everyone, I'm quite new to programming with OpenFOAM and need some help. I am trying to create a new scalar field that calculates the total difference in viscosity between a given cell and all of its neighbouring cells. What is the syntax I need to get the value of a variable in a given cell and the value in all cells directly adjacent? I'm hoping to get this to work for an AMR method and to work in parallel. Thanks, Elliott

 July 26, 2021, 13:43 #2 Senior Member   Michael Alletto Join Date: Jun 2018 Location: Bremen Posts: 608 Rep Power: 14 How to get the neighbour of one cell? Just a few seconds googling helps a lot

August 3, 2021, 07:01
#3
New Member

Elliott Sutton
Join Date: Dec 2019
Posts: 5
Rep Power: 5
Quote:
 Originally Posted by mAlletto How to get the neighbour of one cell? Just a few seconds googling helps a lot
Thank you for this.

I've performed the calculation as shown below, but receive the error that " 'celli' was not declared in this scope". I'm not sure how to properly declare 'celli' as any cell in the mesh. Any help would be appreciated.

Declaration of the variable in the .C file, initialised based on a viscosity field:
Code:
```    etaGrad_
(
IOobject
(
U.time().timeName(),
U.mesh(),
IOobject::AUTO_WRITE
),
eta_
),```
The actual calculation in .C:
Code:
```
const objectRegistry& db();
const volVectorField& U = db().lookupObject<volVectorField>("U");
const fvMesh& mesh = U.mesh();
const labelList& neighbour = mesh.cellCells[celli]();

forAll(neighbour,celli)
{
}```
Declaration in the .H file:
Code:
```        //- Viscosity gradient field

 Tags neighbouring cells, parallel calculation, scalar field