CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

cell volume calculation

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 15, 2011, 10:54
Default cell volume calculation
  #1
New Member
 
Mike
Join Date: May 2011
Posts: 19
Rep Power: 15
mikemech is on a distinguished road
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.
mikemech is offline   Reply With Quote

Old   September 15, 2011, 11:20
Default
  #2
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 21
romant is on a distinguished road
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
http://www.cfd-online.com/Forums/ope...ne-volume.html
__________________
~roman

Last edited by romant; September 15, 2011 at 11:20. Reason: forgot a link
romant is offline   Reply With Quote

Old   September 15, 2011, 11:31
Default
  #3
New Member
 
Mike
Join Date: May 2011
Posts: 19
Rep Power: 15
mikemech is on a distinguished road
Hi romant,

You mean that if I type in the terminal window "mesh.V()[34332]" I ll get the volume of cell number 34332 ?
mikemech is offline   Reply With Quote

Old   September 15, 2011, 11:43
Default
  #4
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 21
romant is on a distinguished road
no this should have been in C++ in the source code.
__________________
~roman
romant is offline   Reply With Quote

Old   September 16, 2011, 05:06
Default
  #5
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by mikemech View Post
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.
tomislav_maric is offline   Reply With Quote

Old   September 16, 2011, 07:58
Default
  #6
New Member
 
Mike
Join Date: May 2011
Posts: 19
Rep Power: 15
mikemech is on a distinguished road
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.
mikemech is offline   Reply With Quote

Old   September 17, 2011, 08:38
Default
  #7
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by mikemech View Post
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.
tomislav_maric is offline   Reply With Quote

Old   October 11, 2011, 10:43
Default
  #8
New Member
 
alex
Join Date: Jun 2009
Posts: 17
Rep Power: 17
oort is on a distinguished road
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 View Post
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
http://www.cfd-online.com/Forums/ope...ne-volume.html
oort is offline   Reply With Quote

Old   October 11, 2011, 11:03
Default global volume
  #9
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 21
romant is on a distinguished road
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
romant is offline   Reply With Quote

Old   October 11, 2011, 11:48
Default
  #10
New Member
 
alex
Join Date: Jun 2009
Posts: 17
Rep Power: 17
oort is on a distinguished road
Thanks romant.
The total cell's volume given by your method have deviation from "geometric" calculations of 0.002% in my mesh.
oort is offline   Reply With Quote

Old   May 23, 2012, 18:15
Default
  #11
New Member
 
Join Date: Feb 2012
Posts: 4
Rep Power: 14
pvpnr is on a distinguished road
Quote:
Originally Posted by oort View Post
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
pvpnr is offline   Reply With Quote

Reply


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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 07:09
FvMatrix coefficients shrina OpenFOAM Running, Solving & CFD 10 October 3, 2013 15:38
gradient calculation of cell centered finite volume method zhengjg Main CFD Forum 10 November 12, 2012 00:13
On the damBreak4phaseFine cases paean OpenFOAM Running, Solving & CFD 0 November 14, 2008 22:14
Calculation of cell volume and face handedness Mark FLUENT 0 August 30, 2001 08:45


All times are GMT -4. The time now is 04:26.