CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   udf source (https://www.cfd-online.com/Forums/fluent-udf/189386-udf-source.html)

fersim June 19, 2017 04:30

udf source
 
Hello,

I have a question and I will like if anyone can help me to write the following DEFINE_SOURCE:
I inform you that the values of T_mean and Time is in a txt file named result.txt.

I want to write an udf program that uses the found values of the text file.
I ran the progame and I did not find any errors but the program does not give me the values of
T_mean and Time. Help me please.


DEFINE_SOURCE(Source_AIR, c, t, dS, eqn)
{
real source, Time,T_mean;
FILE *pFile;
pFile=fopen("c:/result.txt","r");
fscanf(pFile,"%g %g\n",&Time,&T_mean);
fclose(pFile);
source =32*T_mean*Time;
dS[eqn] = 0.0;
return source;
}

KaLium June 19, 2017 07:38

-You don't give any value to T_mean

-Also this equation is odd:
TEMP=T_Mean;
source =32*T_Mean*TEMP/TIM;

T_mean*TEMP is the same as T_mean^2
Why do you even need the TEMP?

-You have not defined the T_Moyenne inside the DEFINE_SOURCE.

-You should remove the semicolon ';' from inside of fscanf(pFile,"%g ;%g\n" and fprintf(pFile,"%g ;%g\n"

-fscanf( is missing the last bracket ')'

fersim June 19, 2017 08:08

thank you for your replay

For this Source term, I want open file text (in mu case result.txt), in this file they have a value, for exemple 30 299. (30 is 30 sec, and 299 is temperature).

for DEFINE SOURCE, I want open result.txt and read 30 as time and 299 as temperture.

Tahnk you.

DEFINE_SOURCE(Source_AIR, c, t, dS, eqn)
{
real source, Time,T_mean;
FILE *pFile;
pFile=fopen("c:/result.txt","r");
fscanf(pFile,"%g %g\n",&Time,&T_mean);
fclose(pFile);
source =32*T_mean*Time;
dS[eqn] = 0.0;
return source;
}

KaLium June 19, 2017 08:19

still:

-fscanf( is missing the last bracket ')'
-T_Moyenne
-are you sure about that source-equation?

fersim June 19, 2017 08:30

My problem is not in the equation or in the bracket (. but how can I read a file txt and load some variables (Time and Time) in the DEFINE SOURCE

KaLium June 19, 2017 08:45

Your problem was also the bracket. UDF do not work, if the code is wrong.

Do you need the "\n" when using fscanf();?

You could also try %f in your fscanf(); or are you using double precision?

fersim June 19, 2017 09:21

not necessery to put \n or double double precision, I want juste read a text file
and calculate source =32*T_mean*Time. the values of Time and T_mean finded in the file text.

I want to have any solution to read these two values from a text file.


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