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/)
-   -   Neighbor of a boundary face (http://www.cfd-online.com/Forums/openfoam-programming-development/98402-neighbor-boundary-face.html)

skabilan March 9, 2012 20:36

Neighbor of a boundary face
 
Hi Foamers,

I need to access the neighboring faces of boundary face. I have the following code:

label patchID = mesh.boundaryMesh().findPatchID("walls");
const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
forAll(cPatch, facei)
{
I need to access the neighboring FACES of facei
}

Thanks in advance!
Senthil

anon_a March 10, 2012 03:36

Code:

    List<List<bool> > neighbourFace;                          // a list for each face,
                                                                            // a list of bools for the other faces of the patch
                                                                            // The bool responds to whether they are neighbour faces or not
    label patchID = mesh.boundaryMesh().findPatchID("walls");
    const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
    neighbourFace.setSize(cPatch.size());
    forAll(cPatch, faceI)                                            // faceI: the face whose neighbour faces we want
    {
        neighbourFace[faceI].setSize(cPatch.size());
        forAll(cPatch, faceJ)                                        // faceJ: possible neighbour face
        {
            neighbourFace[faceI][faceJ] = false;

            if (faceI != faceJ)                                        // if they are the same, they can't be neighbours
            {
                forAll(cPatch[faceI], pointI)                      // check all points of which faceI consists
                {

                    forAll(cPatch[faceJ], pointJ)                  // and compare them with the ones of faceJ
                    {
                        if (cPatch[faceI][pointI] == cPatch[faceJ][pointJ])
                            {
                                neighbourFace[faceI][faceJ] = true;
                            }
                    }
                }
            }
        }
    }

I have only tested that briefly but it seems to be working.
I check if there are common points but you can easily modify it to check if there are common edges only.

skabilan March 10, 2012 15:41

Hi anon_a,

Thank you for the help!

Cheers!
Senthil


All times are GMT -4. The time now is 07:32.