/* 0015grid.c wing in wind tunnel, plot, get left and right grid */ /* wing defined by y=f(x), sequence of points around boundary */ /* pitch about maximum chord, compute x,y,dx,dy */ /* for grid position, slope and normal */ /* write output file 0015a**.dat ** is angle of attack */ #include #include #include #include #include static double xmin = 0.0; static double xmax = 1.0; static double xoff = 0.0; /* 2.0; works with/without offset*/ static double yoff = 0.0; /* 2.0; */ static double ymin; /* computed, depends on angle of attack */ static double ymax; static double xmins; static double xmaxs; static double xtop, ytop, xbot, ybot; /* special points */ static double grid = 0.02; /* grid spacing, may be computed */ static int written = 0; static int maxwrite = 2; static int width = 600; static int height = 600; /* upper part for title */ static double Pi = M_PI; #define npts 200 static double xp[npts]; static double yp[npts]; #define outpts 100 static double leftp[outpts]; /* xinter */ static double rightp[outpts]; static double ygrid[outpts]; static int npts_lr; static double angle_deg = 22.0; /* may be read in */ static char angle_ch[] = "22"; static char fname[] = "0015a22.dat"; static FILE* fout; #undef min #define min(a,b) ((a)<(b)?(a):(b)) #undef max #define max(a,b) ((a)>(b)?(a):(b)) static double f(double x) /* basic symmetrical wing, x=0.0,1.0, need top/bot */ { return (15./20.)*(0.29690*sqrt(x)-0.12600*x-0.35160*x*x+ 0.28430*x*x*x-0.10150*x*x*x*x); } /* end f */ /* rotate wing coordinates based on angle of attack */ static void pitch(double angle, double x, double y, double *ax, double *ay) { double xc; xc = x-0.3; /* rotate about maximum chord */ *ax = 0.3+xc*cos(angle)+y*sin(angle); *ay = -xc*sin(angle)+y*cos(angle); } /* end pitch */ static void yminmax() /* uses and sets globals for min/max */ { int j; ymax = yp[0]; ymin = yp[0]; xmaxs = xp[0]; xmins = xp[0]; ytop = yp[0]; /* for top and bottom grid point */ xtop = xp[0]; for(j=1; jytop) { ytop=yp[j]; xtop = xp[j];} } grid = (ymax-ymin)/11.0; /* just first time */ printf("ymin=%f, ymax=%f \n", ymin, ymax); printf("xmins=%f, xmaxs=%f \n", xmins, xmaxs); printf("xtop=%f, ytop=%f \n", xtop, ytop); printf("grid step=%f \n", grid); } /* end yminmax */ static void build_bound(double angle_deg) /* build wing boundary */ { int j; double x1, y1, x2, y2; double ax1, ay1, ax2, ay2; /* top, positive surface */ double nax1, nay1, nax2, nay2; /* negative surface */ int n; double dx; double angle; angle = Pi*angle_deg/180.0; n = npts/2; dx = (xmax-xmin)/(double)(n-1); for(j=0; jxmaxs) return 0; if(yymax) return 0; for(j=0; jmax(yp[j],yp[j+1])) continue; /* y high */ if(ymax(xp[j],xp[j+1])) continue; /* x beyond */ xinter = xp[j]+(y-yp[j])*(xp[j+1]-xp[j])/(yp[j+1]-yp[j]); if(x>xinter) continue; /* x beyond */ c = 1-c; /* crossing */ } return c; } /* end inside */ void display(void) { double x, y, xlow, xhigh; char title[] = "grid for ** degree angle of attack"; char *p; int i, j; title[9] = angle_ch[0]; title[10] = angle_ch[1]; /* clear window */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity (); /* Draw wings */ draw(); /* fill inside wing, PDE will use points outside */ glColor3f(0.0, 0.0, 1.0); glPointSize(2.0); for(i=1; ixlow && xxlow && xmax(yp[j],yp[j+1])) continue; /* y high */ if(ymax(yp[j],yp[j+1])) continue; /* y high */ if(y=rightp[i]) printf("error on next line \n"); printf(" %f %f %f \n", ygrid[i], leftp[i], rightp[i]); i++; } ygrid[i] = ytop+yoff; /* bottom point */ leftp[i] = xtop; rightp[i] = xtop; printf(" %f %f %f \n", ygrid[i], leftp[i], rightp[i]); i++; npts_lr = i; printf("\nraw points i, x, y \n"); for(i=0; i1) { angle_ch[0] = argv[1][0]; /* use exactly 2 digits. e.g. 00 */ angle_ch[1] = argv[1][1]; angle_deg = (double)atoi(angle_ch); } init(); glutMainLoop(); return 0; } /* end main of 0015grid.c */