一维对流扩散问题TDMA算法

/*
一维对流扩散问题TDMA算法,支持中心差分,迎风,混合,指数,乘方格式,还可
以输出精确解

用法
直接编译运行,不带参数运行时会自动输出使用方法:

upwind –left=(左端点处的值) –right=(右端点处的值) –pdelta=(网格Pe数)
–scheme=(格式,可选center/upwind/mixed/exponent/power/precise) –output=(输出文
件名)

如:
upwind –left=100 –right=200 –pdelta=5 –scheme=upwind –output=Pe5Upwind.dat
参数顺序无关紧要。

注意现在的代码输出相对值(phi-phi0)/(phi_L-phi0),想输出绝对值phi的自己改代码吧:)
另存为upwind.c编译即可
//*/
#include 
#include 
#include 
#include 

double max(double number1,double number2);
void parseParameter(int *argc, char **argv, double *PHI_0, double *PHI_L, double *P_Delta, char *scheme, char *outputfilename);

int main(int argc, char **argv)	
{
	
  const int GRIDAMOUNT=20;//网格数目为20,由于两端点已知,实际未知数个数为19个。
  double PHI_0=100;
	
  double PHI_L=200;
  double P_Delta=1; //网格Pe数,取为1,5,10等。
  char scheme[10]="upwind";
	
  int PRECISE=0;
  char outputfilename[100]="output.dat";
	
  double a_E[GRIDAMOUNT-1];
  double a_W[GRIDAMOUNT-1];
	
  double a_P[GRIDAMOUNT-1];
  double A_P_Delta[GRIDAMOUNT-1];
	
  double P_TDMA[GRIDAMOUNT-1];
  double Q_TDMA[GRIDAMOUNT-1];
	
  double PHI[GRIDAMOUNT-1];
	
  int i;
	
  FILE *dataoutput;
	
  parseParameter(&argc, argv, &PHI_0, &PHI_L, &P_Delta, scheme, outputfilename);
	
  if(!strcmp(scheme,"upwind"))
    {
      for (i=0;i=0;i--)
	
    {
      PHI[i]=P_TDMA[i]*PHI[i+1]+Q_TDMA[i];
	
    }
	
  /* 注意:以下为精确解的计算,仅当需要精确解时方才去掉注释语句  */
  if (PRECISE){
    for (i=0;i=number2)
	
    {
      maxvalue=number1;
    }
  return maxvalue;
	
}
	
void parseParameter(int *argc, char **argv, double *PHI_0, double *PHI_L, double *P_Delta, char *scheme, char *outputfilename)
	
{
  int i=0;
  int pointerofequ=0;
	
  if (*argc<=1)
    {
      fprintf(stderr,"\n Usage:\n%s –scheme SCHEME\n\t –pdelta P_Delta\n\t –left VALUE-OF-LEFT\n\t –right VALUE-OF_RIGHT\n\t –output OUTPUTFILE\n",argv[0]);
	
      exit(0);
    }
  for (i=1;i<*argc;i++)
	
    {
      if ((argv[i][0]=='-')&&(argv[i][1]=='-'))
	
	{
	  argv[i]+=2;
	  pointerofequ=strcspn(argv[i],"=");
	
	  if(!strncmp(argv[i],"pdelta",pointerofequ))
	
	    {
	      argv[i]+=pointerofequ+1;
	      *P_Delta=atol(argv[i]);
	
	    }
	  else if(!strncmp(argv[i],"left",pointerofequ))
	
	    {
	      argv[i]+=pointerofequ+1;
	      *PHI_0=atol(argv[i]);
	
	    }
	  else if(!strncmp(argv[i],"right",pointerofequ))
	
	    {
	      argv[i]+=pointerofequ+1;
	      *PHI_L=atol(argv[i]);
	
	    }
	  else if(!strncmp(argv[i],"scheme",pointerofequ))
	
	    {
	      argv[i]+=pointerofequ+1;
	      strcpy(scheme,argv[i]);
	
	    }
	  else if(!strncmp(argv[i],"output",pointerofequ))
	
	    {
	      argv[i]+=pointerofequ+1;
	      strcpy(outputfilename,argv[i]);
	
	    }
	  else
	    {
	      fprintf(stderr,"\n Unrecognized parameters: –%s\n",argv[i]);
	
	      fprintf(stderr,"\n Usage:\n%s –scheme SCHEME\n\t –pdelta P_Delta\n\t –left VALUE-OF-LEFT\n\t –right VALUE-OF_RIGHT\n\t –output OUTPUTFILE\n",argv[0]);
	
	      exit(0);
	    }
	}
    }
  return;
	
}

你可能感兴趣的:(c++MFC学习笔记)