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

Search adjacent cells and assign

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 31, 2020, 04:49
Default Search adjacent cells and assign
  #1
New Member
 
Join Date: Mar 2020
Posts: 23
Rep Power: 6
loving_cfd is on a distinguished road
Hello, my dears.

I want to loop over all the cell in the computational domain, search the four or eight neighbor cells and assign at each timestep.

It can be implemented in Fluent via the macros of c_face_loop and C_F0.

How about on OpenFOAM?
loving_cfd is offline   Reply With Quote

Old   March 31, 2020, 13:06
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
Neighbour cells can be accessed via cellCells(). So off the top of my head it would be something like :

Code:
forAll(mesh.C(), celli) //outer, all cell loop
{
    label curCell = mesh.C()[celli];

    labelList curNeiCells = mesh.cellCells()[curCell];

    forAll(curNeiCells, cellj) //inner, neighbor cell loop
    {
         do something here...
    }
}
There might be a more elegant way to do it, but looping is pretty straightforward. Of course, the first loop doesn't have to be all cells if you already have a list of cells in mind.

Caelan
clapointe is offline   Reply With Quote

Old   April 14, 2020, 05:21
Default reply to Caelan
  #3
New Member
 
Join Date: Mar 2020
Posts: 23
Rep Power: 6
loving_cfd is on a distinguished road
Dear Caelan,

Appreciate for your relpy!

Your reply help me learn more on OpenFOAM.

I will try the method on my program and share the result with you.

Best wishes!
loving_cfd is offline   Reply With Quote

Reply

Tags
cell, openfoam, programming


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
mass source term to boundary cells adjacent to a wall Kimia Fluent UDF and Scheme Programming 7 November 15, 2020 11:53
decomposePar: how to distribute cells unevenly? floquation OpenFOAM Pre-Processing 4 February 25, 2017 05:15
How to assign different values for every cells in a part of the domain clktp OpenFOAM Pre-Processing 0 April 1, 2016 12:45
assign values to selected cells zxj160 OpenFOAM Pre-Processing 4 June 29, 2012 13:17
How to Reference an Adjacent Cell in a UDF ? jeff8541 FLUENT 0 March 8, 2011 11:33


All times are GMT -4. The time now is 19:05.