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

[Technical] How to identify cell neighbours

Register Blogs Community New Posts Updated Threads Search

Like Tree30Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 24, 2015, 11:16
Default
  #41
Member
 
Xinguang Wang
Join Date: Feb 2015
Posts: 45
Rep Power: 11
JasonWang3 is on a distinguished road
Hi Su

Do you have any idea on how to access the neighbour cells of cell(i) in y direction.

The cell P is known now, which is close to the wall, and I want to use the label of cell N which is above P, and the face label of n, which is between cell P and cell N.

Thanks a lot.
JasonWang3 is offline   Reply With Quote

Old   September 24, 2015, 12:47
Default
  #42
Member
 
Xinguang Wang
Join Date: Feb 2015
Posts: 45
Rep Power: 11
JasonWang3 is on a distinguished road
Quote:
Originally Posted by CHARLES View Post
I'm confused about how to access a specific cell using cellCells. For example, how can I use cellCells to access the NORTH cell of each cell in my domain?

Here's an example of what I would like to do... I know that the code may not compile, I'm just trying to explain what I'm doing.

Code:
V=value; //V is a boundary field ('value' is calculated and varies across the domain)

forAll(U, celli)
{
U[celli]=V[celli];
U[NORTH of celli] = U[celli];
}
hi Charles

Have you found a way to your questions? I meet the same situation.

Thanks a lot.

Xinguang
JasonWang3 is offline   Reply With Quote

Old   October 13, 2015, 12:09
Default
  #43
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
I am currently facing with this problem as well. Unfortunately, the idea of a compass like navigation is not possible for unstructured non-orthogonal meshes to my opinion. However, for playing around I assumed a orthogonal mesh aligned with the coordinate axis and by this it is possible to detect the direction of the neighbour by calculating the vector between the cell centres of the neighbour and the master cell. Some quick & and dirty piece of code would look like this

Code:
    forAll(mesh_.cells(),cellI)
    {
        vector cellCenter = mesh_.C()[cellI];
        labelList neighbours = mesh_.cellCells()[cellI];
        forAll(neighbours,cellJ)
        {
            vector direction = mesh_.C()[neighbours[cellJ]] - cellCenter;
            label axis = 0;
            for(label i=0; i<3;i++)
            {
                if (mag(direction[i])>=mag(direction[axis]))
                {
                    axis = i;
                }
            }
            switch(axis)
            {
                case 0:
                    Info << "Seems like x-Axis" << endl;
                    break;
                case 1:
                    Info << "Seems like y-Axis" << endl;
                    break;
                case 2:
                    Info << "Seems like z-Axis" << endl;
                    break;
            }
        }
    }
Best regards,
Fabian
fs82 is offline   Reply With Quote

Old   March 7, 2016, 08:51
Default Neighbours within a radius
  #44
New Member
 
Robert R.
Join Date: Feb 2016
Location: Braunschweig, Germany
Posts: 7
Rep Power: 10
chefkoch89 is on a distinguished road
Hey,

I need to check a value (temperature) of cells within a radius around the celli. Do I understand it right, that it is just possible to get the direct neighbors of the celli with your code?
Right now I have no ideo how to implement such loop over all cells into my code. Do you got any proposals?

Thank you
chefkoch89 is offline   Reply With Quote

Old   March 16, 2016, 05:09
Default
  #45
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
I would say yes, you can do it with my code sniplet. However, there are some tools who create cellZones and cellSets and have a option to create spheres around a given centre. I would suggest to look into this tools and see how the handle the creation of spheres. As a starting point look at meshTools/sets/cellSources/sphereToCell/sphereToCell.C

Best regrads
Fabian
fs82 is offline   Reply With Quote

Old   March 16, 2016, 07:08
Default
  #46
New Member
 
Robert R.
Join Date: Feb 2016
Location: Braunschweig, Germany
Posts: 7
Rep Power: 10
chefkoch89 is on a distinguished road
Thanks for the response.

I do understand the usage of sphereToCell just to refine the mesh, but not to create a virtual value to identify the cell temperatures within this sphere.
Maybe you can write a short code to show what you mean.

Thanks a lot
chefkoch89 is offline   Reply With Quote

Old   March 16, 2016, 11:12
Default
  #47
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
I think the solution is already included in sphereToCell.C in the function combine:
Code:
//This gets all cell centres of all mesh cells
const pointField& ctrs = mesh_.cellCentres();

    //This calculates the radius of your sphere
    const scalar radSquared = radius_*radius_;

    //Loop over all cells
    forAll(ctrs, cellI)
    {
        //calculates the distance between the cell centre and the current cell 
        //with the index cellI
        scalar offset = magSqr(centre_ - ctrs[cellI]);
        if (offset <= radSquared)
        {
            //Do something, e.g. store the current cell id in a list
        }
    }
May be you have to think a little bit about the loops and how to define the centre point for your spheres. If you want to have a sphere around each cell, than I guess with the code above you have to add a second loop about all cells around it. However, this should be feasible. Finally, if you stored the list of cell ids for each sphere you can work with it and calculate values, averages or whatever. This is some programming effort.

Best regards
Fabian
fs82 is offline   Reply With Quote

Old   March 17, 2016, 11:16
Default
  #48
New Member
 
Robert R.
Join Date: Feb 2016
Location: Braunschweig, Germany
Posts: 7
Rep Power: 10
chefkoch89 is on a distinguished road
This sounds great and I think that's the right way to get what I need. My problem is that I don't know how to use sphereToCell. I always find the usage within the preprocessor "setFields".

Thank's for the response.
chefkoch89 is offline   Reply With Quote

Old   March 17, 2016, 11:36
Default
  #49
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
My suggestion was NOT to use sphereToCell. You have to write your own utility and copy the parts of the code of sphereThoCell which helps you to solve your problem. May be it is possible to use a utility or a function of swak4Foam to yield the same result, but I do not know that at the moment.
fs82 is offline   Reply With Quote

Old   April 7, 2016, 09:36
Default
  #50
New Member
 
sina
Join Date: Jul 2013
Posts: 21
Rep Power: 13
aghsin is on a distinguished road
Quote:
Originally Posted by su_junwei View Post
Hi Khaled

mesh.cellCells()[cellI] gives the neighbours of cell cellI

su junwei
Hi,
How can I use the above command in openFOAM? I mean where must I write this function?
aghsin is offline   Reply With Quote

Old   June 13, 2017, 12:00
Default
  #51
Member
 
Mahdi
Join Date: Jul 2012
Posts: 53
Rep Power: 14
Mahdi2010 is on a distinguished road
I read many threads, but I have a question which can be related to this thread:

Is it possible to access each cell neighbor and assign the value of every 2 cells to an temporary cell list?
Let's imagine we have a 64x64 structured 2D domain. I want to take every two cells in X-direction and Y-direction,
and make a 32x32 imaginary domain with the cell center values coming from surrounding cells.

It is like to hold a magnifier in hand, and zoom out what we see!. Then the cell center values in the 32x32 imaginary
domain can be calculated as average of the every 4 cell center (it is just a temporary list not really a mesh).
Mahdi2010 is offline   Reply With Quote

Old   June 15, 2017, 07:39
Default
  #52
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
I do not have a solution for your problem, but I would like to add a comment and an idea

You have to have in mind that OpenFOAM uses an unstructured mesh which could consist of tetrahedra, hexahedra or whatever. Furthermore, the mesh in OpenFOAM is face based, which means every face knows about the cells which it belongs to. To conclude, this means you can get a list of all cells, you also can get a list of faces that belong to a certain cell and with this it is possible to get the neighbouring cell for each face. But than you get stuck, because the mesh is unstructured band you do not know which direction you have to move on. Everything you can do is a very costly search, checking the distanced and so on. What you are describing is very easy on structured meshes, especially on equidistant meshes. However, OpenFOAM is built for unstructured meshes and, hence, you are somewhat limited.

But there is the possibility to map between meshes with "mapFields". To create a coarse mesh with blockMesh is quite simple. Furthermore, there are various tools available to manipulate the mesh, e.g., refineMesh. May be this helps to solve your problem.

Best regards
Fabian
fs82 is offline   Reply With Quote

Old   June 15, 2017, 08:46
Default
  #53
Member
 
Mahdi
Join Date: Jul 2012
Posts: 53
Rep Power: 14
Mahdi2010 is on a distinguished road
Quote:
Originally Posted by fs82 View Post
I do not have a solution for your problem, but I would like to add a comment and an idea

You have to have in mind that OpenFOAM uses an unstructured mesh which could consist of tetrahedra, hexahedra or whatever. Furthermore, the mesh in OpenFOAM is face based, which means every face knows about the cells which it belongs to. To conclude, this means you can get a list of all cells, you also can get a list of faces that belong to a certain cell and with this it is possible to get the neighbouring cell for each face. But than you get stuck, because the mesh is unstructured band you do not know which direction you have to move on. Everything you can do is a very costly search, checking the distanced and so on. What you are describing is very easy on structured meshes, especially on equidistant meshes. However, OpenFOAM is built for unstructured meshes and, hence, you are somewhat limited.

But there is the possibility to map between meshes with "mapFields". To create a coarse mesh with blockMesh is quite simple. Furthermore, there are various tools available to manipulate the mesh, e.g., refineMesh. May be this helps to solve your problem.

Best regards
Fabian

Thanks for your contribution to this discussion, I understand your point as I also spent much time on that. Unlike the equidistant structured grids that we can create with any kind of programming tool, OpenFOAM has this limitation.

Regarding the other ideas like mapping, I think this is not also possible, because I would need this so-called imaginary "coarse grid" during the simulation in every time step. In other words, it is going to act as an intermediate container list storing average of every 4 cells in the intersecting vertex. Then it will be deleted/updated in the next time step. Therefore, this is something completely independent of the mesh, while I assume mapping is something in pre-proceesing phase. What do you think?
Mahdi2010 is offline   Reply With Quote

Old   June 16, 2017, 03:41
Default
  #54
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
A possible idea could be, in the case you do not use a moving mesh or mesh refinement, to do before starting the simulation a search run and store the relationships between your simulation mesh and the coarse mesh. You can use the pointInCell and findCell functions of polymesh to check if a cell center is located within a certain range of another one. However, I tried this once and it is really a slow process. So you will not be able to do it every time step. Another idea would be to have a second coarse mesh during runtime and instead of averaging do an interpolation?

Best regards
Fabian
fs82 is offline   Reply With Quote

Old   June 16, 2017, 04:15
Default
  #55
Member
 
Mahdi
Join Date: Jul 2012
Posts: 53
Rep Power: 14
Mahdi2010 is on a distinguished road
Quote:
Originally Posted by fs82 View Post
A possible idea could be, in the case you do not use a moving mesh or mesh refinement, to do before starting the simulation a search run and store the relationships between your simulation mesh and the coarse mesh. You can use the pointInCell and findCell functions of polymesh to check if a cell center is located within a certain range of another one. However, I tried this once and it is really a slow process. So you will not be able to do it every time step. Another idea would be to have a second coarse mesh during runtime and instead of averaging do an interpolation?

Best regards
Fabian

Your first suggestion is something very demanding as you said because, in the case of having a fine grid, it would take too long for even one step. But I am interested in the second idea. You mean having both grids on the simulation, but using "fine" for the simulation and "coarse" for just interpolation of values?Is this doable in OpenFOAM?


This is actually what I wanted to to do from the beginning, but I assumed only one mesh can be imported to the OpenFOAM not two. In addition, I also tried to have two meshes connected at one patch, but this would also result in other issues like BC for the intersection! Perhaps I have gone too far and there is an easier way to proceed with this interpolation idea you also suggested. Could you please tell me if any of OF tutorials does this?Or in any post on this forum has been already discussed?
Mahdi2010 is offline   Reply With Quote

Old   June 16, 2017, 12:12
Default overset grid
  #56
New Member
 
sina
Join Date: Jul 2013
Posts: 21
Rep Power: 13
aghsin is on a distinguished road
Quote:
Originally Posted by Mahdi2010 View Post
Your first suggestion is something very demanding as you said because, in the case of having a fine grid, it would take too long for even one step. But I am interested in the second idea. You mean having both grids on the simulation, but using "fine" for the simulation and "coarse" for just interpolation of values?Is this doable in OpenFOAM?


This is actually what I wanted to to do from the beginning, but I assumed only one mesh can be imported to the OpenFOAM not two. In addition, I also tried to have two meshes connected at one patch, but this would also result in other issues like BC for the intersection! Perhaps I have gone too far and there is an easier way to proceed with this interpolation idea you also suggested. Could you please tell me if any of OF tutorials does this?Or in any post on this forum has been already discussed?
Hi have you already knew about overset grid? it might be a solution for you.
aghsin is offline   Reply With Quote

Old   June 17, 2017, 04:40
Default
  #57
Member
 
Mahdi
Join Date: Jul 2012
Posts: 53
Rep Power: 14
Mahdi2010 is on a distinguished road
Quote:
Originally Posted by aghsin View Post
Hi have you already knew about overset grid? it might be a solution for you.

I have actually heard about overset (not touched though), but as far as I know, this is something for complicated geometries for that a normal uniform meshing is not practical. The domain can use this feature to make a connection between the different type of meshes to cover the whole geometry. Therefore, in overset all the grids are really involved in the solution.

But what I am looking for is much simpler (in concept): The coarser grid is going to be used only as the container of (the averaged values of) what is computed over the finer grid at each time step. So, no involvement in the simulation from the coarse grid is needed.

Have you seen something similar before?
Mahdi2010 is offline   Reply With Quote

Old   June 19, 2017, 03:46
Default
  #58
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
I think what you are aiming at is often named as chimera grids. I never used it but I have seen a couple of presentations at the OpenFOAM User Conference. I think the mapping between the grids is the most important issue. As far as I know people use external library for mapping, but I am not sure as I never used it, e.g., SUGGAR++ (http://celeritassimtech.com/?page_id=21).

Best regards
Fabian
fs82 is offline   Reply With Quote

Old   June 19, 2017, 04:22
Default
  #59
New Member
 
sina
Join Date: Jul 2013
Posts: 21
Rep Power: 13
aghsin is on a distinguished road
Quote:
Originally Posted by Mahdi2010 View Post
I have actually heard about overset (not touched though), but as far as I know, this is something for complicated geometries for that a normal uniform meshing is not practical. The domain can use this feature to make a connection between the different type of meshes to cover the whole geometry. Therefore, in overset all the grids are really involved in the solution.

But what I am looking for is much simpler (in concept): The coarser grid is going to be used only as the container of (the averaged values of) what is computed over the finer grid at each time step. So, no involvement in the simulation from the coarse grid is needed.

Have you seen something similar before?
Sorry, I have not seen similar thing.
aghsin is offline   Reply With Quote

Old   November 20, 2017, 01:40
Default
  #60
Member
 
Vishwesh Ravi Shrimali
Join Date: Aug 2017
Posts: 43
Rep Power: 9
vishwesh is on a distinguished road
Hi!

My problem can also get some help from sphereToCell. I have written a solver which can identify the centre and the radius of the sphere. I want to get all the cells inside that sphere and modify their alpha values. My question is can I directly use the combine function given in sphereToCell.C by putting sphereToCell.C, and other relevant files in the same folder, adding them to Make/files file, including them in the main solver and using the function combine?

Thanks

Vishwesh

Quote:
Originally Posted by fs82 View Post
I think the solution is already included in sphereToCell.C in the function combine:
Code:
//This gets all cell centres of all mesh cells
const pointField& ctrs = mesh_.cellCentres();

    //This calculates the radius of your sphere
    const scalar radSquared = radius_*radius_;

    //Loop over all cells
    forAll(ctrs, cellI)
    {
        //calculates the distance between the cell centre and the current cell 
        //with the index cellI
        scalar offset = magSqr(centre_ - ctrs[cellI]);
        if (offset <= radSquared)
        {
            //Do something, e.g. store the current cell id in a list
        }
    }
May be you have to think a little bit about the loops and how to define the centre point for your spheres. If you want to have a sphere around each cell, than I guess with the code above you have to add a second loop about all cells around it. However, this should be feasible. Finally, if you stored the list of cell ids for each sphere you can work with it and calculate values, averages or whatever. This is some programming effort.

Best regards
Fabian
vishwesh 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
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 19:57
Determining cell neighbours on unstructured grid orxan.shibli Main CFD Forum 4 September 25, 2011 06:29
Help Me, what's the Cell Above any given cell in 3D. gomane8 Main CFD Forum 3 September 11, 2011 22:29
neighbours of a cell Asghari FLUENT 17 October 7, 2010 18:41
neighbours of a cell Asghari FLUENT 0 July 9, 2006 14:28


All times are GMT -4. The time now is 12:00.