Add files via upload
This commit is contained in:
committed by
GitHub
parent
d227439e84
commit
b1d8db471a
@@ -50,6 +50,8 @@
|
|||||||
|
|
||||||
#define CIRCLE_PATTERN 0 /* pattern of circles */
|
#define CIRCLE_PATTERN 0 /* pattern of circles */
|
||||||
|
|
||||||
|
#define ABSORBING_CIRCLES 0 /* set to 1 for circular scatterers to be absorbing */
|
||||||
|
|
||||||
#define NMAXCIRCLES 1000 /* total number of circles (must be at least NCX*NCY for square grid) */
|
#define NMAXCIRCLES 1000 /* total number of circles (must be at least NCX*NCY for square grid) */
|
||||||
// #define NCX 10 /* number of circles in x direction */
|
// #define NCX 10 /* number of circles in x direction */
|
||||||
// #define NCY 15 /* number of circles in y direction */
|
// #define NCY 15 /* number of circles in y direction */
|
||||||
@@ -126,10 +128,8 @@
|
|||||||
/* animation part */
|
/* animation part */
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
void init_boundary_config(smin, smax, anglemin, anglemax, configs)
|
void init_boundary_config(double smin, double smax, double anglemin, double anglemax, double *configs[NPARTMAX])
|
||||||
/* initialize configuration: drop on the boundary, beta version */
|
/* initialize configuration: drop on the boundary, beta version */
|
||||||
double smin, smax, anglemin, anglemax;
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double ds, da, s, angle, alpha, pos[2], conf[2];
|
double ds, da, s, angle, alpha, pos[2], conf[2];
|
||||||
@@ -151,9 +151,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_drop_config(x0, y0, angle1, angle2, configs) /* initialize configuration: drop at (x0,y0) */
|
void init_drop_config(double x0, double y0, double angle1, double angle2, double *configs[NPARTMAX])
|
||||||
double x0, y0, angle1, angle2;
|
/* initialize configuration: drop at (x0,y0) */
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double dalpha, alpha, pos[2];
|
double dalpha, alpha, pos[2];
|
||||||
@@ -172,9 +171,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int resample(color, configs) /* add particles where the front is stretched too thin */
|
int resample(int color[NPARTMAX], double *configs[NPARTMAX])
|
||||||
int color[NPARTMAX];
|
/* add particles where the front is stretched too thin */
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int len, i, j, k, iplus, newnparticles=nparticles, *newcolor;
|
int len, i, j, k, iplus, newnparticles=nparticles, *newcolor;
|
||||||
double dx, dy, pos[2], s1, s2, s, x, y, x1, y1, theta, alpha, beta, length2;
|
double dx, dy, pos[2], s1, s2, s, x, y, x1, y1, theta, alpha, beta, length2;
|
||||||
@@ -261,10 +259,9 @@ double *configs[NPARTMAX];
|
|||||||
else return(1);
|
else return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_config(color, configs)
|
|
||||||
/* draw the wave front by ordering colors */
|
void draw_config(int color[NPARTMAX], double *configs[NPARTMAX])
|
||||||
int color[NPARTMAX];
|
/* draw the particles */
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double x1, y1, x2, y2, cosphi, sinphi, rgb[3], dist, dmax;
|
double x1, y1, x2, y2, cosphi, sinphi, rgb[3], dist, dmax;
|
||||||
@@ -315,10 +312,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw_ordered_config(color, configs)
|
void draw_ordered_config(int color[NPARTMAX], double *configs[NPARTMAX])
|
||||||
/* draw the wave front, one color after the other */
|
/* draw the wave front, one color after the other */
|
||||||
int color[NPARTMAX];
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i, col;
|
int i, col;
|
||||||
double x1, y1, x2, y2, cosphi, sinphi, rgb[3], dist, dmax;
|
double x1, y1, x2, y2, cosphi, sinphi, rgb[3], dist, dmax;
|
||||||
@@ -376,10 +371,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void graph_movie(time, color, configs)
|
void graph_movie(int time, int color[NPARTMAX], double *configs[NPARTMAX])
|
||||||
/* compute next movie frame */
|
/* compute next movie frame */
|
||||||
int time, color[NPARTMAX];
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@@ -407,10 +400,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void graph_no_movie(time, color, configs)
|
void graph_no_movie(int time, int color[NPARTMAX], double *configs[NPARTMAX])
|
||||||
/* plot next image without making a movie */
|
/* plot next image without making a movie */
|
||||||
int time, color[NPARTMAX];
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ double circlex[NMAXCIRCLES], circley[NMAXCIRCLES], circlerad[NMAXCIRCLES];
|
|||||||
short int circleactive[NMAXCIRCLES]; /* tells which circular scatters are active */
|
short int circleactive[NMAXCIRCLES]; /* tells which circular scatters are active */
|
||||||
int ncircles = NMAXCIRCLES; /* actual number of circles, can be decreased e.g. for random patterns */
|
int ncircles = NMAXCIRCLES; /* actual number of circles, can be decreased e.g. for random patterns */
|
||||||
|
|
||||||
|
double x_shooter = -0.2, y_shooter = -0.6, x_target = 0.4, y_target = 0.7;
|
||||||
|
/* shooter and target positions for "laser in room of mirrors" simulations, with default values for square domain */
|
||||||
|
|
||||||
/* some basic math */
|
/* some basic math */
|
||||||
|
|
||||||
@@ -28,8 +30,12 @@ int ncircles = NMAXCIRCLES; /* actual number of circles, can be decre
|
|||||||
|
|
||||||
#define D_CIRCLES 20 /* several circles */
|
#define D_CIRCLES 20 /* several circles */
|
||||||
#define D_CIRCLES_IN_RECT 21 /* several circles inside a rectangle */
|
#define D_CIRCLES_IN_RECT 21 /* several circles inside a rectangle */
|
||||||
|
#define D_CIRCLES_IN_GENUSN 22 /* several circles in polygon with identified opposite sides */
|
||||||
|
|
||||||
#define C_FOUR_CIRCLES 0 /* four circles almost touching each other */
|
#define C_FOUR_CIRCLES 0 /* four circles almost touching each other */
|
||||||
#define C_SQUARE 1 /* square grid of circles */
|
#define C_SQUARE 1 /* square grid of circles */
|
||||||
#define C_HEX 2 /* hexagonal/triangular grid of circles */
|
#define C_HEX 2 /* hexagonal/triangular grid of circles */
|
||||||
#define C_LASER 3 /* laser fight in a room of mirrors */
|
#define C_GOLDEN_MEAN 3 /* golden mean grid */
|
||||||
|
|
||||||
|
#define C_LASER 11 /* laser fight in a room of mirrors */
|
||||||
|
#define C_LASER_GENUSN 12 /* laser fight in a translation surface */
|
||||||
@@ -42,6 +42,12 @@
|
|||||||
#define C_CLOAK 5 /* invisibility cloak */
|
#define C_CLOAK 5 /* invisibility cloak */
|
||||||
#define C_CLOAK_A 6 /* first optimized invisibility cloak */
|
#define C_CLOAK_A 6 /* first optimized invisibility cloak */
|
||||||
|
|
||||||
|
#define C_GOLDEN_MEAN 10 /* pattern based on vertical shifts by golden mean */
|
||||||
|
#define C_GOLDEN_SPIRAL 11 /* spiral pattern based on golden mean */
|
||||||
|
#define C_SQUARE_HEX 12 /* alternating between square and hexagonal/triangular */
|
||||||
|
|
||||||
|
#define C_ONE 97 /* one single circle, as for Sinai */
|
||||||
|
#define C_TWO 98 /* two concentric circles of different type */
|
||||||
#define C_NOTHING 99 /* no circle at all, for comparisons */
|
#define C_NOTHING 99 /* no circle at all, for comparisons */
|
||||||
|
|
||||||
|
|
||||||
@@ -60,10 +66,12 @@
|
|||||||
#define BC_PERIODIC 1 /* periodic boundary conditions */
|
#define BC_PERIODIC 1 /* periodic boundary conditions */
|
||||||
#define BC_ABSORBING 2 /* absorbing boundary conditions (beta version) */
|
#define BC_ABSORBING 2 /* absorbing boundary conditions (beta version) */
|
||||||
#define BC_VPER_HABS 3 /* vertically periodic and horizontally absorbing boundary conditions */
|
#define BC_VPER_HABS 3 /* vertically periodic and horizontally absorbing boundary conditions */
|
||||||
|
#define BC_ABS_REFLECT 4 /* absorbing boundary conditions, except reflecting at y=0, for comparisons */
|
||||||
|
// #define BC_OSCILL_ABSORB 5 /* oscillating boundary condition on the left, absorbing on other walls */
|
||||||
|
|
||||||
/* For debugging purposes only */
|
/* For debugging purposes only */
|
||||||
#define FLOOR 0 /* set to 1 to limit wave amplitude to VMAX */
|
// #define FLOOR 0 /* set to 1 to limit wave amplitude to VMAX */
|
||||||
#define VMAX 10.0 /* max value of wave amplitude */
|
// #define VMAX 10.0 /* max value of wave amplitude */
|
||||||
|
|
||||||
/* Plot types */
|
/* Plot types */
|
||||||
|
|
||||||
|
|||||||
56
heat.c
56
heat.c
@@ -107,6 +107,7 @@
|
|||||||
#define NVID 50 /* number of iterations between images displayed on screen */
|
#define NVID 50 /* number of iterations between images displayed on screen */
|
||||||
// #define NVID 100 /* number of iterations between images displayed on screen */
|
// #define NVID 100 /* number of iterations between images displayed on screen */
|
||||||
#define NSEG 100 /* number of segments of boundary */
|
#define NSEG 100 /* number of segments of boundary */
|
||||||
|
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */
|
||||||
|
|
||||||
#define PAUSE 100 /* number of frames after which to pause */
|
#define PAUSE 100 /* number of frames after which to pause */
|
||||||
#define PSLEEP 1 /* sleep time during pause */
|
#define PSLEEP 1 /* sleep time during pause */
|
||||||
@@ -160,11 +161,9 @@ double intstep1; /* integration step used in absorbing boundary conditions */
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void init_gaussian(x, y, mean, amplitude, scalex, phi, xy_in)
|
void init_gaussian(double x, double y, double mean, double amplitude, double scalex,
|
||||||
|
double *phi[NX], short int * xy_in[NX])
|
||||||
/* initialise field with gaussian at position (x,y) */
|
/* initialise field with gaussian at position (x,y) */
|
||||||
double x, y, mean, amplitude, scalex, *phi[NX];
|
|
||||||
short int * xy_in[NX];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int i, j, in;
|
int i, j, in;
|
||||||
double xy[2], dist2, module, phase, scale2;
|
double xy[2], dist2, module, phase, scale2;
|
||||||
@@ -193,11 +192,8 @@ void init_gaussian(x, y, mean, amplitude, scalex, phi, xy_in)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_julia_set(phi, xy_in)
|
void init_julia_set(double *phi[NX], short int * xy_in[NX])
|
||||||
/* change Julia set boundary condition */
|
/* change Julia set boundary condition */
|
||||||
double *phi[NX];
|
|
||||||
short int * xy_in[NX];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int i, j, in;
|
int i, j, in;
|
||||||
double xy[2], dist2, module, phase, scale2;
|
double xy[2], dist2, module, phase, scale2;
|
||||||
@@ -220,9 +216,8 @@ void init_julia_set(phi, xy_in)
|
|||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
|
|
||||||
void compute_gradient(phi, nablax, nablay)
|
void compute_gradient(double *phi[NX], double *nablax[NX], double *nablay[NX])
|
||||||
/* compute the gradient of the field */
|
/* compute the gradient of the field */
|
||||||
double *phi[NX], *nablax[NX], *nablay[NX];
|
|
||||||
{
|
{
|
||||||
int i, j, iplus, iminus, jplus, jminus;
|
int i, j, iplus, iminus, jplus, jminus;
|
||||||
double dx;
|
double dx;
|
||||||
@@ -241,12 +236,9 @@ double *phi[NX], *nablax[NX], *nablay[NX];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_field_line(x, y, xy_in, nablax, nablay, delta, nsteps)
|
void draw_field_line(double x, double y, short int *xy_in[NX], double *nablax[NX],
|
||||||
// void draw_field_line(x, y, nablax, nablay, delta, nsteps)
|
double *nablay[NX], double delta, int nsteps)
|
||||||
/* draw a field line of the gradient, starting in (x,y) */
|
/* draw a field line of the gradient, starting in (x,y) */
|
||||||
double x, y, *nablax[NX], *nablay[NX], delta;
|
|
||||||
int nsteps;
|
|
||||||
short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
double x1, y1, x2, y2, pos[2], nabx, naby, norm2, norm;
|
double x1, y1, x2, y2, pos[2], nabx, naby, norm2, norm;
|
||||||
int i = 0, ij[2], cont = 1;
|
int i = 0, ij[2], cont = 1;
|
||||||
@@ -303,11 +295,8 @@ short int *xy_in[NX];
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_wave(phi, xy_in, scale, time)
|
void draw_wave(double *phi[NX], short int *xy_in[NX], double scale, int time)
|
||||||
/* draw the field */
|
/* draw the field */
|
||||||
double *phi[NX], scale;
|
|
||||||
short int *xy_in[NX];
|
|
||||||
int time;
|
|
||||||
{
|
{
|
||||||
int i, j, iplus, iminus, jplus, jminus, ij[2], counter = 0;
|
int i, j, iplus, iminus, jplus, jminus, ij[2], counter = 0;
|
||||||
static int first = 1;
|
static int first = 1;
|
||||||
@@ -413,9 +402,8 @@ int time;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void evolve_wave_half(phi_in, phi_out, xy_in)
|
void evolve_wave_half(double *phi_in[NX], double *phi_out[NX], short int *xy_in[NX])
|
||||||
/* time step of field evolution */
|
/* time step of field evolution */
|
||||||
double *phi_in[NX], *phi_out[NX]; short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
int i, j, iplus, iminus, jplus, jminus;
|
int i, j, iplus, iminus, jplus, jminus;
|
||||||
double delta1, delta2, x, y;
|
double delta1, delta2, x, y;
|
||||||
@@ -493,18 +481,16 @@ void evolve_wave_half(phi_in, phi_out, xy_in)
|
|||||||
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void evolve_wave(phi, phi_tmp, xy_in)
|
void evolve_wave(double *phi[NX], double *phi_tmp[NX], short int *xy_in[NX])
|
||||||
/* time step of field evolution */
|
/* time step of field evolution */
|
||||||
double *phi[NX], *phi_tmp[NX]; short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
evolve_wave_half(phi, phi_tmp, xy_in);
|
evolve_wave_half(phi, phi_tmp, xy_in);
|
||||||
evolve_wave_half(phi_tmp, phi, xy_in);
|
evolve_wave_half(phi_tmp, phi, xy_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void old_evolve_wave(phi, xy_in)
|
void old_evolve_wave(double *phi[NX], short int *xy_in[NX])
|
||||||
/* time step of field evolution */
|
/* time step of field evolution */
|
||||||
double *phi[NX]; short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
int i, j, iplus, iminus, jplus, jminus;
|
int i, j, iplus, iminus, jplus, jminus;
|
||||||
double delta1, delta2, x, y, *newphi[NX];
|
double delta1, delta2, x, y, *newphi[NX];
|
||||||
@@ -595,9 +581,8 @@ void old_evolve_wave(phi, xy_in)
|
|||||||
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
double compute_variance(phi, xy_in)
|
double compute_variance(double *phi[NX], short int * xy_in[NX])
|
||||||
/* compute the variance (total probability) of the field */
|
/* compute the variance (total probability) of the field */
|
||||||
double *phi[NX]; short int * xy_in[NX];
|
|
||||||
{
|
{
|
||||||
int i, j, n = 0;
|
int i, j, n = 0;
|
||||||
double variance = 0.0;
|
double variance = 0.0;
|
||||||
@@ -615,10 +600,8 @@ double *phi[NX]; short int * xy_in[NX];
|
|||||||
return(variance/(double)n);
|
return(variance/(double)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renormalise_field(phi, xy_in, variance)
|
void renormalise_field(double *phi[NX], short int * xy_in[NX], double variance)
|
||||||
/* renormalise variance of field */
|
/* renormalise variance of field */
|
||||||
double *phi[NX], variance;
|
|
||||||
short int * xy_in[NX];
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double stdv;
|
double stdv;
|
||||||
@@ -635,8 +618,7 @@ short int * xy_in[NX];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_level(level)
|
void print_level(int level)
|
||||||
int level;
|
|
||||||
{
|
{
|
||||||
double pos[2];
|
double pos[2];
|
||||||
char message[50];
|
char message[50];
|
||||||
@@ -660,10 +642,7 @@ void print_Julia_parameters()
|
|||||||
write_text(pos[0], pos[1], message);
|
write_text(pos[0], pos[1], message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_Julia_parameters(time, phi, xy_in)
|
void set_Julia_parameters(int time, double *phi[NX], short int *xy_in[NX])
|
||||||
int time;
|
|
||||||
double *phi[NX];
|
|
||||||
short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
double jangle, cosj, sinj, radius = 0.15;
|
double jangle, cosj, sinj, radius = 0.15;
|
||||||
|
|
||||||
@@ -680,10 +659,7 @@ short int *xy_in[NX];
|
|||||||
printf("Julia set parameters : i = %i, angle = %.5lg, cx = %.5lg, cy = %.5lg \n", time, jangle, julia_x, julia_y);
|
printf("Julia set parameters : i = %i, angle = %.5lg, cx = %.5lg, cy = %.5lg \n", time, jangle, julia_x, julia_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_Julia_parameters_cardioid(time, phi, xy_in)
|
void set_Julia_parameters_cardioid(int time, double *phi[NX], short int *xy_in[NX])
|
||||||
int time;
|
|
||||||
double *phi[NX];
|
|
||||||
short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
double jangle, cosj, sinj, yshift;
|
double jangle, cosj, sinj, yshift;
|
||||||
|
|
||||||
|
|||||||
@@ -42,32 +42,19 @@
|
|||||||
|
|
||||||
#define SCALING_FACTOR 1.0 /* scaling factor of drawing, needed for flower billiards, otherwise set to 1.0 */
|
#define SCALING_FACTOR 1.0 /* scaling factor of drawing, needed for flower billiards, otherwise set to 1.0 */
|
||||||
|
|
||||||
// #define XMIN -1.8
|
|
||||||
// #define XMAX 1.8 /* x interval */
|
|
||||||
// #define YMIN -0.91
|
|
||||||
// #define YMAX 1.115 /* y interval for 9/16 aspect ratio */
|
|
||||||
|
|
||||||
/* Choice of the billiard table, see global_particles.c */
|
/* Choice of the billiard table, see global_particles.c */
|
||||||
|
|
||||||
#define B_DOMAIN 14 /* choice of domain shape */
|
#define B_DOMAIN 20 /* choice of domain shape */
|
||||||
|
|
||||||
#define CIRCLE_PATTERN 0 /* pattern of circles */
|
#define CIRCLE_PATTERN 2 /* pattern of circles */
|
||||||
|
|
||||||
|
#define ABSORBING_CIRCLES 0 /* set to 1 for circular scatterers to be absorbing */
|
||||||
|
|
||||||
#define NMAXCIRCLES 1000 /* total number of circles (must be at least NCX*NCY for square grid) */
|
#define NMAXCIRCLES 1000 /* total number of circles (must be at least NCX*NCY for square grid) */
|
||||||
// #define NCX 10 /* number of circles in x direction */
|
|
||||||
// #define NCY 15 /* number of circles in y direction */
|
|
||||||
#define NCX 15 /* number of circles in x direction */
|
#define NCX 15 /* number of circles in x direction */
|
||||||
#define NCY 20 /* number of circles in y direction */
|
#define NCY 20 /* number of circles in y direction */
|
||||||
|
|
||||||
#define LAMBDA 0.75 /* parameter controlling shape of billiard */
|
#define LAMBDA 0.75 /* parameter controlling shape of billiard */
|
||||||
// #define LAMBDA -3.346065215 /* sin(60°)/sin(15°) for Reuleaux-type triangle with 90° angles */
|
|
||||||
// #define LAMBDA 3.0 /* parameter controlling shape of billiard */
|
|
||||||
// #define LAMBDA 0.6 /* parameter controlling shape of billiard */
|
|
||||||
// #define LAMBDA 0.4175295 /* sin(20°)/sin(55°) for 9-star shape with 30° angles */
|
|
||||||
// #define LAMBDA -1.949855824 /* 7-sided Reuleaux triangle */
|
|
||||||
// #define LAMBDA 3.75738973 /* sin(36°)/sin(9°) for 5-star shape with 90° angles */
|
|
||||||
// #define LAMBDA -1.73205080756888 /* -sqrt(3) for Reuleaux triangle */
|
|
||||||
// #define LAMBDA 1.73205080756888 /* sqrt(3) for triangle tiling plane */
|
|
||||||
#define MU 0.035 /* second parameter controlling shape of billiard */
|
#define MU 0.035 /* second parameter controlling shape of billiard */
|
||||||
#define FOCI 1 /* set to 1 to draw focal points of ellipse */
|
#define FOCI 1 /* set to 1 to draw focal points of ellipse */
|
||||||
#define NPOLY 8 /* number of sides of polygon */
|
#define NPOLY 8 /* number of sides of polygon */
|
||||||
@@ -81,16 +68,15 @@
|
|||||||
|
|
||||||
/* Simulation parameters */
|
/* Simulation parameters */
|
||||||
|
|
||||||
#define NPART 5000 /* number of particles */
|
#define NPART 30000 /* number of particles */
|
||||||
#define NPARTMAX 100000 /* maximal number of particles after resampling */
|
#define NPARTMAX 100000 /* maximal number of particles after resampling */
|
||||||
#define LMAX 0.01 /* minimal segment length triggering resampling */
|
#define LMAX 0.01 /* minimal segment length triggering resampling */
|
||||||
#define DMIN 0.02 /* minimal distance to boundary for triggering resampling */
|
#define DMIN 0.02 /* minimal distance to boundary for triggering resampling */
|
||||||
#define CYCLE 1 /* set to 1 for closed curve (start in all directions) */
|
#define CYCLE 1 /* set to 1 for closed curve (start in all directions) */
|
||||||
|
#define SHOWTRAILS 0 /* set to 1 to keep trails of the particles */
|
||||||
|
|
||||||
#define NSTEPS 3000 /* number of frames of movie */
|
#define NSTEPS 3000 /* number of frames of movie */
|
||||||
#define TIME 1000 /* time between movie frames, for fluidity of real-time simulation */
|
#define TIME 1000 /* time between movie frames, for fluidity of real-time simulation */
|
||||||
// #define DPHI 0.000002 /* integration step */
|
|
||||||
// #define DPHI 0.00002 /* integration step */
|
|
||||||
#define DPHI 0.000005 /* integration step */
|
#define DPHI 0.000005 /* integration step */
|
||||||
#define NVID 150 /* number of iterations between images displayed on screen */
|
#define NVID 150 /* number of iterations between images displayed on screen */
|
||||||
|
|
||||||
@@ -102,9 +88,9 @@
|
|||||||
|
|
||||||
/* Colors and other graphical parameters */
|
/* Colors and other graphical parameters */
|
||||||
|
|
||||||
#define NCOLORS 16 /* number of colors */
|
#define NCOLORS 32 /* number of colors */
|
||||||
#define COLORSHIFT 0 /* hue of initial color */
|
#define COLORSHIFT 0 /* hue of initial color */
|
||||||
#define RAINBOW_COLOR 1 /* set to 1 to use different colors for all particles */
|
#define RAINBOW_COLOR 0 /* set to 1 to use different colors for all particles */
|
||||||
#define FLOWER_COLOR 0 /* set to 1 to adapt initial colors to flower billiard (tracks vs core) */
|
#define FLOWER_COLOR 0 /* set to 1 to adapt initial colors to flower billiard (tracks vs core) */
|
||||||
#define NSEG 100 /* number of segments of boundary */
|
#define NSEG 100 /* number of segments of boundary */
|
||||||
#define LENGTH 0.02 /* length of velocity vectors */
|
#define LENGTH 0.02 /* length of velocity vectors */
|
||||||
@@ -132,11 +118,9 @@
|
|||||||
/* animation part */
|
/* animation part */
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
void init_boundary_config(smin, smax, anglemin, anglemax, configs)
|
void init_boundary_config(double smin, double smax, double anglemin, double anglemax, double *configs[NPARTMAX])
|
||||||
/* initialize configuration: drop on the boundary, beta version */
|
/* initialize configuration: drop on the boundary, beta version */
|
||||||
/* WORKS FOR ELLIPSE, HAS TO BE ADAPTED TO GENERAL BILLIARD */
|
/* WORKS FOR ELLIPSE, HAS TO BE ADAPTED TO GENERAL BILLIARD */
|
||||||
double smin, smax, anglemin, anglemax;
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double ds, da, s, angle, theta, alpha, pos[2];
|
double ds, da, s, angle, theta, alpha, pos[2];
|
||||||
@@ -158,9 +142,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_drop_config(x0, y0, angle1, angle2, configs) /* initialize configuration: drop at (x0,y0) */
|
void init_drop_config(double x0, double y0, double angle1, double angle2, double *configs[NPARTMAX])
|
||||||
double x0, y0, angle1, angle2;
|
/* initialize configuration: drop at (x0,y0) */
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double dalpha, alpha;
|
double dalpha, alpha;
|
||||||
@@ -181,10 +164,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_sym_drop_config(x0, y0, angle1, angle2, configs)
|
void init_sym_drop_config(double x0, double y0, double angle1, double angle2, double *configs[NPARTMAX])
|
||||||
/* initialize configuration with two symmetric partial drops */
|
/* initialize configuration with two symmetric partial drops */
|
||||||
double x0, y0, angle1, angle2;
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double dalpha, alpha, meanangle;
|
double dalpha, alpha, meanangle;
|
||||||
@@ -210,9 +191,8 @@ double *configs[NPARTMAX];
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_line_config(x0, y0, x1, y1, angle, configs) /* initialize configuration: line (x0,y0)-(x1,y1) in direction alpha */
|
void init_line_config(double x0, double y0, double x1, double y1, double angle, double *configs[NPARTMAX])
|
||||||
double x0, y0, x1, y1, angle;
|
/* initialize configuration: line (x0,y0)-(x1,y1) in direction alpha */
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double dx, dy;
|
double dx, dy;
|
||||||
@@ -231,16 +211,14 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw_config(color, configs, active)
|
void draw_config(int color[NPARTMAX], double *configs[NPARTMAX], int active[NPARTMAX])
|
||||||
/* draw the particles */
|
/* draw the particles */
|
||||||
int color[NPARTMAX], active[NPARTMAX];
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
double x1, y1, x2, y2, cosphi, sinphi, rgb[3];
|
double x1, y1, x2, y2, cosphi, sinphi, rgb[3];
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
blank();
|
if (!SHOWTRAILS) blank();
|
||||||
if (PAINT_INT) paint_billiard_interior();
|
if (PAINT_INT) paint_billiard_interior();
|
||||||
|
|
||||||
glLineWidth(PARTICLE_WIDTH);
|
glLineWidth(PARTICLE_WIDTH);
|
||||||
@@ -335,10 +313,8 @@ double *configs[NPARTMAX];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void graph_movie(time, color, configs, active)
|
void graph_movie(int time, int color[NPARTMAX], double *configs[NPARTMAX], int active[NPARTMAX])
|
||||||
/* compute next movie frame */
|
/* compute next movie frame */
|
||||||
int time, color[NPARTMAX], active[NPARTMAX];
|
|
||||||
double *configs[NPARTMAX];
|
|
||||||
{
|
{
|
||||||
int i, j, c;
|
int i, j, c;
|
||||||
|
|
||||||
@@ -370,77 +346,6 @@ double *configs[NPARTMAX];
|
|||||||
// draw_config(color, configs);
|
// draw_config(color, configs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_circle_config()
|
|
||||||
{
|
|
||||||
int i, j, n;
|
|
||||||
double dx, dy;
|
|
||||||
|
|
||||||
switch (CIRCLE_PATTERN) {
|
|
||||||
case (C_FOUR_CIRCLES):
|
|
||||||
{
|
|
||||||
ncircles = 4;
|
|
||||||
|
|
||||||
circlex[0] = 1.0;
|
|
||||||
circley[0] = 0.0;
|
|
||||||
circlerad[0] = 0.8;
|
|
||||||
|
|
||||||
circlex[1] = -1.0;
|
|
||||||
circley[1] = 0.0;
|
|
||||||
circlerad[1] = 0.8;
|
|
||||||
|
|
||||||
circlex[2] = 0.0;
|
|
||||||
circley[2] = 0.8;
|
|
||||||
circlerad[2] = 0.4;
|
|
||||||
|
|
||||||
circlex[3] = 0.0;
|
|
||||||
circley[3] = -0.8;
|
|
||||||
circlerad[3] = 0.4;
|
|
||||||
|
|
||||||
for (i=0; i<4; i++) circleactive[i] = 1;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (C_SQUARE):
|
|
||||||
{
|
|
||||||
ncircles = NCX*NCY;
|
|
||||||
dy = (YMAX - YMIN)/((double)NCY);
|
|
||||||
for (i = 0; i < NCX; i++)
|
|
||||||
for (j = 0; j < NCY; j++)
|
|
||||||
{
|
|
||||||
n = NCY*i + j;
|
|
||||||
circlex[n] = ((double)(i-NCX/2) + 0.5)*dy;
|
|
||||||
circley[n] = YMIN + ((double)j + 0.5)*dy;
|
|
||||||
circlerad[n] = MU;
|
|
||||||
circleactive[n] = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (C_HEX):
|
|
||||||
{
|
|
||||||
ncircles = NCX*(NCY+1);
|
|
||||||
dy = (YMAX - YMIN)/((double)NCY);
|
|
||||||
dx = dy*0.5*sqrt(3.0);
|
|
||||||
for (i = 0; i < NCX; i++)
|
|
||||||
for (j = 0; j < NCY+1; j++)
|
|
||||||
{
|
|
||||||
n = (NCY+1)*i + j;
|
|
||||||
circlex[n] = ((double)(i-NCX/2) + 0.5)*dy;
|
|
||||||
circley[n] = YMIN + ((double)j - 0.5)*dy;
|
|
||||||
if ((i+NCX)%2 == 1) circley[n] += 0.5*dy;
|
|
||||||
circlerad[n] = MU;
|
|
||||||
circleactive[n] = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
printf("Function init_circle_config not defined for this pattern \n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void animation()
|
void animation()
|
||||||
{
|
{
|
||||||
double time, dt, alpha, r;
|
double time, dt, alpha, r;
|
||||||
@@ -456,24 +361,27 @@ void animation()
|
|||||||
configs[i] = (double *)malloc(8*sizeof(double));
|
configs[i] = (double *)malloc(8*sizeof(double));
|
||||||
|
|
||||||
/* init circle configuration if the domain is D_CIRCLES */
|
/* init circle configuration if the domain is D_CIRCLES */
|
||||||
if (B_DOMAIN == D_CIRCLES) init_circle_config();
|
if ((B_DOMAIN == D_CIRCLES)||(B_DOMAIN == D_CIRCLES_IN_RECT)||(B_DOMAIN == D_CIRCLES_IN_GENUSN)) init_circle_config();
|
||||||
|
|
||||||
|
|
||||||
/* initialize system by putting particles in a given point with a range of velocities */
|
/* initialize system by putting particles in a given point with a range of velocities */
|
||||||
r = cos(PI/(double)NPOLY)/cos(DPI/(double)NPOLY);
|
r = cos(PI/(double)NPOLY)/cos(DPI/(double)NPOLY);
|
||||||
|
|
||||||
// init_drop_config(0.0, 0.0, 0.0, PI, configs);
|
// init_line_config(-1.25, -0.5, -1.25, 0.5, 0.0, configs);
|
||||||
|
// init_drop_config(-0.75, 0.0, -0.1, 0.1, configs);
|
||||||
// init_drop_config(0.5, 0.5, -1.0, 1.0, configs);
|
// init_drop_config(0.5, 0.5, -1.0, 1.0, configs);
|
||||||
// init_sym_drop_config(-1.0, 0.5, -PID, PID, configs);
|
// init_sym_drop_config(-1.0, 0.5, -PID, PID, configs);
|
||||||
// init_drop_config(-0.999, 0.0, -alpha, alpha, configs);
|
// init_drop_config(-0.999, 0.0, -alpha, alpha, configs);
|
||||||
|
|
||||||
// other possible initial conditions :
|
// other possible initial conditions :
|
||||||
// init_line_config(-1.25, -0.5, -1.25, 0.5, 0.0, configs);
|
init_line_config(-1.25, -0.5, -1.25, 0.5, 0.0, configs);
|
||||||
init_line_config(0.0, -1.0, -1.0, 1.0, 0.25*PID, configs);
|
// init_line_config(0.0, -0.5, 0.0, 0.5, 0.0, configs);
|
||||||
|
// init_line_config(-1.25, -0.5, -1.25, 0.5, 0.0*PID, configs);
|
||||||
|
// init_line_config(-1.0, -0.3, -1.0, 0.3, 0.0, configs);
|
||||||
// init_line_config(-0.7, -0.45, -0.7, 0.45, 0.0, configs);
|
// init_line_config(-0.7, -0.45, -0.7, 0.45, 0.0, configs);
|
||||||
// init_line_config(-1.5, 0.1, -0.1, 1.0, -0.5*PID, configs);
|
// init_line_config(-1.5, 0.1, -0.1, 1.0, -0.5*PID, configs);
|
||||||
|
|
||||||
blank();
|
if (!SHOWTRAILS) blank();
|
||||||
glColor3f(0.0, 0.0, 0.0);
|
glColor3f(0.0, 0.0, 0.0);
|
||||||
if (DRAW_BILLIARD) draw_billiard();
|
if (DRAW_BILLIARD) draw_billiard();
|
||||||
|
|
||||||
@@ -556,9 +464,13 @@ void display(void)
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
blank();
|
blank();
|
||||||
|
|
||||||
|
if (!SHOWTRAILS)
|
||||||
|
{
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
blank();
|
blank();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
animation();
|
animation();
|
||||||
|
|
||||||
@@ -571,7 +483,9 @@ void display(void)
|
|||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
if (SHOWTRAILS) glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH);
|
||||||
|
else glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||||
|
// glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||||
glutInitWindowSize(WINWIDTH,WINHEIGHT);
|
glutInitWindowSize(WINWIDTH,WINHEIGHT);
|
||||||
glutCreateWindow("Billiard animation");
|
glutCreateWindow("Billiard animation");
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
#define NSTEPS 200 /* number of frames of movie */
|
#define NSTEPS 200 /* number of frames of movie */
|
||||||
#define NVID 1200 /* number of iterations between images displayed on screen */
|
#define NVID 1200 /* number of iterations between images displayed on screen */
|
||||||
#define NSEG 100 /* number of segments of boundary */
|
#define NSEG 100 /* number of segments of boundary */
|
||||||
|
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */
|
||||||
|
|
||||||
#define PAUSE 1000 /* number of frames after which to pause */
|
#define PAUSE 1000 /* number of frames after which to pause */
|
||||||
#define PSLEEP 1 /* sleep time during pause */
|
#define PSLEEP 1 /* sleep time during pause */
|
||||||
@@ -140,12 +141,10 @@ double intstep1; /* integration step used in absorbing boundary conditions */
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void init_coherent_state(x, y, px, py, scalex, phi, psi, xy_in)
|
void init_coherent_state(double x, double y, double px, double py, double scalex, double *phi[NX],
|
||||||
|
double *psi[NX], short int *xy_in[NX])
|
||||||
/* initialise field with coherent state of position (x,y) and momentum (px, py) */
|
/* initialise field with coherent state of position (x,y) and momentum (px, py) */
|
||||||
/* phi is real part, psi is imaginary part */
|
/* phi is real part, psi is imaginary part */
|
||||||
double x, y, px, py, scalex, *phi[NX], *psi[NX];
|
|
||||||
short int * xy_in[NX];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double xy[2], dist2, module, phase, scale2;
|
double xy[2], dist2, module, phase, scale2;
|
||||||
@@ -181,9 +180,9 @@ void init_coherent_state(x, y, px, py, scalex, phi, psi, xy_in)
|
|||||||
/* animation part */
|
/* animation part */
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
void schrodinger_color_scheme(phi, psi, scale, time, rgb)
|
void schrodinger_color_scheme(double phi, double psi, double scale, int time, double rgb[3])
|
||||||
double phi, psi, scale, rgb[3];
|
// double phi, psi, scale, rgb[3];
|
||||||
int time;
|
// int time;
|
||||||
{
|
{
|
||||||
double phase, amp, lum;
|
double phase, amp, lum;
|
||||||
|
|
||||||
@@ -204,11 +203,8 @@ int time;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw_wave(phi, psi, xy_in, scale, time)
|
void draw_wave(double *phi[NX], double *psi[NX], short int *xy_in[NX], double scale, int time)
|
||||||
/* draw the field */
|
/* draw the field */
|
||||||
double *phi[NX], *psi[NX], scale;
|
|
||||||
short int *xy_in[NX];
|
|
||||||
int time;
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double rgb[3], xy[2], x1, y1, x2, y2, amp, phase;
|
double rgb[3], xy[2], x1, y1, x2, y2, amp, phase;
|
||||||
@@ -234,10 +230,12 @@ int time;
|
|||||||
glEnd ();
|
glEnd ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
void evolve_wave_half(double *phi_in[NX], double *psi_in[NX], double *phi_out[NX], double *psi_out[NX],
|
||||||
/* time step of field evolution */
|
short int *xy_in[NX])
|
||||||
/* phi is real part, psi is imaginary part */
|
// void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
||||||
double *phi_in[NX], *psi_in[NX], *phi_out[NX], *psi_out[NX]; short int *xy_in[NX];
|
// /* time step of field evolution */
|
||||||
|
// /* phi is real part, psi is imaginary part */
|
||||||
|
// double *phi_in[NX], *psi_in[NX], *phi_out[NX], *psi_out[NX]; short int *xy_in[NX];
|
||||||
{
|
{
|
||||||
int i, j, iplus, iminus, jplus, jminus;
|
int i, j, iplus, iminus, jplus, jminus;
|
||||||
double delta1, delta2, x, y;
|
double delta1, delta2, x, y;
|
||||||
@@ -325,19 +323,19 @@ void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
|||||||
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void evolve_wave(phi, psi, phi_tmp, psi_tmp, xy_in)
|
void evolve_wave(double *phi[NX], double *psi[NX], double *phi_tmp[NX], double *psi_tmp[NX], short int *xy_in[NX])
|
||||||
/* time step of field evolution */
|
/* time step of field evolution */
|
||||||
/* phi is value of field at time t, psi at time t-1 */
|
/* phi is real part, psi is imaginary part */
|
||||||
double *phi[NX], *psi[NX], *phi_tmp[NX], *psi_tmp[NX]; short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
evolve_wave_half(phi, psi, phi_tmp, psi_tmp, xy_in);
|
evolve_wave_half(phi, psi, phi_tmp, psi_tmp, xy_in);
|
||||||
evolve_wave_half(phi_tmp, psi_tmp, phi, psi, xy_in);
|
evolve_wave_half(phi_tmp, psi_tmp, phi, psi, xy_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double compute_variance(phi, psi, xy_in)
|
double compute_variance(double *phi[NX], double *psi[NX], short int *xy_in[NX])
|
||||||
|
// double compute_variance(phi, psi, xy_in)
|
||||||
/* compute the variance (total probability) of the field */
|
/* compute the variance (total probability) of the field */
|
||||||
double *phi[NX], *psi[NX]; short int * xy_in[NX];
|
// double *phi[NX], *psi[NX]; short int * xy_in[NX];
|
||||||
{
|
{
|
||||||
int i, j, n = 0;
|
int i, j, n = 0;
|
||||||
double variance = 0.0;
|
double variance = 0.0;
|
||||||
@@ -355,10 +353,8 @@ double *phi[NX], *psi[NX]; short int * xy_in[NX];
|
|||||||
return(variance/(double)n);
|
return(variance/(double)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renormalise_field(phi, psi, xy_in, variance)
|
void renormalise_field(double *phi[NX], double *psi[NX], short int *xy_in[NX], double variance)
|
||||||
/* renormalise variance of field */
|
/* renormalise variance of field */
|
||||||
double *phi[NX], *psi[NX], variance;
|
|
||||||
short int * xy_in[NX];
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double stdv;
|
double stdv;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
442
sub_wave.c
442
sub_wave.c
@@ -67,9 +67,8 @@ void init() /* initialisation of window */
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void hsl_to_rgb(h, s, l, rgb) /* color conversion from HSL to RGB */
|
void hsl_to_rgb(double h, double s, double l, double rgb[3]) /* color conversion from HSL to RGB */
|
||||||
/* h = hue, s = saturation, l = luminosity */
|
/* h = hue, s = saturation, l = luminosity */
|
||||||
double h, s, l, rgb[3];
|
|
||||||
{
|
{
|
||||||
double c = 0.0, m = 0.0, x = 0.0;
|
double c = 0.0, m = 0.0, x = 0.0;
|
||||||
|
|
||||||
@@ -109,19 +108,14 @@ double h, s, l, rgb[3];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
double color_amplitude(value, scale, time)
|
double color_amplitude(double value, double scale, int time)
|
||||||
/* transforms the wave amplitude into a double in [-1,1] to feed into color scheme */
|
/* transforms the wave amplitude into a double in [-1,1] to feed into color scheme */
|
||||||
double value, scale;
|
|
||||||
int time;
|
|
||||||
{
|
{
|
||||||
return(tanh(SLOPE*value/scale)*exp(-((double)time*ATTENUATION)));
|
return(tanh(SLOPE*value/scale)*exp(-((double)time*ATTENUATION)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void color_scheme(scheme, value, scale, time, rgb) /* color scheme */
|
void color_scheme(int scheme, double value, double scale, int time, double rgb[3]) /* color scheme */
|
||||||
double value, scale;
|
|
||||||
int scheme, time;
|
|
||||||
double rgb[3];
|
|
||||||
{
|
{
|
||||||
double hue, y, r, amplitude;
|
double hue, y, r, amplitude;
|
||||||
int intpart;
|
int intpart;
|
||||||
@@ -182,6 +176,21 @@ void save_frame()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void save_frame_counter(int counter)
|
||||||
|
/* same as save_frame, but with imposed image number (for option DOUBLE_MOVIE) */
|
||||||
|
{
|
||||||
|
char *name="wave.", n2[100];
|
||||||
|
char format[6]=".%05i";
|
||||||
|
|
||||||
|
strcpy(n2, name);
|
||||||
|
sprintf(strstr(n2,"."), format, counter);
|
||||||
|
strcat(n2, ".tif");
|
||||||
|
printf(" saving frame %s \n",n2);
|
||||||
|
writetiff(n2, "Wave equation in a planar domain", 0, 0,
|
||||||
|
WINWIDTH, WINHEIGHT, COMPRESSION_LZW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void write_text( double x, double y, char *st)
|
void write_text( double x, double y, char *st)
|
||||||
{
|
{
|
||||||
@@ -203,8 +212,7 @@ void write_text( double x, double y, char *st)
|
|||||||
/* some basic math */
|
/* some basic math */
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
double vabs(x) /* absolute value */
|
double vabs(double x) /* absolute value */
|
||||||
double x;
|
|
||||||
{
|
{
|
||||||
double res;
|
double res;
|
||||||
|
|
||||||
@@ -213,9 +221,7 @@ void write_text( double x, double y, char *st)
|
|||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
double module2(x, y) /* Euclidean norm */
|
double module2(double x, double y) /* Euclidean norm */
|
||||||
double x, y;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
double m;
|
double m;
|
||||||
|
|
||||||
@@ -223,9 +229,7 @@ void write_text( double x, double y, char *st)
|
|||||||
return(m);
|
return(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
double argument(x, y)
|
double argument(double x, double y)
|
||||||
double x, y;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
double alph;
|
double alph;
|
||||||
|
|
||||||
@@ -257,10 +261,8 @@ void write_text( double x, double y, char *st)
|
|||||||
/* sets of coordinates decreases number of double computations when */
|
/* sets of coordinates decreases number of double computations when */
|
||||||
/* drawing the field */
|
/* drawing the field */
|
||||||
|
|
||||||
void xy_to_ij(x, y, ij)
|
void xy_to_ij(double x, double y, int ij[2])
|
||||||
/* convert (x,y) position to (i,j) in table representing wave */
|
/* convert (x,y) position to (i,j) in table representing wave */
|
||||||
double x, y;
|
|
||||||
int ij[2];
|
|
||||||
{
|
{
|
||||||
double x1, y1;
|
double x1, y1;
|
||||||
|
|
||||||
@@ -272,9 +274,8 @@ int ij[2];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xy_to_pos(x, y, pos)
|
void xy_to_pos(double x, double y, double pos[2])
|
||||||
/* convert (x,y) position to double-valued position in table representing wave */
|
/* convert (x,y) position to double-valued position in table representing wave */
|
||||||
double x, y, pos[2];
|
|
||||||
{
|
{
|
||||||
double x1, y1;
|
double x1, y1;
|
||||||
|
|
||||||
@@ -286,10 +287,8 @@ double x, y, pos[2];
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ij_to_xy(i, j, xy)
|
void ij_to_xy(int i, int j, double xy[2])
|
||||||
/* convert (i,j) position in table representing wave to (x,y) */
|
/* convert (i,j) position in table representing wave to (x,y) */
|
||||||
int i, j;
|
|
||||||
double xy[2];
|
|
||||||
{
|
{
|
||||||
double x1, y1;
|
double x1, y1;
|
||||||
|
|
||||||
@@ -297,8 +296,26 @@ double xy[2];
|
|||||||
xy[1] = YMIN + ((double)j)*(YMAX-YMIN)/((double)NY);
|
xy[1] = YMIN + ((double)j)*(YMAX-YMIN)/((double)NY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_rectangle(x1, y1, x2, y2)
|
void erase_area(double x, double y, double dx, double dy)
|
||||||
double x1, y1, x2, y2;
|
{
|
||||||
|
double pos[2], rgb[3];
|
||||||
|
|
||||||
|
hsl_to_rgb(220.0, 0.8, 0.7, rgb);
|
||||||
|
|
||||||
|
glColor3f(rgb[0], rgb[1], rgb[2]);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
xy_to_pos(x - dx, y - dy, pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
xy_to_pos(x + dx, y - dy, pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
xy_to_pos(x + dx, y + dy, pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
xy_to_pos(x - dx, y + dy, pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_rectangle(double x1, double y1, double x2, double y2)
|
||||||
{
|
{
|
||||||
double pos[2];
|
double pos[2];
|
||||||
|
|
||||||
@@ -314,9 +331,7 @@ double x1, y1, x2, y2;
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_rotated_rectangle(double x1, double y1, double x2, double y2)
|
||||||
void draw_rotated_rectangle(x1, y1, x2, y2)
|
|
||||||
double x1, y1, x2, y2;
|
|
||||||
{
|
{
|
||||||
double pos[2];
|
double pos[2];
|
||||||
double xa, ya, xb, yb, xc, yc;
|
double xa, ya, xb, yb, xc, yc;
|
||||||
@@ -340,12 +355,51 @@ double x1, y1, x2, y2;
|
|||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_circle(double x, double y, double r, int nseg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
double pos[2], alpha, dalpha;
|
||||||
|
|
||||||
|
dalpha = DPI/(double)nseg;
|
||||||
|
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
for (i=0; i<=nseg; i++)
|
||||||
|
{
|
||||||
|
alpha = (double)i*dalpha;
|
||||||
|
xy_to_pos(x + r*cos(alpha), y + r*sin(alpha), pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_colored_circle(double x, double y, double r, int nseg, double rgb[3])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
double pos[2], alpha, dalpha;
|
||||||
|
|
||||||
|
dalpha = DPI/(double)nseg;
|
||||||
|
|
||||||
|
glColor3f(rgb[0], rgb[1], rgb[2]);
|
||||||
|
glBegin(GL_TRIANGLE_FAN);
|
||||||
|
xy_to_pos(x, y, pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
for (i=0; i<=nseg; i++)
|
||||||
|
{
|
||||||
|
alpha = (double)i*dalpha;
|
||||||
|
xy_to_pos(x + r*cos(alpha), y + r*sin(alpha), pos);
|
||||||
|
glVertex2d(pos[0], pos[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void init_circle_config()
|
void init_circle_config()
|
||||||
/* initialise the arrays circlex, circley, circlerad and circleactive */
|
/* initialise the arrays circlex, circley, circlerad and circleactive */
|
||||||
/* for billiard shape D_CIRCLES */
|
/* for billiard shape D_CIRCLES */
|
||||||
{
|
{
|
||||||
int i, j, n;
|
int i, j, n, ncirc0;
|
||||||
double dx, dy, p, phi, r, ra[5], sa[5];
|
double dx, dy, p, phi, r, r0, ra[5], sa[5], height, x, y = 0.0, gamma;
|
||||||
|
|
||||||
switch (CIRCLE_PATTERN) {
|
switch (CIRCLE_PATTERN) {
|
||||||
case (C_SQUARE):
|
case (C_SQUARE):
|
||||||
@@ -372,11 +426,13 @@ void init_circle_config()
|
|||||||
for (j = 0; j < NGRIDY+1; j++)
|
for (j = 0; j < NGRIDY+1; j++)
|
||||||
{
|
{
|
||||||
n = (NGRIDY+1)*i + j;
|
n = (NGRIDY+1)*i + j;
|
||||||
circlex[n] = ((double)(i-NGRIDX/2) + 0.5)*dy;
|
circlex[n] = ((double)(i-NGRIDX/2) + 0.5)*dy; /* is +0.5 needed? */
|
||||||
circley[n] = YMIN + ((double)j - 0.5)*dy;
|
circley[n] = YMIN + ((double)j - 0.5)*dy;
|
||||||
if ((i+NGRIDX)%2 == 1) circley[n] += 0.5*dy;
|
if ((i+NGRIDX)%2 == 1) circley[n] += 0.5*dy;
|
||||||
circlerad[n] = MU;
|
circlerad[n] = MU;
|
||||||
circleactive[n] = 1;
|
/* activate only circles that intersect the domain */
|
||||||
|
if ((circley[n] < YMAX + MU)&&(circley[n] > YMIN - MU)) circleactive[n] = 1;
|
||||||
|
else circleactive[n] = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -388,9 +444,9 @@ void init_circle_config()
|
|||||||
for (j = 0; j < NGRIDY; j++)
|
for (j = 0; j < NGRIDY; j++)
|
||||||
{
|
{
|
||||||
n = NGRIDY*i + j;
|
n = NGRIDY*i + j;
|
||||||
circlex[n] = ((double)(i-NGRIDX/2) + 0.5 + 0.5*(double)rand()/RAND_MAX)*dy;
|
circlex[n] = ((double)(i-NGRIDX/2) + 0.5*((double)rand()/RAND_MAX - 0.5))*dy;
|
||||||
circley[n] = YMIN + ((double)j + 0.5 + 0.5*(double)rand()/RAND_MAX)*dy;
|
circley[n] = YMIN + ((double)j + 0.5 + 0.5*((double)rand()/RAND_MAX - 0.5))*dy;
|
||||||
circlerad[n] = MU*(1.0 + 0.35*(double)rand()/RAND_MAX);
|
circlerad[n] = MU*sqrt(1.0 + 0.8*((double)rand()/RAND_MAX - 0.5));
|
||||||
circleactive[n] = 1;
|
circleactive[n] = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -461,6 +517,129 @@ void init_circle_config()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case (C_GOLDEN_MEAN):
|
||||||
|
{
|
||||||
|
ncircles = 300;
|
||||||
|
gamma = (sqrt(5.0) - 1.0)*0.5; /* golden mean */
|
||||||
|
height = YMAX - YMIN;
|
||||||
|
dx = 2.0*LAMBDA/((double)ncircles);
|
||||||
|
for (n = 0; n < ncircles; n++)
|
||||||
|
{
|
||||||
|
circlex[n] = -LAMBDA + n*dx;
|
||||||
|
circley[n] = y;
|
||||||
|
y += height*gamma;
|
||||||
|
if (y > YMAX) y -= height;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
circleactive[n] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* test for circles that overlap top or bottom boundary */
|
||||||
|
ncirc0 = ncircles;
|
||||||
|
for (n=0; n < ncirc0; n++)
|
||||||
|
{
|
||||||
|
if (circley[n] + circlerad[n] > YMAX)
|
||||||
|
{
|
||||||
|
circlex[ncircles] = circlex[n];
|
||||||
|
circley[ncircles] = circley[n] - height;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
ncircles ++;
|
||||||
|
}
|
||||||
|
else if (circley[n] - circlerad[n] < YMIN)
|
||||||
|
{
|
||||||
|
circlex[ncircles] = circlex[n];
|
||||||
|
circley[ncircles] = circley[n] + height;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
ncircles ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_GOLDEN_SPIRAL):
|
||||||
|
{
|
||||||
|
ncircles = 1;
|
||||||
|
circlex[0] = 0.0;
|
||||||
|
circley[0] = 0.0;
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
circlex[ncircles] = x;
|
||||||
|
circley[ncircles] = y;
|
||||||
|
ncircles++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<ncircles; i++)
|
||||||
|
{
|
||||||
|
circlerad[i] = MU;
|
||||||
|
/* inactivate circles outside the domain */
|
||||||
|
if ((circley[i] < YMAX + MU)&&(circley[i] > YMIN - MU)) circleactive[i] = 1;
|
||||||
|
// printf("i = %i, circlex = %.3lg, circley = %.3lg\n", i, circlex[i], circley[i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_SQUARE_HEX):
|
||||||
|
{
|
||||||
|
ncircles = NGRIDX*(NGRIDY+1);
|
||||||
|
dy = (YMAX - YMIN)/((double)NGRIDY);
|
||||||
|
dx = dy*0.5*sqrt(3.0);
|
||||||
|
for (i = 0; i < NGRIDX; i++)
|
||||||
|
for (j = 0; j < NGRIDY+1; j++)
|
||||||
|
{
|
||||||
|
n = (NGRIDY+1)*i + j;
|
||||||
|
circlex[n] = ((double)(i-NGRIDX/2) + 0.5)*dy; /* is +0.5 needed? */
|
||||||
|
circley[n] = YMIN + ((double)j - 0.5)*dy;
|
||||||
|
if (((i+NGRIDX)%4 == 2)||((i+NGRIDX)%4 == 3)) circley[n] += 0.5*dy;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
/* activate only circles that intersect the domain */
|
||||||
|
if ((circley[n] < YMAX + MU)&&(circley[n] > YMIN - MU)) circleactive[n] = 1;
|
||||||
|
else circleactive[n] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_ONE):
|
||||||
|
{
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
ncircles += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_TWO): /* used for comparison with cloak */
|
||||||
|
{
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 2;
|
||||||
|
ncircles += 1;
|
||||||
|
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
circlerad[ncircles] = 2.0*MU;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
ncircles += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_NOTHING):
|
||||||
|
{
|
||||||
|
ncircles += 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
printf("Function init_circle_config not defined for this pattern \n");
|
printf("Function init_circle_config not defined for this pattern \n");
|
||||||
@@ -477,19 +656,19 @@ double x, y;
|
|||||||
int i, j, k, k1, k2, condition;
|
int i, j, k, k1, k2, condition;
|
||||||
|
|
||||||
switch (B_DOMAIN) {
|
switch (B_DOMAIN) {
|
||||||
case D_RECTANGLE:
|
case (D_RECTANGLE):
|
||||||
{
|
{
|
||||||
if ((vabs(x) <LAMBDA)&&(vabs(y) < 1.0)) return(1);
|
if ((vabs(x) <LAMBDA)&&(vabs(y) < 1.0)) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_ELLIPSE:
|
case (D_ELLIPSE):
|
||||||
{
|
{
|
||||||
if (x*x/(LAMBDA*LAMBDA) + y*y < 1.0) return(1);
|
if (x*x/(LAMBDA*LAMBDA) + y*y < 1.0) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_STADIUM:
|
case (D_STADIUM):
|
||||||
{
|
{
|
||||||
if ((x > -0.5*LAMBDA)&&(x < 0.5*LAMBDA)&&(y > -1.0)&&(y < 1.0)) return(1);
|
if ((x > -0.5*LAMBDA)&&(x < 0.5*LAMBDA)&&(y > -1.0)&&(y < 1.0)) return(1);
|
||||||
else if (module2(x+0.5*LAMBDA, y) < 1.0) return(1);
|
else if (module2(x+0.5*LAMBDA, y) < 1.0) return(1);
|
||||||
@@ -497,13 +676,13 @@ double x, y;
|
|||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_SINAI:
|
case (D_SINAI):
|
||||||
{
|
{
|
||||||
if (x*x + y*y > LAMBDA*LAMBDA) return(1);
|
if (x*x + y*y > LAMBDA*LAMBDA) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_DIAMOND:
|
case (D_DIAMOND):
|
||||||
{
|
{
|
||||||
l2 = LAMBDA*LAMBDA;
|
l2 = LAMBDA*LAMBDA;
|
||||||
r2 = l2 + (LAMBDA-1.0)*(LAMBDA-1.0);
|
r2 = l2 + (LAMBDA-1.0)*(LAMBDA-1.0);
|
||||||
@@ -514,26 +693,26 @@ double x, y;
|
|||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_TRIANGLE:
|
case (D_TRIANGLE):
|
||||||
{
|
{
|
||||||
if ((x>-LAMBDA)&&(y>-1.0)&&(LAMBDA*y+x<0.0)) return(1);
|
if ((x>-LAMBDA)&&(y>-1.0)&&(LAMBDA*y+x<0.0)) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_FLAT:
|
case (D_FLAT):
|
||||||
{
|
{
|
||||||
if (y > -LAMBDA) return(1);
|
if (y > -LAMBDA) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_ANNULUS:
|
case (D_ANNULUS):
|
||||||
{
|
{
|
||||||
l2 = LAMBDA*LAMBDA;
|
l2 = LAMBDA*LAMBDA;
|
||||||
r2 = x*x + y*y;
|
r2 = x*x + y*y;
|
||||||
if ((r2 > l2)&&(r2 < 1.0)) return(1);
|
if ((r2 > l2)&&(r2 < 1.0)) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
case D_POLYGON:
|
case (D_POLYGON):
|
||||||
{
|
{
|
||||||
condition = 1;
|
condition = 1;
|
||||||
omega = DPI/((double)NPOLY);
|
omega = DPI/((double)NPOLY);
|
||||||
@@ -546,13 +725,13 @@ double x, y;
|
|||||||
// for (k=0; k<NPOLY; k++) condition = condition*(-x*sin((k+0.5)*omega) + y*cos((k+0.5)*omega) < c);
|
// for (k=0; k<NPOLY; k++) condition = condition*(-x*sin((k+0.5)*omega) + y*cos((k+0.5)*omega) < c);
|
||||||
return(condition);
|
return(condition);
|
||||||
}
|
}
|
||||||
case D_YOUNG:
|
case (D_YOUNG):
|
||||||
{
|
{
|
||||||
if ((x < -MU)||(x > MU)) return(1);
|
if ((x < -MU)||(x > MU)) return(1);
|
||||||
else if ((vabs(y-LAMBDA) < MU)||(vabs(y+LAMBDA) < MU)) return (1);
|
else if ((vabs(y-LAMBDA) < MU)||(vabs(y+LAMBDA) < MU)) return (1);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
case D_GRATING:
|
case (D_GRATING):
|
||||||
{
|
{
|
||||||
k1 = -(int)((-YMIN)/LAMBDA);
|
k1 = -(int)((-YMIN)/LAMBDA);
|
||||||
k2 = (int)(YMAX/LAMBDA);
|
k2 = (int)(YMAX/LAMBDA);
|
||||||
@@ -565,11 +744,11 @@ double x, y;
|
|||||||
// printf("x = %.3lg, y = %.3lg, k1 = %i, k2 = %i, condition = %i\n", x, y, k1, k2, condition);
|
// printf("x = %.3lg, y = %.3lg, k1 = %i, k2 = %i, condition = %i\n", x, y, k1, k2, condition);
|
||||||
return(condition);
|
return(condition);
|
||||||
}
|
}
|
||||||
case D_EHRENFEST:
|
case (D_EHRENFEST):
|
||||||
{
|
{
|
||||||
return(((x-1.0)*(x-1.0) + y*y < LAMBDA*LAMBDA)||((x+1.0)*(x+1.0) + y*y < LAMBDA*LAMBDA)||((vabs(x) < 1.0)&&(vabs(y) < MU)));
|
return(((x-1.0)*(x-1.0) + y*y < LAMBDA*LAMBDA)||((x+1.0)*(x+1.0) + y*y < LAMBDA*LAMBDA)||((vabs(x) < 1.0)&&(vabs(y) < MU)));
|
||||||
}
|
}
|
||||||
case D_DISK_GRID:
|
case (D_DISK_GRID):
|
||||||
{
|
{
|
||||||
dy = (YMAX - YMIN)/((double)NGRIDY);
|
dy = (YMAX - YMIN)/((double)NGRIDY);
|
||||||
for (i = -NGRIDX/2; i < NGRIDX/2; i++)
|
for (i = -NGRIDX/2; i < NGRIDX/2; i++)
|
||||||
@@ -581,7 +760,7 @@ double x, y;
|
|||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
case D_DISK_HEX:
|
case (D_DISK_HEX):
|
||||||
{
|
{
|
||||||
dy = (YMAX - YMIN)/((double)NGRIDY);
|
dy = (YMAX - YMIN)/((double)NGRIDY);
|
||||||
dx = dy*0.5*sqrt(3.0);
|
dx = dy*0.5*sqrt(3.0);
|
||||||
@@ -595,7 +774,7 @@ double x, y;
|
|||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
case D_CIRCLES:
|
case (D_CIRCLES):
|
||||||
{
|
{
|
||||||
for (i = 0; i < ncircles; i++)
|
for (i = 0; i < ncircles; i++)
|
||||||
if (circleactive[i])
|
if (circleactive[i])
|
||||||
@@ -607,7 +786,7 @@ double x, y;
|
|||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
case D_MENGER:
|
case (D_MENGER):
|
||||||
{
|
{
|
||||||
x1 = 0.5*(x+1.0);
|
x1 = 0.5*(x+1.0);
|
||||||
y1 = 0.5*(y+1.0);
|
y1 = 0.5*(y+1.0);
|
||||||
@@ -619,7 +798,7 @@ double x, y;
|
|||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
case D_JULIA_INT:
|
case (D_JULIA_INT):
|
||||||
{
|
{
|
||||||
u = x/JULIA_SCALE;
|
u = x/JULIA_SCALE;
|
||||||
v = y/JULIA_SCALE;
|
v = y/JULIA_SCALE;
|
||||||
@@ -634,7 +813,7 @@ double x, y;
|
|||||||
if (u*u + v*v < MANDELLIMIT) return(1);
|
if (u*u + v*v < MANDELLIMIT) return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
case D_MENGER_ROTATED:
|
case (D_MENGER_ROTATED):
|
||||||
{
|
{
|
||||||
x2 = 1.0*(x + y);
|
x2 = 1.0*(x + y);
|
||||||
y2 = 1.0*(x - y);
|
y2 = 1.0*(x - y);
|
||||||
@@ -651,7 +830,7 @@ double x, y;
|
|||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
case D_ANNULUS_HEATED: /* returns 2 if in inner circle */
|
case (D_ANNULUS_HEATED): /* returns 2 if in inner circle */
|
||||||
{
|
{
|
||||||
l2 = LAMBDA*LAMBDA;
|
l2 = LAMBDA*LAMBDA;
|
||||||
r2 = x*x + y*y;
|
r2 = x*x + y*y;
|
||||||
@@ -660,7 +839,7 @@ double x, y;
|
|||||||
else if (r2mu <= l2) return(2);
|
else if (r2mu <= l2) return(2);
|
||||||
else return (0);
|
else return (0);
|
||||||
}
|
}
|
||||||
case D_MENGER_HEATED:
|
case (D_MENGER_HEATED):
|
||||||
{
|
{
|
||||||
if ((vabs(x) >= 1.0)||(vabs(y) >= 1.0)) return(0);
|
if ((vabs(x) >= 1.0)||(vabs(y) >= 1.0)) return(0);
|
||||||
else
|
else
|
||||||
@@ -676,7 +855,7 @@ double x, y;
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case D_MENGER_H_OPEN: /* returns 2 if in inner circle */
|
case (D_MENGER_H_OPEN): /* returns 2 if in inner circle */
|
||||||
{
|
{
|
||||||
x1 = 0.5*(x+1.0);
|
x1 = 0.5*(x+1.0);
|
||||||
y1 = 0.5*(y+1.0);
|
y1 = 0.5*(y+1.0);
|
||||||
@@ -688,7 +867,7 @@ double x, y;
|
|||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
case D_MANDELBROT:
|
case (D_MANDELBROT):
|
||||||
{
|
{
|
||||||
u = 0.0;
|
u = 0.0;
|
||||||
v = 0.0;
|
v = 0.0;
|
||||||
@@ -707,7 +886,7 @@ double x, y;
|
|||||||
else if ((x-0.5)*(x-0.5)/3.0 + y*y/1.0 > 1.2) return(2);
|
else if ((x-0.5)*(x-0.5)/3.0 + y*y/1.0 > 1.2) return(2);
|
||||||
else return(1);
|
else return(1);
|
||||||
}
|
}
|
||||||
case D_MANDELBROT_CIRCLE:
|
case (D_MANDELBROT_CIRCLE):
|
||||||
{
|
{
|
||||||
u = 0.0;
|
u = 0.0;
|
||||||
v = 0.0;
|
v = 0.0;
|
||||||
@@ -723,7 +902,7 @@ double x, y;
|
|||||||
else if ((x-LAMBDA)*(x-LAMBDA) + (y-0.5)*(y-0.5) < MU*MU) return(2);
|
else if ((x-LAMBDA)*(x-LAMBDA) + (y-0.5)*(y-0.5) < MU*MU) return(2);
|
||||||
else return(1);
|
else return(1);
|
||||||
}
|
}
|
||||||
case D_JULIA:
|
case (D_JULIA):
|
||||||
{
|
{
|
||||||
u = x/JULIA_SCALE;
|
u = x/JULIA_SCALE;
|
||||||
v = y/JULIA_SCALE;
|
v = y/JULIA_SCALE;
|
||||||
@@ -750,9 +929,8 @@ double x, y;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ij_in_billiard(i, j)
|
int ij_in_billiard(int i, int j)
|
||||||
/* returns 1 if (i,j) represents a point in the billiard */
|
/* returns 1 if (i,j) represents a point in the billiard */
|
||||||
int i, j;
|
|
||||||
{
|
{
|
||||||
double xy[2];
|
double xy[2];
|
||||||
|
|
||||||
@@ -811,31 +989,13 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
|
|
||||||
glLineWidth(2);
|
glLineWidth(2);
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glBegin(GL_LINE_LOOP);
|
|
||||||
for (i=0; i<=NSEG; i++)
|
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = x0 + r*cos(phi);
|
|
||||||
y = r*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(x0, 0.0, r, NSEG);
|
||||||
for (i=0; i<=NSEG; i++)
|
draw_circle(-x0, 0.0, r, NSEG);
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = -x0 + r*cos(phi);
|
|
||||||
y = r*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_STADIUM:
|
case (D_STADIUM):
|
||||||
{
|
{
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
for (i=0; i<=NSEG; i++)
|
for (i=0; i<=NSEG; i++)
|
||||||
@@ -857,21 +1017,12 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
glEnd();
|
glEnd();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_SINAI:
|
case (D_SINAI):
|
||||||
{
|
{
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(0.0, 0.0, LAMBDA, NSEG);
|
||||||
for (i=0; i<=NSEG; i++)
|
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = LAMBDA*cos(phi);
|
|
||||||
y = LAMBDA*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_DIAMOND:
|
case (D_DIAMOND):
|
||||||
{
|
{
|
||||||
alpha = atan(1.0 - 1.0/LAMBDA);
|
alpha = atan(1.0 - 1.0/LAMBDA);
|
||||||
dphi = (PID - 2.0*alpha)/(double)NSEG;
|
dphi = (PID - 2.0*alpha)/(double)NSEG;
|
||||||
@@ -936,26 +1087,8 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
}
|
}
|
||||||
case (D_ANNULUS):
|
case (D_ANNULUS):
|
||||||
{
|
{
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(0.0, 0.0, LAMBDA, NSEG);
|
||||||
for (i=0; i<=NSEG; i++)
|
draw_circle(0.0, 0.0, 1.0, NSEG);
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = LAMBDA*cos(phi);
|
|
||||||
y = LAMBDA*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
glBegin(GL_LINE_LOOP);
|
|
||||||
for (i=0; i<=NSEG; i++)
|
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = cos(phi);
|
|
||||||
y = sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (D_POLYGON):
|
case (D_POLYGON):
|
||||||
@@ -1008,27 +1141,18 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
glEnd();
|
glEnd();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_GRATING:
|
case (D_GRATING):
|
||||||
{
|
{
|
||||||
k1 = -(int)(-YMIN/LAMBDA);
|
k1 = -(int)(-YMIN/LAMBDA);
|
||||||
k2 = (int)(YMAX/LAMBDA);
|
k2 = (int)(YMAX/LAMBDA);
|
||||||
for (i=k1; i<= k2; i++)
|
for (i=k1; i<= k2; i++)
|
||||||
{
|
{
|
||||||
z = (double)i*LAMBDA;
|
z = (double)i*LAMBDA;
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(0.0, z, MU, NSEG);
|
||||||
for (j=0; j<=NSEG; j++)
|
|
||||||
{
|
|
||||||
phi = (double)j*DPI/(double)NSEG;
|
|
||||||
x = MU*cos(phi);
|
|
||||||
y = z + MU*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_EHRENFEST:
|
case (D_EHRENFEST):
|
||||||
{
|
{
|
||||||
alpha = asin(MU/LAMBDA);
|
alpha = asin(MU/LAMBDA);
|
||||||
x0 = 1.0 - sqrt(LAMBDA*LAMBDA - MU*MU);
|
x0 = 1.0 - sqrt(LAMBDA*LAMBDA - MU*MU);
|
||||||
@@ -1053,7 +1177,7 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
glEnd ();
|
glEnd ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_DISK_GRID:
|
case (D_DISK_GRID):
|
||||||
{
|
{
|
||||||
glLineWidth(2);
|
glLineWidth(2);
|
||||||
for (i = -NGRIDX/2; i < NGRIDX/2; i++)
|
for (i = -NGRIDX/2; i < NGRIDX/2; i++)
|
||||||
@@ -1063,20 +1187,11 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
dx = dy*0.5*sqrt(3.0);
|
dx = dy*0.5*sqrt(3.0);
|
||||||
x1 = ((double)i + 0.5)*dy;
|
x1 = ((double)i + 0.5)*dy;
|
||||||
y1 = YMIN + ((double)j + 0.5)*dy;
|
y1 = YMIN + ((double)j + 0.5)*dy;
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(x1, y1, MU, NSEG);
|
||||||
for (k=0; k<=NSEG; k++)
|
|
||||||
{
|
|
||||||
phi = (double)k*DPI/(double)NSEG;
|
|
||||||
x = x1 + MU*cos(phi);
|
|
||||||
y = y1 + MU*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case D_DISK_HEX:
|
case (D_DISK_HEX):
|
||||||
{
|
{
|
||||||
glLineWidth(2);
|
glLineWidth(2);
|
||||||
for (i = -NGRIDX/2; i < NGRIDX/2; i++)
|
for (i = -NGRIDX/2; i < NGRIDX/2; i++)
|
||||||
@@ -1086,16 +1201,7 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
x1 = ((double)i + 0.5)*dy;
|
x1 = ((double)i + 0.5)*dy;
|
||||||
y1 = YMIN + ((double)j + 0.5)*dy;
|
y1 = YMIN + ((double)j + 0.5)*dy;
|
||||||
if ((i+NGRIDX)%2 == 1) y1 += 0.5*dy;
|
if ((i+NGRIDX)%2 == 1) y1 += 0.5*dy;
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(x1, y1, MU, NSEG);
|
||||||
for (k=0; k<=NSEG; k++)
|
|
||||||
{
|
|
||||||
phi = (double)k*DPI/(double)NSEG;
|
|
||||||
x = x1 + MU*cos(phi);
|
|
||||||
y = y1 + MU*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1103,19 +1209,7 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
{
|
{
|
||||||
glLineWidth(BOUNDARY_WIDTH);
|
glLineWidth(BOUNDARY_WIDTH);
|
||||||
for (i = 0; i < ncircles; i++)
|
for (i = 0; i < ncircles; i++)
|
||||||
if (circleactive[i])
|
if (circleactive[i]) draw_circle(circlex[i], circley[i], circlerad[i], NSEG);
|
||||||
{
|
|
||||||
glBegin(GL_LINE_LOOP);
|
|
||||||
for (k=0; k<=NSEG; k++)
|
|
||||||
{
|
|
||||||
phi = (double)k*DPI/(double)NSEG;
|
|
||||||
x = circlex[i] + circlerad[i]*cos(phi);
|
|
||||||
y = circley[i] + circlerad[i]*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (D_MENGER):
|
case (D_MENGER):
|
||||||
@@ -1221,26 +1315,8 @@ void draw_billiard() /* draws the billiard boundary */
|
|||||||
}
|
}
|
||||||
case (D_ANNULUS_HEATED):
|
case (D_ANNULUS_HEATED):
|
||||||
{
|
{
|
||||||
glBegin(GL_LINE_LOOP);
|
draw_circle(MU, 0.0, LAMBDA, NSEG);
|
||||||
for (i=0; i<=NSEG; i++)
|
draw_circle(0.0, 0.0, 1.0, NSEG);
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = MU + LAMBDA*cos(phi);
|
|
||||||
y = LAMBDA*sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
glBegin(GL_LINE_LOOP);
|
|
||||||
for (i=0; i<=NSEG; i++)
|
|
||||||
{
|
|
||||||
phi = (double)i*DPI/(double)NSEG;
|
|
||||||
x = cos(phi);
|
|
||||||
y = sin(phi);
|
|
||||||
xy_to_pos(x, y, pos);
|
|
||||||
glVertex2d(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
glEnd ();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (D_MENGER_HEATED):
|
case (D_MENGER_HEATED):
|
||||||
|
|||||||
667
sub_wave_comp.c
Normal file
667
sub_wave_comp.c
Normal file
@@ -0,0 +1,667 @@
|
|||||||
|
/* some changes in sub_wave.c required by wave_comparison.c */
|
||||||
|
|
||||||
|
short int circletop[NMAXCIRCLES]; /* set to 1 if circle is in top half */
|
||||||
|
|
||||||
|
|
||||||
|
void init_circle_config_half(int pattern, int top)
|
||||||
|
/* initialise the arrays circlex, circley, circlerad and circleactive */
|
||||||
|
/* for billiard shape D_CIRCLES */
|
||||||
|
{
|
||||||
|
int i, j, n, ncirc0;
|
||||||
|
double dx, dy, p, phi, r, ra[5], sa[5], height, y = 0.0, gamma, ymean, ytop, ybottom;
|
||||||
|
|
||||||
|
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;
|
||||||
|
circlex[n] = ((double)(i-NGRIDX/2) + 0.5)*dy;
|
||||||
|
y = ((double)j + 0.5)*dy;
|
||||||
|
if (top) circley[n] = ymean + y;
|
||||||
|
else circley[n] = ymean - y;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
circleactive[n] = 1;
|
||||||
|
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++)
|
||||||
|
for (j = 0; j < NGRIDY/2+1; j++)
|
||||||
|
{
|
||||||
|
n = ncircles + (NGRIDY+1)*i/2 + j;
|
||||||
|
circlex[n] = ((double)(i-NGRIDX/2))*dy;
|
||||||
|
y = ((double)j - 0.5)*dy;
|
||||||
|
if ((i+NGRIDX)%2 == 1) y += 0.5*dy;
|
||||||
|
if (top) circley[n] = ymean + 0.5*dy + y;
|
||||||
|
else circley[n] = ymean - 0.5*dy - y;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
circleactive[n] = 1;
|
||||||
|
circletop[n] = top;
|
||||||
|
}
|
||||||
|
ncircles += NGRIDX*(NGRIDY+1)/2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
circlex[n] = ((double)(i-NGRIDX/2) + 0.5*((double)rand()/RAND_MAX - 0.5))*dy;
|
||||||
|
if (NGRIDX%2 == 0) circlex[n] += 0.5*dy;
|
||||||
|
y = ((double)j + 0.5 + 0.5*((double)rand()/RAND_MAX - 0.5))*dy;
|
||||||
|
if (top) circley[n] = ymean + y;
|
||||||
|
else circley[n] = ymean - y;
|
||||||
|
circlerad[n] = MU*sqrt(1.0 + 0.8*((double)rand()/RAND_MAX - 0.5));
|
||||||
|
circleactive[n] = 1;
|
||||||
|
circletop[n] = top;
|
||||||
|
printf("n = %i, x = %.3lg\n", n, circlex[n]);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
circlex[n] = ((double)(i-NGRIDX/2) + 0.5)*dy;
|
||||||
|
y = YMIN + ((double)j + 0.5)*dy;
|
||||||
|
if ( ((top)&&(y > 0.0))||((!top)&&(y <= 0.0)) )
|
||||||
|
circley[n] = y;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
p = (double)rand()/RAND_MAX;
|
||||||
|
if (p < P_PERCOL) circleactive[n] = 1;
|
||||||
|
else circleactive[n] = 0;
|
||||||
|
circletop[n] = top;
|
||||||
|
}
|
||||||
|
ncircles += NGRIDX*NGRIDY/2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_RAND_POISSON):
|
||||||
|
{
|
||||||
|
for (i = 0; i < NPOISSON/2; i++)
|
||||||
|
{
|
||||||
|
n = ncircles + i;
|
||||||
|
circlex[n] = LAMBDA*(2.0*(double)rand()/RAND_MAX - 1.0);
|
||||||
|
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)) )
|
||||||
|
circley[n] = y;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
circleactive[n] = 1;
|
||||||
|
circletop[n] = top;
|
||||||
|
printf("n = %i, x = %.3lg\n", n, circlex[n]);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
circlex[n] = r*cos(phi);
|
||||||
|
y = r*sin(phi);
|
||||||
|
if ( ((top)&&(y > 0.0))||((!top)&&(y <= 0.0)) )
|
||||||
|
circley[n] = y;
|
||||||
|
circlerad[n] = MU;
|
||||||
|
circleactive[n] = 1;
|
||||||
|
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];
|
||||||
|
circlex[n] = r*cos(phi);
|
||||||
|
circley[n] = r*sin(phi);
|
||||||
|
|
||||||
|
if (top) y = r*sin(phi);
|
||||||
|
else y = -r*sin(phi);
|
||||||
|
|
||||||
|
circley[n] = y;
|
||||||
|
|
||||||
|
circlerad[n] = LAMBDA*ra[j];
|
||||||
|
circleactive[n] = 1;
|
||||||
|
circletop[n] = top;
|
||||||
|
}
|
||||||
|
ncircles += 105;
|
||||||
|
|
||||||
|
/* add circle in the center */
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 2;
|
||||||
|
circletop[ncircles] = top;
|
||||||
|
ncircles += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
circlex[ncircles + n] = -LAMBDA + n*dx;
|
||||||
|
circley[ncircles + n] = y;
|
||||||
|
|
||||||
|
if (top)
|
||||||
|
{
|
||||||
|
y += height*gamma;
|
||||||
|
if (y > YMAX) y -= height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
y -= height*gamma;
|
||||||
|
if (y < YMIN) y += height;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
circlerad[ncircles + n] = MU;
|
||||||
|
circleactive[ncircles + n] = 1;
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
if (circley[ncirc0 + n] + circlerad[ncirc0 + n] > ytop)
|
||||||
|
{
|
||||||
|
circlex[ncircles] = circlex[ncirc0 + n];
|
||||||
|
circley[ncircles] = circley[ncirc0 + n] - height;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
ncircles ++;
|
||||||
|
}
|
||||||
|
else if (circley[ncirc0 + n] - circlerad[ncirc0 + n] < ybottom)
|
||||||
|
{
|
||||||
|
circlex[ncircles] = circlex[ncirc0 + n];
|
||||||
|
circley[ncircles] = circley[ncirc0 + n] + height;
|
||||||
|
circlerad[ncircles] = MU;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
ncircles ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_ONE):
|
||||||
|
{
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
if (top) circlerad[ncircles] = MU;
|
||||||
|
else circlerad[ncircles] = MUB;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
circletop[ncircles] = top;
|
||||||
|
ncircles += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_TWO):
|
||||||
|
{
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
if (top) circlerad[ncircles] = MU;
|
||||||
|
else circlerad[ncircles] = MUB;
|
||||||
|
circleactive[ncircles] = 2;
|
||||||
|
circletop[ncircles] = top;
|
||||||
|
ncircles += 1;
|
||||||
|
|
||||||
|
circlex[ncircles] = 0.0;
|
||||||
|
circley[ncircles] = 0.0;
|
||||||
|
if (top) circlerad[ncircles] = 2.0*MU;
|
||||||
|
else circlerad[ncircles] = 2.0*MUB;
|
||||||
|
circleactive[ncircles] = 1;
|
||||||
|
circletop[ncircles] = top;
|
||||||
|
ncircles += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (C_NOTHING):
|
||||||
|
{
|
||||||
|
ncircles += 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
printf("Function init_circle_config not defined for this pattern \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_circle_config_comp()
|
||||||
|
/* initialise the arrays circlex, circley, circlerad and circleactive */
|
||||||
|
/* for billiard shape D_CIRCLES */
|
||||||
|
{
|
||||||
|
ncircles = 0;
|
||||||
|
init_circle_config_half(CIRCLE_PATTERN, 1);
|
||||||
|
init_circle_config_half(CIRCLE_PATTERN_B, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
||||||
|
{
|
||||||
|
double l2, r2, r2mu, omega, c, angle, z, x1, y1, x2, y2, u, v, u1, v1, dx, dy;
|
||||||
|
int i, j, k, k1, k2, condition, type;
|
||||||
|
|
||||||
|
switch (domain) {
|
||||||
|
case D_MENGER:
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
case D_CIRCLES:
|
||||||
|
{
|
||||||
|
for (i = 0; i < ncircles; i++)
|
||||||
|
if (circleactive[i] != 0)
|
||||||
|
{
|
||||||
|
/* choose specific type according to value of circleactive[i] */
|
||||||
|
if (circleactive[i] == 1) type = 0;
|
||||||
|
else type = circleactive[i];
|
||||||
|
|
||||||
|
x1 = circlex[i];
|
||||||
|
y1 = circley[i];
|
||||||
|
r2 = circlerad[i]*circlerad[i];
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
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]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw_billiard_half(int domain, int pattern, int top) /* draws the billiard boundary */
|
||||||
|
/* two domain version implemented for D_CIRCLES */
|
||||||
|
{
|
||||||
|
double x0, x, y, x1, y1, dx, dy, phi, r = 0.01, pos[2], pos1[2], alpha, dphi, omega, z, l, signtop;
|
||||||
|
int i, j, k, k1, k2, mr2;
|
||||||
|
|
||||||
|
if (BLACK) glColor3f(1.0, 1.0, 1.0);
|
||||||
|
else glColor3f(0.0, 0.0, 0.0);
|
||||||
|
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++)
|
||||||
|
if ((circleactive[i])&&(circletop[i] == top))
|
||||||
|
{
|
||||||
|
glBegin(GL_LINE_STRIP);
|
||||||
|
for (k=0; k<=NSEG; k++)
|
||||||
|
{
|
||||||
|
phi = (double)k*DPI/(double)NSEG;
|
||||||
|
x = circlex[i] + circlerad[i]*cos(phi);
|
||||||
|
y = circley[i] + circlerad[i]*sin(phi);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
case (D_MANDELBROT):
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (D_MANDELBROT_CIRCLE):
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (D_JULIA):
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
printf("Function draw_billiard not defined for this billiard \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw_billiard_comp() /* draws the billiard boundary */
|
||||||
|
{
|
||||||
|
draw_billiard_half(B_DOMAIN, CIRCLE_PATTERN, 1);
|
||||||
|
draw_billiard_half(B_DOMAIN_B, CIRCLE_PATTERN_B, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw_wave_comp(double *phi[NX], double *psi[NX], short int *xy_in[NX], double scale, int time)
|
||||||
|
/* 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))
|
||||||
|
{
|
||||||
|
if (PLOT == P_AMPLITUDE)
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
double energy = 0.0, pos, xleft = XMAX, xright = XMIN;
|
||||||
|
static short int first = 1;
|
||||||
|
static int ileft, iright, jmid = NY/2;
|
||||||
|
|
||||||
|
if (first) /* compute box limits */
|
||||||
|
{
|
||||||
|
/* find leftmost and rightmost circle */
|
||||||
|
for (i=0; i<ncircles; i++)
|
||||||
|
if ((circleactive[i])&&(circlex[i] - circlerad[i] < xleft)) xleft = circlex[i] - circlerad[i];
|
||||||
|
for (i=0; i<ncircles; i++)
|
||||||
|
if ((circleactive[i])&&(circlex[i] + circlerad[i] > xright)) xright = circlex[i] + circlerad[i];
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* top left box */
|
||||||
|
for (i=0; i<ileft; i++)
|
||||||
|
for (j=jmid; j<NY; j++)
|
||||||
|
energy += compute_energy(phi, psi, xy_in, i, j);
|
||||||
|
energies[0] = energy;
|
||||||
|
|
||||||
|
/* top middle box */
|
||||||
|
energy = 0.0;
|
||||||
|
for (i=ileft; i<iright; i++)
|
||||||
|
for (j=jmid; j<NY; j++)
|
||||||
|
energy += compute_energy(phi, psi, xy_in, i, j);
|
||||||
|
energies[1] = energy;
|
||||||
|
|
||||||
|
/* top right box */
|
||||||
|
energy = 0.0;
|
||||||
|
for (i=iright; i<NX; i++)
|
||||||
|
for (j=jmid; j<NY; j++)
|
||||||
|
energy += compute_energy(phi, psi, xy_in, i, j);
|
||||||
|
energies[2] = energy;
|
||||||
|
|
||||||
|
/* bottom left box */
|
||||||
|
energy = 0.0;
|
||||||
|
for (i=0; i<ileft; i++)
|
||||||
|
for (j=0; j<jmid; j++)
|
||||||
|
energy += compute_energy(phi, psi, xy_in, i, j);
|
||||||
|
energies[3] = energy;
|
||||||
|
|
||||||
|
/* bottom middle box */
|
||||||
|
energy = 0.0;
|
||||||
|
for (i=ileft; i<iright; i++)
|
||||||
|
for (j=0; j<jmid; j++)
|
||||||
|
energy += compute_energy(phi, psi, xy_in, i, j);
|
||||||
|
energies[4] = energy;
|
||||||
|
|
||||||
|
/* bottom right box */
|
||||||
|
energy = 0.0;
|
||||||
|
for (i=iright; i<NX; i++)
|
||||||
|
for (j=0; j<jmid; j++)
|
||||||
|
energy += compute_energy(phi, psi, xy_in, i, j);
|
||||||
|
energies[5] = energy;
|
||||||
|
|
||||||
|
printf("Energies: %.5lg, %.5lg, %.5lg\n %.5lg, %.5lg, %.5lg\n", energies[0], energies[1], energies[2], energies[3], energies[4], energies[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_energies(double energies[6], double top_energy, double bottom_energy)
|
||||||
|
{
|
||||||
|
char message[50];
|
||||||
|
double ytop, ybot, pos[2], centerx = -0.075;
|
||||||
|
|
||||||
|
ytop = YMAX - 0.1;
|
||||||
|
ybot = -0.1;
|
||||||
|
// ybot = YMIN + 0.05;
|
||||||
|
|
||||||
|
erase_area(XMIN + 0.175, ytop + 0.025, 0.1, 0.05);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
sprintf(message, "%.3f", energies[0]/top_energy);
|
||||||
|
xy_to_pos(XMIN + 0.1, ytop, pos);
|
||||||
|
write_text(pos[0], pos[1], message);
|
||||||
|
|
||||||
|
erase_area(centerx + 0.075, ytop + 0.025, 0.1, 0.05);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
sprintf(message, "%.3f", energies[1]/top_energy);
|
||||||
|
xy_to_pos(centerx, ytop, pos);
|
||||||
|
write_text(pos[0], pos[1], message);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
sprintf(message, "%.5f", energies[2]/top_energy);
|
||||||
|
xy_to_pos(XMAX - 0.28, ytop, pos);
|
||||||
|
write_text(pos[0], pos[1], message);
|
||||||
|
|
||||||
|
erase_area(XMIN + 0.175, ybot + 0.025, 0.1, 0.05);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
sprintf(message, "%.3f", energies[3]/bottom_energy);
|
||||||
|
xy_to_pos(XMIN + 0.1, ybot, pos);
|
||||||
|
write_text(pos[0], pos[1], message);
|
||||||
|
|
||||||
|
erase_area(centerx + 0.075, ybot + 0.025, 0.1, 0.05);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
sprintf(message, "%.3f", energies[4]/bottom_energy);
|
||||||
|
xy_to_pos(centerx, ybot, pos);
|
||||||
|
write_text(pos[0], pos[1], message);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
sprintf(message, "%.5f", energies[5]/bottom_energy);
|
||||||
|
xy_to_pos(XMAX - 0.28, ybot, pos);
|
||||||
|
write_text(pos[0], pos[1], message);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
339
wave_billiard.c
339
wave_billiard.c
@@ -15,6 +15,9 @@
|
|||||||
/* gcc -o wave_billiard wave_billiard.c */
|
/* gcc -o wave_billiard wave_billiard.c */
|
||||||
/* -L/usr/X11R6/lib -ltiff -lm -lGL -lGLU -lX11 -lXmu -lglut -O3 -fopenmp */
|
/* -L/usr/X11R6/lib -ltiff -lm -lGL -lGLU -lX11 -lXmu -lglut -O3 -fopenmp */
|
||||||
/* */
|
/* */
|
||||||
|
/* OMP acceleration may be more effective after executing */
|
||||||
|
/* export OMP_NUM_THREADS=2 in the shell before running the program */
|
||||||
|
/* */
|
||||||
/* To make a video, set MOVIE to 1 and create subfolder tif_wave */
|
/* To make a video, set MOVIE to 1 and create subfolder tif_wave */
|
||||||
/* It may be possible to increase parameter PAUSE */
|
/* It may be possible to increase parameter PAUSE */
|
||||||
/* */
|
/* */
|
||||||
@@ -40,6 +43,7 @@
|
|||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
|
|
||||||
#define MOVIE 0 /* set to 1 to generate movie */
|
#define MOVIE 0 /* set to 1 to generate movie */
|
||||||
|
#define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */
|
||||||
|
|
||||||
/* General geometrical parameters */
|
/* General geometrical parameters */
|
||||||
|
|
||||||
@@ -58,24 +62,20 @@
|
|||||||
#define XMAX 2.0 /* x interval */
|
#define XMAX 2.0 /* x interval */
|
||||||
#define YMIN -1.125
|
#define YMIN -1.125
|
||||||
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */
|
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */
|
||||||
// #define XMIN -1.8
|
|
||||||
// #define XMAX 1.8 /* x interval */
|
|
||||||
// #define YMIN -1.0125
|
|
||||||
// #define YMAX 1.0125 /* y interval for 9/16 aspect ratio */
|
|
||||||
|
|
||||||
#define JULIA_SCALE 1.0 /* scaling for Julia sets */
|
#define JULIA_SCALE 1.0 /* scaling for Julia sets */
|
||||||
|
|
||||||
/* Choice of the billiard table */
|
/* Choice of the billiard table */
|
||||||
|
|
||||||
#define B_DOMAIN 3 /* choice of domain shape, see list in global_pdes.c */
|
#define B_DOMAIN 20 /* choice of domain shape, see list in global_pdes.c */
|
||||||
|
|
||||||
#define CIRCLE_PATTERN 4 /* pattern of circles, see list in global_pdes.c */
|
#define CIRCLE_PATTERN 11 /* pattern of circles, see list in global_pdes.c */
|
||||||
|
|
||||||
#define P_PERCOL 0.25 /* probability of having a circle in C_RAND_PERCOL arrangement */
|
#define P_PERCOL 0.25 /* probability of having a circle in C_RAND_PERCOL arrangement */
|
||||||
#define NPOISSON 300 /* number of points for Poisson C_RAND_POISSON arrangement */
|
#define NPOISSON 300 /* number of points for Poisson C_RAND_POISSON arrangement */
|
||||||
|
|
||||||
#define LAMBDA 0.75 /* parameter controlling the dimensions of domain */
|
#define LAMBDA 0.85 /* parameter controlling the dimensions of domain */
|
||||||
#define MU 0.025 /* parameter controlling the dimensions of domain */
|
#define MU 0.03 /* parameter controlling the dimensions of domain */
|
||||||
#define NPOLY 3 /* number of sides of polygon */
|
#define NPOLY 3 /* number of sides of polygon */
|
||||||
#define APOLY 1.0 /* angle by which to turn polygon, in units of Pi/2 */
|
#define APOLY 1.0 /* angle by which to turn polygon, in units of Pi/2 */
|
||||||
#define MDEPTH 4 /* depth of computation of Menger gasket */
|
#define MDEPTH 4 /* depth of computation of Menger gasket */
|
||||||
@@ -91,16 +91,21 @@
|
|||||||
|
|
||||||
/* Physical parameters of wave equation */
|
/* Physical parameters of wave equation */
|
||||||
|
|
||||||
#define TWOSPEEDS 1 /* set to 1 to replace hardcore boundary by medium with different speed */
|
#define TWOSPEEDS 0 /* set to 1 to replace hardcore boundary by medium with different speed */
|
||||||
|
#define OSCILLATE_LEFT 0 /* set to 1 to add oscilating boundary condition on the left */
|
||||||
|
#define OSCILLATE_TOPBOT 0 /* set to 1 to enforce a planar wave on top and bottom boundary */
|
||||||
|
|
||||||
#define OMEGA 0.9 /* frequency of periodic excitation */
|
#define OMEGA 0.002 /* frequency of periodic excitation */
|
||||||
#define COURANT 0.01 /* Courant number */
|
#define AMPLITUDE 1.0 /* amplitude of periodic excitation */
|
||||||
#define COURANTB 0.003 /* Courant number in medium B */
|
#define COURANT 0.02 /* Courant number */
|
||||||
|
#define COURANTB 0.01 /* Courant number in medium B */
|
||||||
#define GAMMA 0.0 /* damping factor in wave equation */
|
#define GAMMA 0.0 /* damping factor in wave equation */
|
||||||
#define GAMMA_BC 1.0e-4 /* damping factor on boundary */
|
#define GAMMAB 1.0e-6 /* damping factor in wave equation */
|
||||||
// #define GAMMA 5.0e-10 /* damping factor in wave equation */
|
#define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */
|
||||||
|
#define GAMMA_TOPBOT 1.0e-6 /* damping factor on boundary */
|
||||||
#define KAPPA 0.0 /* "elasticity" term enforcing oscillations */
|
#define KAPPA 0.0 /* "elasticity" term enforcing oscillations */
|
||||||
#define KAPPA_BC 5.0e-4 /* "elasticity" term on absorbing boundary */
|
#define KAPPA_SIDES 5.0e-4 /* "elasticity" term on absorbing boundary */
|
||||||
|
#define KAPPA_TOPBOT 0.0 /* "elasticity" term on absorbing boundary */
|
||||||
/* The Courant number is given by c*DT/DX, where DT is the time step and DX the lattice spacing */
|
/* The Courant number is given by c*DT/DX, where DT is the time step and DX the lattice spacing */
|
||||||
/* The physical damping coefficient is given by GAMMA/(DT)^2 */
|
/* The physical damping coefficient is given by GAMMA/(DT)^2 */
|
||||||
/* Increasing COURANT speeds up the simulation, but decreases accuracy */
|
/* Increasing COURANT speeds up the simulation, but decreases accuracy */
|
||||||
@@ -112,10 +117,11 @@
|
|||||||
|
|
||||||
/* Parameters for length and speed of simulation */
|
/* Parameters for length and speed of simulation */
|
||||||
|
|
||||||
#define NSTEPS 7000 /* number of frames of movie */
|
#define NSTEPS 3000 /* number of frames of movie */
|
||||||
#define NVID 50 /* number of iterations between images displayed on screen */
|
#define NVID 20 /* number of iterations between images displayed on screen */
|
||||||
#define NSEG 100 /* number of segments of boundary */
|
#define NSEG 100 /* number of segments of boundary */
|
||||||
#define INITIAL_TIME 200 /* time after which to start saving frames */
|
#define INITIAL_TIME 250 /* time after which to start saving frames */
|
||||||
|
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */
|
||||||
|
|
||||||
#define PAUSE 1000 /* number of frames after which to pause */
|
#define PAUSE 1000 /* number of frames after which to pause */
|
||||||
#define PSLEEP 1 /* sleep time during pause */
|
#define PSLEEP 1 /* sleep time during pause */
|
||||||
@@ -124,7 +130,9 @@
|
|||||||
|
|
||||||
/* Plot type, see list in global_pdes.c */
|
/* Plot type, see list in global_pdes.c */
|
||||||
|
|
||||||
#define PLOT 1
|
#define PLOT 0
|
||||||
|
|
||||||
|
#define PLOT_B 1 /* plot type for second movie */
|
||||||
|
|
||||||
/* Color schemes */
|
/* Color schemes */
|
||||||
|
|
||||||
@@ -133,10 +141,10 @@
|
|||||||
#define COLOR_SCHEME 1 /* choice of color scheme, see list in global_pdes.c */
|
#define COLOR_SCHEME 1 /* choice of color scheme, see list in global_pdes.c */
|
||||||
|
|
||||||
#define SCALE 0 /* set to 1 to adjust color scheme to variance of field */
|
#define SCALE 0 /* set to 1 to adjust color scheme to variance of field */
|
||||||
#define SLOPE 1.0 /* sensitivity of color on wave amplitude */
|
#define SLOPE 1.5 /* sensitivity of color on wave amplitude */
|
||||||
// #define SLOPE 0.5 /* sensitivity of color on wave amplitude */
|
|
||||||
#define ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */
|
#define ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */
|
||||||
#define E_SCALE 750.0 /* scaling factor for energy representation */
|
#define E_SCALE 2000.0 /* scaling factor for energy representation */
|
||||||
|
// #define E_SCALE 2500.0 /* scaling factor for energy representation */
|
||||||
|
|
||||||
#define COLORHUE 260 /* initial hue of water color for scheme C_LUM */
|
#define COLORHUE 260 /* initial hue of water color for scheme C_LUM */
|
||||||
#define COLORDRIFT 0.0 /* how much the color hue drifts during the whole simulation */
|
#define COLORDRIFT 0.0 /* how much the color hue drifts during the whole simulation */
|
||||||
@@ -144,199 +152,34 @@
|
|||||||
#define LUMAMP 0.3 /* amplitude of luminosity variation for scheme C_LUM */
|
#define LUMAMP 0.3 /* amplitude of luminosity variation for scheme C_LUM */
|
||||||
#define HUEMEAN 220.0 /* mean value of hue for color scheme C_HUE */
|
#define HUEMEAN 220.0 /* mean value of hue for color scheme C_HUE */
|
||||||
#define HUEAMP -220.0 /* amplitude of variation of hue for color scheme C_HUE */
|
#define HUEAMP -220.0 /* amplitude of variation of hue for color scheme C_HUE */
|
||||||
// #define HUEMEAN 320.0 /* mean value of hue for color scheme C_HUE */
|
|
||||||
// #define HUEAMP 100.0 /* amplitude of variation of hue for color scheme C_HUE */
|
/* For debugging purposes only */
|
||||||
|
#define FLOOR 0 /* set to 1 to limit wave amplitude to VMAX */
|
||||||
|
#define VMAX 10.0 /* max value of wave amplitude */
|
||||||
|
|
||||||
|
|
||||||
#include "global_pdes.c"
|
#include "global_pdes.c" /* constants and global variables */
|
||||||
#include "sub_wave.c"
|
#include "sub_wave.c" /* common functions for wave_billiard, heat and schrodinger */
|
||||||
|
#include "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
|
||||||
|
|
||||||
|
|
||||||
double courant2, courantb2; /* Courant parameters squared */
|
double courant2, courantb2; /* Courant parameters squared */
|
||||||
|
|
||||||
void init_wave(x, y, phi, psi, xy_in)
|
|
||||||
/* initialise field with drop at (x,y) - phi is wave height, psi is phi at time t-1 */
|
|
||||||
double x, y, *phi[NX], *psi[NX]; short int * xy_in[NX];
|
|
||||||
|
|
||||||
{
|
|
||||||
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] = 0.2*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01);
|
|
||||||
else phi[i][j] = 0.0;
|
|
||||||
psi[i][j] = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_planar_wave(x, y, phi, psi, xy_in)
|
|
||||||
/* 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 */
|
|
||||||
double x, y, *phi[NX], *psi[NX]; short int * xy_in[NX];
|
|
||||||
|
|
||||||
{
|
|
||||||
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(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(phi, psi, xy_in)
|
|
||||||
/* initialise flat field - phi is wave height, psi is phi at time t-1 */
|
|
||||||
double *phi[NX], *psi[NX]; short int * xy_in[NX];
|
|
||||||
|
|
||||||
{
|
|
||||||
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(xy[0],xy[1]);
|
|
||||||
phi[i][j] = 0.0;
|
|
||||||
psi[i][j] = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_drop_to_wave(factor, x, y, phi, psi)
|
|
||||||
/* add drop at (x,y) to the field with given prefactor */
|
|
||||||
double factor, x, y, *phi[NX], *psi[NX];
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
phi[i][j] += 0.2*factor*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void oscillate_linear_wave(amplitude, t, x1, y1, x2, y2, phi, psi)
|
|
||||||
/* oscillating boundary condition at (x,y), beta version */
|
|
||||||
double amplitude, t, x1, y1, x2, y2, *phi[NX], *psi[NX];
|
|
||||||
{
|
|
||||||
int i, j, ij1[2], ij2[2], imin, imax, jmin, jmax, d = 5;
|
|
||||||
double xy[2], dist2;
|
|
||||||
|
|
||||||
xy_to_ij(x1, y1, ij1);
|
|
||||||
xy_to_ij(x2, y2, ij2);
|
|
||||||
imin = ij1[0] - d; if (imin < 0) imin = 0;
|
|
||||||
imax = ij2[0] + d; if (imax >= 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
/* animation part */
|
/* animation part */
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
double compute_energy(phi, psi, xy_in, i, j)
|
|
||||||
double *phi[NX], *psi[NX];
|
|
||||||
short int *xy_in[NX];
|
|
||||||
int i, j;
|
|
||||||
{
|
|
||||||
double velocity, energy, gradientx2, gradienty2;
|
|
||||||
int iplus, iminus, jplus, jminus;
|
|
||||||
|
|
||||||
velocity = (phi[i][j] - psi[i][j]);
|
void evolve_wave_half(double *phi_in[NX], double *psi_in[NX], double *phi_out[NX], double *psi_out[NX],
|
||||||
|
short int *xy_in[NX])
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void draw_wave(phi, psi, xy_in, scale, time)
|
|
||||||
/* draw the field */
|
|
||||||
double *phi[NX], *psi[NX], scale;
|
|
||||||
short int *xy_in[NX];
|
|
||||||
int time;
|
|
||||||
{
|
|
||||||
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]))
|
|
||||||
{
|
|
||||||
if (PLOT == P_AMPLITUDE)
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
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 evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
|
||||||
/* time step of field evolution */
|
/* time step of field evolution */
|
||||||
/* phi is value of field at time t, psi at time t-1 */
|
/* phi is value of field at time t, psi at time t-1 */
|
||||||
double *phi_in[NX], *psi_in[NX], *phi_out[NX], *psi_out[NX]; short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
int i, j, iplus, iminus, jplus, jminus;
|
int i, j, iplus, iminus, jplus, jminus;
|
||||||
double delta, x, y, c, cc;
|
double delta, x, y, c, cc, gamma;
|
||||||
|
static long time = 0;
|
||||||
|
|
||||||
|
time++;
|
||||||
|
|
||||||
// c = COURANT;
|
// c = COURANT;
|
||||||
// cc = courant2;
|
// cc = courant2;
|
||||||
@@ -348,11 +191,13 @@ void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
|||||||
{
|
{
|
||||||
c = COURANT;
|
c = COURANT;
|
||||||
cc = courant2;
|
cc = courant2;
|
||||||
|
gamma = GAMMA;
|
||||||
}
|
}
|
||||||
else if (TWOSPEEDS)
|
else if (TWOSPEEDS)
|
||||||
{
|
{
|
||||||
c = COURANTB;
|
c = COURANTB;
|
||||||
cc = courantb2;
|
cc = courantb2;
|
||||||
|
gamma = GAMMAB;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((TWOSPEEDS)||(xy_in[i][j])){
|
if ((TWOSPEEDS)||(xy_in[i][j])){
|
||||||
@@ -381,6 +226,14 @@ void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
|||||||
jminus = (j-1) % NY;
|
jminus = (j-1) % NY;
|
||||||
if (jminus < 0) jminus += NY;
|
if (jminus < 0) jminus += NY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* imposing linear wave on top and bottom by making Laplacian 1d */
|
||||||
|
if (OSCILLATE_TOPBOT)
|
||||||
|
{
|
||||||
|
if (j == NY-1) jminus = NY-1;
|
||||||
|
else if (j == 0) jplus = 0;
|
||||||
|
}
|
||||||
|
|
||||||
delta = phi_in[iplus][j] + phi_in[iminus][j] + phi_in[i][jplus] + phi_in[i][jminus] - 4.0*phi_in[i][j];
|
delta = phi_in[iplus][j] + phi_in[iminus][j] + phi_in[i][jplus] + phi_in[i][jminus] - 4.0*phi_in[i][j];
|
||||||
|
|
||||||
x = phi_in[i][j];
|
x = phi_in[i][j];
|
||||||
@@ -388,43 +241,47 @@ void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
|||||||
|
|
||||||
/* evolve phi */
|
/* evolve phi */
|
||||||
if ((B_COND == BC_PERIODIC)||(B_COND == BC_DIRICHLET))
|
if ((B_COND == BC_PERIODIC)||(B_COND == BC_DIRICHLET))
|
||||||
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - GAMMA*(x-y);
|
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - gamma*(x-y);
|
||||||
else if (B_COND == BC_ABSORBING)
|
else if (B_COND == BC_ABSORBING)
|
||||||
{
|
{
|
||||||
if ((i>0)&&(i<NX-1)&&(j>0)&&(j<NY-1))
|
if ((i>0)&&(i<NX-1)&&(j>0)&&(j<NY-1))
|
||||||
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - gamma*(x-y);
|
||||||
|
|
||||||
/* upper border */
|
/* upper border */
|
||||||
else if (j==NY-1)
|
else if (j==NY-1)
|
||||||
phi_out[i][j] = x - c*(x - phi_in[i][NY-2]) - KAPPA_BC*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = x - c*(x - phi_in[i][NY-2]) - KAPPA_TOPBOT*x - GAMMA_TOPBOT*(x-y);
|
||||||
|
|
||||||
/* lower border */
|
/* lower border */
|
||||||
else if (j==0)
|
else if (j==0)
|
||||||
phi_out[i][j] = x - c*(x - phi_in[i][1]) - KAPPA_BC*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = x - c*(x - phi_in[i][1]) - KAPPA_TOPBOT*x - GAMMA_TOPBOT*(x-y);
|
||||||
|
|
||||||
/* right border */
|
/* right border */
|
||||||
if (i==NX-1)
|
if (i==NX-1)
|
||||||
phi_out[i][j] = x - c*(x - phi_in[NX-2][j]) - KAPPA_BC*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = x - c*(x - phi_in[NX-2][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
|
|
||||||
/* left border */
|
/* left border */
|
||||||
else if (i==0)
|
else if (i==0)
|
||||||
phi_out[i][j] = x - c*(x - phi_in[1][j]) - KAPPA_BC*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = x - c*(x - phi_in[1][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
}
|
}
|
||||||
else if (B_COND == BC_VPER_HABS)
|
else if (B_COND == BC_VPER_HABS)
|
||||||
{
|
{
|
||||||
if ((i>0)&&(i<NX-1))
|
if ((i>0)&&(i<NX-1))
|
||||||
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - GAMMA*(x-y);
|
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - gamma*(x-y);
|
||||||
|
|
||||||
/* right border */
|
/* right border */
|
||||||
else if (i==NX-1)
|
else if (i==NX-1)
|
||||||
phi_out[i][j] = x - c*(x - phi_in[NX-2][j]) - KAPPA_BC*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = x - c*(x - phi_in[NX-2][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
|
|
||||||
/* left border */
|
/* left border */
|
||||||
else if (i==0)
|
else if (i==0)
|
||||||
phi_out[i][j] = x - c*(x - phi_in[1][j]) - KAPPA_BC*x - GAMMA_BC*(x-y);
|
phi_out[i][j] = x - c*(x - phi_in[1][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
}
|
}
|
||||||
psi_out[i][j] = x;
|
psi_out[i][j] = x;
|
||||||
|
|
||||||
|
/* add oscillating boundary condition on the left */
|
||||||
|
if ((i == 0)&&(OSCILLATE_LEFT)) phi_out[i][j] = AMPLITUDE*cos((double)time*OMEGA);
|
||||||
|
psi_out[i][j] = x;
|
||||||
|
|
||||||
if (FLOOR)
|
if (FLOOR)
|
||||||
{
|
{
|
||||||
if (phi_out[i][j] > VMAX) phi_out[i][j] = VMAX;
|
if (phi_out[i][j] > VMAX) phi_out[i][j] = VMAX;
|
||||||
@@ -439,46 +296,22 @@ void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void evolve_wave(phi, psi, phi_tmp, psi_tmp, xy_in)
|
void evolve_wave(double *phi[NX], double *psi[NX], double *phi_tmp[NX], double *psi_tmp[NX], short int *xy_in[NX])
|
||||||
/* time step of field evolution */
|
/* time step of field evolution */
|
||||||
/* phi is value of field at time t, psi at time t-1 */
|
/* phi is value of field at time t, psi at time t-1 */
|
||||||
double *phi[NX], *psi[NX], *phi_tmp[NX], *psi_tmp[NX]; short int *xy_in[NX];
|
|
||||||
{
|
{
|
||||||
evolve_wave_half(phi, psi, phi_tmp, psi_tmp, xy_in);
|
evolve_wave_half(phi, psi, phi_tmp, psi_tmp, xy_in);
|
||||||
evolve_wave_half(phi_tmp, psi_tmp, phi, psi, xy_in);
|
evolve_wave_half(phi_tmp, psi_tmp, phi, psi, xy_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double compute_variance(phi, psi, xy_in)
|
|
||||||
/* compute the variance of the field, to adjust color scheme */
|
|
||||||
double *phi[NX], *psi[NX]; short int * xy_in[NX];
|
|
||||||
{
|
|
||||||
int i, j, n = 0;
|
|
||||||
double variance = 0.0;
|
|
||||||
|
|
||||||
for (i=1; i<NX; i++)
|
|
||||||
for (j=1; j<NY; j++)
|
|
||||||
{
|
|
||||||
if (xy_in[i][j])
|
|
||||||
{
|
|
||||||
n++;
|
|
||||||
variance += phi[i][j]*phi[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (n==0) n=1;
|
|
||||||
return(variance/(double)n);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void animation()
|
void animation()
|
||||||
{
|
{
|
||||||
double time, scale;
|
double time, scale;
|
||||||
double *phi[NX], *psi[NX], *phi_tmp[NX], *psi_tmp[NX];
|
double *phi[NX], *psi[NX], *phi_tmp[NX], *psi_tmp[NX];
|
||||||
short int *xy_in[NX];
|
short int *xy_in[NX];
|
||||||
int i, j, s;
|
int i, j, s;
|
||||||
|
static int counter = 0;
|
||||||
|
|
||||||
/* Since NX and NY are big, it seemed wiser to use some memory allocation here */
|
/* Since NX and NY are big, it seemed wiser to use some memory allocation here */
|
||||||
for (i=0; i<NX; i++)
|
for (i=0; i<NX; i++)
|
||||||
@@ -497,8 +330,11 @@ void animation()
|
|||||||
courantb2 = COURANTB*COURANTB;
|
courantb2 = COURANTB*COURANTB;
|
||||||
|
|
||||||
/* initialize wave with a drop at one point, zero elsewhere */
|
/* initialize wave with a drop at one point, zero elsewhere */
|
||||||
init_planar_wave(XMIN + 0.01, 0.0, phi, psi, xy_in);
|
// init_wave_flat(phi, psi, xy_in);
|
||||||
// init_planar_wave(XMIN + 1.0, 0.0, phi, psi, xy_in);
|
|
||||||
|
init_planar_wave(XMIN + 0.015, 0.0, phi, psi, xy_in);
|
||||||
|
// init_planar_wave(XMIN + 0.02, 0.0, phi, psi, xy_in);
|
||||||
|
// init_planar_wave(XMIN + 0.8, 0.0, phi, psi, xy_in);
|
||||||
// init_wave(-1.5, 0.0, phi, psi, xy_in);
|
// init_wave(-1.5, 0.0, phi, psi, xy_in);
|
||||||
// init_wave(0.0, 0.0, phi, psi, xy_in);
|
// init_wave(0.0, 0.0, phi, psi, xy_in);
|
||||||
|
|
||||||
@@ -509,7 +345,7 @@ void animation()
|
|||||||
|
|
||||||
blank();
|
blank();
|
||||||
glColor3f(0.0, 0.0, 0.0);
|
glColor3f(0.0, 0.0, 0.0);
|
||||||
draw_wave(phi, psi, xy_in, 1.0, 0);
|
draw_wave(phi, psi, xy_in, 1.0, 0, PLOT);
|
||||||
draw_billiard();
|
draw_billiard();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
@@ -530,7 +366,7 @@ void animation()
|
|||||||
}
|
}
|
||||||
else scale = 1.0;
|
else scale = 1.0;
|
||||||
|
|
||||||
draw_wave(phi, psi, xy_in, scale, i);
|
draw_wave(phi, psi, xy_in, scale, i, PLOT);
|
||||||
for (j=0; j<NVID; j++)
|
for (j=0; j<NVID; j++)
|
||||||
{
|
{
|
||||||
evolve_wave(phi, psi, phi_tmp, psi_tmp, xy_in);
|
evolve_wave(phi, psi, phi_tmp, psi_tmp, xy_in);
|
||||||
@@ -547,6 +383,15 @@ void animation()
|
|||||||
if (i >= INITIAL_TIME) save_frame();
|
if (i >= INITIAL_TIME) save_frame();
|
||||||
else printf("Initial phase time %i of %i\n", i, INITIAL_TIME);
|
else printf("Initial phase time %i of %i\n", i, INITIAL_TIME);
|
||||||
|
|
||||||
|
if ((i >= INITIAL_TIME)&&(DOUBLE_MOVIE))
|
||||||
|
{
|
||||||
|
draw_wave(phi, psi, xy_in, scale, i, PLOT_B);
|
||||||
|
draw_billiard();
|
||||||
|
glutSwapBuffers();
|
||||||
|
save_frame_counter(NSTEPS + 21 + counter);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
/* it seems that saving too many files too fast can cause trouble with the file system */
|
/* it seems that saving too many files too fast can cause trouble with the file system */
|
||||||
/* so this is to make a pause from time to time - parameter PAUSE may need adjusting */
|
/* so this is to make a pause from time to time - parameter PAUSE may need adjusting */
|
||||||
if (i % PAUSE == PAUSE - 1)
|
if (i % PAUSE == PAUSE - 1)
|
||||||
@@ -561,7 +406,21 @@ void animation()
|
|||||||
|
|
||||||
if (MOVIE)
|
if (MOVIE)
|
||||||
{
|
{
|
||||||
|
if (DOUBLE_MOVIE)
|
||||||
|
{
|
||||||
|
draw_wave(phi, psi, xy_in, scale, i, PLOT);
|
||||||
|
draw_billiard();
|
||||||
|
glutSwapBuffers();
|
||||||
|
}
|
||||||
for (i=0; i<20; i++) save_frame();
|
for (i=0; i<20; i++) save_frame();
|
||||||
|
if (DOUBLE_MOVIE)
|
||||||
|
{
|
||||||
|
draw_wave(phi, psi, xy_in, scale, i, PLOT_B);
|
||||||
|
draw_billiard();
|
||||||
|
glutSwapBuffers();
|
||||||
|
for (i=0; i<20; i++) save_frame_counter(NSTEPS + 21 + counter + i);
|
||||||
|
}
|
||||||
|
|
||||||
s = system("mv wave*.tif tif_wave/");
|
s = system("mv wave*.tif tif_wave/");
|
||||||
}
|
}
|
||||||
for (i=0; i<NX; i++)
|
for (i=0; i<NX; i++)
|
||||||
|
|||||||
222
wave_common.c
Normal file
222
wave_common.c
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
/* 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; 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 */
|
||||||
|
{
|
||||||
|
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] = 0.2*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01);
|
||||||
|
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 */
|
||||||
|
/* 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(xy[0],xy[1]);
|
||||||
|
|
||||||
|
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.0005)*cos(-sqrt(dist2)/0.01);
|
||||||
|
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.0005)*cos(-sqrt(dist2)/0.02);
|
||||||
|
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.005)*cos(-sqrt(dist2)/0.02);
|
||||||
|
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.01)*cos(-sqrt(dist2)/0.02);
|
||||||
|
if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.0005)*cos(-sqrt(dist2)/0.01);
|
||||||
|
// if ((xy_in[i][j])||(TWOSPEEDS)) phi[i][j] = 0.01*exp(-dist2/0.05)*cos(-sqrt(dist2)/0.025);
|
||||||
|
else phi[i][j] = 0.0;
|
||||||
|
psi[i][j] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_wave_flat( 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(xy[0],xy[1]);
|
||||||
|
phi[i][j] = 0.0;
|
||||||
|
psi[i][j] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
phi[i][j] += 0.2*factor*exp(-dist2/0.001)*cos(-sqrt(dist2)/0.01);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void oscillate_linear_wave(double amplitude, double t, double x1, double y1, double x2, double y2, double *phi[NX],
|
||||||
|
double *psi[NX])
|
||||||
|
/* oscillating boundary condition at (x,y), beta version */
|
||||||
|
{
|
||||||
|
int i, j, ij1[2], ij2[2], imin, imax, jmin, jmax, d = 5;
|
||||||
|
double xy[2], dist2;
|
||||||
|
|
||||||
|
xy_to_ij(x1, y1, ij1);
|
||||||
|
xy_to_ij(x2, y2, ij2);
|
||||||
|
imin = ij1[0] - d; if (imin < 0) imin = 0;
|
||||||
|
imax = ij2[0] + d; if (imax >= 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<NX; i++)
|
||||||
|
for (j=1; j<NY; j++)
|
||||||
|
{
|
||||||
|
if (xy_in[i][j])
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
variance += phi[i][j]*phi[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n==0) n=1;
|
||||||
|
return(variance/(double)n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double compute_dissipation(double *phi[NX], double *psi[NX], short int *xy_in[NX], double x, double y)
|
||||||
|
{
|
||||||
|
double velocity;
|
||||||
|
int ij[2];
|
||||||
|
|
||||||
|
xy_to_ij(x, y, ij);
|
||||||
|
|
||||||
|
velocity = (phi[ij[0]][ij[1]] - psi[ij[0]][ij[1]]);
|
||||||
|
|
||||||
|
return(velocity*velocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw_wave(double *phi[NX], double *psi[NX], short int *xy_in[NX], double scale, int time, int plot)
|
||||||
|
/* draw the field */
|
||||||
|
{
|
||||||
|
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]))
|
||||||
|
{
|
||||||
|
if (plot == P_AMPLITUDE)
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
glColor3f(rgb[0], rgb[1], rgb[2]);
|
||||||
|
|
||||||
|
glVertex2i(i, j);
|
||||||
|
glVertex2i(i+1, j);
|
||||||
|
glVertex2i(i+1, j+1);
|
||||||
|
glVertex2i(i, j+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnd ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
486
wave_comparison.c
Normal file
486
wave_comparison.c
Normal file
@@ -0,0 +1,486 @@
|
|||||||
|
/*********************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Animation of wave equation in a planar domain */
|
||||||
|
/* */
|
||||||
|
/* N. Berglund, december 2012, may 2021 */
|
||||||
|
/* */
|
||||||
|
/* UPDATE 24/04: distinction between damping and "elasticity" parameters */
|
||||||
|
/* UPDATE 27/04: new billiard shapes, bug in color scheme fixed */
|
||||||
|
/* UPDATE 28/04: code made more efficient, with help of Marco Mancini */
|
||||||
|
/* */
|
||||||
|
/* Feel free to reuse, but if doing so it would be nice to drop a */
|
||||||
|
/* line to nils.berglund@univ-orleans.fr - Thanks! */
|
||||||
|
/* */
|
||||||
|
/* compile with */
|
||||||
|
/* gcc -o wave_billiard wave_billiard.c */
|
||||||
|
/* -L/usr/X11R6/lib -ltiff -lm -lGL -lGLU -lX11 -lXmu -lglut -O3 -fopenmp */
|
||||||
|
/* */
|
||||||
|
/* OMP acceleration may be more effective after executing */
|
||||||
|
/* export OMP_NUM_THREADS=2 in the shell before running the program */
|
||||||
|
/* */
|
||||||
|
/* To make a video, set MOVIE to 1 and create subfolder tif_wave */
|
||||||
|
/* It may be possible to increase parameter PAUSE */
|
||||||
|
/* */
|
||||||
|
/* create movie using */
|
||||||
|
/* ffmpeg -i wave.%05d.tif -vcodec libx264 wave.mp4 */
|
||||||
|
/* */
|
||||||
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* NB: The algorithm used to simulate the wave equation is highly paralellizable */
|
||||||
|
/* One could make it much faster by using a GPU */
|
||||||
|
/* */
|
||||||
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <GL/glut.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <tiffio.h> /* Sam Leffler's libtiff library. */
|
||||||
|
#include <omp.h>
|
||||||
|
|
||||||
|
#define MOVIE 0 /* set to 1 to generate movie */
|
||||||
|
|
||||||
|
#define WINWIDTH 1280 /* window width */
|
||||||
|
#define WINHEIGHT 720 /* window height */
|
||||||
|
|
||||||
|
#define NX 1280 /* number of grid points on x axis */
|
||||||
|
#define NY 720 /* number of grid points on y axis */
|
||||||
|
|
||||||
|
#define XMIN -2.0
|
||||||
|
#define XMAX 2.0 /* x interval */
|
||||||
|
#define YMIN -1.125
|
||||||
|
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */
|
||||||
|
|
||||||
|
#define JULIA_SCALE 1.0 /* scaling for Julia sets */
|
||||||
|
|
||||||
|
/* Choice of the billiard table */
|
||||||
|
|
||||||
|
#define B_DOMAIN 20 /* choice of domain shape, see list in global_pdes.c */
|
||||||
|
#define B_DOMAIN_B 20 /* choice of domain shape, see list in global_pdes.c */
|
||||||
|
|
||||||
|
#define CIRCLE_PATTERN 1 /* pattern of circles, see list in global_pdes.c */
|
||||||
|
#define CIRCLE_PATTERN_B 10 /* pattern of circles, see list in global_pdes.c */
|
||||||
|
|
||||||
|
#define P_PERCOL 0.25 /* probability of having a circle in C_RAND_PERCOL arrangement */
|
||||||
|
#define NPOISSON 300 /* number of points for Poisson C_RAND_POISSON arrangement */
|
||||||
|
|
||||||
|
#define LAMBDA 0.8 /* parameter controlling the dimensions of domain */
|
||||||
|
#define MU 0.03 /* parameter controlling the dimensions of domain */
|
||||||
|
#define MUB 0.03 /* parameter controlling the dimensions of domain */
|
||||||
|
#define NPOLY 3 /* number of sides of polygon */
|
||||||
|
#define APOLY 1.0 /* angle by which to turn polygon, in units of Pi/2 */
|
||||||
|
#define MDEPTH 4 /* depth of computation of Menger gasket */
|
||||||
|
#define MRATIO 3 /* ratio defining Menger gasket */
|
||||||
|
#define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */
|
||||||
|
#define MANDELLIMIT 10.0 /* limit value for approximation of Mandelbrot set */
|
||||||
|
#define FOCI 1 /* set to 1 to draw focal points of ellipse */
|
||||||
|
#define NGRIDX 15 /* number of grid point for grid of disks */
|
||||||
|
#define NGRIDY 20 /* number of grid point for grid of disks */
|
||||||
|
|
||||||
|
/* You can add more billiard tables by adapting the functions */
|
||||||
|
/* xy_in_billiard and draw_billiard below */
|
||||||
|
|
||||||
|
/* Physical parameters of wave equation */
|
||||||
|
|
||||||
|
#define TWOSPEEDS 0 /* set to 1 to replace hardcore boundary by medium with different speed */
|
||||||
|
#define OSCILLATE_LEFT 0 /* set to 1 to add oscilating boundary condition on the left */
|
||||||
|
#define OSCILLATE_TOPBOT 0 /* set to 1 to enforce a planar wave on top and bottom boundary */
|
||||||
|
|
||||||
|
#define OMEGA 0.0035 /* frequency of periodic excitation */
|
||||||
|
#define AMPLITUDE 1.0 /* amplitude of periodic excitation */
|
||||||
|
#define COURANT 0.02 /* Courant number */
|
||||||
|
#define COURANTB 0.0075 /* Courant number in medium B */
|
||||||
|
#define GAMMA 0.0 /* damping factor in wave equation */
|
||||||
|
#define GAMMAB 1.0e-5 /* damping factor in wave equation */
|
||||||
|
#define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */
|
||||||
|
#define GAMMA_TOPBOT 1.0e-6 /* damping factor on boundary */
|
||||||
|
#define KAPPA 0.0 /* "elasticity" term enforcing oscillations */
|
||||||
|
#define KAPPA_SIDES 5.0e-4 /* "elasticity" term on absorbing boundary */
|
||||||
|
#define KAPPA_TOPBOT 0.0 /* "elasticity" term on absorbing boundary */
|
||||||
|
/* The Courant number is given by c*DT/DX, where DT is the time step and DX the lattice spacing */
|
||||||
|
/* The physical damping coefficient is given by GAMMA/(DT)^2 */
|
||||||
|
/* Increasing COURANT speeds up the simulation, but decreases accuracy */
|
||||||
|
/* For similar wave forms, COURANT^2*GAMMA should be kept constant */
|
||||||
|
|
||||||
|
/* Boundary conditions, see list in global_pdes.c */
|
||||||
|
|
||||||
|
#define B_COND 3
|
||||||
|
|
||||||
|
/* Parameters for length and speed of simulation */
|
||||||
|
|
||||||
|
#define NSTEPS 6000 /* number of frames of movie */
|
||||||
|
#define NVID 25 /* number of iterations between images displayed on screen */
|
||||||
|
#define NSEG 100 /* number of segments of boundary */
|
||||||
|
#define INITIAL_TIME 200 /* time after which to start saving frames */
|
||||||
|
#define COMPUTE_ENERGIES 1 /* set to 1 to compute and print energies */
|
||||||
|
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */
|
||||||
|
|
||||||
|
#define PAUSE 1000 /* number of frames after which to pause */
|
||||||
|
#define PSLEEP 1 /* sleep time during pause */
|
||||||
|
#define SLEEP1 1 /* initial sleeping time */
|
||||||
|
#define SLEEP2 1 /* final sleeping time */
|
||||||
|
|
||||||
|
/* Plot type, see list in global_pdes.c */
|
||||||
|
|
||||||
|
#define PLOT 1
|
||||||
|
|
||||||
|
/* Color schemes */
|
||||||
|
|
||||||
|
#define BLACK 1 /* background */
|
||||||
|
|
||||||
|
#define COLOR_SCHEME 1 /* choice of color scheme, see list in global_pdes.c */
|
||||||
|
|
||||||
|
#define SCALE 0 /* set to 1 to adjust color scheme to variance of field */
|
||||||
|
#define SLOPE 1.5 /* sensitivity of color on wave amplitude */
|
||||||
|
#define ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */
|
||||||
|
#define E_SCALE 2000.0 /* scaling factor for energy representation */
|
||||||
|
|
||||||
|
#define COLORHUE 260 /* initial hue of water color for scheme C_LUM */
|
||||||
|
#define COLORDRIFT 0.0 /* how much the color hue drifts during the whole simulation */
|
||||||
|
#define LUMMEAN 0.5 /* amplitude of luminosity variation for scheme C_LUM */
|
||||||
|
#define LUMAMP 0.3 /* amplitude of luminosity variation for scheme C_LUM */
|
||||||
|
#define HUEMEAN 220.0 /* mean value of hue for color scheme C_HUE */
|
||||||
|
#define HUEAMP -220.0 /* amplitude of variation of hue for color scheme C_HUE */
|
||||||
|
|
||||||
|
/* For debugging purposes only */
|
||||||
|
#define FLOOR 0 /* set to 1 to limit wave amplitude to VMAX */
|
||||||
|
#define VMAX 10.0 /* max value of wave amplitude */
|
||||||
|
|
||||||
|
|
||||||
|
#include "global_pdes.c" /* constants and global variables */
|
||||||
|
#include "sub_wave.c" /* common functions for wave_billiard, heat and schrodinger */
|
||||||
|
#include "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
|
||||||
|
#include "sub_wave_comp.c" /* some functions specific to wave_comparison */
|
||||||
|
|
||||||
|
double courant2, courantb2; /* Courant parameters squared */
|
||||||
|
|
||||||
|
|
||||||
|
/*********************/
|
||||||
|
/* animation part */
|
||||||
|
/*********************/
|
||||||
|
|
||||||
|
void evolve_wave_half(double *phi_in[NX], double *psi_in[NX], double *phi_out[NX], double *psi_out[NX],
|
||||||
|
short int *xy_in[NX])
|
||||||
|
/* time step of field evolution */
|
||||||
|
/* phi is value of field at time t, psi at time t-1 */
|
||||||
|
{
|
||||||
|
int i, j, iplus, iminus, jplus, jminus, jmid = NY/2;
|
||||||
|
double delta, x, y, c, cc, gamma;
|
||||||
|
static long time = 0;
|
||||||
|
|
||||||
|
time++;
|
||||||
|
|
||||||
|
#pragma omp parallel for private(i,j,iplus,iminus,jplus,jminus,delta,x,y)
|
||||||
|
for (i=0; i<NX; i++){
|
||||||
|
for (j=0; j<NY; j++){
|
||||||
|
if (xy_in[i][j])
|
||||||
|
{
|
||||||
|
c = COURANT;
|
||||||
|
cc = courant2;
|
||||||
|
gamma = GAMMA;
|
||||||
|
}
|
||||||
|
else if (TWOSPEEDS)
|
||||||
|
{
|
||||||
|
c = COURANTB;
|
||||||
|
cc = courantb2;
|
||||||
|
gamma = GAMMAB;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((TWOSPEEDS)&&(xy_in[i][j] != 2))||(xy_in[i][j] == 1)){
|
||||||
|
/* discretized Laplacian for various boundary conditions */
|
||||||
|
if ((B_COND == BC_DIRICHLET)||(B_COND == BC_ABSORBING)||(B_COND == BC_ABS_REFLECT))
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
else if (jplus == jmid) jplus = jmid-1;
|
||||||
|
jminus = (j-1);
|
||||||
|
if (jminus == -1) jminus = 0;
|
||||||
|
else if (jminus == jmid-1) jminus = jmid;
|
||||||
|
}
|
||||||
|
else if (B_COND == BC_PERIODIC)
|
||||||
|
{
|
||||||
|
iplus = (i+1) % NX;
|
||||||
|
iminus = (i-1) % NX;
|
||||||
|
if (iminus < 0) iminus += NX;
|
||||||
|
if (j < jmid) /* lower half */
|
||||||
|
{
|
||||||
|
jplus = (j+1) % jmid;
|
||||||
|
jminus = (j-1) % jmid;
|
||||||
|
if (jminus < 0) jminus += jmid;
|
||||||
|
}
|
||||||
|
else /* upper half */
|
||||||
|
{
|
||||||
|
jplus = j+1;
|
||||||
|
if (jplus >= NY) jplus -= jmid;
|
||||||
|
jminus = j-1;
|
||||||
|
if (jminus < jmid) jminus += jmid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (B_COND == BC_VPER_HABS)
|
||||||
|
{
|
||||||
|
iplus = (i+1); if (iplus == NX) iplus = NX-1;
|
||||||
|
iminus = (i-1); if (iminus == -1) iminus = 0;
|
||||||
|
if (j < jmid) /* lower half */
|
||||||
|
{
|
||||||
|
jplus = (j+1) % jmid;
|
||||||
|
jminus = (j-1) % jmid;
|
||||||
|
if (jminus < 0) jminus += jmid;
|
||||||
|
}
|
||||||
|
else /* upper half */
|
||||||
|
{
|
||||||
|
jplus = j+1;
|
||||||
|
if (jplus >= NY) jplus -= jmid;
|
||||||
|
jminus = j-1;
|
||||||
|
if (jminus < jmid) jminus += jmid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* imposing linear wave on top and bottom by making Laplacian 1d */
|
||||||
|
if (OSCILLATE_TOPBOT)
|
||||||
|
{
|
||||||
|
if (j == NY-1) jminus = NY-1;
|
||||||
|
else if (j == 0) jplus = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
delta = phi_in[iplus][j] + phi_in[iminus][j] + phi_in[i][jplus] + phi_in[i][jminus] - 4.0*phi_in[i][j];
|
||||||
|
|
||||||
|
x = phi_in[i][j];
|
||||||
|
y = psi_in[i][j];
|
||||||
|
|
||||||
|
/* evolve phi */
|
||||||
|
if ((B_COND == BC_PERIODIC)||(B_COND == BC_DIRICHLET))
|
||||||
|
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - gamma*(x-y);
|
||||||
|
else if ((B_COND == BC_ABSORBING)||(B_COND == BC_ABS_REFLECT))
|
||||||
|
{
|
||||||
|
if ((i>0)&&(i<NX-1)&&(j>0)&&(j<NY-1))
|
||||||
|
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - gamma*(x-y);
|
||||||
|
|
||||||
|
/* upper border */
|
||||||
|
else if (j==NY-1)
|
||||||
|
phi_out[i][j] = x - c*(x - phi_in[i][NY-2]) - KAPPA_TOPBOT*x - GAMMA_TOPBOT*(x-y);
|
||||||
|
|
||||||
|
/* lower border */
|
||||||
|
else if (j==0)
|
||||||
|
phi_out[i][j] = x - c*(x - phi_in[i][1]) - KAPPA_TOPBOT*x - GAMMA_TOPBOT*(x-y);
|
||||||
|
|
||||||
|
/* right border */
|
||||||
|
if (i==NX-1)
|
||||||
|
phi_out[i][j] = x - c*(x - phi_in[NX-2][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
|
|
||||||
|
/* left border */
|
||||||
|
else if (i==0)
|
||||||
|
phi_out[i][j] = x - c*(x - phi_in[1][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
|
}
|
||||||
|
else if (B_COND == BC_VPER_HABS)
|
||||||
|
{
|
||||||
|
if ((i>0)&&(i<NX-1))
|
||||||
|
phi_out[i][j] = -y + 2*x + cc*delta - KAPPA*x - gamma*(x-y);
|
||||||
|
|
||||||
|
/* right border */
|
||||||
|
else if (i==NX-1)
|
||||||
|
phi_out[i][j] = x - c*(x - phi_in[NX-2][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
|
|
||||||
|
/* left border */
|
||||||
|
else if (i==0)
|
||||||
|
phi_out[i][j] = x - c*(x - phi_in[1][j]) - KAPPA_SIDES*x - GAMMA_SIDES*(x-y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add oscillating boundary condition on the left */
|
||||||
|
if ((i == 0)&&(OSCILLATE_LEFT)) phi_out[i][j] = AMPLITUDE*cos((double)time*OMEGA);
|
||||||
|
psi_out[i][j] = x;
|
||||||
|
|
||||||
|
if (FLOOR)
|
||||||
|
{
|
||||||
|
if (phi_out[i][j] > VMAX) phi_out[i][j] = VMAX;
|
||||||
|
if (phi_out[i][j] < -VMAX) phi_out[i][j] = -VMAX;
|
||||||
|
if (psi_out[i][j] > VMAX) psi_out[i][j] = VMAX;
|
||||||
|
if (psi_out[i][j] < -VMAX) psi_out[i][j] = -VMAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void evolve_wave(double *phi[NX], double *psi[NX], double *phi_tmp[NX], double *psi_tmp[NX], short int *xy_in[NX])
|
||||||
|
/* time step of field evolution */
|
||||||
|
/* phi is value of field at time t, psi at time t-1 */
|
||||||
|
{
|
||||||
|
evolve_wave_half(phi, psi, phi_tmp, psi_tmp, xy_in);
|
||||||
|
evolve_wave_half(phi_tmp, psi_tmp, phi, psi, xy_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void animation()
|
||||||
|
{
|
||||||
|
double time, scale, energies[6], top_energy, bottom_energy;
|
||||||
|
double *phi[NX], *psi[NX], *phi_tmp[NX], *psi_tmp[NX];
|
||||||
|
short int *xy_in[NX];
|
||||||
|
int i, j, s;
|
||||||
|
|
||||||
|
/* Since NX and NY are big, it seemed wiser to use some memory allocation here */
|
||||||
|
for (i=0; i<NX; i++)
|
||||||
|
{
|
||||||
|
phi[i] = (double *)malloc(NY*sizeof(double));
|
||||||
|
psi[i] = (double *)malloc(NY*sizeof(double));
|
||||||
|
phi_tmp[i] = (double *)malloc(NY*sizeof(double));
|
||||||
|
psi_tmp[i] = (double *)malloc(NY*sizeof(double));
|
||||||
|
xy_in[i] = (short int *)malloc(NY*sizeof(short int));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initialise positions and radii of circles */
|
||||||
|
printf("initializing circle configuration\n");
|
||||||
|
if ((B_DOMAIN == D_CIRCLES)||(B_DOMAIN_B == D_CIRCLES)) init_circle_config_comp();
|
||||||
|
|
||||||
|
courant2 = COURANT*COURANT;
|
||||||
|
courantb2 = COURANTB*COURANTB;
|
||||||
|
|
||||||
|
/* initialize wave with a drop at one point, zero elsewhere */
|
||||||
|
int_planar_wave_comp(XMIN + 0.015, 0.0, phi, psi, xy_in);
|
||||||
|
// int_planar_wave_comp(XMIN + 0.5, 0.0, phi, psi, xy_in);
|
||||||
|
printf("initializing wave\n");
|
||||||
|
// int_planar_wave_comp(XMIN + 0.1, 0.0, phi, psi, xy_in);
|
||||||
|
// int_planar_wave_comp(XMIN + 1.0, 0.0, phi, psi, xy_in);
|
||||||
|
// init_wave(-1.5, 0.0, phi, psi, xy_in);
|
||||||
|
// init_wave(0.0, 0.0, phi, psi, xy_in);
|
||||||
|
|
||||||
|
/* add a drop at another point */
|
||||||
|
// add_drop_to_wave(1.0, 0.7, 0.0, phi, psi);
|
||||||
|
// add_drop_to_wave(1.0, -0.7, 0.0, phi, psi);
|
||||||
|
// add_drop_to_wave(1.0, 0.0, -0.7, phi, psi);
|
||||||
|
|
||||||
|
/* initialize energies */
|
||||||
|
if (COMPUTE_ENERGIES)
|
||||||
|
{
|
||||||
|
compute_energy_tblr(phi, psi, xy_in, energies);
|
||||||
|
top_energy = energies[0] + energies[1] + energies[2];
|
||||||
|
bottom_energy = energies[3] + energies[4] + energies[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
blank();
|
||||||
|
glColor3f(0.0, 0.0, 0.0);
|
||||||
|
printf("drawing wave\n");
|
||||||
|
draw_wave_comp(phi, psi, xy_in, 1.0, 0);
|
||||||
|
|
||||||
|
printf("drawing billiard\n");
|
||||||
|
draw_billiard_comp();
|
||||||
|
|
||||||
|
glutSwapBuffers();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sleep(SLEEP1);
|
||||||
|
|
||||||
|
for (i=0; i<=INITIAL_TIME + NSTEPS; i++)
|
||||||
|
{
|
||||||
|
//printf("%d\n",i);
|
||||||
|
/* compute the variance of the field to adjust color scheme */
|
||||||
|
/* the color depends on the field divided by sqrt(1 + variance) */
|
||||||
|
if (SCALE)
|
||||||
|
{
|
||||||
|
scale = sqrt(1.0 + compute_variance(phi,psi, xy_in));
|
||||||
|
// printf("Scaling factor: %5lg\n", scale);
|
||||||
|
}
|
||||||
|
else scale = 1.0;
|
||||||
|
|
||||||
|
draw_wave_comp(phi, psi, xy_in, scale, i);
|
||||||
|
|
||||||
|
draw_billiard_comp();
|
||||||
|
|
||||||
|
|
||||||
|
if (COMPUTE_ENERGIES)
|
||||||
|
{
|
||||||
|
compute_energy_tblr(phi, psi, xy_in, energies);
|
||||||
|
if (i < INITIAL_TIME)
|
||||||
|
{
|
||||||
|
top_energy = energies[0] + energies[1] + energies[2];
|
||||||
|
bottom_energy = energies[3] + energies[4] + energies[5];
|
||||||
|
}
|
||||||
|
print_energies(energies, top_energy, bottom_energy);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j=0; j<NVID; j++)
|
||||||
|
{
|
||||||
|
evolve_wave(phi, psi, phi_tmp, psi_tmp, xy_in);
|
||||||
|
// if (i % 10 == 9) oscillate_linear_wave(0.2*scale, 0.15*(double)(i*NVID + j), -1.5, YMIN, -1.5, YMAX, phi, psi);
|
||||||
|
}
|
||||||
|
|
||||||
|
glutSwapBuffers();
|
||||||
|
|
||||||
|
if (MOVIE)
|
||||||
|
{
|
||||||
|
if (i >= INITIAL_TIME) save_frame();
|
||||||
|
else printf("Initial phase time %i of %i\n", i, INITIAL_TIME);
|
||||||
|
|
||||||
|
/* it seems that saving too many files too fast can cause trouble with the file system */
|
||||||
|
/* so this is to make a pause from time to time - parameter PAUSE may need adjusting */
|
||||||
|
if (i % PAUSE == PAUSE - 1)
|
||||||
|
{
|
||||||
|
printf("Making a short pause\n");
|
||||||
|
sleep(PSLEEP);
|
||||||
|
s = system("mv wave*.tif tif_wave/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MOVIE)
|
||||||
|
{
|
||||||
|
for (i=0; i<20; i++) save_frame();
|
||||||
|
s = system("mv wave*.tif tif_wave/");
|
||||||
|
}
|
||||||
|
for (i=0; i<NX; i++)
|
||||||
|
{
|
||||||
|
free(phi[i]);
|
||||||
|
free(psi[i]);
|
||||||
|
free(phi_tmp[i]);
|
||||||
|
free(psi_tmp[i]);
|
||||||
|
free(xy_in[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void display(void)
|
||||||
|
{
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
blank();
|
||||||
|
glutSwapBuffers();
|
||||||
|
blank();
|
||||||
|
glutSwapBuffers();
|
||||||
|
|
||||||
|
animation();
|
||||||
|
sleep(SLEEP2);
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
glutDestroyWindow(glutGetWindow());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
glutInit(&argc, argv);
|
||||||
|
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||||
|
glutInitWindowSize(WINWIDTH,WINHEIGHT);
|
||||||
|
glutCreateWindow("Wave equation in a planar domain");
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
glutDisplayFunc(display);
|
||||||
|
|
||||||
|
glutMainLoop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user