CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   cell volume calculation (http://www.cfd-online.com/Forums/openfoam/92483-cell-volume-calculation.html)

mikemech September 15, 2011 09:54

cell volume calculation
 
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.

romant September 15, 2011 10:20

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

mikemech September 15, 2011 10:31

Hi romant,

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

romant September 15, 2011 10:43

no this should have been in C++ in the source code.

tomislav_maric September 16, 2011 04:06

Quote:

Originally Posted by mikemech (Post 324247)
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.

mikemech September 16, 2011 06:58

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.

tomislav_maric September 17, 2011 07:38

Quote:

Originally Posted by mikemech (Post 324388)
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.

oort October 11, 2011 09:43

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 (Post 324251)
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


romant October 11, 2011 10:03

global volume
 
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.

oort October 11, 2011 10:48

Thanks romant.
The total cell's volume given by your method have deviation from "geometric" calculations of 0.002% in my mesh. :)

pvpnr May 23, 2012 17:15

Quote:

Originally Posted by oort (Post 327468)
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


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