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

[Technical] How to get one cell's point label list in correct order (right-hand rule)?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By hjasak

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 3, 2020, 12:11
Default How to get one cell's point label list in correct order (right-hand rule)?
  #1
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Dear Foamers,

I am writing a small tool to output OpenFOAM mesh to other formats. So far I can get correct
points, faces and boundary information.

However, when it comes to write one cell's point label list, the order is not correct.

For example a hex cell knowing its cell type from
Code:
 const cellModel& cell_type = cellShapes()[celli].model;
the correct order of point label list should be (0 1 2 3, 4 5 6 7). But in OpenFOAM the stored point label from
Code:
const labelList& cell_point_labels = cellPoints()[celli];
for this hex cell is like (0 1 3 2, 4 5 7 6), which breaks the right hand rule.

So my question is: knowing a cell's type, all faces and points, how to get the corrected order of point labels? i.e. for visualization purpose in vtk file format.

Thanks a lot.

___________________________________________

Update 1:

I found that the tool "foamToVTK" can output cell's point labels/IDs correctly. Anyone can give some tips where is
the actual code/function to output cell's point labels?

Last edited by keepfit; October 8, 2020 at 08:20.
keepfit is offline   Reply With Quote

Old   October 3, 2020, 19:52
Default
  #2
Senior Member
 
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9
Marpole is on a distinguished road
For class fvMesh, I remember, you can use get cellList, faceList and pointList from function cell(), face() and point(). You can then need reassemble to get the point index oder for a cell. As different cell type has different point order, there might be no function that you can use directly. I might be wrong.
Marpole is offline   Reply With Quote

Old   October 4, 2020, 03:48
Default
  #3
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by Marpole View Post
For class fvMesh, I remember, you can use get cellList, faceList and pointList from function cell(), face() and point(). You can then need reassemble to get the point index oder for a cell. As different cell type has different point order, there might be no function that you can use directly. I might be wrong.
I can write some functions to make the correct ordering of point labels, e.g. for simple cell types like hex, tet. But for cell type tetWedge and wedge in OpenFOAM, 4 points to define a face, while these 4 points are usually not on the same plane, how to deal with this issue?

Last edited by keepfit; October 4, 2020 at 16:16.
keepfit is offline   Reply With Quote

Old   October 4, 2020, 11:12
Default
  #4
Senior Member
 
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9
Marpole is on a distinguished road
If you refer to OpenFOAM User Guide, section 5.1.3 cell types, a cell's faces are indexed, so does the edge and point (including Wedge and tetWedge).



The return of functions cells() and faces() give you faces and points in the same order and number of them (please check as I did this 2-3 years ago). You can then code to judge if it is wedge , tetWedge and then get the point in correct order or in the order you want to export.
Marpole is offline   Reply With Quote

Old   October 4, 2020, 16:20
Default
  #5
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by Marpole View Post
If you refer to OpenFOAM User Guide, section 5.1.3 cell types, a cell's faces are indexed, so does the edge and point (including Wedge and tetWedge).



The return of functions cells() and faces() give you faces and points in the same order and number of them (please check as I did this 2-3 years ago). You can then code to judge if it is wedge , tetWedge and then get the point in correct order or in the order you want to export.
I actually output a cell's point coordinates (not labels), the ordering is still not correct. Code is like:

Code:
const cellList& cList = cells();

forAll(cList, celli)
{
    const auto& cPts = cList[celli].points(faces(), points());
    forAll(cPts, pointi)
    {
      std::cout
        << cPts[pointi].x() << " "
        << cPts[pointi].y() << " " 
        << cPts[pointi].z() << std::endl;
    }
    std::cout << std::endl;
}
You can check this.
keepfit is offline   Reply With Quote

Old   October 4, 2020, 16:30
Default
  #6
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
You need to ask for a cell shape and than ask that for points. This will give you the correct ordering you expect.

However, not all cells have shapes; if you have anything larger than a hex, the numbering conventions are not well established. The code answer to cell shape will be "I don't know" and you will not get a meaningful order.

Why? Well, what order would you expect for a dodecahedron, for example.

Hrv
olesen likes this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   October 5, 2020, 08:33
Wink
  #7
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by hjasak View Post
You need to ask for a cell shape and than ask that for points. This will give you the correct ordering you expect.

However, not all cells have shapes; if you have anything larger than a hex, the numbering conventions are not well established. The code answer to cell shape will be "I don't know" and you will not get a meaningful order.

Why? Well, what order would you expect for a dodecahedron, for example.

Hrv
As we only need the correct ordering of point labels for post-processing purpose e.g. visualization in ParaView, so we need to write our own point label ordering for specific format? I can not even get the hex cell's correct ordering of point labels from cellShapes() or cells().
keepfit is offline   Reply With Quote

Old   October 5, 2020, 16:54
Default
  #8
Senior Member
 
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9
Marpole is on a distinguished road
Can you post your mesh files and let me know which cell you are looking at?
Marpole is offline   Reply With Quote

Old   October 6, 2020, 04:30
Default
  #9
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by Marpole View Post
Can you post your mesh files and let me know which cell you are looking at?
I tested it on a very simple mesh: 3x3 cells

Code:
vertices
(
    (0 0 0)
    (1 0 0)
    (1 1 0)
    (0 1 0)
    (0 0 0.1)
    (1 0 0.1)
    (1 1 0.1)
    (0 1 0.1)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (3 3 1) simpleGrading (1 1 1)
);
So I wrote down all point/face/cell labels, and checked what OpenFOAM can output in terms of point labels for one cell, which can be used directly for a legacy vtk file.
keepfit is offline   Reply With Quote

Old   October 6, 2020, 11:48
Default
  #10
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by keepfit View Post
As we only need the correct ordering of point labels for post-processing purpose e.g. visualization in ParaView, so we need to write our own point label ordering for specific format? I can not even get the hex cell's correct ordering of point labels from cellShapes() or cells().

Hrv's answer is correct, or there is a bug, or you are doing something wrong.

Using cells() is not what you want. This returns the list of faces defining (enclosing) the cell, which is not what you asked.


If you have obtained the cellShape(), it contains a list of points defining the cell. It should also be in the correct point order. Example of its use,

Note that the VTK conversions have a flipped prism types, but both EnSight and STARCD formats have the same point ordering as OpenFOAM, and there is no problem there.
olesen is offline   Reply With Quote

Old   October 7, 2020, 09:06
Unhappy
  #11
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by olesen View Post


Hrv's answer is correct, or there is a bug, or you are doing something wrong.

Using cells() is not what you want. This returns the list of faces defining (enclosing) the cell, which is not what you asked.


If you have obtained the cellShape(), it contains a list of points defining the cell. It should also be in the correct point order. Example of its use,

Note that the VTK conversions have a flipped prism types, but both EnSight and STARCD formats have the same point ordering as OpenFOAM, and there is no problem there.
Thanks! olesen. It works.

so for the vector:
Code:
const cellShapeList& cShapes = cellShapes();
the type "cellShape" is actually the point labels of a cell. I actually checked the "cellShape Class Reference" carefully, sadly did not find any container/vector or functions to get these point labels.

Last edited by keepfit; October 7, 2020 at 11:04.
keepfit is offline   Reply With Quote

Old   October 8, 2020, 02:33
Default
  #12
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by keepfit View Post
the type "cellShape" is actually the point labels of a cell. I actually checked the "cellShape Class Reference" carefully, sadly did not find any container/vector or functions to get these point labels.
Like you said, it is the list of point labels. You don't need any special methods to get at the list. The cell Shape is the list!
olesen is offline   Reply With Quote

Old   October 8, 2020, 05:03
Talking
  #13
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by olesen View Post
Like you said, it is the list of point labels. You don't need any special methods to get at the list. The cell Shape is the list!
We really need some reference book or user manual to give a big picture on the most important OpenFOAM classes and most useful functions. I have been using openFOAM for 5+ years, it was always a headache to find some useful functions, or to modify some source codes buried deeply. Most of the time I felt like finding a needle in a haystack

Last edited by keepfit; October 8, 2020 at 08:20.
keepfit is offline   Reply With Quote

Old   October 8, 2020, 18:25
Default
  #14
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by keepfit View Post
We really need some reference book or user manual to give a big picture on the most important OpenFOAM classes and most useful functions. I have been using openFOAM for 5+ years, it was always a headache to find some useful functions, or to modify some source codes buried deeply. Most of the time I felt like finding a needle in a haystack
I understand your sentiment. The problem always being how to define what the "big picture" is, and to structure things such that people can find it. If you could sketch an overview of how you would structure things, it would be interesting.
olesen is offline   Reply With Quote

Old   October 10, 2020, 16:27
Default
  #15
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by olesen View Post
I understand your sentiment. The problem always being how to define what the "big picture" is, and to structure things such that people can find it. If you could sketch an overview of how you would structure things, it would be interesting.
Well, I used to do some simulation on a commercial software of solid mechanics (finite difference method), which is commands driven (like MatLab) + a GUI. I had 3 or 4 ref. books at hand, pretty convenient to find whatever I needed. For OpenFOAM, perhaps we can catalog the reference book into:

Code:
Mesh: 
  primitive mesh: point, face, cell, etc
  dynamic mesh [optional]
  fvMesh: fvFace, fvCell, boundary faces, etc

Numerics:
  Boundary conditions
  Surface interpolation schemes
  PDEs dicretization: convection/diffusion/pressure terms, etc
  Turbulence models
  Sparse Matrix and Ax=B assembly
  Sparse linear system solvers

Post-processing: (less important)
  drag/lift coefficients
  yPlus 
  etc
There might be something important missing here, but I think this is pretty much the contents that should be covered by an OF ref. book.

Last edited by keepfit; October 11, 2020 at 09:11.
keepfit is offline   Reply With Quote

Old   October 13, 2020, 06:40
Default
  #16
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
I guess something like this is what you mean?
https://openfoam.com/documentation/g...urbulence.html

If you have some content, would be worth contacting
https://wiki.openfoam.com/Technical_..._and_Tutorials
olesen is offline   Reply With Quote

Old   October 13, 2020, 13:15
Default
  #17
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by olesen View Post
I guess something like this is what you mean?
https://openfoam.com/documentation/g...urbulence.html

If you have some content, would be worth contacting
https://wiki.openfoam.com/Technical_..._and_Tutorials
There is some online documentation of open-source software I really like, e.g.

https://lammps.sandia.gov/doc/Commands_all.html

At the moment I am making my own CFD code for the interactions between real particles and fluids . By focusing on the core operation such as surface interpolation and PDEs discrecretization, etc, then some open-source math libraries (PETSc, Eigen3, etc) are used for the solution of sparse linear system. Meshing and visualization are simply based on existing open-source tools. The reason why I'm doing this is that, I personally felt like it will take forever for me to complete it with OF, as it needs a lot of tweak or modification on the basic classes in OpenFOAM, not to mention a lot of new classes are needed as well for the moving particle-fluid interaction.

Last edited by keepfit; October 14, 2020 at 04:01.
keepfit is offline   Reply With Quote

Reply

Tags
mesh; points; labels


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
[OpenFOAM.com] swak4foam compiling issues on a cluster saj216 OpenFOAM Installation 5 January 17, 2023 16:05
[snappyHexMesh] How to define to right point for locationInMesh Mirage12 OpenFOAM Meshing & Mesh Conversion 7 March 13, 2016 14:07
snappyhexmesh remove blockmesh geometry philipp1 OpenFOAM Running, Solving & CFD 2 December 12, 2014 10:58
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 05:50
[Gmsh] Gmsh and samplesurface touf OpenFOAM Meshing & Mesh Conversion 2 December 10, 2007 02:27


All times are GMT -4. The time now is 11:06.