CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Define source (http://www.cfd-online.com/Forums/fluent/30460-define-source.html)

Ridha November 2, 2002 19:15

Define source
 
Hi every body ! i use a (Define_source) for calculing source term.To read a data extern (table_file(Meteo.txt) is denpend on the time). i use the function fscanf Where table_file is the file in which data is stored. and i use these values from the table in calculating the heat flux.every iteration at every time step i read the data file (Meteo.txt) and calcul the heat source , so i use the soubroutine (by Greg Perkins ftp://ftp.cfd-online.com/fluent/udf_scalar_dos.c ) My problom is that Fluent open and read the table_file on every cells because the define_Source is teh function typically loops overs cells in a cell thread and computes cell,(example if for 15000 cell the file meteo is open 15000) what i do ? can i use define adjust to read and store teh data ? please help me ************************************************** ************************************************** ********** File meteo time 0 3 .... Tamb 280 300 vent 280 300 Humid0.5 Ra Tambiante vent Humid 0 10 300 0.5 0.8 3 10 301 3 0.86 6 20 305 4 0.8 9 0 280 0.5 0.9

******************************************* ****************************************** #include"udf.h" # define elements 46 # define elementp 47 #define mu 0.8 /* coefficient d'extinction*/ #define Print printf static real f_s=0.0,dS_s=0.0,Ra=0.0,Tamb=0.0,vent=0.0,Humid=0. 0; /* STATIC version of f and dS Tamb,vent,Humid*/ static int control_t=0 ; /* We use STATIC 'cause we want Fluent to */ static int first_iter ; /* remember these values from iteration */ static real Temp;

**************************** **************************** UDF SOURCE

DEFINE_SOURCE(cell_Source, cell, thread, ds, eqn) {

face_t f;

double temp,source,y,time[elementp],Hs[elementp],Ta[elementp],wind[elementp],Humidt[elementp];

real x[ND_ND];

int i,n,time_step, iter,current_iter;

FILE *fichier;

FILE *fp;

FILE *fd;

fichier= fopen("Meteo.txt","r");

fp=fopen ("out1","w");

fd=fopen ("out2","w");

time_step = RP_Get_Integer("time-step");

temp=((RP_Get_Real("flow-time"))/3600.); current_iter = (nres == 0) ? (0) : ((int) count2[nres - 1]); /* C_CENTROID(x, cell, thread);

y=x[1];*/

/* and iteration */

if(control_t != time_step)

first_iter = current_iter; /* If there's a change */

/* in TIME STEP number, we use it as a cue to flag the iteration as first */

if(first_iter == current_iter) /* Execute for first iteration of each t_step */

{

/* for (i = 0; i< elements ;i++)

{

fscanf(fichier,"%f %f %f %f %f",&time[i],&Hs[i],&Ta[i],&wind[i],&Humidt[i]);

/*read table_file*/ }*/

}

fclose(fichier); for(n = 0; n < elements; n++)

{

if ( (time[n] <= temp) && (temp < time[n+1]) )

{

/* C_CENTROID(x, cell, thread);

y=x[1];

source =f_s =0.6 * Hs[n]* y ;

ds[eqn]=dS_s =0.0;*/

Tamb=Ta[n];

vent=wind[n];

Humid=Humidt[n];

Ra=Hs[n];

} }

C_CENTROID(x, cell, thread);

y=x[1];

ds[eqn]=dS_s =0.0;

control_t = time_step;

}

else

{

C_CENTROID(x, cell, thread);

y=x[1];

source = f_s; /* We don't recalculate, but we need to keep */

ds[eqn] = dS_s; /* returning these values, for the UDF to be effective */

}

return source; }

************************************************** ************************************************** **********



All times are GMT -4. The time now is 13:10.