|
[Sponsors] |
June 19, 2017, 05:30 |
udf source
|
#1 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 11 |
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. |
|
June 19, 2017, 08:38 |
|
#2 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
-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 ')' |
|
June 19, 2017, 09:08 |
|
#3 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 11 |
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; } |
|
June 19, 2017, 09:19 |
|
#4 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
still:
-fscanf( is missing the last bracket ')' -T_Moyenne -are you sure about that source-equation? |
|
June 19, 2017, 09:30 |
|
#5 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 11 |
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
|
|
June 19, 2017, 09:45 |
|
#6 |
Senior Member
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9 |
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? |
|
June 19, 2017, 10:21 |
|
#7 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 11 |
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. |
|
|
|
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 |