CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

neighbours of a cell

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 9, 2006, 13:29
Default neighbours of a cell
  #1
Asghari
Guest
 
Posts: n/a
Hi all;

How can i access to all of the neighbours of a specified cell ,for instance, using udf's ? ,please help me.

Best Regards.

Mehdi Asghari

  Reply With Quote

Old   July 9, 2006, 17:23
Default Re: neighbours of a cell
  #2
jasond
Guest
 
Posts: n/a
Well, the way that I have done it is to loop over the faces and use the face's cells to get at the neighbors. There may be a better way to do it - if anyone knows of one that isn't as bad as the code below, please let me know. I wrote this after I just gave up on finding a better way. Here is my UDF code to get across the face given a face number n (sorry about the formatting):

int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n)

{

face_t f;

Thread *tf;

f = C_FACE(c,t,n);

tf = C_FACE_THREAD(c,t,n);

if (!BOUNDARY_FACE_THREAD_P(tf))

{

(*cn) = F_C0(f,tf);

if((*cn) == c)

{

(*cn) = F_C1(f,tf);

(*tn) = F_C1_THREAD(f,tf);

}

else

{

(*tn) = F_C0_THREAD(f,tf);

}

return 1;

}

return 0; }
  Reply With Quote

Old   July 11, 2006, 12:18
Default Re: neighbours of a cell
  #3
Asghari
Guest
 
Posts: n/a
Thank you,

Ok,But how do you attach(hook) this Subroutine (macro) to Fluent software, please lead me?

Thank a lot.

  Reply With Quote

Old   July 11, 2006, 13:01
Default Re: neighbours of a cell
  #4
jasond
Guest
 
Posts: n/a
The answer to that really depends on what you are trying to do, and without that info I can't really give you much advice. If you can give me an idea of that, then I may be able to help you.

Jason
  Reply With Quote

Old   July 12, 2006, 01:48
Default Re: neighbours of a cell
  #5
Asghari
Guest
 
Posts: n/a
Ok, i try to ask my question precisely .Suppose i want to write a macro like c_face_loop for looping over neighbouring celles on a specified cell . How can i produce a macro as c_face_loop and define it for fluent(for example define it in define_adjust)?

I am thankful to you.

  Reply With Quote

Old   July 12, 2006, 09:44
Default Re: neighbours of a cell
  #6
jasond
Guest
 
Posts: n/a
Well, I'm still not sure I understand you, but I have attached below a function (that I mainly got from the Fluent UDF docs) that uses the neighborcell routine. If you are going to use this in a DEFINE_ADJUST situation, I guess you'll loop over all cells or something. Now, I haven't had time to test this (Fluent is running right now) and I am not sure if the cut-and-paste was totally successful, but this is the general idea. If the face itself is required, then you can move that part out into the loop.


DEFINE_ADJUST(my_adjust,d)
{
cell_t c,neighbor;
Thread *t,*neighborthread;
int n;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
c_face_loop(c, t, n)
{
if(neighborcell(c,t,&neighbor,&neighborthread,n))
{
/* Do stuff */
}
}
end_c_loop(c,t)
}
}
  Reply With Quote

Old   July 12, 2006, 12:56
Default Re: neighbours of a cell
  #7
Asghari
Guest
 
Posts: n/a
Thank you very much.

But i want to loop on all of cells connected to each nodes (not only faces) where construct referance cell. Can you help me?

  Reply With Quote

Old   July 12, 2006, 14:02
Default Re: neighbours of a cell
  #8
jasond
Guest
 
Posts: n/a
That is a bit harder, as I am pretty sure that sort of information is not stored (even implicitly like cell neighbor information). I have done it, but the details of the programming depend upon what exactly you are trying to do. I precomputed it before my calculations (loop over all cells, check to see if a cell shares any nodes with the cell of interest, and save a list of the ones that do). It is not very elegant, but if done only once there is little penalty. It can also be done on the fly during calculations, but that is not so easy, and without knowing a lot more about what you are doing I can't really help you (well, I could give you an opinion, but that is not all that helpful).

Jason
  Reply With Quote

Old   July 13, 2006, 00:39
Default Re: neighbours of a cell
  #9
Asghari
Guest
 
Posts: n/a
Ok,I am working on two phase flow simulation with condensation and evaporation(liquid-gas) . For discovering phase change in a cell, i need to search(loop) on neighboring cells(with same define in previous message) . IF (T < saturation temperature ) and (all of the T_neighbors >saturation temperature )phase change has take placed ,therefor mentioned cell is an interface cell.

Do you have better idea for this case?
  Reply With Quote

Old   July 13, 2006, 11:57
Default Re: neighbours of a cell
  #10
jasond
Guest
 
Posts: n/a
I have a couple separate observations:

1) I'm not sure that your expanded definition of cell neighbors is required - Fluent is a cell-centered code, so the communication between two cells with a common node is strongest if they share a face (I'm glossing over some details here). Shouldn't it be enough that the cell has (face) neighbors that satisfy you temperature condition? I would think that it should be, but you would probably know better than I would about that.

2) It sounds like you'll be needing to check a lot of cells for this condition. For your definition of cell neighbors, precomputation is the way I would go. The easiest thing to do would be just to build a list of neighbors for each cell. This should be feasible as long as the grid is not too large. If you do have a large grid, then if you don't need to check the entire grid you can generate the data for a subset of the grid only. If you can use the stricter definition of cell neighbors, then I would use a loop setup similar to that in my previous message.

To summarize: if I were you, I would try to use the stricter definition of cell neighbors, but failing that I would precompute as much as possible.

Jason
  Reply With Quote

Old   July 14, 2006, 00:56
Default Re: neighbours of a cell
  #11
Asghari
Guest
 
Posts: n/a
I have two questions from you.

1-Why if i have a large grid , it is'nt logical to use precomputation? for example , if i use 2d mesh, according to my definition from neighboring cell ,number of cell neighbors for each cell is twice of cell neighbors according to stricter definition of cell neighbors, and ,number of calculations in each time step , is twice and in any iteration i need only to calculate twice.Is it right?

2-How can i precompute and build a list of neighbors for each cell? Please lead me .
  Reply With Quote

Old   July 14, 2006, 13:19
Default Re: neighbours of a cell
  #12
jasond
Guest
 
Posts: n/a
My answers:

1) It is still logical to use precomputation if you have a large grid (by large I mean a large number of cells), but the larger neighborhood definition will double the neighbor count only for 2D quads in a structured arrangement. If you use triangles, it is potentially much worse, and in 3D it could be much, much worse. Even for hexes, we're talking 26 neighbors instead of 6 (if I've counted right). Some of this depends on grid quality and the like, but the storage required could get unpleasant.

2) The easy solution is to loop over the nodes of each cell, and for each node loop over all the cells and check to see which cells share that node. This isn't a very elegant solution, but will work. Storage is easy if you know the number of neighbors that each cell has beforehand (an array with dimensions "# of cells" x "# of neighbors per cell").
  Reply With Quote

Old   July 15, 2006, 11:27
Default Re: neighbours of a cell
  #13
Asghari
Guest
 
Posts: n/a
Ok,I satisfied to use from neighboring cells according to your definition from neighboring cells based on faces (not nodes).

Only i have a question from you.

In one of your messages , you introduce your routine as following.

1-int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n)

But,in another message you presented this routine in following format :

2-if(neighborcell(c,t,&neighbor,&neighborthread,n)).

Why did you use from two different format in arguments for example in #1:

*t

and in #2:

&neighbor (diference is observed in this operands:& and *) ?

  Reply With Quote

Old   July 15, 2006, 15:33
Default Re: neighbours of a cell
  #14
jasond
Guest
 
Posts: n/a
Well... unless I'm missing something, that is more of a basic C programming question. In the definition of neighborcell (your #1), the argument "cell_t *cn" is a cell_t pointer because I want the routine to store the neighbor cell in a specified location. So when I call it (your #2) I have to provide the address of the variable (in this case the address of the variable "cell_t neighbor", which is "&neighbor"). The same thing holds for "Thread ** neighborthread." If you don't know what I'm talking about, you'll need to get ahold of a C programming book. Does that answer your question?

Jason
  Reply With Quote

Old   July 16, 2006, 12:22
Default Re: neighbours of a cell
  #15
Asghari
Guest
 
Posts: n/a
I see,Thank you.

If it is'nt for you trouble, please answer to two my question's.

1-can i use from neighbor variable directly after following line without using & (pointer oprand)?

if(neighborcell(c,t,&neighbor,&neighborthread,n))

2-;If your answer to question 1 would be yes ;Assume i want to access to the neighbor temperature using C_T macro (cell temperature) . My question from you is this: Which format is true? C_T(neighbor,neighborthread) or C_T(neighbor,t).
  Reply With Quote

Old   July 17, 2006, 11:37
Default Re: neighbours of a cell
  #16
jasond
Guest
 
Posts: n/a
Answers:

1) Yes. We passed the address of neighbor and neighborthread to the function and stored what we needed at the specified location. Incidentally, "&" in this case is usually called the address-of operator.

2) Maybe both, but I don't think it is a good idea to use C_T(neighbor,t). If neighbor and c are stored in the same thread, then it will work, but I'm not sure that there is any way of knowing that they will be. I've been told that the safest thing is to assume that they are not and use C_T(neighbor,neighborthread).

Since this message thread is already pretty long, are there any other questions I can help you with?

Jason

  Reply With Quote

Old   July 19, 2006, 10:22
Default Re: neighbours of a cell
  #17
Asghari
Guest
 
Posts: n/a
Thank you very much;

In the hope of next meeting with you .
  Reply With Quote

Old   October 7, 2010, 17:41
Default
  #18
Member
 
CJ
Join Date: Jun 2009
Posts: 34
Rep Power: 17
solefire is on a distinguished road
Dear,

I have a question, probably it is very easy for u, if I have got a cell ID , source[0], I want to get the flux of faces of this cell, "just for this cell" , it is structured grid, could u help check what is wrong with my code, Thanks a lot!!


DEFINE_ON_DEMAND(get_mf)
{
Domain *d; /*pointer to the collection of all cells' threads (stored information) */
/* declare domain pointer since it is not passed as an argument to the DEFINE macro */
cell_t c; /* cell identifier */
Thread *t; /* pointer to a thread */
d = Get_Domain(1); /*domain is already available to your function (via define_adjust argument). */
mf=0.0;
int i=0.0;

/************try to get neighbouring faces of the cell********************************************** ***/

/* If face lies at domain boundary, use face values; */
/* If face lies IN the domain, use average of adjacent cells. */



c_face_loop(c, t, i)

{
face_t f;
Thread *tf;
f = C_FACE(c,t,i);
tf = C_FACE_THREAD(c,t,i);
c0 = F_C0(f,tf);
c1 = F_C1(f,tf);
t0 = THREAD_T0(tf);
t1 = THREAD_T1(tf);
real NV_VEC(psi_vec), NV_VEC(A), flux = 0.0;
F_AREA(A, f, t);


if (!BOUNDARY_FACE_THREAD_P(tf))
{
/* c0 is current cell*/
if (c0 == source[0])
{

NV_DS(psi_vec, =, C_U(c,t),C_V(c,t),C_W(c,t),*,1.0);
NV_DS(psi_vec, +=, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,1.0);
flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */

}
else
{

NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,1.0);
NV_DS(psi_vec, +=, C_U(c,t),C_V(c,t),C_W(c,t),*,1.0);
flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */

}
}
}


}

hereby density is 1.0;
solefire is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Determining cell neighbours on unstructured grid orxan.shibli Main CFD Forum 4 September 25, 2011 05:29
cell neighbours manuutin STAR-CD 1 August 17, 2010 20:29
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 21:58
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 04:15
Warning 097- AB Siemens 6 November 15, 2004 04:41


All times are GMT -4. The time now is 21:31.