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

Cells loop

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 31, 2011, 09:09
Default Cells loop
  #1
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 17
Andrea_85 is on a distinguished road
Hi,
I need to perform a "special" loop over all the cells. For a given cell i need to know the value of a variable in the nearby cells (those cells that share one face with the given cell) and then replace the value of this variable in the given cell with an average through the cell and the neighboring cells. The best thing would be to have a 9x9 stencil around each cell, but to start is enough for me to have the value of this variable in the NORTH, SOUTH, EAST, WEST cells.

For example if the variable is the pressure P, i would like to do something like this:

p[cellI] = (p[cellI]+ p[cell_NORD] + p[cell_SOUTH] +p[cell_EAST] + p[cell_WEST])/5

Now, i know that using mesh.cellCell()[cellI] you can access the neighboring cells of the given cellI.
Unfortunatly my c++ skills are not so good, so i do not know how to loop over the indices of neighbors. Any help is appreciated!

and also if someone have an idea to incude easily also the diagonal cells in this sum (NE, SE, SW, NW). (of course using an orthogonal mesh)

Thanks

andrea
Andrea_85 is offline   Reply With Quote

Old   May 31, 2011, 09:38
Default
  #2
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
Hi Andrea

Try e.g. this, it has, however, not been test compiled.

Code:
volScalarField pnew("pnew", p);

const labelListList & cellCells = mesh.cellCells();

forAll( cellCells, celli )
{
    ccs = cellCells[celli];

    forAll(ccs, ci )
    {
          pnew += p[ccs[ci]];
    }

    pnew[celli] /= (ccs.size() + 1.0);
}
Best regards,

Niels
ngj is offline   Reply With Quote

Old   May 31, 2011, 11:47
Default
  #3
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 17
Andrea_85 is on a distinguished road
Hi Niels,
thanks for reply. I did it a little different but it works. something like that:
Code:
scalarField pAdj(mesh.nCells(),scalar(0));
 volScalarField pnew("pnew", p);
       scalar n = 3;


       for(int iter = 0; iter<n; iter++)
       {
        forAll(mesh.cells(),cellI)
        {
          labelList adjacent = mesh.cellCells()[cellI];
          int size = adjacent.size();


           for(int j=0; j<size; j++)
           {
              pAdj[cellI] += p[adjacent[j]];
           }

           pnew[cellI] +=  pAdj[cellI];
            pnew[cellI] /= size+1;
           }
        }
now have you got any idea how to construct a 3x3 stencil(I have mistyped in the last post) around a given cell (only 6 cells around a cell on boundary). Maybe using the neighbors of neighbors? this is not a 3x3 stencil but is not a big problem, the problem is that some cells are taken several times. Hope it is clear!!

Thanks again

andrea
Andrea_85 is offline   Reply With Quote

Old   June 1, 2011, 05:23
Default
  #4
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 17
Andrea_85 is on a distinguished road
Hi,

is there a way, given a certain list, to add other labels? Something like addToList.
If yes, what is the syntax? (Suppose you have two lists, and wanting to put the values ​​of the list 2 into the list 1).

Thanks

andrea
Andrea_85 is offline   Reply With Quote

Old   October 3, 2012, 21:01
Default Values at east and north cell
  #5
Member
 
,...
Join Date: Apr 2011
Posts: 92
Rep Power: 14
hawkeye321 is an unknown quantity at this point
Hi FOAMERS
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   May 5, 2014, 00:47
Default
  #6
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
mahdiiowa, did you ever figure out how to reference specific cells?
CHARLES 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
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 06:50
[snappyHexMesh] snappyHexMesh won't work - zeros everywhere! sc298 OpenFOAM Meshing & Mesh Conversion 2 March 27, 2011 22:11
[snappyHexMesh] snappyHexMesh aborting Tobi OpenFOAM Meshing & Mesh Conversion 0 November 10, 2010 04:23
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 16:57
physical boundary error!! kris Siemens 2 August 3, 2005 01:32


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