CFD Online Logo CFD Online URL
Home > Forums

How to get a 27 cell stencil in OpenFOAM.

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

Rate this Entry

How to get a 27 cell stencil in OpenFOAM.

Posted January 31, 2012 at 10:30 by tomislav_maric

The primitiveMesh::cellCells returns with a cross cell stencil of 6 cells (the cell in question is excluded). This computation comes from the basis of OpenFOAM: face addressing. Although it is very efficient, this kind of computation introduces errros e.g. in the gradient reconstruction of sharp fields.

Try to generate a field that has a jump in a single layer of cells, whose iso surface is a plane, and try to compute the normal field of this plane from the fraction gradient using any interpolation and gradient scheme available in OF, then you'll see what I mean.

However, in OpenFOAM there is a possibility to get the full 27 cell stencil although the mesh is unstructured. The class for this is CPCCelltoCellStencil, and it's extremely easy to use (once, you find it ):

CPCCellToCellStencil wideStencil(mesh);

// Get the stencil of a single cell. 

const labelList& cell27stencil = wideStencil[cellID];
There are other stencils available: look in /src/finiteVolume/fvMesh/extendedStencil. Some create lists of faces, others allow to collect cell centres from the stencil directly, etc. They are used e.g. for higher order grad schemes.
Posted in Uncategorized
Views 1760 Comments 2 Edit Tags Email Blog Entry
« Prev     Main     Next »
Total Comments 2


  1. Old Comment
    lakeat's Avatar
    Posted February 8, 2013 at 16:42 by lakeat lakeat is offline
  2. Old Comment
    How is it possible to use this class in parallel computing?
    I mean if I want to apply it to a cell next to the cpu interface some of the stencil labels will refer to cells of other cpu that are not visible then.
    Please correct me if I am wrong.
    Posted July 11, 2013 at 14:20 by alexmogavero alexmogavero is offline

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