# udf problem

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 October 26, 2005, 05:30 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 manshu likes this.

 October 27, 2005, 04:26 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.

 October 29, 2005, 05:05 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.

 October 29, 2005, 14:04 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

 October 30, 2005, 21:43 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.

 November 1, 2005, 02:36 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

 February 23, 2012, 04:52 #9 Member   Yolk Join Date: Nov 2011 Posts: 38 Rep Power: 14 Hi RoM, Can you tell me how can I prescribe pressure profile on one inner face?

 May 20, 2012, 16: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, 05:18 #11 New Member   Karl Chapman Join Date: Jun 2012 Location: Madrid Posts: 3 Rep Power: 13 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, 03:09
#12
New Member

jianglei
Join Date: May 2012
Location: xiamen
Posts: 12
Rep Power: 13
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 !

 July 16, 2016, 13:00 mixed convection #13 New Member   saad Join Date: May 2012 Posts: 6 Rep Power: 13 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, 00:30
#14
New Member

Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 10
Quote:
 Originally Posted by s.m.saad jamil 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.
I think your tavg value is taken as 0 from outside the loop. Add another real term as tavg_new and change the value of tavg to tavg_new inside the loop. Addition to this, don't use vol_tot. You have defined vol_tot = 0 outside the loop. Instead use volume itself in the formula outside. The new code would be as shown below. Try this, it might help you save the average temperature.

{
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, 03: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, 14:44
#16
Member

mahya
Join Date: Jul 2016
Posts: 45
Rep Power: 9
Quote:
 Originally Posted by RoM ;125673 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
How can i declare cell in my udf?

 April 18, 2017, 02: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, 07:56 #18 New Member   madan Join Date: Sep 2017 Posts: 5 Rep Power: 8 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, 20: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).