CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Cell volume and face area calculation (https://www.cfd-online.com/Forums/openfoam-programming-development/158213-cell-volume-face-area-calculation.html)

richard_vega August 18, 2015 13:28

Cell volume and face area calculation
 
Is there a simple way to obtain a list that has the volume of each cell in a mesh along with a list that has the area of each face in a mesh?

alexeym August 18, 2015 13:37

Hi,

1. V method in fvMesh (http://foam.sourceforge.net/docs/cpp...9d5006af5644e5)

2. Sf method in fvMesh (http://foam.sourceforge.net/docs/cpp...121219b4ce84f9)

richard_vega August 18, 2015 13:54

Thank you for the quick reply. I probably should have stated somewhere in that question that I have no experience programming in OpenFOAM. The extent of my experience is using standard solvers and utilities, so the links did not mean a while lot to me. Could you add a bit more explanation on how I could use these functions?

alexeym August 18, 2015 14:04

Quote:

Originally Posted by richard_vega (Post 560067)
Could you add a bit more explanation on how I could use these functions?

Obviously, it depends on where you would like to use them.

But basically if you have mesh object or type fvMesh (usually you have it in solvers and in most of utilities), then if you would like to iterate over cell volumes, you can use something like:

Code:

forAll(mesh.V(), idx)
{
    Info<< "Volume of cell with index " << idx << " is " << mesh.V()[idx] << end;
}

Maybe it would be better, if you post why do you need volumes of cells and areas of faces.

richard_vega August 18, 2015 14:10

why I need them...
 
I am using OpenFOAM only as a pre and post processor to my code, which is written in C/OpenCL. Somewhere in my code, I am calculating the volumes and areas and I am getting some strange results that I believe are a result of the 5 digit precision in the points file. I wanted to use OpenFOAM to calculate the volumes and areas to see if this a bug in my code, or indeed the precision issue I am suspecting. Thus, I was hoping for sort of a one-liner that would generate a file called "volumes," but I guess no dice. I will try your suggestion tonight.

alexeym August 18, 2015 14:46

1 Attachment(s)
If you just need to look at the list of volumes you can use

Code:

Info << mesh.V() << endl;
Or you can use utility from attached archive, it will write cell volumes in volumes.dat file and face areas into areas.dat file.

J. Pan April 7, 2021 06:08

Quote:

Originally Posted by alexeym (Post 560084)
If you just need to look at the list of volumes you can use

Code:

Info << mesh.V() << endl;
Or you can use utility from attached archive, it will write cell volumes in volumes.dat file and face areas into areas.dat file.

Hi Alexey,

I tried to compile the utility but encountered the following error. I appreciate if you could give any hints. FYI: I am using openfoam 5 and Ubuntu 20.04.

write_cell_volumes_and_face_areas.cpp:6:10: fatal error: OFstream.H: No such file or directory
6 | #include "OFstream.H"
| ^~~~~~~~~~~~
compilation terminated.


All times are GMT -4. The time now is 02:17.