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

What's wrong with my UDF?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 8, 2019, 23:39
Question What's wrong with my UDF?
  #1
New Member
 
刘宵
Join Date: Aug 2019
Posts: 4
Rep Power: 7
Jonathon_L is on a distinguished road
Hi all,
This is my code and I'm trying to calculate the value of w by UDF. The value of w is related to the angle at which the fluid impacts the wall. So I loop through the cells first, then loop the faces inside the cells. Finally, I hope that I can save the value of w to the data so that I can see the distribution of w from the contour. But my UDF doesn't work, I don't know what' wrong with it.
Thanks very much if you can give me some suggestions.


#include "udf.h"
#include "math.h"
#include "metric.h"
#include "mem.h"
DEFINE_ON_DEMAND(on_demand_w)
{
real w;
int n;
real densic=3200;
real c;
real alpha;
real A[ND_ND];
real vel[3];
real velm;
real Am;
real cos;
real velx;
real vely;
real velz;
real qm;
Domain *d;
Thread *t;
cell_t c0;
face_t f;
d=Get_Domain(1);
c=sqrt(3*480*1000000/densic);
thread_loop_c(t,d)
{
c0=F_C0(f,t);
begin_c_loop(c0,t)
{
real denmix=C_R(c0,t);
c_face_loop(c0,t,n)
{
velx=F_U(f,t);
vely=F_V(f,t);
velz=F_W(f,t);
vel[1]=velx;
vel[2]=vely;
vel[3]=velz;
qm=velx*denmix*3.1416*0.0045*0.0045;
F_AREA(A,f,t);
velm=NV_MAG(vel);
Am=NV_MAG(A);
cos=NV_DOT(vel,A)/velm/Am;
alpha=asin(cos)*180/3.1416;
w=7/3.1416*qm/denmix*pow((velm/c),2.5)*sin(2*alpha)*sin(alpha);
C_UDMI(c0,t,0)=w;
fprintf("out_w:%g\n",w);
}
}
end_c_loop(c0,t)
}
}
Jonathon_L is offline   Reply With Quote

Old   September 9, 2019, 16:41
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Code:
#include "udf.h"
#include "math.h"
#include "metric.h"
#include "mem.h"
DEFINE_ON_DEMAND(on_demand_w)
{
 real w;
 int n;
 real densic=3200;
 real c;
 real alpha;
 real A[ND_ND];
 real vel[3];
 real velm;
 real Am;
 real cos;
 real velx;
 real vely;
 real velz;
 real qm; 
 Domain *d;
 Thread *t;
 cell_t c0;
 face_t f;
 d=Get_Domain(1);
 c=sqrt(3*480*1000000/densic);
 thread_loop_c(t,d)
 {
  c0=F_C0(f,t);
  .. (rest of code removed because the first problem is here)
You ask Fluent to use f, but you never tell Fluent what f is. Yes, you declare it as a face, but Fluent has no idea which face you mean.

I cannot really figure out what you are trying to do, but probably you forgot to loop over all faces or something like that.

Your compiler should have complained that something is wrong in this line. Always check compiler errors, especially if you have a problem with compiling!
pakk is offline   Reply With Quote

Old   September 9, 2019, 16:47
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
And some suggestions to improve your code:

Quote:
Originally Posted by Jonathon_L View Post
real denmix=C_R(c0,t);
You should have declared this variable higher up, at least in the default dialect of c that Fluent uses.

Quote:
Originally Posted by Jonathon_L View Post
velx=F_U(f,t);
vely=F_V(f,t);
velz=F_W(f,t);
vel[1]=velx;
vel[2]=vely;
vel[3]=velz;
This is not very useful, just simplify it to:
Code:
	        vel[1]=F_U(f,t);
                vel[2]=F_V(f,t);
                vel[3]=F_W(f,t);
Quote:
Originally Posted by Jonathon_L View Post
alpha=asin(cos)*180/3.1416;
w=7/3.1416*qm/denmix*pow((velm/c),2.5)*sin(2*alpha)*sin(alpha);
Your alpha is in degrees, but sin expects an angle in radians. Don't convert, just keep it as it is:
Code:
                alpha=asin(cos);
                w=7/3.1416*qm/denmix*pow((velm/c),2.5)*sin(2*alpha)*sin(alpha);
pakk is offline   Reply With Quote

Old   September 9, 2019, 22:09
Default
  #4
New Member
 
刘宵
Join Date: Aug 2019
Posts: 4
Rep Power: 7
Jonathon_L is on a distinguished road
Quote:
You ask Fluent to use f, but you never tell Fluent what f is. Yes, you declare it as a face, but Fluent has no idea which face you mean.

I cannot really figure out what you are trying to do, but probably you forgot to loop over all faces or something like that.

Your compiler should have complained that something is wrong in this line. Always check compiler errors, especially if you have a problem with compiling!
Thank you for your reply, and I'll try.
Jonathon_L is offline   Reply With Quote

Reply

Tags
udf code


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
can anyone help me about the udf of dynamic contact angle in FLUENT? Albert Lee FLUENT 0 July 1, 2018 09:21
Dynamic Mesh UDF Qureshi FLUENT 7 March 23, 2017 08:37
whats wrong with this udf ? h.mortezaee Fluent UDF and Scheme Programming 3 September 14, 2015 08:32
something wrong when compiling udf, however the code is correct when interpreting richard ben Fluent UDF and Scheme Programming 7 May 11, 2013 08:36
what's wrong with the UDF major FLUENT 6 March 3, 2005 07:39


All times are GMT -4. The time now is 13:54.