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/)
-   -   Iterate over nearing cells of a specified cell (https://www.cfd-online.com/Forums/openfoam-programming-development/134671-iterate-over-nearing-cells-specified-cell.html)

ooo May 3, 2014 12:50

Iterate over nearing cells of a specified cell
 
Hi FOAMers,

I've implemented a user-interpolation in OpenFOAM , but to compute the distance of the current cell to near cells, i have to iterate over all cells which can be costly.
So do you have any suggestion on how to iterate over a specified radius of a cell(or coordinate), and not over all cells. (to reduce computation cost)
What i'm doing :
Code:

forAll(U,cellI)
point[XX].x() - mesh.C()[cellI].x()
...

What i want to do:
Code:

forAll(iterate over nearing cells of point[XX].x())
point[XX].x() - mesh.C()[cellI].x()
...

Thank you in advance,

ngj May 4, 2014 14:26

Good evening ooo

You should be able to construct what you want using the following methods in the mesh class:

Code:

mesh.cellCells();
mesh.pointCells();
mesh.cellPoints();

Be aware that you will need to treat the processor boundaries specially (and potentially also periodic/cyclic boundaries).

Kind regards,

Niels

ooo May 20, 2014 13:36

Quote:

Originally Posted by ngj (Post 489743)
Good evening ooo

You should be able to construct what you want using the following methods in the mesh class:

Code:

mesh.cellCells();
mesh.pointCells();
mesh.cellPoints();

Be aware that you will need to treat the processor boundaries specially (and potentially also periodic/cyclic boundaries).

Kind regards,

Niels

Thank you.
Having 2 cell layers (or maximum 3) is enough for me so i'm using this code.(if it works, then i continue to removing duplication by uniqueOrder...)
It gives no compilation error, but segmentation error in running.
Do you know what's the problem?
Code:

labelListList cellCells;
forAll(mesh.cells(),cellI)
        {
        labelList layer1 = mesh.cellCells()[cellI];
        cellCells[cellI].append(layer1) ;
        for(int i=0; i<layer1.size(); i++)
        {
        labelList layer2 = mesh.cellCells()[layer1[i]];
        cellCells[cellI].append(layer2);
        }
        }


ngj May 20, 2014 16:52

You never define the size of cellCells, and afterward you to assign something to the ceellI'th array of cellCells, but it still does not have a size.

If I understand the code correct, the append works on the nested labelList, and not on the outer list.

Kind regards,

Niels

ooo May 20, 2014 17:29

Thank you.
Using dynamic labelLists solved the problem.


All times are GMT -4. The time now is 04:16.