CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

UDF:spatial-temporal temperature profile on a wall

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 9, 2008, 07:43
Default UDF:spatial-temporal temperature profile on a wall
  #1
Martin Bellmann
Guest
 
Posts: n/a
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) }

  Reply With Quote

Old   July 9, 2008, 16:38
Default Re: UDF:spatial-temporal temperature profile on a
  #2
Paul
Guest
 
Posts: n/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

  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
udf for Temperature profile Ralf FLUENT 5 December 6, 2008 02:42
Spatial &Temporal differencing scheme impingingjet NewBee Main CFD Forum 4 July 16, 2008 13:23
temporal and spatial discretization. pity Main CFD Forum 0 June 10, 2007 23:53
Spatial and temporal discretization Giuseppe FLUENT 2 January 23, 2006 06:18
1st order temporal & 2nd order spatial Prateep Chatterjee FLUENT 0 January 19, 2003 01:31


All times are GMT -4. The time now is 08:51.