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

loop through structured mesh by i,j,k

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 20, 2010, 12:27
Default loop through structured mesh by i,j,k
  #1
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
Hello all,

I know I can loop through all cells of a mesh using forAll(mesh.cells(),celli). However, this won't tell me anything about the geometric location of the neighbors. I'd like to only use the neighbors on a certain axis for my further calculations. Does anyone have an idea?

In pseudo code, in 2D:
Code:
for (i =0; i < mesh.max_i; i++)
     for (j =0; j < mesh.max_j; i++)
           // calculation involving mesh.cell[j-1], mesh.cell[j], mesh.cell[j+1]
akidess is offline   Reply With Quote

Old   July 20, 2010, 13:41
Default
  #2
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
I suppose you could look at cell-faces, take the dot-product of the unit face-normal with the axis-direction that you want, and check its magnitude. You can then choose the owner/neighbour of those faces to get the adjacent cell.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   July 21, 2010, 06:01
Default
  #3
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
Thanks, that got me started! Now I'm facing a weird problem though: Every now and then, instead of a sensible neighbour cellID, I get something way off, eg.

Code:
inner circle, celli: 932
neigh: 962 //makes sense
inner circle, celli: 932
neigh: 1751339886 //can't be, grid only has like 1200 cells, using it to access a field naturally leads to a seg fault
Any Idea why that would be happening and how to avoid it?

Code:
vector axis(0, 1, 0);

    forAll( mesh.C(), celli)
    {
            // Neighbour and owner cells to given face
            const unallocLabelList & nei = mesh.neighbour();
            const unallocLabelList & own = mesh.owner();

            // This is a list of faces of which the cell is build
            const cell& cProp = mesh.cells()[celli];

            // Loop over all faces
            forAll(cProp, facei)
            {
                label owner = own[cProp[facei]];
                label neigh = nei[cProp[facei]];

                //find faces in y-direction
                if (mag(mesh.Sf()[facei] & axis) > 0)
                {
                     Info << "celli: " << celli << endl;
                     if (owner == celli) {
                         Info << "neigh: " << neigh << endl;   
                     } else { // neigh == celli
                         Info << "owner: " << owner << endl;
                     }
                }
            }
    }
akidess is offline   Reply With Quote

Old   July 21, 2010, 06:10
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
That would occur, if you are requesting a neighbour for a boundary face. You should make a conditional like

Code:
if (cProp[facei] < own.size())
{
    // Can ask for both owner and neighbour
}
else
{
    // Only owner exists
}
Cheers,

Niels
ngj is offline   Reply With Quote

Old   July 21, 2010, 06:27
Default
  #5
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
So my guess is that the large number are boundary cells and could be just filtered out by comparing with mesh.size() [edit: Sorry Niels, didn't see your post while writing this one]. However, I now noticed that I'm not seeing two neighbors as expected on a 2D mesh, but three! Whats going on? Here is an image of cellIDs I got out of paraview.



Looking at cell 31, I want to get 1 and 61 as output. Instead I'm getting:
celli: 31
neigh: 61
owner: 31

celli: 31
owner: 31
neigh: NULL

celli: 31
neigh: 31
owner: 30

Why is there an inner face, and why am I getting the left neighbor instead of the lower one?
akidess is offline   Reply With Quote

Reply

Tags
cells, index, loop, mesh, neighbor


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
[ICEM] Generating Mesh for STL Car in Windtunnel Simulation tommymoose ANSYS Meshing & Geometry 48 April 15, 2013 05:24
Exporting structured mesh from ICEMCFD to Fluent? jeevan kumar FLUENT 1 January 23, 2012 12:21
[ICEM] Unstructure Meshing Around Imported Plot3D Structured Mesh ICEM kawamatt2 ANSYS Meshing & Geometry 17 December 20, 2011 12:45
need reference for structured mesh generation cfduser03 Main CFD Forum 3 September 7, 2009 10:58
Structured mesh of a 3d sharp trailing edge Gilles Main CFD Forum 2 May 23, 2008 14:23


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