CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Get absolute faceID of a cell

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 8, 2020, 09:03
Default Get absolute faceID of a cell
  #1
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
Hi there. I would like to get the faceIDs of some cells whose neighbour cell and owner cell have a specific scalar value (volscalarfield)


  • I loop throw my cell (with the help of my 'box' voldscalarfield).
  • if my cell scalar has a certain value:
    • i get the 6 faces of my cell
    • for all these faces:
      • if the adjacant cell has a scalar of a certain value :
        • i append the faceid to a list
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;

                }
            }
        }
    }
Voulet is offline   Reply With Quote

Old   December 15, 2020, 02:22
Default up
  #2
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
No one to help me ?
Voulet is offline   Reply With Quote

Old   December 15, 2020, 04:37
Default
  #3
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 802
Blog Entries: 1
Rep Power: 18
dlahaye is on a distinguished road
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 .
dlahaye is offline   Reply With Quote

Old   December 15, 2020, 05:05
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Voulet View Post
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;

                }
            }
        }
     }

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);
         }
      }
    }
}
I've just made an assumption about what you want to do on boundaries.


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);
    }
}
BTW: in both cases I have used the equal() method when checking values, to account for possible rounding.



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();
dlahaye likes this.
olesen is offline   Reply With Quote

Old   December 20, 2020, 07:59
Default
  #5
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
Thanks a lot. Your answer help me to understand more deeply the openfoam mesh structuration.
Quote:
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);
    }
}
I don't understand the second loop. I guess that is intended to get the cells on the boundary whose owner cell have a box == 1 value. That's what i'm looking for. I do undertand that the faces indexing start with internal faces and then swith to boundary faces (that's why for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); ++facei)).


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.
Voulet is offline   Reply With Quote

Old   December 20, 2020, 08:47
Default
  #6
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
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 ?



Voulet is offline   Reply With Quote

Reply

Tags
mesh face cell absolute


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
[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


All times are GMT -4. The time now is 01:00.