CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF writing: parabolic profile (http://www.cfd-online.com/Forums/fluent-udf/99704-udf-writing-parabolic-profile.html)

Kwiaci April 10, 2012 02:57

UDF writing: parabolic profile
 
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)
}

coglione April 10, 2012 04:49

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

Kwiaci April 10, 2012 06:54

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?

Daniel Tanner April 10, 2012 10:23

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)
/****************************/
/****************************/
}

kitrax May 23, 2012 12:26

Help, unable to interpret
 
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;
}

Daniel Tanner May 28, 2012 07:36

Velocity_Profile = Anode*(i/(2*F))/(P_anode/(R*T) is missing a bracket.

kitrax May 29, 2012 04:21

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

ghost82 May 29, 2012 05:37

Quote:

Originally Posted by kitrax (Post 363525)
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)

kitrax May 29, 2012 06:24

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 June 5, 2012 08:18

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

ghost82 June 5, 2012 09:02

Quote:

Originally Posted by kitrax (Post 364820)
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

kitrax June 5, 2012 10:13

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.


All times are GMT -4. The time now is 07:50.