Entire fan udf in c program


2The user defined fan udf has a part of the code in fortran77 and the remaining part in c language.The entire code has been changed into c language.
Following are the steps to be followed:

1)Read the case file into fluent and identify the zone id of fan through

Define---->Boundary Conditions

and this id has to be specified in the souce code(fan.c) before compilation.

2)Compile the c file ,fan.c, which is given at the end of this text.


3)Give the name of the executable(a.out) to fluent through

Define --->User Defined --->User-Defined Fan Model


4) Intialise the flow field

5)Type the command (update-user-fans) through TUI.This enables fluent to write out the intial profile file.

6)Hook the appropriate profile files which will be available by now, to fan zone through

Define --->Boundary Condition --->fan

7)Start the simulation.

A detailed procedure of the user defined fan model can be found through

<a target=_blank href="http://www.fluentusers.com/fluent6/doc/ori/html/ug/node247.htm">http://www.fluentusers.com/fluent6/doc/ori/html/ug/node247.htm</a>http://www.fluentusers.com/fluent6/doc/ori/html/ug/node247.htm

*********************************************************************
fan.c
*********************************************************************


#include <stdio.h>
#include <string.h>
/*======================================================================
c This program is invoked at intervals by Rampant to read a
c profile-format file that contains radially averaged data at
c a fan face, compute new pressure-jump and swirl-velocity
c components, and write a new profile file that will subsequently
c be read by Rampant to update the fan conditions.
c
c Usage: fantest < input_profile > output_profile
===========================================================================*/

#define npmax 900

const char zone[10] = "fan-5"; /* fan-->zone name of fan;5-->zone id of fan -->USER INPUT */
static int i,inp; /* input: number of profile points*/
static int iptype; /* input: profile type (0=radial, 1=point)*/
static float ir[npmax]; /* input: radial positions*/
static float ip[npmax]; /* input: pressure*/
static float idp[npmax]; /* input: pressure-jump*/
static float irho[npmax]; /* input: density*/
static float iva[npmax]; /* input: axial velocity*/
static float ivr[npmax]; /* input: radial velocity*/
static float ivt[npmax]; /* input: tangential velocity*/
static char zonename[50];
static int status,len;
static char outfile[50],infile[50];
int rfanprof();
void wfanprof();


int main()
{
status = rfanprof();
if (status!= 0)
{
printf("error reading input profile file /n");
}
else
{
for(i = 1;i<= inp;i++)
{
idp[i] = 200.0 - 10.0*iva[i]; /* variartion of pressure-jump */
ivt[i] = 20.0*ir[i]; /* variation of tangential velocity */
ivr[i] = 0.0; /* variartion of radial velocity */
}

wfanprof();
}
return 0;

}

static char readbracket(FILE *fd)
{
char temp;
do
{
temp = getc(fd);
}while ((temp != '(') && temp != ')');
return temp;
}
int rfanprof()
{
FILE *fd;
int n,n_field;
int n_data;
char field[50];
sprintf(outfile,"%s-out.prof",zone);

printf("Reading file.... %s nn",outfile);
fd = fopen(outfile,"r");
readbracket(fd);
readbracket(fd);
fscanf(fd,"%s",zonename);
fscanf(fd,"%s",field);
fscanf(fd,"%d",&inp);
readbracket(fd);
/* printf("No Of Points =%d nn",inp);*/
if (strcmp(zonename,zone) != 0)
{
/* printf("zone name is not same n");*/
return 1;
}
if (inp > npmax)
{
fprintf(stderr,"nread-fan-profile: Too many data points: %d > %d.n",
inp, npmax);
return 1;
}

if (strcmp(field,"radial") == 0)
iptype = 0;
else if (strcmp(field,"point") == 0)
{
iptype = 1;
printf ("Cannot read point type of specification n");
}
else
{
fprintf(stderr,"nread-fan-profile: Wrong profile type: %s instead of radial or point.n",
field);
return 1;
}

readbracket(fd);
do
{
char temp[50];
fscanf(fd,"%s",temp);
strcpy(field,temp);
if (strcmp(field,"r")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&ir[i]);
readbracket(fd);
}
else if(strcmp(field,"pressure")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&ip[i]);
readbracket(fd);
}
else if(strcmp(field,"pressure-jump")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&idp[i]);
readbracket(fd);
}
else if(strcmp(field,"density")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&irho[i]);
readbracket(fd);
}
else if(strcmp(field,"axial-velocity")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&iva[i]);
readbracket(fd);
}
else if(strcmp(field,"radial-velocity")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&ivr[i]);
readbracket(fd);
}
else if(strcmp(field,"tangential-velocity")==0)
{
for(i=1;i<=inp;i++)
fscanf(fd,"%f",&ivt[i]);
readbracket(fd);
}
else
{
/* printf("Unrecognised variable name while reading the file n");*/
return 1;
}

}
while(readbracket(fd) != ')');
return 0;
}



void wfanprof()
{

/* writes a FLUENT profile file for input by the user fan model */
FILE * out;
char * typename;

sprintf(infile,"%s-in.prof",zone);
out = fopen(infile,"w");
/* printf("Writing File......%s nn",infile);*/
if (iptype==0)
typename = "radial";
else
typename = "point";

fprintf(out,"(");
fprintf(out,"(%s %s %d)n",zone,typename,inp);

fprintf(out,"(r n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",ir[i]);
fprintf(out,")n");

fprintf(out,"(pressure n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",ip[i]);
fprintf(out,")n");


fprintf(out,"(pressure-jump n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",idp[i]);
fprintf(out,")n");

fprintf(out,"(density n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",irho[i]);
fprintf(out,")n");

fprintf(out,"(axial-velocity n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",iva[i]);
fprintf(out,")n");


fprintf(out,"(radial-velocity n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",ivr[i]);
fprintf(out,")n");

fprintf(out,"(tangential-velocity n");
for (i=1;i<=inp;i++)
fprintf(out,"%f t",ivt[i]);
fprintf(out,")n");

fprintf(out,")n");

}





Show Form
No comments yet. Be the first to add a comment!