YouTube-simulations/sub_wave_comp.c

1382 lines
51 KiB
C
Raw Permalink Normal View History

2021-08-15 11:49:37 +02:00
/* some changes in sub_wave.c required by wave_comparison.c */
short int circletop[NMAXCIRCLES]; /* set to 1 if circle is in top half */
2021-11-12 16:22:24 +01:00
void init_circle_config_half(int pattern, int top, t_circle circles[NMAXCIRCLES])
2021-08-15 11:49:37 +02:00
/* initialise the arrays circlex, circley, circlerad and circleactive */
/* for billiard shape D_CIRCLES */
{
2021-09-01 17:03:02 +02:00
int i, j, k, n, ncirc0, n_p_active, ncandidates=5000, naccepted, nnew;
2022-02-05 18:44:39 +01:00
double dx, dy, p, phi, r, r0, ra[5], sa[5], height, x, y = 0.0, gamma, ymean, ytop, ybottom, dpoisson = 3.05*MU, xmax;
2021-09-01 17:03:02 +02:00
short int active_poisson[NMAXCIRCLES], far;
2021-08-15 11:49:37 +02:00
ymean = 0.5*(YMIN + YMAX);
switch (pattern) {
case (C_SQUARE):
{
dy = (YMAX - YMIN)/((double)NGRIDY);
for (i = 0; i < NGRIDX; i++)
for (j = 0; j < NGRIDY/2; j++)
{
printf("i = %i, j = %i, n = %i\n", i, j, n);
n = ncircles + NGRIDY*i/2 + j;
2021-11-12 16:22:24 +01:00
circles[n].xc = ((double)(i-NGRIDX/2) + 0.5)*dy;
2021-08-15 11:49:37 +02:00
y = ((double)j + 0.5)*dy;
2021-11-12 16:22:24 +01:00
if (top) circles[n].yc = ymean + y;
else circles[n].yc = ymean - y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
}
ncircles += NGRIDX*NGRIDY/2;
break;
}
case (C_HEX):
{
dy = (YMAX - YMIN)/((double)NGRIDY);
dx = dy*0.5*sqrt(3.0);
for (i = 0; i < NGRIDX; i++)
2021-12-28 15:42:56 +01:00
for (j = 0; j < NGRIDY/2+2; j++)
2021-08-15 11:49:37 +02:00
{
2021-12-28 15:42:56 +01:00
n = ncircles + (NGRIDY+2)*i/2 + j;
circles[n].xc = ((double)(i-NGRIDX/2) + 0.5)*dy;
2021-08-15 11:49:37 +02:00
y = ((double)j - 0.5)*dy;
if ((i+NGRIDX)%2 == 1) y += 0.5*dy;
2021-11-12 16:22:24 +01:00
if (top) circles[n].yc = ymean + 0.5*dy + y;
else circles[n].yc = ymean - 0.5*dy - y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
}
2021-12-28 15:42:56 +01:00
ncircles += NGRIDX*(NGRIDY+2)/2;
2021-08-15 11:49:37 +02:00
break;
}
2022-02-05 18:44:39 +01:00
case (C_HEX_NONUNIF):
{
dy = (YMAX - YMIN)/((double)NGRIDY);
dx = dy*0.5*sqrt(3.0);
for (i = 0; i < NGRIDX; i++)
for (j = 0; j < NGRIDY/2+2; j++)
{
n = ncircles + (NGRIDY+2)*i/2 + j;
x = ((double)(i-NGRIDX/2) + 0.5)*dy;
xmax = ((double)(NGRIDX/2) - 0.5)*dy;
if (top) circles[n].xc = x - HEX_NONUNIF_COMPRESSSION*(x*x - xmax*xmax);
else circles[n].xc = x - HEX_NONUNIF_COMPRESSSION_B*(x*x - xmax*xmax);
y = ((double)j - 0.5)*dy;
if ((i+NGRIDX)%2 == 1) y += 0.5*dy;
if (top) circles[n].yc = ymean + 0.5*dy + y;
else circles[n].yc = ymean - 0.5*dy - y;
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
circles[n].active = 1;
circletop[n] = top;
}
ncircles += NGRIDX*(NGRIDY+2)/2;
break;
}
2021-08-15 11:49:37 +02:00
case (C_RAND_DISPLACED):
{
dy = (YMAX - YMIN)/((double)NGRIDY);
for (i = 0; i < NGRIDX; i++)
for (j = 0; j < NGRIDY/2; j++)
{
n = ncircles + NGRIDY*i/2 + j;
2021-11-12 16:22:24 +01:00
circles[n].xc = ((double)(i-NGRIDX/2) + 0.5*((double)rand()/RAND_MAX - 0.5))*dy;
if (NGRIDX%2 == 0) circles[n].xc += 0.5*dy;
2021-08-15 11:49:37 +02:00
y = ((double)j + 0.5 + 0.5*((double)rand()/RAND_MAX - 0.5))*dy;
2021-11-12 16:22:24 +01:00
if (top) circles[n].yc = ymean + y;
else circles[n].yc = ymean - y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU*sqrt(1.0 + 0.8*((double)rand()/RAND_MAX - 0.5));
else circles[n].radius = MUB*sqrt(1.0 + 0.8*((double)rand()/RAND_MAX - 0.5));
2021-11-12 16:22:24 +01:00
circles[n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
2021-11-12 16:22:24 +01:00
printf("n = %i, x = %.3lg\n", n, circles[n].xc);
2021-08-15 11:49:37 +02:00
}
ncircles += NGRIDX*NGRIDY/2;
break;
}
case (C_RAND_PERCOL):
{
dy = (YMAX - YMIN)/((double)NGRIDY);
for (i = 0; i < NGRIDX; i++)
for (j = 0; j < NGRIDY/2; j++)
{
n = ncircles + NGRIDY*i/2 + j;
2021-11-12 16:22:24 +01:00
circles[n].xc = ((double)(i-NGRIDX/2) + 0.5)*dy;
2021-08-15 11:49:37 +02:00
y = YMIN + ((double)j + 0.5)*dy;
if ( ((top)&&(y > 0.0))||((!top)&&(y <= 0.0)) )
2021-11-12 16:22:24 +01:00
circles[n].yc = y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
2021-08-15 11:49:37 +02:00
p = (double)rand()/RAND_MAX;
2021-11-12 16:22:24 +01:00
if (p < P_PERCOL) circles[n].active = 1;
else circles[n].active = 0;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
}
ncircles += NGRIDX*NGRIDY/2;
break;
}
case (C_RAND_POISSON):
{
for (i = 0; i < NPOISSON/2; i++)
{
n = ncircles + i;
2021-11-12 16:22:24 +01:00
circles[n].xc = LAMBDA*(2.0*(double)rand()/RAND_MAX - 1.0);
2021-08-15 11:49:37 +02:00
if (top) y = ymean + (YMAX-ymean)*(double)rand()/RAND_MAX;
else y = ymean + (YMIN-ymean)*(double)rand()/RAND_MAX;
if ( ((top)&&(y > 0.0))||((!top)&&(y <= 0.0)) )
2021-11-12 16:22:24 +01:00
circles[n].yc = y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
2021-11-12 16:22:24 +01:00
printf("n = %i, x = %.3lg\n", n, circles[n].xc);
2021-08-15 11:49:37 +02:00
}
ncircles += NPOISSON/2;
break;
}
case (C_CLOAK):
{
for (i = 0; i < 40; i++)
for (j = 0; j < 5; j++)
{
n = ncircles + 5*i + j;
phi = (double)i*DPI/40.0;
r = LAMBDA*0.5*(1.0 + (double)j/5.0);
2021-11-12 16:22:24 +01:00
circles[n].xc = r*cos(phi);
2021-08-15 11:49:37 +02:00
y = r*sin(phi);
if ( ((top)&&(y > 0.0))||((!top)&&(y <= 0.0)) )
2021-11-12 16:22:24 +01:00
circles[n].yc = y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
}
ncircles += 200;
break;
}
case (C_CLOAK_A): /* optimized model A1 by C. Jo et al */
{
ra[0] = 0.0731; sa[0] = 1.115;
ra[1] = 0.0768; sa[1] = 1.292;
ra[2] = 0.0652; sa[2] = 1.464;
ra[3] = 0.056; sa[3] = 1.633;
ra[4] = 0.0375; sa[4] = 1.794;
for (i = 0; i < 21; i++)
for (j = 0; j < 5; j++)
{
n = ncircles + 5*i + j;
phi = (double)i*DPI/40.0;
r = LAMBDA*sa[j];
2021-11-12 16:22:24 +01:00
circles[n].xc = r*cos(phi);
circles[n].yc = r*sin(phi);
2021-08-15 11:49:37 +02:00
if (top) y = r*sin(phi);
else y = -r*sin(phi);
2021-11-12 16:22:24 +01:00
circles[n].yc = y;
2021-08-15 11:49:37 +02:00
2021-11-12 16:22:24 +01:00
circles[n].radius = LAMBDA*ra[j];
circles[n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[n] = top;
}
ncircles += 105;
/* add circle in the center */
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = 0.0;
circles[ncircles].yc = 0.0;
2021-11-13 23:06:17 +01:00
if (top) circles[ncircles].radius = MU;
else circles[ncircles].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[ncircles].active = 2;
2021-08-15 11:49:37 +02:00
circletop[ncircles] = top;
ncircles += 1;
break;
}
2021-09-01 17:03:02 +02:00
case (C_POISSON_DISC):
{
printf("Generating Poisson disc sample\n");
/* generate first circle */
n = ncircles;
2021-11-12 16:22:24 +01:00
circles[n].xc = LAMBDA*(2.0*(double)rand()/RAND_MAX - 1.0);
2021-09-01 17:03:02 +02:00
if (top) y = ymean + (YMAX-ymean)*(double)rand()/RAND_MAX;
else y = ymean + (YMIN-ymean)*(double)rand()/RAND_MAX;
2021-11-12 16:22:24 +01:00
circles[n].yc = y;
2021-11-13 23:06:17 +01:00
if (top) circles[n].radius = MU;
else circles[n].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[n].active = 1;
2021-09-01 17:03:02 +02:00
circletop[n] = top;
active_poisson[n] = 1;
n_p_active = 1;
ncirc0 = 1;
while ((n_p_active > 0)&&(ncircles + ncirc0 < NMAXCIRCLES))
{
/* randomly select an active circle */
i = rand()%(ncirc0);
n = ncircles + i;
while (!active_poisson[ncircles + i]) i = rand()%(ncirc0);
2021-11-12 16:22:24 +01:00
// printf("Starting from circle %i at (%.3f,%.3f)\n", i, circles[i].xc, circles[i].yc);
2021-09-01 17:03:02 +02:00
/* generate new candidates */
naccepted = 0;
for (j=0; j<ncandidates; j++)
{
r = dpoisson*(2.0*(double)rand()/RAND_MAX + 1.0);
phi = DPI*(double)rand()/RAND_MAX;
2021-11-12 16:22:24 +01:00
x = circles[n].xc + r*cos(phi);
y = circles[n].yc + r*sin(phi);
2021-09-01 17:03:02 +02:00
// printf("Testing new circle at (%.3f,%.3f)\t", x, y);
far = 1;
for (k=ncircles; k<ncircles + ncirc0; k++) if ((k!=n))
{
/* new circle is far away from circle k */
2021-11-12 16:22:24 +01:00
far = far*((x - circles[k].xc)*(x - circles[k].xc) + (y - circles[k].yc)*(y - circles[k].yc) >= dpoisson*dpoisson);
2021-09-01 17:03:02 +02:00
/* new circle is in domain */
if (top) far = far*(vabs(x) < LAMBDA)*(y < YMAX)*(y > 0.0);
else far = far*(vabs(x) < LAMBDA)*(y > YMIN)*(y < 0.0);
}
if (far) /* accept new circle */
{
printf("New circle at (%.3f,%.3f) accepted\n", x, y);
nnew = ncircles + ncirc0;
2021-11-12 16:22:24 +01:00
circles[nnew].xc = x;
circles[nnew].yc = y;
2021-11-13 23:06:17 +01:00
if (top) circles[nnew].radius = MU;
else circles[nnew].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[nnew].active = 1;
2021-09-01 17:03:02 +02:00
active_poisson[nnew] = 1;
2021-11-12 16:22:24 +01:00
// circleactive[nnew] = 1;
2021-09-01 17:03:02 +02:00
circletop[nnew] = top;
ncirc0++;
n_p_active++;
naccepted++;
}
// else printf("Rejected\n");
}
if (naccepted == 0) /* inactivate circle i */
{
// printf("No candidates work, inactivate circle %i\n", ncircles + i);
active_poisson[ncircles + i] = 0;
n_p_active--;
}
printf("%i active circles\n", n_p_active);
// sleep(1);
}
printf("Already existing: %i circles\n", ncircles);
ncircles += ncirc0;
printf("Generated %i circles\n", ncirc0);
printf("Total: %i circles\n", ncircles);
break;
}
2021-08-15 11:49:37 +02:00
case (C_GOLDEN_MEAN):
{
gamma = (sqrt(5.0) - 1.0)*0.5; /* golden mean */
height = YMAX - ymean;
dx = 2.0*LAMBDA/150.0;
if (top) y = ymean + 0.5*height;
else y = ymean - 0.5*height;
for (n = 0; n < 150; n++)
{
2021-11-12 16:22:24 +01:00
circles[ncircles + n].xc = -LAMBDA + n*dx;
circles[ncircles + n].yc = y;
2021-08-15 11:49:37 +02:00
if (top)
{
y += height*gamma;
if (y > YMAX) y -= height;
}
else
{
y -= height*gamma;
if (y < YMIN) y += height;
}
2021-11-13 23:06:17 +01:00
if (top) circles[ncircles + n].radius = MU;
else circles[ncircles + n].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[ncircles + n].active = 1;
2021-08-15 11:49:37 +02:00
circletop[ncircles] = top;
}
/* test for circles that overlap top or bottom boundary */
ncirc0 = ncircles;
ncircles += 150;
if (top) ytop = YMAX;
else ytop = ymean;
if (top) ybottom = ymean;
else ybottom = YMIN;
for (n=0; n < 150; n++)
{
2021-11-12 16:22:24 +01:00
if (circles[ncirc0+n].yc + circles[ncirc0 + n].radius > ytop)
2021-08-15 11:49:37 +02:00
{
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = circles[ncirc0 + n].xc;
circles[ncircles].yc = circles[ncirc0+n].yc - height;
circles[ncircles].radius = MU;
circles[ncircles].active = 1;
2021-08-15 11:49:37 +02:00
ncircles ++;
}
2021-11-12 16:22:24 +01:00
else if (circles[ncirc0+n].yc - circles[ncirc0 + n].radius < ybottom)
2021-08-15 11:49:37 +02:00
{
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = circles[ncirc0 + n].xc;
circles[ncircles].yc = circles[ncirc0+n].yc + height;
circles[ncircles].radius = MU;
circles[ncircles].active = 1;
2021-08-15 11:49:37 +02:00
ncircles ++;
}
}
break;
}
2021-09-01 17:03:02 +02:00
case (C_GOLDEN_SPIRAL):
{
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = 0.0;
circles[ncircles].yc = 0.0;
2021-11-13 23:06:17 +01:00
if (top) circles[ncircles].radius = MU;
else circles[ncircles].radius = MUB;
2021-11-12 16:22:24 +01:00
circles[ncircles].active = 1;
2021-09-01 17:03:02 +02:00
circletop[ncircles] = top;
gamma = (sqrt(5.0) - 1.0)*PI; /* golden mean times 2Pi */
phi = 0.0;
r0 = 2.0*MU;
r = r0 + MU;
for (i=0; i<1000; i++)
{
x = r*cos(phi);
y = r*sin(phi);
phi += gamma;
r += MU*r0/r;
if ((vabs(x) < LAMBDA)&&(vabs(y) < YMAX + MU))
{
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = x;
circles[ncircles].yc = y;
circles[ncircles].radius = MU;
if (((top)&&(circles[ncircles].yc < YMAX + MU)&&(circles[ncircles].yc > ymean - MU))
||((!top)&&(circles[ncircles].yc < ymean + MU)&&(circles[ncircles].yc > YMIN - MU)))
2021-09-01 17:03:02 +02:00
{
2021-11-12 16:22:24 +01:00
circles[ncircles].active = 1;
2021-09-01 17:03:02 +02:00
circletop[ncircles] = top;
ncircles++;
}
}
}
break;
}
2021-08-15 11:49:37 +02:00
case (C_ONE):
{
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = 0.0;
circles[ncircles].yc = 0.0;
if (top) circles[ncircles].radius = MU;
else circles[ncircles].radius = MUB;
circles[ncircles].active = 1;
2021-08-15 11:49:37 +02:00
circletop[ncircles] = top;
ncircles += 1;
break;
}
case (C_TWO):
{
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = 0.0;
circles[ncircles].yc = 0.0;
if (top) circles[ncircles].radius = MU;
else circles[ncircles].radius = MUB;
circles[ncircles].active = 2;
2021-08-15 11:49:37 +02:00
circletop[ncircles] = top;
ncircles += 1;
2021-11-12 16:22:24 +01:00
circles[ncircles].xc = 0.0;
circles[ncircles].yc = 0.0;
if (top) circles[ncircles].radius = 2.0*MU;
else circles[ncircles].radius = 2.0*MUB;
circles[ncircles].active = 1;
2021-08-15 11:49:37 +02:00
circletop[ncircles] = top;
ncircles += 1;
break;
}
case (C_NOTHING):
{
ncircles += 0;
break;
}
default:
{
printf("Function init_circle_config not defined for this pattern \n");
}
}
}
2021-11-12 16:22:24 +01:00
void init_circle_config_comp(t_circle circles[NMAXCIRCLES])
2021-08-15 11:49:37 +02:00
/* initialise the arrays circlex, circley, circlerad and circleactive */
/* for billiard shape D_CIRCLES */
{
ncircles = 0;
2021-11-12 16:22:24 +01:00
init_circle_config_half(CIRCLE_PATTERN, 1, circles);
init_circle_config_half(CIRCLE_PATTERN_B, 0, circles);
2021-08-15 11:49:37 +02:00
}
2021-11-12 16:22:24 +01:00
void init_circle_config_energy(t_circle circles[NMAXCIRCLES])
2021-09-01 17:03:02 +02:00
/* initialise the arrays circlex, circley, circlerad and circleactive */
/* for billiard shape D_CIRCLES */
{
ncircles = 0;
2021-11-12 16:22:24 +01:00
init_circle_config_half(CIRCLE_PATTERN, 0, circles);
2021-09-01 17:03:02 +02:00
}
2021-08-15 11:49:37 +02:00
2021-11-13 23:06:17 +01:00
2021-12-28 15:42:56 +01:00
void init_polygon_config_half(int pattern, int top, int random_angle, int xdep_angle, t_polygon polygons[NMAXCIRCLES])
2021-11-13 23:06:17 +01:00
/* initialise the polygon configuration, for billiard shape D_CIRCLES */
/* uses init_circle_config, this is where C++ would be more elegant */
{
int i;
t_circle circle[NMAXCIRCLES];
// ncircles = 0;
init_circle_config_half(pattern, top, circle);
for (i=0; i<NMAXCIRCLES; i++)
{
polygons[i].xc = circle[i].xc;
polygons[i].yc = circle[i].yc;
polygons[i].radius = circle[i].radius;
polygons[i].active = circle[i].active;
polygons[i].nsides = NPOLY;
2021-12-28 15:42:56 +01:00
if ((top)&&(circletop[i]))
{
if (random_angle) polygons[i].angle = DPI*(double)rand()/RAND_MAX;
else if (xdep_angle) polygons[i].angle = APOLY + PID*POLY_ROTATION_ANGLE*polygons[i].xc;
else polygons[i].angle = APOLY;
}
else if ((!top)&&(!circletop[i]))
{
if (random_angle) polygons[i].angle = DPI*(double)rand()/RAND_MAX;
else if (xdep_angle) polygons[i].angle = APOLY_B + PID*POLY_ROTATION_ANGLE*polygons[i].xc;
else polygons[i].angle = APOLY_B;
}
if (i < ncircles) printf("(x,y) = (%.2f, %.2f), r = %.2f, angle = %.2f, sides = %i\n", polygons[i].xc, polygons[i].yc, polygons[i].radius, polygons[i].angle, polygons[i].nsides);
2021-11-13 23:06:17 +01:00
}
}
void init_polygon_config_comp(t_polygon polygons[NMAXCIRCLES])
/* initialise polygon configuration for billiard shape D_POLYGONS */
{
ncircles = 0;
2021-12-28 15:42:56 +01:00
init_polygon_config_half(CIRCLE_PATTERN, 1, RANDOM_POLY_ANGLE, XDEP_POLY_ANGLE, polygons);
init_polygon_config_half(CIRCLE_PATTERN_B, 0, RANDOM_POLY_ANGLE_B, XDEP_POLY_ANGLE_B, polygons);
2021-11-13 23:06:17 +01:00
}
2021-08-15 11:49:37 +02:00
int xy_in_billiard_half(double x, double y, int domain, int pattern, int top)
/* returns 1 if (x,y) represents a point in the billiard */
{
2023-12-26 23:01:20 +01:00
double l2, r2, r2mu, omega, c, angle, z, x1, y1, x2, y2, u, v, u1, v1, dx, dy, width, a, b;
2021-08-15 11:49:37 +02:00
int i, j, k, k1, k2, condition, type;
switch (domain) {
2023-07-08 23:28:23 +02:00
case (D_NOTHING):
{
return(1);
break;
}
2021-11-13 23:06:17 +01:00
case (D_MENGER):
2021-08-15 11:49:37 +02:00
{
x1 = 0.5*(x+1.0);
y1 = 0.5*(y+1.0);
for (k=0; k<MDEPTH; k++)
{
x1 = x1*(double)MRATIO;
y1 = y1*(double)MRATIO;
if ((top)&&(y > 0.0)&&(vabs(x)<1.0)&&(vabs(y)<1.0)&&(((int)x1 % MRATIO)==MRATIO/2)&&(((int)y1 % MRATIO)==MRATIO/2)) return(0);
else if ((!top)&&(y < 0.0)&&(vabs(x)<1.0)&&(vabs(y)<1.0)&&(((int)x1 % MRATIO)==MRATIO/2)&&(((int)y1 % MRATIO)==MRATIO/2)) return(0);
}
return(1);
}
2021-11-13 23:06:17 +01:00
case (D_CIRCLES):
2021-08-15 11:49:37 +02:00
{
for (i = 0; i < ncircles; i++)
2021-11-12 16:22:24 +01:00
if (circles[i].active != 0)
2021-08-15 11:49:37 +02:00
{
2021-11-12 16:22:24 +01:00
/* choose specific type according to value of circles[i].active */
if (circles[i].active == 1) type = 0;
else type = circles[i].active;
2021-08-15 11:49:37 +02:00
2021-11-12 16:22:24 +01:00
x1 = circles[i].xc;
y1 = circles[i].yc;
r2 = circles[i].radius*circles[i].radius;
2021-08-15 11:49:37 +02:00
if ((top)&&(circletop[i])&&(y > 0.0)&&((x-x1)*(x-x1) + (y-y1)*(y-y1) < r2)) return(type);
else if ((!top)&&(!circletop[i])&&(y < 0.0)&&((x-x1)*(x-x1) + (y-y1)*(y-y1) < r2)) return(type);
}
return(1);
}
2021-11-13 23:06:17 +01:00
case (D_POLYGONS):
{
for (i = 0; i < ncircles; i++)
if (polygons[i].active)
{
/* choose specific type according to value of circles[i].active */
if (polygons[i].active == 1) type = 0;
else type = polygons[i].active;
if ((top)&&(circletop[i])&&(y > 0.0)&&(in_tpolygon(x, y, polygons[i]))) return(type);
else if ((!top)&&(!circletop[i])&&(y < 0.0)&&(in_tpolygon(x, y, polygons[i]))) return(type);
}
return(1);
}
2022-03-13 15:29:50 +01:00
case (D_FRESNEL):
{
if (vabs(y) > 0.9*vabs(LAMBDA)) return(1);
if (vabs(x) > MU) return(1);
x1 = sqrt(LAMBDA*LAMBDA - y*y) - vabs(LAMBDA);
while (x1 <= 0.0) x1 += MU;
if (LAMBDA > 0.0)
{
if (x < x1) return(0);
else return(1);
}
else
{
if (x > -x1) return(0);
else return(1);
}
}
case (D_CIRCLE_SEGMENT):
{
if (vabs(y) > 0.9*vabs(LAMBDA)) return(1);
y1 = 0.9*LAMBDA;
x1 = sqrt(LAMBDA*LAMBDA - y1*y1) - vabs(LAMBDA) + MU;
if ((LAMBDA > 0.0)&&(x < x1)) return(1);
else if ((LAMBDA < 0.0)&&(x > -x1)) return(1);
x1 = sqrt(LAMBDA*LAMBDA - y*y) - vabs(LAMBDA) + MU;
if (LAMBDA > 0.0)
{
if (x < x1) return(0);
else return(1);
}
else
{
if (x > -x1) return(0);
else return(1);
}
}
2023-12-26 23:01:20 +01:00
case (D_TWO_LENSES_WALL):
{
width = 0.2;
a = 1.9;
b = 1.9 - 2.0*LAMBDA + 2.0*width;
x1 = vabs(x);
if (module2(x1 - a, y) > LAMBDA) return(1);
if (module2(x1 - b, y) > LAMBDA) return(1);
return(0);
}
case (D_TWO_LENSES_OBSTACLE):
{
width = 0.2;
a = 1.9;
b = 1.9 - 2.0*LAMBDA + 2.0*width;
x1 = vabs(x);
if (module2(x1 - a, y) > LAMBDA) return(1);
if (module2(x1 - b, y) > LAMBDA) return(1);
return(0);
}
2022-03-13 15:29:50 +01:00
default:
2021-08-15 11:49:37 +02:00
{
printf("Function ij_in_billiard not defined for this billiard \n");
return(0);
}
}
}
int xy_in_billiard_comp(double x, double y)
/* returns 1 if (x,y) represents a point in the billiard */
{
if (y > 0) return(xy_in_billiard_half(x, y, B_DOMAIN, CIRCLE_PATTERN, 1));
else return(xy_in_billiard_half(x, y, B_DOMAIN_B, CIRCLE_PATTERN_B, 0));
}
int ij_in_billiard_comp(int i, int j)
/* returns 1 if (i,j) represents a point in the billiard */
{
double xy[2];
ij_to_xy(i, j, xy);
return(xy_in_billiard_comp(xy[0], xy[1]));
}
2023-12-26 23:01:20 +01:00
void draw_billiard_half(int domain, int pattern, int top, int fade, double fade_value)
/* draws the billiard boundary */
2021-08-15 11:49:37 +02:00
/* two domain version implemented for D_CIRCLES */
{
2023-12-26 23:01:20 +01:00
double x0, x, y, x1, y1, dx, dy, phi, r = 0.01, pos[2], pos1[2], alpha, dphi, omega, z, l, signtop, width, a, b, arcangle;
2021-08-15 11:49:37 +02:00
int i, j, k, k1, k2, mr2;
2023-12-26 23:01:20 +01:00
static int first = 1;
2021-12-28 15:42:56 +01:00
glEnable(GL_SCISSOR_TEST);
if (top) glScissor(0.0, YMID, NX, YMID);
2022-03-13 15:29:50 +01:00
// if (top) glScissor(0.0, YMID, NX, YMAX);
2021-12-28 15:42:56 +01:00
else glScissor(0.0, 0.0, NX, YMID);
2021-08-15 11:49:37 +02:00
2023-12-26 23:01:20 +01:00
if (fade)
{
if (BLACK) glColor3f(fade_value, fade_value, fade_value);
else glColor3f(1.0 - fade_value, 1.0 - fade_value, 1.0 - fade_value);
}
else
{
if (BLACK) glColor3f(1.0, 1.0, 1.0);
else glColor3f(0.0, 0.0, 0.0);
}
2021-08-15 11:49:37 +02:00
glLineWidth(5);
if (top) signtop = 1.0;
else signtop = -1.0;
glEnable(GL_LINE_SMOOTH);
switch (domain) {
case (D_MENGER):
{
glLineWidth(3);
// draw_rectangle(XMIN, -1.0, XMAX, 1.0);
/* level 1 */
if (MDEPTH > 0)
{
glLineWidth(2);
x = 1.0/((double)MRATIO);
draw_rectangle(-x, 0.0, x, signtop*x);
}
/* level 2 */
if (MDEPTH > 1)
{
glLineWidth(1);
mr2 = MRATIO*MRATIO;
l = 2.0/((double)mr2);
for (i=0; i<MRATIO; i++)
for (j=MRATIO/2; j<MRATIO; j++)
if ((i!=MRATIO/2)||(j!=MRATIO/2))
{
x = -1.0 - 0.5*l + 2.0*((double)i + 0.5)/((double)MRATIO);
y = -1.0 - 0.5*l + 2.0*((double)j + 0.5)/((double)MRATIO);
y1 = y+l;
if (y < 0.0) y = 0.0;
if (y1 < 0.0) y1 = 0.0;
draw_rectangle(x, signtop*y, x+l, signtop*y1);
}
}
/* level 3 */
if (MDEPTH > 2)
{
glLineWidth(1);
l = 2.0/((double)(mr2*MRATIO));
for (i=0; i<mr2; i++)
for (j=mr2/2; j<mr2; j++)
if ( (((i%MRATIO!=MRATIO/2))||(j%MRATIO!=MRATIO/2)) && (((i/MRATIO!=MRATIO/2))||(j/MRATIO!=MRATIO/2)) )
{
x = -1.0 - 0.5*l + 2.0*((double)i + 0.5)/((double)mr2);
y = -1.0 - 0.5*l + 2.0*((double)j + 0.5)/((double)mr2);
y1 = y+l;
if (y < 0.0) y = 0.0;
if (y1 < 0.0) y1 = 0.0;
draw_rectangle(x, signtop*y, x+l, signtop*y1);
}
}
break;
}
case (D_CIRCLES):
{
glLineWidth(2);
for (i = 0; i < ncircles; i++)
2021-11-12 16:22:24 +01:00
if ((circles[i].active)&&(circletop[i] == top))
2021-08-15 11:49:37 +02:00
{
glBegin(GL_LINE_STRIP);
for (k=0; k<=NSEG; k++)
{
phi = (double)k*DPI/(double)NSEG;
2021-11-12 16:22:24 +01:00
x = circles[i].xc + circles[i].radius*cos(phi);
y = circles[i].yc + circles[i].radius*sin(phi);
2021-08-15 11:49:37 +02:00
if ((top)&&(circletop[i])&&(y < 0.0)) y = 0.0;
if ((!top)&&(!circletop[i])&&(y > 0.0)) y = 0.0;
xy_to_pos(x, y, pos);
glVertex2d(pos[0], pos[1]);
}
glEnd ();
}
break;
}
2021-11-13 23:06:17 +01:00
case (D_POLYGONS):
{
glLineWidth(BOUNDARY_WIDTH);
for (i = 0; i < ncircles; i++)
if ((polygons[i].active)&&(circletop[i] == top))
{
if ((top)&&(circletop[i])) draw_tpolygon(polygons[i]);
else if ((!top)&&(!circletop[i])) draw_tpolygon(polygons[i]);
}
break;
}
2022-03-13 15:29:50 +01:00
case (D_FRESNEL):
{
glLineWidth(BOUNDARY_WIDTH);
glBegin(GL_LINE_LOOP);
for (i=0; i<npolyline; i++) tvertex_lineto(polyline[i]);
glEnd();
break;
}
case (D_CIRCLE_SEGMENT):
{
glLineWidth(BOUNDARY_WIDTH);
glBegin(GL_LINE_LOOP);
for (i=0; i<NSEG; i++)
{
y = -0.9*LAMBDA + (double)i*1.8*LAMBDA/(double)NSEG;
if (LAMBDA > 0.0) x = sqrt(LAMBDA*LAMBDA - y*y) - LAMBDA + MU;
else x = -sqrt(LAMBDA*LAMBDA - y*y) - LAMBDA - MU;
xy_to_pos(x, y, pos);
glVertex2d(pos[0], pos[1]);
}
y = 0.9*LAMBDA;
if (LAMBDA > 0.0) x = sqrt(LAMBDA*LAMBDA - y*y) - LAMBDA + MU;
else x = -sqrt(LAMBDA*LAMBDA - y*y) - LAMBDA - MU;
xy_to_pos(x, y, pos);
glVertex2d(pos[0], pos[1]);
glEnd();
break;
}
2023-12-26 23:01:20 +01:00
case (D_TWO_LENSES_WALL):
{
width = 0.2;
a = 1.9;
b = 1.9 - 2.0*LAMBDA + 2.0*width;
if (first)
{
arcangle = acos(1.0 - width/LAMBDA);
first = 0;
}
draw_circle_arc(a, 0.0, LAMBDA, PI-arcangle, 2.0*arcangle, NSEG);
draw_circle_arc(b, 0.0, LAMBDA, -arcangle, 2.0*arcangle, NSEG);
draw_circle_arc(-a, 0.0, LAMBDA, -arcangle, 2.0*arcangle, NSEG);
draw_circle_arc(-b, 0.0, LAMBDA, PI-arcangle, 2.0*arcangle, NSEG);
width = 0.05;
draw_rectangle(-width, MU, width, YMAX + 1.0);
draw_rectangle(-width, YMIN-1.0, width, -MUB);
break;
}
case (D_TWO_LENSES_OBSTACLE):
{
width = 0.2;
a = 1.9;
b = 1.9 - 2.0*LAMBDA + 2.0*width;
if (first)
{
arcangle = acos(1.0 - width/LAMBDA);
first = 0;
}
draw_circle_arc(a, 0.0, LAMBDA, PI-arcangle, 2.0*arcangle, NSEG);
draw_circle_arc(b, 0.0, LAMBDA, -arcangle, 2.0*arcangle, NSEG);
draw_circle_arc(-a, 0.0, LAMBDA, -arcangle, 2.0*arcangle, NSEG);
draw_circle_arc(-b, 0.0, LAMBDA, PI-arcangle, 2.0*arcangle, NSEG);
width = 0.05;
draw_rectangle(-width, -MUB, width, MU);
break;
}
2021-08-15 11:49:37 +02:00
case (D_MANDELBROT):
{
/* Do nothing */
break;
}
case (D_MANDELBROT_CIRCLE):
{
/* Do nothing */
break;
}
case (D_JULIA):
{
/* Do nothing */
break;
}
2023-07-08 23:28:23 +02:00
case (D_NOTHING):
{
/* Do nothing */
break;
}
default:
2021-08-15 11:49:37 +02:00
{
printf("Function draw_billiard not defined for this billiard \n");
}
}
2021-12-28 15:42:56 +01:00
glDisable(GL_SCISSOR_TEST);
2021-08-15 11:49:37 +02:00
}
2023-12-26 23:01:20 +01:00
void draw_billiard_comp(int fade, double fade_value) /* draws the billiard boundary */
2021-08-15 11:49:37 +02:00
{
2023-12-26 23:01:20 +01:00
draw_billiard_half(B_DOMAIN, CIRCLE_PATTERN, 1, fade, fade_value);
draw_billiard_half(B_DOMAIN_B, CIRCLE_PATTERN_B, 0, fade, fade_value);
2021-08-15 11:49:37 +02:00
}
void int_planar_wave_comp(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 */
/* beta version, works for vertical planar wave only so far */
{
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_in[i][j] = xy_in_billiard_comp(xy[0],xy[1]);
if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.0005)*cos(-sqrt(dist2)/0.01);
else phi[i][j] = 0.0;
psi[i][j] = 0.0;
}
}
void init_wave_flat_comp( double *phi[NX], double *psi[NX], short int * xy_in[NX])
/* initialise flat field - 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);
xy_in[i][j] = xy_in_billiard_comp(xy[0],xy[1]);
phi[i][j] = 0.0;
psi[i][j] = 0.0;
}
}
2023-07-08 23:28:23 +02:00
void add_circular_wave_comp(double factor, double x, double y, double *phi[NX], double *psi[NX], short int * xy_in[NX], int half)
/* add drop at (x,y) to the field with given prefactor */
{
int i, j;
double xy[2], dist2;
for (i=0; i<NX; i++)
{
if (half == 1) for (j=NY/2; 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);
}
else for (j=0; j<NY/2; 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);
}
}
}
2022-03-13 15:29:50 +01:00
void draw_wave_comp(double *phi[NX], double *psi[NX], short int *xy_in[NX], double scale, int time, int plot)
2021-08-15 11:49:37 +02:00
/* draw the field */
{
int i, j, iplus, iminus, jplus, jminus;
double rgb[3], xy[2], x1, y1, x2, y2, velocity, energy, gradientx2, gradienty2, pos[2];
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] != 2))||(xy_in[i][j] == 1))
{
2022-03-13 15:29:50 +01:00
switch (plot) {
2021-12-28 15:42:56 +01:00
case (P_AMPLITUDE):
{
color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb);
break;
}
case (P_ENERGY):
{
energy = compute_energy(phi, psi, xy_in, i, j);
if (COLOR_PALETTE >= 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_SCALE*log(total_energy[i][j]/(double)(time+1)), scale, time, rgb);
// break;
// }
2021-08-15 11:49:37 +02:00
}
2021-12-28 15:42:56 +01:00
// if (PLOT == P_AMPLITUDE)
// color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb);
// else if (PLOT == P_ENERGY)
// {
// energy = compute_energy(phi, psi, xy_in, i, j);
// if (COLOR_PALETTE >= COL_TURBO) color_scheme_asym(COLOR_SCHEME, energy, scale, time, rgb);
// else color_scheme(COLOR_SCHEME, energy, scale, time, rgb);
// }
// else if (PLOT == 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);
// }
2021-08-15 11:49:37 +02:00
glColor3f(rgb[0], rgb[1], rgb[2]);
glVertex2i(i, j);
glVertex2i(i+1, j);
glVertex2i(i+1, j+1);
glVertex2i(i, j+1);
}
}
glEnd ();
/* draw horizontal mid line */
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
xy_to_pos(XMIN, 0.5*(YMIN+YMAX), pos);
glVertex2d(pos[0], pos[1]);
xy_to_pos(XMAX, 0.5*(YMIN+YMAX), pos);
glVertex2d(pos[0], pos[1]);
glEnd();
}
2023-07-08 23:28:23 +02:00
void draw_wave_comp_highres_palette(int size, double *phi[NX], double *psi[NX], double *total_energy[NX], short int *xy_in[NX], double scale, int time, int plot, int palette, int fade, double fade_value)
/* draw the field */
{
int i, j, iplus, iminus, jplus, jminus, k;
double rgb[3], xy[2], x1, y1, x2, y2, velocity, energy, gradientx2, gradienty2, pos[2];
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] != 2))||(xy_in[i][j] == 1))
{
switch (plot) {
case (P_AMPLITUDE):
{
color_scheme_palette(COLOR_SCHEME, palette, phi[i][j], scale, time, rgb);
break;
}
case (P_ENERGY):
{
energy = compute_energy(phi, psi, xy_in, i, j);
if (COLOR_PALETTE >= 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(COLOR_SCHEME, LOG_SHIFT + LOG_SCALE*log(energy), scale, time, rgb);
break;
}
2023-12-26 23:01:20 +01:00
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;
}
2023-07-08 23:28:23 +02:00
}
// if (PLOT == P_AMPLITUDE)
// color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb);
// else if (PLOT == P_ENERGY)
// {
// energy = compute_energy(phi, psi, xy_in, i, j);
// if (COLOR_PALETTE >= COL_TURBO) color_scheme_asym(COLOR_SCHEME, energy, scale, time, rgb);
// else color_scheme(COLOR_SCHEME, energy, scale, time, rgb);
// }
// else if (PLOT == 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);
// }
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 ();
/* draw horizontal mid line */
2023-12-26 23:01:20 +01:00
if (fade) glColor3f(fade_value, fade_value, fade_value);
else glColor3f(1.0, 1.0, 1.0);
2023-07-08 23:28:23 +02:00
glBegin(GL_LINE_STRIP);
xy_to_pos(XMIN, 0.5*(YMIN+YMAX), pos);
glVertex2d(pos[0], pos[1]);
xy_to_pos(XMAX, 0.5*(YMIN+YMAX), pos);
glVertex2d(pos[0], pos[1]);
glEnd();
}
2021-08-15 11:49:37 +02:00
void compute_energy_tblr(double *phi[NX], double *psi[NX], short int *xy_in[NX], double energies[6])
/* compute total energy in top/bottom left/right boxes */
{
int i, j, ij[2];
2021-12-28 15:42:56 +01:00
double energy = 0.0, rescale, pos, xleft = XMAX, xright = XMIN, emax = 1.2, xc, r;
double *energy_ij[NX];
2021-08-15 11:49:37 +02:00
static short int first = 1;
static int ileft, iright, jmid = NY/2;
2021-09-01 17:03:02 +02:00
static double sqremax;
2021-12-28 15:42:56 +01:00
for (i=0; i<NX; i++) energy_ij[i] = (double *)malloc(NY*sizeof(double));
2021-08-15 11:49:37 +02:00
if (first) /* compute box limits */
{
/* find leftmost and rightmost circle */
for (i=0; i<ncircles; i++)
2021-12-28 15:42:56 +01:00
{
if ((circles[i].active)&&(circles[i].xc - circles[i].radius < xleft)) xleft = circles[i].xc - circles[i].radius;
if ((polygons[i].active)&&(polygons[i].xc - polygons[i].radius < xleft)) xleft = polygons[i].xc - polygons[i].radius;
2021-11-12 16:22:24 +01:00
if ((circles[i].active)&&(circles[i].xc + circles[i].radius > xright)) xright = circles[i].xc + circles[i].radius;
2021-12-28 15:42:56 +01:00
if ((polygons[i].active)&&(polygons[i].xc + polygons[i].radius > xright)) xright = polygons[i].xc + polygons[i].radius;
}
// for (i=0; i<ncircles; i++)
// if ((circles[i].active)&&(circles[i].xc - circles[i].radius < xleft)) xleft = circles[i].xc - circles[i].radius;
// for (i=0; i<ncircles; i++)
// if ((circles[i].active)&&(circles[i].xc + circles[i].radius > xright)) xright = circles[i].xc + circles[i].radius;
2021-08-15 11:49:37 +02:00
xy_to_ij(xleft, 0.0, ij);
ileft = ij[0];
xy_to_ij(xright, 0.0, ij);
iright = ij[0];
first = 0;
printf("xleft = %.3lg, xright = %.3lg", xleft, xright);
}
2021-09-01 17:03:02 +02:00
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
energy_ij[i][j] = compute_energy(phi, psi, xy_in, i, j);
/* prevent local energy from growing too large */
if (FLOOR)
{
for (i=10; i<NX; i++)
for (j=0; j<NY; j++)
if ((xy_in[i][j])&&(energy_ij[i][j] > emax))
{
rescale = sqrt(emax/energy_ij[i][j]);
if (j%100 == 0) printf("Rescaling at (%i,%i) by %.5lg\n", i, j, rescale);
phi[i][j] = phi[i][j]*rescale;
psi[i][j] = psi[i][j]*rescale;
}
else if (energy_ij[i][j] > 0.1*emax)
{
rescale = sqrt(0.1*emax/energy_ij[i][j]);
if (j%10 == 0) printf("Rescaling at (%i,%i) by %.5lg\n", i, j, rescale);
phi[i][j] = phi[i][j]*rescale;
psi[i][j] = psi[i][j]*rescale;
}
}
2021-08-15 11:49:37 +02:00
/* top left box */
for (i=0; i<ileft; i++)
for (j=jmid; j<NY; j++)
2021-09-01 17:03:02 +02:00
energy += energy_ij[i][j];
2021-08-15 11:49:37 +02:00
energies[0] = energy;
/* top middle box */
energy = 0.0;
for (i=ileft; i<iright; i++)
for (j=jmid; j<NY; j++)
2021-09-01 17:03:02 +02:00
energy += energy_ij[i][j];
2021-08-15 11:49:37 +02:00
energies[1] = energy;
/* top right box */
energy = 0.0;
for (i=iright; i<NX; i++)
for (j=jmid; j<NY; j++)
2021-09-01 17:03:02 +02:00
energy += energy_ij[i][j];
2021-08-15 11:49:37 +02:00
energies[2] = energy;
/* bottom left box */
energy = 0.0;
for (i=0; i<ileft; i++)
for (j=0; j<jmid; j++)
2021-09-01 17:03:02 +02:00
energy += energy_ij[i][j];
2021-08-15 11:49:37 +02:00
energies[3] = energy;
/* bottom middle box */
energy = 0.0;
for (i=ileft; i<iright; i++)
for (j=0; j<jmid; j++)
2021-09-01 17:03:02 +02:00
energy += energy_ij[i][j];
2021-08-15 11:49:37 +02:00
energies[4] = energy;
/* bottom right box */
energy = 0.0;
for (i=iright; i<NX; i++)
for (j=0; j<jmid; j++)
2021-09-01 17:03:02 +02:00
energy += energy_ij[i][j];
2021-08-15 11:49:37 +02:00
energies[5] = energy;
2021-09-01 17:03:02 +02:00
// printf("Energies: %.5lg, %.5lg, %.5lg\n %.5lg, %.5lg, %.5lg\n", energies[0], energies[1], energies[2], energies[3], energies[4], energies[5]);
2021-12-28 15:42:56 +01:00
for (i=0; i<NX; i++) free(energy_ij[i]);
2021-08-15 11:49:37 +02:00
}
void print_energies(double energies[6], double top_energy, double bottom_energy)
{
char message[50];
2021-12-28 15:42:56 +01:00
double ytop, ybot, pos[2], centerx = -0.075, boxxright = XMAX - 0.17, textxright = XMAX - 0.28, boxwidth = 0.1,
2022-02-05 18:44:39 +01:00
boxheight = 0.05, leftboxshift = 0.185, centerboxshift = 0.085, text_color;
2021-12-28 15:42:56 +01:00
2022-02-05 18:44:39 +01:00
if (BLACK_TEXT) text_color = 0.0;
else text_color = 1.0;
2021-12-28 15:42:56 +01:00
/* adapt sizes of text areas to high resolution */
if (WINWIDTH > 1280)
{
boxheight = 0.035;
// centerx -= 0.2;
boxwidth = 0.08;
leftboxshift = 0.16;
centerboxshift = 0.06;
}
2021-08-15 11:49:37 +02:00
ytop = YMAX - 0.1;
2021-09-01 17:03:02 +02:00
ybot = YMIN + 0.05;
2021-11-13 23:06:17 +01:00
if (DRAW_COLOR_SCHEME)
{
boxxright -= 0.35;
textxright -= 0.35;
}
2021-08-15 11:49:37 +02:00
2021-12-28 15:42:56 +01:00
erase_area(XMIN + leftboxshift, ytop + 0.025, boxwidth, boxheight);
2021-08-15 11:49:37 +02:00
2022-02-05 18:44:39 +01:00
glColor3f(text_color, text_color, text_color);
2021-08-15 11:49:37 +02:00
sprintf(message, "%.3f", energies[0]/top_energy);
xy_to_pos(XMIN + 0.1, ytop, pos);
write_text(pos[0], pos[1], message);
2021-12-28 15:42:56 +01:00
erase_area(centerx + centerboxshift, ytop + 0.025, boxwidth, boxheight);
2021-08-15 11:49:37 +02:00
2022-02-05 18:44:39 +01:00
glColor3f(text_color, text_color, text_color);
2021-08-15 11:49:37 +02:00
sprintf(message, "%.3f", energies[1]/top_energy);
xy_to_pos(centerx, ytop, pos);
write_text(pos[0], pos[1], message);
2021-12-28 15:42:56 +01:00
erase_area(boxxright, ytop + 0.025, boxwidth + 0.05, boxheight);
2021-11-13 23:06:17 +01:00
2022-02-05 18:44:39 +01:00
glColor3f(text_color, text_color, text_color);
2021-08-15 11:49:37 +02:00
sprintf(message, "%.5f", energies[2]/top_energy);
2021-11-13 23:06:17 +01:00
xy_to_pos(textxright, ytop, pos);
2021-08-15 11:49:37 +02:00
write_text(pos[0], pos[1], message);
2021-12-28 15:42:56 +01:00
erase_area(XMIN + leftboxshift, ybot + 0.025, boxwidth, boxheight);
2021-08-15 11:49:37 +02:00
2022-02-05 18:44:39 +01:00
glColor3f(text_color, text_color, text_color);
2021-08-15 11:49:37 +02:00
sprintf(message, "%.3f", energies[3]/bottom_energy);
xy_to_pos(XMIN + 0.1, ybot, pos);
write_text(pos[0], pos[1], message);
2021-12-28 15:42:56 +01:00
erase_area(centerx + centerboxshift, ybot + 0.025, boxwidth, boxheight);
2021-08-15 11:49:37 +02:00
2022-02-05 18:44:39 +01:00
glColor3f(text_color, text_color, text_color);
2021-08-15 11:49:37 +02:00
sprintf(message, "%.3f", energies[4]/bottom_energy);
xy_to_pos(centerx, ybot, pos);
write_text(pos[0], pos[1], message);
2021-12-28 15:42:56 +01:00
erase_area(boxxright, ybot + 0.025, boxwidth + 0.05, boxheight);
2021-11-13 23:06:17 +01:00
2022-02-05 18:44:39 +01:00
glColor3f(text_color, text_color, text_color);
2021-08-15 11:49:37 +02:00
sprintf(message, "%.5f", energies[5]/bottom_energy);
2021-11-13 23:06:17 +01:00
xy_to_pos(textxright, ybot, pos);
2021-08-15 11:49:37 +02:00
write_text(pos[0], pos[1], message);
}
2023-12-26 23:01:20 +01:00
void init_ior_2d_comp(short int *xy_in[NX], double *tcc_table[NX], double ior_angle)
/* compute variable index of refraction */
/* should be at some point merged with 3D version in suv_wave_3d.c */
{
int i, j, k, n, inlens, ncircles;
double courant2 = COURANT*COURANT, courantb2 = COURANTB*COURANTB, lambda1, mu1;
double u, v, u1, x, y, xy[2], norm2, speed, r2, c, salpha, h, ll, ca, sa, x1, y1, dx, dy, sum, sigma, x0, y0, rgb[3];
double xc[NGRIDX*NGRIDY], yc[NGRIDX*NGRIDY], height[NGRIDX*NGRIDY];
static double xc_stat[NGRIDX*NGRIDY], yc_stat[NGRIDX*NGRIDY], sigma_stat;
static int first = 1;
t_circle circles[NMAXCIRCLES];
rgb[0] = 1.0;
rgb[1] = 1.0;
rgb[2] = 1.0;
if (VARIABLE_IOR)
{
switch (IOR) {
case (IOR_LENS_WALL):
{
printf("Initializing IOR_LENS_WALL\n");
for (i=0; i<NX; i++){
for (j=0; j<NY/2; j++){
ij_to_xy(i, j, xy);
x = xy[0];
y = xy[1];
if ((vabs(x) < 0.05)&&(vabs(y) > MUB)) tcc_table[i][j] = 0.0;
else
{
if (xy_in[i][j] != 0) tcc_table[i][j] = courant2;
else tcc_table[i][j] = courantb2;
}
}
for (j=NY/2; j<NY; j++){
ij_to_xy(i, j, xy);
x = xy[0];
y = xy[1];
if ((vabs(x) < 0.05)&&(vabs(y) > MU)) tcc_table[i][j] = 0.0;
else
{
if (xy_in[i][j] != 0) tcc_table[i][j] = courant2;
else tcc_table[i][j] = courantb2;
}
}
}
break;
}
case (IOR_LENS_OBSTACLE):
{
printf("Initializing IOR_LENS_OBSTACLE\n");
for (i=0; i<NX; i++){
for (j=0; j<NY/2; j++){
ij_to_xy(i, j, xy);
x = xy[0];
y = xy[1];
if ((vabs(x) < 0.05)&&(vabs(y) < MUB)) tcc_table[i][j] = 0.0;
else
{
if (xy_in[i][j] != 0) tcc_table[i][j] = courant2;
else tcc_table[i][j] = courantb2;
}
}
for (j=NY/2; j<NY; j++){
ij_to_xy(i, j, xy);
x = xy[0];
y = xy[1];
if ((vabs(x) < 0.05)&&(vabs(y) < MU)) tcc_table[i][j] = 0.0;
else
{
if (xy_in[i][j] != 0) tcc_table[i][j] = courant2;
else tcc_table[i][j] = courantb2;
}
}
}
break;
}
default:
{
for (i=0; i<NX; i++){
for (j=0; j<NY; j++){
tcc_table[i][j] = COURANT;
}
}
}
}
}
else
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++){
for (j=0; j<NY; j++){
if (xy_in[i*NY+j] != 0)
{
tcc_table[i][j] = courant2;
}
else if (TWOSPEEDS)
{
tcc_table[i][j] = courantb2;
}
}
}
}
}