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

UDF writing: parabolic profile

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 10, 2012, 02:57
Default UDF writing: parabolic profile
  #1
Member
 
Robert
Join Date: Mar 2011
Location: Warsaw
Posts: 62
Rep Power: 15
Kwiaci is on a distinguished road
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)
}
Kwiaci is offline   Reply With Quote

Old   April 10, 2012, 04:49
Default
  #2
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
No, it does not. Define x as a vector having three components --> x[0] will give you x-coordinate, x[1] y-coord and x[2] z-coordinate.
cheers

cheers
coglione is offline   Reply With Quote

Old   April 10, 2012, 06:54
Default
  #3
Member
 
Robert
Join Date: Mar 2011
Location: Warsaw
Posts: 62
Rep Power: 15
Kwiaci is on a distinguished road
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?
Kwiaci is offline   Reply With Quote

Old   April 10, 2012, 10:23
Default
  #4
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 17
Daniel Tanner is on a distinguished road
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)
/****************************/
/****************************/
}
Daniel Tanner is offline   Reply With Quote

Old   May 23, 2012, 12:26
Default Help, unable to interpret
  #5
New Member
 
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 15
kitrax is on a distinguished road
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;
}
kitrax is offline   Reply With Quote

Old   May 28, 2012, 07:36
Default
  #6
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 17
Daniel Tanner is on a distinguished road
Velocity_Profile = Anode*(i/(2*F))/(P_anode/(R*T) is missing a bracket.
Daniel Tanner is offline   Reply With Quote

Old   May 29, 2012, 04:21
Default
  #7
New Member
 
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 15
kitrax is on a distinguished road
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 c-files due to not being able to install microsoft visual studio.

Thanks
kitrax is offline   Reply With Quote

Old   May 29, 2012, 05:37
Default
  #8
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26
ghost82 will become famous soon enough
Quote:
Originally Posted by kitrax View Post
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 c-files due to not being able to install microsoft visual studio.

Thanks
Yes you can, but be sure that your macros can run if interpreted and not compiled (for example, udfs for body motion have to be compiled)
ghost82 is offline   Reply With Quote

Old   May 29, 2012, 06:24
Default
  #9
New Member
 
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 15
kitrax is on a distinguished road
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 post-processing. I am looking at the concentration change of hydrogen and I want to compare my 3-D results with a 1-D model, so i just want to look at the concentration change in the z-axis.

To do this I am using X-Y plot in fluent. I set my y-axis function as the concentration of H2 and my x-axis function as my direction vector (z-axis direction in this case). However, I dont get a single concentration profile, but multiple points.

Doesnt make any sense as the the 3-D solution and a slice in the axis of interest looks correct.

can you help
kitrax is offline   Reply With Quote

Old   June 5, 2012, 08:18
Default
  #10
New Member
 
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 15
kitrax is on a distinguished road
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
kitrax is offline   Reply With Quote

Old   June 5, 2012, 09:02
Default
  #11
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26
ghost82 will become famous soon enough
Quote:
Originally Posted by kitrax View Post
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
Hi,
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
ghost82 is offline   Reply With Quote

Old   June 5, 2012, 10:13
Default
  #12
New Member
 
karthik
Join Date: Oct 2010
Posts: 14
Rep Power: 15
kitrax is on a distinguished road
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 1e-10, 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.
kitrax is offline   Reply With Quote

Reply

Tags
profile, udf


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
please help UDF for velocity profile in y-directio raju Fluent UDF and Scheme Programming 6 April 12, 2019 23:21
UDF error - parabolic velocity profile - 3D turbine Zaqie Fluent UDF and Scheme Programming 9 June 25, 2016 19:08
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


All times are GMT -4. The time now is 18:51.