Add files via upload

This commit is contained in:
nilsberglund-orleans
2021-10-24 15:20:56 +02:00
committed by GitHub
parent 660e3d15fd
commit dadfb985ed
18 changed files with 3207 additions and 502 deletions

View File

@@ -38,6 +38,7 @@
#define XMIN -4.0
#define XMAX 4.0 /* x interval */
#define YMIN -1.25
// #define YMID 1.25
#define YMAX 3.25 /* y interval for 9/16 aspect ratio */
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
@@ -51,20 +52,30 @@
/* Choice of the billiard table, see global_particles.c */
#define B_DOMAIN 21 /* choice of domain shape */
#define B_DOMAIN 23 /* choice of domain shape */
#define CIRCLE_PATTERN 6 /* pattern of circles */
// #define CIRCLE_PATTERN 21 /* pattern of circles */
#define ABSORBING_CIRCLES 0 /* set to 1 for circular scatterers to be absorbing */
#define NMAXCIRCLES 5000 /* total number of circles (must be at least NCX*NCY for square grid) */
#define NCX 40 /* number of circles in x direction */
#define NMAXCIRCLES 1000 /* total number of circles (must be at least NCX*NCY for square grid) */
#define NCX 44 /* number of circles in x direction */
#define NCY 10 /* number of circles in y direction */
#define NPOISSON 500 /* number of points for Poisson C_RAND_POISSON arrangement */
// #define NCX 50 /* number of circles in x direction */
// #define NCY 20 /* number of circles in y direction */
// #define NCX 52 /* number of circles in x direction */
// #define NCY 30 /* number of circles in y direction */
#define NPOISSON 350 /* number of points for Poisson C_RAND_POISSON arrangement */
#define NGOLDENSPIRAL 2000 /* max number of points for C_GOLDEN_SPIRAL arrandement */
#define LAMBDA 3.8 /* parameter controlling shape of domain */
#define LAMBDA 3.8105 /* parameter controlling shape of domain */
// #define MU 0.1 /* second parameter controlling shape of billiard */
// #define MU 0.085 /* second parameter controlling shape of billiard */
// #define MU 0.09 /* second parameter controlling shape of billiard */
#define MU 0.05 /* second parameter controlling shape of billiard */
// #define MU 0.034 /* second parameter controlling shape of billiard */
#define FOCI 1 /* set to 1 to draw focal points of ellipse */
#define NPOLY 4 /* number of sides of polygon */
#define APOLY 0.5 /* angle by which to turn polygon, in units of Pi/2 */
@@ -85,9 +96,14 @@
#define SHOWTRAILS 0 /* set to 1 to keep trails of the particles */
#define TEST_ACTIVE 0 /* set to 1 to test whether particle is in billiard */
#define NSTEPS 7700 /* number of frames of movie */
#define NSTEPS 11700 /* number of frames of movie */
// #define NSTEPS 1000 /* number of frames of movie */
// #define TIME 1500 /* time between movie frames, for fluidity of real-time simulation */
#define TIME 4000 /* time between movie frames, for fluidity of real-time simulation */
// #define DPHI 0.0001 /* integration step */
// #define DPHI 0.00002 /* integration step */
#define DPHI 0.00007 /* integration step */
// #define DPHI 0.000035 /* integration step */
#define NVID 150 /* number of iterations between images displayed on screen */
/* Decreasing TIME accelerates the animation and the movie */
@@ -98,8 +114,11 @@
/* Colors and other graphical parameters */
#define NCOLORS 32 /* number of colors */
#define COLORSHIFT 0 /* hue of initial color */
#define COLOR_PALETTE 1 /* Color palette, see list in global_pdes.c */
// #define NCOLORS 256 /* number of colors */
#define NCOLORS 48 /* number of colors */
#define COLORSHIFT 2 /* hue of initial color */
#define RAINBOW_COLOR 1 /* set to 1 to use different colors for all particles */
#define SINGLE_COLOR 1 /* set to 1 to make all particles a single color */
#define FLOWER_COLOR 0 /* set to 1 to adapt initial colors to flower billiard (tracks vs core) */
@@ -108,6 +127,7 @@
#define BILLIARD_WIDTH 2 /* width of billiard */
#define PARTICLE_WIDTH 4 /* width of particles */
#define FRONT_WIDTH 3 /* width of wave front */
// #define COLOR_TRAJECTORY 0 /* hue for single color */
#define COLOR_TRAJECTORY 8 /* hue for single color */
#define BLACK 1 /* set to 1 for black background */
@@ -118,7 +138,7 @@
#define ERASE_OUTSIDE 1 /* set to 1 to erase outside of rectangular billiard (beta) */
#define PAUSE 1000 /* number of frames after which to pause */
#define PAUSE 500 /* number of frames after which to pause */
#define PSLEEP 5 /* sleep time during pause */
#define SLEEP1 1 /* initial sleeping time */
#define SLEEP2 1000 /* final sleeping time */
@@ -133,6 +153,7 @@
int ncol = 0, nobst = 0, nmaxpeg = 0;
int npath[NPATHBINS];
double max_free_path = 0.0;
/*********************/
/* animation part */
@@ -404,6 +425,7 @@ void graph_movie(int time, int color[NPARTMAX], double *configs[NPARTMAX], int a
{
int i, j, k, c;
double rgb[3];
static double total_pathlength = 0.0;
for (j=0; j<time; j++)
{
@@ -424,22 +446,44 @@ void graph_movie(int time, int color[NPARTMAX], double *configs[NPARTMAX], int a
glEnd ();
}
total_pathlength += configs[i][3];
c = vbilliard(configs[i]);
ncol++;
/* update number of collisions, not counting boundary for periodic b.c. */
if (B_DOMAIN != D_CIRCLES_IN_TORUS) ncol++;
else if (c >= 0) ncol++;
if ((c >= 0)&&(circlecolor[c] == 0)) nobst++;
circlecolor[c]++;
/* take care of circles doubled because of periodic boundary conditions */
if ((circleactive[c])&&(B_DOMAIN == D_CIRCLES_IN_TORUS)&&(partner_circle[c] != c)) circlecolor[partner_circle[c]]++;
newcircle[c] = 10;
/* update free path statistics */
k = (int)((double)NPATHBINS*configs[i][3]/PATHLMAX);
if (k < NPATHBINS) npath[k]++;
// if (circlecolor[c] > nmaxpeg) nmaxpeg = circlecolor[c];
// if (circlecolor[c] > NCOLORS) circlecolor[c] = 1;
// if (c>=0) color[i]++;
if (ncol > 1) /* disregard very first collision */
{
if (B_DOMAIN != D_CIRCLES_IN_TORUS)
{
k = (int)((double)NPATHBINS*configs[i][3]/PATHLMAX);
if (k < NPATHBINS) npath[k]++;
if (total_pathlength > max_free_path) max_free_path = total_pathlength;
total_pathlength = 0.0;
}
else /* case with periodic boundary conditions */
{
if (c >= 0) /* a circle is hit, update histogram */
{
// printf("total path length %.3lg\n", total_pathlength);
k = (int)((double)NPATHBINS*total_pathlength/PATHLMAX);
if (k < NPATHBINS) npath[k]++;
if (total_pathlength > max_free_path) max_free_path = total_pathlength;
total_pathlength = 0.0;
}
}
}
if (!RAINBOW_COLOR)
{
@@ -514,8 +558,10 @@ void print_particle_numbers(double *configs[NPARTMAX])
void draw_statistics()
{
int i, n, colmax = 35, pegcollisions[70], nypegs = 70, meanpegs = 0, total_coll = 0, ymax = 0, meanbins = 0, total_bin = 0;
double x, y, yscale = 120.0, y0, dx, rgb[3], xshift;
int i, n, colmax = 55, pegcollisions[90], nypegs = 70, meanpegs = 0, meansquarepegs = 0, total_coll = 0, ymax = 0,
meanbins = 0, meansquarebins, total_bin = 0, stephits = 10, tickstephits = 1;
double x, y, yscale = 110.0, y0, dx, rgb[3], xshift, coll_mean, coll_stdv, path_mean, path_stdv, ebin, len_over_bin,
steppath = 0.5;
char message[50];
glLineWidth(1);
@@ -525,10 +571,10 @@ void draw_statistics()
xshift = XMIN + 0.3;
rgb[0] = 0.0; rgb[1] = 0.0; rgb[2] = 1.0;
/* histogramm of number of collisions per peg */
/* histogram of number of collisions per peg */
for (i=0; i<colmax; i++) pegcollisions[i] = 0;
for (i=0; i<ncircles; i++)
for (i=0; i<ncircles; i++) if ((circleactive[i])&&(!double_circle[i]))
{
n = circlecolor[i];
if (n < colmax) pegcollisions[n]++;
@@ -537,6 +583,7 @@ void draw_statistics()
{
total_coll += pegcollisions[i];
meanpegs += i*pegcollisions[i];
meansquarepegs += i*i*pegcollisions[i];
}
for (i=1; i<colmax; i++)
@@ -550,8 +597,8 @@ void draw_statistics()
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
/* histogramm */
for (i=1; i<colmax; i++)
/* histogram */
for (i=0; i<colmax; i++)
{
x = xshift + (double)i*dx;
y = y0 + (double)pegcollisions[i]*YMAX/yscale;
@@ -574,7 +621,7 @@ void draw_statistics()
glEnd ();
}
for (i=1; i<colmax; i++)
for (i=tickstephits; i<colmax; i+=tickstephits)
{
glBegin(GL_LINE_STRIP);
glVertex2d(xshift + (double)i*dx, y0 - 0.025);
@@ -582,10 +629,10 @@ void draw_statistics()
glEnd ();
}
for (i=10; i<colmax; i+=10)
for (i=stephits; i<nypegs - stephits; i+=stephits)
{
sprintf(message, "%4d", i);
write_text_fixedwidth(xshift + (double)i*dx - 0.12, y0 - 0.12, message);
write_text_fixedwidth(xshift + (double)i*dx - 0.15, y0 - 0.12, message);
}
for (i=10; i<nypegs; i+=10)
@@ -594,20 +641,34 @@ void draw_statistics()
write_text_fixedwidth(xshift - 0.3, y0 - 0.025 + (double)i*YMAX/yscale, message);
}
coll_mean = (double)meanpegs/(double)total_coll;
coll_stdv = sqrt((double)meansquarepegs/(double)total_coll - coll_mean*coll_mean);
sprintf(message, "hits");
write_text_fixedwidth(xshift + (double)(colmax-3)*dx, y0 - 0.12, message);
sprintf(message, "pegs");
write_text_fixedwidth(xshift - 0.25, y0 - 0.025 + (double)(nypegs - 3)*YMAX/yscale, message);
sprintf(message, "Mean %.4lg", (double)meanpegs/(double)total_coll);
write_text(-1.0, YMAX - 0.3, message);
// sprintf(message, "Mean %.4lg", (double)meanpegs/(double)total_coll);
/* histogramm of path lengths */
sprintf(message, "Max hits/peg %d", nmaxpeg);
write_text(-1.5, YMAX - 0.3, message);
sprintf(message, "Mean hits/peg %.4lg", coll_mean);
write_text(-1.5, YMAX - 0.5, message);
sprintf(message, "Stdv hits/peg %.4lg", coll_stdv);
write_text(-1.5, YMAX - 0.7, message);
/* histogram of path lengths */
for (i=1; i<NPATHBINS; i++)
{
if (npath[i] > ymax) ymax = npath[i];
total_bin += npath[i];
meanbins += i*npath[i];
meansquarebins += i*i*npath[i];
}
yscale = 0.9*(YMAX-y0)*(double)ymax;
@@ -620,13 +681,13 @@ void draw_statistics()
x = xshift + (double)i*dx;
y = y0 + (double)npath[i]*YMAX/yscale;
erase_rectangle(x, y0, x+dx, y, rgb);
if (y > y0) erase_rectangle(x, y0, x+dx, y, rgb);
}
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
/* histogramm */
for (i=1; i<NPATHBINS; i++)
/* histogram */
for (i=1; i<NPATHBINS; i++) if (npath[i] > 0)
{
x = xshift + (double)i*dx;
y = y0 + (double)npath[i]*YMAX/yscale;
@@ -636,19 +697,23 @@ void draw_statistics()
glVertex2d(x+dx, y0);
glVertex2d(x, y0);
}
glVertex2d(xshift, y0);
glEnd ();
glBegin(GL_LINE_STRIP);
glVertex2d(xshift, YMAX - 0.1);
glVertex2d(xshift, y0);
glVertex2d(xshift + (double)NPATHBINS*dx, y0);
glEnd ();
for (x = 0.5; x < PATHLMAX; x+=0.5)
for (x = steppath; x < PATHLMAX; x+=steppath)
{
i = (int)(x*(double)NPATHBINS/PATHLMAX);
sprintf(message, "%.2f", x);
write_text_fixedwidth(xshift + (double)i*dx - 0.1, y0 - 0.12, message);
}
for (x = 0.1; x < PATHLMAX; x+=0.1)
for (x = steppath; x < PATHLMAX; x+=steppath)
{
i = (int)(x*(double)NPATHBINS/PATHLMAX);
glBegin(GL_LINE_STRIP);
@@ -656,12 +721,24 @@ void draw_statistics()
glVertex2d(xshift + (double)i*dx, y0 + 0.025);
glEnd ();
}
ebin = (double)meanbins/(double)total_bin; /* mean bin */
len_over_bin = PATHLMAX/(double)NPATHBINS; /* conversion from bin to path length */
path_mean = ebin*len_over_bin; /* mean free path */
path_stdv = sqrt((double)meansquarebins/(double)total_bin - ebin*ebin)*len_over_bin;
sprintf(message, "free path");
write_text_fixedwidth(XMAX - 0.6, y0 - 0.12, message);
sprintf(message, "Mean free path %.4lg", (double)meanbins*PATHLMAX/(double)(total_bin*NPATHBINS));
sprintf(message, "Max free path %.4lg", max_free_path);
write_text(2.2, YMAX - 0.3, message);
sprintf(message, "Mean free path %.4lg", path_mean);
write_text(2.2, YMAX - 0.5, message);
sprintf(message, "Stdv free path %.4lg", path_stdv);
write_text(2.2, YMAX - 0.7, message);
}
@@ -681,24 +758,38 @@ void animation(int circle_config)
configs[i] = (double *)malloc(8*sizeof(double));
/* init circle configuration if the domain is D_CIRCLES */
if ((B_DOMAIN == D_CIRCLES)||(B_DOMAIN == D_CIRCLES_IN_RECT)||(B_DOMAIN == D_CIRCLES_IN_GENUSN))
if ((B_DOMAIN == D_CIRCLES)||(B_DOMAIN == D_CIRCLES_IN_RECT)||(B_DOMAIN == D_CIRCLES_IN_GENUSN)
||(B_DOMAIN == D_CIRCLES_IN_TORUS))
init_circle_config_pinball(circle_config);
/* remove discs that are not in domain */
if ((B_DOMAIN == D_CIRCLES_IN_RECT)||(B_DOMAIN == D_CIRCLES_IN_GENUSN))
if ((B_DOMAIN == D_CIRCLES_IN_RECT)||(B_DOMAIN == D_CIRCLES_IN_GENUSN))
// ||(B_DOMAIN == D_CIRCLES_IN_TORUS))
for (i=0; i<ncircles; i++)
{
if (vabs(circley[i]) + circlerad[i] > 0.99) circleactive[i] = 0;
if (vabs(circlex[i]) + circlerad[i] > 0.99*LAMBDA) circleactive[i] = 0;
}
else if (B_DOMAIN == D_CIRCLES_IN_TORUS)
for (i=0; i<ncircles; i++)
{
if (vabs(circley[i]) - circlerad[i] > 1.0) circleactive[i] = 0;
if (vabs(circlex[i]) - circlerad[i] > LAMBDA) circleactive[i] = 0;
}
// for (i=0; i<ncircles; i++)
// printf("Circle %i at (%.2f, %.2f), double %i, partner %i\n", i, circlex[i], circley[i], double_circle[i], partner_circle[i]);
// if (vabs(circley[i]) > 1.0) circleactive[i] = 0;
/* initialize system by putting particles in a given point with a range of velocities */
r = cos(PI/(double)NPOLY)/cos(DPI/(double)NPOLY);
// init_drop_config(0.4, 0.0, PID, 0.5*PID, configs);
init_drop_config(0.0, 0.0, -0.45*PID, 0.45*PID, configs);
// init_line_config(-1.25, -0.5, -1.25, 0.5, 0.0, configs);
init_drop_config(0.5, 0.1, -0.5*PID, 0.5*PID, configs);
// init_drop_config(0.0, 0.0, -0.5*PID, 0.5*PID, configs);
// init_drop_config(0.5, 0.1, -0.5*PID, 0.5*PID, configs);
// init_drop_config(-1.4, 0.0, -0.5*PID, 0.5*PID, configs);
// init_drop_config(0.5, 0.5, -1.0, 1.0, configs);
// init_sym_drop_config(-1.0, 0.5, -PID, PID, configs);
@@ -795,9 +886,9 @@ void animation(int circle_config)
for (j=0; j<ncircles; j++)
if (circlecolor[j] > nmaxpeg) nmaxpeg = circlecolor[j];
sprintf(message, "max hits per peg: %d", nmaxpeg);
glColor3f(1.0, 1.0, 1.0);
write_text(-0.6, YMIN + 0.08, message);
// sprintf(message, "max hits per peg: %d", nmaxpeg);
// glColor3f(1.0, 1.0, 1.0);
// write_text(-0.6, YMIN + 0.08, message);
// write_text(-0.3, YMIN + 0.04, message);
draw_statistics();
@@ -849,8 +940,8 @@ void display(void)
}
animation(CIRCLE_PATTERN);
// animation(C_TRI);
// animation(C_GOLDEN_SPIRAL);
// animation(C_SQUARE);
// animation(C_HEX);