/* functions common to wave_billiard.c, wave_comparison.c, mangrove.c */ void init_xyin(short int * xy_in[NX]) /* initialise table xy_in, needed when obstacles are killed */ // short int * xy_in[NX]; // { int i, j; double xy[2]; for (i=0; i 0 - phi is wave height, psi is phi at time t-1 */ { int i, j; double xy[2], dist2; for (i=0; i 0.0)&&((xy_in[i][j])||(TWOSPEEDS))) phi[i][j] = INITIAL_AMP*exp(-dist2/INITIAL_VARIANCE)*cos(-sqrt(dist2)/INITIAL_WAVELENGTH); else phi[i][j] = 0.0; psi[i][j] = 0.0; } } void init_circular_wave_xplusminus(double xleft, double yleft, double xright, double yright, double *phi[NX], double *psi[NX], short int * xy_in[NX]) /* initialise field with two drops, x > 0 and x < 0 do not communicate - phi is wave height, psi is phi at time t-1 */ { int i, j; double xy[2], dist2; for (i=0; i= NX) imax = NX-1; jmin = ij1[1] - d; if (jmin < 0) jmin = 0; jmax = ij2[1] + d; if (jmax >= NY) jmax = NY-1; for (i = imin; i < imax; i++) for (j = jmin; j < jmax; j++) { ij_to_xy(i, j, xy); dist2 = (xy[0]-x1)*(xy[0]-x1); /* to be improved */ // dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y); // if (dist2 < 0.01) if (dist2 < 0.001) phi[i][j] = amplitude*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01)*cos(t*OMEGA); // phi[i][j] += 0.2*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01)*cos(t*OMEGA); } } void compute_gradient(double *phi[NX], double *psi[NX], double x, double y, double gradient[2]) { double velocity; int iplus, iminus, jplus, jminus, ij[2], i, j; xy_to_ij(x, y, ij); i = ij[0]; j = ij[1]; iplus = (i+1); if (iplus == NX) iplus = NX-1; iminus = (i-1); if (iminus == -1) iminus = 0; jplus = (j+1); if (jplus == NY) jplus = NY-1; jminus = (j-1); if (jminus == -1) jminus = 0; gradient[0] = (phi[iplus][j]-phi[i][j])*(phi[iplus][j]-phi[i][j]) + (phi[i][j] - phi[iminus][j])*(phi[i][j] - phi[iminus][j]); gradient[1] = (phi[i][jplus]-phi[i][j])*(phi[i][jplus]-phi[i][j]) + (phi[i][j] - phi[i][jminus])*(phi[i][j] - phi[i][jminus]); } double compute_energy(double *phi[NX], double *psi[NX], short int *xy_in[NX], int i, int j) { double velocity, energy, gradientx2, gradienty2; int iplus, iminus, jplus, jminus; velocity = (phi[i][j] - psi[i][j]); iplus = (i+1); if (iplus == NX) iplus = NX-1; iminus = (i-1); if (iminus == -1) iminus = 0; jplus = (j+1); if (jplus == NY) jplus = NY-1; jminus = (j-1); if (jminus == -1) jminus = 0; gradientx2 = (phi[iplus][j]-phi[i][j])*(phi[iplus][j]-phi[i][j]) + (phi[i][j] - phi[iminus][j])*(phi[i][j] - phi[iminus][j]); gradienty2 = (phi[i][jplus]-phi[i][j])*(phi[i][jplus]-phi[i][j]) + (phi[i][j] - phi[i][jminus])*(phi[i][j] - phi[i][jminus]); if (xy_in[i][j]) return(E_SCALE*E_SCALE*(velocity*velocity + 0.5*COURANT*COURANT*(gradientx2+gradienty2))); else if (TWOSPEEDS) return(E_SCALE*E_SCALE*(velocity*velocity + 0.5*COURANTB*COURANTB*(gradientx2+gradienty2))); else return(0); } double compute_variance(double *phi[NX], double *psi[NX], short int *xy_in[NX]) /* compute the variance of the field, to adjust color scheme */ { int i, j, n = 0; double variance = 0.0; for (i=1; i NY/2) color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb); else color_scheme(COLOR_SCHEME, compute_energy(phi, psi, xy_in, i, j), scale, time, rgb); } glColor3f(rgb[0], rgb[1], rgb[2]); glVertex2i(i, j); glVertex2i(i+1, j); glVertex2i(i+1, j+1); glVertex2i(i, j+1); } } glEnd (); } void draw_wave_e(double *phi[NX], double *psi[NX], double *total_energy[NX], short int *xy_in[NX], double scale, int time, int plot) /* draw the field, new version with total energy option */ { int i, j, iplus, iminus, jplus, jminus; double rgb[3], xy[2], x1, y1, x2, y2, velocity, energy, gradientx2, gradienty2; static double dtinverse = ((double)NX)/(COURANT*(XMAX-XMIN)), dx = (XMAX-XMIN)/((double)NX); glBegin(GL_QUADS); // printf("dtinverse = %.5lg\n", dtinverse); for (i=0; i= COL_TURBO) color_scheme_asym(COLOR_SCHEME, energy, scale, time, rgb); else color_scheme(COLOR_SCHEME, energy, scale, time, rgb); break; } case (P_MIXED): { if (j > NY/2) color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb); else color_scheme(COLOR_SCHEME, compute_energy(phi, psi, xy_in, i, j), scale, time, rgb); break; } case (P_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); total_energy[i][j] += energy; if (COLOR_PALETTE >= COL_TURBO) color_scheme_asym(COLOR_SCHEME, total_energy[i][j]/(double)(time+1), scale, time, rgb); else color_scheme(COLOR_SCHEME, total_energy[i][j]/(double)(time+1), scale, time, rgb); break; } } glColor3f(rgb[0], rgb[1], rgb[2]); glVertex2i(i, j); glVertex2i(i+1, j); glVertex2i(i+1, j+1); glVertex2i(i, j+1); } } glEnd (); }