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

UDF Code doesn't work

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 26, 2019, 03:11
Default UDF Code doesn't work
  #1
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
Hey, I really need your help.

I'm struggling with an UDF Code that should calculate the force that particles and a fluid (water) exert on a moving body. The velocity of the body should slow down dependent on these two forces. I wrote an UDF code, but Fluent says ERROR, the UDF isn't compiled for parallel use on the current platform. I really don't understand that. Here's my code. I really appreciate if somebody could check and help me


#include "udf.h"

static real v_prev = 0.3;

DEFINE_DPM_BC(Particle_Infos,p,t,f,f_normal,dim)
{
#if !RP_HOST

cell_t p_cell; /* Cells where particles reside */

real p_n; /* Number of particles in a parcel */

real p_mass; /* Mass of each particle */

real pur_vel[ND_ND]; /* Velocity of each particle */

int i; /* vector number*/

flow_time = CURRENT_TIME; /* Get current flow time */

Thread *p_cell_thread;

/**** Now calculating force of particles*******/

p_cell = F_C0(f,t); /* return cell thread index in which face thread "t" is */

p_cell_thread = THREAD_T0(t); /* Get the face centroid from ANSYS FLUENT */

F_CENTROID(pur_f_centroid,f,t); /* Get the number of the particles in a parcel from FLUENT */

p_n = P_N(p); /* Get the mass of the particle from ANSYS FLUENT */

p_mass = P_MASS(p); /* Get the velocity of the particle from ANSYS FLUENT */

for(i=0;i<dim;i++)
pur_vel[i] = P_VEL(p)[i]; /* When the particles hit the wall face, mark the cell, which consists
this face.*/

C_UDMI(p_cell,p_cell_thread,0) = PUR_cell; /* Store the number of particles hitting this face all the
time. */

C_UDMI(p_cell,p_cell_thread,1) += p_n;

C_UDMI(p_cell,p_cell_thread,2) += p_n * p_mass; /* mass of particles hitting the face */


C_UDMI(p_cell,p_cell_thread,6) += p_n * p_mass * pur_vel[0]; /* Total impulse of all parcels in x
direction in a cell */

C_UDMI(p_cell,p_cell_thread,17) += 1; /* Store the number of parcels hitting on this face all the
time*/

return PATH_ABORT;
#endif

}

DEFINE_CG_MOTION(bubble, dt, vel, omega, time, dtime)
{
Thread *t;
face_t f;

real NV_VEC(A);
real Wall_Shear_Force;
real viscous,force;
real dv;
real force_p;

/* reset velocities */
NV_S (vel, =, 0.0);
NV_S (omega, =, 0.0);

if (!Data_Valid_P ())
return;

/* get the thread pointer for which this motion is defined */
t = DT_THREAD (dt);

/* compute pressure force on body by looping through all faces */
viscous = 0.0;

begin_f_loop (f, t)
{
cell_t c0 = F_C0(f,t);
Thread *t0 = THREAD_T0(t);
F_AREA (A, f, t);
Wall_Shear_Force = -F_STORAGE_R_N3V(f,t ,SV_WALL_SHEAR)[0];
viscous += Wall_Shear_Force ;
force_p += C_UDMI(c0,t0,6);
}
end_f_loop (f, t)

# if RP_NODE
{
/* Reduce in parallel */
PRF_GRSUM1 (viscous);
PRF_GRSUM1 (force_p);
}
# endif

/* compute change in velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */

dv = dtime * (viscous + 0.000512 + force_p/dtime) / 0.000055;

v_prev += dv;

Message0("time = %f, x_vel = %f, force = %f\n", time, v_prev,
force);

/* set x-component of velocity */
vel[0] = v_prev;
}
force_95 is offline   Reply With Quote

Old   October 28, 2019, 01:13
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
try
Code:
#include "udf.h"

static real v_prev = 0.3;

DEFINE_DPM_BC(Particle_Infos,p,t,f,f_normal,dim)
{
#if !RP_HOST

cell_t p_cell; /* Cells where particles reside */

real p_n; /* Number of particles in a parcel */

real p_mass; /* Mass of each particle */

real pur_vel[ND_ND]; /* Velocity of each particle */

int i; /* vector number*/

Thread *p_cell_thread;

real flow_time;

flow_time = CURRENT_TIME; /* Get current flow time */

/**** Now calculating force of particles*******/

p_cell = F_C0(f,t); /* return cell thread index in which face thread "t" is */

p_cell_thread = THREAD_T0(t); /* Get the face centroid from ANSYS FLUENT */

p_n = P_N(p); /* Get the mass of the particle from ANSYS FLUENT */

p_mass = P_MASS(p); /* Get the velocity of the particle from ANSYS FLUENT */

for(i=0;i<dim;i++)
pur_vel[i] = P_VEL(p)[i]; /* When the particles hit the wall face, mark the cell, which consists
this face.*/

C_UDMI(p_cell,p_cell_thread,0) = PUR_cell; /* Store the number of particles hitting this face all the
time. */

C_UDMI(p_cell,p_cell_thread,1) += p_n;

C_UDMI(p_cell,p_cell_thread,2) += p_n * p_mass; /* mass of particles hitting the face */


C_UDMI(p_cell,p_cell_thread,6) += p_n * p_mass * pur_vel[0]; /* Total impulse of all parcels in x
direction in a cell */

C_UDMI(p_cell,p_cell_thread,17) += 1; /* Store the number of parcels hitting on this face all the
time*/

return PATH_ABORT;
#endif

}

DEFINE_CG_MOTION(bubble, dt, vel, omega, time, dtime)
{
Thread *t;
face_t f;

real NV_VEC(A);
real Wall_Shear_Force;
real viscous,force;
real dv;
real force_p;

/* reset velocities */
NV_S (vel, =, 0.0);
NV_S (omega, =, 0.0);

if (!Data_Valid_P ())
return;

/* get the thread pointer for which this motion is defined */
t = DT_THREAD (dt);

/* compute pressure force on body by looping through all faces */
viscous = 0.0;

begin_f_loop (f, t)
{
cell_t c0 = F_C0(f,t);
Thread *t0 = THREAD_T0(t);
F_AREA (A, f, t);
Wall_Shear_Force = -F_STORAGE_R_N3V(f,t ,SV_WALL_SHEAR)[0];
viscous += Wall_Shear_Force ;
force_p += C_UDMI(c0,t0,6);
}
end_f_loop (f, t)

# if RP_NODE
{
/* Reduce in parallel */
PRF_GRSUM1 (viscous);
PRF_GRSUM1 (force_p);
}
# endif

/* compute change in velocity, i.e., dv = F * dt / mass
velocity update using explicit Euler formula */

dv = dtime * (viscous + 0.000512 + force_p/dtime) / 0.000055;

v_prev += dv;

Message0("time = %f, x_vel = %f, force = %f\n", time, v_prev,
force);

/* set x-component of velocity */
vel[0] = v_prev;
}
WARNING:
C_UDMI(p_cell,p_cell_thread,0) = PUR_cell;

PUR_cell; is not defined !!!!!!
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 28, 2019, 03:13
Default
  #3
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
thank you !


I added a real PUR_cell;



Now I can compile the code, but when I start calculating, Fluent breaks down and only the Workbench is open. What could now be the problem?


best regards
force_95 is offline   Reply With Quote

Old   October 28, 2019, 03:19
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
i don't know.
I recommend you to run Fluent separably
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 28, 2019, 05:23
Default
  #5
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
thank you anyway.


Fluent does what it wants to, its kind of hopeless
force_95 is offline   Reply With Quote

Old   October 28, 2019, 23:54
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
if you expect to get help you should describe everything in details
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 29, 2019, 04:07
Default
  #7
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
I try to explain the problem in detail.

There is a moving body whose velocity slows down dependent on the viscous force that a fluid exerts on this body. So this UDF works fine. Now I inserted particles and realized that there is no difference. So my UDF Code doesn't see those particles. Thats the reason why I tried to extend my UDF code. The idea is that the impulse of all particles hitting the moving body is summed up and divided by time step in order to get the force. The UDF you see in this thread is the one who tries to calculate viscous force as well as force of particles.
I can compile the UDF, but when I start calculating, FLUENT breaks down with No Error Messages.
force_95 is offline   Reply With Quote

Old   October 30, 2019, 00:19
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
something wrong with your settings, play with them
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ 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
Urgent help for UDF Code needed force_95 FLUENT 2 October 25, 2019 07:35
Need help with udf code for particles force_95 FLUENT 0 October 24, 2019 08:58
UDF code for heat generating source valerhain Fluent UDF and Scheme Programming 13 November 18, 2015 14:24
udf fluent 6.3.26 don't work in fluent 12 enry Fluent UDF and Scheme Programming 16 September 9, 2010 02:44
Optimizing UDF Code Cebeci FLUENT 18 September 6, 2003 03:40


All times are GMT -4. The time now is 22:30.