CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

help on UDF (on_demand)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 7, 2003, 13:06
Default help on UDF (on_demand)
  #1
Marc
Guest
 
Posts: n/a
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

  Reply With Quote

Old   July 8, 2003, 19:21
Default Re: help on UDF (on_demand)
  #2
alex
Guest
 
Posts: n/a
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
  Reply With Quote

Old   July 9, 2003, 03:43
Default Re: help on UDF (on_demand)
  #3
Marc
Guest
 
Posts: n/a
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
  Reply With Quote

Old   July 9, 2003, 14:27
Default Re: help on UDF (on_demand)
  #4
alex
Guest
 
Posts: n/a
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
  Reply With Quote

Old   July 9, 2003, 14:50
Default Re: help on UDF (on_demand)
  #5
Marc
Guest
 
Posts: n/a
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
  Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Mesh UDF Qureshi FLUENT 7 March 23, 2017 08:37
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


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