#include #define MAXDIM 510 void initialize(double u[][MAXDIM], int flag[][MAXDIM]); void set_cordinate(int n,double x[][MAXDIM],double y[][MAXDIM]); void set_boundary_wall_pot(int n, double u[][MAXDIM], int f[][MAXDIM]); void set_circle(double x0, double y0, double r, double v, int n, double x[][MAXDIM], double y[][MAXDIM], double u[][MAXDIM], int f[][MAXDIM]); void plot_3d(FILE *gp, char *data_file, double rot_x, double rot_z); /*=====================================================================*/ /* main */ /*=====================================================================*/ int main(void){ double u[MAXDIM][MAXDIM]; double x[MAXDIM][MAXDIM], y[MAXDIM][MAXDIM]; int flag[MAXDIM][MAXDIM]; int i,j; int k, iteration; int nlat; char *plot_data_file; FILE *fp; FILE *gp; plot_data_file="result.txt"; nlat=100; initialize(u, flag); set_cordinate(nlat,x,y); set_boundary_wall_pot(nlat, u, flag); set_circle(0.3, 0.3, 0.2, 20.0, nlat, x, y, u, flag); set_circle(0.7, 0.6, 0.03, -20.0, nlat, x, y, u, flag); iteration=2000; /*---------------------------------*/ /* ここにガウスザイデル法の計算を書く */ /* 3重の繰り返し構造 */ /*---------------------------------*/ fp=fopen(plot_data_file,"w"); for(j=0; j<=nlat; j++){ for(i=0; i<=nlat; i++){ fprintf(fp, "%f\t%f\t%f\n",x[i][j],y[i][j],u[i][j]); } fprintf(fp,"\n"); } fclose(fp); gp = popen("gnuplot -persist","w"); plot_3d(gp, plot_data_file, 30, 30); plot_3d(gp, plot_data_file, 45, 30); plot_3d(gp, plot_data_file, 60, 30); plot_3d(gp, plot_data_file, 75, 30); pclose(gp); return 0; } /*=====================================================================*/ /* initialize function */ /*=====================================================================*/ void initialize(double u[][MAXDIM], int flag[][MAXDIM]){ /*---------------------------------*/ /* 繰り返しを使って、初期化する。 */ /*---------------------------------*/ } /*=====================================================================*/ /* set coordinate */ /*=====================================================================*/ void set_cordinate(int n,double x[][MAXDIM],double y[][MAXDIM]){ /*-------------------------------------------*/ /* 繰り返しを使って、格子点の座標を設定する。 */ /*-------------------------------------------*/ } /*=====================================================================*/ /* set external boudary points */ /*=====================================================================*/ void set_boundary_wall_pot(int n, double u[][MAXDIM], int f[][MAXDIM]){ /*---------------------------------------------------------*/ /* 繰り返しを使って、外部境界のポテンシャルとフラグを設定する */ /*---------------------------------------------------------*/ } /*=====================================================================*/ /* set circler boundary */ /*=====================================================================*/ void set_circle(double x0, double y0, double r, double v, int n, double x[][MAXDIM], double y[][MAXDIM], double u[][MAXDIM], int f[][MAXDIM]){ /*---------------------------------------------------------------*/ /* 繰り返しを使って、電極内部の格子点のポテンシャルとフラグを設定する */ /*---------------------------------------------------------------*/ } /*==========================================================*/ /* 3D plot */ /*==========================================================*/ void plot_3d(FILE *gp, char *data_file, double rot_x, double rot_z){ /* == flowing lines make a graph by using gnuplot == */ printf("start plot 3D\n"); fprintf(gp, "reset\n"); fprintf(gp, "set terminal postscript eps color\n"); fprintf(gp, "set output \"graph.eps\"\n"); fprintf(gp, "set view %f,%f\n", rot_x, rot_z); fprintf(gp, "set contour base\n"); fprintf(gp, "set cntrparam levels 20\n"); fprintf(gp, "set hidden3d\n"); fprintf(gp, "set nokey\n"); fprintf(gp, "splot \"%s\" with lines\n", data_file); fprintf(gp, "set terminal x11\n"); fprintf(gp, "replot\n"); }