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

enquire explanation of the code

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By upeksa

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 28, 2015, 20:59
Default enquire explanation of the code
  #1
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Here is an example from ANSYS help, tracking particle's reflections at walls.

Code:
/* reflect boundary condition for inert particles */
 #include "udf.h"
 DEFINE_DPM_BC(bc_reflect,p,t,f,f_normal,dim)
 {
    real alpha; /* angle of particle path with face normal */
    real vn=0.;
    real nor_coeff = 1.;
    real tan_coeff = 0.3;
    real normal[3];
    int i, idim = dim;
    real NV_VEC(x);

for (i=0; i<idim; i++)
       normal[i] = f_normal[i];

    if(p->type==DPM_TYPE_INERT)
      {
         alpha = M_PI/2. - acos(MAX(-1.,MIN(1.,NV_DOT(normal,P_VEL(p))/
              MAX(NV_MAG(P_VEL(p)),DPM_SMALL))));
         if ((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))
               F_CENTROID(x,f,t);

         /* calculate the normal component, rescale its magnitude by
           the coefficient of restitution and subtract the change */

         /* Compute normal velocity. */
         for(i=0; i<idim; i++)
           vn += P_VEL(p)[i]*normal[i];

         /* Subtract off normal velocity. */
           for(i=0; i<idim; i++)
             P_VEL(p)[i] -= vn*normal[i];

         /* Apply tangential coefficient of restitution. */
           for(i=0; i<idim; i++)
             P_VEL(p)[i] *= tan_coeff;

         /* Add reflected normal velocity. */
           for(i=0; i<idim; i++)
             P_VEL(p)[i] -= nor_coeff*vn*normal[i];

         /* Store new velocity in P_VEL0 of particle */
         for(i=0; i<idim; i++)
           P_VEL0(p)[i] = P_VEL(p)[i];

         return PATH_ACTIVE;
      }
  return PATH_ABORT;
 }
In the code, what exactly does the statement do as shown below?

Code:
for (i=0; i<idim; i++)
       normal[i] = f_normal[i];

and

if ((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))
               F_CENTROID(x,f,t);
mimi0201 is offline   Reply With Quote

Old   October 29, 2015, 04:10
Default
  #2
Member
 
Join Date: Jul 2013
Posts: 80
Rep Power: 12
upeksa is on a distinguished road
for (i=0; i<idim; i++)
normal[i] = f_normal[i];


int idim=dim, where dim is argument in DEFINE_DPM_BC, which stands for the dimension of the flow problem. The value is 2 in 2d, for 2d-axisymmetric and 2d-axisymmetric-swirling flow, while it is 3 in 3d flows.

You are looping through the components for the vector "normal" and setting an equivalence between "normal" and "f_normal", which this last one is another argument of DEFINE_DPM_BC that contains the unit vector which is normal to the face (the boundary condition where DEFINE_DPM_BC is hooked to).

if ((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))
F_CENTROID(x,f,t);


(Copied from the udf guide): You can use the NULLP and NNULLP functions to check whether storage has been allocated for userdefined scalars. NULLP returns TRUE if storage is not allocated, and NNULLP returns TRUE if storage is allocated.
If you are not using UDS, I guess you can omit it.

(THREAD_TYPE(t) == THREAD_F_WALL) is used to check if you are in a wall

F_CENTROID(x,f,t) sets the array "x" as the coordinates of the face centroid of the wall.

Cheers
pakk likes this.
upeksa is offline   Reply With Quote

Old   October 29, 2015, 18:43
Default
  #3
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Quote:
Originally Posted by upeksa View Post
for (i=0; i<idim; i++)
normal[i] = f_normal[i];


int idim=dim, where dim is argument in DEFINE_DPM_BC, which stands for the dimension of the flow problem. The value is 2 in 2d, for 2d-axisymmetric and 2d-axisymmetric-swirling flow, while it is 3 in 3d flows.

You are looping through the components for the vector "normal" and setting an equivalence between "normal" and "f_normal", which this last one is another argument of DEFINE_DPM_BC that contains the unit vector which is normal to the face (the boundary condition where DEFINE_DPM_BC is hooked to).

if ((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))
F_CENTROID(x,f,t);


(Copied from the udf guide): You can use the NULLP and NNULLP functions to check whether storage has been allocated for userdefined scalars. NULLP returns TRUE if storage is not allocated, and NNULLP returns TRUE if storage is allocated.
If you are not using UDS, I guess you can omit it.

(THREAD_TYPE(t) == THREAD_F_WALL) is used to check if you are in a wall

F_CENTROID(x,f,t) sets the array "x" as the coordinates of the face centroid of the wall.

Cheers
Thank you so much for the reply, and i have several questions.
1. So u mean dim is argument in DEFINE_DPM_BC, but why don't we just use dim then, why we need to define dim as idim?
2. Similarly, what is the purpose to define normal[i] = f_normal[i]?
3. What does the statement "F_CENTROID(x,f,t)" do? it calls the controid if statement "((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))" is true, but why do we need the centroid?

I'm new to UDF so I have a lot of silly questions. Really appreciate!
mimi0201 is offline   Reply With Quote

Old   October 30, 2015, 07:54
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by mimi0201 View Post
Thank you so much for the reply, and i have several questions.
1. So u mean dim is argument in DEFINE_DPM_BC, but why don't we just use dim then, why we need to define dim as idim?
I see no reason in this code. It would have been easier to use dim.
Quote:
2. Similarly, what is the purpose to define normal[i] = f_normal[i]?
I see no purpose in this code. It would have been easier and more clear to use f_normal everywhere.
Quote:
3. What does the statement "F_CENTROID(x,f,t)" do? it calls the controid if statement "((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))" is true, but why do we need the centroid?
Here it gives 'x' the coordinates of the center of the cell where the particle is in. But 'x' is never used again, so this is not really useful to do.
Quote:
I'm new to UDF so I have a lot of silly questions. Really appreciate!
These are definitely not silly questions, I think they are good questions for somebody new to UDF. This example has some unnecessary lines of code, and you have seen that they have no purpose. I think you understand UDFs better than some other people!
pakk is offline   Reply With Quote

Old   October 31, 2015, 21:49
Default
  #5
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Quote:
Originally Posted by pakk View Post
I see no reason in this code. It would have been easier to use dim.

I see no purpose in this code. It would have been easier and more clear to use f_normal everywhere.

Here it gives 'x' the coordinates of the center of the cell where the particle is in. But 'x' is never used again, so this is not really useful to do.

These are definitely not silly questions, I think they are good questions for somebody new to UDF. This example has some unnecessary lines of code, and you have seen that they have no purpose. I think you understand UDFs better than some other people!
So as you explained, codes shown below are all redundant if I just want to track the particle hitting on the wall:
Code:
dim=idim;
normal[i] = f_normal[i];
((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))";
F_CENTROID(x,f,t);
But which code shows that, when particle hitting on the wall then calculate the normal velocity etc.?
Cheers!
mimi0201 is offline   Reply With Quote

Old   November 2, 2015, 05:32
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
This code is a boundary condition. So the code is only run when a particle has reached a wall. And the steps that are taken then, are in the code. Look at the comments!
Code:
         /* Compute normal velocity. */
         /* Subtract off normal velocity. */
         /* Apply tangential coefficient of restitution. */
         /* Add reflected normal velocity. */
         /* Store new velocity in P_VEL0 of particle */
pakk is offline   Reply With Quote

Old   November 2, 2015, 17:45
Default
  #7
Member
 
Join Date: Mar 2015
Posts: 30
Rep Power: 11
mimi0201 is on a distinguished road
Quote:
Originally Posted by pakk View Post
This code is a boundary condition. So the code is only run when a particle has reached a wall. And the steps that are taken then, are in the code. Look at the comments!
Code:
         /* Compute normal velocity. */
         /* Subtract off normal velocity. */
         /* Apply tangential coefficient of restitution. */
         /* Add reflected normal velocity. */
         /* Store new velocity in P_VEL0 of particle */
Oh ok! That was a bit tricky,haha. I think I get it now, i was stuck in the beginning of the code for a long time.
mimi0201 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
The FOAM Documentation Project - SHUT-DOWN holger_marschall OpenFOAM 242 March 7, 2013 12:30
How to make code run in parallel? cwang5 OpenFOAM Programming & Development 1 May 30, 2011 04:47
Open Source Vs Commercial Software MechE OpenFOAM 28 May 16, 2011 11:02
Error in CFX Solver Leuchte CFX 5 November 6, 2010 06:12
Small 3-D code Zdravko Stojanovic Main CFD Forum 2 July 19, 2010 10:11


All times are GMT -4. The time now is 13:42.