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

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

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 23, 2021, 05:27
Default The results of findCell are different out and in for-loop
  #1
New Member
 
Shuo Mi
Join Date: Nov 2020
Location: London
Posts: 19
Rep Power: 5
Msure is on a distinguished road
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!
Msure is offline   Reply With Quote

Reply

Tags
openfoam; findcell;


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



All times are GMT -4. The time now is 14:33.