|
[Sponsors] |
June 20, 2020, 13:27 |
UDF : read report file
|
#1 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
Dear all,
I would like to read a report file in a UDF at each time step of an unsteady simulation to perfom some computations on the lift coefficient. Here is an example of a report file for the lift coefficient : "lift-rfile" "Time Step" "report_udf etc.." ("Time Step" "report_udf" "flow-time") 0 0 0 1 4.041365 0.0001 2 -0.053317 0.0002 And here is my UDF : #include "udf.h" FILE *file_r; DEFINE_EXECUTE_AT_END(udf_test) { #if !RP_NODE int current_ts = N_TIME; float *signal; signal = (float*)malloc((current_ts+1)*sizeof(float)); char line[100]; int index; float f1, f2; file_r = fopen("lift-rfile.out", "r"); if (file_r = NULL) { Message("Cannot open lift-rfile.out\n"); exit(1); } /* Skip three lines by reading three lines and ignoring */ fgets(line, 100, file_r); fgets(line, 100, file_r); fgets(line, 100, file_r); while (fscanf(file_r, "%d%f%f", &index, &f1, &f2) > 0) { signal[index] = f1; Message("%f \n",f1); } fclose(file_r); #endif } However, as soon as fluent tries to fgets and fscanf the report file, it abords with the error message "MPI Application rank 1 exited before MPI_Finalize() with status -1073740777" Do you have an idea of why and how to fix it ? Thanks in advance ! |
|
June 20, 2020, 16:44 |
Reading a File
|
#2 |
Senior Member
|
It appears that you have only one file to be read in or do you have one file for each time-step? If the former, why do you want to read it again and again?
And check for the location of the error, whether it is at fgets or at fscanf. Make FILE *file_r local variable and do not use #if !RP_NODE until the code works fine without parallelization. It will make debugging easier.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 20, 2020, 17:11 |
|
#3 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
Thanks for your answer!
Actually, it is the same file but the latter is modified at each time step since it contains the time history of the lift coefficient. Regarding the error, it happens at the fgets. I have already tried to make it local but fluent abords directly... It only works when the variable is global. |
|
June 21, 2020, 17:05 |
Lift Coefficient
|
#4 |
Senior Member
|
If it is being written by the same simulation, then preferable would be to determine lift coefficient within the UDF instead of reading it from the file.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 22, 2020, 02:23 |
|
#5 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
how could you know, that fluent aborts on fgets line???
put Messge0 to control the line, which leads to error this is example of code, which works well Code:
/* N is number of lines X is vector of size N to store values from table */ void read_param_table(char *file, int N, real X[PARAM_N]) { FILE *fp; int i; char str[101]; if((fp=fopen(file,"r"))==NULL) { printf("cannot open file...\n"); exit(0); } while(i < 3) { fgets(str, 101, fp); i++; /* Skip the first lines. */ } for(i=0; i<N; i++) { fscanf(fp, "%lf", &X[i]);} fclose(fp); }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
Tags |
reading text file, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OpenFoam "Permission denied" and "command not found" problems. | iyidaniel@yahoo.co.uk | OpenFOAM Running, Solving & CFD | 11 | January 2, 2018 07:47 |
[swak4Foam] Problem installing swak_2.x for OpenFoam-2.4.0 | towanda | OpenFOAM Community Contributions | 6 | September 5, 2015 22:03 |
[swak4Foam] build problem swak4Foam OF 2.2.0 | mcathela | OpenFOAM Community Contributions | 14 | April 23, 2013 14:59 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 20:08 |