CFD Online Logo CFD Online URL
Home > Forums > FLUENT

UDF problem

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

LinkBack Thread Tools Display Modes
Old   June 18, 2007, 17:23
Default UDF problem
Dimitris Fidaros
Posts: n/a
I have recently started to use UDF and so I am new with it. I want to calculate the average value of user defined scalar on specific face of a 3d domain and to write this value on an ASCII file at the end of time step (transient simulation) but I couldn't manage to compute it. I would appreciate any help on this. Here is the listing I have done.

/************************************************** **********************/ * UDF that calculates the average chlorine concentration at outlet face*/ /* and it prints it at external ASCII file and on GUI */ /************************************************** **********************/

#include "udf.h" DEFINE_EXECUTE_AT_END(chlorine_out_average) { static int last_ts=-1; int cur_ts = N_TIME; real time = CURRENT_TIME; real fa real fi; real tfa; real tfi; real mfi; int n; int id = 4; /* Change id number in order to corespond to right boundary*/ face_t f;

Domain *d = Get_Domain(1); Thread *t = Lookup_Thread(d, id); cell_t c; FILE *fp = fopen("usds_story.txt", "w");

begin_f_loop(f, t) { fa = C_AREA(f,t); fi = C_UDSI(c,t,1); tfa += fa; tfi += fi*fa; } end_f_loop(f, t);

mfi = tfi / tfa;

if (last_ts != curr_ts) { last_ts = curr_ts; fprintf(fp,"Time_Step Time UDS") } fprintf(fp, "%d\ %g\t %g\t14.8E\n", cur_ts, time, mfi); printf("Time Step:%d Time:%g\t UDS:%g\t14.8E\n", cur_ts, time, mfi); }

Thanks in advance

  Reply With Quote

Old   June 19, 2007, 03:11
Default Re: UDF problem
Posts: n/a
as it tells the name, the macro DEFINE_EXECUTE_AT_END is executed at the end of the time step (in case of an unsteady simulation), or et the and of iteration (in case of a steady state simulation), so you don't need to check if you are at the first iteration within the timestep. I assume that in the variable fa you want to store the face area. the correct macro is F_AREA(f,t) and not C_AREA(f,t). Another thing, to print messages to the console, use the macro Message instead of printf.
  Reply With Quote

Old   June 19, 2007, 04:16
Default Re: UDF problem
Posts: n/a
Moreover, the correct way to write the Area macro is: F_AREA(A,f,t) , being A the name of the variable. The output A is a vector, not a scalar.

If you want to access to C_UDSI(c,t,1) you must say who is "c". You cannot start a loop over faces, so you will be in a face "f" and call for the UDS in the cell "c". Maybe you are trying to call F_UDSI(f,t,i) ?

For many variables exists two versions, one for the cell values (macros starting with C_XXX) and another for the interpolated values in faces (macros starting with F_XXX)

Greetings, Diego
  Reply With Quote

Old   June 20, 2007, 20:59
Default Re: UDF problem
Dimitris Fidaros
Posts: n/a
Thanks a lot. I fix my problem but i would to help me with the parallel version of this code

  Reply With Quote


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 40 October 18, 2017 07:17
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 10:58

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