enquire explanation of the code

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

 October 28, 2015, 21:59 enquire explanation of the code #1 Member   Join Date: Mar 2015 Posts: 30 Rep Power: 4 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; itype==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

 October 29, 2015, 05:10 #2 Member   Join Date: Jul 2013 Posts: 75 Rep Power: 6 for (i=0; i

October 29, 2015, 19:43
#3
Member

Join Date: Mar 2015
Posts: 30
Rep Power: 4
Quote:
 Originally Posted by upeksa for (i=0; i
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!

October 30, 2015, 08:54
#4
Senior Member

Join Date: Nov 2013
Posts: 1,084
Rep Power: 14
Quote:
 Originally Posted by mimi0201 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!

October 31, 2015, 22:49
#5
Member

Join Date: Mar 2015
Posts: 30
Rep Power: 4
Quote:
 Originally Posted by pakk 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];
F_CENTROID(x,f,t);```
But which code shows that, when particle hitting on the wall then calculate the normal velocity etc.?
Cheers!

 November 2, 2015, 06:32 #6 Senior Member   Join Date: Nov 2013 Posts: 1,084 Rep Power: 14 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 */```

November 2, 2015, 18:45
#7
Member

Join Date: Mar 2015
Posts: 30
Rep Power: 4
Quote:
 Originally Posted by pakk 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.

 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 holger_marschall OpenFOAM 242 March 7, 2013 13:30 cwang5 OpenFOAM Programming & Development 1 May 30, 2011 04:47 MechE OpenFOAM 28 May 16, 2011 11:02 Leuchte CFX 5 November 6, 2010 07:12 Zdravko Stojanovic Main CFD Forum 2 July 19, 2010 10:11

All times are GMT -4. The time now is 08:16.