CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   help on UDF (on_demand) (http://www.cfd-online.com/Forums/fluent/31784-help-udf-on_demand.html)

 Marc July 7, 2003 12:06

help on UDF (on_demand)

Dear all,

I am using FLUENT 6.0.20 and trying to calculate the mean temperature in a flow field using a On_Demand UDF as given in the Fluent UDF User Guide (Fluent. Inc December 3, 2001, pp 4-9):

#include "udf.h"

DEFINE_ON_DEMAND(on_demand_calc)

Domain *d;

{

real tavg = 0.;

real tmax = 0.;

real tmin = 0.;

real temp,volume,vol_tot;

Thread *t;

cell_t c;

d=Get_Domain(1); /* Get the domain using Fluent utility */

/* Loop over all cell threads in the domain */

thread_loop_c(t,d)

{

/* Compute max, min, volume-averaged temperature */

/* Loop over all cells */

begin_c_loop(c,t)

{

volume = C_VOLUME(c,t); /* get cell volume */

temp = C_T(c,t); /* get cell temperature */

if (temp < tmin || tmin == 0.) tmin = temp;

if (temp > tmax || tmax ==0. ) tmax = temp;

vol_tot += volume;

tavg += temp*volume;

}

end_c_loop(c,t)

tavg /= vol_tot;

printf("\n Tmin = %g Tmax = %g Tavg = %g\n", tmin,tmax,tavg);

/* Compute temperature function and store in user-defined memory */

/* (local index 0) */

begin_c_loop(c,t)

{

temp = C_T(c,t);

C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin);

}

end_c_loop(c,t)

}

}

When trying to intrepret it in Fluent, I get always an error message "parse error in line 10", I moved the line "Domain *d;" into the main program body (before the line "real tavg = 0.;") as

DEFINE_ON_DEMAND(on_demand_calc) {

Domain *d;

real tavg = 0.;

real tmax = 0.;

.......

the interpretation passes. But when activing the On-Demand UDF, it calculates the mean temperature then immediately gives me an error message:

Error: fluent.6.0.20 received a fatal signal (SEGMENTATION VIOLATION). Error Object: #f

I tried to re-launch Fluent many times but always got the same error message after excuting the UDF. I tried also another UDF example in the same user manual (pp. 4-12) DEFINE_RW_FILE, the compilation and calculation work well but when I try to write the dat file, I got the same error message. I cannot figure out what's wrong there. Can someone give me some hints? I am running Fluent 6.0.20 on Linux Redhat 7.2.

Thanx in advance.

Marc

 alex July 8, 2003 18:21

Re: help on UDF (on_demand)

Hi

Your problem is due to changes from fluent 5 to 6 you should write

extern Doamin* domain; instead of Domain *d

# include "udf.h"

extern Domain* domain;

DEFINE_ON_DEMAND(demo_calc)

Good luck

Alex

 Marc July 9, 2003 02:43

Re: help on UDF (on_demand)

Hi Alex,

Thank you for your reply. In the UDF user manual pp. 1-3, it is said that the old "extern Domain" marco in Fluent 5 should be replaced by the new macro

Domain *d domain=Get_Domain(1)

command. And the UDF works after I moved the line

Domain *d

into the DEFINE_ON_DEMAND block. My problem is why it gives me always a "Segmentation Violation" message after each excution?

Thank you for your time all the same.

Regards,

Marc

 alex July 9, 2003 13:27

Re: help on UDF (on_demand)

Hi

Sorry about give you the wrong advice, you must to use this form in fluent 6.0

DEFINE_ON_DEMAND(my_udf1) { Domain *domain=Get_Domain(1);

Now, the segmentation problem that you are getting is generated because you have not initialize the used define memory. As a result,

If you have not iterate your flow field Initialize the variable in the solver Initialize-Initialize.

If you have already iterate your flow field, Open the contours plot, select User define memory, select one surface, and then display. In this way, you will initialize indirectly the UDM without changing the data in other field. Unfortunately, I have not found a better way to do it. However, It works!!

Then request the demand function

Good look

Alex Munoz

 Marc July 9, 2003 13:50

Re: help on UDF (on_demand)

Hi Alex,

I found out today the problem is from the UDM, I should first reserve User Defined Memory before excuting the on-demande UDF. Another problem may be from the string length in the "printf": in Fluent 6.0.12 linux version, when the string length in the printf is more than 31, it will cause a segmentation error. It is said that this problem was fixed in the 6.0.20 version but I am working on the 6.0.20 version, the problem still exists.

Thank you again for your kind help.

Best regards,

Marc

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