CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF:spatial-temporal temperature profile on a wall (http://www.cfd-online.com/Forums/fluent/48723-udf-spatial-temporal-temperature-profile-wall.html)

Martin Bellmann July 9, 2008 06:43

UDF:spatial-temporal temperature profile on a wall
 
Hello All, I'm using the UDF below to specify spatial and temporal temperature profiles on a wall for a cylindrical geometry in 3d. The temperatures are defined on the basis of a cartesian coordinate system (x,y,z). How i can modify this UDF for defining radial profiles (r)in 3d?

Resolution: A UDF has been written to read an input file containing both the spatial and temporal variations of a scalar quantity. The format of this file follows the standard profile format closely and is explained at the end of this file.

The UDF contains three sections: ---------------------------------------------------- - ReadFile Type: On-Demand Purpose: To read the input file table - GetData Type: Function Purpose: Interpolate data - Tspec Type: Profile Purpose: Assign data to each face of the face zone

%-------------------------------------------------------------------------------------------------------------------------------------------------------------------%

#include "udf.h"

int NPtsTm,NPtsData; int DataIsRead = 0; float *tmarr,*xarr,*yarr,*zarr,**Tarr;

DEFINE_ON_DEMAND(ReadFile) { int n,i; float data; FILE* fp;

fp = fopen("DataFile","r"); if ( fp!=NULL ) Message("Reading file \n"); else Message("Error in opening file \n");

fscanf(fp,"%d %d\n",&NPtsTm,&NPtsData); Message("\n"); Message("There are %d time entries and %d spatial entries\n",NPtsTm,NPtsData);

/* Dynamic allocation for 1D array */

tmarr = (float *) malloc(NPtsTm*sizeof(float)); xarr = (float *) malloc(NPtsData*sizeof(float)); yarr = (float *) malloc(NPtsData*sizeof(float)); zarr = (float *) malloc(NPtsData*sizeof(float));

/* Dynamic allocation for 2D array */ { float *temp; temp = (float * ) malloc(NPtsTm*NPtsData*sizeof(float)); Tarr = (float **) malloc(NPtsTm*sizeof(float *));

for(n=0;n<NPtsTm;n++) Tarr[n] = temp + n*NPtsData; }

if ( (tmarr==NULL)||(xarr==NULL)||(yarr==NULL)||(zarr== NULL)||(Tarr==NULL) ) Message("Memory allocation error \n");

fscanf(fp,"\n"); Message("\n"); Message("The following is the %d time entries\n",NPtsTm); for ( n=0;n<NPtsTm;n++ ) { fscanf(fp,"%f \n",&data); tmarr[n] = data; Message(" %f\n",data); }

fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); xarr[i] = data; }

fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); yarr[i] = data; }

fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); zarr[i] = data; }

for ( n=0;n<NPtsTm;n++ ) { fscanf(fp,"\n"); for ( i=0;i<NPtsData;i++ ) { fscanf(fp,"%f \n",&data); Tarr[n][i] = data; } }

DataIsRead = 1; fclose(fp);

/* Output check */

Message("\n"); Message("The following is the %d coordinate entries\n",NPtsData); for ( i=0;i<NPtsData;i++ ) { Message(" %f %f %f\n",xarr[i],yarr[i],zarr[i]); }

for ( n=0;n<NPtsTm;n++ ) { Message("\n"); Message("The following is scalar data for time entry # %d\n",n); for ( i=0;i<NPtsData;i++ ) { Message(" %f\n",Tarr[n][i]); } } }

/*----------------------------------------------------------------------------*/

float GetData(float xf, float yf, float zf, float tm) { int n,nL,nU,i; float tmL,tmU,data,dataL,dataU,sf,smin;

tm += 1.0e-7;

/* Find the time bracket */

nL = 0; nU = 1; tmL = tmarr[nL]; tmU = tmarr[nU];

for ( n=0;n<NPtsTm;n++ ) { if ( (tm>=tmarr[n])&&(tm<=tmarr[n+1]) ) { nL = n; nU = n+1; tmL = tmarr[nL]; tmU = tmarr[nU]; break; } }

/* Find data at the lower and upper time bound */

smin = 1.0e30; dataL = 0.0; dataU = 0.0;

for ( i=0;i<NPtsData;i++ ) { sf = sqrt( pow((xarr[i]-xf),2) + pow((yarr[i]-yf),2) + pow((zarr[i]-zf),2) ); if ( sf<=smin ) { smin = sf; dataL = Tarr[nL][i]; dataU = Tarr[nU][i]; } }

/* Interpolate between lower and upper time values */

data = dataL + ( tm - tmL )/( tmU - tmL )*( dataU - dataL );

return data; }

/*----------------------------------------------------------------------------*/

DEFINE_PROFILE(Tspec,tf,pos) { face_t f; float tm,xf[ND_ND];

tm = RP_Get_Real("flow-time");

begin_f_loop(f,tf) { F_CENTROID(xf,f,tf); F_PROFILE(f,tf,pos) = GetData(xf[0],xf[1],xf[2],tm); } end_f_loop(f,tf) }


Paul July 9, 2008 15:38

Re: UDF:spatial-temporal temperature profile on a
 
If x is your symmetry axis then

r=sqrt(y*y+z*z)

By the way, the above formula is from memory so you better check before you implement it.

All the best,

Paul



All times are GMT -4. The time now is 09:58.