# Cells loop

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 May 31, 2011, 08:09 Cells loop #1 Senior Member   Andrea Ferrari Join Date: Dec 2010 Posts: 312 Rep Power: 9 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

 May 31, 2011, 08:38 #2 Senior Member   Niels Gjoel Jacobsen Join Date: Mar 2009 Location: Deltares, Delft, The Netherlands Posts: 1,754 Rep Power: 29 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

 May 31, 2011, 10:47 #3 Senior Member   Andrea Ferrari Join Date: Dec 2010 Posts: 312 Rep Power: 9 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

 June 1, 2011, 04:23 #4 Senior Member   Andrea Ferrari Join Date: Dec 2010 Posts: 312 Rep Power: 9 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

 October 3, 2012, 20:01 Values at east and north cell #5 Member   ,... Join Date: Apr 2011 Posts: 92 Rep Power: 7 Hi FOAMERS Is there any way (any function) to get the value of a parameter at the east and north of a specific cell?

 May 4, 2014, 23:47 #6 Member   CHARLES Join Date: May 2013 Posts: 46 Rep Power: 6 mahdiiowa, did you ever figure out how to reference specific cells?

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post hsieh Open Source Meshers: Gmsh, Netgen, CGNS, ... 32 September 13, 2011 05:50 sc298 OpenFOAM Native Meshers: snappyHexMesh and Others 2 March 27, 2011 21:11 Tobi OpenFOAM Native Meshers: snappyHexMesh and Others 0 November 10, 2010 04:23 Franny Main CFD Forum 13 July 7, 2007 15:57 kris Siemens 2 August 3, 2005 00:32

All times are GMT -4. The time now is 10:25.

 Contact Us - CFD Online - Privacy Statement - Top