# cell volume calculation

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

 September 15, 2011, 09:54 cell volume calculation #1 New Member   Mike Join Date: May 2011 Posts: 19 Rep Power: 7 Hello, I'm facing this problem: I want to calculate the volume of a certain cell that is contained in my grid. Is there any straightforward method for doing that? Thank you.

 September 15, 2011, 10:20 #2 Senior Member     Roman Thiele Join Date: Aug 2009 Location: Stockholm, Sweden Posts: 366 Rep Power: 13 you could create a field for all the cell volumes and then access your specific cell the field is created with Code: ``` volScalarField cellVolu ( IOobject ( "cellVolu", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("zero", dimVolume, 0.0) ); cellVolu.internalField() = mesh.V();``` and access to the volume of a specific cell is then given by Code: `cellVolu()[cellIndex];` or right away by Code: `mesh.V()[cellIndex]` have a look at similar things How to compute cellZone volume __________________ ~roman Last edited by romant; September 15, 2011 at 10:20. Reason: forgot a link

 September 15, 2011, 10:31 #3 New Member   Mike Join Date: May 2011 Posts: 19 Rep Power: 7 Hi romant, You mean that if I type in the terminal window "mesh.V()[34332]" I ll get the volume of cell number 34332 ?

 September 15, 2011, 10:43 #4 Senior Member     Roman Thiele Join Date: Aug 2009 Location: Stockholm, Sweden Posts: 366 Rep Power: 13 no this should have been in C++ in the source code. __________________ ~roman

September 16, 2011, 04:06
#5
Senior Member

Tomislav Maric
Join Date: Mar 2009
Posts: 281
Blog Entries: 5
Rep Power: 12
Quote:
 Originally Posted by mikemech Hello, I'm facing this problem: I want to calculate the volume of a certain cell that is contained in my grid. Is there any straightforward method for doing that? Thank you.
There is a Foam::cell::mag() method for this. It is local and approximative:

cell.C:
Code:
```00238 Foam::scalar Foam::cell::mag
00239 (
00240     const pointField& p,
00241     const faceUList& f
00242 ) const
00243 {
00244     // When one wants to access the cell centre and magnitude, the
00245     // functionality on the mesh level should be used in preference to the
00246     // functions provided here. They do not rely to the functionality
00247     // implemented here, provide additional checking and are more efficient.
00248     // The cell::centre and cell::mag functions may be removed in the future.
00249
00250     // WARNING! See cell::centre```
There are more accurate ways of computing cell magnitude (polyhedron volume)
than this one, and you should check out the literature if you absolutely need local computations. Do you need the volume of a single cell (set of cells), or do you need mesh level operations?

If you just want a volume of a single cell, or a zone of cells defined by some
criterion, you can go about it like this:

Code:
```const cellList& cells = mesh.cells();
const faceList& faces = mesh.faces();
const pointField& points = mesh.points();

// Let's say that you want a volume of the 100th cell..

scalar cellV = cells[100].mag(points,faces);```
Of course, finding out the proper label for the cell(s) will depend on what you
actually want to do.

T.

 September 16, 2011, 06:58 #6 New Member   Mike Join Date: May 2011 Posts: 19 Rep Power: 7 Thank you tomislav_maric, Well I need to find the volume of one cell, and I know its label. So I ll try the second idea you mentioned.

September 17, 2011, 07:38
#7
Senior Member

Tomislav Maric
Join Date: Mar 2009
Posts: 281
Blog Entries: 5
Rep Power: 12
Quote:
 Originally Posted by mikemech Thank you tomislav_maric, Well I need to find the volume of one cell, and I know its label. So I ll try the second idea you mentioned.
Cool, I'm glad to be of help!

T.

October 11, 2011, 09:43
#8
New Member

alex
Join Date: Jun 2009
Posts: 17
Rep Power: 9
Hi!
If i put

Code:
`cellVolu.write();`
bellow the "cellVolu.internalField() = mesh.V();" is written the cellVolu field.
How can I sum all the cell volumes? I want calculate the global volume of my geometry.

Thanks.

Quote:
 Originally Posted by romant you could create a field for all the cell volumes and then access your specific cell the field is created with Code: ``` volScalarField cellVolu ( IOobject ( "cellVolu", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("zero", dimVolume, 0.0) ); cellVolu.internalField() = mesh.V();``` and access to the volume of a specific cell is then given by Code: `cellVolu()[cellIndex];` or right away by Code: `mesh.V()[cellIndex]` have a look at similar things How to compute cellZone volume

 October 11, 2011, 10:03 global volume #9 Senior Member     Roman Thiele Join Date: Aug 2009 Location: Stockholm, Sweden Posts: 366 Rep Power: 13 Hej, it is easiest calculated Code: `scalar volumeSum = sum(cellVolu).value();` or if you don't need it in a program, just run Code: `checkMesh` which will give you the total volume as one of the outputs. __________________ ~roman

 October 11, 2011, 10:48 #10 New Member   alex Join Date: Jun 2009 Posts: 17 Rep Power: 9 Thanks romant. The total cell's volume given by your method have deviation from "geometric" calculations of 0.002% in my mesh.

May 23, 2012, 17:15
#11
New Member

Join Date: Feb 2012
Posts: 4
Rep Power: 6
Quote:
 Originally Posted by oort Hi! If i put Code: `cellVolu.write();` bellow the "cellVolu.internalField() = mesh.V();" is written the cellVolu field. How can I sum all the cell volumes? I want calculate the global volume of my geometry. Thanks.
in which source code file do we have to make these changes

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Ganesh FLUENT 13 January 22, 2014 05:11 shrina OpenFOAM Running, Solving & CFD 10 October 3, 2013 14:38 zhengjg Main CFD Forum 10 November 12, 2012 00:13 paean OpenFOAM Running, Solving & CFD 0 November 14, 2008 22:14 Mark FLUENT 0 August 30, 2001 07:45

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