CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   using UDF to read file (https://www.cfd-online.com/Forums/fluent/49698-using-udf-read-file.html)

Ellen November 4, 2008 15:39

using UDF to read file
 
Hi,

I've been trying to read a table to Fluent using UDF. I started simple: read a file which contains only one number. It can be interpreted, but when I run it, Fluent gave me an error message saying sth like "fatal error", asking me to exit and restart. Then I skipped the reading part (fscanf), and only open a file with "ifp = fopen("myfile.txt", "r"), but there's still the same error message.

I tried to write to a file using fopen and fprintf, and it worked ok.

Can anyone please give an idea why I can write but cannot read using UDF? or, please tell me where I did wrong.

Thank you in advance, Ellen

CDE November 4, 2008 22:23

Re: using UDF to read file
 
did you set Fluents working directory to where myfile.txt is?

Ellen November 5, 2008 09:19

Re: using UDF to read file
 
Yes, the file myfile.txt is in the same directory as the case file that I'm running. Yesterday I tried some more with the udf code, and after I put the definition "FILE *ifp, *ofp" outside the DEFINE_PROPERTY() function, the case was able to run without any error. But it run very slowly and it didn't read from the file. (there's only one number is this file, and I checked whether the number was read or not by writing this number to another file using fprintf).

Do you have any suggestions? Thanks a lot.

Ellen

CDE November 5, 2008 15:53

Re: using UDF to read file
 
type ls in the fluent console and hit enter to see if the working directory is correct.

Can you post the code?

You can add code like the following example to detect the file reading errors

if ((fp = fopen(filename, "w"))==NULL)

Message("\n Warning: Unable to open %s for writing\n",filename); else

Message("\nWriting Pressure to %s...",filename);


Ellen November 5, 2008 17:38

Re: using UDF to read file
 
Thanks a lot for the reply, CDE. I'll try what you suggested.

I found the reason of the incorrect file reading. It's because a mismatch of the data type and the format specifier I used in fscanf. Now I'm able to read the data file correctly into an array, however, the running speed is very slow (it takes about 10 seconds to perform one iteration). I've posted another message in this board about this problem. Do you have any idea what might be the reason?

Ellen

Ehsan November 25, 2008 17:38

Re: using UDF to read file
 
Hi Ellen, I have the same problem when try reading from the file.Could you advise please Ehsan


All times are GMT -4. The time now is 21:18.