From f56b8a0ab488ed724734bb31883e38accaa8f679 Mon Sep 17 00:00:00 2001 From: nilsberglund-orleans <83530463+nilsberglund-orleans@users.noreply.github.com> Date: Sun, 18 Jul 2021 15:06:59 +0200 Subject: [PATCH] Add files via upload --- drop_billiard.c | 68 +++++----- global_particles.c | 33 +++++ global_pdes.c | 90 ++++++++++++++ heat.c | 209 ++++++++++++++++++------------- particle_billiard.c | 215 ++++++++++++++++++++++---------- schrodinger.c | 179 ++++++++++----------------- sub_wave.c | 294 +++++++++++++++++++++++++++++++++++++++++++- wave_billiard.c | 288 +++++++++++++++++++++++-------------------- 8 files changed, 951 insertions(+), 425 deletions(-) create mode 100644 global_particles.c create mode 100644 global_pdes.c diff --git a/drop_billiard.c b/drop_billiard.c index a45d841..9a13700 100644 --- a/drop_billiard.c +++ b/drop_billiard.c @@ -33,32 +33,28 @@ #define WINWIDTH 1280 /* window width */ #define WINHEIGHT 720 /* window height */ -#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 */ -// #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 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 XMIN -1.8 +// #define XMAX 1.8 /* x interval */ +// #define YMIN -0.91 +// #define YMAX 1.115 /* y interval for 9/16 aspect ratio */ #define SCALING_FACTOR 1.0 /* scaling factor of drawing, needed for flower billiards, otherwise set to 1.0 */ -/* Choice of the billiard table */ +/* Choice of the billiard table, see global_particles.c */ -#define B_DOMAIN 9 /* choice of domain shape */ +#define B_DOMAIN 13 /* choice of domain shape */ -#define D_RECTANGLE 0 /* rectangular domain */ -#define D_ELLIPSE 1 /* elliptical domain */ -#define D_STADIUM 2 /* stadium-shaped domain */ -#define D_SINAI 3 /* Sinai billiard */ -#define D_DIAMOND 4 /* diamond-shaped billiard */ -#define D_TRIANGLE 5 /* triangular billiard */ -#define D_ANNULUS 7 /* annulus */ -#define D_POLYGON 8 /* polygon */ -#define D_REULEAUX 9 /* Reuleaux and star shapes */ -#define D_FLOWER 10 /* Bunimovich flower */ -#define D_ALT_REU 11 /* alternating between star and Reuleaux */ +#define CIRCLE_PATTERN 0 /* pattern of circles */ + +#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 NCY 20 /* number of circles in y direction */ // #define LAMBDA 1.0 /* parameter controlling shape of billiard */ #define LAMBDA 1.124950941 /* sin(36°)/sin(31.5°) for 5-star shape with 45° angles */ @@ -72,16 +68,17 @@ #define APOLY -1.0 /* angle by which to turn polygon, in units of Pi/2 */ #define DRAW_BILLIARD 1 /* set to 1 to draw billiard */ #define DRAW_CONSTRUCTION_LINES 1 /* set to 1 to draw additional construction lines for billiard */ +#define PERIODIC_BC 0 /* set to 1 to enforce periodic boundary conditions when drawing particles */ #define RESAMPLE 0 /* set to 1 if particles should be added when dispersion too large */ -#define NPART 100000 /* number of particles */ +#define NPART 50000 /* number of particles */ #define NPARTMAX 100000 /* maximal number of particles after resampling */ -#define NSTEPS 4000 /* number of frames of movie */ -#define TIME 15 /* time between movie frames, for fluidity of real-time simulation */ +#define NSTEPS 5500 /* number of frames of movie */ +#define TIME 40 /* time between movie frames, for fluidity of real-time simulation */ #define DPHI 0.0001 /* integration step */ -#define NVID 10 /* number of iterations between images displayed on screen */ +#define NVID 20 /* number of iterations between images displayed on screen */ /* Decreasing TIME accelerates the animation and the movie */ /* For constant speed of movie, TIME*DPHI should be kept constant */ @@ -91,16 +88,17 @@ /* simulation parameters */ #define LMAX 0.01 /* minimal segment length triggering resampling */ -#define LPERIODIC 1.0 /* lines longer than this are not drawn (useful for Sinai billiard) */ -#define LCUT 1000.0 /* controls the max size of segments not considered as being cut */ +#define LPERIODIC 0.1 /* lines longer than this are not drawn (useful for Sinai billiard) */ +#define LCUT 2.0 /* controls the max size of segments not considered as being cut */ #define DMIN 0.02 /* minimal distance to boundary for triggering resampling */ #define CYCLE 0 /* set to 1 for closed curve (start in all directions) */ #define ORDER_COLORS 1 /* set to 1 if colors should be drawn in order */ /* color and other graphical parameters */ -#define NCOLORS 10 /* number of colors */ +#define NCOLORS 16 /* number of colors */ #define COLORSHIFT 200 /* hue of initial color */ +#define RAINBOW_COLOR 1 /* set to 1 to use different colors for all particles */ #define NSEG 100 /* number of segments of boundary */ #define BILLIARD_WIDTH 4 /* width of billiard */ #define FRONT_WIDTH 3 /* width of wave front */ @@ -120,6 +118,7 @@ #define DPI 6.283185307 #define PID 1.570796327 +#include "global_particles.c" #include "sub_part_billiard.c" @@ -394,8 +393,11 @@ double *configs[NPARTMAX]; if (configs[i][2]<0.0) { vbilliard(configs[i]); - color[i]++; - if (color[i] >= NCOLORS) color[i] -= NCOLORS; + if (!RAINBOW_COLOR) + { + color[i]++; + if (color[i] >= NCOLORS) color[i] -= NCOLORS; + } } configs[i][2] += DPHI; @@ -449,7 +451,8 @@ void animation() for (i=0; i 0) compute_gradient(phi, nablax, nablay); /* compute the position of origins of field lines */ @@ -371,25 +331,24 @@ int time; printf("computing linex\n"); - x1 = sqrt(3.58); - y1 = 0.0; + x1 = LAMBDA + MU*1.01; + y1 = 1.0; linex[0] = x1; liney[0] = y1; dangle = DPI/((double)(N_FIELD_LINES*FIELD_LINE_FACTOR)); for (i = 1; i < N_FIELD_LINES*FIELD_LINE_FACTOR; i++) { -// angle = PID + (double)i*dangle; angle = (double)i*dangle; - x2 = sqrt(3.58)*cos(angle); - y2 = sqrt(1.18)*sin(angle); + x2 = LAMBDA + MU*1.01*cos(angle); + y2 = 0.5 + MU*1.01*sin(angle); linex[i] = x2; liney[i] = y2; distance[i-1] = module2(x2-x1,y2-y1); x1 = x2; y1 = y2; } - distance[N_FIELD_LINES*FIELD_LINE_FACTOR - 1] = module2(x2-sqrt(3.58),y2); + distance[N_FIELD_LINES*FIELD_LINE_FACTOR - 1] = module2(x2-LAMBDA,y2-0.5); } dx = (XMAX-XMIN)/((double)NX); @@ -404,7 +363,6 @@ int time; value = module2(nablax[i][j], nablay[i][j]); } -// if ((phi[i][j] - T_IN)*(phi[i][j] - T_OUT) < 0.0) if (xy_in[i][j] == 1) { color_scheme(COLOR_SCHEME, value, scale, time, rgb); @@ -431,18 +389,14 @@ int time; else integral[i] = intens; } deltaintens = integral[N_FIELD_LINES*FIELD_LINE_FACTOR-1]/((double)N_FIELD_LINES); -// deltaintens = integral[N_FIELD_LINES*FIELD_LINE_FACTOR-1]/((double)N_FIELD_LINES + 1.0); -// deltaintens = integral[N_FIELD_LINES*FIELD_LINE_FACTOR-1]/((double)N_FIELD_LINES); // printf("delta = %.5lg\n", deltaintens); i = 0; -// draw_field_line(linex[0], liney[0], nablax, nablay, 0.00002, 100000); draw_field_line(linex[0], liney[0], xy_in, nablax, nablay, 0.00002, 100000); for (j = 1; j < N_FIELD_LINES+1; j++) { while ((integral[i] <= j*deltaintens)&&(i < N_FIELD_LINES*FIELD_LINE_FACTOR)) i++; -// draw_field_line(linex[i], liney[i], nablax, nablay, 0.00002, 100000); draw_field_line(linex[i], liney[i], xy_in, nablax, nablay, 0.00002, 100000); counter++; } @@ -459,12 +413,101 @@ int time; -void evolve_wave(phi, xy_in) +void evolve_wave_half(phi_in, phi_out, xy_in) +/* time step of field evolution */ + double *phi_in[NX], *phi_out[NX]; short int *xy_in[NX]; +{ + int i, j, iplus, iminus, jplus, jminus; + double delta1, delta2, x, y; + + #pragma omp parallel for private(i,j,iplus,iminus,jplus,jminus,delta1,delta2,x,y) + for (i=0; i0)&&(i0)&&(j VMAX) phi_out[i][j] = VMAX; + if (phi_out[i][j] < -VMAX) phi_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(phi, phi_tmp, xy_in) +/* 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_tmp, phi, xy_in); +} + + +void old_evolve_wave(phi, xy_in) /* time step of field evolution */ double *phi[NX]; short int *xy_in[NX]; { int i, j, iplus, iminus, jplus, jminus; - double delta1, delta2, x, y, *newphi[NX];; + double delta1, delta2, x, y, *newphi[NX]; for (i=0; i 2000 */ // julia_x = 0.5*(cosj*(1.0 - 0.5*cosj) + 0.5*sinj*sinj); // julia_y = 0.5*sinj*(1.0-cosj); init_julia_set(phi, xy_in); @@ -669,7 +708,7 @@ short int *xy_in[NX]; void animation() { double time, scale, dx, var, jangle, cosj, sinj; - double *phi[NX]; + double *phi[NX], *phi_tmp[NX]; short int *xy_in[NX]; int i, j, s; @@ -677,6 +716,7 @@ void animation() for (i=0; i 1) dalpha = (angle2 - angle1)/((double)(NPART-1)); + else dalpha = 0.0; for (i=0; i= NCOLORS) color[i] -= NCOLORS; + if (!RAINBOW_COLOR) + { + color[i]++; + if (color[i] >= NCOLORS) color[i] -= NCOLORS; + } } configs[i][2] += DPHI; @@ -280,36 +282,39 @@ double *configs[NPARTMAX]; glEnd (); /* taking care of boundary conditions - only needed for periodic boundary conditions */ - if (SCALING_FACTOR*x2 > XMAX) + if (PERIODIC_BC) { - glBegin(GL_LINE_STRIP); - glVertex2d(SCALING_FACTOR*(x1+XMIN-XMAX), SCALING_FACTOR*y1); - glVertex2d(SCALING_FACTOR*(x2+XMIN-XMAX), SCALING_FACTOR*y2); - glEnd (); - } + if (SCALING_FACTOR*x2 > XMAX) + { + glBegin(GL_LINE_STRIP); + glVertex2d(SCALING_FACTOR*(x1+XMIN-XMAX), SCALING_FACTOR*y1); + glVertex2d(SCALING_FACTOR*(x2+XMIN-XMAX), SCALING_FACTOR*y2); + glEnd (); + } - if (SCALING_FACTOR*x2 < XMIN) - { - glBegin(GL_LINE_STRIP); - glVertex2d(SCALING_FACTOR*(x1-XMIN+XMAX), SCALING_FACTOR*y1); - glVertex2d(SCALING_FACTOR*(x2-XMIN+XMAX), SCALING_FACTOR*y2); - glEnd (); - } + if (SCALING_FACTOR*x2 < XMIN) + { + glBegin(GL_LINE_STRIP); + glVertex2d(SCALING_FACTOR*(x1-XMIN+XMAX), SCALING_FACTOR*y1); + glVertex2d(SCALING_FACTOR*(x2-XMIN+XMAX), SCALING_FACTOR*y2); + glEnd (); + } - if (SCALING_FACTOR*y2 > YMAX) - { - glBegin(GL_LINE_STRIP); - glVertex2d(SCALING_FACTOR*x1, SCALING_FACTOR*(y1+YMIN-YMAX)); - glVertex2d(SCALING_FACTOR*x2, SCALING_FACTOR*(y2+YMIN-YMAX)); - glEnd (); - } + if (SCALING_FACTOR*y2 > YMAX) + { + glBegin(GL_LINE_STRIP); + glVertex2d(SCALING_FACTOR*x1, SCALING_FACTOR*(y1+YMIN-YMAX)); + glVertex2d(SCALING_FACTOR*x2, SCALING_FACTOR*(y2+YMIN-YMAX)); + glEnd (); + } - if (SCALING_FACTOR*y2 < YMIN) - { - glBegin(GL_LINE_STRIP); - glVertex2d(SCALING_FACTOR*x1, SCALING_FACTOR*(y1+YMAX-YMIN)); - glVertex2d(SCALING_FACTOR*x2, SCALING_FACTOR*(y2+YMAX-YMIN)); - glEnd (); + if (SCALING_FACTOR*y2 < YMIN) + { + glBegin(GL_LINE_STRIP); + glVertex2d(SCALING_FACTOR*x1, SCALING_FACTOR*(y1+YMAX-YMIN)); + glVertex2d(SCALING_FACTOR*x2, SCALING_FACTOR*(y2+YMAX-YMIN)); + glEnd (); + } } } @@ -343,11 +348,14 @@ double *configs[NPARTMAX]; { if (configs[i][2]<0.0) { +// printf("reflecting particle %i\n", i); c = vbilliard(configs[i]); // if (c>=0) color[i]++; - color[i]++; - if (color[i] >= NCOLORS) color[i] -= NCOLORS; - + if (!RAINBOW_COLOR) + { + color[i]++; + if (color[i] >= NCOLORS) color[i] -= NCOLORS; + } } configs[i][2] += DPHI; @@ -363,7 +371,74 @@ double *configs[NPARTMAX]; } +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() @@ -379,19 +454,24 @@ void animation() active = malloc(sizeof(int)*(NPARTMAX)); for (i=0; i0)&&(i0)&&(j VMAX) newphi[i][j] = VMAX; - if (newphi[i][j] < -VMAX) newphi[i][j] = -VMAX; - if (newpsi[i][j] > VMAX) newpsi[i][j] = VMAX; - if (newpsi[i][j] < -VMAX) newpsi[i][j] = -VMAX; + 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; } } } } - - for (i=0; i 0) + { + glLineWidth(2); + x = 1.0/((double)MRATIO); + draw_rotated_rectangle(x, x, -x, -x); + } + + /* level 2 */ + if (MDEPTH > 1) + { + glLineWidth(1); + mr2 = MRATIO*MRATIO; + l = 2.0/((double)mr2); + + for (i=0; i 2) + { + glLineWidth(1); + l = 2.0/((double)(mr2*MRATIO)); + + for (i=0; i NY/2) color_scheme(COLOR_SCHEME, phi[i][j], scale, time, rgb); + else color_scheme(COLOR_SCHEME, compute_energy(phi, psi, xy_in, i, j), scale, time, rgb); + } glColor3f(rgb[0], rgb[1], rgb[2]); glVertex2i(i, j); @@ -303,14 +338,25 @@ void evolve_wave_half(phi_in, psi_in, phi_out, psi_out, xy_in) int i, j, iplus, iminus, jplus, jminus; double delta, x, y, c, cc; - c = COURANT; - cc = courant2; +// c = COURANT; +// cc = courant2; #pragma omp parallel for private(i,j,iplus,iminus,jplus,jminus,delta,x,y) for (i=0; i0)&&(i0)&&(j0)&&(i VMAX) phi[i][j] = VMAX; - if (phi[i][j] < -VMAX) phi[i][j] = -VMAX; - if (psi[i][j] > VMAX) psi[i][j] = VMAX; - if (psi[i][j] < -VMAX) psi[i][j] = -VMAX; - } - } - } - } -// printf("phi(0,0) = %.3lg, psi(0,0) = %.3lg\n", phi[NX/2][NY/2], psi[NX/2][NY/2]); -} double compute_variance(phi, psi, xy_in) @@ -448,6 +472,7 @@ double compute_variance(phi, psi, xy_in) } + void animation() { double time, scale; @@ -464,12 +489,18 @@ void animation() psi_tmp[i] = (double *)malloc(NY*sizeof(double)); xy_in[i] = (short int *)malloc(NY*sizeof(short int)); } + + /* initialise positions and radii of circles */ + if (B_DOMAIN == D_CIRCLES) init_circle_config(); courant2 = COURANT*COURANT; + courantb2 = COURANTB*COURANTB; /* initialize wave with a drop at one point, zero elsewhere */ -// init_wave_flat(phi, psi, xy_in); - init_wave(0.0, 0.0, phi, psi, xy_in); + init_planar_wave(XMIN + 0.01, 0.0, phi, psi, xy_in); +// init_planar_wave(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); @@ -487,7 +518,7 @@ void animation() sleep(SLEEP1); - for (i=0; i<=NSTEPS; i++) + for (i=0; i<=INITIAL_TIME + NSTEPS; i++) { //printf("%d\n",i); /* compute the variance of the field to adjust color scheme */ @@ -499,16 +530,12 @@ void animation() } else scale = 1.0; -// /* TO BE ADAPTED */ -// scale = 1.0; - draw_wave(phi, psi, xy_in, scale, i); for (j=0; j= 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 */