|
[Sponsors] |
September 30, 2021, 14:34 |
Can't read data from file to a UDF
|
#1 |
New Member
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 10 |
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. Last edited by Emanuel Camacho; September 30, 2021 at 14:40. Reason: Moved to -> Fluent UDF and Scheme Programming |
|
September 30, 2021, 16:09 |
|
#2 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
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. |
|
September 30, 2021, 18:16 |
|
#3 | ||
New Member
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 10 |
Quote:
Quote:
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? |
|||
September 30, 2021, 20:45 |
|
#4 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
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. |
|
October 1, 2021, 04:28 |
|
#5 |
New Member
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 10 |
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"); Code:
Code Last edited by Emanuel Camacho; October 1, 2021 at 13:52. |
|
October 1, 2021, 07:15 |
|
#6 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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",×tep,&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); 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
__________________
best regards ****************************** press LIKE if this message was helpful |
|
October 1, 2021, 07:22 |
|
#7 |
New Member
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 10 |
How can I do such a thing? I am very sorry but when it comes to this topic I am pretty info-excluded.
Done. |
|
October 1, 2021, 07:38 |
|
#8 |
New Member
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 10 |
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); |
|
October 1, 2021, 07:39 |
|
#9 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
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); 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. |
|
October 1, 2021, 13:51 |
|
#10 |
New Member
Emanuel Camacho
Join Date: Oct 2016
Posts: 13
Rep Power: 10 |
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); |
|
|
|
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 09:46 |
[swak4Foam] Installation Problem with OF 6 version | Aurel | OpenFOAM Community Contributions | 14 | November 18, 2020 17:18 |
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 | Seroga | OpenFOAM Community Contributions | 9 | June 12, 2015 18:18 |
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem | Attesz | OpenFOAM Meshing & Mesh Conversion | 12 | May 2, 2013 11:52 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 20:08 |