CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Access cell volume from boundry condition (

JimKnopf March 7, 2011 10:48

Access cell volume from boundry condition
Hej there!

I'm struggling with a probably little problem. I want to access the volume of the first cell normal to a boundry from within the boundry condition.

For example like rho*CellVolume for mass of the first cell normal to a boundary.

Probably it's just one line of code, but I don't get, since I'm quite new to OpenFoam programming.

Thanks and greetings

cliffoi March 7, 2011 12:33

The functionality isn't directly available (at least not in the older versions of OF). Maybe theres a better way in OF-1.6 or newer, but this should do the trick.
From with xxxFvPatchField<type>::someFunc()

const fvPatchScalarField& rhop = patch().lookupPatchField<volScalarField, scalar>("rho");
const scalarField& V = patch().boundaryMesh().mesh().V();
const unallocLabelList& faceCells = this->patch().faceCells();

scalarField rhoVp(this->size());

forAll(faceCells, faceI)
rhoVp[faceI] = rhop[faceI]*V[faceCells[faceI]];

JimKnopf March 10, 2011 05:29

Thanks! It did the job.

All times are GMT -4. The time now is 08:56.