我正在尝试使用2d TDMA求解器求解2d瞬态热方程。但是,我发现在定义温度场和实现求解器方面存在困难。 我使用了以下代码(LBL函数:逐行方法)但它没有用。
提前感谢您的帮助。
void LBL (int n, int m, int n1, int m1,int m2,
double dt, double dx, double dy,
vector <double> &x, vector<double> &y,
vector< vector<double> > &aw,
vector< vector<double> > &b,
vector< vector<double> > &ap,
vector< vector<double> > &ae,
vector< vector<double> > &an,
vector< vector<double> > &as,
vector< vector<double> > &ap0,
vector< vector<double> > &P,
vector< vector<double> > &Q,
vector< vector<double> > &Td,
vector< vector<double> > &d,
vector< vector<double> > &T0)
{
double ERROR;
double t=0;
double r[n][m];
for(int j=0; j<m; j++)
{
for(int i=0;i<n;i++)
{
d[i][j] =Tin;
r[i][j]=Tin;
T0[i][j]=Tin;
}
}
int s=0;
mi =100000;
while (t<tm)
{
cout << " \n t=" << t<<endl;
/****************calculation of dij****************/
bi(t,n,m,dx,dy,dt,ap0,T0,b);
do
{
for (int j=0; j<m; j++)
{
for (int i=0; i<n; i++)
{
d[i][j] = an[i][j] * r[i][j+1] + as[i][j] * r[i][j-1] + b[i][j];
}
}
MAXI= fabs(d[0][0]-r[0][0])/d[0][0];
for ( int j =0; j < m; j++)
{
for(int i= 0; i<n; i++)
{
ERROR=fabs(d[i][j]-r[i][j])/d[i][j];
if (MAXI < ERROR) MAXI =ERROR;
}
}
cout << " \n MAXI=" << MAXI<<endl;
for ( int j =0; j < m; j++)
{
for(int i= 0; i<n; i++)
{
r[i][j]=d[i][j];
}
}
s++;
} while (MAXI>eps && s<mi );
/***********calculation tdma******************/
for (int j=0; j<m; j++)
{
P[0][j]=ae[0][j]/ap[0][j];
}
for (int j=0; j<m; j++)
{
Q[0][j]=d[0][j]/ap[0][j];
}
for (int j=0; j<m; j++)
{
for(int i=1; i<n; i++)
{
P[i][j]=an[i][j]/(ap[i][j]- (aw[i][j]*P[i-1][j]));
Q[i][j]= (d[i][j] + (aw[i][j]*Q[i-1][j]) ) / (ap[i][j]-(aw[i][j]*P[i-1][j]));
}
}
for(int j =0; j<m; j++)
{
Td[n-1][j]=Q[n-1][j];
}
for(int j =0;j<m;j++)
{
for (int i=n-2; i>=0; i--)
{
Td[i][j]=P[i][j]*Td[i+1][j] + Q[i][j];
}
}
for (int j=0; j<m; j++)
{
for (int i =0; i<n; i++)
{
T0[i][j] =Td[i][j];
}
}
t+=dt;
}
}