CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   (ask) how to create UDF for inlet velocity profile (https://www.cfd-online.com/Forums/fluent-udf/86275-ask-how-create-udf-inlet-velocity-profile.html)

sincity March 18, 2011 07:38

(ask) how to create UDF for inlet velocity profile
 
hi all
i have a question
what should i do if i wanna go to use UDF for my inlet velocity profile 3D case
how can i define it
just a simple question, hope it will be answered by you.regards

Amir March 18, 2011 07:49

Hi,
refer to DEFINE_PROFILE macro in UDF-manual.

sincity March 18, 2011 08:34

hi amir thanks for attention
actually the UDF manual is not helping me at all because i want to create UDf for 3D case inlet velocity profile, but i dont know how to define the velocity function in 3D vector (x,y,z)
maybe you have some tutorial or case example??regards.

Amir March 18, 2011 09:44

Hi Wibi,
here's a example for fully developed flow in a pipe:
Code:

#include "udf.h"
#define Q 1.5625e-5  //unit m3/sec
#define Diameter 4.5e-3  //unit m
DEFINE_PROFILE(axialVelocity,t,i)
{
    real x[ND_ND];
    real r,Area;
    face_t f;
    Area=(M_PI/4.0)*pow(Diameter,2);
    begin_f_loop(f,t)
    {
        F_CENTROID(x,f,t);
        r=sqrt(pow(x[0],2)+pow(x[1],2));
        F_PROFILE(f,t,i)=(2.0*Q/Area)*(1-pow(2.0*r/Diameter,2));
    }
    end_f_loop(f,t)
}


sincity March 18, 2011 10:49

mmm...is it UDF for 3D case amir??

Amir March 18, 2011 13:07

Quote:

Originally Posted by sincity (Post 300064)
mmm...is it UDF for 3D case amir??

it computes axial velocity magnitude in a pipe(z-direction) as a function of x & y.
you can also define three UDFs for each velocity components that are similar to above. it depends on the method that you want to set velocity in B.C. panel; magnitude normal or components.

sincity March 18, 2011 23:32

amir my friend,
i am very confuse about what were you talking about, since i'm new user for UDF
so i hope you have more time to explain about this topic.
amir in defining UDF should i plot my velocity data first to get the function
or just go straight use your UDF example that you gave to me?
please answer.regards

Amir March 19, 2011 08:51

Ok,
first you should decide what kind of velocity declaration you want to use.(in B.C. panel) e.g. you can use velocity magnitude normal to plane or setting individual velocity components. without UDF, you can set constant values for them in GUI.
but for your case that three components change with coordinates(I think), you should write 3 UDF for velocity components and declare them as functions of x,y,z and hook them in respective places. it's obvious that you should have velocities as functions of x,y,z.
if you post your velocity function, I may help you more.

regards,

Amir

sincity March 20, 2011 23:44

its going converging.. my question is i have no idea about that velocity function, that's what i want to talk about you. how can i extract my own velocity function, especially in my 3D case??

Amir March 21, 2011 03:01

if your inlet velocity profile is obtained from another FLUENT calculation, it's easy to handle. else you need to use other post processing softwares like MATLAB or others to fit functions to them and then use obtained functions in UDFs.

sincity March 21, 2011 03:31

could i just adapting the function from another velocity function and put it on my UDF??maybe your function? or maybe any general form of function that i could use

Amir March 21, 2011 03:36

you can use any forms of explicit functions in UDfs.
e.g.:
V_x=V_x(x,y,z),....

wangy16 November 16, 2011 17:41

Quote:

Originally Posted by Amir (Post 300294)
if your inlet velocity profile is obtained from another FLUENT calculation, it's easy to handle. else you need to use other post processing softwares like MATLAB or others to fit functions to them and then use obtained functions in UDFs.

Can you tell me how to extract the 3D velocity profile from another FLUENT calculation and load the velocity file as the input? I don't know how to get the velocity file. I read some tutorial saying the velocity file can be obtained as a file format of "XY".

Amir November 17, 2011 02:40

Quote:

Originally Posted by wangy16 (Post 332416)
Can you tell me how to extract the 3D velocity profile from another FLUENT calculation and load the velocity file as the input? I don't know how to get the velocity file. I read some tutorial saying the velocity file can be obtained as a file format of "XY".

Hi,

you can use (file->write->profile) in your previous results and the use (file->read->profile) in new case. (for more info, refer to manual)

Bests,

wanna88 November 22, 2011 05:46

Hi,

My project is to perform CFD analysis on dissecting aneurismal aorta.

I have to create pulsatile inlet velocity and pulsatile outlet pressure waveform at inlet and outlet of the aorta respectively.

The example of pulsatile inlet velocity is as shown in the link below
http://www.google.com.my/imgres?q=Ti...Wl_WbBw&zoom=1

May I know how to define this type of graph using UDF?

Thank you so much

Amir November 22, 2011 07:39

Quote:

Originally Posted by wanna88 (Post 333062)
Hi,

My project is to perform CFD analysis on dissecting aneurismal aorta.

I have to create pulsatile inlet velocity and pulsatile outlet pressure waveform at inlet and outlet of the aorta respectively.

The example of pulsatile inlet velocity is as shown in the link below
http://www.google.com.my/imgres?q=Ti...Wl_WbBw&zoom=1

May I know how to define this type of graph using UDF?

Thank you so much

Hi,

you have 2 choices:
1) you can prepare a file with special format which defines desires parameter at different time; it this method, you cannot specify spacial variation. (you can find further explanation in manual in setting unsteady BCs)
2) you can fit functions for different segments and write a UDF for it; this method doesn't have ant restrictions in special declaration.

Bests,

wanna88 November 22, 2011 20:59

2) you can fit functions for different segments and write a UDF for it; this method doesn't have ant restrictions in special declaration.

May I know in details what is mean by fir functions for different segments and write a UDF for it?


Thank you.

REgards,
Naimah

Amir November 23, 2011 04:57

Quote:

Originally Posted by wanna88 (Post 333193)
2) you can fit functions for different segments and write a UDF for it; this method doesn't have ant restrictions in special declaration.

May I know in details what is mean by fir functions for different segments and write a UDF for it?


Thank you.

REgards,
Naimah

In UDFs, you have to declare parameter variations via functions, so you can digitize your graph and then find a functions which fit to your discrete data; for this purpose, it's better to fit different functions for different segments for better accuracy but it's straight forward.

Bests,

wanna88 December 5, 2011 04:12

Hi Amir,

May I know how to do post processing in FLUENT?

For example I would like to see the plotted graph (pressure/velocity) vs time.
Besides, how to get the data for cross sectional area at certain parts of geometry at certain time?

Thank you.

Regards,
Naimah

Amir December 5, 2011 08:53

Quote:

Originally Posted by wanna88 (Post 334640)
Hi Amir,

May I know how to do post processing in FLUENT?

For example I would like to see the plotted graph (pressure/velocity) vs time.
Besides, how to get the data for cross sectional area at certain parts of geometry at certain time?

Thank you.

Regards,
Naimah

Dear Naimah,

It depends, e.g. if you want to have pressure or velocity in a specified point, you can use "solve->monitor->surface ...."; if you didn't activate it before iteration, you have to write a simple journal file for this purpose.
For extracting data of cross-sections; firstly you need to generate these cross-sections in "surface->quadratic or plane" then you can export desired data to other post processors in "file->export". But if you want to export these data for successive time steps; you have to choices: 1) there is such capability in ver. 13 in "file-> export" I think. 2) you can write a journal file to do what you want during iteration.

Bests,

wanna88 December 7, 2011 04:23

Quote:

Originally Posted by Amir (Post 334682)
Dear Naimah,

It depends, e.g. if you want to have pressure or velocity in a specified point, you can use "solve->monitor->surface ...."; if you didn't activate it before iteration, you have to write a simple journal file for this purpose.
For extracting data of cross-sections; firstly you need to generate these cross-sections in "surface->quadratic or plane" then you can export desired data to other post processors in "file->export". But if you want to export these data for successive time steps; you have to choices: 1) there is such capability in ver. 13 in "file-> export" I think. 2) you can write a journal file to do what you want during iteration.

Bests,


Dear Amir,

Thank you for the info.
Since I m a new user of FLUENT, may I know how to get to this command
"surface->quadratic or plane"

Is this thing read the result at the cross section?

Besides, what is mean by read to journal file? I have tried to read data at certain interval that I set up. However, It come out with a lot of nodes number at 1 time interval. may I know how to extract this data?

Thank you so much for your help.

Regards,
Naimah

Amir December 7, 2011 05:28

Quote:

Originally Posted by wanna88 (Post 334971)
Since I m a new user of FLUENT, may I know how to get to this command
"surface->quadratic or plane"
Is this thing read the result at the cross section?

You need to create desired cross-sections for post processing; for this purpose, from the surface tab you can select either quadratic or plane that are two different way to create these cross-sections. When you create these cross-sections, the data are interpolated automatically for them.
Quote:

Originally Posted by wanna88 (Post 334971)
Besides, what is mean by read to journal file? I have tried to read data at certain interval that I set up. However, It come out with a lot of nodes number at 1 time interval. may I know how to extract this data?

Journal files are simple tools to automate what we need in FLUENT; I'm not sure that I understand your goal, but with this tool you can do any post processing with several case and data files. I may help if I know what exactly you need to do.

Bests,

wanna88 December 7, 2011 05:49

Quote:

Originally Posted by Amir (Post 334988)
You need to create desired cross-sections for post processing; for this purpose, from the surface tab you can select either quadratic or plane that are two different way to create these cross-sections. When you create these cross-sections, the data are interpolated automatically for them.

Journal files are simple tools to automate what we need in FLUENT; I'm not sure that I understand your goal, but with this tool you can do any post processing with several case and data files. I may help if I know what exactly you need to do.

Bests,

Dear Amir,

My project is to perform CFD simulation for aortic dissecting aneurysm.

I would like to see what happen in the geometry at particular time and location (cross section). To see how it changes from certain time to time.

Therefore, I need to see the plot at different part of the aorta.

Thank you

Regards,
Naimah

Amir December 7, 2011 09:41

Quote:

Originally Posted by wanna88 (Post 334991)
Dear Amir,

My project is to perform CFD simulation for aortic dissecting aneurysm.

I would like to see what happen in the geometry at particular time and location (cross section). To see how it changes from certain time to time.

Therefore, I need to see the plot at different part of the aorta.

Thank you

Regards,
Naimah

Ok, if you want to have contours of desired variables and you haven't run the case ans also use FLUENT 13 or newer, there's an option for transient exporting data @ specified surfaces, but if this is not the case, i.e. you've run your case or you may want some graphs not contours I think the only way is using journal file. For example, do what you want via text user interface in FLUENT, when you find a correct commands, you'll need a journal generator; which can be a simple program with any language that can expand the text user interface commands for transient data files which are saved before. For more info, you can refer to user and TUI guides.

Bests,

wanna88 December 8, 2011 23:44

Dear Amir,

Thank you so much for the info.
I still working on it.

However, may i ask you question regarding how fluent function?
Based on tutorial 4 : modeling compressible transient flow

A steady state solution is run first before it used as the initial condition for transient.
In the tutorial, after simulation for steady state is done, the next steps is to change the time from steady to transient.

May I know how the software function/how the software read the result from steady state solution to be used as input/initial condition for transient simulation.

I believe it is not just a simple click by changing the steady to transient.

Thank you.

Regards,
Naimah

Amir December 9, 2011 02:54

Quote:

Originally Posted by wanna88 (Post 335223)
Dear Amir,

Thank you so much for the info.
I still working on it.

However, may i ask you question regarding how fluent function?
Based on tutorial 4 : modeling compressible transient flow

A steady state solution is run first before it used as the initial condition for transient.
In the tutorial, after simulation for steady state is done, the next steps is to change the time from steady to transient.

May I know how the software function/how the software read the result from steady state solution to be used as input/initial condition for transient simulation.

I believe it is not just a simple click by changing the steady to transient.

Thank you.

Regards,
Naimah

Dear Naimah,

In contrast to your belief, it's done by simply changing steady to unsteady solver in current case. ;)
I other words, FLUENT uses any data stored in computational domain which can be provided via direct initialization or any previous simulations as initial condition .... (Also, you can use results of one case for initialization of other case; for this purpose, you need to use "file->interpolate")

Bests,

wanna88 December 30, 2011 03:15

Dear Amir,

Thank you so much for the info.

I have another questions regarding the Fluent.

1. I have set the value at inlet boundary condition at : velocity inlet : 0.175 m/s
At the solution initialization when I click compute from inlet, it will give diffrence value:

Initial value:
Gauge pressure : 0 Pa
X velocity :- 0.036 m/s
Y velocity: -0.0053 m/s
Z velocity : 0.165821 m/s

Why it give difference value? Are these value initial guess calculated by the Fluent?

2. Can I used different types of Solution methods for transient and steady case for the same case:

Transient : PISO and second order upwind
Steady : SIMPLE and first order upwind


REgards,
Naimah

Amir December 30, 2011 05:29

Hi,

1) Maybe you've set the velocity magnitude normal to the boundary and FLUENT computes its projections in required direction. I don't think this would be an important issue; this is just an initial guess which improved later.

2) Note that PISO, SIMPLE and ... are pressure velocity coupling methods and can be used with other interpolation schemes such as first order, .... Obviously, you cannot use 2 velocity-pressure coupling methods simultaneously! but you can use them separately and may used as initial values for others. Note that you can also use "SIMPLE and first order upwind" for transient and vice versa; although, the PISO algorithm is more preferable for unsteady simulations. (for more info regarding algorithms and schemes you can refer to the user manual)

Bests,

wanna88 January 4, 2012 03:35

Hi Amir,

Thank you very much for the info.

May I ask some more questions?
I have real image from CT scan data.
After smoothing, the inner part that I want to evaluate is lose.
Therefore I would like to create this part in Design Modeler in ANSYS.
Can it be done?

Thank you.

Regards,
Naimah

Amir January 4, 2012 08:14

Quote:

Originally Posted by wanna88 (Post 337794)
Hi Amir,

Thank you very much for the info.

May I ask some more questions?
I have real image from CT scan data.
After smoothing, the inner part that I want to evaluate is lose.
Therefore I would like to create this part in Design Modeler in ANSYS.
Can it be done?

Thank you.

Regards,
Naimah

Dear Naimah,

I'm not sure it can be done via ANSYS Design Modeler. I heard mimics software can process these data for importing to grid generator softwares but I don't have further info in this field.

Bests,

wanna88 February 14, 2012 22:50

Axial velocity
 
1 Attachment(s)
Hi Amir,


I would like to ask several questions regarding how to define and plot the axial velocity and how to define the rotation axis direction in Cell Zone Condition.

Herewith I attached the figures that showed the plane in a curved tube.
Based on my understanding, I need to define the rotation axis direction for the flow to select the axial velocity. Is it correct?

How Im going to determine the rotation axis direction in the curved plane as per attached file? the rotation axis direction is not 90 degree (perpendicular) to the plane.
How Im going to take/Define the result of axial velocity?

Looking forward for your feedback.

Thank you so much.

naimah

ghost82 February 15, 2012 07:56

Quote:

Originally Posted by wanna88 (Post 344497)
Hi Amir,


I would like to ask several questions regarding how to define and plot the axial velocity and how to define the rotation axis direction in Cell Zone Condition.

Herewith I attached the figures that showed the plane in a curved tube.
Based on my understanding, I need to define the rotation axis direction for the flow to select the axial velocity. Is it correct?

How Im going to determine the rotation axis direction in the curved plane as per attached file? the rotation axis direction is not 90 degree (perpendicular) to the plane.
How Im going to take/Define the result of axial velocity?

Looking forward for your feedback.

Thank you so much.

naimah

Hi!
I think you can create a custom field function in fluent (http://hpce.iitm.ac.in/website/Manua...g/node1364.htm) to decompose for example the x velocity into a velocity perpendicular to your plane (use sin and cos).

Daniele

Roby_1986 February 15, 2013 07:31

UDF_logarithmic velocity profile
 
Hi everybody,
I'm studying, with Fluent, the model shown in the attached image.
I've to impose a loarithmic velocity profile at the upwind boundary, that is:
U(h)=Uo/k*ln(h/ho)
where: Uo= 1,068 m/s
ho=o,005 m
k=0,41 (-)

The questions are two:

1)In setting the boundary conditions,I've to select, for the upwind face, a UDF velocity profil (created on the basis of the formula: U(h)=Uo/k*ln(h/ho)). While, for the other three faces, which are also inlet faces, I have to select the same UDF or to create other ones?

2)I've imposted a possible code for UDF, that is:

#include "udf.h"

#DEFINE Uo 1,068 //unit m/s
#DEFINE k 0,41
#DEFINE ho 0,005 //unit m

DEFINE_PROFILE(inlet_x_velocity,t,i)
{
real x[ND_ND];
real y;
face_t f;

begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y = x[1];
F_PROFILE(f,thread,index) = Uo/k*log(y/ho);
}
end_f_loop(f,t)
}

Is it correct in your opinion?
I've never programmed in C language, so I don't know how to crate a UDF file, for loading it in FLUENT. Someone could please tell me how to do this?
Or, eventually, could I copy the code directly within command lines of fluent?

Thanks

Amir February 15, 2013 09:02

Quote:

Originally Posted by Roby_1986 (Post 408015)
Hi everybody,
I'm studying, with Fluent, the model shown in the attached image.
I've to impose a loarithmic velocity profile at the upwind boundary, that is:
U(h)=Uo/k*ln(h/ho)
where: Uo= 1,068 m/s
ho=o,005 m
k=0,41 (-)

The questions are two:

1)In setting the boundary conditions,I've to select, for the upwind face, a UDF velocity profil (created on the basis of the formula: U(h)=Uo/k*ln(h/ho)). While, for the other three faces, which are also inlet faces, I have to select the same UDF or to create other ones?

2)I've imposted a possible code for UDF, that is:

#include "udf.h"

#DEFINE Uo 1,068 //unit m/s
#DEFINE k 0,41
#DEFINE ho 0,005 //unit m

DEFINE_PROFILE(inlet_x_velocity,t,i)
{
real x[ND_ND];
real y;
face_t f;

begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
y = x[1];
F_PROFILE(f,thread,index) = Uo/k*log(y/ho);
}
end_f_loop(f,t)
}

Is it correct in your opinion?
I've never programmed in C language, so I don't know how to crate a UDF file, for loading it in FLUENT. Someone could please tell me how to do this?
Or, eventually, could I copy the code directly within command lines of fluent?

Thanks

Dear Roberta,

1) Yes, you can hook this UDF to all three faces (like aerodynamic examples)
2) Your UDF needs few modifications, try this:
Code:

#include "udf.h"

#define Uo 1.068    //unit m/s
#define k 0.41
#define ho 0.005    //unit m

DEFINE_PROFILE(inlet_x_velocity,t,i)
{
  real x[ND_ND];
  real y;
  face_t f;

  begin_f_loop(f,t)
  {
      F_CENTROID(x,f,t);
      y = x[1];
      F_PROFILE(f,t,i) = Uo/k*log(y/ho); 
  }
  end_f_loop(f,t)
}

3) You can interpret such simple UDFs, however, you can also compile it via extra C++ compiler on your system. Refer to my blog here for further tips in this regard.

Bests,

Roby_1986 February 15, 2013 10:24

Dear Amir,
Thanks for the corrections.
Someone else has suggested to me to set the top, left and right faces as symmetry boundary conditions.
But I can't understand what this means. I should not have a symmetry with respect to anything?
Someone said that: "the problem with inlet BCs at the side walls is that the flow should be perpendicular to the face. In my case, the velocity is tangential to the surface. A symmetry boundary condition (zero shear stress) is the usual way to model such a boundary".

I've seen that setting the boundary conditions at the other 3 faces, besides the upwind one, I can choose, within Velocity Inlet, the option "Magnitude and Direction" and, as Reference frame, the option "Relative to adjacent cell zone", and then select the UDF inlet_x_velocity as Velocity Magnitude.
What do you think about this way?Should be more correct to use Symmetry BC, rather than velocity inlet?In which way?

Finally, as regard the definition of UDF, since I don't have basis of C programmation, I've seen that I can write these simple boundary conditions in a txt file, then save it as c.file and intrerpret it in fluent.


Thanks a lot.
Bests

Amir February 15, 2013 10:58

Quote:

Originally Posted by Roby_1986 (Post 408061)
What do you think about this way?Should be more correct to use Symmetry BC, rather than velocity inlet?In which way?

You know, it depends on your case, to be more precise:
- Setting U velocity means: Specific U velocity, Zero lateral velocities
- Setting Symmetry BC means: Zero shear stress, Zero lateral velocity (There is not any constrain on tangential velocity magnitude)
If you're modelling a building among others, the symmetry bc in better but if it's the only building in a rather large domain, I suggest velocity bc. As I said this is a common choice in aerodynamic cases in incompressible flow field too where we want to set bc around a single wing.
Quote:

Originally Posted by Roby_1986 (Post 408061)
Finally, as regard the definition of UDF, since I don't have basis of C programmation, I've seen that I can write these simple boundary conditions in a txt file, then save it as c.file and intrerpret it in fluent.

Yah, this is the best approach for such UDFs.

Do not hesitate to ask if it's not clear or face any difficulties.

Bests,

Roby_1986 February 26, 2013 04:55

Dear Amir,
I've done some simulations with the different boundary conditions, already discussed in the previous post.
Finally my BC are:
On the frontal face of the huge air parallelepiped: inlet velocity with a UDF imposing a velocity profile changing with a log-law.
On the upper and side faces of the huge air parallelepiped: inlet velocity with the same UDF on x direction
On the back face of the huge domain: pressure outlet=0
On the building walls, there is no slip and a roughness height=0 and roughness constant=0.5.
While the basis of the huge air parallelepiped is a wall, with no slip and a roughness height of 5*10^(-5) and a roughness constant=0.5.
Then, I've a k-epsilon RNG model, with Standard Wall Function It=4% and Lt=0.4 m
Now, I've to calculate a Volume flow rate on an opening, located on the front wall of the building, so while meshing I've created a name selection on the surface of this opening, which is set as "Interior"on boundary condition in Fluent.
The problem is that I obtain a Volume flow rate too small, and I can't understand the reason.
The model converges, the mass conservation is respected. I've tried to change BC on the upper and side faces of the domain, to eliminate the roughness on the basis but nothing changes.
What could be the problem?
Thanks a lot

ghost82 February 26, 2013 05:05

Quote:

Originally Posted by Roby_1986 (Post 410145)
Dear Amir,
I've done some simulations with the different boundary conditions, already discussed in the previous post.
Finally my BC are:
On the frontal face of the huge air parallelepiped: inlet velocity with a UDF imposing a velocity profile changing with a log-law.
On the upper and side faces of the huge air parallelepiped: inlet velocity with the same UDF on x direction
On the back face of the huge domain: pressure outlet=0
On the building walls, there is no slip and a roughness height=0 and roughness constant=0.5.
While the basis of the huge air parallelepiped is a wall, with no slip and a roughness height of 5*10^(-5) and a roughness constant=0.5.
Then, I've a k-epsilon RNG model, with Standard Wall Function It=4% and Lt=0.4 m
Now, I've to calculate a Volume flow rate on an opening, located on the front wall of the building, so while meshing I've created a name selection on the surface of this opening, which is set as "Interior"on boundary condition in Fluent.
The problem is that I obtain a Volume flow rate too small, and I can't understand the reason.
The model converges, the mass conservation is respected. I've tried to change BC on the upper and side faces of the domain, to eliminate the roughness on the basis but nothing changes.
What could be the problem?
Thanks a lot

Maybe your grid is too coarse?
What is the calculated value and the real one?

Roby_1986 February 26, 2013 17:57

Hi everybody,
Probably the problem is not the mesh but the boundary conditions. I want to try to separate the outdoor air domain (the huge air parallelepiped) and the internal building air domain, setting the building window not as "interior" but as velocity inlet or pressure inlet for the domain constitutes of the interior air.
This might be correct in your opinion?
My aim is to evaluate the volume flow rate on the building window.
Thanks a lot

mesh_generation April 11, 2013 03:26

Dear Sir
I am working on fluent for last one year. I am familier with C++ and MATLAB. In writing UDF for inlet boundary or for moving wall I feel difficulty. From last few weeks only due to one error in my code I can not proceed further. Please help me or contact me on my personal mail id so we can discuss in detail:

my mail id is
: ashutoshverma194@ymail.com
vermaashutosh143@gmail.com


All times are GMT -4. The time now is 11:47.