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/)
-   -   Search adjacent cells and assign (https://www.cfd-online.com/Forums/openfoam-programming-development/225542-search-adjacent-cells-assign.html)

loving_cfd March 31, 2020 03:49

Search adjacent cells and assign
 
Hello, my dears.

I want to loop over all the cell in the computational domain, search the four or eight neighbor cells and assign at each timestep.

It can be implemented in Fluent via the macros of c_face_loop and C_F0.

How about on OpenFOAM?

clapointe March 31, 2020 12:06

Neighbour cells can be accessed via cellCells(). So off the top of my head it would be something like :

Code:

forAll(mesh.C(), celli) //outer, all cell loop
{
    label curCell = mesh.C()[celli];

    labelList curNeiCells = mesh.cellCells()[curCell];

    forAll(curNeiCells, cellj) //inner, neighbor cell loop
    {
        do something here...
    }
}

There might be a more elegant way to do it, but looping is pretty straightforward. Of course, the first loop doesn't have to be all cells if you already have a list of cells in mind.

Caelan

loving_cfd April 14, 2020 04:21

reply to Caelan
 
Dear Caelan,

Appreciate for your relpy!

Your reply help me learn more on OpenFOAM.

I will try the method on my program and share the result with you.

Best wishes!


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