CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   I need UDF help. (

S.Whitney October 15, 2007 11:29

I need UDF help.
I have a situation where I need to have a source/sink of a chemical within a mixture on a boundary. The size of the source/sink depends on the average mass fraction of that chemical across that entire boundary.

Thus, I need to do this: 1) Calculate the average mass fraction of a chemical in a mixture on a boundary. 2) Perform mathematical calculations on that average mass fraction. 3) Have a source/sink over that entire boundary that depends on the results of those calculations.

Initially I thought I could create a profile UDF to do all of the above. On the boundary wall, I set the species mass fraction to the UDF. But that failed miserably. It failed because Fluent would force the mass fraction to be whatever level I set it to, and wouldn't let any of that chemical flow into/out of the cell during the iteration. Thus from one iteration to the next, there would be no diffusion into/out of the cell and when I calculated the next iteration's average mass fraction it was simply just what I set it to during the last iteration.

For example, suppose in iteration #1, I set the mass fraction to 0.5. Some of that mass should diffuse away, and the mass fraction may drop to ~0.4. However, while the surrounding cells properly get the mass diffusion, for iteration #2 when I calculated the average mass fraction on the boundary, it was still 0.5 and not the lowered value after some diffused away. Fluent wouldn't adjust the mass fraction during it's iteration.

So, then I thought I could have a source UDF and a profile UDF. I wanted the profile UDF to average the mass fraction and store it into a global variable. Then the source UDF would adjust the mass fraction as needed. I created a face which is one node thick around the boundary in which to run the source UDF. Again, I have a problem. The source UDF reads the global variable just fine and sources/sinks perfectly. But the profile UDF cannot calculate the average mass fraction, it is always zero even if displaying the mass fraction contours in Fluent shows non-zero values. The face loop that properly calculated the average before, now gives zero each and every time.

Can anybody provide some help? Thanks.

Here is what I have so far:

#include "udf.h"

real average_conc;

DEFINE_PROFILE(wall_concentration, t, i) { face_t f; real j;

average_conc=0.0; j=0; begin_f_loop(f,t)




} end_f_loop(f,t) average_conc=average_conc/j;

printf("Profile: %f\n",average_conc); }

DEFINE_SOURCE(wall_source,c,t,dS,eqn) { real source;

source = 1.0; dS[eqn] = 0.0;

printf("Source: %f\n",average_conc); return source; }

Forget the source and dS[] numbers for now, I edited out all the complicated math.

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