CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Getting node of a position (https://www.cfd-online.com/Forums/openfoam-programming-development/113987-getting-node-position.html)

anishtain4 March 2, 2013 15:39

Getting node of a position
 
How do you find the grid point that is near a location?
The purpose is to calculate space correlation of a turbulence field which means:

Code:

R(r)=<u(x)u(x+r)>/<u(x)^2>

fumiya March 2, 2013 23:28

The most easiest way
 
I think the most easiest way to do your job is the following:

Code:

    vector pos(0.0,0.0,0.0); //Change the position as you like
    scalar limitLeng = 0.1;  //Change the value as you like

    const cellList& Cells = mesh.cells();
    const pointField& Points = mesh.points();

    forAll(Cells, cellI)
    {
        if(mag(mesh.C()[cellI] - pos) < limitLeng)
        {
            forAll(mesh.cellPoints()[cellI], pointi)
            {
                //You can access labels of cell vertices
                label pointI = mesh.cellPoints()[cellI][pointi];
                scalar r = mag(pos - Points[pointI]);

                //your stuff
            }
        }
    }

Please post the codes, if there are more efficient ways.

Hope that helps,
Fumiya

l_r_mcglashan March 3, 2013 07:37

The above code is unreliable, as the answer will be dependent on limitLeng. You are also not considering the situation where the nearest point to the location you are looking up may not be a part of the cell that it is inside of, although that will depend on how your mesh was constructed.

primitiveMesh has a findCell function. Use that instead.

If you want something more efficient then meshSearch uses an octree method for faster lookup. It doesn't work in parallel though so the location you lookup must be within the local mesh.


All times are GMT -4. The time now is 15:29.