|
[Sponsors] |
October 26, 2005, 05:57 |
udf problem
|
#1 |
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. |
|
October 26, 2005, 06:30 |
Re: udf problem
|
#2 |
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 |
|
October 27, 2005, 05:26 |
Re: udf problem
|
#3 |
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. |
|
October 27, 2005, 07:04 |
Re: udf problem
|
#4 |
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 |
|
October 29, 2005, 06:05 |
Re: udf problem
|
#5 |
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. |
|
October 29, 2005, 15:04 |
Re: udf problem
|
#6 |
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 |
|
October 30, 2005, 22:43 |
Re: udf problem
|
#7 |
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. |
|
November 1, 2005, 03:36 |
Re: udf problem
|
#8 |
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 |
|
February 23, 2012, 05:52 |
|
#9 |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
Hi RoM,
Can you tell me how can I prescribe pressure profile on one inner face? |
|
May 20, 2012, 17:17 |
|
#10 |
New Member
moon
Join Date: Feb 2012
Posts: 26
Rep Power: 14 |
hi,
can i sak you a question . if plot this udf profile , it will be the same with udf defin on demand ? |
|
November 23, 2012, 06:18 |
|
#11 |
New Member
Karl Chapman
Join Date: Jun 2012
Location: Madrid
Posts: 3
Rep Power: 14 |
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); } |
|
December 4, 2012, 04:09 |
|
#12 | |
New Member
jianglei
Join Date: May 2012
Location: xiamen
Posts: 12
Rep Power: 14 |
Quote:
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 ! |
||
July 16, 2016, 14:00 |
mixed convection
|
#13 |
New Member
saad
Join Date: May 2012
Posts: 6
Rep Power: 14 |
I am trying to store the value of mean temperature in user defined memory and want to use that stored value in my source.
But the value is not stored correctly. I am writing my UDF below. #include "udf.h" DEFINE_ON_DEMAND(on_demand_calc) { real tavg; real temp,volume,vol_tot; Domain*d; Thread*t; int i; int ID; cell_t c; tavg = 0.; vol_tot = 0.; d = Get_Domain(1); t=Lookup_Thread(d,5); thread_loop_c(t,d) { begin_c_loop(c,t) { volume = C_VOLUME(c,t); temp = C_T(c,t)-273.5; vol_tot += volume; tavg += temp*volume; } end_c_loop(c,t) tavg = tavg/vol_tot; } printf("Tavg = %g\n",tavg); printf("volume = %g\n",volume); printf("vol_tot = %g\n",vol_tot); printf("temp = %g\n",temp); thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDMI(c,t,0) = tavg; } end_c_loop(c,t) } } DEFINE_SOURCE(mom_source,c,t,dS,eqn) { real x[ND_ND]; real source; C_CENTROID(x,c,t); source= 1.-5.33*(C_T(c,t)-C_UDMI(c,t,0)); dS[eqn]=0.; return source; } Please help me, how to save the value of mean temperature. |
|
July 18, 2016, 01:30 |
|
#14 | |
New Member
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11 |
Quote:
thread_loop_c(t,d) { begin_c_loop(c,t) { volume = C_VOLUME(c,t); temp = C_T(c,t)-273.5; tavg_new = tavg+(temp*volume); } end_c_loop(c,t) tavg = tavg_new/volume; } NOTE: Don't use too many real variables. Fluent gets confused on which value to consider and which not. You are telling the value of tavg = 0 outside the loop and you are defining the same term everywhere. So Fluent takes the value tavg as 0 and saves it in the UDM. Make sure you avoid that. |
||
August 24, 2016, 04:13 |
UDF to restrict the temperature rise after certain limit in Fluent analysis
|
#15 |
New Member
Thasneem Moosa
Join Date: Mar 2016
Posts: 3
Rep Power: 10 |
While running the iterations for Closed loop two turn pulsating heat pipe the temperature of the evaporator section vigorously shoots to higher temperatures which is not acceptable practically.Where as the condenser temperature remains constant.Hence the thermal resistance also constantly increases at increasing heat input which is contradicting to the experimental results.Kindly post a udf program to restrict the temperature after certain limit.
|
|
October 12, 2016, 15:44 |
|
#16 | |
Member
mahya
Join Date: Jul 2016
Posts: 45
Rep Power: 10 |
Quote:
|
||
April 18, 2017, 03:11 |
How to add face temperature and cell temperature in udf?
|
#17 |
New Member
Swapnil Chavanda
Join Date: Jan 2017
Location: Pune
Posts: 19
Rep Power: 9 |
Hello,
I have written code for average temperature. I know this is wrong. But if anyone knows about "how to calculate average temperature of cell and face?" Please let me know Also, rectify my code as below Thanks in advance #include "udf.h" DEFINE_ON_DEMAND(on_demand_calc_avg_temperature) { Thread *t; Domain *d; cell_t c; face_t f; real wall_temperature,cell_temperature,avg_temp; d = Get_Domain(1); thread_loop_f(t,d) { begin_f_loop(f,t) { wall_temperature=F_T(f,t); } end_f_loop(f,t) } thread_loop_c(t,d) { begin_c_loop(c,t) { cell_temperature=C_T(c,t); } end_c_loop(c,t) avg_temp=(wall_temperature+cell_temperature)/2; C_UDMI(c,t,0) =avg_temp; Message(" Wall Temperature = %f deg K\n", avg_temp); } } |
|
September 21, 2017, 08:56 |
|
#18 |
New Member
madan
Join Date: Sep 2017
Posts: 5
Rep Power: 9 |
Hi everybody,
I am doing a transient simulation of conjugated heat transfer problem. In that I have a solid that plays a role of heat generation(W/m3) varying with time (q=q(t)). Since i am weak in codings, I need a help to write a udf for heat source varying with time. value is q=6.75e11 Thank you. |
|
December 18, 2017, 21:36 |
|
#19 |
New Member
sennaiu
Join Date: Dec 2017
Posts: 2
Rep Power: 0 |
http://www.afs.enea.it/project/neptu...df/node100.htm
You can use Lookup_Thread when you want to retrieve the pointer t to the thread that is associated with a given integer zone ID number for a boundary zone. The zone_ID that is passed to the macro is the zone number that ANSYS FLUENT assigns to the boundary and displays in the boundary condition dialog box (e.g., Fluid). Note that this macro does the inverse of THREAD_ID (see below). |
|
February 19, 2018, 05:56 |
ANSYS FLUENT simulation by UDF of unsteady state simulation of U-tube heat exchanger
|
#20 |
New Member
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8 |
I am trying to simulate closed loop U-Tube heat exchanger at which the fluid outlet is heated by electrical heater then enter again the U-Tube, So I used UDF to defined the temperature profile at outlet then using UDM to store it, and after that defining the temperature profile at inlet equal to the value stored in the UDM from previous time step.the problem is that, it works well until the time of 8400 sec then the temperature remain constant and didn't change with time, My total simulation time is 252000 sec, the time step is 60 sec.
What is the wrong and what could be the problem? thanks in advance, the following indicate the UDF used #include "udf.h" /* Defining outlet temperature.*/ DEFINE_ADJUST(average_exit_temp,domain) { face_t f1; face_t f2; real tempa=0.0; real totalarea=0.0; real avetempa=0.0; real A[ND_ND]; real tt=RP_Get_Real("flow-time"); int ID1 = 28; /* the outlet boundary condition identifier*/ Thread *outlet_thread = Lookup_Thread(domain,ID1); int ID2 = 27; /* the inlet boundary condition identifier*/ Thread *inlet_thread = Lookup_Thread(domain,ID2); //printf("average temperature1=%e\n",avetempa); /*loop over faces in a face thread to get the information stored on faces.*/ begin_f_loop(f1,outlet_thread) { /* F_T gets face temperature.+=causes all faces areas/temperatures to be added together.*/ F_AREA(A,f1,outlet_thread); totalarea +=NV_MAG(A); tempa +=NV_MAG(A)*F_T(f1,outlet_thread); } end_f_loop(f1,outlet_thread) avetempa= tempa/totalarea+ ((5989.8-0.0001*tt)/(0.285888*4182)); begin_f_loop(f2,inlet_thread) { F_UDMI(f2,inlet_thread,0)=avetempa; } end_f_loop(f2,inlet_thread) } DEFINE_PROFILE(Inlettemp,t,i) { real time=RP_Get_Real("flow-time"); face_t f; if(time<=60) { begin_f_loop(f,t) { F_PROFILE(f,t,i)=288.15; } end_f_loop(f,t) } else { begin_f_loop(f,t) { if(F_UDMI(f,t,0)<315; {F_PROFILE(f,t,i) = F_UDMI(f,t,0);} else { break; } } end_f_loop(f,t) } } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
ATTN ALL: SOLUTON TO UDF COMPILE PROBLEM | Rizwan | Fluent UDF and Scheme Programming | 40 | March 18, 2018 07:05 |
Problem with my udf | july | Fluent UDF and Scheme Programming | 3 | June 20, 2010 07:56 |
UDF problem | mansha goraya | FLUENT | 0 | October 29, 2007 01:31 |
udf compiling problem | akr | FLUENT | 3 | August 22, 2007 08:14 |
UDF problem | chiseung | FLUENT | 4 | January 10, 2002 10:58 |