|
[Sponsors] |
November 13, 2019, 08:46 |
store/retrieve using DEFINE_RW_FILE
|
#1 |
Member
South Yorkshire
Join Date: May 2018
Posts: 33
Rep Power: 8 |
Hi,
I am trying to save some values I calculated using a compiled UDF. For this, I used the DEFINE_RW_MACRO to save the values in the data file (.das). The ideas is to retrieve these values when I open an intermediate time step (.cas and .das file) in Fluent. The problem is that the values are correctly stored in the .das file but when I try to retrieve them they are all zero. This is the part of my UDF Code:
FILE *fp; static real x = 0.0; static real vx = 0.0; static real y = 0.0; static real vy = 0.0; DEFINE_RW_FILE(read_data, fp) { Message0("\nReading user defined data from the data file...\n"); #if PARALLEL #if RP_HOST fscanf(fp, "%f", &x); fscanf(fp, "\n%f", &vx); fscanf(fp, "\n%f", &y); fscanf(fp, "\n%f", &vy); #endif #else fscanf(fp, "\n%f", &x); fscanf(fp, "\n%f", &vx); fscanf(fp, "\n%f", &y); fscanf(fp, "\n%f", &vy); #endif Message("READER INLOOP: %f %f %f %f\n",x,vx,y,vy); } DEFINE_RW_FILE(write_data, fp) { Message0("\nWriting user defined data to the data file...\n"); #if PARALLEL #if RP_HOST fprintf(fp, "%f", x); fprintf(fp, "\n%f", vx); fprintf(fp, "\n%f", y); fprintf(fp, "\n%f", vy); #endif #else fprintf(fp, "%f", x); fprintf(fp, "\n%f", vx); fprintf(fp, "\n%f", y); fprintf(fp, "\n%f", vy); #endif } Code:
(0 "User defined section:") (3307 5.703351e-05 1.468713e-03 -9.805568e-08 -1.883227e-06) Any ideas of why this is happening? Any ideas would be really appreciated. Regards, |
|
November 14, 2019, 15:09 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
I think you don't need the newline in your fscan.
|
|
November 18, 2019, 09:37 |
|
#3 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
One idea is a workaround rather than a solution, but possibly better than exporting to file: you could store the values in RP-variables, and then they are automatically saved with the .cas file.
Did you see in the manual that DEFINE_RW_FILE is not suitable for Windows? (This seems crazy to me, as whatever C compiler is being used will have access to file-IO libraries.) Another workaround: you could declare your own "static FILE*fp;" as a global variable, with DEFINE_ON_DEMAND routines to fopen and fclose it. In parallel, you would need to make sure that only one process accessed a file -- the host process is the obvious candidate, but you could consider "#if I_AM_NODE_ZERO_P". If the session is parallel, you will probably want to read the results only into the host process, and then broadcast them using host_to_node_real_4 or whatever. But if the fscanf commands were working, you would expect one of those Message calls to report the correct values. You can check whether fscanf commands return the expected values, and report which line is in error if they do not. Good luck! Ed |
|
Tags |
fluent - udf, udf code |
|
|