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

udf problem

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 4 Post By RoM

Reply
 
LinkBack Thread Tools Display Modes
Old   October 26, 2005, 04:57
Default udf problem
  #1
jane
Guest
 
Posts: n/a
this is my udf code. #include "udf.h" # define domain_ID 8 DEFINE_ON_DEMAND(demo_calc) { float tavg = 0.; float temp,volume,vol_tot; Thread *t; cell_t c; Domain* domain; domain = Get_Domain(domain_ID); thread_loop_c(t,domain) { begin_c_loop(c,t) { volume = C_VOLUME(c,t); temp = C_T(c,t); vol_tot += volume; tavg += temp*volume;} end_c_loop(c,t) tavg /= vol_tot; C_UDMI(c,t,0) =tavg; } }

DEFINE_PROFILE(inlet_temperature,thread,position) {Thread *t; cell_t c;

face_t f; begin_f_loop(f,thread)

{

F_PROFILE(f,thread,position)=C_UDMI(c,t,0)-8;

} end_f_loop(f,thread) }

i built UDF library and hooked the UDF(define->user defined->function->compiled) successfully. Then i defined UDM to 1. at last, i tried to hook DEFINE_ON_DEMAND(define->user defined->executed on demand) ,but i failed. and the following message came.

FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: ()

any help and advisor are appreciated. thank you. i need your help.
  Reply With Quote

Old   October 26, 2005, 05:30
Default Re: udf problem
  #2
RoM
Guest
 
Posts: n/a
Some suggestions

1. Dont use "float" (or "double") to define real variables. Use "real" instead.

2. Reserve at least one UDM (define->user-defined->memory).

3. Are you absolutly shure your domain id is 8? The ID values shown in the bc panel are not domain IDs, they are thread IDs. If you are not in multiphase you should use d=Get_Domain(1).

Hope this helps

RoM
  Reply With Quote

Old   October 27, 2005, 04:26
Default Re: udf problem
  #3
jane
Guest
 
Posts: n/a
thank you very much, Rom. you really help me a lot. but i am still confused. could you answer me other several questions?

1. does Reserving one UDM mean to set the number 1 at define->user-defined->memory ? 2.in the formula, d=Get_Domain(1),what is the d?

3. can you give me an example of thread IDs? i donot know how to use it at all.

i appreciate your help.
  Reply With Quote

Old   October 27, 2005, 06:04
Default Re: udf problem
  #4
RoM
Guest
 
Posts: n/a
Reserving one memory means setting the value
in define->user-define->memory... panel to 1.


Unfortunatly data types in fluent are not very well documented and lots of errors
(ACCESS VIOLATIONS) occur due to wrong handling of the data. For single phase
problem the data structure in fluent looks like this

Domain-->Threads--->cell threads (fluid/solid)
|
---->face threads (usually boundary faces)

The Domain is the top of you data structure and there is only one domain in
single phase flows. It can be accessed with

Domain* d;
d=Get_Domain(1);

Inside your domain, data are organized in threads. A thread is collection of
cells (cell thread) or faces (face thread) that have something in common. For
example all faces that form a specific boundary are grouped together in one face
thread (you could call this thread a boundary face thread).

Lets consider a simple 3d pipe with one inlet (face thread), one outlet
(face thread), a wall (face thread) and one fluid zone (cell thread). The
structure in fluent will look like this

Domain-->Threads--->fluid zone cell thread
(Pipe) |
|--->inlet face thread
|--->outlet face thread
|--->wall face thread

To access threads you have two options. You will have a good time if fluent
will provide the right thread pointer for you like in the
DEFINE_PROFILE(name,thread,position) where thread will be a the face thread
for the boundary your profile function is hooked in.

If fluent is not that nice (like in a ON_DEMAND function) you will have to get
the thread you want with the Lookup_Thread function. For this function you will
need the domain pointer from above and the ID of your thread. To get the ID open
the bc panel, click on wall or fluid/solid zone and the ID number is shown in
the lower right corner. Now you can access the thread with

Thread* t;
t=Lookup_Thread(d,ID);

It is important to notice, that the thread pointer is a generic type. It can
point to cell threads or face threads. If you try to use a face thread pointer
in a funtion that requires a cell thread (or vice versa) you will produce a nice
access violation. So make always shure your thread pointer is of the right type.
If you are not shure about a thread you can get its ID with

int id;
id=THREAD_ID(t);

and compare with the number in the bc panel.

Now to your udf

#include "udf.h"

DEFINE_ON_DEMAND(demo_calc)
{
real tavg;
real temp,volume,vol_tot;
Domain* domain;
Thread* t;
cell_t c;

tavg=0.;
vol_tot=0.;
domain = Get_Domain(1); /* there is only one domain */

/* loop over all cell threads in your domain, if you have only one cell
thread in your domain (eg. only one fluid zone) the loop will be perfomed
only once */
thread_loop_c(t,domain)
{
/* loop over all cells within the cell thread where c is just an
integer number, enumerating the cells. If your thread holds for
instance 100 cells the loop wil be perfomed 100 times, each time
c is increased by one starting from zero */
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t);
temp = C_T(c,t);
vol_tot += volume;
tavg += temp*volume;
}
end_c_loop(c,t)
tavg /= vol_tot;
}
Message("Tavg=%g",tavg);

/* Now that we have calculated the the average temperature we need to
store it. Since UDMs are associtated with cells we need two additional loops
to store the value in each cell */

/* again loop over all cell threads */
thread_loop_c(t,domain)
{
/* loop over all celss within thread */
begin_c_loop(c,t)
{
/* store value */
C_UDMI(c,t,0)=tavg;
}
end_c_loop(c,t)
}

/* Be sure to verify the result with a contour plot of UDM-0 */
}

Now the profile. First your version

DEFINE_PROFILE(inlet_temperature,thread,position)
{
face_t f;
cell_t c;

begin_f_loop(f,thread)
{
F_PROFILE(f,thread,position)=C_UDMI(c,thread,0)-8;
}
end_f_loop(f,thread)
}

Its a nice example on and udf that compiles well and the crahses horrible. What
happened? The thread passed by fluent and used in the face looping macro is face
thread. If you try to use this face thread to access cell data with
C_UDMI(c,thread,0) you get a nice access violation. To access the cell data you
need first the cell thread for the cell that is associated with the face.

DEFINE_PROFILE(inlet_temperature,thread,position)
{
face_t f;
Thread *c0_thread;
cell_t c0;
real tavg;

/* loop over all faces within thread */
begin_f_loop(f,thread)
{
/* get the cell thread and cell number for the adjancent cell */
c0_thread=THREAD_T0(thread);
c0=F_C0(f,thread);
/* get tavg from the cell memory */
tavg=C_UDMI(c0,c0_thread,0);
/* set the profile to tavg-8 */
F_PROFILE(f,thread,position)=tavg-8.;
}
end_f_loop(f,thread)
}


Hope this helps

RoM
  Reply With Quote

Old   October 29, 2005, 05:05
Default Re: udf problem
  #5
jane
Guest
 
Posts: n/a
dear RoM, thanks for your help. you really helped me a lot. i did the work according to your suggestions. i devided the code to several parts and tried bit by bit.

this is one of my programme:

#include "udf.h" DEFINE_ON_DEMAND(demo_calc) { real tavg; real temp,volume,vol_tot; Domain *domain; Thread *t; cell_t c;

tavg=0.; vol_tot=0.; domain = Get_Domain(1); t=Lookup_Thread(domain,8); begin_c_loop(c,t) { volume = C_VOLUME(c,t); temp = C_T(c,t); vol_tot += volume; tavg += temp*volume; } end_c_loop(c,t) tavg /= vol_tot;

Message("Tavg=%g",tavg);

}

It is compiled and loaded successfully. when i tried to execute it (define->user-defined -> execute on demand), i failed. could you tell me why. i am really comfused. thank you very much.
  Reply With Quote

Old   October 29, 2005, 14:04
Default Re: udf problem
  #6
RoM
Guest
 
Posts: n/a
The only reason your udf should crash is, if the thread id (8) is not an cell thread. Please check in the bc panel if you fluid zone got the id 8. If 8 is the id of a boundary (wall, inlet outlet, etc.) the udf will crash.

Good Luck

RoM

  Reply With Quote

Old   October 30, 2005, 21:43
Default Re: udf problem
  #7
Jane
Guest
 
Posts: n/a
Dear RoM, you really hit the points. thank you very much. you are really helpful. i have solved the problem.

now i have other questions.

1. could you tell me the diference between facet average and vertex average? 2. in the iterate panel, is setting Time step size 60 and max iteration per time step 20 the same as setting them 3 and 1 respectively?

sorry to bother you.

  Reply With Quote

Old   November 1, 2005, 02:36
Default Re: udf problem
  #8
RoM
Guest
 
Posts: n/a
No need to be sorry and you dont bother me.

1. A Surface is build from small faces (facets) and you can calculate the facet average for a vaule X from sum over all facet values/number of facets. Vertex (or node) average is defined similar as sum over all vertex values/number of vertice. The governing equations for postprocessing values can be found in chapter 30 user guide (fluent 6.2). Since fluent stores only one value per cell (in the cell center) all other values needs to be extrapoltated from the cell center. So the values for facesvalues and vertexvalues might be slightly different, although they should be consistent for each cell.

2. For transient calculations time step size is the time fluent advances the soultion in time. For each time step fluent does a number of calculations and if everything works well it will achive convergence bevor advancing to the next time step. Sometimes it will need a lot of iterations to get a converged solution so you can limit the number of iterations for each time step. If the calculation for the time step exceeds this number fluent will advance in time even with a not converged solution. Finding the right tradeoff between step size and max iterations to keep the solution running stable is really an art. Since i am not doing transient simulations i am probaly of little help here. To make a long story short, step size 60/max it 20 is not the same as 3/1.

RoM
  Reply With Quote

Old   February 23, 2012, 04:52
Default
  #9
New Member
 
Yolk
Join Date: Nov 2011
Posts: 23
Rep Power: 4
Yannian is on a distinguished road
Hi RoM,
Can you tell me how can I prescribe pressure profile on one inner face?
Yannian is offline   Reply With Quote

Old   May 20, 2012, 16:17
Default
  #10
New Member
 
moon
Join Date: Feb 2012
Posts: 22
Rep Power: 4
moun139 is on a distinguished road
hi,
can i sak you a question .
if plot this udf profile , it will be the same with udf defin on demand ?
moun139 is offline   Reply With Quote

Old   November 23, 2012, 05:18
Default
  #11
New Member
 
Karl Chapman
Join Date: Jun 2012
Location: Madrid
Posts: 3
Rep Power: 4
karlchapman is on a distinguished road
Hello Rom

I am having some trouble trying to calculate a new viscosity damping function and I am having some porblems in exctracting the variables required for yplus at y=0. At the moment my code runs however the values are not correct, where density is a value of e-13.

If you have time would it be possible to take a look at my code, I have simplified it as much as possible just to show the variables I am trying to extract.

Many regards Karl

#include "udf.h"
#include "math.h"

DEFINE_TURBULENT_VISCOSITY(ko_mu_t, c, t)

{
/*cell_t c;*/

int wall_ID = 23;
int wall_ID2=24;
int wall_ID3=10017;

Domain*d = Get_Domain(1);

Thread*twall = Lookup_Thread(d,wall_ID);
FILE * fp;

real rho;
real rho1;
real k;
real omg;
real mu_L;
real mu_L1;
real s;
real Cmu;
real y;
real str;

thread_loop_c(twall,d)
{

begin_c_loop(c,twall)
{
rho = C_R(c,twall);
mu_L = C_MU_L(c,twall);
str = C_STRAIN_RATE_MAG(c,twall);
}
end_c_loop(c,twall)

}

fp = fopen("mod_visc_1stIt.txt","a");
fprintf(fp,"%12.4e %12.4e %12.4e\n",rho1, mu_L1, str);
fclose (fp);
}
karlchapman is offline   Reply With Quote

Old   December 4, 2012, 03:09
Default
  #12
New Member
 
jianglei
Join Date: May 2012
Location: xiamen
Posts: 12
Rep Power: 4
dragonship2011 is on a distinguished road
Quote:
Originally Posted by RoM
;125727
No need to be sorry and you dont bother me.

1. A Surface is build from small faces (facets) and you can calculate the facet average for a vaule X from sum over all facet values/number of facets. Vertex (or node) average is defined similar as sum over all vertex values/number of vertice. The governing equations for postprocessing values can be found in chapter 30 user guide (fluent 6.2). Since fluent stores only one value per cell (in the cell center) all other values needs to be extrapoltated from the cell center. So the values for facesvalues and vertexvalues might be slightly different, although they should be consistent for each cell.

2. For transient calculations time step size is the time fluent advances the soultion in time. For each time step fluent does a number of calculations and if everything works well it will achive convergence bevor advancing to the next time step. Sometimes it will need a lot of iterations to get a converged solution so you can limit the number of iterations for each time step. If the calculation for the time step exceeds this number fluent will advance in time even with a not converged solution. Finding the right tradeoff between step size and max iterations to keep the solution running stable is really an art. Since i am not doing transient simulations i am probaly of little help here. To make a long story short, step size 60/max it 20 is not the same as 3/1.

RoM
hello, Rom
i want to consult you .In the Fluent software , how can i get the ship center of gravity and buoyant coordinates ? The case is finished. I want to search the ship CFD with free surface .
regards
thank you very much !
dragonship2011 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ATTN ALL: SOLUTON TO UDF COMPILE PROBLEM Rizwan Fluent UDF and Scheme Programming 30 March 21, 2014 06:34
Problem with my udf july Fluent UDF and Scheme Programming 3 June 20, 2010 06:56
UDF problem mansha goraya FLUENT 0 October 29, 2007 01:31
udf compiling problem akr FLUENT 3 August 22, 2007 07:14
UDF problem chiseung FLUENT 4 January 10, 2002 09:58


All times are GMT -4. The time now is 01:28.