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

UDF-Code for calculating the viscous force

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 26, 2019, 09:20
Post UDF-Code for calculating the viscous force
  #1
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
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.
force_95 is offline   Reply With Quote

Old   September 26, 2019, 21:14
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
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;
}
compile this code

best regards
AlexanderZ is offline   Reply With Quote

Old   September 27, 2019, 02:38
Default
  #3
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
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
force_95 is offline   Reply With Quote

Old   September 27, 2019, 02:40
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
code, I've provided is compiled with no errors,
show what error did you get

best regards
AlexanderZ is offline   Reply With Quote

Old   September 30, 2019, 02:33
Default
  #5
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
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
force_95 is offline   Reply With Quote

Old   October 1, 2019, 03:13
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
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)
allocate memory for UDM in fluent GUI:
user-defined -> memory -> UDM locations change to 1

to monitor your UDM_0 make surface report area-weight average of udm_0

best regards
AlexanderZ is offline   Reply With Quote

Old   October 1, 2019, 03:30
Default
  #7
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
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
force_95 is offline   Reply With Quote

Old   October 1, 2019, 08:18
Post
  #8
New Member
 
jens meier
Join Date: Sep 2019
Posts: 28
Rep Power: 6
force_95 is on a distinguished road
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.
force_95 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
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


All times are GMT -4. The time now is 03:52.