CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   where to find the labels of the hex ? (http://www.cfd-online.com/Forums/openfoam-programming-development/93128-where-find-labels-hex.html)

hsingtzu October 5, 2011 19:16

where to find the labels of the hex ?
 
Hi

when I look at the output file of u or p, it is a long list of numbers.
I know each number corresponds to one hex, but I am wondering what hex the number corresponds to. Where can I find the hex labels, just like the point labels, so I will know which number goes to which hex which is hex number __ and is composed by point__, __, __, ...

Thanks
Hsingtzu

marupio October 5, 2011 21:22

It's not easy. I'd suggest you use a post-processing program, or the built-in sample utility.

If you don't have mesh motion, your mesh details will be in: /case/constant/polyMesh/

If you do have mesh motion, you also have to refer to your time directories.

1. The geometry starts with points. The points are clear to understand... but they aren't explicitly numbered.

2. Number them, starting at zero from the top.

3. Next comes faces. These are groups of points that form a face. The numbers in the groups correspond to the numbers you gave the points list (in step 2). Again, the faces aren't explicitly numbered... but you don't need to number them.

4. Next come the cells. This is what you are looking for... each cell corresponds with the numbers in your velocity or pressure output files. Finally, after all that work! ... there is no cells file ... but there are two other files: neighbours and owners. The numbers in these files are the cell numbers. These files have a one to one correspondence with the faces file. Using these three files in concert, you can figure out which faces are "owned" by which cells, and which are "neighbours". Outside faces don't have neighbours, so the owners file is longer.

There's probably a way to output the cell centres, in a list, corresponding to the cell numbers.

tomislav_maric October 6, 2011 02:52

Quote:

Originally Posted by hsingtzu (Post 326840)
Hi

when I look at the output file of u or p, it is a long list of numbers.
I know each number corresponds to one hex, but I am wondering what hex the number corresponds to. Where can I find the hex labels, just like the point labels, so I will know which number goes to which hex which is hex number __ and is composed by point__, __, __, ...

Thanks
Hsingtzu

Hi, here's a very very simple example of direct cellList - vol*Field addressing.

Code:

// Get the mesh cells  = these are the hexes you're talking about, but they
// may not be hex, they can be of any shape (convex logical polyhedron).
const cellList& meshCells = mesh.cells();

// Let's say that your field is called F (again, just a silly example)

forAll (meshCells, I)
{
    // Do something silly.
    F[I] = 5;
    // Access cell points from the cell list...
    const cell& c = meshCells[I];
    pointField cellPoints = c.points(meshPoints);
}

Something like the example above would be used if you want an operation on the specific cell to change the value of the field.

Notice that the "I" counter maps directly from fvMesh::cells to the vol*Field, because each F value is related to a single cell centre. So, the position of the value in your field F is actually the label of the cell in the field cells. Its indirect, and gets clear if you write some loops over the lists yourself, output that and anaylse. Check out Foam:: PrimitiveMesh class for connectivity information.

Hope this helps,

Tomislav

hsingtzu October 6, 2011 11:53

Thanks to marupio and Tomislav.
I would match the numbers in the "face" file and that in the "owner" file to get the points of the cell. Then I would use the "points" file to find the coordinates. If I would like to find the center of the cell, I find the avg of the points :)

Also I can write a code according to Tomislav's suggestion.

Hsingtzu

tomislav_maric October 6, 2011 13:56

Quote:

Originally Posted by hsingtzu (Post 326925)
Thanks to marupio and Tomislav.
I would match the numbers in the "face" file and that in the "owner" file to get the points of the cell. Then I would use the "points" file to find the coordinates. If I would like to find the center of the cell, I find the avg of the points :)

Also I can write a code according to Tomislav's suggestion.

Hsingtzu

No problem. My advice: if you need something from a cell , use the Foam::cell class, meaning a function from this class.

Check out the Doxygen C++ documentation and search there for the stuff you need.

If you need local cell computation (like I do), then use Foam::cell::centre (be aware that the local cell computation of the volume magnitude and centre are approximative and don't check for non-planar faces). If you want the cell magnitude or centre for every cell of the mesh, use fvMesh::C() method.

Search for the methods in the src directory, or go here and search:

http://http://www.openfoam.com/docs/cpp/

Godspeed,
Tomislav :)


All times are GMT -4. The time now is 21:50.