|
[Sponsors] |
June 24, 2008, 12:05 |
read file in UDF
|
#1 |
Guest
Posts: n/a
|
Hi guys, I need to read some discrete data from a file for all the cells in the domain. Do you have a UDF which can do this or could you please tell me how to achieve this.
thanx |
|
June 25, 2008, 02:46 |
Re: read file in UDF
|
#2 |
Guest
Posts: n/a
|
Hello Echo,
Here is an example extracted from my UDF, where I add convective heat flux at certain coupled wall zones. The input file, named fin-9.inp, is __________________________________________________ _______________ 10 3.42 300 .01 ! id, HTC, Tamb, thick side-mi v-wall (metal) 23 3.42 300 .01 ! id, HTC, Tamb, thick side-mi-shadow v-wall (air ) 12 12.14 300 .01 ! id, HTC, Tamb, thick top-m h-wall (air ) 25 12.14 300 .01 ! id, HTC, Tamb, thick top-m-shadow h-wall (metal) __________________________________________________ _______________ and the relevant part of the UDF that reads it is __________________________________________________ _______________ #include "udf.h" #include <stdio.h> float HTCv[100], Tambv[100], thickv[100], HTC, Tamb, thick; int id; char line[80]; FILE *finp, *fout; /* declare file pointers */ DEFINE_EXECUTE_ON_LOADING(report_version, libname) /************************************************** ****************** UDF called on loading of libname ************************************************** *******************/ { /* identify UDF version, function entry print and input echo */ fout = fopen("fin-9.out", "a"); /* open fout for append */ fprintf(fout, "report_version:\n\ ***** external convection on coupled walls - udf-9.c of 23/06/08 *****\n\ open file for writing\n"); /* read input */ finp = fopen("fin-9.inp", "r"); /* open finp for read */ while( feof(finp) == 0 ) /* read until EOF reached in input */ { fgets(line, 70, finp); /* read 70 characters */ sscanf(line, "%d %g %g %g", &id, &HTC, &Tamb, &thick); HTCv [id] = HTC; Tambv [id] = Tamb; thickv[id] = thick; } fclose(finp); /* close finp */ fclose(fout); /* close fout */ } __________________________________________________ _______________ NOTE: Being an absolute beginner in C, I am sure that the coding is extremely clumsy, but it works fine, and you can get the idea and improve the coding. I hope it helps, Rami |
|
June 25, 2008, 11:58 |
Re: read file in UDF
|
#3 |
Guest
Posts: n/a
|
Hi Rami, thanks for your reply. My actual goal was to use the read data for initialization of a UDS. I wrote the following UDF for this purpose but it doesn't work. Do you have an idea where the problem arises from?
#include "udf.h" DEFINE_INIT(my_init_func,d) { cell_t c; Thread *t; real xc[ND_ND]; FILE *file; real numbers[800]; int i,j; file = fopen("fscanf.txt", "r"); i = 1 ; while(!feof(file)) { /* loop through and store the numbers into the array */ fscanf(file, "%f", &numbers[i]); i++; } fclose(file); /* loop over all cell threads in the domain */ thread_loop_c(t,d) { j=0; /* loop over all cells */ begin_c_loop_all(c,t) { j=j+1; C_CENTROID(xc,c,t); C_UDSI(c,t,0) = numbers[j]; } end_c_loop_all(c,t) } } |
|
June 29, 2008, 03:41 |
Re: read file in UDF
|
#4 |
Guest
Posts: n/a
|
As I already said, I am a beginner in C (and also quite new to FLUENT), so I cannot be of much help in debugging. I suggest you add details to explain what you mean by "it doesn't work" so others may help.
|
|
July 4, 2017, 13:37 |
|
#5 |
New Member
Sri Charan Akula
Join Date: Jun 2017
Posts: 8
Rep Power: 9 |
Hello Echo.
Did you find out how to make your udf work? |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
using UDF to read file | Ellen | FLUENT | 5 | November 25, 2008 18:38 |
How to read a file from a macro | StarCD | Siemens | 2 | July 8, 2004 22:31 |
Why I can't read one external file? | Lee | Siemens | 7 | April 2, 2004 13:25 |
Read file | RBM | FLUENT | 0 | July 14, 2002 14:48 |
Read data file | R.B.M | FLUENT | 0 | July 11, 2002 00:16 |