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

Find all adjacent cells

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 4 Post By Alish1984
  • 3 Post By hjasak

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 27, 2011, 05:47
Default Find all adjacent cells
  #1
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Dear all,

I would like to do calculations for a certain cell that involves all adjacent cells. I know that with cellCells one can find the up, down, left, and right neighbours. Now, in an orthogonal 2D mesh, does anyone know of a smart way to access also the "diagonal" adjacent cells, i.e. northwest, northeast, southeast, and southwest neighbours? Thanks in advance!
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   March 30, 2011, 10:26
Default Find all adjacent cells
  #2
ata
Senior Member
 
ata's Avatar
 
ata kamyabi
Join Date: Aug 2009
Location: Kerman
Posts: 323
Rep Power: 18
ata is on a distinguished road
I think you can use the adjacents of the adjacents. What do you think?
ata is offline   Reply With Quote

Old   March 31, 2011, 04:27
Default
  #3
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Hi Ata,

Thanks for your reply. If I use the adjacents of the adjacents, then I get the "west-west", "east-east", etc neighbours. I need the north-west, south-west, etc neighbours ...
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   March 31, 2011, 04:37
Default
  #4
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
The face numbering is done in a consistent way, and I think you can use that to your advantage. Let's say you found the right (west) neighbor of a cell, the face between them is west_cell_faces[0]. To get the west west neighbor, you can get the neighbor on the face west_cell_faces[1].

Have a look at U-127 and it should become more clear what I'm trying to say.
akidess is offline   Reply With Quote

Old   March 31, 2011, 04:51
Default
  #5
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Hi Anton,

Thanks for your idea. But I'm afraid that that won't solve it, unless I completely miss the point . I have been trying to prevent it, but now I'll have to share some of my drawing talent.

The cell in question is cell C (see drawing). Now, cellCells() will give cells N, E, S, and W. The cells I want are NE, SE, SW, and NW.

Quote:
Let's say you found the right (west) neighbor of a cell, the face between them is west_cell_faces[0]
Ok, so this is the face between cells W and C, right?

Quote:
To get the west west neighbor, you can get the neighbor on the face west_cell_faces[1].
But isn't this the same as what Ata said above? I need the "diagonal" neighbours in my fantastic drawing above . The trick might work if you could get the "upper face" of the W cell, i.e. the face between cell W and cell NW ...
Attached Images
File Type: jpeg cells.jpeg (6.0 KB, 45 views)
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   March 31, 2011, 04:59
Default
  #6
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
Sorry, I was thinking of far neighbor cells without diagonals But the same idea should be possible -> instead of taking faces 0 and 1, take faces 4 and 5.

[edit]: Oh dear, not only did I misunderstand the original intent, but also I did mix up east and west. Shame on me
akidess is offline   Reply With Quote

Old   March 31, 2011, 05:03
Default Find all adjacent cells
  #7
ata
Senior Member
 
ata's Avatar
 
ata kamyabi
Join Date: Aug 2009
Location: Kerman
Posts: 323
Rep Power: 18
ata is on a distinguished road
Hi Gijsbert Wierink
I think the notrh adjacent of the west adjacent cell is the north-west adjacent of the original cell. Is it true?
Best regards
Ata
ata is offline   Reply With Quote

Old   March 31, 2011, 05:56
Default
  #8
Senior Member
 
Kathrin Kissling
Join Date: Mar 2009
Location: Besigheim, Germany
Posts: 134
Rep Power: 17
kathrin_kissling is on a distinguished road
Hi Gijs,

you could try (now only for one stencil or my head will break)

labelList adjacent = mesh.cellCells()[cellI];

int size = adjacent.size();
//You need to now how many lists need to be defined now

//For each set a label list
PtrList<labelList> adjOfAdj(size);
for(int j; j<size; j++)
{
adjOfAdj.set
(
j,
new labelList(mesh.cellCells()[adjacent[j]]) //not too sure about the new
);
}
Now create a dynamic list to store your diagonals
dynamicList<label> diagonals(0);
Assuming you have at least one entry
So now you can loop over the single lists
int counter = 0;
for(int k; k<size; k++)
{
forAll(adjOfAdj[k], adjI)
{
label labelOne=adjOfAdj[k][adjI];
for(int j; j<size; j++)
{
if(j!=k)
{
forAll(adjOfAdj[j], adjII)
{
if(adjOfAdj[j][adjII]==labelOne)
{
counter++;
diagonals.resize(counter, labelOne)
}
}
}
}
}
}

In the end the dynamicList holds all your diagonals

I didnt implement or compile this its more a kind of a scope what could be done. I did the most in other code snippets but maybe the one or the other does not work at first!

Best

Kathrin
kathrin_kissling is offline   Reply With Quote

Old   April 1, 2011, 03:10
Default
  #9
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Hi Kathrin,

Many thanks for that! I made a method using findCell around a cell, but that is of course very slow if you mesh is bigger tha, say, 9 cells . Thanks for the input, I'll give it a try!
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   April 8, 2011, 06:05
Default
  #10
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Ask the cell for points that it touches and then as the points for cells - that will give you the second layer, but you will have duplicates. You can easily filter them by putting all cell indices into a labelHashSet and asking it for toc() = table of contents.

Enjoy,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   June 1, 2011, 11:17
Default
  #11
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 17
Andrea_85 is on a distinguished road
Hi all,
i was looking for somthing very similar to implement in my version of OF. Have a look at this post http://www.cfd-online.com/Forums/ope...ells-loop.html

For my case is not really important a 3x3 stencil,i only need "some" cells around a given cell, so the mesh.cellCells() function is ok.

At the moment i wrote this code:
Code:
forAll(mesh.cells(),cellI)
        {
          labelList adjI = mesh.cellCells()[cellI];


           for(int j=0; j<adjI.size(); j++)
           {
          
              labelList adjII = mesh.cellCells()[adjI[j]];
            }
           }
Now, my problem is how to create a single list, with inside all the labels coming from adjI and adjII and then check for duplicates.

If i define a third list: "labelHashSet adjTot"
and then i fill the list with the values coming from adjI and adjII (using .insert()), does not work (the list does not contain duplicate, so the size is correct, but it does not contain the label of the cells. It contains only 0 and 1) . but maybe I did something wrong!! (labelHashSet is not a kind of List?!?)

any help will be appreciated!

Thanks in advance

andrea
Andrea_85 is offline   Reply With Quote

Old   May 11, 2012, 07:26
Default
  #12
Member
 
Kim Yusik
Join Date: Dec 2009
Posts: 39
Rep Power: 17
impecca is on a distinguished road
did anyone experience a problem when you try to access the neighbour cells in parallel computing? in my case I have a problem but I don't know how to fix it. I wrote a thread (link below) but no reponse so far. It will be very appreciated if someone gives any advice.
Regards



http://www.cfd-online.com/Forums/ope...computing.html
impecca is offline   Reply With Quote

Old   October 3, 2012, 21:18
Default east and north cell values
  #13
Member
 
,...
Join Date: Apr 2011
Posts: 92
Rep Power: 14
hawkeye321 is an unknown quantity at this point
Is there any way (any function) to get the value of a parameter at the east and north of a specific cell?
hawkeye321 is offline   Reply With Quote

Old   October 6, 2012, 07:04
Default
  #14
ata
Senior Member
 
ata's Avatar
 
ata kamyabi
Join Date: Aug 2009
Location: Kerman
Posts: 323
Rep Power: 18
ata is on a distinguished road
Hi
First find the neighbors and then compare they coordinates to find desired cells.
ata is offline   Reply With Quote

Old   May 5, 2014, 16:18
Default
  #15
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
It seems that cellCells can be used to access ALL cells around a specific cell... how would you access only the NORTH cell?
CHARLES is offline   Reply With Quote

Old   May 5, 2014, 17:10
Default
  #16
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Cheap shot. FOAM is a polyhedral mesh code and it uses face addressing on mixed cell types. There's no such thing as "north". I think you need to read my Thesis

Some questions to help you think:
- what is North on a tet cell?
- ... and on a dodekahedron?

Therefore, the whole compass framework does not work any more. For things like linear upwind and similar we use gradients (see the Gamma paper) and for others we adapt the numerics.

For special algorithms, there is a function called oppositeFace, but beware: if your cell is not prismatic, the function will respond with an "I don't know".

Hope this helps,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   May 6, 2014, 13:25
Default
  #17
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Thanks Hrv, you were helpful!

I must say, I'm impressed with your dissertation.

The point you make about the compass framework not being applicable to such element shapes makes sense. I am currently considering structured meshes with hexahedral elements so I thought cellCells could be used to project a cell's boundary value to all cells above it.

Can you say more about oppositeFace or perhaps suggest a way to achieve what I am trying to do?
CHARLES is offline   Reply With Quote

Old   February 22, 2017, 10:55
Default
  #18
Member
 
Ali Shamooni
Join Date: Oct 2010
Posts: 44
Rep Power: 16
Alish1984 is on a distinguished road
Quote:
Originally Posted by gwierink View Post
Hi Anton,

Thanks for your idea. But I'm afraid that that won't solve it, unless I completely miss the point . I have been trying to prevent it, but now I'll have to share some of my drawing talent.

The cell in question is cell C (see drawing). Now, cellCells() will give cells N, E, S, and W. The cells I want are NE, SE, SW, and NW.

Ok, so this is the face between cells W and C, right?

But isn't this the same as what Ata said above? I need the "diagonal" neighbours in my fantastic drawing above . The trick might work if you could get the "upper face" of the W cell, i.e. the face between cell W and cell NW ...



Thanks Hrv

For anyone who is still interested this is the piece of code:

forAll(U,celli)
{
//if (celli==0)
//{
labelHashSet setNBCells(1);
labelList lCP = mesh.cellPoints(celli);

//Pout<<lCP<<endl;
forAll(lCP,pointi)
{
labelList lPC=mesh.pointCells(lCP[pointi]);
//Pout<<lPC<<endl;
setNBCells.insert(lPC);
}
//Pout<<setNBCells<<endl;
labelList NBCells=setNBCells.toc();

//}
}
Alish1984 is offline   Reply With Quote

Old   February 23, 2017, 18:27
Default
  #19
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Caveat - this does not work properly across processor boundaries
Tobi, tom_flint2012 and tonnykz like this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] How to delete cells in OF based on CheckMesh? AndTen OpenFOAM Meshing & Mesh Conversion 15 July 27, 2018 07:13
How to find adjacent cells evgenii OpenFOAM Running, Solving & CFD 3 September 27, 2008 03:03
Accessing neighbour cells!! Thiyagarajandhayalan Siemens 2 March 21, 2008 05:26
Pointers to wall adjacent cells in CFX 5 Fabian CFX 2 November 21, 2002 12:14
a way to find out wall-neighboring cells? Christian FLUENT 4 May 10, 2002 09:30


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