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/)
-   -   The results of findCell are different out and in for-loop (https://www.cfd-online.com/Forums/openfoam-programming-development/239767-results-findcell-different-out-loop.html)

Msure November 23, 2021 05:27

The results of findCell are different out and in for-loop
 
Hello everyone,

I came across a problem when I wrote my own solver. I need to use findCell to find the which cell that my point is in. But for the same point, the results of findCell are different out and in my for-loop.
Code:

#include "fvCFD.H"
#include "meshSearch.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    argList::addBoolOption
    (
        "noOverwrite",
        "increment time to avoid overwriting initial fields"
    );
    #include "setRootCase.H"
    #include "createTime.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    #include "createMesh.H"
IOdictionary blockMeshDict
(
    IOobject
    (
        "blockMeshDict",
        runTime.system(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    )
); 
IOdictionary NetProperties
(
    IOobject
    (
        "NetProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    )
);
const dictionary& NetDict(NetProperties.subDict("deltaFunction"));
const label  nx(blockMeshDict.lookup<scalar>("nx"));
const label  ny(blockMeshDict.lookup<scalar>("ny"));
const label  nz(blockMeshDict.lookup<scalar>("nz"));
const scalar lx(blockMeshDict.lookup<scalar>("lx"));
const scalar ly(blockMeshDict.lookup<scalar>("ly"));
const scalar lz(blockMeshDict.lookup<scalar>("lz"));
const scalar dx = lx/nx;
const scalar dy = ly/ny;
const scalar dz = lz/nz;
const List<label> offSet_
(
    NetDict.lookup("a")
);

meshSearch searchEngine_(mesh);

vector tmpKnotPoint(1.5,0.72,1.359);
vector point1(1.47727,0.694583,1.30181);
vector point2(1.5,0.694583,1.30181);
Pout << "point1 (1.47727 0.694583 1.30181) should be inside cell " << searchEngine_.findCell(point1) << endl;
Pout << "point2(1.5 0.694583 1.30181) should be inside cell " << searchEngine_.findCell(point2) << endl;

vector tmpOffSetPoint;
label num = 0;
forAll(offSet_, zi)
{
    tmpOffSetPoint.z() = tmpKnotPoint.z() + offSet_[zi]*dz;
    forAll(offSet_, yi)
    {
        tmpOffSetPoint.y() = tmpKnotPoint.y() + offSet_[yi]*dy;
        forAll(offSet_, xi)
        {
            tmpOffSetPoint.x() = tmpKnotPoint.x() + offSet_[xi]*dx;
            label cellId = searchEngine_.findCell(tmpOffSetPoint);
            Pout << num << "  " << cellId << "  " << tmpOffSetPoint  << endl;
        }                   
    }
}

    return 0;
}

and the output:
HTML Code:

point1 (1.47727 0.694583 1.30181) should be inside cell 423586
point2(1.5 0.694583 1.30181) should be inside cell 423587
0  423587  (1.47727 0.694583 1.30181)
0  423587  (1.5 0.694583 1.30181)
0  423785  (1.47727 0.72 1.30181)
0  423785  (1.5 0.72 1.30181)
0  442595  (1.47727 0.694583 1.359)
0  442595  (1.5 0.694583 1.359)
0  442793  (1.47727 0.72 1.359)
0  442793  (1.5 0.72 1.359)

The point1 and point2 should be in 423586 and 423587, but inside the loop, it shows that they are both in cell 423587.
I have no idea about this. I tried mesh.findCell, the same results.
Could anyone tell me what's wrong in this piece of code? Thanks so much!


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