CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Meshing & Mesh Conversion (
-   -   How to get mesh total volume quickly? (

ic3wall August 1, 2012 15:24

How to get mesh total volume quickly?

What's the fastest way to get the total volume of a mesh precisely (sum of volume of each cell)?

I know checkMesh is giving Mesh total volume but i'm not sure if it's really mesh total volume or volume of bounding box ..

Thank you!

tcarrigan August 1, 2012 17:24

What software are you using to generate the mesh? It may provide the appropriate utilities for doing a volume calculation.

matt.mech.eng August 1, 2012 19:20

checkMesh gives the volume of the mesh not the bounding box
you can easily calculate the volume of the bounding box yourself.. compare with checkMesh volume given

potentialFoam January 21, 2016 13:34

Dear Foamers,

I would like to get the total volume of a solution domain.
I tried

scalar totalVolume(0.0);
forAll(mesh_.cells(),i) //cellI)
totalVolume += mesh_.V()[i]; //cellI];

without success. (Wrong result, but I don't know why.)

Then I found this last answer and hence I tried to get it with 'checkMesh'.
Unfortunately, I can't find the code snippet in the folder
using e.g.:
grep -nr "volume"

Can you please show me, where they hid it? :)


alexeym January 21, 2016 16:14


Why have you decided to iterate over strange cells() list? This does the job:


scalar vol = 0.0;
forAll(mesh.V(), idx)
    vol += mesh.V()[idx];
reduce(vol, sumOp<scalar>());
Info<< vol << endl;

The same thing:


scalar vol = gSum(mesh.V());
Info<< vol << endl;

(in fact gSum is just short way to say

scalar vol = sum(mesh.V());
reduce(vol, sumOp<scalar>());


Also it is up to you to check if you run 2D axisymmetric case and multiply result to get real mesh volume.

Answering you last question: it is in primitiveMeshCheck.C (

potentialFoam January 22, 2016 04:57

Thanks Alexey,

it works :)
(I use

scalar vol = gSum( mesh_.V() );

All times are GMT -4. The time now is 23:19.