CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   How to get the volume of a cell (

dbxmcf March 19, 2007 00:35

Hi, all: I searched the for
Hi, all:

I searched the forum and doxygen, found a function mag and the following comments:
// When one wants to access the cell centre and magnitude, the
// functionality on the mesh level should be used in preference to the
// functions provided here. They do not rely to the functionality
// implemented here, provide additional checking and are more efficient.
// The cell::centre and cell::mag functions may be removed in the future.

// WARNING! See cell::centre

// first calculate the aproximate cell centre as the average of all
// face centres

I am just confused how to use it and what is the best way to find the cell volume? What I am trying to do is something like:

Thanks a lot!

eugene March 19, 2007 05:57


nimasam August 1, 2010 03:09

hi friend
i want to access volume of cells in volScalarField but in openFoam there is two ways to access to the mesh volume and none of them are volScalarField:
const DimensionedField<scalar, volMesh>& V() const;
const scalarField& cellVolumes() const;

fisch June 9, 2011 07:15

nimasam, did you found a solution?
I have the same problem now...

thanks, rupert

l_r_mcglashan June 9, 2011 09:40

mesh.V() is a scalarField, not a volScalarField. Why would you have volumes at patches?

fisch June 9, 2011 10:11

thanks for the quick reply, l_r_mcglashan

i used it without thinking because it's written like this in the programmersGuide P33.

kaveh19 August 8, 2015 08:02

measuring volume
hi guys,
how can I measure the volume of geometry in openFoan?

kmooney August 9, 2015 20:20


Originally Posted by kaveh19 (Post 558757)
hi guys,
how can I measure the volume of geometry in openFoan?

Something like this should work if executed in a top level of a solver:


scalar totalVolume(0.0);
totalVolume += mesh.V()[cellI];

PicklER February 12, 2016 12:22

Is it possible to get the volumes only of the cells at patchID?

If I have:


label patchID = mesh.boundaryMesh().findPatchID(patchName);
Then something like mesh.V()[patchID] ?

Otherwise to get the

for only the patch corresponding to patchID?

Then I can use that which Kyle recommended. I would like to multiply the value on a patch face with the volume of the cell corresponding to the patch face. The will give me something like a indication of adding mass to cell.

elmo555 April 19, 2016 05:02

I also have a question regarding the use of mesh.V():

  • Why is a volScalarField not available? Volume is a scalar quantity, and I'd like to have it for each cell in my mesh. How is this related to patches? (@l_r_mcglashan). Patches shouldn't have volumes
  • How comes I can use mesh.V() to multiply with a volScalarField, but not divide one by it? Example below...

Info<< "Total liquid volume liquidV = " << sum(mesh.V()*alpha1).value() << endl;
// doesn't work
volScalarField interfDens(aInterfaceCells/mesh.V());

Both alpha1 and aInterfaceCells are volScalarField. What am I doing wrong?

JackW August 14, 2017 00:54

I assume that people want to do it for postprocessing. This is how I did it (by copying LESDelta and cubeRootVolDelta implementation):


# include "calculatedFvPatchFields.H"

volScalarField V (
        IOobject (
      dimensionedScalar("small", dimLength*dimLength*dimLength, SMALL),
V.internalField() = mesh.V();

The calculatedFvPatchScalarField::typeName just defines calculated patch types, which evaluates to SMALL (what it was initialised as)

linyanx September 25, 2017 11:39

Hi Lennart,
I meet the exactly the same question as you mentioned. I was trying to calculate the weight for every cell and store the value into the volScalarField.

K = 0.5*magSqr(U)*rho*mesh.V();
Sadly the system would complain it while compilation. Do you have any idea about this?
All the best,

All times are GMT -4. The time now is 22:38.