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

using UDF to read file

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 4, 2008, 16:39
Default using UDF to read file
  #1
Ellen
Guest
 
Posts: n/a
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
  Reply With Quote

Old   November 4, 2008, 23:23
Default Re: using UDF to read file
  #2
CDE
Guest
 
Posts: n/a
did you set Fluents working directory to where myfile.txt is?
  Reply With Quote

Old   November 5, 2008, 10:19
Default Re: using UDF to read file
  #3
Ellen
Guest
 
Posts: n/a
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
  Reply With Quote

Old   November 5, 2008, 16:53
Default Re: using UDF to read file
  #4
CDE
Guest
 
Posts: n/a
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);

  Reply With Quote

Old   November 5, 2008, 18:38
Default Re: using UDF to read file
  #5
Ellen
Guest
 
Posts: n/a
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
  Reply With Quote

Old   November 25, 2008, 18:38
Default Re: using UDF to read file
  #6
Ehsan
Guest
 
Posts: n/a
Hi Ellen, I have the same problem when try reading from the file.Could you advise please Ehsan
  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
read file in UDF Echo FLUENT 4 July 4, 2017 13:37
How to read a file from a macro StarCD Siemens 2 July 8, 2004 22:31
Why I can't read one external file? Lee Siemens 7 April 2, 2004 13:25
Read file RBM FLUENT 0 July 14, 2002 14:48
Read data file R.B.M FLUENT 0 July 11, 2002 00:16


All times are GMT -4. The time now is 01:37.