二维有限体积法计算热传导及源码
//#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
#define q 500
#define k 1000
void main ()
{ //input the value you want:
double L,dx,dy,T,Ax,Ay,d;
int m,n,i,j,kk,mm ;
//char str1[20];
char *str1="conf.dat";
//cout<>str1;
//string str1("data.");
ifstream fin(str1);
if(!fin)
{
cout<
exit(1);
}
cout<
fin>>L>>m>>n>>T;
cout<
cout<
cout<
//creat the maxtrix
mm=m*n;
dx=0.3/m;
dy=0.4/n;
vector ae(mm),ap(mm),aw(mm),an(mm),as(mm),su (mm),sp(mm) ;
Ax=L*dy;
Ay=L*dx;
//结¨¢点Ì?0,左Á ¨®下?角?顶£¤点Ì?
aw[0]=0.0;
ae[0]=k*Ax/dx;an[0]=k*Ay/dy;as[0]=0.0;
sp[0]=0.0;su[0]=q*Ax*k;
ap[0]=aw[0]+ae[0]+an[0]+as[0]-sp[0];
for(i=1;i
{
if(i
{
aw[i]=0.0;
ae[i]=k*Ax/dx;
an[i]=k*Ay/dy;
as[i]=k*Ay/dy;
su[i]=q*Ax*k;
sp[i]=0.0;
ap[i]=aw[i]+ae[i]+as[i]+an[i]-sp[i];
}
else if(i==n-1)
//左Á ¨®上¦?角?顶£¤点Ì?
{
as[i]=k*Ay/dy;
ae[i]=k*Ax/dx;
aw[i]=0.0;
an[i]=0.0;
sp[i]=-2*as[i];
su[i]=q*Ax*k+2*as[i]*T;
ap[i]=aw[i]+ae[i]+as[i]+an[i]-sp[i];
}
else if(i==mm-n) //右® ¨°下?角?顶£¤点Ì?
{ ae[i]=0.0;
as[i]=0.0;
aw [i]=k*Ax/dx;
an[i]=k*Ay/dy;
su[i]=0;
sp[i]=0;
ap[i]=aw [i]+ae[i]+as[i]+an[i]-sp [i];
}
else if(i==mm-1) //右® ¨°上¦?角?顶£¤点Ì?
{
ae[i]=0.0;
aw[i]=k*Ax/dx;
as[i]=k*Ay/dy;
an[i]=0.0;
su[i]=2*as[i]*T ;
sp[i]=-2*as[i];
ap[i]=aw