|
[Sponsors] |
December 8, 2020, 09:03 |
Get absolute faceID of a cell
|
#1 |
Member
Join Date: Jun 2019
Posts: 41
Rep Power: 7 |
Hi there. I would like to get the faceIDs of some cells whose neighbour cell and owner cell have a specific scalar value (volscalarfield)
My issue is that the faceid i'm receving are made of 0, 1, 2, 3, 4, 5 : ie they are the relative faces of my cell. How can i get the absolute faceId in order to use them after ? Thanks a lot. Here is my code : Code:
DynamicList<label> Omega2FaceList; // Facelist // loop over the cell of my mesh forAll(box, celli) { // if my scalar is equal to one if (box[celli] = 1.0){ // get facesid of the cell const cell& faces = mesh.cells()[celli]; // Info << "cell faces : " << faces << endl; forAll(faces,facei) { const scalar& sOwner = box[mesh.owner()[facei]]; const scalar& sNeighbour = box[mesh.neighbour()[facei]]; // Info << "cell owner value : " << box[mesh.owner()[facei]] << endl; // Info << "cell neighbour value: " << box[mesh.neighbour()[facei]] << endl; if ((sOwner == 1.0) && (sNeighbour == 0.0)) { Omega2FaceList.append(facei); Info << "facei: " << facei << endl; } } } } |
|
December 15, 2020, 02:22 |
up
|
#2 |
Member
Join Date: Jun 2019
Posts: 41
Rep Power: 7 |
No one to help me ?
|
|
December 15, 2020, 04:37 |
|
#3 |
Senior Member
|
Not sure here.
However, loops over faces (instead of over cells) in OpenFoam are more intuitive (given the face-based structure of OpenFoam). Each face has one owner and one neighbor cell. Thus you could loop over all faces and check if the field value in the owner and neighbor cell has target value. If so, store value of the given face. The following was adapted from Listing 6.10 in Chapter 6 of the book by Moukalled e.a. DynamicList<label> Omega2FaceList; // Facelist const labelList& own = faceOwner(); const labelList& nei = faceNeighbour(); forAll (own,facei) { if ( (box[own[facei]]==1.) && (box[nei[facei]]==1.) ) { Omega2FaceList.append(facei); } } Hope this gives ideas . |
|
December 15, 2020, 05:05 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
I have no idea what it is about the forAll macro that misleads so many people. It is simply a for-loop over the size of some list-like item. You are reusing the facei, which is an index, as if it is the face ID! Without questioning if there is a better way, here is a cleaner version of your code. Please examine the changes to see your error. Code:
DynamicList<label> Omega2FaceList; // Facelist // loop over the cell of my mesh forAll(box, celli) { if (!equal(box[celli], 1)) { continue; } for (const label facei : mesh.cells()[celli]) { if ( equal(box[mesh.owner()[facei]], 1) && ( !mesh.isInternalFace(facei) || equal(box[mesh.neighbour()[facei]], 0) ) { Omega2FaceList.append(facei); } } } } However, since you are essentially just looking for faces to select, it makes much more sense to be checking them directly. Code:
DynamicList<label> Omega2FaceList; // Facelist for (label facei = 0; facei < mesh.nInternalFaces(); ++facei) { const label own = mesh.owner()[facei]; const label nei = mesh.neighbour()[facei]; if (equal(box[own], 1) && equal(box[nei], 0)) { Omega2FaceList.append(facei); } } for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); ++facei) { const label own = mesh.owner()[facei]; if (equal(box[own], 1)) { Omega2FaceList.append(facei); } } Depending on the density of faces to be selected and what you want to do with the information afterwards, you may find a bitSet a convenient container. For example, Code:
bitSet selectFaces(mesh.nFaces()); for (label facei = 0; facei < mesh.nInternalFaces(); ++facei) { const label own = mesh.owner()[facei]; const label nei = mesh.neighbour()[facei]; if (equal(box[own], 1) && equal(box[nei], 0)) { selectFaces.set(facei); } } ... later on Info<< "found " << selectFaces.count() << " faces" << nl; if (selectFaces.test(1000)) Info<< "face 1000 is selected" << nl; for (const label facei : selectFaces) ... // Pick the other faces selectFaces.flip(); |
||
December 20, 2020, 07:59 |
|
#5 | |
Member
Join Date: Jun 2019
Posts: 41
Rep Power: 7 |
Thanks a lot. Your answer help me to understand more deeply the openfoam mesh structuration.
Quote:
However i get a list out of bound. It seems that the mesh.owner.()size() is the same than the mesh.nInternalFaces() and that the boundary cells are not present in the mesh.owner. How is it possible ? Looking at my constant/polymesh/owner, the size of the list should is however equal to mesh.nFaces (nearly twice as mesh.nInternalFaces). Looking at the documentation, line 278 https://cpp.openfoam.org/v8/fvMesh_8H_source.html that the owner list only concern the internal faces. Am I wrongly construcing my mesh ? I only #include fvMesh.H to do it. |
||
December 20, 2020, 08:47 |
|
#6 |
Member
Join Date: Jun 2019
Posts: 41
Rep Power: 7 |
Yes, it seems that the mesh.owner() list is only okay for the internal faces. So how can i know to which cell is connected a face whose id correspond to a boundary face ?
|
|
Tags |
mesh face cell absolute |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field | lakeat | OpenFOAM Community Contributions | 58 | December 23, 2021 03:36 |
Set cell volume integrated field values to preserve integral | Diro7 | OpenFOAM Pre-Processing | 2 | June 3, 2018 11:44 |
Partition: cell count = 0 | metmet | FLUENT | 1 | August 31, 2014 20:41 |
monitoring cell | Jane | Siemens | 2 | March 4, 2004 22:01 |
cell to cell relation | CMB | Siemens | 1 | December 4, 2003 05:05 |