|
[Sponsors] |
September 26, 2019, 09:20 |
UDF-Code for calculating the viscous force
|
#1 |
New Member
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6 |
Hey all,
I have some problems with my UDF-Code. The code should calculate the decrease of the speed of a body depending on the viscous force that the fluid (water) bears on that body. this is my code: #include "udf.h" static real v_prev = 0.3; DEFINE_CG_MOTION(bubble, dt, vel, omega, time, dtime) { Thread *t; face_t f; real NV_VEC(A); real Wall_Shear_Force; real viscous; real dv; /* 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) { F_AREA (A, f, t); Wall_Shear_Force = -F_STORAGE_R_N3V(f,t ,SV_WALL_SHEAR)[0]; viscous += Wall_Shear_Force ; } end_f_loop (f, t) /* compute change in velocity, i.e., dv = F * dt / mass velocity update using explicit Euler formula */ dv = dtime * viscous / 0.000055; v_prev += dv; Message ("time = %f, x_vel = %f, force = %f\n", time, v_prev, force); /* set x-component of velocity */ vel[0] = v_prev; } I'm really hoping that somebody can help me. |
|
September 26, 2019, 21:14 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
what kind of problem do you have? describe in details!
for you code if you are using version v19.0 or earlier: Code:
#include "udf.h" static real v_prev = 0.3; 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; /* 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 */ force = 0.0; viscous = 0.0; begin_f_loop (f, t) { F_AREA (A, f, t); Wall_Shear_Force = -F_STORAGE_R_N3V(f,t ,SV_WALL_SHEAR)[0]; viscous += Wall_Shear_Force ; } end_f_loop (f, t) # if RP_NODE { /* Reduce in parallel */ PRF_GRSUM1 (viscous); } # endif /* compute change in velocity, i.e., dv = F * dt / mass velocity update using explicit Euler formula */ dv = dtime * viscous / 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; } best regards |
|
September 27, 2019, 02:38 |
|
#3 |
New Member
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6 |
thank you for your answer!
The problem with my UDF code is that I get error messages all the time when I try to compile the code in Fluent. I guess its because I'm not familiar with programming in C. The goal of the code should be that the body for which I use the code should slow down depending on the viscous force that a fluid exerts. Kind regards |
|
September 27, 2019, 02:40 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
code, I've provided is compiled with no errors,
show what error did you get best regards |
|
September 30, 2019, 02:33 |
|
#5 |
New Member
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6 |
I just tried to compile it. It seems to be working. Thank you !
Do you also know what I have to change in the code when I want to extract a text file which shows the viscous force over the flow time? I want to plot the viscous force. Best regards |
|
October 1, 2019, 03:13 |
|
#6 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may use UDMs to store variable you want.
modify this part Code:
begin_f_loop (f, t) { F_AREA (A, f, t); Wall_Shear_Force = -F_STORAGE_R_N3V(f,t ,SV_WALL_SHEAR)[0]; viscous += Wall_Shear_Force ; F_UDMI(f,t,0) = Wall_Shear_Force ; } end_f_loop (f, t) user-defined -> memory -> UDM locations change to 1 to monitor your UDM_0 make surface report area-weight average of udm_0 best regards |
|
October 1, 2019, 03:30 |
|
#7 |
New Member
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6 |
thank you.
Meanwhile I've got another problem. When I insert particles (with a Matlab generated file), I expect the bubble to slow down very faster than without particles. But there is no difference between simulating without and with particles. I dont understand why , because I enabled "Interaction with continous phase". Thats really weird. best regards |
|
October 1, 2019, 08:18 |
|
#8 |
New Member
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6 |
Is it possible that the viscous force I'm calculating is ignoring the particles ? Do I have to enable the energy equation ?
Last edited by force_95; October 1, 2019 at 09:22. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Different force result: DEFINE_Source UDF & without UDF | A.Rah | FLUENT | 1 | November 11, 2017 07:22 |
writing a udf for a specific body force | rima_se2003 | Fluent UDF and Scheme Programming | 3 | October 15, 2014 02:37 |
something wrong when compiling udf, however the code is correct when interpreting | richard ben | Fluent UDF and Scheme Programming | 7 | May 11, 2013 07:36 |
UDF force on a face | enry | Fluent UDF and Scheme Programming | 10 | March 23, 2011 10:48 |
pressure force and viscous force | CFD | FLUENT | 0 | March 7, 2006 01:03 |