📄 exam3.c
字号:
/*
* exam3.c : example 3 for SIMPLE
*/
/*
* 注意C与FORTRAN的差别:
* 1. C中的数组下标是从0开始的,而FORTRAN则是从1开始的
* 因此本程序中的一些量(如L1,L2,L3,M1,M2,M3,NFMAX,nGam,nP,nRho,IPref,JPref)比FORTRAN程序中的小1
* 所有数组的下标从0开始,程序中数组下标中出现的数字比FORTRAN中的小1
* 2. C的数组是按行优先读的,而FORTRAN的则是按列读的
* 因此本程序中的F的定义不同,是F[NFMAX][I][J]
* 3. C用指针来实现FORTRAN的EQUIVALENCE功能。
* 如定义double (*U)[NSIZE],U=F[0],则U[i][j]等同于F[0][i][j];
*/
#include "staincl.h"
#include "extern.h"
/*global variable for user */
double (*T)[NSIZE];
double (*W)[NSIZE];
double Amu;
double Den;
double Cond;
double Qw;
double Cp;
double RhoCp;
double dPdZ;
double dTbdZ;
double Tw;
double Tb;
double WBAR;
double Re;
double FRe;
double ANu;
/*******************************************************************************
* functon name: fnGrid
* description: in this file you should do:
* --initialize variable you defined
* --set the filename of the output file, the step can be ignored
* --set the title of the variable that will be calculated
* --set which variable will be calc and print
* --set axis mode-nMode: 1-cartesian, 2-axisymmetric, 3-polar
* --set the number of steps
* --set the number of grids
* --devide grids
********************************************************************************/
void fnGrid()
{
W=F[3];
T=F[4];
Amu=1;
Den=1;
Cond=1;
Cp=1;
RhoCp=Den*Cp;
dPdZ=-100;
dTbdZ=5;
Tw=0;
szTitle[3]="W/WBAR";
szTitle[4]="Theta";
bSolve[3]=TRUE;
bPrint[3]=TRUE;
bPrint[4]=TRUE;
iLast=22;
XL=0.5;
YL=0.5;
L1=6;//
M1=6;//
fnUGrid();
}
/*******************************************************************************
* functon name: fnStart
* description: in this file you should do:
* --initialize the
********************************************************************************/
void fnStart()
{
int i,j;
for( i=0;i<=L1;i++)
{
for( j=0;j<=M1;j++)
{
W[i][j]=0;
T[i][j]=1;
if(i==L1||j==M1)
T[i][j]=Tw;
}
}
}
/*******************************************************************************
* functon name: fnDense
* description: in this file you should do:
* --calc the density if needed
********************************************************************************/
void fnDense()
{
}
/*******************************************************************************
* functon name: fnbound
* description: in this file you should do:
* --calc the boundary
********************************************************************************/
void fnBound()
{
int i,j;
double Asum,Wsum,Tsum,AR,WR,DH;
for( i=1;i<=L2;i++)
{
T[i][0]=T[i][1];
W[i][0]=W[i][1];
}
for( j=1;j<=M2;j++)
{
T[0][j]=T[1][j];
W[0][j]=W[1][j];
}
Asum=0;
Wsum=0;
Tsum=0;
for(i=1;i<=L2;i++)
{
for(j=1;j<=M2;j++)
{
AR=XCV[i]*YCV[j];
WR=W[i][j]*AR;
Wsum+=WR;
Asum+=AR;
Tsum+=WR*T[i][j];
}
}
WBAR=Wsum/Asum;
Tb=Tsum/(Wsum+1e-30);
DH=4*XL*YL/(XL+YL);
Re=Den*WBAR*DH/Amu;
FRe=-2*dPdZ*DH/(Den*pow(WBAR,2)+1e-30)*Re;
Qw=dTbdZ*RhoCp*Wsum/(XL+YL);
ANu=Qw*DH/(Cond*(Tw-Tb)+1e-30);
if(iIter==10)
{
bSolve[4]=TRUE;
bSolve[3]=FALSE;
}
}
/*******************************************************************************
* functon name: fnOutput
* description: in this file you should do:
* --print calc info to terminal or write to file
********************************************************************************/
void fnOutPut()
{
int i,j;
if(iIter==0)
{
fprintf(pFileOut,"\n Iter F*Re Nu");
}
fprintf(pFileOut,"\n %4d %12.8f %12.8f ",iIter,FRe,ANu);
if(iIter==iLast)
{
for( i=1;i<=L1;i++)
{
for( j=1;j<=M1;j++)
{
W[i][j]/=(WBAR+1e-30);
T[i][j]=(T[i][j]-Tw)/(Tb-Tw+1e-30);
}
}
fnPrint();
}
}
/*******************************************************************************
* functon name: fnGamsor
* description: in this file you should do:
* --set the gam
* --set the sc,sp
********************************************************************************/
void fnGamSor()
{
int i,j;
double Theta,dTdZ;
for( i=0;i<=L1;i++)
{
for( j=0;j<=M1;j++)
{
Gam[i][j]=Amu;
if(nF==4)//4
Gam[i][j]=Cond;
Gam[i][0]=0;
Gam[0][j]=0;
}
}
if(nF==3)
{
for( i=1;i<=L2;i++)
for( j=1;j<=M2;j++)
Con[i][j]=-dPdZ;
}
else
{
for( i=1;i<=L2;i++)
{
for( j=1;j<=M2;j++)
{
Theta=(T[i][j]-Tw)/(Tb-Tw+1.E-30);
dTdZ=Theta*dTbdZ;
Con[i][j]=-RhoCp*W[i][j]*dTdZ;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -