Add files via upload

This commit is contained in:
nilsberglund-orleans authored and GitHub committed 2021-09-26 16:47:29 +02:00
1 parent 70440115ee
commit c73cbe10a0
10 files changed
+2597 -79

No files matched your search

+159 -3
View File
@@ -16,6 +16,22 @@ void init_xyin(short int * xy_in[NX])
}
}
void init_xyin_xrange(short int * xy_in[NX], int imin, int imax)
/* initialise table xy_in, needed when obstacles are killed */
// short int * xy_in[NX];
//
{
int i, j;
double xy[2];
for (i=imin; i<imax; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
xy_in[i][j] = xy_in_billiard(xy[0],xy[1]);
}
}
void init_wave(double x, double y, double *phi[NX], double *psi[NX], short int * xy_in[NX])
/* initialise field with drop at (x,y) - phi is wave height, psi is phi at time t-1 */
@@ -30,12 +46,53 @@ void init_wave(double x, double y, double *phi[NX], double *psi[NX], short int *
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
xy_in[i][j] = xy_in_billiard(xy[0],xy[1]);
if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.2*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01);
if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.2*exp(-dist2/0.005)*cos(-sqrt(dist2)/0.1);
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.2*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01);
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.2*exp(-dist2/0.00025)*cos(-sqrt(dist2)/0.005);
else phi[i][j] = 0.0;
psi[i][j] = 0.0;
}
}
void init_circular_wave(double x, double y, double *phi[NX], double *psi[NX], short int * xy_in[NX])
/* 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;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
xy_in[i][j] = xy_in_billiard(xy[0],xy[1]);
if ((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_wave_plus(double x, double y, double *phi[NX], double *psi[NX], short int * xy_in[NX])
/* initialise field with drop at (x,y) for y > 0 - phi is wave height, psi is phi at time t-1 */
{
int i, j;
double xy[2], dist2;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
xy_in[i][j] = xy_in_billiard(xy[0],xy[1]);
if ((xy[1] > 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_planar_wave(double x, double y, double *phi[NX], double *psi[NX], short int * xy_in[NX])
/* initialise field with drop at (x,y) - phi is wave height, psi is phi at time t-1 */
@@ -81,7 +138,7 @@ void init_wave_flat( double *phi[NX], double *psi[NX], short int * xy_in[NX])
void add_drop_to_wave(double factor, double x, double y, double *phi[NX], double *psi[NX])
/* add drop at (x,y) to the field with given prefactor */
/* OLD VERSION - add drop at (x,y) to the field with given prefactor */
{
int i, j;
double xy[2], dist2;
@@ -95,6 +152,22 @@ void add_drop_to_wave(double factor, double x, double y, double *phi[NX], double
}
}
void add_circular_wave(double factor, double x, double y, double *phi[NX], double *psi[NX], short int * xy_in[NX])
/* add drop at (x,y) to the field with given prefactor */
{
int i, j;
double xy[2], dist2;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
if ((xy_in[i][j])||(TWOSPEEDS))
phi[i][j] += INITIAL_AMP*factor*exp(-dist2/INITIAL_VARIANCE)*cos(-sqrt(dist2)/INITIAL_WAVELENGTH);
}
}
void oscillate_linear_wave(double amplitude, double t, double x1, double y1, double x2, double y2, double *phi[NX],
double *psi[NX])
@@ -123,6 +196,26 @@ void oscillate_linear_wave(double amplitude, double t, double x1, double y1, dou
}
}
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)
{
@@ -196,7 +289,11 @@ void draw_wave(double *phi[NX], double *psi[NX], short int *xy_in[NX], double sc
if ((TWOSPEEDS)||(xy_in[i][j]))
{
if (plot == P_AMPLITUDE)
color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb);
{
/* make wave luminosity larger inside obstacles */
if (!(xy_in[i][j])) color_scheme_lum(COLOR_SCHEME, phi[i][j], scale, time, 0.7, rgb);
else color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb);
}
else if (plot == P_ENERGY)
color_scheme(COLOR_SCHEME, compute_energy(phi, psi, xy_in, i, j), scale, time, rgb);
else if (plot == P_MIXED)
@@ -216,6 +313,65 @@ void draw_wave(double *phi[NX], double *psi[NX], short int *xy_in[NX], double sc
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<NX; i++)
for (j=0; j<NY; j++)
{
if ((TWOSPEEDS)||(xy_in[i][j]))
{
switch (plot) {
case (P_AMPLITUDE):
{
/* make wave luminosity larger inside obstacles */
if (!(xy_in[i][j])) color_scheme_lum(COLOR_SCHEME, phi[i][j], scale, time, 0.7, rgb);
else color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb);
break;
}
case (P_ENERGY):
{
color_scheme(COLOR_SCHEME, compute_energy(phi, psi, xy_in, i, j), 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;
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 ();
}