|
[Sponsors] |
October 28, 2015, 21:59 |
enquire explanation of the code
|
#1 |
Member
Join Date: Mar 2015
Posts: 30
Rep Power: 11 |
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; } 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); |
|
October 29, 2015, 05:10 |
|
#2 |
Member
Join Date: Jul 2013
Posts: 80
Rep Power: 13 |
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 |
|
October 29, 2015, 19:43 |
|
#3 | |
Member
Join Date: Mar 2015
Posts: 30
Rep Power: 11 |
Quote:
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,965
Rep Power: 27 |
Quote:
Quote:
Quote:
Quote:
|
|||||
October 31, 2015, 22:49 |
|
#5 | |
Member
Join Date: Mar 2015
Posts: 30
Rep Power: 11 |
Quote:
Code:
dim=idim; normal[i] = f_normal[i]; ((NNULLP(t)) && (THREAD_TYPE(t) == THREAD_F_WALL))"; F_CENTROID(x,f,t); Cheers! |
||
November 2, 2015, 06:32 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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: 11 |
Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
The FOAM Documentation Project - SHUT-DOWN | holger_marschall | OpenFOAM | 242 | March 7, 2013 13:30 |
How to make code run in parallel? | cwang5 | OpenFOAM Programming & Development | 1 | May 30, 2011 05:47 |
Open Source Vs Commercial Software | MechE | OpenFOAM | 28 | May 16, 2011 12:02 |
Error in CFX Solver | Leuchte | CFX | 5 | November 6, 2010 07:12 |
Small 3-D code | Zdravko Stojanovic | Main CFD Forum | 2 | July 19, 2010 11:11 |