/* 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.0); } void compute_energy_flux(double *phi[NX], double *psi[NX], short int *xy_in[NX], int i, int j, double *gx, double *gy, double *arg, double *module) /* computes energy flux given by c^2 norm(nabla u) du/dt*/ { double velocity, energy, gradientx, gradienty; int iplus, iminus, jplus, jminus; velocity = vabs(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; gradientx = (phi[iplus][j] - phi[iminus][j]); gradienty = (phi[i][jplus] - phi[i][jminus]); *arg = argument(gradientx,gradienty); if (*arg < 0.0) *arg += DPI; if (*arg > DPI) *arg -= DPI; if ((xy_in[i][j])||(TWOSPEEDS)) { *module = velocity*module2(gradientx, gradienty); *gx = velocity*gradientx; *gy = velocity*gradienty; } else { *module = 0.0; *gx = 0.0; *gy = 0.0; } // if (xy_in[i][j]) return(E_SCALE*E_SCALE*(velocity*COURANT*module2(gradientx,gradienty))); // else if (TWOSPEEDS) return(E_SCALE*E_SCALE*(velocity*COURANTB*module2(gradientx,gradienty))); } 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], double *color_scale[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, field_value, energy, gradientx2, gradienty2, r2; 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; } case (P_LOG_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb); break; } case (P_LOG_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); if (energy == 0.0) energy = 1.0e-20; total_energy[i][j] += energy; energy = LOG_SHIFT + LOG_SCALE*log(total_energy[i][j]/(double)(time+1)); color_scheme(COLOR_SCHEME, energy, 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 (); } void draw_wave_highres(int size, 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; } case (P_LOG_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); // energy = LOG_SHIFT + LOG_SCALE*log(energy); // if (energy < 0.0) energy = 0.0; color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb); break; } case (P_LOG_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); if (energy == 0.0) energy = 1.0e-20; total_energy[i][j] += energy; color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(total_energy[i][j]/(double)(time+1)), scale, time, rgb); break; } } glColor3f(rgb[0], rgb[1], rgb[2]); glVertex2i(i, j); glVertex2i(i+size, j); glVertex2i(i+size, j+size); glVertex2i(i, j+size); } } glEnd (); } void draw_wave_ediss(double *phi[NX], double *psi[NX], double *total_energy[NX], double *color_scale[NX], short int *xy_in[NX], double *gamma[NX], double gammamax, double scale, int time, int plot) /* draw the field with luminosity depending on damping */ { int i, j, k, iplus, iminus, jplus, jminus; double rgb[3], xy[2], x1, y1, x2, y2, velocity, field_value, energy, gradientx2, gradienty2, r2; 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; } case (P_LOG_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb); break; } case (P_LOG_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); if (energy == 0.0) energy = 1.0e-20; total_energy[i][j] += energy; color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(total_energy[i][j]/(double)(time+1)), scale, time, rgb); break; } } for (k=0; k<3; k++) rgb[k]*= 1.0 - gamma[i][j]/gammamax; 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_highres_diss(int size, double *phi[NX], double *psi[NX], double *total_energy[NX], short int *xy_in[NX], double *gamma[NX], double gammamax, double scale, int time, int plot) /* draw the field, new version with total energy option */ { int i, j, k, 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; } case (P_LOG_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); // energy = LOG_SHIFT + LOG_SCALE*log(energy); // if (energy < 0.0) energy = 0.0; color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb); break; } case (P_LOG_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); if (energy == 0.0) energy = 1.0e-20; total_energy[i][j] += energy; color_scheme(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(total_energy[i][j]/(double)(time+1)), scale, time, rgb); break; } } for (k=0; k<3; k++) rgb[k]*= 1.0 - gamma[i][j]/gammamax; glColor3f(rgb[0], rgb[1], rgb[2]); glVertex2i(i, j); glVertex2i(i+size, j); glVertex2i(i+size, j+size); glVertex2i(i, j+size); } } glEnd (); } void draw_wave_epalette(double *phi[NX], double *psi[NX], double *total_energy[NX], double *total_flux, double *color_scale[NX], short int *xy_in[NX], double scale, int time, int plot, int palette, int fade, double fade_value) /* same as draw_wave_e, but with color scheme specification */ { int i, j, k, iplus, iminus, jplus, jminus; double rgb[3], xy[2], x1, y1, x2, y2, velocity, field_value, energy, gradientx2, gradienty2, r2, arg, mod, flux_factor, gx, gy, mgx, mgy, ffactor; 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_palette(COLOR_SCHEME, palette, energy, scale, time, rgb); else color_scheme_palette(COLOR_SCHEME, palette, energy, scale, time, rgb); break; } case (P_MIXED): { if (j > NY/2) color_scheme_palette(COLOR_SCHEME, palette, phi[i][j], scale, time, rgb); else color_scheme_palette(COLOR_SCHEME, palette, 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_palette(COLOR_SCHEME, palette, total_energy[i][j]/(double)(time+1), scale, time, rgb); else color_scheme_palette(COLOR_SCHEME, palette, total_energy[i][j]/(double)(time+1), scale, time, rgb); break; } case (P_LOG_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); color_scheme_palette(COLOR_SCHEME, palette, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb); break; } case (P_LOG_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); if (energy == 0.0) energy = 1.0e-20; total_energy[i][j] += energy; energy = LOG_SHIFT + LOG_SCALE*log(total_energy[i][j]/(double)(time+1)); color_scheme_palette(COLOR_SCHEME, palette, energy, scale, time, rgb); break; } case (P_ENERGY_FLUX): { compute_energy_flux(phi, psi, xy_in, i, j, &gx, &gy, &arg, &mod); // color_scheme_palette(C_ONEDIM_LINEAR, palette, arg/DPI, 1.0, 1, rgb); // flux_factor = tanh(mod*E_SCALE); // for (k=0; k<3; k++) rgb[k] *= flux_factor; color_scheme_asym_palette(COLOR_SCHEME, palette, mod*FLUX_SCALE, scale, time, rgb); break; } case (P_TOTAL_ENERGY_FLUX): { // ffactor = 1.0; compute_energy_flux(phi, psi, xy_in, i, j, &gx, &gy, &arg, &mod); total_flux[2*NX*NY + 2*j*NX + 2*i] += gx; total_flux[2*NX*NY + 2*j*NX + 2*i + 1] += gy; total_flux[2*j*NX + 2*i] += total_flux[2*NX*NY + 2*j*NX + 2*i]; total_flux[2*j*NX + 2*i + 1] += total_flux[2*NX*NY + 2*j*NX + 2*i + 1]; // total_flux[2*j*NX + 2*i] *= 1.0 + 1.0/(double)(time+1); // total_flux[2*j*NX + 2*i + 1] *= 1.0 + 1.0/(double)(time+1); // total_flux[2*j*NX + 2*i] *= ffactor; // total_flux[2*j*NX + 2*i + 1] *= ffactor; // total_flux[2*j*NX + 2*i] += gx; // total_flux[2*j*NX + 2*i + 1] += gy; // total_flux[2*j*NX + 2*i] *= 1.0/ffactor; // total_flux[2*j*NX + 2*i + 1] *= 1.0/ffactor; // total_flux[2*j*NX + 2*i] += 0.1*gx; // total_flux[2*j*NX + 2*i + 1] += 0.1*gy; mgx = total_flux[2*j*NX + 2*i]; mgy = total_flux[2*j*NX + 2*i + 1]; // mgx = total_flux[2*j*NX + 2*i]/sqrt((double)(time+1)); // mgy = total_flux[2*j*NX + 2*i + 1]/sqrt((double)(time+1)); // mgx = total_flux[2*j*NX + 2*i]/(1.0 + 0.1*log((double)(time+2))); // mgy = total_flux[2*j*NX + 2*i + 1]/(1.0 + 0.1*log((double)(time+2))); mod = module2(mgx, mgy); arg = argument(mgx, mgy); if (arg < 0.0) arg += DPI; color_scheme_palette(C_ONEDIM_LINEAR, palette, arg/DPI, 1.0, 1, rgb); flux_factor = tanh(mod*FLUX_SCALE); for (k=0; k<3; k++) rgb[k] *= flux_factor; // color_scheme_asym_palette(COLOR_SCHEME, palette, mod, scale, time, rgb); break; } } if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value; 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_highres_palette(int size, double *phi[NX], double *psi[NX], double *total_energy[NX], double *total_flux, short int *xy_in[NX], double scale, int time, int plot, int palette, int fade, double fade_value) /* same as draw_wave_highres, but with color scheme option */ { int i, j, k, iplus, iminus, jplus, jminus; double rgb[3], xy[2], x1, y1, x2, y2, velocity, energy, gradientx2, gradienty2, arg, mod, flux_factor, gx, gy, mgx, mgy; 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_palette(COLOR_SCHEME, palette, energy, scale, time, rgb); else color_scheme_palette(COLOR_SCHEME, palette, energy, scale, time, rgb); break; } case (P_MIXED): { if (j > NY/2) color_scheme_palette(COLOR_SCHEME, palette, phi[i][j], scale, time, rgb); else color_scheme_palette(COLOR_SCHEME, palette, 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_palette(COLOR_SCHEME, palette, total_energy[i][j]/(double)(time+1), scale, time, rgb); else color_scheme_palette(COLOR_SCHEME, palette, total_energy[i][j]/(double)(time+1), scale, time, rgb); break; } case (P_LOG_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); // energy = LOG_SHIFT + LOG_SCALE*log(energy); // if (energy < 0.0) energy = 0.0; color_scheme_palette(COLOR_SCHEME, palette, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb); break; } case (P_LOG_MEAN_ENERGY): { energy = compute_energy(phi, psi, xy_in, i, j); if (energy == 0.0) energy = 1.0e-20; total_energy[i][j] += energy; color_scheme_palette(COLOR_SCHEME, palette, LOG_SHIFT + LOG_SCALE*log(total_energy[i][j]/(double)(time+1)), scale, time, rgb); break; } case (P_ENERGY_FLUX): { compute_energy_flux(phi, psi, xy_in, i, j, &gx, &gy, &arg, &mod); // color_scheme_palette(C_ONEDIM_LINEAR, palette, arg/DPI, 1.0, 1, rgb); // flux_factor = tanh(mod*E_SCALE); // for (k=0; k<3; k++) rgb[k] *= flux_factor; color_scheme_asym_palette(COLOR_SCHEME, palette, mod*FLUX_SCALE, scale, time, rgb); break; } case (P_TOTAL_ENERGY_FLUX): { compute_energy_flux(phi, psi, xy_in, i, j, &gx, &gy, &arg, &mod); total_flux[2*j*NX + 2*i] *= 0.99; total_flux[2*j*NX + 2*i + 1] *= 0.99; total_flux[2*j*NX + 2*i] += gx; total_flux[2*j*NX + 2*i + 1] += gy; // mgx = total_flux[2*j*NX + 2*i]/(double)(time+1); // mgy = total_flux[2*j*NX + 2*i + 1]/(double)(time+1); mgx = total_flux[2*j*NX + 2*i]; mgy = total_flux[2*j*NX + 2*i + 1]; // mgx = total_flux[2*j*NX + 2*i]/log((double)(time+2)); // mgy = total_flux[2*j*NX + 2*i + 1]/log((double)(time+2)); mod = module2(mgx, mgy); arg = argument(mgx, mgy); if (arg < 0.0) arg += DPI; color_scheme_palette(C_ONEDIM_LINEAR, palette, arg/DPI, 1.0, 1, rgb); flux_factor = tanh(mod*E_SCALE); for (k=0; k<3; k++) rgb[k] *= flux_factor; break; } } if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value; glColor3f(rgb[0], rgb[1], rgb[2]); glVertex2i(i, j); glVertex2i(i+size, j); glVertex2i(i+size, j+size); glVertex2i(i, j+size); } } glEnd (); } /* modified function for "flattened" wave tables */ void init_circular_wave_mod(double x, double y, double phi[NX*NY], double psi[NX*NY], short int xy_in[NX*NY]) /* initialise field with drop at (x,y) - phi is wave height, psi is phi at time t-1 */ { int i, j; double xy[2], dist2; printf("Initializing wave\n"); // #pragma omp parallel for private(i,j,xy,dist2) for (i=0; ii3-1)) iplus = i1; // else if ((j>=j2)&&(iplus>i2-1)) iplus = i1; // // iminus = i-1; // if ((j=j2)&&(iminusj3-1)) jplus = j1; // else if ((i>=i2)&&(jplus>j2-1)) jplus = j1; // // jminus = j-1; // if ((i=i2)&&(jminus=i2-1)&&(j>=j2-1)) return(0.0); if ((i>=i3-1)||(j>=j3-1)) return(0.0); } gradientx2 = (phi[iplus*NY+j]-phi[i*NY+j])*(phi[iplus*NY+j]-phi[i*NY+j]) + (phi[i*NY+j] - phi[iminus*NY+j])*(phi[i*NY+j] - phi[iminus*NY+j]); gradienty2 = (phi[i*NY+jplus]-phi[i*NY+j])*(phi[i*NY+jplus]-phi[i*NY+j]) + (phi[i*NY+j] - phi[i*NY+jminus])*(phi[i*NY+j] - phi[i*NY+jminus]); if (xy_in[i*NY+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.0); } void compute_energy_flux_mod(double phi[NX*NY], double psi[NX*NY], short int xy_in[NX*NY], int i, int j, double *gx, double *gy, double *arg, double *module) /* computes energy flux given by c^2 norm(nabla u) du/dt*/ { double velocity, energy, gradientx, gradienty, max = 1.0e5, current_mod, current_arg; int iplus, iminus, jplus, jminus; if ((i == 0)||(i == NX-1)||(j == 0)||(j == NY-1)) { current_mod = 0.0; current_arg = PI; *gx = 0.0; *gy = 0.0; } else if ((xy_in[i*NY+j])||(TWOSPEEDS)) { velocity = vabs(phi[i*NY+j] - psi[i*NY+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;*/ gradientx = (phi[(i+1)*NY+j] - phi[(i-1)*NY+j]); gradienty = (phi[i*NY+j+1] - phi[i*NY+j-1]); if (gradientx > max) gradientx = max; else if (gradientx < -max) gradientx = -max; if (gradienty > max) gradienty = max; else if (gradienty < -max) gradienty = -max; current_mod = velocity*module2(gradientx, gradienty); if (current_mod > 1.0e-10) { current_arg = argument(gradientx,gradienty); if (current_arg < 0.0) current_arg += DPI; if (current_arg >= DPI) current_arg -= DPI; } else current_arg = PI; *gx = velocity*gradientx; *gy = velocity*gradienty; } else { current_mod = 0.0; current_arg = PI; *gx = 0.0; *gy = 0.0; } *module = current_mod; *arg = current_arg; } double compute_phase(double phi[NX*NY], double psi[NX*NY], short int xy_in[NX*NY], int i, int j) { double velocity, angle; velocity = (phi[i*NY+j] - psi[i*NY+j]); if (module2(phi[i*NY+j], velocity) < 1.0e-10) return(0.0); else if (xy_in[i*NY+j]) { angle = argument(phi[i*NY+j], PHASE_FACTOR*velocity/COURANT); if (angle < 0.0) angle += DPI; if ((i==NY/2)&&(j==NY/2)) printf("Phase = %.3lg Pi\n", angle/PI); return(angle); } else if (TWOSPEEDS) { angle = argument(phi[i*NY+j], PHASE_FACTOR*velocity/COURANTB); if (angle < 0.0) angle += DPI; return(angle); } else return(0.0); }