
[Sponsors] 
April 10, 2012, 02:57 
UDF writing: parabolic profile

#1 
Member
Robert
Join Date: Mar 2011
Location: Warsaw
Posts: 62
Rep Power: 6 
Hello!
I try to create a parabolic velocity profile for the velocity inlet in 3D geometry. I have created UDF below but I have still problems with it. Does my UDF see x and y coordinates? #include "udf.h" DEFINE_PROFILE(parabolic_profile,t,i) { real x; real y; face_t f; begin_f_loop(f,t) { F_CENTROID(x,f,t); y = x[1]; F_PROFILE(f,t,i) = x*x+y+y; } end_f_loop(f,t) } 

April 10, 2012, 04:49 

#2 
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 8 
No, it does not. Define x as a vector having three components > x[0] will give you xcoordinate, x[1] ycoord and x[2] zcoordinate.
cheers cheers 

April 10, 2012, 06:54 

#3 
Member
Robert
Join Date: Mar 2011
Location: Warsaw
Posts: 62
Rep Power: 6 
So should it look like this?
#include "udf.h" DEFINE_PROFILE(parabolic_profile,t,i) { real x [ND_ND]; real y; real z; face_t f; begin_f_loop(f,t) { F_CENTROID(x,f,t); y = x[0]; z = x[1]; F_PROFILE(f,t,i) = y*y+z+z; } end_f_loop(f,t) } By the way what is [ND_ND] for? Do I have to write it? 

April 10, 2012, 10:23 

#4 
Member
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 8 
Below is a copy of a UDF I used recently. Whenever you use these initialise the flow, perform 1 iteration and visualise the contour to ensure it is what you are looking for.
ND_ND stores the dimension of the problem e.g., 2D or 3D. Also be careful with the way you assign x and y. The vector x contains components (x[0], x[1], x[2]) which are normally considered (x,y,z). Let me know if you have questions. I have not fully tested this UDF but it worked for my application. Good luck. #include"udf.h" DEFINE_PROFILE(velocity, thread, position) { /* This UDF applies a parabolic velocity profile to the boundary surface hooked in Fluent */ /* This operates for 3D models in any orientation */ /****************************/ /* THE USER INPUTS */ /****************************/ /* the centroid of the boundary face (x0,y0,z0) */ real x0 = 0.0; real y0 = 0.0; real z0 = 0.0; /* the maximum radius of the pipe and maximum centerline veloicty of the parabola */ real Max_Radius = 0.0005; /* diameter of the pipe Max_Radius */ real Peak_Velocity = 20.0; /* maximum centerline velocity of the parabola */ /****************************/ /****************************/ /****************************/ /* Main Program */ /****************************/ real x[ND_ND]; /* this will hold the position vector of the face/element centroid */ real r; /* distance from the centre of the pipe */ real Velocity_Profile; /* Velocity to be written to boundary */ face_t f; /* f the hooked boundary face in fluent */ /* This starts the main loop. As each element on the face is looped over its centroid is determined and the distance from this to the centre of the parabola. The velocity required is calculated based on this distance and applied. */ begin_f_loop(f,thread) { F_CENTROID(x, f, thread); /* the coordinates of the current face/element centroid accessed by F_CENTROID */ /* Radius from central axis of parabola is */ if (ND_ND==2) /* for 2D modelling */ { r = pow(pow((x[0]x0),2)+pow((x[1]y0),2),0.5); } if (ND_ND==3) /* for 3D modelling */ { r = pow(pow((x[0]x0),2)+pow((x[1]y0),2)+pow((x[2]z0),2),0.5); } /* Write Profile in x */ Velocity_Profile = Peak_Velocity*(1.0((r*r)/(Max_Radius*Max_Radius))); /* Write velocity boundary condition */ F_PROFILE(f, thread, position) = Velocity_Profile; /* Apply velocity profile to selected boundary */ } end_f_loop(f, thread) /****************************/ /****************************/ } 

May 23, 2012, 12:26 
Help, unable to interpret

#5 
New Member
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 6 
Hi, Please can you help me,
I am trying to set a velocity inlet condition (not really a profile, more just a value for the inlet). I wrote the following UDF, but now I cannot get it to interpret, keeps giving me a parse error on the equation that I enter for the Velocity_Profile. Here is the c_code: #include "udf.h" DEFINE_PROFILE(Velocity_Profile, thread, position) { /****************************/ /* THE USER INPUTS */ /****************************/ /* the centroid of the boundary face (x0,y0,z0) */ real x0 = 0.0; real y0 = 0.0; real z0 = 0.0; /****************************/ /*Parameters*/ /****************************/ //Stochiometric factor real Anode = 1.5; real Cathode = 2; real F = 96485; /* Faradays constant (C/mol) */ real R = 8.314; /* Universal gas constant (J/mol)*/ real T = 353; /* Temperature (K) */ real P_anode = 101325; /* Anode pressure (Pa) */ real i = 0.00004; //(A/m2) current density /****************************/ /* Main Program */ /****************************/ real x[ND_ND]; real Velocity_Profile; /* Velocity to be written to boundary */ face_t f; /* f the hooked boundary face in fluent */ begin_f_loop(f,thread); { F_CENTROID(x, f, thread); /* the coordinates of the current face/element centroid accessed by F_CENTROID */ /* Write Profile in x */ Velocity_Profile = Anode*(i/(2*F))/(P_anode/(R*T); /* Write velocity boundary condition */ F_PROFILE(f, thread, position) = Velocity_Profile; /* Apply velocity profile to selected boundary */ } end_f_loop(f, thread); /****************************/ /****************************/ //return Velocity_Profile; } 

May 28, 2012, 07:36 

#6 
Member
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 8 
Velocity_Profile = Anode*(i/(2*F))/(P_anode/(R*T) is missing a bracket.


May 29, 2012, 04:21 

#7 
New Member
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 6 
Hi Daniel,
Thanks for the reply, I actually figured out the problem the moment I put up the question, should have put a follow up saying that I got the answer. Thanks again. I also had a quick question regarding multiple UDFs on the same C file. Can I run multiple macros on the same file? i.e. specify an inlet velocity as well as a sink term using multiple macros on the same file and then interpret it in fluent? I am asking this question because I am struggling to compile my different cfiles due to not being able to install microsoft visual studio. Thanks 

May 29, 2012, 05:37 

#8  
Senior Member
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 910
Rep Power: 15 
Quote:


May 29, 2012, 06:24 

#9 
New Member
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 6 
Thanks Ghost,
I got it to work, my system is a fuel cell so dont think I have any body motion UDFs. Plus I check all my UDFs can be interpreted anyway. Thanks again. Just a quick question regarding postprocessing. I am looking at the concentration change of hydrogen and I want to compare my 3D results with a 1D model, so i just want to look at the concentration change in the zaxis. To do this I am using XY plot in fluent. I set my yaxis function as the concentration of H2 and my xaxis function as my direction vector (zaxis direction in this case). However, I dont get a single concentration profile, but multiple points. Doesnt make any sense as the the 3D solution and a slice in the axis of interest looks correct. can you help 

June 5, 2012, 08:18 

#10 
New Member
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 6 
Hi Ghost/Daniel,
Regarding my last question, if you try running the UDF, it interprets, but the value it gives is incorrect, can simply be checked using a calculator. Can you explain why? Makes no sense to me. K 

June 5, 2012, 09:02 

#11  
Senior Member
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 910
Rep Power: 15 
Quote:
I'm not an expert in udf..but aren't you assigning a constant velocity with this equation?? /* Write Profile in x */ Velocity_Profile = Anode*(i/(2*F))/(P_anode/(R*T); Daniele 

June 5, 2012, 10:13 

#12 
New Member
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 6 
Hi Daniele,
Yeah its constant, my supervisor wants me to write it to be able to change the current density value later on (when I get it to work). I actually got the code to work properly though, the reason for the mistake was that fluent doesnt understand 10^10, only 1e10, stupid error but thanks for the reply. On the topic of fluent, I am writing a UDF to define a sink term in the catalyst zone of my domain (consisting of 3 zones). However, I need to specify a flux with the following units(kg/m3.sec). I am not sure whether to divide my mass flow(kg/sec) by total catalyst domain volume or a the volume of a single element. I would think its the volume of the entire domain and then fluent calculates the kg/sec value by multiplying by the volume of a single element and summing that over the domain. 

Tags 
profile, udf 
Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
UDF error  parabolic velocity profile  3D turbine  Zaqie  Fluent UDF and Scheme Programming  8  May 11, 2014 08:34 
please help UDF for velocity profile in ydirectio  raju  FLUENT  3  September 22, 2008 16:36 
UDF: PROFILE + SOURCE  Nuno  FLUENT  0  September 1, 2008 15:31 
Seek help in writing UDF  Jack Martinez  FLUENT  9  June 14, 2007 10:24 
New to writing UDF  Sandilya  FLUENT  0  May 31, 2007 12:03 