⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exam8.c

📁 CSIMPLE2d CFD C源程序
💻 C
字号:
/*
* exam8.c : example 8 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 (*Vth)[NSIZE];
	double Amu;
	double Omiga;
	double Uin;
	double Flowin;
	double Fl;
	double Ar;

/*******************************************************************************
* 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()
{
	int i;

	Vth=F[3];

	szTitle[0]="U";
	szTitle[1]="V";
	szTitle[2]="Str Fun";
	szTitle[10]="pressure";
	szTitle[3]="R*Vth";
	Relax[0]=0.5;
	Relax[1]=0.5;
	Relax[10]=0.8;
	for( i=0;i<=3;i++)
	{
		bSolve[i]=TRUE;
		bPrint[i]=TRUE;
	}
	bPrint[10]=TRUE;
	iLast=25;
	nMode=2;
	XL=0.5;
	YL=0.5;
	R[1]=0;
	L1=6;//
	M1=6;//

	fnUGrid();
}

/*******************************************************************************
* functon name:	fnStart
* description:	in this file you should do:
*			--initialize the 
********************************************************************************/
void fnStart()
{
	int i,j;
	Omiga=100;
	Uin=100;
	for( i=0;i<=L1;i++)
	{
		for( j=0;j<=M1;j++)
		{
			U[i][j]=0;
			V[i][j]=0;
			Vth[i][j]=0;
			Vth[L1][j]=R[j]*R[j]*Omiga;
		}
	}
	U[1][1]=Uin;
	Amu=1;
}

/*******************************************************************************
* 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;
	double Flt,Add;
	if(iIter==0)
		Flowin=Rho[0][1]*U[1][1]*YCVR[1];
	Fl=0;
	Ar=0;
	for( i=L3;i<=L2;i++)
	{
		Flt=R[M1]*XCV[i]*Rho[i][M1];
		Ar+=Flt;
		Fl+=Flt*V[i][M2];
	}
	Add=(Flowin-Fl)/Ar;
	for(i=L3;i<=L2;i++)
		V[i][M1]=V[i][M2]+Add;
}

/*******************************************************************************
* functon name:	fnOutput
* description:	in this file you should do:
*			--print calc info to terminal or write to file
********************************************************************************/
void fnOutPut()
{
	if(iIter==0)
		fprintf(pFileOut,"\n    Iter    SMax    SSum      U[4][4]      V[4][4]  ");
	fprintf(pFileOut,"\n  %4d  %12.3e  %12.3e  %12.3e  %12.3e",iIter,SMax,SSum,U[3][3],V[3][3]);

	if(iIter==iLast)
		fnPrint();
}

/*******************************************************************************
* functon name:	fnGamsor
* description:	in this file you should do:
*			--set the gam 
*			--set the sc,sp
********************************************************************************/
void fnGamSor()
{
	int i,j;
	double rswm,Rhom;
	if(iIter==0)
	{
		for( i=0;i<=L1;i++)
			for( j=0;j<=M1;j++)
				Gam[i][j]=Amu;
		Gam[L3][M1]=0;
		Gam[L2][M1]=0;
	}
	if(nF==1)
	{
		for( i=1;i<=L2;i++)
		{
			for( j=2;j<=M2;j++)
			{
				rswm=FY[j]*Vth[i][j]+FYM[j]*Vth[i][j-1];
				Rhom=FY[j]*Rho[i][j]+FYM[j]*Rho[i][j-1];
				Con[i][j]=Rhom*rswm*rswm/(RMN[j]*RMN[j]*RMN[j]);
				AP[i][j]=-Amu/(RMN[j]*RMN[j]);
			}
		}
	}
	if(nF==3)
	{
		for( i=1;i<=L2;i++)
		{
			for( j=1;j<=M2;j++)
			{
				Ar=2*Amu/YCVR[j];
				Con[i][j]=Ar*Vth[i][j-1];
				AP[i][j]=-Ar;
			}
		}
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -