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

udf source

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 19, 2017, 05:30
Default udf source
  #1
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 11
fersim is on a distinguished road
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;
}

Last edited by fersim; June 19, 2017 at 13:39.
fersim is offline   Reply With Quote

Old   June 19, 2017, 08:38
Default
  #2
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
-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 ')'
KaLium is offline   Reply With Quote

Old   June 19, 2017, 09:08
Default
  #3
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 11
fersim is on a distinguished road
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;
}
fersim is offline   Reply With Quote

Old   June 19, 2017, 09:19
Default
  #4
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
still:

-fscanf( is missing the last bracket ')'
-T_Moyenne
-are you sure about that source-equation?
KaLium is offline   Reply With Quote

Old   June 19, 2017, 09:30
Default
  #5
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 11
fersim is on a distinguished road
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
fersim is offline   Reply With Quote

Old   June 19, 2017, 09:45
Default
  #6
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
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?
KaLium is offline   Reply With Quote

Old   June 19, 2017, 10:21
Default
  #7
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 11
fersim is on a distinguished road
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.
fersim is offline   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
[swak4Foam] swak4foam for OpenFOAM 4.0 mnikku OpenFOAM Community Contributions 80 May 17, 2022 09:06
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 10:07
[Other] How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Community Contributions 9 June 12, 2015 18:18
[swak4Foam] Swak4FOAM 0.2.3 / OF2.2.x installation error FerdiFuchs OpenFOAM Community Contributions 27 April 16, 2014 16:14


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