/* 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= 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); } } 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 (); }