Loop over the faces of a cell in UDF

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

 October 15, 2001, 11:57 Loop over the faces of a cell in UDF #1 Anthony Wachs Guest   Posts: n/a Hi everybody, Does someone know how to do a loop over the faces of a cell in an UDF ? or what is the macro to name the face of a given cell ? I have found the instruction "C_FACE(cell,thread,i)" where I suppose that "i" corresponds to face number i of the cell. Therefore, I tried a thing like : for (i=0;i less C_NFACES(cell,thread);i++) { f0=C_FACE(cell,thread,i); ... } (I write "less" otherwise errors occurs in the text, but in the C source, I obviously used the sign, thus don't mind about that, the problem is not here!!) but it doesn't seem to work. Any help would be really appreciated. Thanks in advance Anthony

 October 15, 2001, 15:06 Re: Loop over the faces of a cell in UDF #2 ravi Guest   Posts: n/a The integer variables C_NNODES and C_NFACES return the number of nodes or faces, respectively, for a given cell. The integer variable F_NNODES returns the number of nodes associated with a face. So this is not the appropriate macro for looping over faces in a cell. Use : begin_f_loop(f,t) end_f_loop(f,t) ---> which loops over faces in a face thread.

 October 16, 2001, 03:04 Re: Loop over the faces of a cell in UDF #3 Anthony Wachs Guest   Posts: n/a Hi Ravi, Thank you for your contribution. Unfortunetaly, your answer does not correspond to what I would like to do. I know very well the command : begin_f_loop(f,t) end_f_loop(f,t), which as you mentioned as well, is useful for a loop over faces in a FACE THREAD. But I am concerned with loop over faces of a CELL, not of a thread : this is completely different. I have been using "begin_f_loop(f,t) end_f_loop(f,t)" efficiently for a long time in simpler situations, when I would like to do a loop over faces of a face thread. If you have any other suggestion concerning how to write a "LOOP OVER FACES OF A CELL", thank you in advance Anthony

 October 16, 2001, 05:58 Re: Loop over the faces of a cell in UDF #4 Greg Perkins Guest   Posts: n/a Ok here's how to do it: int numbf; cell_t cf; Thread *tf,*f_thread; face_t face; /* cf,tf is cell & cell thread */ c_face_loop(cf,tf,numbf) { face = C_FACE(cf,tf,numbf); f_thread = C_FACE_THREAD(cf,tf,numbf); /* do what you like with face numbf with face & f_thread */ /* -- eg temp = F_T(face,thread); */ } Greg

 October 16, 2001, 10:55 Re: Loop over the faces of a cell in UDF #5 Anthony Wachs Guest   Posts: n/a Thanks Greg !! Anthony

September 20, 2015, 07:22
#6
Member

Eduardo Tola
Join Date: Aug 2015
Posts: 50
Rep Power: 2
Quote:
 Originally Posted by Greg Perkins ;98638 Ok here's how to do it: int numbf; cell_t cf; Thread *tf,*f_thread; face_t face; /* cf,tf is cell & cell thread */ c_face_loop(cf,tf,numbf) { face = C_FACE(cf,tf,numbf); f_thread = C_FACE_THREAD(cf,tf,numbf); /* do what you like with face numbf with face & f_thread */ /* -- eg temp = F_T(face,thread); */ } Greg
Hello, to all and thank you for this post because it is exacly what I was looking for:

However, I am struggling to implement the code written here.

I am trying to implement a code able to calculate the mass flow in different planes created by the user, not boundaries.

My idea is integrate through a volumen and then divide for the width of the volumen. The code is created in a way that if the cell is located in the section then a loop through all the faces wants to be done.
Because the mass flow importance for this problem is only the one in the direction Z, I calculate the normal vector of the face an multiply the Z component by the mass flow, for each face.
I am having problems because I need to initialize two times the variables, for the first bucle and for the second bucle.
I would really appreciate to get some help in this problem.
Attached can be found the code.

Code:
```#include "udf.h"
#include <math.h>
#define Num_div 5

{
face_t f;
cell_t c;

int n=0;
int max_div=0;
int numbf;
real division=0;        // Width of the division
real kk0=0;                // Minimum variable for each Division
real kk1=0;                // Maximum variable for each Division
real x[ND_ND];
real NormalVector[ND_ND];
real Area;
real SUMflow=0.;

division=0.09/Num_div;                                // Calculating the division
max_div=Num_div+1;

for (n = 1; n < max_div; ++n)
{
/////////////////////////////////////////////////////////////////////////////
kk0=(n-1)*division+0.01;                            // Minimum variable for each Division
kk1=n*division+0.01;                                // Maximum variable for each Division
SUMflow=0;

thread_loop_c(t, d)                                            // Variable that stores the SUM of Mass Flow is initialized to zero
{
C_CENTROID(x,c,t);
if ((x[2]<kk1) && (x[2]>kk0))    // All the parcels are organized in different sections
{
//  L O O P - O V E R - A L L - T H E - F A C E S - O F - A - C E L L
/////////////////////////////////////////////////////////////////////////////////////////////////////
cell_t cf;
face_t face;
/* cf,tf is cell & cell thread */
F_AREA(NormalVector,face,tf);
Area=  sqrt(NormalVector[0]*NormalVector[0]+NormalVector[1]*NormalVector[1]+NormalVector[2]*NormalVector[2]);
NormalVector[0]=NormalVector[0]/(Area);
c_face_loop(cf,tf,numbf)
{
face = C_FACE(cf,tf,numbf);
/* do what you like with face numbf with
/* -- eg temp = F_T(face,thread); */
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//  L O O P - O V E R - A L L - T H E - F A C E S - O F - A - C E L L

}
}

Message ("%f\t",SUMflow/division);
}
Message ("\n");
}
}```
I have already created a code that integrate and get the mass flow of liquid droplets using the DPM model. The idea is using both together as a convengence criteria.

Thank you very much
__________________
Having fun with CFD =)

 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 stru OpenFOAM Pre-Processing 2 August 25, 2015 03:58 shipman OpenFOAM 3 July 24, 2014 08:14 Shogan FLUENT 1 May 28, 2014 15:03 magicalmarshmallow FLUENT 3 April 4, 2014 12:25 chelvistero OpenFOAM 11 January 15, 2010 20:43

All times are GMT -4. The time now is 06:40.