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

Can't read data from file to a UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By LuckyTran
  • 1 Post By LuckyTran
  • 1 Post By AlexanderZ
  • 1 Post By LuckyTran

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 30, 2021, 13:34
Question Can't read data from file to a UDF
  #1
New Member
 
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 9
Emanuel Camacho is on a distinguished road
Good day,

I am trying to read some data from the forces report file that Fluent generates into a UDF but all values appear 0 in Fluent.

I attached 3 figures to illustrate the data file (no 1), the UDF code (no 2), and the message observed in Fluent (no3).

What can I be doing wrong? Do I need to add something else to the code since I am using file-related functions (fscanf and such)?

EDIT: Moved to the Fluent UDF and Scheme Programming Subforum.
Attached Images
File Type: jpg 1.jpg (78.7 KB, 18 views)
File Type: jpg 2.jpg (25.3 KB, 19 views)
File Type: jpg 3.jpg (117.3 KB, 16 views)

Last edited by Emanuel Camacho; September 30, 2021 at 13:40. Reason: Moved to -> Fluent UDF and Scheme Programming
Emanuel Camacho is offline   Reply With Quote

Old   September 30, 2021, 15:09
Default
  #2
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,675
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
Two things come to mind
1) How are all the 12 variable declared? Are they declared as doubles or floats? Are they initialized to 0? If so, can you initialize them to 3.14159 to debug?
2) It's possible fscanf is stuck on the line at timestamp 0 with 12 0's and ending with a \n and it is not going to the next line.

If your code now spits out 3.14159 we know nothing is being read, or it is being read and not being written to memory.
If the code spits out all 0's again, we know it's stuck on the line.
Emanuel Camacho likes this.
LuckyTran is offline   Reply With Quote

Old   September 30, 2021, 17:16
Default
  #3
New Member
 
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 9
Emanuel Camacho is on a distinguished road
Quote:
Originally Posted by LuckyTran View Post
Two things come to mind
1) How are all the 12 variable declared? Are they declared as doubles or floats? Are they initialized to 0? If so, can you initialize them to 3.14159 to debug?
Variables are declared as real which I assume are doubles. I did as you said, and initialized them to 3.1415.

Quote:
Originally Posted by LuckyTran View Post
2) It's possible fscanf is stuck on the line at timestamp 0 with 12 0's and ending with a \n and it is not going to the next line. If your code now spits out 3.14159 we know nothing is being read, or it is being read and not being written to memory. If the code spits out all 0's again, we know it's stuck on the line.
After doing as you said, the results are shown below.

control: 1 | timestep: 0 | flowtime: 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500
control: 2 | timestep: 0 | flowtime: 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500
control: 3 | timestep: 0 | flowtime: 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500
control: 4 | timestep: 0 | flowtime: 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500
control: 5 | timestep: 0 | flowtime: 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500
control: 6 | timestep: 0 | flowtime: 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500 | 3.141500
.
.
.

So, as you said nothing is being read or being read and not written to memory. What should I do?
Emanuel Camacho is offline   Reply With Quote

Old   September 30, 2021, 19:45
Default
  #4
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,675
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
Can you like maybe give more than 2 lines of your UDF?

It's really hard to debug something assuming you've done everything correctly, when nothing is working correctly.

Like, where is the fprintf even being nested... At this point, I bet you could hard code timestep=2021; into this for loop and it would still print timestep = 0.
Emanuel Camacho likes this.
LuckyTran is offline   Reply With Quote

Old   October 1, 2021, 03:28
Default
  #5
New Member
 
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 9
Emanuel Camacho is on a distinguished road
Sure, here it is. Thank you for the help.

EDIT: I added this

Code:
if (file_forces == NULL)
Message0("FILE WAS NOT OPENNED!\n");
else
Message0("CONTINUING!\n");
and Fluent showed the first option meaning that the file is not being opened! Can it be the file directory?

Code:
Code

Last edited by Emanuel Camacho; October 1, 2021 at 12:52.
Emanuel Camacho is offline   Reply With Quote

Old   October 1, 2021, 06:15
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
problem could be in communication between host and nodes
Code:
         #if !RP_NODE
                fscanf(file_forces,"%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&timestep,&flow_time,&C_D_1,&C_L_1,&C_M_1,&C_D_2,&C_L_2,&C_M_2,&D_f_1,&L_f_1,&D_f_2,&L_f_2);
                #endif

                Message0("control: %d | timestep: %d | flowtime: %lf | %lf | %lf | %lf | %lf | %lf | %lf\n",contr,timestep,flow_time,C_D_1,C_D_2,C_L_1,C_L_2,C_M_1,C_M_2);
here you are reading on host, but asking to print from node_0 which doesn't have information

so you should transfer data from host to nodes


also I can see C_T and C_P variables in your code, which could be a problem as fluent already uses these names for temperature and pressure
I recommend you to use other names
Emanuel Camacho likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 1, 2021, 06:22
Default
  #7
New Member
 
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 9
Emanuel Camacho is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post

so you should transfer data from host to nodes
How can I do such a thing? I am very sorry but when it comes to this topic I am pretty info-excluded.

Quote:
Originally Posted by AlexanderZ View Post
also I can see C_T and C_P variables in your code, which could be a problem as fluent already uses these names for temperature and pressure
I recommend you to use other names
Done.
Emanuel Camacho is offline   Reply With Quote

Old   October 1, 2021, 06:38
Default
  #8
New Member
 
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 9
Emanuel Camacho is on a distinguished road
I used this code, and it seems to be working. Will do some more testing.

Code:
host_to_node_int_1(timestep);         
host_to_node_real_7(flow_time,C_D_1,C_L_1,C_M_1,C_D_2,C_L_2,C_M_2);
host_to_node_real_4(D_f_1,L_f_1,D_f_2,L_f_2);
Thank you guys!
Emanuel Camacho is offline   Reply With Quote

Old   October 1, 2021, 06:39
Default
  #9
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,675
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
add this after fopen to make sure the file is actually opened for reading

Code:
if (file_forces == NULL)
printf("*\nCANNOT OPEN THE FILE\n*")

else
printf("*\n File ID is %d\n", file_forces);
You can use Message if you don't like printf

another thing you can do is check the return value of fscanf each time it is called. fscanf returns an integer for the number of assigned inputs and returning EOF if it doesn't.

Code:
int banana1, banana2, number;
number = fscanf(fp, "%d", banana1)
// number will be 1 if this works
number = fscanf(fp, "%d %d", banana1, banana2)
// number will be 2 if this works

You should have 12 if your code works as intended. But we currently have the suspicion that it's not working, so it won't.
Emanuel Camacho likes this.
LuckyTran is offline   Reply With Quote

Old   October 1, 2021, 12:51
Default
  #10
New Member
 
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 9
Emanuel Camacho is on a distinguished road
Thank you LuckyTran and AlexanderZ for helping me out.

By passing information from the host to the nodes, the problem was solved.

Code:
 
host_to_node_int_1(timestep);         
host_to_node_real_7(flow_time,C_D_1,C_L_1,C_M_1,C_D_2,C_L_2,C_M_2);
host_to_node_real_4(D_f_1,L_f_1,D_f_2,L_f_2);
Thanks once again.
Emanuel Camacho 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
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 08:46
[swak4Foam] Installation Problem with OF 6 version Aurel OpenFOAM Community Contributions 14 November 18, 2020 16:18
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Community Contributions 9 June 12, 2015 17:18
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Meshing & Mesh Conversion 12 May 2, 2013 10:52
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08


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