|
[Sponsors] |
UDF to read large file and store it in C_UDMI |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 18, 2022, 09:05 |
UDF to read large file and store it in C_UDMI
|
#1 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
Dear all,
I ran a first simulation on a mesh and i have exported a quantity of interest (QoI) at each cell center of my CFD domain in a ASCII file type. It is thus a very large file (millions of lines): cellNumber, x-coordinate, y-coordinate, z-coordinate, QoI . . . I would like to re-use this result for a second simulation on the same mesh. How can I read the file and store the QoI inside a C_UDMI(c,t) ? I guess the following option is naive Code:
DEFINE_ON_DEMAND(read_QoI) { #if !RP_NODE /* serial or host process */ char line[100]; int index; float f1, f2, f3, f4; int number_cell = 13786084; float *QoI; QoI = (float *)malloc((number_cell -1)*sizeof(float)); FILE* file_r; file_r = fopen("QoI_ascii", "r"); if(file_r==NULL) { Message("\n"); Message("Error opening file \n"); Message(" \n"); } /* Skip one line by reading one line and ignoring */ fgets(line, 100, file_r); while (fscanf(file_r, "%d%f%f%f%f", &index, &f1, &f2, &f3, &f4) > 0) { QoI[index-1] = f4; } fclose(file_r); Domain *d; d = Get_Domain(1); Thread *t; cell_t c; thread_loop_c(t,d) { begin_c_loop(c,t) { int ID = C_ID(c,t); C_UDMI(c,t,0) = QoI[ID-1]; } end_c_loop(c,t) } free(signal); #endif } Thanks in advance ! |
|
January 19, 2022, 03:55 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
1. you may write profile and later read it without any UDF
2. on the other hand for single core your code should work well in case you are storing the same cell index as C_ID(c,t) macro returns.
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 19, 2022, 05:01 |
|
#3 | |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
Quote:
1. Can the profile tool also be used with field data? Or should it be used for surface ? 2. Ok thanks a lot, I'll give a try with a smaller file then! |
||
Tags |
udf, udf and programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to read a Value from Text File and store it in Variables | Amirreza_pro | Fluent UDF and Scheme Programming | 5 | April 5, 2024 16:14 |
How to read a Value from Text File and store it in Variables (writing in UDF) | Amirreza_pro | FLUENT | 0 | October 26, 2020 04:50 |
simple UDF doesn't read input from external file. interprets/compiles without errors | ahmad_xjtu | Fluent UDF and Scheme Programming | 5 | March 23, 2018 03:03 |
UDF macro to read the name of the case file | polaritus | Fluent UDF and Scheme Programming | 2 | March 23, 2015 05:59 |
Results saving in CFD | hawk | Main CFD Forum | 16 | July 21, 2005 21:51 |