Add files via upload

This commit is contained in:
Nils Berglund 2022-10-18 23:28:20 +02:00 committed by GitHub
parent 49b0b4a646
commit 46a381dcf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 3484 additions and 543 deletions

View File

@ -122,12 +122,21 @@
#define SLEEP2 100 /* final sleeping time */ #define SLEEP2 100 /* final sleeping time */
#define END_FRAMES 25 /* number of frames at end of movie */ #define END_FRAMES 25 /* number of frames at end of movie */
#define NXMAZE 8 /* width of maze */
#define NYMAZE 8 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 58 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define PI 3.141592654 #define PI 3.141592654
#define DPI 6.283185307 #define DPI 6.283185307
#define PID 1.570796327 #define PID 1.570796327
#include "global_particles.c" #include "global_particles.c"
#include "sub_maze.c"
#include "sub_part_billiard.c" #include "sub_part_billiard.c"

View File

@ -23,6 +23,7 @@
#define E_RPS 4 /* rock-paper-scissors equation */ #define E_RPS 4 /* rock-paper-scissors equation */
#define E_RPSLZ 41 /* rock-paper-scissors-lizard-Spock equation */ #define E_RPSLZ 41 /* rock-paper-scissors-lizard-Spock equation */
#define E_SCHRODINGER 5 /* Schrodinger equation */ #define E_SCHRODINGER 5 /* Schrodinger equation */
#define E_EULER_INCOMP 6 /* incompressigle Euler equation */
/* Choice of potential */ /* Choice of potential */
@ -32,6 +33,12 @@
#define POT_DOUBLE_COULOMB 4 /* sum of Coulomb potentials located at focal points of ellipse */ #define POT_DOUBLE_COULOMB 4 /* sum of Coulomb potentials located at focal points of ellipse */
#define POT_FERMIONS 5 /* two interacting 1D fermions */ #define POT_FERMIONS 5 /* two interacting 1D fermions */
#define POT_FERMIONS_PERIODIC 6 /* two interacting 1D fermions on the circle */ #define POT_FERMIONS_PERIODIC 6 /* two interacting 1D fermions on the circle */
#define POT_MAZE 7 /* higher potential on walls of a maze */
/* Choice of vector potential */
#define VPOT_CONSTANT_FIELD 100 /* constant magnetic field */
#define VPOT_AHARONOV_BOHM 101 /* single flux line for Aharonov-Bohm effect */
/* plot types used by rde */ /* plot types used by rde */
@ -56,6 +63,11 @@
#define Z_THETA_RPSLZ 41 /* polar angle */ #define Z_THETA_RPSLZ 41 /* polar angle */
#define Z_NORM_GRADIENT_RPSLZ 42 /* gradient of polar angle */ #define Z_NORM_GRADIENT_RPSLZ 42 /* gradient of polar angle */
/* for Euler equation */
#define Z_EULER_VORTICITY 50 /* vorticity of velocity */
#define Z_EULER_LOG_VORTICITY 51 /* log of vorticity of velocity */
#define Z_EULER_VORTICITY_ASYM 52 /* vorticity of velocity */
/* macros to avoid unnecessary computations in 3D plots */ /* macros to avoid unnecessary computations in 3D plots */
#define COMPUTE_THETA ((cplot == Z_POLAR)||(cplot == Z_NORM_GRADIENT)||(cplot == Z_ANGLE_GRADIENT)||(cplot == Z_NORM_GRADIENT_INTENSITY)||(cplot == Z_VORTICITY)||(cplot == Z_VORTICITY_ABS)) #define COMPUTE_THETA ((cplot == Z_POLAR)||(cplot == Z_NORM_GRADIENT)||(cplot == Z_ANGLE_GRADIENT)||(cplot == Z_NORM_GRADIENT_INTENSITY)||(cplot == Z_VORTICITY)||(cplot == Z_VORTICITY_ABS))
@ -104,6 +116,7 @@ typedef struct
double field_arg; /* argument of field or gradient */ double field_arg; /* argument of field or gradient */
double curl; /* curl of field */ double curl; /* curl of field */
double cos_angle; /* cos of angle between normal vector and direction of light */ double cos_angle; /* cos of angle between normal vector and direction of light */
double log_vorticity; /* logarithm of vorticity (for Euler equation) */
double rgb[3]; /* RGB color code */ double rgb[3]; /* RGB color code */
double *p_zfield[2]; /* pointers to z field (second pointer for option DOUBLE_MOVIE) */ double *p_zfield[2]; /* pointers to z field (second pointer for option DOUBLE_MOVIE) */
double *p_cfield[2]; /* pointers to color field (second pointer for option DOUBLE_MOVIE) */ double *p_cfield[2]; /* pointers to color field (second pointer for option DOUBLE_MOVIE) */

View File

@ -14,7 +14,8 @@
#define NMAXCIRCLES 20000 /* total number of circles/polygons (must be at least NCX*NCY for square grid) */ #define NMAXCIRCLES 20000 /* total number of circles/polygons (must be at least NCX*NCY for square grid) */
#define MAXNEIGH 20 /* max number of neighbours kept in memory */ #define MAXNEIGH 20 /* max number of neighbours kept in memory */
#define NMAXOBSTACLES 100 /* max number of obstacles */ #define NMAXOBSTACLES 100 /* max number of obstacles */
#define NMAXSEGMENTS 1000 /* max number of repelling segments */ #define NMAXSEGMENTS 1000 /* max number of repelling segments */
#define NMAXGROUPS 50 /* max number of groups of segments */
#define C_SQUARE 0 /* square grid of circles */ #define C_SQUARE 0 /* square grid of circles */
#define C_HEX 1 /* hexagonal/triangular grid of circles */ #define C_HEX 1 /* hexagonal/triangular grid of circles */
@ -60,6 +61,9 @@
#define S_DAM 12 /* segments forming a dam that can break */ #define S_DAM 12 /* segments forming a dam that can break */
#define S_DAM_WITH_HOLE 13 /* segments forming a dam in which a hole can open */ #define S_DAM_WITH_HOLE 13 /* segments forming a dam in which a hole can open */
#define S_DAM_WITH_HOLE_AND_RAMP 14 /* segments forming a dam in which a hole can open */ #define S_DAM_WITH_HOLE_AND_RAMP 14 /* segments forming a dam in which a hole can open */
#define S_MAZE 15 /* segments forming a maze */
#define S_EXT_RECTANGLE 16 /* particles outside a rectangle */
#define S_DAM_BRICKS 17 /* dam made of several bricks */
/* particle interaction */ /* particle interaction */
@ -102,6 +106,12 @@
#define G_INCREASE_RELEASE 1 /* slow increase and instant release */ #define G_INCREASE_RELEASE 1 /* slow increase and instant release */
#define G_INCREASE_DECREASE 2 /* slow increase an decrease */ #define G_INCREASE_DECREASE 2 /* slow increase an decrease */
/* Rocket shapes */
#define RCK_DISC 0 /* disc-shaped rocket */
#define RCK_RECT 1 /* rectangular rocket */
#define RCK_RECT_HAT 2 /* rectangular rocket with a hat */
/* Nozzle shapes */ /* Nozzle shapes */
#define NZ_STRAIGHT 0 /* straight nozzle */ #define NZ_STRAIGHT 0 /* straight nozzle */
@ -109,6 +119,7 @@
#define NZ_GLAS 2 /* glas-shaped nozzle */ #define NZ_GLAS 2 /* glas-shaped nozzle */
#define NZ_CONE 3 /* cone-shaped nozzle */ #define NZ_CONE 3 /* cone-shaped nozzle */
#define NZ_TRUMPET 4 /* trumpet-shaped nozzle */ #define NZ_TRUMPET 4 /* trumpet-shaped nozzle */
#define NZ_BROAD 5 /* broad straight nozzle */
#define NZ_NONE 99 /* no nozzle */ #define NZ_NONE 99 /* no nozzle */
/* Plot types */ /* Plot types */
@ -218,6 +229,7 @@ typedef struct
typedef struct typedef struct
{ {
double x1, x2, y1, y2; /* extremities of segment */ double x1, x2, y1, y2; /* extremities of segment */
double xc, yc; /* mid-point of segment */
double nx, ny; /* normal vector */ double nx, ny; /* normal vector */
double c; /* constant term in cartesian eq nx*x + ny*y = c */ double c; /* constant term in cartesian eq nx*x + ny*y = c */
double length; /* length of segment */ double length; /* length of segment */
@ -230,6 +242,7 @@ typedef struct
double nx0, ny0; /* initial normal vector */ double nx0, ny0; /* initial normal vector */
double angle01, angle02; /* initial values of angles in which concave corners repel */ double angle01, angle02; /* initial values of angles in which concave corners repel */
double fx, fy; /* x and y-components of force on segment */ double fx, fy; /* x and y-components of force on segment */
double torque; /* torque on segment with respect to its center */
short int inactivate; /* set to 1 for segment to become inactive at time SEGMENT_DEACTIVATION_TIME */ short int inactivate; /* set to 1 for segment to become inactive at time SEGMENT_DEACTIVATION_TIME */
} t_segment; } t_segment;
@ -238,6 +251,23 @@ typedef struct
double xc, yc; /* center of circle */ double xc, yc; /* center of circle */
} t_tracer; } t_tracer;
typedef struct
{
double xc, yc; /* center of mass of obstacle */
double angle; /* orientation of obstacle */
double vx, vy; /* velocity of center of mass */
double omega; /* angular velocity */
double mass; /* mass of obstacle */
double moment_inertia; /* moment of inertia */
} t_group_segments;
int ncircles, nobstacles, nsegments, counter = 0; typedef struct
{
double xc, yc; /* coordinates of centers of mass */
double vx, vy; /* velocities */
double omega; /* angular velocity */
} t_group_data;
int ncircles, nobstacles, nsegments, ngroups = 1, counter = 0;

View File

@ -78,6 +78,7 @@ double x_shooter = -0.2, y_shooter = -0.6, x_target = 0.4, y_target = 0.7;
#define P_TOKA_PRIME 6 /* Tokarsky room made of 86 triangles */ #define P_TOKA_PRIME 6 /* Tokarsky room made of 86 triangles */
#define P_TREE 7 /* pine tree */ #define P_TREE 7 /* pine tree */
#define P_TOKA_NONSELF 8 /* Tokarsky non-self-unilluminable room */ #define P_TOKA_NONSELF 8 /* Tokarsky non-self-unilluminable room */
#define P_MAZE 10 /* maze */
/* Color palettes */ /* Color palettes */

View File

@ -61,6 +61,10 @@
#define D_GROOVE 48 /* groove array supposed to induce polaritons */ #define D_GROOVE 48 /* groove array supposed to induce polaritons */
#define D_FABRY_PEROT 49 /* Fabry-Perrot cavity (in fact simply a vertical slab) */ #define D_FABRY_PEROT 49 /* Fabry-Perrot cavity (in fact simply a vertical slab) */
#define D_LSHAPE 50 /* L-shaped billiard (surface of genus 2) */ #define D_LSHAPE 50 /* L-shaped billiard (surface of genus 2) */
#define D_WAVEGUIDE 51 /* wave guide */
#define D_WAVEGUIDE_W 52 /* W-shaped wave guide */
#define D_MAZE 53 /* maze */
#define D_MAZE_CLOSED 54 /* closed maze */
#define NMAXCIRCLES 10000 /* total number of circles/polygons (must be at least NCX*NCY for square grid) */ #define NMAXCIRCLES 10000 /* total number of circles/polygons (must be at least NCX*NCY for square grid) */
#define NMAXPOLY 50000 /* maximal number of vertices of polygonal lines (for von Koch et al) */ #define NMAXPOLY 50000 /* maximal number of vertices of polygonal lines (for von Koch et al) */
@ -192,6 +196,12 @@ typedef struct
double posi, posj; /* (i,j) coordinates of vertex */ double posi, posj; /* (i,j) coordinates of vertex */
} t_vertex; } t_vertex;
typedef struct
{
double x1, y1, x2, y2; /* (x,y) coordinates of vertices */
double posi1, posj1, posi2, posj2; /* (i,j) coordinates of vertices */
} t_rectangle;
typedef struct typedef struct
{ {
int nneighb; /* number of neighbours to compute Laplacian */ int nneighb; /* number of neighbours to compute Laplacian */
@ -201,10 +211,12 @@ typedef struct
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 */
int npolyline = NMAXPOLY; /* actual length of polyline */ int npolyline = NMAXPOLY; /* actual length of polyline */
int npolyrect = NMAXPOLY; /* actual number of polyrect */
t_circle circles[NMAXCIRCLES]; /* circular scatterers */ t_circle circles[NMAXCIRCLES]; /* circular scatterers */
t_polygon polygons[NMAXCIRCLES]; /* polygonal scatterers */ t_polygon polygons[NMAXCIRCLES]; /* polygonal scatterers */
t_vertex polyline[NMAXPOLY]; /* vertices of polygonal line */ t_vertex polyline[NMAXPOLY]; /* vertices of polygonal line */
t_rectangle polyrect[NMAXPOLY]; /* vertices of rectangles */
/* the same for comparisons between different domains */ /* the same for comparisons between different domains */
int ncircles_b = NMAXCIRCLES; /* actual number of circles, can be decreased e.g. for random patterns */ int ncircles_b = NMAXCIRCLES; /* actual number of circles, can be decreased e.g. for random patterns */

View File

@ -16,6 +16,8 @@
#define BC_TRIANGLE_SITE_DIRICHLET 20 /* triangular lattice, site percolation, Dirichlet b.c. */ #define BC_TRIANGLE_SITE_DIRICHLET 20 /* triangular lattice, site percolation, Dirichlet b.c. */
#define BC_POISSON_DISC 50 /* Poisson disc (blue noise) lattice */ #define BC_POISSON_DISC 50 /* Poisson disc (blue noise) lattice */
#define BC_CUBIC_DIRICHLET 100 /* cubic lattice */
/* Plot types */ /* Plot types */
#define PLOT_SQUARES 0 /* plot squares */ #define PLOT_SQUARES 0 /* plot squares */
@ -25,6 +27,14 @@
#define PLOT_HEX_BONDS 4 /* plot edges of hexagonal lattice */ #define PLOT_HEX_BONDS 4 /* plot edges of hexagonal lattice */
#define PLOT_POISSON_DISC 5 /* plot Poisson disc process */ #define PLOT_POISSON_DISC 5 /* plot Poisson disc process */
#define PLOT_CUBES 10 /* plot cubes */
/* 3D representation */
#define REP_AXO_3D 0 /* linear projection (axonometry) */
#define REP_PROJ_3D 1 /* projection on plane orthogonal to observer line of sight */
/* Color schemes */ /* Color schemes */
#define C_LUM 0 /* color scheme modifies luminosity (with slow drift of hue) */ #define C_LUM 0 /* color scheme modifies luminosity (with slow drift of hue) */

14
heat.c
View File

@ -35,7 +35,7 @@
#include <tiffio.h> /* Sam Leffler's libtiff library. */ #include <tiffio.h> /* Sam Leffler's libtiff library. */
#include <omp.h> #include <omp.h>
#define MOVIE 1 /* set to 1 to generate movie */ #define MOVIE 0 /* set to 1 to generate movie */
/* General geometrical parameters */ /* General geometrical parameters */
@ -188,7 +188,19 @@
#define AMPLITUDE 0.8 /* amplitude of periodic excitation */ #define AMPLITUDE 0.8 /* amplitude of periodic excitation */
/* end of constants only used by wave_billiard and wave_3d */ /* end of constants only used by wave_billiard and wave_3d */
/* for compatibility with sub_wave and sub_maze */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define ADD_POTENTIAL 0
#define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
#include "global_pdes.c" #include "global_pdes.c"
#include "sub_maze.c"
#include "sub_wave.c" #include "sub_wave.c"

View File

@ -49,36 +49,48 @@
#define WINWIDTH 1280 /* window width */ #define WINWIDTH 1280 /* window width */
#define WINHEIGHT 720 /* window height */ #define WINHEIGHT 720 /* window height */
#define XMIN -2.0 // #define XMIN -2.3
#define XMAX 2.0 /* x interval */ // #define XMAX 3.7 /* x interval */
#define YMIN -1.125 // #define YMIN -1.6875
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */ // #define YMAX 1.6875 /* y interval for 9/16 aspect ratio */
#define INITXMIN -2.0 #define XMIN -3.3
#define INITXMAX -0.04 /* x interval for initial condition */ #define XMAX 4.7 /* x interval */
#define INITYMIN -1.125 #define YMIN -2.25
#define INITYMAX 0.65 /* y interval for initial condition */ #define YMAX 2.25 /* y interval for 9/16 aspect ratio */
#define BCXMIN -2.05 #define INITXMIN -2.5
#define BCXMAX 2.0 /* x interval for boundary condition */ #define INITXMAX 2.5 /* x interval for initial condition */
#define BCYMIN -1.125 #define INITYMIN -1.7
#define BCYMAX 1.25 /* y interval for boundary condition */ #define INITYMAX 0.7 /* y interval for initial condition */
// #define BCXMIN -3.1
// #define BCXMAX 3.1 /* x interval for boundary condition */
// #define BCYMIN -4.5
// #define BCYMAX 4.5 /* y interval for boundary condition */
#define BCXMIN -5.1
#define BCXMAX 6.1 /* x interval for boundary condition */
#define BCYMIN -6.5
#define BCYMAX 44.0 /* y interval for boundary condition */
#define OBSXMIN -2.0 #define OBSXMIN -2.0
#define OBSXMAX 2.0 /* x interval for motion of obstacle */ #define OBSXMAX 2.0 /* x interval for motion of obstacle */
#define CIRCLE_PATTERN 1 /* pattern of circles, see list in global_ljones.c */ #define CIRCLE_PATTERN 8 /* pattern of circles, see list in global_ljones.c */
#define ADD_FIXED_OBSTACLES 0 /* set to 1 do add fixed circular obstacles */ #define ADD_FIXED_OBSTACLES 0 /* set to 1 do add fixed circular obstacles */
#define OBSTACLE_PATTERN 3 /* pattern of obstacles, see list in global_ljones.c */ #define OBSTACLE_PATTERN 3 /* pattern of obstacles, see list in global_ljones.c */
#define ADD_FIXED_SEGMENTS 1 /* set to 1 to add fixed segments as obstacles */ #define ADD_FIXED_SEGMENTS 1 /* set to 1 to add fixed segments as obstacles */
#define SEGMENT_PATTERN 14 /* pattern of repelling segments, see list in global_ljones.c */ #define SEGMENT_PATTERN 102 /* pattern of repelling segments, see list in global_ljones.c */
#define ROCKET_SHAPE 2 /* shape of rocket combustion chamber, see list in global_ljones.c */
#define ROCKET_SHAPE_B 2 /* shape of second rocket */
#define NOZZLE_SHAPE 1 /* shape of nozzle, see list in global_ljones.c */ #define NOZZLE_SHAPE 1 /* shape of nozzle, see list in global_ljones.c */
#define NOZZLE_SHAPE_B 2 /* shape of nozzle for second rocket, see list in global_ljones.c */ #define NOZZLE_SHAPE_B 0 /* shape of nozzle for second rocket, see list in global_ljones.c */
#define TWO_TYPES 0 /* set to 1 to have two types of particles */ #define TWO_TYPES 0 /* set to 1 to have two types of particles */
#define TPYE_PROPORTION 0.7 /* proportion of particles of first type */ #define TPYE_PROPORTION 0.5 /* proportion of particles of first type */
#define SYMMETRIZE_FORCE 1 /* set to 1 to symmetrize two-particle interaction, only needed if particles are not all the same */ #define SYMMETRIZE_FORCE 1 /* set to 1 to symmetrize two-particle interaction, only needed if particles are not all the same */
#define CENTER_PX 0 /* set to 1 to center horizontal momentum */ #define CENTER_PX 0 /* set to 1 to center horizontal momentum */
#define CENTER_PY 0 /* set to 1 to center vertical momentum */ #define CENTER_PY 0 /* set to 1 to center vertical momentum */
@ -91,12 +103,15 @@
#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 100 /* number of points for Poisson C_RAND_POISSON arrangement */ #define NPOISSON 100 /* number of points for Poisson C_RAND_POISSON arrangement */
#define PDISC_DISTANCE 2.5 /* minimal distance in Poisson disc process, controls density of particles */ #define PDISC_DISTANCE 2.7 /* minimal distance in Poisson disc process, controls density of particles */
#define PDISC_CANDIDATES 50 /* number of candidates in construction of Poisson disc process */ #define PDISC_CANDIDATES 100 /* number of candidates in construction of Poisson disc process */
#define RANDOM_POLY_ANGLE 0 /* set to 1 to randomize angle of polygons */ #define RANDOM_POLY_ANGLE 0 /* set to 1 to randomize angle of polygons */
#define LAMBDA 0.8 /* parameter controlling the dimensions of domain */ #define LAMBDA 0.8 /* parameter controlling the dimensions of domain */
#define MU 0.0075 /* parameter controlling radius of particles */ // #define MU 0.02 /* parameter controlling radius of particles */
// #define MU 0.015 /* parameter controlling radius of particles */
#define MU 0.009 /* parameter controlling radius of particles */
// #define MU 0.012 /* parameter controlling radius of particles */
#define MU_B 0.018 /* parameter controlling radius of particles of second type */ #define MU_B 0.018 /* parameter controlling radius of particles of second type */
#define NPOLY 25 /* number of sides of polygon */ #define NPOLY 25 /* number of sides of polygon */
#define APOLY 0.666666666 /* angle by which to turn polygon, in units of Pi/2 */ #define APOLY 0.666666666 /* angle by which to turn polygon, in units of Pi/2 */
@ -119,11 +134,13 @@
/* Parameters for length and speed of simulation */ /* Parameters for length and speed of simulation */
#define NSTEPS 3500 /* number of frames of movie */ #define NSTEPS 3300 /* number of frames of movie */
#define NVID 60 /* number of iterations between images displayed on screen */ // #define NSTEPS 2000 /* number of frames of movie */
#define NVID 100 /* number of iterations between images displayed on screen */
#define NSEG 250 /* number of segments of boundary */ #define NSEG 250 /* number of segments of boundary */
#define INITIAL_TIME 0 /* time after which to start saving frames */ #define INITIAL_TIME 10 /* time after which to start saving frames */
#define OBSTACLE_INITIAL_TIME 10 /* time after which to start moving obstacle */ // #define OBSTACLE_INITIAL_TIME 10 /* time after which to start moving obstacle */
#define OBSTACLE_INITIAL_TIME 200 /* time after which to start moving obstacle */
#define BOUNDARY_WIDTH 1 /* width of particle boundary */ #define BOUNDARY_WIDTH 1 /* width of particle boundary */
#define LINK_WIDTH 2 /* width of links between particles */ #define LINK_WIDTH 2 /* width of links between particles */
#define CONTAINER_WIDTH 4 /* width of container boundary */ #define CONTAINER_WIDTH 4 /* width of container boundary */
@ -137,16 +154,17 @@
/* Boundary conditions, see list in global_ljones.c */ /* Boundary conditions, see list in global_ljones.c */
#define BOUNDARY_COND 0 #define BOUNDARY_COND 20
/* Plot type, see list in global_ljones.c */ /* Plot type, see list in global_ljones.c */
#define PLOT 11 #define PLOT 0
#define PLOT_B 0 /* plot type for second movie */ #define PLOT_B 8 /* plot type for second movie */
#define DRAW_BONDS 1 /* set to 1 to draw bonds between neighbours */ #define DRAW_BONDS 0 /* set to 1 to draw bonds between neighbours */
#define COLOR_BONDS 1 /* set to 1 to color bonds according to length */ #define COLOR_BONDS 1 /* set to 1 to color bonds according to length */
#define FILL_TRIANGLES 1 /* set to 1 to fill triangles between neighbours */ #define FILL_TRIANGLES 1 /* set to 1 to fill triangles between neighbours */
#define COLOR_SEG_GROUPS 1 /* set to 1 to collor segment groups differently */
/* Color schemes */ /* Color schemes */
@ -173,36 +191,36 @@
#define ENERGY_HUE_MAX 50.0 /* color of saturated particle */ #define ENERGY_HUE_MAX 50.0 /* color of saturated particle */
#define PARTICLE_HUE_MIN 359.0 /* color of original particle */ #define PARTICLE_HUE_MIN 359.0 /* color of original particle */
#define PARTICLE_HUE_MAX 0.0 /* color of saturated particle */ #define PARTICLE_HUE_MAX 0.0 /* color of saturated particle */
#define PARTICLE_EMAX 1.0e3 /* energy of particle with hottest color */ #define PARTICLE_EMAX 2.0e2 /* energy of particle with hottest color */
#define HUE_TYPE0 280.0 /* hue of particles of type 0 */ #define HUE_TYPE0 70.0 /* hue of particles of type 0 */
#define HUE_TYPE1 70.0 /* hue of particles of type 1 */ #define HUE_TYPE1 280.0 /* hue of particles of type 1 */
#define HUE_TYPE2 70.0 /* hue of particles of type 2 */ #define HUE_TYPE2 .0 /* hue of particles of type 2 */
#define HUE_TYPE3 210.0 /* hue of particles of type 3 */ #define HUE_TYPE3 210.0 /* hue of particles of type 3 */
#define RANDOM_RADIUS 0 /* set to 1 for random circle radius */ #define RANDOM_RADIUS 0 /* set to 1 for random circle radius */
#define DT_PARTICLE 3.0e-6 /* time step for particle displacement */ #define DT_PARTICLE 3.0e-6 /* time step for particle displacement */
#define KREPEL 12.0 /* constant in repelling force between particles */ #define KREPEL 12.0 /* constant in repelling force between particles */
#define EQUILIBRIUM_DIST 3.5 /* Lennard-Jones equilibrium distance */ #define EQUILIBRIUM_DIST 4.5 /* Lennard-Jones equilibrium distance */
#define EQUILIBRIUM_DIST_B 3.5 /* Lennard-Jones equilibrium distance for second type of particle */ #define EQUILIBRIUM_DIST_B 3.5 /* Lennard-Jones equilibrium distance for second type of particle */
#define REPEL_RADIUS 20.0 /* radius in which repelling force acts (in units of particle radius) */ #define REPEL_RADIUS 20.0 /* radius in which repelling force acts (in units of particle radius) */
#define DAMPING 10.0 /* damping coefficient of particles */ #define DAMPING 5.0 /* damping coefficient of particles */
#define PARTICLE_MASS 1.0 /* mass of particle of radius MU */ #define PARTICLE_MASS 1.0 /* mass of particle of radius MU */
#define PARTICLE_MASS_B 1.0 /* mass of particle of radius MU */ #define PARTICLE_MASS_B 1.0 /* mass of particle of radius MU */
#define PARTICLE_INERTIA_MOMENT 0.2 /* moment of inertia of particle */ #define PARTICLE_INERTIA_MOMENT 0.2 /* moment of inertia of particle */
#define PARTICLE_INERTIA_MOMENT_B 0.02 /* moment of inertia of second type of particle */ #define PARTICLE_INERTIA_MOMENT_B 0.02 /* moment of inertia of second type of particle */
#define V_INITIAL 0.0 /* initial velocity range */ #define V_INITIAL 0.0 /* initial velocity range */
#define OMEGA_INITIAL 10.0 /* initial angular velocity range */ #define OMEGA_INITIAL 10.0 /* initial angular velocity range */
#define THERMOSTAT 0 /* set to 1 to switch on thermostat */ #define THERMOSTAT 1 /* set to 1 to switch on thermostat */
#define VARY_THERMOSTAT 0 /* set to 1 for time-dependent thermostat schedule */ #define VARY_THERMOSTAT 0 /* set to 1 for time-dependent thermostat schedule */
#define SIGMA 5.0 /* noise intensity in thermostat */ #define SIGMA 5.0 /* noise intensity in thermostat */
#define BETA 0.02 /* initial inverse temperature */ #define BETA 0.02 /* initial inverse temperature */
#define MU_XI 0.01 /* friction constant in thermostat */ #define MU_XI 0.01 /* friction constant in thermostat */
#define KSPRING_BOUNDARY 1.0e11 /* confining harmonic potential outside simulation region */ #define KSPRING_BOUNDARY 1.0e7 /* confining harmonic potential outside simulation region */
#define KSPRING_OBSTACLE 1.0e11 /* harmonic potential of obstacles */ #define KSPRING_OBSTACLE 1.0e11 /* harmonic potential of obstacles */
#define NBH_DIST_FACTOR 7.0 /* radius in which to count neighbours */ #define NBH_DIST_FACTOR 7.5 /* radius in which to count neighbours */
#define GRAVITY 2000.0 /* gravity acting on all particles */ #define GRAVITY 15.0 /* gravity acting on all particles */
#define GRAVITY_X 0.0 /* gravity acting on all particles */ #define GRAVITY_X 0.0 /* horizontal gravity acting on all particles */
#define INCREASE_GRAVITY 0 /* set to 1 to increase gravity during the simulation */ #define INCREASE_GRAVITY 0 /* set to 1 to increase gravity during the simulation */
#define GRAVITY_SCHEDULE 2 /* type of gravity schedule, see list in global_ljones.c */ #define GRAVITY_SCHEDULE 2 /* type of gravity schedule, see list in global_ljones.c */
#define GRAVITY_FACTOR 100.0 /* factor by which to increase gravity */ #define GRAVITY_FACTOR 100.0 /* factor by which to increase gravity */
@ -222,13 +240,13 @@
#define SPIN_RANGE_B 5.0 /* range of spin-spin interaction for second type of particle */ #define SPIN_RANGE_B 5.0 /* range of spin-spin interaction for second type of particle */
#define QUADRUPOLE_RATIO 0.6 /* anisotropy in quadrupole potential */ #define QUADRUPOLE_RATIO 0.6 /* anisotropy in quadrupole potential */
#define INCREASE_BETA 0 /* set to 1 to increase BETA during simulation */ #define INCREASE_BETA 1 /* set to 1 to increase BETA during simulation */
#define BETA_FACTOR 0.01 /* factor by which to change BETA during simulation */ #define BETA_FACTOR 0.025 /* factor by which to change BETA during simulation */
#define N_TOSCILLATIONS 1.5 /* number of temperature oscillations in BETA schedule */ #define N_TOSCILLATIONS 1.5 /* number of temperature oscillations in BETA schedule */
#define NO_OSCILLATION 1 /* set to 1 to have exponential BETA change only */ #define NO_OSCILLATION 1 /* set to 1 to have exponential BETA change only */
#define MIDDLE_CONSTANT_PHASE 370 /* final phase in which temperature is constant */ #define MIDDLE_CONSTANT_PHASE 1600 /* final phase in which temperature is constant */
#define FINAL_DECREASE_PHASE 350 /* final phase in which temperature decreases */ #define FINAL_DECREASE_PHASE 1500 /* final phase in which temperature decreases */
#define FINAL_CONSTANT_PHASE 1180 /* final phase in which temperature is constant */ #define FINAL_CONSTANT_PHASE -1 /* final phase in which temperature is constant */
#define DECREASE_CONTAINER_SIZE 0 /* set to 1 to decrease size of container */ #define DECREASE_CONTAINER_SIZE 0 /* set to 1 to decrease size of container */
#define SYMMETRIC_DECREASE 0 /* set tp 1 to decrease container symmetrically */ #define SYMMETRIC_DECREASE 0 /* set tp 1 to decrease container symmetrically */
@ -249,7 +267,7 @@
#define N_P_AVERAGE 100 /* size of pressure averaging window */ #define N_P_AVERAGE 100 /* size of pressure averaging window */
#define N_T_AVERAGE 50 /* size of temperature averaging window */ #define N_T_AVERAGE 50 /* size of temperature averaging window */
#define MAX_PRESSURE 3.0e10 /* pressure shown in "hottest" color */ #define MAX_PRESSURE 3.0e10 /* pressure shown in "hottest" color */
#define PARTIAL_THERMO_COUPLING 1 /* set to 1 to couple only particles to the right of obstacle to thermostat */ #define PARTIAL_THERMO_COUPLING 0 /* set to 1 to couple only particles to the right of obstacle to thermostat */
#define PARTIAL_THERMO_REGION 1 /* region for partial thermostat coupling (see list in global_ljones.c) */ #define PARTIAL_THERMO_REGION 1 /* region for partial thermostat coupling (see list in global_ljones.c) */
#define PARTIAL_THERMO_SHIFT 0.2 /* distance from obstacle at the right of which particles are coupled to thermostat */ #define PARTIAL_THERMO_SHIFT 0.2 /* distance from obstacle at the right of which particles are coupled to thermostat */
#define PARTIAL_THERMO_WIDTH 0.5 /* vertical size of partial thermostat coupling */ #define PARTIAL_THERMO_WIDTH 0.5 /* vertical size of partial thermostat coupling */
@ -283,21 +301,33 @@
#define OMEGAMAX 100.0 /* maximal rotation speed */ #define OMEGAMAX 100.0 /* maximal rotation speed */
#define PRINT_OMEGA 0 /* set to 1 to print angular speed */ #define PRINT_OMEGA 0 /* set to 1 to print angular speed */
#define PRINT_PARTICLE_SPEEDS 0 /* set to 1 to print average speeds/momenta of particles */ #define PRINT_PARTICLE_SPEEDS 0 /* set to 1 to print average speeds/momenta of particles */
#define PRINT_SEGMENTS_SPEEDS 0 /* set to 1 to print velocity of moving segments */ #define PRINT_SEGMENTS_SPEEDS 1 /* set to 1 to print velocity of moving segments */
#define MOVE_BOUNDARY 0 /* set to 1 to move repelling segments, due to force from particles */ #define MOVE_BOUNDARY 0 /* set to 1 to move repelling segments, due to force from particles */
#define SEGMENTS_MASS 40.0 /* mass of collection of segments */ #define SEGMENTS_MASS 40.0 /* mass of collection of segments */
#define DEACTIVATE_SEGMENT 1 /* set to 1 to deactivate last segment after a certain time */ #define DEACTIVATE_SEGMENT 1 /* set to 1 to deactivate last segment after a certain time */
#define SEGMENT_DEACTIVATION_TIME 500 /* time at which to deactivate last segment */ #define SEGMENT_DEACTIVATION_TIME 200 /* time at which to deactivate last segment */
#define RELEASE_ROCKET_AT_DEACTIVATION 0 /* set to 1 to limit segments velocity before segment release */ #define RELEASE_ROCKET_AT_DEACTIVATION 1 /* set to 1 to limit segments velocity before segment release */
#define SEGMENTS_X0 0.0 /* initial position of segments */ #define SEGMENTS_X0 1.5 /* initial position of segments */
#define SEGMENTS_Y0 1.5 /* initial position of segments */ #define SEGMENTS_Y0 0.0 /* initial position of segments */
#define SEGMENTS_VX0 0.0 /* initial velocity of segments */ #define SEGMENTS_VX0 0.0 /* initial velocity of segments */
#define SEGMENTS_VY0 -4.0 /* initial velocity of segments */ #define SEGMENTS_VY0 0.0 /* initial velocity of segments */
#define DAMP_SEGS_AT_NEGATIVE_Y 0 /* set to 1 to dampen segments when y coordinate is negative */ #define DAMP_SEGS_AT_NEGATIVE_Y 0 /* set to 1 to dampen segments when y coordinate is negative */
#define MOVE_SEGMENT_GROUPS 1 /* set to 1 to group segments into moving units */
#define SEGMENT_GROUP_MASS 1000.0 /* mass of segment group */
#define SEGMENT_GROUP_I 1000.0 /* moment of inertia of segment group */
#define SEGMENT_GROUP_DAMPING 0.0 /* damping of segment groups */
#define GROUP_REPULSION 1 /* set to 1 for groups of segments to repel each other */
#define KSPRING_GROUPS 1.0e11 /* harmonic potential between segment groups */
#define GROUP_WIDTH 0.05 /* interaction width of groups */
#define GROUP_G_REPEL 1 /* set to 1 to add repulsion between centers of mass of groups */
#define GROUP_G_REPEL_RADIUS 1.2 /* radius within which centers of mass of groups repel each other */
#define TRACK_SEGMENT_GROUPS 1 /* set to 1 for view to track group of segments */
#define TRACK_X_PADDING 2.0 /* distance from x boundary where tracking starts */
#define POSITION_DEPENDENT_TYPE 0 /* set to 1 to make particle type depend on initial position */ #define POSITION_DEPENDENT_TYPE 0 /* set to 1 to make particle type depend on initial position */
#define POSITION_Y_DEPENDENCE 0 /* set to 1 for the separation between particles to be vertical */ #define POSITION_Y_DEPENDENCE 0 /* set to 1 for the separation between particles to be horizontal */
#define PRINT_ENTROPY 0 /* set to 1 to compute entropy */ #define PRINT_ENTROPY 0 /* set to 1 to compute entropy */
#define REACTION_DIFFUSION 0 /* set to 1 to simulate a chemical reaction (particles may change type) */ #define REACTION_DIFFUSION 0 /* set to 1 to simulate a chemical reaction (particles may change type) */
@ -305,7 +335,10 @@
#define REACTION_PROB 0.0045 /* probability controlling reaction term */ #define REACTION_PROB 0.0045 /* probability controlling reaction term */
#define PRINT_PARTICLE_NUMBER 0 /* set to 1 to print total number of particles */ #define PRINT_PARTICLE_NUMBER 0 /* set to 1 to print total number of particles */
#define PRINT_LEFT 1 /* set to 1 to print certain parameters at the top left instead of right */ #define PRINT_LEFT 0 /* set to 1 to print certain parameters at the top left instead of right */
#define PLOT_SPEEDS 1 /* set to 1 to add a plot of obstacle speeds (e.g. for rockets) */
#define PLOT_TRAJECTORIES 1 /* set to 1 to add a plot of obstacle trajectories (e.g. for rockets) */
#define VMAX_PLOT_SPEEDS 0.6 /* vertical scale of plot of obstacle speeds */
#define EHRENFEST_COPY 0 /* set to 1 to add equal number of larger particles (for Ehrenfest model) */ #define EHRENFEST_COPY 0 /* set to 1 to add equal number of larger particles (for Ehrenfest model) */
@ -315,15 +348,21 @@
#define WALL_FRICTION 0.0 /* friction on wall for BC_RECTANGLE_WALL b.c. */ #define WALL_FRICTION 0.0 /* friction on wall for BC_RECTANGLE_WALL b.c. */
#define WALL_WIDTH 0.1 /* width of wall for BC_RECTANGLE_WALL b.c. */ #define WALL_WIDTH 0.1 /* width of wall for BC_RECTANGLE_WALL b.c. */
#define WALL_VMAX 100.0 /* max speed of wall */ #define WALL_VMAX 100.0 /* max speed of wall */
#define WALL_TIME 500 /* time during which to keep wall */ #define WALL_TIME 0 /* time during which to keep wall */
#define NXMAZE 10 /* width of maze */
#define NYMAZE 10 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 200 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define FLOOR_FORCE 1 /* set to 1 to limit force on particle to FMAX */ #define FLOOR_FORCE 1 /* set to 1 to limit force on particle to FMAX */
#define FMAX 1.0e12 /* maximal force */ #define FMAX 1.0e12 /* maximal force */
#define FLOOR_OMEGA 0 /* set to 1 to limit particle momentum to PMAX */ #define FLOOR_OMEGA 0 /* set to 1 to limit particle momentum to PMAX */
#define PMAX 1000.0 /* maximal force */ #define PMAX 1000.0 /* maximal force */
#define HASHX 160 /* size of hashgrid in x direction */ #define HASHX 120 /* size of hashgrid in x direction */
#define HASHY 80 /* size of hashgrid in y direction */ #define HASHY 450 /* size of hashgrid in y direction */
#define HASHMAX 100 /* maximal number of particles per hashgrid cell */ #define HASHMAX 100 /* maximal number of particles per hashgrid cell */
#define HASHGRID_PADDING 0.1 /* padding of hashgrid outside simulation window */ #define HASHGRID_PADDING 0.1 /* padding of hashgrid outside simulation window */
@ -343,6 +382,8 @@ double vylid = 0.0; /* y speed coordinate of lid (for BC_RECTANGLE_LID b.c
double xwall = 0.0; /* x coordinate of wall (for BC_RECTANGLE_WALL b.c.) */ double xwall = 0.0; /* x coordinate of wall (for BC_RECTANGLE_WALL b.c.) */
double vxwall = 0.0; /* x speed of wall (for BC_RECTANGLE_WALL b.c.) */ double vxwall = 0.0; /* x speed of wall (for BC_RECTANGLE_WALL b.c.) */
double angular_speed = 0.0; /* angular speed of rotating segments */ double angular_speed = 0.0; /* angular speed of rotating segments */
double xtrack = 0.0; /* traking coordinate */
double ytrack = 0.0; /* traking coordinate */
double xsegments[2] = {SEGMENTS_X0, -SEGMENTS_X0}; /* x coordinate of segments (for option MOVE_BOUNDARY) */ double xsegments[2] = {SEGMENTS_X0, -SEGMENTS_X0}; /* x coordinate of segments (for option MOVE_BOUNDARY) */
double ysegments[2] = {SEGMENTS_Y0, SEGMENTS_Y0}; /* y coordinate of segments (for option MOVE_BOUNDARY) */ double ysegments[2] = {SEGMENTS_Y0, SEGMENTS_Y0}; /* y coordinate of segments (for option MOVE_BOUNDARY) */
double vxsegments[2] = {SEGMENTS_VX0, SEGMENTS_VX0}; /* vx coordinate of segments (for option MOVE_BOUNDARY) */ double vxsegments[2] = {SEGMENTS_VX0, SEGMENTS_VX0}; /* vx coordinate of segments (for option MOVE_BOUNDARY) */
@ -352,6 +393,7 @@ int thermostat_on = 1; /* thermostat switch used when VARY_THERMOSTAT is on *
#define THERMOSTAT_ON ((THERMOSTAT)&&((!VARY_THERMOSTAT)||(thermostat_on))) #define THERMOSTAT_ON ((THERMOSTAT)&&((!VARY_THERMOSTAT)||(thermostat_on)))
#include "global_ljones.c" #include "global_ljones.c"
#include "sub_maze.c"
#include "sub_lj.c" #include "sub_lj.c"
#include "sub_hashgrid.c" #include "sub_hashgrid.c"
@ -836,32 +878,195 @@ void evolve_segments(t_segment segment[NMAXSEGMENTS], int time)
} }
void evolve_segment_groups(t_segment segment[NMAXSEGMENTS], int time, t_group_segments segment_group[NMAXGROUPS])
/* new version of evolve_segments that takes the group structure into account */
{
double fx[NMAXGROUPS], fy[NMAXGROUPS], torque[NMAXGROUPS], dx[NMAXGROUPS], dy[NMAXGROUPS], dalpha[NMAXGROUPS];
double x, y, dx0, dy0, padding, proj, distance, f, xx[2], yy[2], xmean = 0.0, ymean = 0.0;
int i, j, k, group = 0;
static double maxdepth, saturation_depth;
maxdepth = 0.5*GROUP_WIDTH;
saturation_depth = 0.1*GROUP_WIDTH;
for (group=0; group<ngroups; group++)
{
fx[group] = 0.0;
fy[group] = 0.0;
torque[group] = 0.0;
}
/* only groups of segments of index 1 or larger are mobile */
for (i=0; i<nsegments; i++) if ((segment[i].active)&&(segment[i].group > 0))
{
group = segment[i].group;
fx[group] += segment[i].fx;
fy[group] += segment[i].fy;
torque[group] += segment[i].torque;
dx0 = segment[i].xc - segment_group[group].xc;
dy0 = segment[i].yc - segment_group[group].yc;
torque[group] += dx0*segment[i].fy - dy0*segment[i].fx;
if (BOUNDARY_COND == BC_SCREEN) /* add force from simulation boundary */
{
x = 0.5*(segment[i].x1 + segment[i].x2);
y = 0.5*(segment[i].y1 + segment[i].y2);
if (x < XMIN + padding) fx[group] += KSPRING_BOUNDARY*(XMIN + padding - x);
else if (x > XMAX - padding) fx[group] -= KSPRING_BOUNDARY*(x - XMAX + padding);
if (y < YMIN + padding) fy[group] += KSPRING_BOUNDARY*(YMIN + padding - y);
else if (y > YMAX - padding) fy[group] -= KSPRING_BOUNDARY*(y - YMAX + padding);
}
else if (BOUNDARY_COND == BC_REFLECT_ABS) /* add force from simulation boundary */
{
y = 0.5*(segment[i].y1 + segment[i].y2);
if (y < YMIN) fy[group] += KSPRING_BOUNDARY*(YMIN - y);
}
/* repulsion between different groups */
if (GROUP_REPULSION) for (j=0; j<nsegments; j++) if ((segment[j].active)&&(segment[j].group != group))
{
xx[0] = segment[j].x1;
yy[0] = segment[j].y1;
xx[1] = segment[j].x2;
yy[1] = segment[j].y2;
for (k=0; k<2; k++)
{
x = xx[k];
y = yy[k];
proj = (segment[i].ny*(x - segment[i].x1) - segment[i].nx*(y - segment[i].y1))/segment[i].length;
if ((proj > 0.0)&&(proj < 1.0))
{
distance = segment[i].nx*x + segment[i].ny*y - segment[i].c;
if ((distance > -maxdepth)&&(distance < 0.0))
{
if (distance < -saturation_depth) distance = -saturation_depth;
f = KSPRING_GROUPS*(-distance);
segment[j].fx += f*segment[i].nx;
segment[j].fy += f*segment[i].ny;
segment[j].torque += (x - segment[i].xc)*f*segment[i].ny - (y - segment[i].yc)*f*segment[i].nx;
fx[group] -= f*segment[i].nx;
fy[group] -= f*segment[i].ny;
torque[group] -= (x - segment[i].xc)*f*segment[i].ny - (y - segment[i].yc)*f*segment[i].nx;
}
}
}
}
}
if (GROUP_G_REPEL) for (i=0; i<ngroups; i++) for (j=i+1; j<ngroups; j++)
{
x = segment_group[j].xc - segment_group[i].xc;
y = segment_group[j].yc - segment_group[i].yc;
distance = module2(x, y);
if (distance < GROUP_G_REPEL_RADIUS)
{
if (distance < 0.1*GROUP_G_REPEL_RADIUS) distance = 0.1*GROUP_G_REPEL_RADIUS;
f = KSPRING_GROUPS*(GROUP_G_REPEL_RADIUS - distance);
fx[j] += f*x/distance;
fy[j] += f*y/distance;
fx[i] -= f*x/distance;
fy[i] -= f*y/distance;
}
}
if (FLOOR_FORCE) for (group=1; group<ngroups; group++)
{
if (fx[group] > FMAX) fx[group] = FMAX;
else if (fx[group] < -FMAX) fx[group] = -FMAX;
if (fy[group] > FMAX) fy[group] = FMAX;
else if (fy[group] < -FMAX) fy[group] = -FMAX;
}
for (group=1; group<ngroups; group++)
{
fy[group] -= GRAVITY*segment_group[group].mass;
fx[group] += GRAVITY_X*segment_group[group].mass;
segment_group[group].vx += fx[group]*DT_PARTICLE/segment_group[group].mass;
segment_group[group].vy += fy[group]*DT_PARTICLE/segment_group[group].mass;
segment_group[group].omega += torque[group]*DT_PARTICLE/segment_group[group].moment_inertia;
segment_group[group].vx *= exp(- DT_PARTICLE*SEGMENT_GROUP_DAMPING);
segment_group[group].vy *= exp(- DT_PARTICLE*SEGMENT_GROUP_DAMPING);
segment_group[group].omega *= exp(- DT_PARTICLE*SEGMENT_GROUP_DAMPING);
dx[group] = segment_group[group].vx*DT_PARTICLE;
dy[group] = segment_group[group].vy*DT_PARTICLE;
dalpha[group] = segment_group[group].omega*DT_PARTICLE;
segment_group[group].xc += dx[group];
segment_group[group].yc += dy[group];
segment_group[group].angle += dalpha[group];
// printf("group %i: (dx, dy) = (%.3lg, %.3lg)\n", group, dx[group], dy[group]);
}
for (i=0; i<nsegments; i++) if ((segment[i].active)&&(segment[i].group > 0))
{
group = segment[i].group;
translate_one_segment(segment, i, dx[group], dy[group]);
rotate_one_segment(segment, i, dalpha[group], segment_group[group].xc, segment_group[group].yc);
}
if (TRACK_SEGMENT_GROUPS)
{
/* compute mean position */
for (group=1; group<ngroups; group++)
{
xmean += segment_group[group].xc;
ymean += segment_group[group].yc;
}
xmean = xmean/((double)(ngroups-1));
ymean = ymean/((double)(ngroups-1));
if (ymean > ytrack) ytrack = ymean;
if (xmean > XMAX - TRACK_X_PADDING)
xtrack = xmean - XMAX + TRACK_X_PADDING;
else if (xmean < XMIN + TRACK_X_PADDING)
xtrack = xmean - XMIN - TRACK_X_PADDING;
}
}
void animation() void animation()
{ {
double time, scale, diss, rgb[3], dissip, gradient[2], x, y, dx, dy, dt, xleft, xright, a, b, double time, scale, diss, rgb[3], dissip, gradient[2], x, y, dx, dy, dt, xleft, xright, a, b,
length, fx, fy, force[2], totalenergy = 0.0, krepel = KREPEL, pos[2], prop, vx, length, fx, fy, force[2], totalenergy = 0.0, krepel = KREPEL, pos[2], prop, vx,
beta = BETA, xi = 0.0, xmincontainer = BCXMIN, xmaxcontainer = BCXMAX, torque, torque_ij, beta = BETA, xi = 0.0, xmincontainer = BCXMIN, xmaxcontainer = BCXMAX, torque, torque_ij,
fboundary = 0.0, pleft = 0.0, pright = 0.0, entropy[2], mean_energy, gravity = GRAVITY; fboundary = 0.0, pleft = 0.0, pright = 0.0, entropy[2], mean_energy, gravity = GRAVITY, speed_ratio;
double *qx, *qy, *px, *py, *qangle, *pangle, *pressure; double *qx, *qy, *px, *py, *qangle, *pangle, *pressure, *obstacle_speeds;
int i, j, k, n, m, s, ij[2], i0, iplus, iminus, j0, jplus, jminus, p, q, p1, q1, p2, q2, total_neighbours = 0, int i, j, k, n, m, s, ij[2], i0, iplus, iminus, j0, jplus, jminus, p, q, p1, q1, p2, q2, total_neighbours = 0,
min_nb, max_nb, close, wrapx = 0, wrapy = 0, nactive = 0, nadd_particle = 0, nmove = 0, nsuccess = 0, min_nb, max_nb, close, wrapx = 0, wrapy = 0, nactive = 0, nadd_particle = 0, nmove = 0, nsuccess = 0,
tracer_n[N_TRACER_PARTICLES], traj_position = 0, traj_length = 0, move = 0, old, m0, floor, nthermo, wall = 0; tracer_n[N_TRACER_PARTICLES], traj_position = 0, traj_length = 0, move = 0, old, m0, floor, nthermo, wall = 0,
group, gshift;
static int imin, imax; static int imin, imax;
static short int first = 1; static short int first = 1;
t_particle *particle; t_particle *particle;
t_obstacle *obstacle; t_obstacle *obstacle;
t_segment *segment; t_segment *segment;
t_group_segments *segment_group;
t_tracer *trajectory; t_tracer *trajectory;
t_group_data *group_speeds;
t_hashgrid *hashgrid; t_hashgrid *hashgrid;
char message[100]; char message[100];
particle = (t_particle *)malloc(NMAXCIRCLES*sizeof(t_particle)); /* particles */ particle = (t_particle *)malloc(NMAXCIRCLES*sizeof(t_particle)); /* particles */
if (ADD_FIXED_OBSTACLES) obstacle = (t_obstacle *)malloc(NMAXOBSTACLES*sizeof(t_obstacle)); /* circular obstacles */ if (ADD_FIXED_OBSTACLES) obstacle = (t_obstacle *)malloc(NMAXOBSTACLES*sizeof(t_obstacle)); /* circular obstacles */
if (ADD_FIXED_SEGMENTS) segment = (t_segment *)malloc(NMAXSEGMENTS*sizeof(t_segment)); /* linear obstacles */ if (ADD_FIXED_SEGMENTS)
{
segment = (t_segment *)malloc(NMAXSEGMENTS*sizeof(t_segment)); /* linear obstacles */
segment_group = (t_group_segments *)malloc(NMAXGROUPS*sizeof(t_group_segments));
}
if (TRACER_PARTICLE) trajectory = (t_tracer *)malloc(TRAJECTORY_LENGTH*N_TRACER_PARTICLES*sizeof(t_tracer)); if (TRACER_PARTICLE) trajectory = (t_tracer *)malloc(TRAJECTORY_LENGTH*N_TRACER_PARTICLES*sizeof(t_tracer));
hashgrid = (t_hashgrid *)malloc(HASHX*HASHY*sizeof(t_hashgrid)); /* hashgrid */ hashgrid = (t_hashgrid *)malloc(HASHX*HASHY*sizeof(t_hashgrid)); /* hashgrid */
qx = (double *)malloc(NMAXCIRCLES*sizeof(double)); qx = (double *)malloc(NMAXCIRCLES*sizeof(double));
@ -872,17 +1077,27 @@ void animation()
pangle = (double *)malloc(NMAXCIRCLES*sizeof(double)); pangle = (double *)malloc(NMAXCIRCLES*sizeof(double));
pressure = (double *)malloc(N_PRESSURES*sizeof(double)); pressure = (double *)malloc(N_PRESSURES*sizeof(double));
/* initialise positions and radii of circles */ /* initialise positions and radii of circles */
init_particle_config(particle); init_particle_config(particle);
init_hashgrid(hashgrid); init_hashgrid(hashgrid);
xshift = OBSTACLE_XMIN; xshift = OBSTACLE_XMIN;
speed_ratio = (double)(25*NVID)*DT_PARTICLE;
if (ADD_FIXED_OBSTACLES) init_obstacle_config(obstacle); if (ADD_FIXED_OBSTACLES) init_obstacle_config(obstacle);
if (ADD_FIXED_SEGMENTS) init_segment_config(segment); if (ADD_FIXED_SEGMENTS) init_segment_config(segment);
if (MOVE_SEGMENT_GROUPS)
{
for (i=0; i<ngroups; i++) init_segment_group(segment, i, segment_group);
group_speeds = (t_group_data *)malloc(ngroups*(INITIAL_TIME + NSTEPS)*sizeof(t_group_data));
}
if (RECORD_PRESSURES) for (i=0; i<N_PRESSURES; i++) pressure[i] = 0.0; if (RECORD_PRESSURES) for (i=0; i<N_PRESSURES; i++) pressure[i] = 0.0;
if (PLOT_SPEEDS) obstacle_speeds = (double *)malloc(2*ngroups*(INITIAL_TIME + NSTEPS)*sizeof(double));
// printf("1\n"); // printf("1\n");
nactive = initialize_configuration(particle, hashgrid, obstacle, px, py, pangle, tracer_n); nactive = initialize_configuration(particle, hashgrid, obstacle, px, py, pangle, tracer_n);
@ -947,12 +1162,14 @@ void animation()
if ((BOUNDARY_COND == BC_RECTANGLE_WALL)&&(i < INITIAL_TIME + WALL_TIME)) wall = 1; if ((BOUNDARY_COND == BC_RECTANGLE_WALL)&&(i < INITIAL_TIME + WALL_TIME)) wall = 1;
else wall = 0; else wall = 0;
if (MOVE_BOUNDARY) for (j=0; j<nsegments; j++) if ((MOVE_BOUNDARY)||(MOVE_SEGMENT_GROUPS)) for (j=0; j<nsegments; j++)
{ {
segment[j].fx = 0.0; segment[j].fx = 0.0;
segment[j].fy = 0.0; segment[j].fy = 0.0;
segment[j].torque = 0.0;
} }
compute_relative_positions(particle, hashgrid); compute_relative_positions(particle, hashgrid);
update_hashgrid(particle, hashgrid, 0); update_hashgrid(particle, hashgrid, 0);
@ -999,12 +1216,36 @@ void animation()
else xwall = 0.0; else xwall = 0.0;
} }
if ((MOVE_BOUNDARY)&&(i > OBSTACLE_INITIAL_TIME)) evolve_segments(segment, i); if ((MOVE_BOUNDARY)&&(i > OBSTACLE_INITIAL_TIME)) evolve_segments(segment, i);
if ((MOVE_SEGMENT_GROUPS)&&(i > OBSTACLE_INITIAL_TIME)) evolve_segment_groups(segment, i, segment_group);
} /* end of for (n=0; n<NVID; n++) */ } /* end of for (n=0; n<NVID; n++) */
// printf("evolved particles\n"); // printf("evolved particles\n");
if (PLOT_SPEEDS) /* record speeds of segments */
{
gshift = INITIAL_TIME + NSTEPS;
if (MOVE_SEGMENT_GROUPS) for (group = 1; group < ngroups; group++)
{
group_speeds[(group-1)*gshift + i].xc = segment_group[group].xc;
group_speeds[(group-1)*gshift + i].yc = segment_group[group].yc;
group_speeds[(group-1)*gshift + i].vx = segment_group[group].vx*speed_ratio;
group_speeds[(group-1)*gshift + i].vy = segment_group[group].vy*speed_ratio;
group_speeds[(group-1)*gshift + i].omega = segment_group[group].omega*speed_ratio;
}
else
{
obstacle_speeds[i] = vysegments[0];
obstacle_speeds[INITIAL_TIME + NSTEPS + i] = vysegments[1];
}
}
if (MOVE_BOUNDARY) if (MOVE_BOUNDARY)
printf("segments position (%.3lg, %.3lg), speed (%.3lg, %.3lg)\n", xsegments[0], ysegments[0], vxsegments[0], vysegments[0]); printf("segment[%i]: (fx, fy) = (%.3lg, %.3lg), torque = %.3lg)\n", i, fx, fy, torque);
if (MOVE_SEGMENT_GROUPS) for (group=1; group<ngroups; group++)
printf("segments position [%i] (%.3lg, %.3lg) angle %.3lg\n speed (%.3lg, %.3lg) omega %.3lg\n",
group, segment_group[group].xc, segment_group[group].yc, segment_group[group].angle, segment_group[group].vx, segment_group[group].vy, segment_group[group].omega);
// if ((PARTIAL_THERMO_COUPLING)) // if ((PARTIAL_THERMO_COUPLING))
if ((PARTIAL_THERMO_COUPLING)&&(i>N_T_AVERAGE)) if ((PARTIAL_THERMO_COUPLING)&&(i>N_T_AVERAGE))
@ -1091,13 +1332,19 @@ void animation()
print_entropy(entropy); print_entropy(entropy);
} }
if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i);
if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i);
if (PRINT_OMEGA) print_omega(angular_speed); if (PRINT_OMEGA) print_omega(angular_speed);
else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle); else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle);
else if (PRINT_SEGMENTS_SPEEDS) print_segments_speeds(vxsegments, vysegments); else if (PRINT_SEGMENTS_SPEEDS)
{
if (MOVE_BOUNDARY) print_segments_speeds(vxsegments, vysegments);
else print_segment_group_speeds(segment_group);
}
glutSwapBuffers(); glutSwapBuffers();
if (MOVIE) if (MOVIE)
{ {
if (i >= INITIAL_TIME) if (i >= INITIAL_TIME)
@ -1129,11 +1376,14 @@ void animation()
draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall); draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall);
print_parameters(beta, mean_energy, krepel, xmaxcontainer - xmincontainer, print_parameters(beta, mean_energy, krepel, xmaxcontainer - xmincontainer,
fboundary/(double)(ncircles*NVID), PRINT_LEFT, pressure, gravity); fboundary/(double)(ncircles*NVID), PRINT_LEFT, pressure, gravity);
if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i);
if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i);
if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright); if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright);
else if (PRINT_PARTICLE_NUMBER) print_particle_number(ncircles); else if (PRINT_PARTICLE_NUMBER) print_particle_number(ncircles);
if (PRINT_OMEGA) print_omega(angular_speed); if (PRINT_OMEGA) print_omega(angular_speed);
else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle); else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle);
else if (PRINT_SEGMENTS_SPEEDS) print_segments_speeds(vxsegments, vysegments); else if (PRINT_SEGMENTS_SPEEDS) print_segment_group_speeds(segment_group);
// print_segments_speeds(vxsegments, vysegments);
glutSwapBuffers(); glutSwapBuffers();
save_frame_lj_counter(NSTEPS + MID_FRAMES + 1 + counter); save_frame_lj_counter(NSTEPS + MID_FRAMES + 1 + counter);
counter++; counter++;
@ -1160,11 +1410,14 @@ void animation()
draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall); draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall);
print_parameters(beta, mean_energy, krepel, xmaxcontainer - xmincontainer, print_parameters(beta, mean_energy, krepel, xmaxcontainer - xmincontainer,
fboundary/(double)(ncircles*NVID), PRINT_LEFT, pressure, gravity); fboundary/(double)(ncircles*NVID), PRINT_LEFT, pressure, gravity);
if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i);
if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i);
if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright); if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright);
else if (PRINT_PARTICLE_NUMBER) print_particle_number(ncircles); else if (PRINT_PARTICLE_NUMBER) print_particle_number(ncircles);
if (PRINT_OMEGA) print_omega(angular_speed); if (PRINT_OMEGA) print_omega(angular_speed);
else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle); else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle);
else if (PRINT_SEGMENTS_SPEEDS) print_segments_speeds(vxsegments, vysegments); else if (PRINT_SEGMENTS_SPEEDS) print_segment_group_speeds(segment_group);
// print_segments_speeds(vxsegments, vysegments);
glutSwapBuffers(); glutSwapBuffers();
} }
for (i=0; i<MID_FRAMES; i++) save_frame_lj(); for (i=0; i<MID_FRAMES; i++) save_frame_lj();
@ -1175,11 +1428,14 @@ void animation()
draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall); draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall);
print_parameters(beta, mean_energy, krepel, xmaxcontainer - xmincontainer, print_parameters(beta, mean_energy, krepel, xmaxcontainer - xmincontainer,
fboundary/(double)(ncircles*NVID), PRINT_LEFT, pressure, gravity); fboundary/(double)(ncircles*NVID), PRINT_LEFT, pressure, gravity);
if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i);
if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i);
if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright); if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright);
else if (PRINT_PARTICLE_NUMBER) print_particle_number(ncircles); else if (PRINT_PARTICLE_NUMBER) print_particle_number(ncircles);
if (PRINT_OMEGA) print_omega(angular_speed); if (PRINT_OMEGA) print_omega(angular_speed);
else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle); else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle);
else if (PRINT_SEGMENTS_SPEEDS) print_segments_speeds(vxsegments, vysegments); else if (PRINT_SEGMENTS_SPEEDS) print_segment_group_speeds(segment_group);
// print_segments_speeds(vxsegments, vysegments);
glutSwapBuffers(); glutSwapBuffers();
} }
if ((TIME_LAPSE)&&(!DOUBLE_MOVIE)) if ((TIME_LAPSE)&&(!DOUBLE_MOVIE))
@ -1196,8 +1452,14 @@ void animation()
free(particle); free(particle);
if (ADD_FIXED_OBSTACLES) free(obstacle); if (ADD_FIXED_OBSTACLES) free(obstacle);
if (ADD_FIXED_SEGMENTS) free(segment); if (ADD_FIXED_SEGMENTS)
{
free(segment);
free(segment_group);
}
if (MOVE_SEGMENT_GROUPS) free(group_speeds);
if (TRACER_PARTICLE) free(trajectory); if (TRACER_PARTICLE) free(trajectory);
if (PLOT_SPEEDS) free(obstacle_speeds);
free(hashgrid); free(hashgrid);
free(qx); free(qx);
free(qy); free(qy);

View File

@ -235,7 +235,19 @@
#define DAMPING 0.0 /* damping of periodic excitation */ #define DAMPING 0.0 /* damping of periodic excitation */
/* end of constants only used by wave_billiard and wave_3d */ /* end of constants only used by wave_billiard and wave_3d */
/* for compatibility with sub_wave and sub_maze */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define ADD_POTENTIAL 0
#define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
#include "global_pdes.c" #include "global_pdes.c"
#include "sub_maze.c" /* support for generating mazes */
#include "sub_wave.c" #include "sub_wave.c"
#include "wave_common.c" #include "wave_common.c"

View File

@ -54,10 +54,10 @@
/* Choice of the billiard table, see global_particles.c */ /* Choice of the billiard table, see global_particles.c */
#define B_DOMAIN 16 /* choice of domain shape */ #define B_DOMAIN 30 /* choice of domain shape */
#define CIRCLE_PATTERN 1 /* pattern of circles */ #define CIRCLE_PATTERN 1 /* pattern of circles */
#define POLYLINE_PATTERN 8 /* pattern of polyline */ #define POLYLINE_PATTERN 10 /* pattern of polyline */
#define ABSORBING_CIRCLES 1 /* set to 1 for circular scatterers to be absorbing */ #define ABSORBING_CIRCLES 1 /* set to 1 for circular scatterers to be absorbing */
@ -87,7 +87,7 @@
/* Simulation parameters */ /* Simulation parameters */
#define NPART 16 /* number of particles */ #define NPART 1000 /* number of particles */
// #define NPART 2000 /* number of particles */ // #define NPART 2000 /* 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 */
@ -96,13 +96,16 @@
#define SHOWTRAILS 1 /* set to 1 to keep trails of the particles */ #define SHOWTRAILS 1 /* set to 1 to keep trails of the particles */
#define SHOWZOOM 0 /* set to 1 to show zoom on specific area */ #define SHOWZOOM 0 /* set to 1 to show zoom on specific area */
#define PRINT_PARTICLE_NUMBER 0 /* set to 1 to print number of particles */ #define PRINT_PARTICLE_NUMBER 0 /* set to 1 to print number of particles */
#define PRINT_LEFT_RIGHT_PARTICLE_NUMBER 1 /* set to 1 to print number of particles on left and right side */
#define PRINT_COLLISION_NUMBER 0 /* set to 1 to print number of collisions */ #define PRINT_COLLISION_NUMBER 0 /* set to 1 to print number of collisions */
#define TEST_ACTIVE 1 /* set to 1 to test whether particle is in billiard */ #define TEST_ACTIVE 1 /* set to 1 to test whether particle is in billiard */
#define NSTEPS 5250 /* number of frames of movie */ #define TEST_INITIAL_COND 1 /* set to 1 to allow only initial conditions that pass a test */
#define TIME 750 /* time between movie frames, for fluidity of real-time simulation */
#define DPHI 0.00001 /* integration step */ #define NSTEPS 6000 /* number of frames of movie */
#define NVID 25 /* number of iterations between images displayed on screen */ #define TIME 1500 /* time between movie frames, for fluidity of real-time simulation */
#define DPHI 0.00002 /* integration step */
#define NVID 25 /* 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 END_FRAMES 25 /* number of still frames at the end of the movie */ #define END_FRAMES 25 /* number of still frames at the end of the movie */
@ -114,16 +117,16 @@
/* Colors and other graphical parameters */ /* Colors and other graphical parameters */
#define COLOR_PALETTE 14 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE 11 /* Color palette, see list in global_pdes.c */
#define NCOLORS 16 /* number of colors */ #define NCOLORS 16 /* number of colors */
#define COLORSHIFT 0 /* hue of initial color */ #define COLORSHIFT 0 /* hue of initial color */
#define RAINBOW_COLOR 0 /* set to 1 to use different colors for all particles */ #define RAINBOW_COLOR 1 /* 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.005 /* length of velocity vectors */ // #define LENGTH 0.01 /* length of velocity vectors */
// #define LENGTH 0.03 /* length of velocity vectors */ #define LENGTH 0.04 /* length of velocity vectors */
#define BILLIARD_WIDTH 2 /* width of billiard */ #define BILLIARD_WIDTH 3 /* width of billiard */
#define PARTICLE_WIDTH 3 /* width of particles */ #define PARTICLE_WIDTH 3 /* width of particles */
#define FRONT_WIDTH 3 /* width of wave front */ #define FRONT_WIDTH 3 /* width of wave front */
@ -133,13 +136,20 @@
#define PAINT_INT 0 /* set to 1 to paint interior in other color (for polygon/Reuleaux) */ #define PAINT_INT 0 /* set to 1 to paint interior in other color (for polygon/Reuleaux) */
#define PAINT_EXT 1 /* set to 1 to paint exterior */ #define PAINT_EXT 1 /* set to 1 to paint exterior */
#define PAUSE 200 /* number of frames after which to pause */ #define PAUSE 1000 /* number of frames after which to pause */
#define PSLEEP 2 /* sleep time during pause */ #define PSLEEP 2 /* sleep time during pause */
#define SLEEP1 1 /* initial sleeping time */ #define SLEEP1 1 /* initial sleeping time */
#define SLEEP2 1 /* final sleeping time */ #define SLEEP2 1 /* final sleeping time */
#define NXMAZE 8 /* width of maze */
#define NYMAZE 8 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 58 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#include "global_particles.c" #include "global_particles.c"
#include "sub_maze.c"
#include "sub_part_billiard.c" #include "sub_part_billiard.c"
int ncollisions = 0; int ncollisions = 0;
@ -403,7 +413,8 @@ void draw_config_showtrails(int color[NPARTMAX], double *configs[NPARTMAX], int
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
for (i=0; i<nparticles; i++) for (i=0; i<nparticles; i++)
// if (active[i])
{ {
// if (configs[i][2]<0.0) // if (configs[i][2]<0.0)
// { // {
@ -484,7 +495,7 @@ void draw_config(int color[NPARTMAX], double *configs[NPARTMAX], int active[NPAR
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
for (i=0; i<nparticles; i++) for (i=0; i<nparticles; i++) if (active[i])
{ {
if (configs[i][2]<0.0) if (configs[i][2]<0.0)
{ {
@ -595,7 +606,7 @@ void graph_movie(int time, int color[NPARTMAX], double *configs[NPARTMAX], int a
for (j=0; j<time; j++) for (j=0; j<time; j++)
{ {
for (i=0; i<nparticles; i++) for (i=0; i<nparticles; i++) if (active[i])
{ {
if (configs[i][2]<0.0) if (configs[i][2]<0.0)
{ {
@ -645,6 +656,35 @@ void print_part_number(double *configs[NPARTMAX], int active[NPARTMAX], double x
} }
void print_left_right_part_number(double *configs[NPARTMAX], int active[NPARTMAX], double xl, double yl, double xr, double yr, double xmin, double xmax)
{
char message[50];
int i, nleft = 0, nright = 0;
double rgb[3], x1, cosphi;
/* count active particles, using the fact that absorbed particles have been given dummy coordinates */
for (i=0; i<nparticles; i++) /*if (active[i])*/
{
cosphi = (configs[i][6] - configs[i][4])/configs[i][3];
x1 = configs[i][4] + configs[i][2]*cosphi;
if (x1 < xmin) nleft++;
else if (x1 > xmax) nright++;
}
hsl_to_rgb(0.0, 0.0, 0.0, rgb);
erase_area(xl, yl - 0.03, 0.5, 0.12, rgb);
erase_area(xr, yr - 0.03, 0.4, 0.12, rgb);
glColor3f(1.0, 1.0, 1.0);
if (nleft > 1) sprintf(message, "%i particles", nleft);
else sprintf(message, "%i particle", nleft);
write_text(xl, yl, message);
if (nright > 1) sprintf(message, "%i particles", nright);
else sprintf(message, "%i particle", nright);
write_text(xr, yr, message);
}
void print_collision_number(int ncollisions, double x, double y) void print_collision_number(int ncollisions, double x, double y)
{ {
char message[50]; char message[50];
@ -730,7 +770,7 @@ void animation()
// init_drop_config(-0.5, 0.0, 0.2, 0.4, configs); // init_drop_config(-0.5, 0.0, 0.2, 0.4, configs);
init_drop_config(0.0, 0.0, 0.0, DPI, configs); init_drop_config(-1.3, 0.2, -0.25*PI, 0.25*PI, configs);
// init_drop_config(-1.3, -0.1, 0.0, DPI, configs); // init_drop_config(-1.3, -0.1, 0.0, DPI, configs);
// init_drop_config(1.4, 0.1, 0.0, DPI, configs); // init_drop_config(1.4, 0.1, 0.0, DPI, configs);
@ -746,11 +786,13 @@ void animation()
// init_line_config(-1.0, -0.3, -1.0, 0.3, 0.0, 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);
if (!SHOWTRAILS) 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();
if (PRINT_PARTICLE_NUMBER) print_part_number(configs, active, XMIN + 0.1, YMIN + 0.1); if (PRINT_PARTICLE_NUMBER) print_part_number(configs, active, XMIN + 0.1, YMIN + 0.1);
else if (PRINT_LEFT_RIGHT_PARTICLE_NUMBER)
print_left_right_part_number(configs, active, XMIN + 0.1, YMIN + 0.1, XMAX - 0.45, YMIN + 0.1, YMAX + MAZE_XSHIFT, YMAX + MAZE_XSHIFT);
else if (PRINT_COLLISION_NUMBER) print_collision_number(ncollisions, XMIN + 0.1, YMIN + 0.1); else if (PRINT_COLLISION_NUMBER) print_collision_number(ncollisions, XMIN + 0.1, YMIN + 0.1);
glutSwapBuffers(); glutSwapBuffers();
@ -787,6 +829,8 @@ void animation()
color[i] = (i*NCOLORS)/NPART; color[i] = (i*NCOLORS)/NPART;
newcolor[i] = (i*NCOLORS)/NPART; newcolor[i] = (i*NCOLORS)/NPART;
} }
if (TEST_INITIAL_COND) nparticles = test_initial_condition(configs, active, newcolor);
sleep(SLEEP1); sleep(SLEEP1);
@ -805,6 +849,9 @@ void animation()
// draw_config(newcolor, configs, active); // draw_config(newcolor, configs, active);
if (DRAW_BILLIARD) draw_billiard(); if (DRAW_BILLIARD) draw_billiard();
if (PRINT_PARTICLE_NUMBER) print_part_number(configs, active, XMIN + 0.1, YMIN + 0.1); if (PRINT_PARTICLE_NUMBER) print_part_number(configs, active, XMIN + 0.1, YMIN + 0.1);
else if (PRINT_LEFT_RIGHT_PARTICLE_NUMBER)
print_left_right_part_number(configs, active, XMIN + 0.1, YMIN + 0.1, XMAX - 0.45, YMIN + 0.1, YMAX + MAZE_XSHIFT, YMAX + MAZE_XSHIFT);
// print_left_right_part_number(configs, XMIN + 0.1, YMIN + 0.1, XMAX - 0.45, YMIN + 0.1, YMIN + MAZE_XSHIFT, YMAX + MAZE_XSHIFT);
else if (PRINT_COLLISION_NUMBER) print_collision_number(ncollisions, XMIN + 0.1, YMIN + 0.1); else if (PRINT_COLLISION_NUMBER) print_collision_number(ncollisions, XMIN + 0.1, YMIN + 0.1);
for (j=0; j<NPARTMAX; j++) color[j] = newcolor[j]; for (j=0; j<NPARTMAX; j++) color[j] = newcolor[j];

View File

@ -142,10 +142,17 @@
#define SLEEP2 1000 /* final sleeping time */ #define SLEEP2 1000 /* final sleeping time */
#define END_FRAMES 100 /* number of still frames at end of movie */ #define END_FRAMES 100 /* number of still frames at end of movie */
#define NXMAZE 8 /* width of maze */
#define NYMAZE 8 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 58 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define NPATHBINS 200 /* number of bins for path length histogramm */ #define NPATHBINS 200 /* number of bins for path length histogramm */
#define PATHLMAX 1.8 /* max free path on graph */ #define PATHLMAX 1.8 /* max free path on graph */
#include "global_particles.c" #include "global_particles.c"
#include "sub_maze.c"
#include "sub_part_billiard.c" #include "sub_part_billiard.c"
#include "sub_part_pinball.c" #include "sub_part_pinball.c"

View File

@ -39,51 +39,56 @@
#include <omp.h> #include <omp.h>
#include <time.h> #include <time.h>
#define MOVIE 1 /* set to 1 to generate movie */ #define MOVIE 0 /* set to 1 to generate movie */
/* General geometrical parameters */ /* General geometrical parameters */
// #define WINWIDTH 1920 /* window width */ #define WINWIDTH 1920 /* window width */
// #define WINHEIGHT 1000 /* window height */ #define WINHEIGHT 1000 /* window height */
// #define NX 1920 /* number of grid points on x axis */ // #define NX 1920 /* number of grid points on x axis */
// #define NY 992 /* number of grid points on y axis */ // #define NY 992 /* number of grid points on y axis */
//
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
// #define YMIN -1.041666667
// #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */
#define HIGHRES 0 /* set to 1 if resolution of grid is double that of displayed image */
#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 XMIN -2.0
#define XMAX 2.0 /* x interval */ #define XMAX 2.0 /* x interval */
#define YMIN -1.125 #define YMIN -1.041666667
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */ #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */
#define HIGHRES 0 /* set to 1 if resolution of grid is double that of displayed image */
// #define WINWIDTH 1280 /* window width */
// #define WINHEIGHT 720 /* window height */
#define NX 256 /* number of grid points on x axis */
#define NY 256 /* number of grid points on y axis */
#define NZ 256 /* number of grid points on z axis, for 3D percolation */
// #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 */
/* Boundary conditions, see list in global_pdes.c */ /* Boundary conditions, see list in global_pdes.c */
#define LATTICE 2 #define LATTICE 100
#define FLOOD_LEFT_BOUNDARY 0 /* set to 1 to flood cells on left boundary */ #define FLOOD_LEFT_BOUNDARY 0 /* set to 1 to flood cells on left boundary */
#define FIND_ALL_CLUSTERS 1 /* set to 1 to find all open clusters */ #define FLOOD_BOTTOM_BOUNDARY 0 /* set to 1 to flood cells on bottom boundary */
#define FIND_ALL_CLUSTERS 1 /* set to 1 to find all open clusters */
#define PLOT_ONLY_FLOODED_CELLS 0 /* set to 1 to plot only flooded cells */
#define PLOT_CLUSTER_SIZE 0 /* set to 1 to add a plot for the size of the percolation cluster */ #define PLOT_CLUSTER_SIZE 0 /* set to 1 to add a plot for the size of the percolation cluster */
#define PLOT_CLUSTER_NUMBER 0 /* set to 1 to add a graph of the number of clusters */ #define PLOT_CLUSTER_NUMBER 0 /* set to 1 to add a graph of the number of clusters */
#define PLOT_CLUSTER_HISTOGRAM 1 /* set to 1 to add a histogram of the number of clusters */ #define PLOT_CLUSTER_HISTOGRAM 1 /* set to 1 to add a histogram of the number of clusters */
#define PRINT_LARGEST_CLUSTER_SIZE 1 /* set to 1 to print size of largest cluster */ #define PRINT_LARGEST_CLUSTER_SIZE 0 /* set to 1 to print size of largest cluster */
#define HISTO_X_LOG_SCALE 1 /* set to 1 to use a log scale on cluster sizes */
#define P_SCHEDULE_POWER 4 /* power controlling slowing down near pc - 2 is standard, higher values mean slower passage */
#define MAX_CLUSTER_NUMBER 6 /* vertical scale of the cluster number plot */ #define MAX_CLUSTER_NUMBER 6 /* vertical scale of the cluster number plot */
#define HISTO_BINS 30 /* number of bins in histogram */ #define HISTO_BINS 30 /* number of bins in histogram */
#define NSTEPS 100 /* number of frames of movie */ #define NSTEPS 100 /* number of frames of movie */
// #define NSTEPS 700 /* number of frames of movie */ // #define NSTEPS 760 /* number of frames of movie */
// #define NSTEPS 830 /* number of frames of movie */
#define PAUSE 200 /* number of frames after which to pause */ #define PAUSE 200 /* number of frames after which to pause */
#define PSLEEP 2 /* sleep time during pause */ #define PSLEEP 2 /* sleep time during pause */
@ -95,11 +100,13 @@
/* Color schemes */ /* Color schemes */
#define COLOR_PALETTE 15 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE 10 /* Color palette, see list in global_pdes.c */
#define BLACK 1 /* background */ #define BLACK 1 /* background */
#define COLOR_CLUSTERS_BY_SIZE 1 /* set to 1 to link cluster color to their size */ #define COLOR_CLUSTERS_BY_SIZE 1 /* set to 1 to link cluster color to their size */
#define COLOR_CELLS_BY_XCOORD 0 /* set to 1 to color cells according to their x-coordinate */
#define COLOR_CELLS_BY_ZCOORD 0 /* set to 1 to color cells according to their z-coordinate */
#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.0 /* sensitivity of color on wave amplitude */
@ -107,10 +114,11 @@
#define HUE_CLOSED 350.0 /* color hue of closed cells */ #define HUE_CLOSED 350.0 /* color hue of closed cells */
#define HUE_OPEN 200.0 /* color hue of open (dry) cells */ #define HUE_OPEN 200.0 /* color hue of open (dry) cells */
#define HUE_FLOODED 45.0 /* color hue of open flooded cells */ #define HUE_FLOODED 300.0 /* color hue of open flooded cells */
#define HUE_GRAPH 250.0 /* color hue in graph of cluster size */ #define HUE_GRAPH_SIZE 250.0 /* color hue in graph of cluster size */
#define HUE_GRAPH_CLUSTERS 150.0 /* color hue in graph of cluster size */
#define CLUSTER_HUEMIN 60.0 /* minimal color hue of clusters */ #define CLUSTER_HUEMIN 10.0 /* minimal color hue of clusters */
#define CLUSTER_HUEMAX 300.0 /* maximal color hue of clusters */ #define CLUSTER_HUEMAX 300.0 /* maximal color hue of clusters */
#define N_CLUSTER_COLORS 20 /* number of different colors of clusters */ #define N_CLUSTER_COLORS 20 /* number of different colors of clusters */
@ -121,6 +129,24 @@
#define HUEMEAN 180.0 /* mean value of hue for color scheme C_HUE */ #define HUEMEAN 180.0 /* mean value of hue for color scheme C_HUE */
#define HUEAMP -180.0 /* amplitude of variation of hue for color scheme C_HUE */ #define HUEAMP -180.0 /* amplitude of variation of hue for color scheme C_HUE */
/* parameters of 3D representation */
double u_3d[2] = {0.75, -0.45}; /* projections of basis vectors for REP_AXO_3D representation */
double v_3d[2] = {-0.75, -0.45};
double w_3d[2] = {0.0, 0.015};
double light[3] = {0.816496581, 0.33333333, 0.4714045}; /* vector of "light" direction for P_3D_ANGLE color scheme */
double observer[3] = {8.0, 11.0, 10.0}; /* location of observer for REP_PROJ_3D representation */
int reset_view = 0; /* switch to reset 3D view parameters (for option ROTATE_VIEW) */
#define REPRESENTATION_3D 1 /* choice of 3D representation */
#define Z_SCALING_FACTOR 1.0 /* overall scaling factor of z axis for REP_PROJ_3D representation */
#define XY_SCALING_FACTOR 2.4 /* overall scaling factor for on-screen (x,y) coordinates after projection */
#define ZMAX_FACTOR 1.0 /* max value of z coordinate for REP_PROJ_3D representation */
#define XSHIFT_3D -0.4 /* overall x shift for REP_PROJ_3D representation */
#define YSHIFT_3D 0.0 /* overall y shift for REP_PROJ_3D representation */
#define ROTATE_VIEW 0 /* set to 1 to rotate viewpoint */
#define ROTATE_ANGLE 360.0 /* total angle of viewpoint rotation */
/* debugging options */ /* debugging options */
#define VERBOSE 0 /* set to 1 to print more messages in shell */ #define VERBOSE 0 /* set to 1 to print more messages in shell */
#define DEBUG 0 /* set to 1 for some debugging features */ #define DEBUG 0 /* set to 1 for some debugging features */
@ -130,24 +156,25 @@
#define ADD_PLOT ((PLOT_CLUSTER_SIZE)||(PLOT_CLUSTER_NUMBER)||(PLOT_CLUSTER_HISTOGRAM)) #define ADD_PLOT ((PLOT_CLUSTER_SIZE)||(PLOT_CLUSTER_NUMBER)||(PLOT_CLUSTER_HISTOGRAM))
#define FIND_CLUSTER_SIZES ((COLOR_CLUSTERS_BY_SIZE)||(PLOT_CLUSTER_HISTOGRAM)) #define FIND_CLUSTER_SIZES ((COLOR_CLUSTERS_BY_SIZE)||(PLOT_CLUSTER_HISTOGRAM))
#define PLOT_3D (LATTICE == BC_CUBIC_DIRICHLET)
#include "global_perc.c" /* constants and global variables */ #include "global_perc.c" /* constants and global variables */
#include "sub_perco_3d.c" /* support for 3D graphics */
#include "sub_perco.c" #include "sub_perco.c"
void animation(int size) void animation(int size)
{ {
int i, j, k, s, nx, ny, nmaxcells, maxsize, nopen, nflooded, nstack, nclusters, maxclustersize = 0, maxclusterlabel; int i, j, k, s, nx, ny, nz, nmaxcells, maxsize, nopen, nflooded, nstack, nclusters, maxclustersize = 0, maxclusterlabel;
int *plot_cluster_number, *cluster_sizes; int *plot_cluster_number, *cluster_sizes;
int ncells; int ncells;
double p, *plot_cluster_size; double p, *plot_cluster_size;
t_perco *cell; t_perco *cell;
t_perco **pstack; t_perco **pstack;
compute_nxny(size, &nx, &ny); compute_nxnynz(size, &nx, &ny, &nz);
nmaxcells = cell_number(NX, NY); nmaxcells = cell_number(NX, NY, NZ);
cell = (t_perco *)malloc(nmaxcells*sizeof(t_perco)); cell = (t_perco *)malloc(nmaxcells*sizeof(t_perco));
if (PLOT_CLUSTER_SIZE) plot_cluster_size = (double *)malloc(NSTEPS*sizeof(double)); if (PLOT_CLUSTER_SIZE) plot_cluster_size = (double *)malloc(NSTEPS*sizeof(double));
@ -155,8 +182,9 @@ void animation(int size)
// if (FIND_CLUSTER_SIZES) // if (FIND_CLUSTER_SIZES)
cluster_sizes = (int *)malloc(2*nmaxcells*sizeof(int)); cluster_sizes = (int *)malloc(2*nmaxcells*sizeof(int));
ncells = init_cell_lattice(cell, nx, ny); ncells = init_cell_lattice(cell, nx, ny, nz);
printf("nx = %i, ny = %i, ncells = %i, maxcells = %i\n", nx, ny, ncells, nmaxcells);
printf("nx = %i, ny = %i, nz = %i, ncells = %i, maxcells = %i\n", nx, ny, nz, ncells, nmaxcells);
pstack = (t_perco* *)malloc(ncells*sizeof(struct t_perco *)); pstack = (t_perco* *)malloc(ncells*sizeof(struct t_perco *));
@ -169,14 +197,21 @@ void animation(int size)
p = p_schedule(i); p = p_schedule(i);
printf("\ni = %i, p = %.4lg\n", i, p); printf("\ni = %i, p = %.4lg\n", i, p);
if (ROTATE_VIEW)
{
viewpoint_schedule(i);
reset_view = 1;
}
init_cell_state(cell, p, ncells, (i == 0)); init_cell_state(cell, p, ncells, (i == 0));
if (FLOOD_LEFT_BOUNDARY) nstack = init_flooded_cells(cell, ncells, nx, ny, pstack); if (FLOOD_LEFT_BOUNDARY) nstack = init_flooded_cells(cell, ncells, nx, ny, nz, 0, pstack);
if (FLOOD_BOTTOM_BOUNDARY) nstack = init_flooded_cells(cell, ncells, nx, ny, nz, 1, pstack);
nopen = count_open_cells(cell, ncells); nopen = count_open_cells(cell, ncells);
printf("Flooded cells, %i open cells, nstack = %i\n", nopen, nstack); printf("Flooded cells, %i open cells, nstack = %i\n", nopen, nstack);
if (FLOOD_LEFT_BOUNDARY) if ((FLOOD_LEFT_BOUNDARY)||(FLOOD_BOTTOM_BOUNDARY))
{ {
nflooded = find_percolation_cluster(cell, ncells, pstack, nstack); nflooded = find_percolation_cluster(cell, ncells, pstack, nstack);
printf("Found percolation cluster with %i flooded cells\n", nflooded); printf("Found percolation cluster with %i flooded cells\n", nflooded);
@ -196,7 +231,7 @@ void animation(int size)
// print_cluster_sizes(cell, ncells, cluster_sizes); // print_cluster_sizes(cell, ncells, cluster_sizes);
draw_configuration(cell, cluster_sizes, ncells, nx, ny, size, ncells); draw_configuration(cell, cluster_sizes, ncells, nx, ny, nz, size, ncells);
print_p(p); print_p(p);
if (PRINT_LARGEST_CLUSTER_SIZE) print_largest_cluster_size(maxclustersize); if (PRINT_LARGEST_CLUSTER_SIZE) print_largest_cluster_size(maxclustersize);
@ -265,8 +300,8 @@ void display(void)
// animation(64); // animation(64);
// animation(32); // animation(32);
// animation(16); // animation(16);
// animation(8); animation(8);
animation(4); // animation(4);
// animation(2); // animation(2);
// animation(1); // animation(1);

308
rde.c
View File

@ -39,58 +39,48 @@
#include <omp.h> #include <omp.h>
#include <time.h> #include <time.h>
#define MOVIE 1 /* 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 */ #define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */
/* General geometrical parameters */ /* General geometrical parameters */
#define WINWIDTH 1920 /* window width */ #define WINWIDTH 1920 /* window width */
#define WINHEIGHT 1000 /* window height */ #define WINHEIGHT 1000 /* window height */
// // #define NX 640 /* number of grid points on x axis */ #define NX 960 /* number of grid points on x axis */
// // #define NY 360 /* number of grid points on y axis */ #define NY 500 /* number of grid points on y axis */
// #define NX 600 /* number of grid points on x axis */ // #define NX 480 /* number of grid points on x axis */
// #define NY 300 /* number of grid points on y axis */ // #define NY 250 /* number of grid points on y axis */
// // #define NX 480 /* number of grid points on x axis */
// // #define NY 240 /* number of grid points on y axis */ #define XMIN -2.0
// // #define NX 1920 /* number of grid points on x axis */ #define XMAX 2.0 /* x interval */
// // #define NY 1000 /* number of grid points on y axis */ #define YMIN -1.041666667
// #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
// #define YMIN -1.041666667
// #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */
// #define WINWIDTH 1280 /* window width */ // #define WINWIDTH 1280 /* window width */
// #define WINHEIGHT 720 /* window height */ // #define WINHEIGHT 720 /* window height */
//
// #define NX 200 /* number of grid points on x axis */ // // #define NX 320 /* number of grid points on x axis */
// #define NY 200 /* number of grid points on y axis */ // // #define NY 180 /* number of grid points on y axis */
#define NX 500 /* number of grid points on x axis */
#define NY 500 /* number of grid points on y axis */
// #define NX 640 /* number of grid points on x axis */ // #define NX 640 /* number of grid points on x axis */
// #define NY 360 /* number of grid points on y axis */ // #define NY 360 /* number of grid points on y axis */
//
// #define NX 1280 /* number of grid points on x axis */ // // #define NX 1280 /* number of grid points on x axis */
// #define NY 720 /* number of grid points on y axis */ // // #define NY 720 /* number of grid points on y axis */
//
#define XMIN -1.8 // #define XMIN -2.0
#define XMAX 1.8 /* x interval */ // #define XMAX 2.0 /* x interval */
#define YMIN -1.8 // #define YMIN -1.125
#define YMAX 1.8 /* y interval for 9/16 aspect ratio */ // #define YMAX 1.125 /* y interval for 9/16 aspect ratio */
/* Choice of simulated equation */ /* Choice of simulated equation */
#define RDE_EQUATION 5 /* choice of reaction term, see list in global_3d.c */ #define RDE_EQUATION 6 /* choice of reaction term, see list in global_3d.c */
#define NFIELDS 2 /* number of fields in reaction-diffusion equation */ #define NFIELDS 2 /* number of fields in reaction-diffusion equation */
#define NLAPLACIANS 2 /* number of fields for which to compute Laplacian */ #define NLAPLACIANS 1 /* number of fields for which to compute Laplacian */
// #define RDE_EQUATION 4 /* choice of reaction term, see list in global_3d.c */
// #define NFIELDS 3 /* number of fields in reaction-diffusion equation */
// #define NLAPLACIANS 3 /* number of fields for which to compute Laplacian */
#define ADD_POTENTIAL 1 /* set to 1 to add a potential (for Schrodinger equation) */ #define ADD_POTENTIAL 0 /* set to 1 to add a potential (for Schrodinger equation) */
#define POTENTIAL 1 /* type of potential, see list in global_3d.c */ #define ADD_MAGNETIC_FIELD 0 /* set to 1 to add a magnetic field (for Schrodinger equation) - then set POTENTIAL 1 */
#define ADD_MAGNETIC_FIELD 1 /* set to 1 to add a magnetic field (for Schrodinger equation) - then set POTENTIAL 1 */ #define POTENTIAL 7 /* type of potential or vector potential, see list in global_3d.c */
#define ANTISYMMETRIZE_WAVE_FCT 0 /* set tot 1 to make wave function antisymmetric */ #define ANTISYMMETRIZE_WAVE_FCT 0 /* set tot 1 to make wave function antisymmetric */
@ -134,10 +124,11 @@
/* Physical patameters of wave equation */ /* Physical patameters of wave equation */
#define DT 0.00000002 // #define DT 0.00000002
// #define DT 0.00000003 // #define DT 0.00000003
// #define DT 0.000000011 // #define DT 0.000000011
// #define DT 0.00000001 #define DT 0.0000012
// #define DT 0.000001
#define VISCOSITY 2.0 #define VISCOSITY 2.0
@ -148,10 +139,18 @@
#define DELTA 0.1 /* time scale separation */ #define DELTA 0.1 /* time scale separation */
#define FHNA 1.0 /* parameter in FHN equation */ #define FHNA 1.0 /* parameter in FHN equation */
#define FHNC -0.01 /* parameter in FHN equation */ #define FHNC -0.01 /* parameter in FHN equation */
#define K_HARMONIC 0.5 /* spring constant of harmonic potential */ #define K_HARMONIC 1.0 /* spring constant of harmonic potential */
#define K_COULOMB 0.5 /* constant in Coulomb potential */ #define K_COULOMB 0.5 /* constant in Coulomb potential */
#define V_MAZE 0.4 /* potential in walls of maze */
#define BZQ 0.0008 /* parameter in BZ equation */ #define BZQ 0.0008 /* parameter in BZ equation */
#define BZF 1.2 /* parameter in BZ equation */ #define BZF 1.2 /* parameter in BZ equation */
#define B_FIELD 10.0 /* magnetic field */
#define AB_RADIUS 0.2 /* radius of region with magnetic field for Aharonov-Bohm effect */
#define K_EULER 50.0 /* constant in stream function integration of Euler equation */
#define SMOOTHEN_VORTICITY 1 /* set to 1 to smoothen vorticity field in Euler equation */
#define SMOOTHEN_PERIOD 10 /* period between smoothenings */
#define SMOOTH_FACTOR 0.015 /* factor by which to smoothen */
#define T_OUT 2.0 /* outside temperature */ #define T_OUT 2.0 /* outside temperature */
#define T_IN 0.0 /* inside temperature */ #define T_IN 0.0 /* inside temperature */
@ -182,9 +181,10 @@
/* Parameters for length and speed of simulation */ /* Parameters for length and speed of simulation */
// #define NSTEPS 500 /* number of frames of movie */ #define NSTEPS 4000 /* number of frames of movie */
#define NSTEPS 1100 /* number of frames of movie */ // #define NSTEPS 2500 /* number of frames of movie */
#define NVID 500 /* 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 1100 /* number of iterations between images displayed on screen */ // #define NVID 1100 /* number of iterations between images displayed on screen */
#define ACCELERATION_FACTOR 1.0 /* factor by which to increase NVID in course of simulation */ #define ACCELERATION_FACTOR 1.0 /* factor by which to increase NVID in course of simulation */
#define DT_ACCELERATION_FACTOR 1.0 /* factor by which to increase time step in course of simulation */ #define DT_ACCELERATION_FACTOR 1.0 /* factor by which to increase time step in course of simulation */
@ -203,22 +203,21 @@
/* Visualisation */ /* Visualisation */
#define PLOT_3D 1 /* controls whether plot is 2D or 3D */ #define PLOT_3D 0 /* controls whether plot is 2D or 3D */
#define ROTATE_VIEW 0 /* set to 1 to rotate position of observer */ #define ROTATE_VIEW 0 /* set to 1 to rotate position of observer */
#define ROTATE_ANGLE 360.0 /* total angle of rotation during simulation */ #define ROTATE_ANGLE 360.0 /* total angle of rotation during simulation */
/* Plot type - color scheme */ /* Plot type - color scheme */
#define CPLOT 32 #define CPLOT 52
// #define CPLOT 32 #define CPLOT_B 51
#define CPLOT_B 31
/* Plot type - height of 3D plot */ /* Plot type - height of 3D plot */
#define ZPLOT 32 /* z coordinate in 3D plot */ #define ZPLOT 52 /* z coordinate in 3D plot */
// #define ZPLOT 32 /* z coordinate in 3D plot */ // #define ZPLOT 32 /* z coordinate in 3D plot */
#define ZPLOT_B 30 /* z coordinate in second 3D plot */ #define ZPLOT_B 51 /* z coordinate in second 3D plot */
#define AMPLITUDE_HIGH_RES 1 /* set to 1 to increase resolution of P_3D_AMPLITUDE plot */ #define AMPLITUDE_HIGH_RES 1 /* set to 1 to increase resolution of P_3D_AMPLITUDE plot */
#define SHADE_3D 1 /* set to 1 to change luminosity according to normal vector */ #define SHADE_3D 1 /* set to 1 to change luminosity according to normal vector */
@ -226,8 +225,8 @@
#define WRAP_ANGLE 1 /* experimental: wrap angle to [0, 2Pi) for interpolation in angle schemes */ #define WRAP_ANGLE 1 /* experimental: wrap angle to [0, 2Pi) for interpolation in angle schemes */
#define FADE_IN_OBSTACLE 0 /* set to 1 to fade color inside obstacles */ #define FADE_IN_OBSTACLE 0 /* set to 1 to fade color inside obstacles */
#define DRAW_OUTSIDE_GRAY 0 /* experimental - draw outside of billiard in gray */ #define DRAW_OUTSIDE_GRAY 0 /* experimental - draw outside of billiard in gray */
#define ADD_POTENTIAL_TO_Z 0 /* set to 1 to add the external potential to z-coordinate of plot */ #define ADD_POTENTIAL_TO_Z 1 /* set to 1 to add the external potential to z-coordinate of plot */
#define ADD_POT_CONSTANT 1.0 /* constant in front of added potential */ #define ADD_POT_CONSTANT 0.35 /* constant in front of added potential */
#define PLOT_SCALE_ENERGY 0.05 /* vertical scaling in energy plot */ #define PLOT_SCALE_ENERGY 0.05 /* vertical scaling in energy plot */
@ -255,7 +254,7 @@
/* Color schemes, see list in global_pdes.c */ /* Color schemes, see list in global_pdes.c */
#define COLOR_PALETTE 11 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE 11 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE_B 0 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE_B 17 /* Color palette, see list in global_pdes.c */
#define BLACK 1 /* black background */ #define BLACK 1 /* black background */
@ -265,7 +264,7 @@
#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.0 /* sensitivity of color on wave amplitude */
#define VSCALE_AMPLITUDE 30.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */ #define VSCALE_AMPLITUDE 0.5 /* additional scaling factor for color scheme P_3D_AMPLITUDE */
#define ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */ #define ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */
#define CURL_SCALE 0.000015 /* scaling factor for curl representation */ #define CURL_SCALE 0.000015 /* scaling factor for curl representation */
#define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */ #define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */
@ -277,13 +276,19 @@
#define LUMMEAN 0.5 /* amplitude of luminosity variation for scheme C_LUM */ #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 LUMAMP 0.3 /* amplitude of luminosity variation for scheme C_LUM */
#define HUEMEAN 359.0 /* mean value of hue for color scheme C_HUE */ #define HUEMEAN 359.0 /* mean value of hue for color scheme C_HUE */
#define HUEAMP -359.0 /* amplitude of variation of hue for color scheme C_HUE */ #define HUEAMP -359.0 /* amplitude of variation of hue for color scheme C_HUE */
#define E_SCALE 100.0 /* scaling factor for energy representation */ #define E_SCALE 100.0 /* scaling factor for energy representation */
#define LOG_SCALE 1.0 /* scaling factor for energy log representation */ #define LOG_SCALE 0.75 /* scaling factor for energy log representation */
#define LOG_SHIFT 0.0 #define LOG_SHIFT 1.0
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */ #define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */
#define COLORBAR_RANGE 2.5 /* scale of color scheme bar */ #define COLORBAR_RANGE 3.0 /* scale of color scheme bar */
#define COLORBAR_RANGE_B 2.5 /* scale of color scheme bar for 2nd part */ #define COLORBAR_RANGE_B 2.5 /* scale of color scheme bar for 2nd part */
#define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */ #define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */
@ -312,38 +317,54 @@ double u_3d[2] = {0.75, -0.45}; /* projections of basis vectors for REP_AXO_
double v_3d[2] = {-0.75, -0.45}; double v_3d[2] = {-0.75, -0.45};
double w_3d[2] = {0.0, 0.015}; double w_3d[2] = {0.0, 0.015};
double light[3] = {0.816496581, -0.40824829, 0.40824829}; /* vector of "light" direction for P_3D_ANGLE color scheme */ double light[3] = {0.816496581, -0.40824829, 0.40824829}; /* vector of "light" direction for P_3D_ANGLE color scheme */
double observer[3] = {8.0, 8.0, 12.0}; /* location of observer for REP_PROJ_3D representation */ double observer[3] = {8.0, 8.0, 8.0}; /* location of observer for REP_PROJ_3D representation */
int reset_view = 0; /* switch to reset 3D view parameters (for option ROTATE_VIEW) */ int reset_view = 0; /* switch to reset 3D view parameters (for option ROTATE_VIEW) */
#define Z_SCALING_FACTOR 1.25 /* overall scaling factor of z axis for REP_PROJ_3D representation */ #define Z_SCALING_FACTOR 0.25 /* overall scaling factor of z axis for REP_PROJ_3D representation */
#define XY_SCALING_FACTOR 1.8 /* overall scaling factor for on-screen (x,y) coordinates after projection */ #define XY_SCALING_FACTOR 1.8 /* overall scaling factor for on-screen (x,y) coordinates after projection */
#define ZMAX_FACTOR 1.0 /* max value of z coordinate for REP_PROJ_3D representation */ #define ZMAX_FACTOR 1.0 /* max value of z coordinate for REP_PROJ_3D representation */
#define XSHIFT_3D -0.1 /* overall x shift for REP_PROJ_3D representation */ #define XSHIFT_3D -0.1 /* overall x shift for REP_PROJ_3D representation */
#define YSHIFT_3D 0.0 /* overall y shift for REP_PROJ_3D representation */ #define YSHIFT_3D 0.0 /* overall y shift for REP_PROJ_3D representation */
#define BORDER_PADDING 2 /* distance from boundary at which to plot points, to avoid boundary effects due to gradient */
/* For debugging purposes only */ /* For debugging purposes only */
#define FLOOR 1 /* set to 1 to limit wave amplitude to VMAX */ #define FLOOR 1 /* set to 1 to limit wave amplitude to VMAX */
#define VMAX 2.0 /* max value of wave amplitude */ #define VMAX 10.0 /* max value of wave amplitude */
#define TEST_GRADIENT 0 /* print norm squared of gradient */
#define REFRESH_B (ZPLOT_B != ZPLOT)||(CPLOT_B != CPLOT) /* to save computing time, to be improved */ #define REFRESH_B (ZPLOT_B != ZPLOT)||(CPLOT_B != CPLOT) /* to save computing time, to be improved */
#define COMPUTE_WRAP_ANGLE ((WRAP_ANGLE)&&((cplot == Z_ANGLE_GRADIENT)||(cplot == Z_ANGLE_GRADIENTX)||(cplot == Z_ARGUMENT)||(cplot == Z_ANGLE_GRADIENTX))) #define COMPUTE_WRAP_ANGLE ((WRAP_ANGLE)&&((cplot == Z_ANGLE_GRADIENT)||(cplot == Z_ANGLE_GRADIENTX)||(cplot == Z_ARGUMENT)||(cplot == Z_ANGLE_GRADIENTX)))
#define PRINT_PARAMETERS ((PRINT_TIME)||(PRINT_VISCOSITY)||(PRINT_RPSLZB)||(PRINT_PROBABILITIES)||(PRINT_NOISE)) #define PRINT_PARAMETERS ((PRINT_TIME)||(PRINT_VISCOSITY)||(PRINT_RPSLZB)||(PRINT_PROBABILITIES)||(PRINT_NOISE))
#include "global_pdes.c" #include "global_pdes.c"
#include "global_3d.c" /* constants and global variables */
#include "sub_maze.c"
#include "sub_wave.c" #include "sub_wave.c"
#include "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */ #include "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
#include "global_3d.c" /* constants and global variables */
#include "sub_wave_3d_rde.c" /* should be later replaced by sub_wave_rde.c */ #include "sub_wave_3d_rde.c" /* should be later replaced by sub_wave_rde.c */
#include "sub_rde.c" #include "sub_rde.c"
double potential(int i, int j) double f_aharonov_bohm(double r2)
/* compute potential (e.g. for Schrödinger equation) */ /* radial part of Aharonov-Bohm vector potential */
{ {
double x, y, xy[2], r, small = 2.0e-1, kx, ky, lx = XMAX - XMIN, r1, r2, r3; double r02 = AB_RADIUS*AB_RADIUS;
if (r2 > r02) return(-0.25*r02/r2);
else return(0.25*(r2 - 2.0*r02)/r02);
// if (r2 > r02) return(1.0/r2);
// else return((2.0*r02 - r2)/(r02*r02));
}
double potential(int i, int j)
/* compute potential (e.g. for Schrödinger equation), or potential part if there is a magnetic field */
{
double x, y, xy[2], r, small = 1.0e-1, kx, ky, lx = XMAX - XMIN, r1, r2, r3, f;
int rect;
ij_to_xy(i, j, xy); ij_to_xy(i, j, xy);
x = xy[0]; x = xy[0];
@ -380,6 +401,23 @@ double potential(int i, int j)
// r = r/3.0; // r = r/3.0;
return (-0.5*K_COULOMB*(1.0/r1 + 1.0/r2 + 1.0/r3)); return (-0.5*K_COULOMB*(1.0/r1 + 1.0/r2 + 1.0/r3));
} }
case (VPOT_CONSTANT_FIELD):
{
return (K_HARMONIC*(x*x + y*y)); /* magnetic field strength b is chosen such that b^2 = K_HARMONIC */
}
case (VPOT_AHARONOV_BOHM):
{
r2 = x*x + y*y;
f = f_aharonov_bohm(r2);
return (B_FIELD*B_FIELD*f*f*r2); /* magnetic field strength b is chosen such that b^2 = K_HARMONIC */
// return (K_HARMONIC*f); /* magnetic field strength b is chosen such that b^2 = K_HARMONIC */
}
case (POT_MAZE):
{
for (rect=0; rect<npolyrect; rect++)
if (ij_in_polyrect(i, j, polyrect[rect])) return(V_MAZE);
return(0.0);
}
default: default:
{ {
return(0.0); return(0.0);
@ -391,17 +429,33 @@ double potential(int i, int j)
void compute_vector_potential(int i, int j, double *ax, double *ay) void compute_vector_potential(int i, int j, double *ax, double *ay)
/* initialize the vector potential, for Schrodinger equation in a magnetic field */ /* initialize the vector potential, for Schrodinger equation in a magnetic field */
{ {
double x, y, xy[2], b; double x, y, xy[2], r2, f;
ij_to_xy(i, j, xy); ij_to_xy(i, j, xy);
x = xy[0]; x = xy[0];
y = xy[1]; y = xy[1];
b = sqrt(K_HARMONIC); switch (POTENTIAL) {
/* magnetic field strength b is chosen such that b^2/4 = K_HARMONIC */ case (VPOT_CONSTANT_FIELD):
{
*ax = b*y; *ax = B_FIELD*y;
*ay = -b*x; *ay = -B_FIELD*x;
break;
}
case (VPOT_AHARONOV_BOHM):
{
r2 = x*x + y*y;
f = f_aharonov_bohm(r2);
*ax = B_FIELD*y*f;
*ay = -B_FIELD*x*f;
break;
}
default:
{
*ax = 0.0;
*ay = 0.0;
}
}
} }
@ -435,9 +489,11 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
/* time step of field evolution */ /* time step of field evolution */
{ {
int i, j, k, iplus, iminus, jplus, jminus; int i, j, k, iplus, iminus, jplus, jminus;
double x, y, z, deltax, deltay, deltaz, rho, pot, vx, vy; double x, y, z, deltax, deltay, deltaz, rho, pot, vx, vy, test = 0.0, dx;
double *delta_phi[NLAPLACIANS], *nabla_phi, *nabla_psi; double *delta_phi[NLAPLACIANS], *nabla_phi, *nabla_psi, *nabla_omega, *delta_vorticity;
static double invsqr3 = 0.577350269; /* 1/sqrt(3) */ static double invsqr3 = 0.577350269; /* 1/sqrt(3) */
static double stiffness = 2.0; /* stiffness of Poisson equation solver */
static int smooth = 0;
for (i=0; i<NLAPLACIANS; i++) delta_phi[i] = (double *)malloc(NX*NY*sizeof(double)); for (i=0; i<NLAPLACIANS; i++) delta_phi[i] = (double *)malloc(NX*NY*sizeof(double));
@ -453,6 +509,38 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
compute_gradient_xy(phi_in[1], nabla_psi); compute_gradient_xy(phi_in[1], nabla_psi);
} }
/* compute gradients of stream function and vorticity for Euler equation */
if (RDE_EQUATION == E_EULER_INCOMP)
{
nabla_psi = (double *)malloc(2*NX*NY*sizeof(double));
nabla_omega = (double *)malloc(2*NX*NY*sizeof(double));
compute_gradient_euler(phi_in[0], nabla_psi);
compute_gradient_euler(phi_in[1], nabla_omega);
dx = (XMAX-XMIN)/((double)NX);
if (SMOOTHEN_VORTICITY) /* beta: try to reduce formation of ripples */
{
if (smooth == 0)
{
delta_vorticity = (double *)malloc(NX*NY*sizeof(double));
compute_laplacian_rde(phi_in[1], delta_vorticity, xy_in);
for (i=0; i<NX*NY; i++) phi_in[1][i] += intstep*SMOOTH_FACTOR*delta_vorticity[i];
free(delta_vorticity);
}
smooth++;
if (smooth >= SMOOTHEN_PERIOD) smooth = 0;
}
}
if (TEST_GRADIENT) {
for (i=0; i<2*NX*NY; i++){
test += nabla_omega[i]*nabla_omega[i];
test += nabla_psi[i]*nabla_psi[i];
}
printf("nabla square = %.5lg\n", test/((double)NX*NY));
}
#pragma omp parallel for private(i,j,k,x,y,z,deltax,deltay,deltaz,rho) #pragma omp parallel for private(i,j,k,x,y,z,deltax,deltay,deltaz,rho)
for (i=0; i<NX; i++){ for (i=0; i<NX; i++){
for (j=0; j<NY; j++){ for (j=0; j<NY; j++){
@ -517,7 +605,7 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
{ {
phi_out[0][i*NY+j] = phi_in[0][i*NY+j] - intstep*delta_phi[1][i*NY+j]; phi_out[0][i*NY+j] = phi_in[0][i*NY+j] - intstep*delta_phi[1][i*NY+j];
phi_out[1][i*NY+j] = phi_in[1][i*NY+j] + intstep*delta_phi[0][i*NY+j]; phi_out[1][i*NY+j] = phi_in[1][i*NY+j] + intstep*delta_phi[0][i*NY+j];
if (ADD_POTENTIAL) if ((ADD_POTENTIAL)||(ADD_MAGNETIC_FIELD))
{ {
pot = potential_field[i*NY+j]; pot = potential_field[i*NY+j];
phi_out[0][i*NY+j] += intstep*pot*phi_in[1][i*NY+j]; phi_out[0][i*NY+j] += intstep*pot*phi_in[1][i*NY+j];
@ -530,10 +618,26 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
phi_out[0][i*NY+j] -= 2.0*intstep*(vx*nabla_phi[i*NY+j] + vy*nabla_phi[NX*NY+i*NY+j]); phi_out[0][i*NY+j] -= 2.0*intstep*(vx*nabla_phi[i*NY+j] + vy*nabla_phi[NX*NY+i*NY+j]);
phi_out[1][i*NY+j] -= 2.0*intstep*(vx*nabla_psi[i*NY+j] + vy*nabla_psi[NX*NY+i*NY+j]); phi_out[1][i*NY+j] -= 2.0*intstep*(vx*nabla_psi[i*NY+j] + vy*nabla_psi[NX*NY+i*NY+j]);
} }
break;
}
case (E_EULER_INCOMP):
{
phi_out[0][i*NY+j] = phi_in[0][i*NY+j] + intstep*stiffness*(delta_phi[0][i*NY+j] + phi_in[1][i*NY+j]*dx*dx);
phi_out[1][i*NY+j] = phi_in[1][i*NY+j] - intstep*K_EULER*(nabla_omega[i*NY+j]*nabla_psi[NX*NY+i*NY+j]);
phi_out[1][i*NY+j] += intstep*K_EULER*(nabla_omega[NX*NY+i*NY+j]*nabla_psi[i*NY+j]);
break;
} }
} }
} }
} }
if (TEST_GRADIENT) {
test = 0.0;
for (i=0; i<NX*NY; i++){
test += delta_phi[0][i] + phi_out[1][i]*dx*dx;
}
printf("Delta psi + omega = %.5lg\n", test/((double)NX*NY));
}
if (FLOOR) for (i=0; i<NX; i++){ if (FLOOR) for (i=0; i<NX; i++){
for (j=0; j<NY; j++){ for (j=0; j<NY; j++){
@ -552,6 +656,12 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
free(nabla_phi); free(nabla_phi);
free(nabla_psi); free(nabla_psi);
} }
if (RDE_EQUATION == E_EULER_INCOMP)
{
free(nabla_psi);
free(nabla_omega);
}
} }
void evolve_wave(double *phi[NFIELDS], double *phi_tmp[NFIELDS], short int xy_in[NX*NY], double potential_field[NX*NY], double vector_potential_field[2*NX*NY]) void evolve_wave(double *phi[NFIELDS], double *phi_tmp[NFIELDS], short int xy_in[NX*NY], double potential_field[NX*NY], double vector_potential_field[2*NX*NY])
@ -660,10 +770,20 @@ void draw_color_bar_palette(int plot, double range, int palette, int fade, doubl
double width = 0.14; double width = 0.14;
// double width = 0.2; // double width = 0.2;
if (ROTATE_COLOR_SCHEME) if (PLOT_3D)
draw_color_scheme_palette_3d(-1.0, -0.8, XMAX - 0.1, -1.0, plot, -range, range, palette, fade, fade_value); {
else if (ROTATE_COLOR_SCHEME)
draw_color_scheme_palette_3d(XMAX - 1.5*width, YMIN + 0.1, XMAX - 0.5*width, YMAX - 0.1, plot, -range, range, palette, fade, fade_value); draw_color_scheme_palette_3d(-1.0, -0.8, XMAX - 0.1, -1.0, plot, -range, range, palette, fade, fade_value);
else
draw_color_scheme_palette_3d(XMAX - 1.5*width, YMIN + 0.1, XMAX - 0.5*width, YMAX - 0.1, plot, -range, range, palette, fade, fade_value);
}
else
{
if (ROTATE_COLOR_SCHEME)
draw_color_scheme_palette_fade(-1.0, -0.8, XMAX - 0.1, -1.0, plot, -range, range, palette, fade, fade_value);
else
draw_color_scheme_palette_fade(XMAX - 1.5*width, YMIN + 0.1, XMAX - 0.5*width, YMAX - 0.1, plot, -range, range, palette, fade, fade_value);
}
} }
double noise_schedule(int i) double noise_schedule(int i)
@ -748,21 +868,25 @@ void animation()
xy_in = (short int *)malloc(NX*NY*sizeof(short int)); xy_in = (short int *)malloc(NX*NY*sizeof(short int));
rde = (t_rde *)malloc(NX*NY*sizeof(t_rde)); rde = (t_rde *)malloc(NX*NY*sizeof(t_rde));
npolyline = init_polyline(MDEPTH, polyline);
for (i=0; i<npolyline; i++) printf("vertex %i: (%.3f, %.3f)\n", i, polyline[i].x, polyline[i].y);
npolyrect = init_polyrect(polyrect);
for (i=0; i<npolyrect; i++) printf("polyrect vertex %i: (%.3f, %.3f) - (%.3f, %.3f)\n", i, polyrect[i].x1, polyrect[i].y1, polyrect[i].x2, polyrect[i].y2);
if (ADD_POTENTIAL) if (ADD_POTENTIAL)
{ {
potential_field = (double *)malloc(NX*NY*sizeof(double)); potential_field = (double *)malloc(NX*NY*sizeof(double));
initialize_potential(potential_field); initialize_potential(potential_field);
} }
else if (ADD_MAGNETIC_FIELD)
if (ADD_MAGNETIC_FIELD)
{ {
potential_field = (double *)malloc(NX*NY*sizeof(double));
vector_potential_field = (double *)malloc(2*NX*NY*sizeof(double)); vector_potential_field = (double *)malloc(2*NX*NY*sizeof(double));
initialize_potential(potential_field);
initialize_vector_potential(vector_potential_field); initialize_vector_potential(vector_potential_field);
} }
npolyline = init_polyline(MDEPTH, polyline);
for (i=0; i<npolyline; i++) printf("vertex %i: (%.3f, %.3f)\n", i, polyline[i].x, polyline[i].y);
dx = (XMAX-XMIN)/((double)NX); dx = (XMAX-XMIN)/((double)NX);
intstep = DT/(dx*dx); intstep = DT/(dx*dx);
@ -779,10 +903,16 @@ void animation()
// init_random(0.5, 0.4, phi, xy_in); // init_random(0.5, 0.4, phi, xy_in);
// init_random(0.0, 0.4, phi, xy_in); // init_random(0.0, 0.4, phi, xy_in);
// init_gaussian(x, y, mean, amplitude, scalex, phi, xy_in) // init_gaussian(x, y, mean, amplitude, scalex, phi, xy_in)
init_coherent_state(1.0, 0.0, 0.0, 5.0, 0.1, phi, xy_in); // init_coherent_state(-1.2, 0.35, 5.0, -2.0, 0.1, phi, xy_in);
// add_coherent_state(-0.75, -0.75, 0.0, 5.0, 0.1, phi, xy_in);
// init_fermion_state(-0.5, 0.5, 2.0, 0.0, 0.1, phi, xy_in); // init_fermion_state(-0.5, 0.5, 2.0, 0.0, 0.1, phi, xy_in);
// init_boson_state(-0.5, 0.5, 2.0, 0.0, 0.1, phi, xy_in); // init_boson_state(-0.5, 0.5, 2.0, 0.0, 0.1, phi, xy_in);
// init_vortex_state(0.4, 0.0, 0.1, phi, xy_in);
// add_vortex_state(-0.4, 0.0, 0.1, phi, xy_in);
init_shear_flow(1.0, 0.02, 0.03, 1, 1, phi, xy_in);
init_cfield_rde(phi, xy_in, CPLOT, rde, 0); init_cfield_rde(phi, xy_in, CPLOT, rde, 0);
if (PLOT_3D) init_zfield_rde(phi, xy_in, ZPLOT, rde, 0); if (PLOT_3D) init_zfield_rde(phi, xy_in, ZPLOT, rde, 0);
@ -985,7 +1115,11 @@ void animation()
} }
free(xy_in); free(xy_in);
if (ADD_POTENTIAL) free(potential_field); if (ADD_POTENTIAL) free(potential_field);
if (ADD_MAGNETIC_FIELD) free(vector_potential_field); else if (ADD_MAGNETIC_FIELD)
{
free(potential_field);
free(vector_potential_field);
}
printf("Time %.5lg\n", time); printf("Time %.5lg\n", time);

View File

@ -168,7 +168,20 @@
#define AMPLITUDE 0.8 /* amplitude of periodic excitation */ #define AMPLITUDE 0.8 /* amplitude of periodic excitation */
/* end of constants only used by wave_billiard and wave_3d */ /* end of constants only used by wave_billiard and wave_3d */
/* for compatibility with sub_wave and sub_maze */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define ADD_POTENTIAL 0
#define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
#include "global_pdes.c" #include "global_pdes.c"
#include "sub_maze.c"
#include "sub_wave.c" #include "sub_wave.c"
double courant2; /* Courant parameter squared */ double courant2; /* Courant parameter squared */

838
sub_lj.c

File diff suppressed because it is too large Load Diff

231
sub_maze.c Normal file
View File

@ -0,0 +1,231 @@
/* Warning: the function init_maze does not always return a maze with a solution */
/* The current algorithm uses a self-avoiding random walk. A better option may be */
/* to give random weights to the dual graph, and finite a maximal spanning tree */
/* Change constant RAND_SHIFT to change the maze */
typedef struct
{
short int nneighb; /* number of neighbours */
int neighb[MAZE_MAX_NGBH]; /* neighbour cells */
short int directions[MAZE_MAX_NGBH]; /* direction of neighbours */
short int north, east, south, west; /* closed walls */
short int active; /* takes value 1 if currently active in RW path */
short int tested; /* takes value 1 if tested */
} t_maze;
int nmaze(int i, int j)
{
return(NXMAZE*j + i);
}
void init_maze_graph(t_maze maze[NXMAZE*NYMAZE])
{
int i, j, k, n;
printf("Initializing maze\n");
/* initialize neighbours */
/* in the bulk */
for (i=1; i<NXMAZE-1; i++)
for (j=1; j<NYMAZE-1; j++)
{
n = nmaze(i, j);
maze[n].nneighb = 4;
maze[n].neighb[0] = nmaze(i, j+1);
maze[n].neighb[1] = nmaze(i+1, j);
maze[n].neighb[2] = nmaze(i, j-1);
maze[n].neighb[3] = nmaze(i-1, j);
for (k=0; k<4; k++) maze[n].directions[k] = k;
}
/* left side */
for (j=1; j<NYMAZE-1; j++)
{
n = nmaze(0, j);
maze[n].nneighb = 3;
maze[n].neighb[0] = nmaze(0, j+1);
maze[n].neighb[1] = nmaze(1, j);
maze[n].neighb[2] = nmaze(0, j-1);
for (k=0; k<3; k++) maze[n].directions[k] = k;
}
/* right side */
for (j=1; j<NYMAZE-1; j++)
{
n = nmaze(NXMAZE-1, j);
maze[n].nneighb = 3;
maze[n].neighb[0] = nmaze(NXMAZE-1, j+1);
maze[n].neighb[1] = nmaze(NXMAZE-2, j);
maze[n].neighb[2] = nmaze(NXMAZE-1, j-1);
maze[n].directions[0] = 0;
maze[n].directions[1] = 3;
maze[n].directions[2] = 2;
}
/* bottom side */
for (i=1; i<NXMAZE-1; i++)
{
n = nmaze(i, 0);
maze[n].nneighb = 3;
maze[n].neighb[0] = nmaze(i, 1);
maze[n].neighb[1] = nmaze(i+1, 0);
maze[n].neighb[2] = nmaze(i-1, 0);
maze[n].directions[0] = 0;
maze[n].directions[1] = 1;
maze[n].directions[2] = 3;
}
/* top side */
for (i=1; i<NXMAZE-1; i++)
{
n = nmaze(i, NYMAZE-1);
maze[n].nneighb = 3;
maze[n].neighb[0] = nmaze(i, NYMAZE-2);
maze[n].neighb[1] = nmaze(i+1, NYMAZE-1);
maze[n].neighb[2] = nmaze(i-1, NYMAZE-1);
maze[n].directions[0] = 2;
maze[n].directions[1] = 1;
maze[n].directions[2] = 3;
}
/* corners */
n = nmaze(0,0);
maze[n].nneighb = 2;
maze[n].neighb[0] = nmaze(1,0);
maze[n].neighb[1] = nmaze(0,1);
maze[n].directions[0] = 1;
maze[n].directions[1] = 0;
n = nmaze(NXMAZE-1,0);
maze[n].nneighb = 2;
maze[n].neighb[0] = nmaze(NXMAZE-2,0);
maze[n].neighb[1] = nmaze(NXMAZE-1,1);
maze[n].directions[0] = 3;
maze[n].directions[1] = 0;
n = nmaze(0,NYMAZE-1);
maze[n].nneighb = 2;
maze[n].neighb[0] = nmaze(1,NYMAZE-1);
maze[n].neighb[1] = nmaze(0,NYMAZE-2);
maze[n].directions[0] = 1;
maze[n].directions[1] = 2;
n = nmaze(NXMAZE-1,NYMAZE-1);
maze[n].nneighb = 2;
maze[n].neighb[0] = nmaze(NXMAZE-2,NYMAZE-1);
maze[n].neighb[1] = nmaze(NXMAZE-1,NYMAZE-2);
maze[n].directions[0] = 3;
maze[n].directions[1] = 2;
/* initialize other parameters */
for (i=0; i<NXMAZE; i++)
for (j=0; j<NYMAZE; j++)
{
n = nmaze(i, j);
maze[n].active = 0;
maze[n].tested = 0;
maze[n].north = 1;
maze[n].east = 1;
maze[n].south = 1;
maze[n].west = 1;
}
}
int find_maze_path(t_maze maze[NXMAZE*NYMAZE], int n0)
/* find a random walk path in the maze */
{
int active_counter = 0, i, n = n0, npaths, inext, nextcell, trial, nnext;
int next_table[4];
/* contruct random walk */
npaths = maze[n].nneighb;
// while ((npaths > 0)&&(!maze[n].tested))
while ((npaths > 0))
{
maze[n].active = 1;
printf("Cell (%i, %i) ", n%NXMAZE, n/NXMAZE);
nnext = 0;
for (i=0; i<npaths; i++)
{
nextcell = maze[n].neighb[i];
if (!maze[nextcell].active)
{
next_table[nnext] = i;
nnext++;
}
}
if (nnext == 0)
{
printf("Ended path\n");
// sleep(5);
npaths = 0;
}
else
{
inext = next_table[rand()%nnext];
nextcell = maze[n].neighb[inext];
switch(maze[n].directions[inext]){
case(0):
{
printf("Moving north\n");
maze[n].north = 0;
maze[nextcell].south = 0;
break;
}
case(1):
{
printf("Moving east\n");
maze[n].east = 0;
maze[nextcell].west = 0;
break;
}
case(2):
{
printf("Moving south\n");
maze[n].south = 0;
maze[nextcell].north = 0;
break;
}
case(3):
{
printf("Moving west\n");
maze[n].west = 0;
maze[nextcell].east = 0;
break;
}
}
n = nextcell;
if (maze[n].tested) npaths = 0;
else npaths = maze[n].nneighb;
active_counter++;
}
}
/* update cell status */
for (n=0; n<NXMAZE*NYMAZE; n++) if (maze[n].active)
{
maze[n].active = 0;
maze[n].tested = 1;
}
printf("Ended path\n");
return(active_counter);
}
void init_maze(t_maze maze[NXMAZE*NYMAZE])
/* init a maze */
{
int i;
init_maze_graph(maze);
for (i=0; i<RAND_SHIFT; i++) rand();
for (i=0; i<NXMAZE*NYMAZE; i++) if (!maze[i].tested) find_maze_path(maze, i);
}

View File

@ -78,6 +78,7 @@ int writetiff(char *filename, char *description, int x, int y, int width, int he
TIFF *file; TIFF *file;
GLubyte *image, *p; GLubyte *image, *p;
int i; int i;
static int mem_counter = 0;
file = TIFFOpen(filename, "w"); file = TIFFOpen(filename, "w");
if (file == NULL) if (file == NULL)
@ -121,6 +122,15 @@ int writetiff(char *filename, char *description, int x, int y, int width, int he
p += width * sizeof(GLubyte) * 3; p += width * sizeof(GLubyte) * 3;
} }
TIFFClose(file); TIFFClose(file);
/* to avoid RAM overflow */
mem_counter++;
if (mem_counter >= 12)
{
free(image);
mem_counter = 0;
}
return 0; return 0;
} }
@ -198,6 +208,20 @@ void save_frame()
} }
void save_frame_counter(int counter)
{
char *name="part.", 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, "Billiard in an ellipse", 0, 0,
WINWIDTH, WINHEIGHT, COMPRESSION_LZW);
}
void write_text_fixedwidth( double x, double y, char *st) void write_text_fixedwidth( double x, double y, char *st)
{ {
@ -5353,7 +5377,8 @@ void print_colors(int color[NPARTMAX]) /* for debugging purposes */
case D_POLYLINE: case D_POLYLINE:
{ {
/* not easy to implement for non-convex polygons */ /* not easy to implement for non-convex polygons */
return(1); if (POLYLINE_PATTERN == P_MAZE) return ((vabs(x) < 1.1*XMAX)&&(vabs(y) < 1.1*YMAX));
else return(1);
break; break;
} }
default: default:
@ -5722,7 +5747,9 @@ void init_polyline(t_segment polyline[NMAXPOLY], t_circle circles[NMAXCIRCLES])
{ {
int i, j, k, l, n, z, ii, jj, terni[SDEPTH], ternj[SDEPTH], quater[SDEPTH], cond; int i, j, k, l, n, z, ii, jj, terni[SDEPTH], ternj[SDEPTH], quater[SDEPTH], cond;
short int vkoch[NMAXCIRCLES], turnright; short int vkoch[NMAXCIRCLES], turnright;
double ratio, omega, angle, sw, length, dist, x, y, ta, tb, a, b; double ratio, omega, angle, sw, length, dist, x, y, ta, tb, a, b,
x1, y1, x2, y2, dx, dy, padding = 0.02, width = 0.01;
t_maze* maze;
switch (POLYLINE_PATTERN) { switch (POLYLINE_PATTERN) {
case (P_RECTANGLE): case (P_RECTANGLE):
@ -6148,6 +6175,96 @@ void init_polyline(t_segment polyline[NMAXPOLY], t_circle circles[NMAXCIRCLES])
} }
break; break;
} }
case (P_MAZE):
{
maze = (t_maze *)malloc(NXMAZE*NYMAZE*sizeof(t_maze));
init_maze(maze);
/* build walls of maze */
dx = (YMAX - YMIN - 2.0*padding)/(double)(NXMAZE);
dy = (YMAX - YMIN - 2.0*padding)/(double)(NYMAZE);
nsides = 0;
ncircles = 0;
for (i=0; i<NXMAZE; i++)
for (j=0; j<NYMAZE; j++)
{
n = nmaze(i, j);
x1 = YMIN + padding + (double)i*dx + MAZE_XSHIFT;
y1 = YMIN + padding + (double)j*dy;
if (((i>0)||(j!=NYMAZE/2))&&(maze[n].west))
{
polyline[nsides].x1 = x1;
polyline[nsides].y1 = y1;
polyline[nsides].x2 = x1;
polyline[nsides].y2 = y1 + dy;
polyline[nsides].angle = PID;
// add_rectangle_to_segments(x1, y1, x1 - width, y1 + dy, segment, 0);
}
nsides++;
if (maze[n].south)
{
polyline[nsides].x1 = x1;
polyline[nsides].y1 = y1;
polyline[nsides].x2 = x1 + dx;
polyline[nsides].y2 = y1;
polyline[nsides].angle = 0.0;
// add_rectangle_to_segments(x1, y1, x1 + dx, y1 - width, segment, 0);
}
nsides++;
}
/* top side of maze */
polyline[nsides].x1 = YMIN + padding + MAZE_XSHIFT;
polyline[nsides].y1 = YMAX - padding;
polyline[nsides].x2 = YMAX - padding + MAZE_XSHIFT;
polyline[nsides].y2 = YMAX - padding;
polyline[nsides].angle = 0.0;
nsides++;
/* right side of maze */
y1 = YMIN + padding + dy*((double)NYMAZE/2);
x1 = YMAX - padding + MAZE_XSHIFT;
polyline[nsides].x1 = x1;
polyline[nsides].y1 = YMIN - 1.0;
polyline[nsides].x2 = x1;
polyline[nsides].y2 = y1 - dy;
polyline[nsides].angle = PID;
nsides++;
polyline[nsides].x1 = x1;
polyline[nsides].y1 = y1;
polyline[nsides].x2 = x1;
polyline[nsides].y2 = YMAX + 1.0;
polyline[nsides].angle = PID;
nsides++;
/* left side of maze */
x1 = YMIN + padding + MAZE_XSHIFT;
polyline[nsides].x1 = x1;
polyline[nsides].y1 = YMIN - 1.0;
polyline[nsides].x2 = x1;
polyline[nsides].y2 = YMIN + padding;
polyline[nsides].angle = PID;
nsides++;
polyline[nsides].x1 = x1;
polyline[nsides].y1 = YMAX - padding;
polyline[nsides].x2 = x1;
polyline[nsides].y2 = YMAX + 1.0;
polyline[nsides].angle = PID;
nsides++;
free(maze);
break;
}
} }
} }
@ -6249,3 +6366,63 @@ void init_polyline_depth(t_segment polyline[NMAXPOLY], t_circle circles[NMAXCIRC
} }
int test_initial_condition(double *configs[NPARTMAX], int active[NPARTMAX], int color[NPARTMAX])
/* apply a test to initial conditions - so far, whether particle has left maze on the right */
{
int i, j, time, nactive = 0, counter = 0, tmax[NPARTMAX], tmaxmax = 0, tmaxmin = 1000;
double conf[8], newconf[8], cosphi, x2, pcolor;
for (i=0; i<nparticles; i++)
{
for (j=0; j<8; j++) conf[j] = configs[i][j];
for (j=0; j<8; j++) newconf[j] = configs[i][j];
time = 0;
while ((time < 100000)&&(newconf[4] < 1000.0))
{
for (j=0; j<8; j++) conf[j] = newconf[j];
vbilliard(newconf);
time++;
}
tmax[i] = time;
printf("tmax = %i\n", time);
cosphi = (conf[6] - conf[4])/conf[3];
x2 = conf[4] + 10.0*cosphi;
if (x2 > 0.0)
{
active[i] = 1;
if (time > tmaxmax) tmaxmax = time;
else if (time < tmaxmin) tmaxmin = time;
}
else active[i] = 0;
nactive += active[i];
}
printf("%i particles, %i active particles\n", nparticles, nactive);
printf("tmin = %i, tmax = %i\n", tmaxmin, tmaxmax);
// sleep(5);
/* reorder particles */
for (i=0; i<nparticles; i++)
{
if (active[i])
{
for (j=0; j<8; j++) configs[counter][j] = configs[i][j];
pcolor = sqrt((double)tmax[i] - (double)tmaxmin - 1.0)/sqrt((double)tmaxmax - (double)tmaxmin);
color[counter] = (int)((double)NCOLORS*pcolor);
active[counter] = 1;
counter++;
}
}
for (i=0; i<counter; i++) active[i] = 1;
for (i=counter; i<nparticles; i++) active[i] = 0;
return(counter);
}

File diff suppressed because it is too large Load Diff

350
sub_rde.c
View File

@ -129,6 +129,38 @@ void init_coherent_state(double x, double y, double px, double py, double scalex
} }
} }
void add_coherent_state(double x, double y, double px, double py, double scalex, double *phi[NFIELDS], short int xy_in[NX*NY])
/* add to the field a coherent state of position (x,y) and momentum (px, py) */
/* phi[0] is real part, phi[1] is imaginary part */
{
int i, j;
double xy[2], dist2, module, phase, scale2;
scale2 = scalex*scalex;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
xy_in[i*NY+j] = xy_in_billiard(xy[0],xy[1]);
if (xy_in[i*NY+j])
{
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
module = exp(-dist2/scale2);
if (module < 1.0e-15) module = 1.0e-15;
phase = (px*(xy[0]-x) + py*(xy[1]-y))/scalex;
phi[0][i*NY+j] += module*cos(phase);
phi[1][i*NY+j] += module*sin(phase);
}
else
{
phi[0][i*NY+j] = 0.0;
phi[1][i*NY+j] = 0.0;
}
}
}
void init_fermion_state(double x, double y, double px, double py, double scalex, double *phi[NFIELDS], short int xy_in[NX*NY]) void init_fermion_state(double x, double y, double px, double py, double scalex, double *phi[NFIELDS], short int xy_in[NX*NY])
/* initialise field with antisymmetric coherent state of position (x,y) and momentum (px, py) */ /* initialise field with antisymmetric coherent state of position (x,y) and momentum (px, py) */
/* phi[0] is real part, phi[1] is imaginary part */ /* phi[0] is real part, phi[1] is imaginary part */
@ -281,6 +313,118 @@ void antisymmetrize_wave_function(double *phi[NFIELDS], short int xy_in[NX*NY])
} }
} }
void init_vortex_state(double x, double y, double scale, double *phi[NFIELDS], short int xy_in[NX*NY])
/* initialise field with vortex at position (x,y) with variance scale */
/* phi[0] is stream function, phi[1] is vorticity */
{
int i, j;
double xy[2], dist2, module, phase, scale2;
// scale2 = scale*scale;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
xy_in[i*NY+j] = xy_in_billiard(xy[0],xy[1]);
if (xy_in[i*NY+j])
{
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
module = exp(-dist2/scale);
phi[1][i*NY+j] = module;
phi[0][i*NY+j] = -module; /* approximate, stream function should solve Poisson equation */
}
else
{
phi[0][i*NY+j] = 0.0;
phi[1][i*NY+j] = 0.0;
}
}
}
void add_vortex_state(double x, double y, double scale, double *phi[NFIELDS], short int xy_in[NX*NY])
/* add vortex at position (x,y) with variance scale to field */
/* phi[0] is stream function, phi[1] is vorticity */
{
int i, j;
double xy[2], dist2, module, phase, scale2;
// scale2 = scale*scale;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
xy_in[i*NY+j] = xy_in_billiard(xy[0],xy[1]);
if (xy_in[i*NY+j])
{
dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y)*(xy[1]-y);
module = exp(-dist2/scale);
phi[1][i*NY+j] += module;
phi[0][i*NY+j] -= module; /* approximate, stream function should solve Poisson equation */
}
else
{
phi[0][i*NY+j] = 0.0;
phi[1][i*NY+j] = 0.0;
}
}
}
void init_shear_flow(double amp, double delta, double rho, int nx, int ny, double *phi[NFIELDS], short int xy_in[NX*NY])
/* initialise field with a shear flow */
/* phi[0] is stream function, phi[1] is vorticity */
/* amp is global amplitude */
/* delta is the amplitude of the periodic perturbation in the x direction */
/* rho controls the size of the transition zone in the y direction */
/* nx is number of oscillations in x direction */
/* ny is number of layers in y direction */
{
int i, j;
double xy[2], y1, a, b, f, cplus, cminus;
a = (double)nx*DPI/(XMAX - XMIN);
b = 0.5;
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
ij_to_xy(i, j, xy);
xy_in[i*NY+j] = xy_in_billiard(xy[0],xy[1]);
y1 = xy[1]*(double)ny/YMAX;
while (y1 > 1.0) y1 -= 2.0;
while (y1 < -1.0) y1 += 2.0;
if (xy_in[i*NY+j])
{
f = delta*cos(a*xy[0]);
cplus = cosh((y1 + b)/rho);
cminus = cosh((y1 - b)/rho);
if (y1 > 0.0)
{
phi[1][i*NY+j] = amp*(f + 1.0/(rho*cminus*cminus));
phi[0][i*NY+j] = amp*(f/(a*a) + rho/(cminus*cminus));
}
else
{
phi[1][i*NY+j] = amp*(f - 1.0/(rho*cplus*cplus));
phi[0][i*NY+j] = amp*(f/(a*a) - rho/(cplus*cplus));
}
}
else
{
phi[0][i*NY+j] = 0.0;
phi[1][i*NY+j] = 0.0;
}
}
}
/*********************/ /*********************/
/* animation part */ /* animation part */
/*********************/ /*********************/
@ -417,7 +561,7 @@ void compute_gradient_xy(double phi[NX*NY], double gradient[2*NX*NY])
/* compute the gradient of the field */ /* compute the gradient of the field */
{ {
int i, j, iplus, iminus, jplus, jminus, padding = 0; int i, j, iplus, iminus, jplus, jminus, padding = 0;
double deltaphi; double deltaphi, maxgradient = 1.0e10;
double dx = (XMAX-XMIN)/((double)NX); double dx = (XMAX-XMIN)/((double)NX);
dx = (XMAX-XMIN)/((double)NX); dx = (XMAX-XMIN)/((double)NX);
@ -426,12 +570,17 @@ void compute_gradient_xy(double phi[NX*NY], double gradient[2*NX*NY])
for (i=1; i<NX-1; i++) for (i=1; i<NX-1; i++)
for (j=1; j<NY-1; j++) for (j=1; j<NY-1; j++)
{ {
iplus = i+1;
iminus = i-1;
jplus = j+1;
jminus = j-1;
deltaphi = phi[iplus*NY+j] - phi[iminus*NY+j]; deltaphi = phi[iplus*NY+j] - phi[iminus*NY+j];
if (vabs(deltaphi) < 1.0e9) gradient[i*NY+j] = (deltaphi)/dx; if (vabs(deltaphi) < maxgradient) gradient[i*NY+j] = (deltaphi)/dx;
else gradient[i*NY+j] = 0.0; else gradient[i*NY+j] = 0.0;
deltaphi = phi[i*NY+jplus] - phi[i*NY+jminus]; deltaphi = phi[i*NY+jplus] - phi[i*NY+jminus];
if (vabs(deltaphi) < 1.0e9) gradient[NX*NY+i*NY+j] = (deltaphi)/dx; if (vabs(deltaphi) < maxgradient) gradient[NX*NY+i*NY+j] = (deltaphi)/dx;
else gradient[NX*NY+i*NY+j] = 0.0; else gradient[NX*NY+i*NY+j] = 0.0;
} }
@ -455,6 +604,93 @@ void compute_gradient_xy(double phi[NX*NY], double gradient[2*NX*NY])
} }
} }
void compute_gradient_euler(double phi[NX*NY], double gradient[2*NX*NY])
/* compute the gradient of the field */
{
int i, j, iplus, iminus, jplus, jminus, padding = 0;
double deltaphi, maxgradient = 1.0e10;
double dx = (XMAX-XMIN)/((double)NX);
dx = (XMAX-XMIN)/((double)NX);
// #pragma omp parallel for private(i)
// for (i=0; i<2*NX*NY; i++) gradient[i] = 0.0;
#pragma omp parallel for private(i,j,iplus,iminus,jplus,jminus)
for (i=1; i<NX-1; i++)
for (j=1; j<NY-1; j++)
{
iplus = i+1;
iminus = i-1;
jplus = j+1;
jminus = j-1;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
}
/* boundaries */
for (i=1; i<NX-1; i++)
{
iplus = i+1;
iminus = i-1;
j = 0;
jplus = 1;
jminus = NY-1;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
j = NY-1;
jplus = 0;
jminus = NY-2;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
}
for (j=1; j<NY-1; j++)
{
jplus = j+1;
jminus = j-1;
i = 0;
iplus = 1;
iminus = NX-1;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
i = NX-1;
iplus = 0;
iminus = NX-2;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
}
/* corners */
i = 0; iplus = 1; iminus = NX-1;
j = 0; jplus = 1; jminus = NY-1;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
j = NY-1; jplus = 0; jminus = NY-2;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
i = NX-1; iplus = 0; iminus = NX-2;
j = 0; jplus = 1; jminus = NY-1;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
j = NY-1; jplus = 0; jminus = NY-2;
gradient[i*NY+j] = 0.5*(phi[iplus*NY+j] - phi[iminus*NY+j]);
gradient[NX*NY+i*NY+j] = 0.5*(phi[i*NY+jplus] - phi[i*NY+jminus]);
}
void compute_gradient_rde(double phi[NX*NY], t_rde rde[NX*NY]) void compute_gradient_rde(double phi[NX*NY], t_rde rde[NX*NY])
/* compute the gradient of the field */ /* compute the gradient of the field */
@ -597,6 +833,22 @@ void compute_field_argument(double *phi[NFIELDS], t_rde rde[NX*NY])
} }
} }
void compute_field_log(double *phi[NFIELDS], t_rde rde[NX*NY])
/* compute the norm squared of first two fields */
{
int i, j;
double value;
#pragma omp parallel for private(i,j,value)
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
value = vabs(phi[1][i*NY+j]);
if (value < 1.0e-5) value = 1.0e-5;
rde[i*NY+j].log_vorticity = LOG_SHIFT + LOG_SCALE*log(value);
}
}
void compute_probabilities(t_rde rde[NX*NY], short int xy_in[NX*NY], double probas[2]) void compute_probabilities(t_rde rde[NX*NY], short int xy_in[NX*NY], double probas[2])
/* compute probabilities for Ehrenfest urns */ /* compute probabilities for Ehrenfest urns */
{ {
@ -654,7 +906,7 @@ void compute_laplacian_rde(double phi_in[NX*NY], double phi_out[NX*NY], short in
{ {
int i, j, iplus, iminus, jplus, jminus; int i, j, iplus, iminus, jplus, jminus;
#pragma omp parallel for private(i,j,iplus,iminus,jplus,jminus) #pragma omp parallel for private(i,j)
for (i=1; i<NX-1; i++){ for (i=1; i<NX-1; i++){
for (j=1; j<NY-1; j++){ for (j=1; j<NY-1; j++){
if (xy_in[i*NY+j]){ if (xy_in[i*NY+j]){
@ -686,10 +938,27 @@ void compute_laplacian_rde(double phi_in[NX*NY], double phi_out[NX*NY], short in
phi_out[i*NY] = phi_in[iminus*NY] + phi_in[iplus*NY] + phi_in[i*NY+1] + phi_in[i*NY+NY-1] - 4.0*phi_in[i*NY]; phi_out[i*NY] = phi_in[iminus*NY] + phi_in[iplus*NY] + phi_in[i*NY+1] + phi_in[i*NY+NY-1] - 4.0*phi_in[i*NY];
phi_out[i*NY+NY-1] = phi_in[iminus*NY+NY-1] + phi_in[iplus*NY+NY-1] + phi_in[i*NY] + phi_in[i*NY+NY-2] - 4.0*phi_in[i*NY+NY-1]; phi_out[i*NY+NY-1] = phi_in[iminus*NY+NY-1] + phi_in[iplus*NY+NY-1] + phi_in[i*NY] + phi_in[i*NY+NY-2] - 4.0*phi_in[i*NY+NY-1];
} }
break;
} }
case (BC_DIRICHLET): case (BC_DIRICHLET):
{ {
/* TO DO */ /* left and right side */
for (j = 1; j < NY-1; j++)
{
phi_out[j] = phi_in[j-1] + phi_in[j+1] + phi_in[NY+j] - 3.0*phi_in[j];
phi_out[(NX-1)*NY+j] = phi_in[(NX-1)*NY+j-1] + phi_in[(NX-1)*NY+j+1] + phi_in[(NX-2)*NY+j] - 3.0*phi_in[(NX-1)*NY+j];
}
/* top and bottom side */
for (i = 1; i < NX-1; i++)
{
phi_out[i*NY] = phi_in[(i-1)*NY] + phi_in[(i+1)*NY] + phi_in[i*NY+1] - 3.0*phi_in[i*NY];
phi_out[i*NY+NY-1] = phi_in[(i-1)*NY+NY-1] + phi_in[(i+1)*NY+NY-1] + phi_in[i*NY+NY-2] - 3.0*phi_in[i*NY+NY-1];
}
/* corners */
phi_out[0] = phi_in[1] + phi_in[NY] - 2.0*phi_in[0];
phi_out[NY-1] = phi_in[NY-2] + phi_in[NY+NY-1] - 2.0*phi_in[NY-1];
phi_out[(NX-1)*NY] = phi_in[(NX-2)*NY] + phi_in[(NX-1)*NY+1] - 2.0*phi_in[(NX-1)*NY];
phi_out[(NX-1)*NY+NY-1] = phi_in[(NX-2)*NY+NY-1] + phi_in[(NX-1)*NY-2] - 2.0*phi_in[(NX-1)*NY+NY-1];
break; break;
} }
} }
@ -720,7 +989,7 @@ void compute_light_angle_rde(short int xy_in[NX*NY], t_rde rde[NX*NY], double po
grady = (*rde[i*NY+j+1].p_zfield[movie] - *rde[i*NY+j-1].p_zfield[movie])/dy; grady = (*rde[i*NY+j+1].p_zfield[movie] - *rde[i*NY+j-1].p_zfield[movie])/dy;
/* case where the potential is added to the z coordinate */ /* case where the potential is added to the z coordinate */
if ((ADD_POTENTIAL)&&(ADD_POTENTIAL_TO_Z)) if (((ADD_POTENTIAL)||(ADD_MAGNETIC_FIELD))&&(ADD_POTENTIAL_TO_Z))
{ {
gradx += ADD_POT_CONSTANT*(potential[(i+1)*NY+j] - potential[(i-1)*NY+j])/dx; gradx += ADD_POT_CONSTANT*(potential[(i+1)*NY+j] - potential[(i-1)*NY+j])/dx;
grady += ADD_POT_CONSTANT*(potential[i*NY+j+1] - potential[i*NY+j-1])/dx; grady += ADD_POT_CONSTANT*(potential[i*NY+j+1] - potential[i*NY+j-1])/dx;
@ -884,13 +1153,32 @@ void compute_field_color_rde(double value, int cplot, int palette, double rgb[3]
color_scheme_palette(COLOR_SCHEME, palette, VSCALE_AMPLITUDE*value, 1.0, 0, rgb); color_scheme_palette(COLOR_SCHEME, palette, VSCALE_AMPLITUDE*value, 1.0, 0, rgb);
break; break;
} }
case (Z_EULER_VORTICITY):
{
if (value < 0.0) value = -value;
color_scheme_asym_palette(COLOR_SCHEME, palette, VSCALE_AMPLITUDE*value, 1.0, 0, rgb);
break;
}
case (Z_EULER_LOG_VORTICITY):
{
// if (value < 0.0) value = -value;
// if (value < 1.0e-10) value = 1.0e-10;
// color_scheme_palette(COLOR_SCHEME, palette, LOG_SCALE*value + LOG_SHIFT, 1.0, 0, rgb);
color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 0, rgb);
break;
}
case (Z_EULER_VORTICITY_ASYM):
{
color_scheme_palette(COLOR_SCHEME, palette, VSCALE_AMPLITUDE*value, 1.0, 0, rgb);
break;
}
} }
} }
double adjust_field(double z, double pot) double adjust_field(double z, double pot)
/* add potential in case of option ADD_POTENTIAL_TO_Z */ /* add potential in case of option ADD_POTENTIAL_TO_Z */
{ {
if ((ADD_POTENTIAL)&&(ADD_POTENTIAL_TO_Z)) return (z + ADD_POT_CONSTANT*pot); if (((ADD_POTENTIAL)||(ADD_MAGNETIC_FIELD))&&(ADD_POTENTIAL_TO_Z)) return (z + ADD_POT_CONSTANT*pot);
else return(z); else return(z);
} }
@ -909,7 +1197,7 @@ double compute_interpolated_colors_rde(int i, int j, t_rde rde[NX*NY], double po
*z_nw = *rde[i*NY+j+1].p_zfield[movie]; *z_nw = *rde[i*NY+j+1].p_zfield[movie];
*z_ne = *rde[(i+1)*NY+j+1].p_zfield[movie]; *z_ne = *rde[(i+1)*NY+j+1].p_zfield[movie];
if ((ADD_POTENTIAL)&&(ADD_POTENTIAL_TO_Z)) if (((ADD_POTENTIAL)||(ADD_MAGNETIC_FIELD))&&(ADD_POTENTIAL_TO_Z))
{ {
*z_sw += ADD_POT_CONSTANT*potential[i*NY+j]; *z_sw += ADD_POT_CONSTANT*potential[i*NY+j];
*z_se += ADD_POT_CONSTANT*potential[(i+1)*NY+j]; *z_se += ADD_POT_CONSTANT*potential[(i+1)*NY+j];
@ -1038,6 +1326,12 @@ void compute_rde_fields(double *phi[NFIELDS], short int xy_in[NX*NY], int zplot,
} }
break; break;
} }
case (E_EULER_INCOMP):
{
if ((zplot == Z_EULER_LOG_VORTICITY)||(cplot == Z_EULER_LOG_VORTICITY))
compute_field_log(phi, rde);
break;
}
default : break; default : break;
} }
} }
@ -1138,6 +1432,24 @@ void init_zfield_rde(double *phi[NFIELDS], short int xy_in[NX*NY], int zplot, t_
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_zfield[movie] = &phi[0][i*NY+j]; for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_zfield[movie] = &phi[0][i*NY+j];
break; break;
} }
case (Z_EULER_VORTICITY):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_zfield[movie] = &phi[1][i*NY+j];
break;
}
case (Z_EULER_LOG_VORTICITY):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_zfield[movie] = &rde[i*NY+j].log_vorticity;
break;
}
case (Z_EULER_VORTICITY_ASYM):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_zfield[movie] = &phi[1][i*NY+j];
break;
}
} }
} }
@ -1237,6 +1549,24 @@ void init_cfield_rde(double *phi[NFIELDS], short int xy_in[NX*NY], int cplot, t_
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_cfield[movie] = &phi[0][i*NY+j]; for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_cfield[movie] = &phi[0][i*NY+j];
break; break;
} }
case (Z_EULER_VORTICITY):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_cfield[movie] = &phi[1][i*NY+j];
break;
}
case (Z_EULER_LOG_VORTICITY):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_cfield[movie] = &rde[i*NY+j].log_vorticity;
break;
}
case (Z_EULER_VORTICITY_ASYM):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++) for (j=0; j<NY; j++) rde[i*NY+j].p_cfield[movie] = &phi[1][i*NY+j];
break;
}
} }
} }
@ -1371,8 +1701,8 @@ void draw_wave_3d_rde(int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t
if (!ROTATE_VIEW) if (!ROTATE_VIEW)
{ {
for (i=0; i<NX-2; i++) for (i=BORDER_PADDING; i<NX-2-BORDER_PADDING; i++)
for (j=0; j<NY-2; j++) for (j=BORDER_PADDING; j<NY-2-BORDER_PADDING; j++)
draw_wave_3d_ij_rde(i, j, movie, phi, xy_in, rde, potential, zplot, cplot, palette, fade, fade_value); draw_wave_3d_ij_rde(i, j, movie, phi, xy_in, rde, potential, zplot, cplot, palette, fade, fade_value);
} }
else /* draw facets in an order depending on the position of the observer */ else /* draw facets in an order depending on the position of the observer */

View File

@ -105,6 +105,8 @@ int writetiff(char *filename, char *description, int x, int y, int width, int he
} }
p += width * sizeof(GLubyte) * 3; p += width * sizeof(GLubyte) * 3;
} }
/* added 9/9/22 and removed again, since it produces an unwanted "band" on the right */
// free(image); /* prevents RAM consumption*/
TIFFClose(file); TIFFClose(file);
return 0; return 0;
} }
@ -440,6 +442,22 @@ void draw_rectangle(double x1, double y1, double x2, double y2)
glEnd(); glEnd();
} }
void draw_filled_rectangle(double x1, double y1, double x2, double y2)
{
double pos[2];
glBegin(GL_TRIANGLE_FAN);
xy_to_pos(x1, y1, pos);
glVertex2d(pos[0], pos[1]);
xy_to_pos(x2, y1, pos);
glVertex2d(pos[0], pos[1]);
xy_to_pos(x2, y2, pos);
glVertex2d(pos[0], pos[1]);
xy_to_pos(x1, y2, pos);
glVertex2d(pos[0], pos[1]);
glEnd();
}
void draw_rotated_rectangle(double x1, double y1, double x2, double y2) void draw_rotated_rectangle(double x1, double y1, double x2, double y2)
{ {
double pos[2]; double pos[2];
@ -481,6 +499,23 @@ void draw_circle(double x, double y, double r, int nseg)
glEnd(); glEnd();
} }
void draw_circle_arc(double x, double y, double r, double angle1, double dangle, int nseg)
{
int i;
double pos[2], alpha, dalpha;
dalpha = dangle/(double)nseg;
glBegin(GL_LINE_STRIP);
for (i=0; i<=nseg; i++)
{
alpha = angle1 + (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]) void draw_colored_circle(double x, double y, double r, int nseg, double rgb[3])
{ {
int i; int i;
@ -1566,6 +1601,120 @@ int compute_qrd_coordinates(t_vertex polyline[NMAXPOLY])
return(n); return(n);
} }
int compute_maze_coordinates(t_rectangle polyrect[NMAXPOLY], int closed)
/* compute positions of quadratic noise diffuser */
{
t_maze* maze;
int i, j, n, nsides = 0, ropening;
double dx, dy, x1, y1, padding = 0.02, pos[2], width = 0.02;
maze = (t_maze *)malloc(NXMAZE*NYMAZE*sizeof(t_maze));
init_maze(maze);
/* build walls of maze */
dx = (YMAX - YMIN - 2.0*padding)/(double)(NXMAZE);
dy = (YMAX - YMIN - 2.0*padding)/(double)(NYMAZE);
ropening = (NYMAZE+1)/2;
for (i=0; i<NXMAZE; i++)
for (j=0; j<NYMAZE; j++)
{
n = nmaze(i, j);
x1 = YMIN + padding + (double)i*dx + MAZE_XSHIFT;
y1 = YMIN + padding + (double)j*dy;
if (((i>0)||(j!=ropening))&&(maze[n].west))
{
polyrect[nsides].x1 = x1 - width;
polyrect[nsides].y1 = y1 - width;
polyrect[nsides].x2 = x1 + width;
polyrect[nsides].y2 = y1 + width + dy;
}
nsides++;
if (maze[n].south)
{
polyrect[nsides].x1 = x1 - width;
polyrect[nsides].y1 = y1 - width;
polyrect[nsides].x2 = x1 + width + dx;
polyrect[nsides].y2 = y1 + width;
}
nsides++;
}
/* top side of maze */
polyrect[nsides].x1 = YMIN + padding + MAZE_XSHIFT;
polyrect[nsides].y1 = YMAX - padding - width;
polyrect[nsides].x2 = YMAX - padding + MAZE_XSHIFT;
polyrect[nsides].y2 = YMAX - padding + width;
nsides++;
/* right side of maze */
y1 = YMIN + padding + dy*((double)ropening);
x1 = YMAX - padding + MAZE_XSHIFT;
polyrect[nsides].x1 = x1 - width;
polyrect[nsides].y1 = YMIN - 1.0;
polyrect[nsides].x2 = x1 + width;
polyrect[nsides].y2 = y1 - dy;
nsides++;
polyrect[nsides].x1 = x1 - width;
polyrect[nsides].y1 = y1;
polyrect[nsides].x2 = x1 + width;
polyrect[nsides].y2 = YMAX + 1.0;
nsides++;
/* left side of maze */
x1 = YMIN + padding + MAZE_XSHIFT;
polyrect[nsides].x1 = x1 - width;
polyrect[nsides].y1 = YMIN - 1.0;
polyrect[nsides].x2 = x1 + width;
polyrect[nsides].y2 = YMIN + padding;
nsides++;
polyrect[nsides].x1 = x1 - width;
polyrect[nsides].y1 = YMAX - padding;
polyrect[nsides].x2 = x1 + width;
polyrect[nsides].y2 = YMAX + 1.0;
nsides++;
if (closed)
{
polyrect[nsides].x1 = XMIN - 0.5*width;
polyrect[nsides].y1 = YMIN - 0.5*width;
polyrect[nsides].x2 = XMIN + 0.5*width;
polyrect[nsides].y2 = YMAX + 0.5*width;
nsides++;
polyrect[nsides].x1 = XMIN - 0.5*width;
polyrect[nsides].y1 = YMIN - 0.5*width;
polyrect[nsides].x2 = x1 + 0.5*width;
polyrect[nsides].y2 = YMIN + 0.5*width;
nsides++;
polyrect[nsides].x1 = XMIN - 0.5*width;
polyrect[nsides].y1 = YMAX - 0.5*width;
polyrect[nsides].x2 = x1 + 0.5*width;
polyrect[nsides].y2 = YMAX + 0.5*width;
nsides++;
}
for (i=0; i<nsides; i++)
{
xy_to_pos(polyrect[i].x1, polyrect[i].y1, pos);
polyrect[i].posi1 = pos[0];
polyrect[i].posj1 = pos[1];
xy_to_pos(polyrect[i].x2, polyrect[i].y2, pos);
polyrect[i].posi2 = pos[0];
polyrect[i].posj2 = pos[1];
}
free(maze);
return(nsides);
}
int init_polyline(int depth, t_vertex polyline[NMAXPOLY]) int init_polyline(int depth, t_vertex polyline[NMAXPOLY])
/* initialise variable polyline, for certain polygonal domain shapes */ /* initialise variable polyline, for certain polygonal domain shapes */
{ {
@ -1629,6 +1778,27 @@ int init_polyline(int depth, t_vertex polyline[NMAXPOLY])
} }
} }
int init_polyrect(t_rectangle polyrect[NMAXPOLY])
/* initialise variable polyrect, for certain polygonal domain shapes */
{
switch (B_DOMAIN) {
case (D_MAZE):
{
return(compute_maze_coordinates(polyrect, 0));
}
case (D_MAZE_CLOSED):
{
return(compute_maze_coordinates(polyrect, 1));
}
default:
{
if ((ADD_POTENTIAL)&&(POTENTIAL == POT_MAZE)) return(compute_maze_coordinates(polyrect, 1));
return(0);
}
}
}
void isospectral_initial_point(double x, double y, double left[2], double right[2]) void isospectral_initial_point(double x, double y, double left[2], double right[2])
/* compute initial coordinates in isospectral billiards */ /* compute initial coordinates in isospectral billiards */
{ {
@ -1676,10 +1846,76 @@ int xy_in_triangle_tvertex(double x, double y, t_vertex z1, t_vertex z2, t_verte
} }
int xy_in_polyrect(double x, double y, t_rectangle rectangle)
/* returns 1 if (x,y) is in rectangle */
{
double x1, y1, x2, y2;
if (rectangle.x1 < rectangle.x2)
{
x1 = rectangle.x1;
x2 = rectangle.x2;
}
else
{
x1 = rectangle.x2;
x2 = rectangle.x1;
}
if (rectangle.y1 < rectangle.y2)
{
y1 = rectangle.y1;
y2 = rectangle.y2;
}
else
{
y1 = rectangle.y2;
y2 = rectangle.y1;
}
if (x < x1) return(0);
if (x > x2) return(0);
if (y < y1) return(0);
if (y > y2) return(0);
return(1);
}
int ij_in_polyrect(double i, double j, t_rectangle rectangle)
/* returns 1 if (x,y) is in rectangle */
{
int i1, i2, j1, j2;
if (rectangle.posi1 < rectangle.posi2)
{
i1 = rectangle.posi1;
i2 = rectangle.posi2;
}
else
{
i1 = rectangle.posi2;
i2 = rectangle.posi1;
}
if (rectangle.posj1 < rectangle.posj2)
{
j1 = rectangle.posj1;
j2 = rectangle.posj2;
}
else
{
j1 = rectangle.posj2;
j2 = rectangle.posj1;
}
if (i < i1) return(0);
if (i > i2) return(0);
if (j < j1) return(0);
if (j > j2) return(0);
return(1);
}
int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_circle *circles) int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_circle *circles)
/* returns 1 if (x,y) represents a point in the billiard */ /* returns 1 if (x,y) represents a point in the billiard */
{ {
double l2, r2, r2mu, omega, b, c, angle, z, x1, y1, x2, y2, u, v, u1, v1, dx, dy, width, alpha, s, a; double l2, r2, r2mu, omega, b, c, angle, z, x1, y1, x2, y2, u, v, u1, v1, dx, dy, width, alpha, s, a, r, height;
int i, j, k, k1, k2, condition = 0, m; int i, j, k, k1, k2, condition = 0, m;
static int first = 1, nsides; static int first = 1, nsides;
@ -2198,6 +2434,57 @@ int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_
else if ((x > 0.0)&&(y > 0.0)) return(0); else if ((x > 0.0)&&(y > 0.0)) return(0);
else return(1); else return(1);
} }
case (D_WAVEGUIDE):
{
x1 = XMIN + MU;
x2 = XMAX - 2.0*MU - 1.5*LAMBDA;
y1 = 0.5*LAMBDA;
y2 = 1.5*LAMBDA;
if (x < x1) return(0);
if (x > x2 + 1.5*LAMBDA) return(0);
if (vabs(y) > y2) return(0);
if (x < x2) return(vabs(y) >= y1);
r = module2(x-x2, y);
if (r < 0.5*LAMBDA) return(0);
if (r > 1.5*LAMBDA) return(0);
return(1);
}
case (D_WAVEGUIDE_W):
{
x1 = vabs(x);
width = LAMBDA - 2.0*MU;
height = 0.5*MU;
if (x1 > 2.0*LAMBDA - MU) return(0);
if (vabs(y) > MU + width + height) return(0);
if (y >= height)
{
r = module2(x1, y-height);
if ((r > MU)&&(r < MU + width)) return(1);
if (x1 > LAMBDA + MU) return(1);
return(0);
}
if (y <= -height)
{
r = module2(x1-LAMBDA, y+height);
if ((r > MU)&&(r < MU + width)) return(1);
return(0);
}
if (x1 > LAMBDA + MU) return(1);
if ((x1 > MU)&&(x1 < MU + width)) return(1);
return(0);
}
case (D_MAZE):
{
for (i=0; i<npolyrect; i++)
if ((x > polyrect[i].x1)&&(x < polyrect[i].x2)&&(y > polyrect[i].y1)&&(y < polyrect[i].y2)) return(0);
return(1);
}
case (D_MAZE_CLOSED):
{
for (i=0; i<npolyrect; i++)
if ((x > polyrect[i].x1)&&(x < polyrect[i].x2)&&(y > polyrect[i].y1)&&(y < polyrect[i].y2)) return(0);
return(1);
}
case (D_MENGER): case (D_MENGER):
{ {
x1 = 0.5*(x+1.0); x1 = 0.5*(x+1.0);
@ -2390,7 +2677,7 @@ void tvertex_lineto(t_vertex z)
void draw_billiard(int fade, double fade_value) /* draws the billiard boundary */ void draw_billiard(int fade, double fade_value) /* draws the billiard boundary */
{ {
double x0, x, y, x1, y1, dx, dy, phi, r = 0.01, pos[2], pos1[2], alpha, dphi, omega, z, l, width, a, b, c, ymax; double x0, x, y, x1, y1, x2, y2, dx, dy, phi, r = 0.01, pos[2], pos1[2], alpha, dphi, omega, z, l, width, a, b, c, ymax, height;
int i, j, k, k1, k2, mr2; int i, j, k, k1, k2, mr2;
static int first = 1, nsides; static int first = 1, nsides;
@ -3209,6 +3496,76 @@ void draw_billiard(int fade, double fade_value) /* draws the billiard bound
draw_line(-LAMBDA + 0.5*MU, YMIN, LAMBDA + 0.5*MU, YMAX); draw_line(-LAMBDA + 0.5*MU, YMIN, LAMBDA + 0.5*MU, YMAX);
break; break;
} }
case (D_WAVEGUIDE):
{
x1 = XMIN + MU;
x2 = XMAX - 2.0*MU - 1.5*LAMBDA;
y1 = 0.5*LAMBDA;
y2 = 1.5*LAMBDA;
glLineWidth(BOUNDARY_WIDTH);
draw_line(x1, y1, x2, y1);
draw_line(x1, y1, x1, y2);
draw_line(x1, y2, x2, y2);
draw_line(x1, -y1, x2, -y1);
draw_line(x1, -y1, x1, -y2);
draw_line(x1, -y2, x2, -y2);
dphi = PI/(double)NSEG;
glBegin(GL_LINE_STRIP);
for (i=0; i<NSEG; i++)
{
phi = -PID + dphi*(double)i;
x = x2 + y2*cos(phi);
y = y2*sin(phi);
xy_to_pos(x, y, pos);
glVertex2d(pos[0], pos[1]);
}
glEnd();
glBegin(GL_LINE_STRIP);
for (i=0; i<NSEG; i++)
{
phi = -PID + dphi*(double)i;
x = x2 + y1*cos(phi);
y = y1*sin(phi);
xy_to_pos(x, y, pos);
glVertex2d(pos[0], pos[1]);
}
glEnd();
break;
}
case (D_WAVEGUIDE_W):
{
width = LAMBDA - 2.0*MU;
height = 0.5*MU;
draw_circle_arc(0.0, height, MU, 0.0, PI, NSEG);
draw_circle_arc(0.0, height, MU + width, 0.0, PI, NSEG);
draw_circle_arc(LAMBDA, -height, MU, PI, PI, NSEG);
draw_circle_arc(LAMBDA, -height, MU + width, PI, PI, NSEG);
draw_circle_arc(-LAMBDA, -height, MU, PI, PI, NSEG);
draw_circle_arc(-LAMBDA, -height, MU + width, PI, PI, NSEG);
draw_line(-2.0*LAMBDA + MU, - height, -2.0*LAMBDA + MU, height + MU + width);
draw_line(-2.0*LAMBDA + MU, height + MU + width, -2.0*LAMBDA + MU + width, height + MU + width);
draw_line(-2.0*LAMBDA + MU + width, height + MU + width, -2.0*LAMBDA + MU + width, -height);
draw_line(-MU-width, -height, -MU-width, height);
draw_line(-MU, -height, -MU, height);
draw_line(2.0*LAMBDA - MU, - height, 2.0*LAMBDA - MU, height + MU + width);
draw_line(2.0*LAMBDA - MU, height + MU + width, 2.0*LAMBDA - MU - width, height + MU + width);
draw_line(2.0*LAMBDA - MU - width, height + MU + width, 2.0*LAMBDA - MU - width, -height);
draw_line(MU+width, -height, MU+width, height);
draw_line(MU, -height, MU, height);
break;
}
case (D_CIRCLE_SEGMENT): case (D_CIRCLE_SEGMENT):
{ {
glLineWidth(BOUNDARY_WIDTH); glLineWidth(BOUNDARY_WIDTH);
@ -3256,6 +3613,24 @@ void draw_billiard(int fade, double fade_value) /* draws the billiard bound
if (polygons[i].active) draw_tpolygon(polygons[i]); if (polygons[i].active) draw_tpolygon(polygons[i]);
break; break;
} }
case (D_MAZE):
{
glLineWidth(BOUNDARY_WIDTH);
if (fade) glColor3f(0.15*fade_value, 0.15*fade_value, 0.15*fade_value);
else glColor3f(0.15, 0.15, 0.15);
for (i=0; i<npolyrect; i++)
draw_filled_rectangle(polyrect[i].x1, polyrect[i].y1, polyrect[i].x2, polyrect[i].y2);
break;
}
case (D_MAZE_CLOSED):
{
glLineWidth(BOUNDARY_WIDTH);
if (fade) glColor3f(0.15*fade_value, 0.15*fade_value, 0.15*fade_value);
else glColor3f(0.15, 0.15, 0.15);
for (i=0; i<npolyrect; i++)
draw_filled_rectangle(polyrect[i].x1, polyrect[i].y1, polyrect[i].x2, polyrect[i].y2);
break;
}
case (D_MENGER): case (D_MENGER):
{ {
glLineWidth(3); glLineWidth(3);
@ -3787,6 +4162,24 @@ void draw_color_scheme_palette_fade(double x1, double y1, double x2, double y2,
amp_to_rgb(0.5*(1.0 + amp), rgb); amp_to_rgb(0.5*(1.0 + amp), rgb);
break; break;
} }
case (50): /* to fix: put #define in correct file */
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
case (51):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
case (52): /* to fix: put #define in correct file */
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
} }
if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value; if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value;
glColor3f(rgb[0], rgb[1], rgb[2]); glColor3f(rgb[0], rgb[1], rgb[2]);

View File

@ -1631,8 +1631,8 @@ void draw_wave_3d(int movie, double phi[NX*NY], double psi[NX*NY], short int xy_
if (!ROTATE_VIEW) if (!ROTATE_VIEW)
{ {
for (i=1; i<NX-2; i++) for (i=0; i<NX-2; i++)
for (j=1; j<NY-2; j++) for (j=0; j<NY-2; j++)
draw_wave_3d_ij(i, j, movie, phi, psi, xy_in, wave, zplot, cplot, palette, fade, fade_value); draw_wave_3d_ij(i, j, movie, phi, psi, xy_in, wave, zplot, cplot, palette, fade, fade_value);
} }
else /* draw facets in an order depending on the position of the observer */ else /* draw facets in an order depending on the position of the observer */
@ -1770,6 +1770,24 @@ void draw_color_scheme_palette_3d(double x1, double y1, double x2, double y2, in
color_scheme_palette(C_ONEDIM_LINEAR, palette, value, 1.0, 1, rgb); color_scheme_palette(C_ONEDIM_LINEAR, palette, value, 1.0, 1, rgb);
break; break;
} }
case (Z_EULER_VORTICITY):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
case (Z_EULER_LOG_VORTICITY):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
case (Z_EULER_VORTICITY_ASYM):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
} }
if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value; if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value;
glColor3f(rgb[0], rgb[1], rgb[2]); glColor3f(rgb[0], rgb[1], rgb[2]);

View File

@ -1194,8 +1194,10 @@ void draw_wave_3d(double phi[NX*NY], double psi[NX*NY], short int xy_in[NX*NY],
// if ((plot == P_3D_ANGLE)||(plot == P_3D_AMP_ANGLE)) compute_light_angle(phi, xy_in, cos_angle); // if ((plot == P_3D_ANGLE)||(plot == P_3D_AMP_ANGLE)) compute_light_angle(phi, xy_in, cos_angle);
for (i=0; i<NX-2; i++) // for (i=0; i<NX-2; i++)
for (j=0; j<NY-2; j++) // for (j=0; j<NY-2; j++)
for (i=1; i<NX-2; i++)
for (j=1; j<NY-2; j++)
{ {
if ((TWOSPEEDS)||(xy_in[i*NY+j])) if ((TWOSPEEDS)||(xy_in[i*NY+j]))
{ {
@ -1463,6 +1465,24 @@ void draw_color_scheme_palette_3d(double x1, double y1, double x2, double y2, in
color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb);
break; break;
} }
case (Z_EULER_VORTICITY):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
case (Z_EULER_LOG_VORTICITY):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
case (Z_EULER_VORTICITY_ASYM):
{
value = min + 1.0*dy*(double)(j - jmin);
color_scheme_palette(COLOR_SCHEME, palette, 0.7*value, 1.0, 0, rgb);
break;
}
} }
if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value; if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value;
glColor3f(rgb[0], rgb[1], rgb[2]); glColor3f(rgb[0], rgb[1], rgb[2]);

151
wave_3d.c
View File

@ -44,65 +44,62 @@
#include <time.h> #include <time.h>
#define MOVIE 0 /* set to 1 to generate movie */ #define MOVIE 0 /* set to 1 to generate movie */
#define DOUBLE_MOVIE 0 /* set to 1 to produce movies for wave height and energy simultaneously */ #define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */
/* General geometrical parameters */ /* General geometrical parameters */
// #define WINWIDTH 1920 /* window width */ #define WINWIDTH 1920 /* window width */
// #define WINHEIGHT 1000 /* window height */ #define WINHEIGHT 1000 /* window height */
// #define NX 2000 /* number of grid points on x axis */ #define NX 2000 /* number of grid points on x axis */
// #define NY 2000 /* number of grid points on y axis */ #define NY 2000 /* number of grid points on y axis */
// // #define NX 1920 /* number of grid points on x axis */ // #define NX 2700 /* number of grid points on x axis */
// // #define NY 1000 /* number of grid points on y axis */ // #define NY 1350 /* number of grid points on y axis */
// // // #define YMIN -1.041666667 // // #define YMIN -1.041666667
// // // #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */ // // #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */
//
// #define XMIN -2.0 // #define XMIN -2.0
// #define XMAX 2.0 /* x interval */ // #define XMAX 2.0 /* x interval */
// #define YMIN -1.041666667 // #define YMIN -1.041666667
// #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */ // #define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */
#define HIGHRES 0 /* set to 1 if resolution of grid is double that of displayed image */ #define HIGHRES 1 /* set to 1 if resolution of grid is double that of displayed image */
#define WINWIDTH 1280 /* window width */ // #define WINWIDTH 1280 /* window width */
#define WINHEIGHT 720 /* window height */ // #define WINHEIGHT 720 /* window height */
// // // // //
// #define NX 1500 /* number of grid points on x axis */ // #define NX 1500 /* number of grid points on x axis */
// #define NY 1500 /* number of grid points on y axis */ // #define NY 1500 /* number of grid points on y axis */
// // //
#define NX 1280 /* number of grid points on x axis */ // // #define NX 640 /* number of grid points on x axis */
#define NY 720 /* number of grid points on y axis */ // // #define NY 360 /* number of grid points on y axis */
//
// #define NX 640 /* number of grid points on x axis */ #define XMIN -1.4
// #define NY 360 /* number of grid points on y axis */ #define XMAX 1.4 /* x interval */
#define YMIN -1.4
#define XMIN -2.0 #define YMAX 1.4 /* y interval for 9/16 aspect ratio */
#define XMAX 2.0 /* x interval */ //
#define YMIN -1.125
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */
#define JULIA_SCALE 0.8 /* scaling for Julia sets */ #define JULIA_SCALE 0.8 /* scaling for Julia sets */
/* Choice of the billiard table */ /* Choice of the billiard table */
#define B_DOMAIN 49 /* choice of domain shape, see list in global_pdes.c */ #define B_DOMAIN 7 /* choice of domain shape, see list in global_pdes.c */
#define CIRCLE_PATTERN 201 /* pattern of circles or polygons, see list in global_pdes.c */ #define CIRCLE_PATTERN 2 /* pattern of circles or polygons, see list in global_pdes.c */
#define COMPARISON 0 /* set to 1 to compare two different patterns */ #define COMPARISON 0 /* set to 1 to compare two different patterns */
#define B_DOMAIN_B 20 /* second domain shape, for comparisons */ #define B_DOMAIN_B 20 /* second domain shape, for comparisons */
#define CIRCLE_PATTERN_B 0 /* second pattern of circles or polygons */ #define CIRCLE_PATTERN_B 0 /* second pattern of circles or polygons */
#define VARIABLE_IOR 0 /* set to 1 for a variable index of refraction */ #define VARIABLE_IOR 0 /* set to 1 for a variable index of refraction */
#define IOR 1 /* choice of index of refraction, see list in global_pdes.c */ #define IOR 2 /* choice of index of refraction, see list in global_pdes.c */
#define MANDEL_IOR_SCALE -0.05 /* parameter controlling dependence of IoR on Mandelbrot escape speed */ #define MANDEL_IOR_SCALE -0.05 /* parameter controlling dependence of IoR on Mandelbrot escape speed */
#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 RANDOM_POLY_ANGLE 1 /* set to 1 to randomize angle of polygons */ #define RANDOM_POLY_ANGLE 1 /* set to 1 to randomize angle of polygons */
#define LAMBDA -0.5 /* parameter controlling the dimensions of domain */ #define LAMBDA 0.7 /* parameter controlling the dimensions of domain */
#define MU 0.25 /* parameter controlling the dimensions of domain */ #define MU 0.0 /* parameter controlling the dimensions of domain */
#define NPOLY 3 /* number of sides of polygon */ #define NPOLY 3 /* number of sides of polygon */
#define APOLY 2.0 /* angle by which to turn polygon, in units of Pi/2 */ #define APOLY 2.0 /* angle by which to turn polygon, in units of Pi/2 */
#define MDEPTH 7 /* depth of computation of Menger gasket */ #define MDEPTH 7 /* depth of computation of Menger gasket */
@ -110,8 +107,8 @@
#define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */ #define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */
#define MANDELLIMIT 10.0 /* limit value for approximation of 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 FOCI 1 /* set to 1 to draw focal points of ellipse */
#define NGRIDX 36 /* number of grid point for grid of disks */ #define NGRIDX 12 /* number of grid point for grid of disks */
#define NGRIDY 6 /* number of grid point for grid of disks */ #define NGRIDY 16 /* number of grid point for grid of disks */
#define X_SHOOTER -0.2 #define X_SHOOTER -0.2
#define Y_SHOOTER -0.6 #define Y_SHOOTER -0.6
@ -131,18 +128,19 @@
/* 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 1 /* set to 1 to replace hardcore boundary by medium with different speed */
#define OSCILLATE_LEFT 1 /* set to 1 to add oscilating boundary condition on the left */ #define OSCILLATE_LEFT 0 /* set to 1 to add oscilating boundary condition on the left */
#define OSCILLATE_TOPBOT 1 /* set to 1 to enforce a planar wave on top and bottom boundary */ #define OSCILLATE_TOPBOT 0 /* set to 1 to enforce a planar wave on top and bottom boundary */
#define OSCILLATION_SCHEDULE 3 /* oscillation schedule, see list in global_pdes.c */ #define OSCILLATION_SCHEDULE 3 /* oscillation schedule, see list in global_pdes.c */
#define OMEGA 0.001 /* frequency of periodic excitation */ #define OMEGA 0.001 /* frequency of periodic excitation */
#define AMPLITUDE 0.8 /* amplitude of periodic excitation */ // #define OMEGA 0.0005 /* frequency of periodic excitation */
#define AMPLITUDE 0.8 /* amplitude of periodic excitation */
#define ACHIRP 0.2 /* acceleration coefficient in chirp */ #define ACHIRP 0.2 /* acceleration coefficient in chirp */
#define COURANT 0.1 /* Courant number */ #define DAMPING 0.0 /* damping of periodic excitation */
#define COURANTB 0.025 /* Courant number in medium B */ #define COURANT 0.06 /* Courant number */
#define DAMPING 0.0 /* damping of periodic excitation */ #define COURANTB 0.15 /* Courant number in medium B */
#define GAMMA 0.0 /* damping factor in wave equation */ #define GAMMA 0.0 /* damping factor in wave equation */
#define GAMMAB 0.0 /* damping factor in wave equation */ #define GAMMAB 0.015 /* damping factor in wave equation */
#define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */ #define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */
#define GAMMA_TOPBOT 1.0e-7 /* damping factor on boundary */ #define GAMMA_TOPBOT 1.0e-7 /* damping factor on boundary */
#define KAPPA 0.0 /* "elasticity" term enforcing oscillations */ #define KAPPA 0.0 /* "elasticity" term enforcing oscillations */
@ -158,14 +156,16 @@
/* Boundary conditions, see list in global_pdes.c */ /* Boundary conditions, see list in global_pdes.c */
#define B_COND 3 // #define B_COND 1
#define B_COND 2
#define PRECOMPUTE_BC 0 /* set to 1 to compute neighbours for Laplacian in advance */ #define PRECOMPUTE_BC 0 /* set to 1 to compute neighbours for Laplacian in advance */
/* Parameters for length and speed of simulation */ /* Parameters for length and speed of simulation */
#define NSTEPS 3000 /* number of frames of movie */ // #define NSTEPS 200 /* number of frames of movie */
#define NVID 8 /* number of iterations between images displayed on screen */ #define NSTEPS 1500 /* number of frames of movie */
#define NVID 10 /* number of iterations between images displayed on screen */
#define NSEG 1000 /* number of segments of boundary */ #define NSEG 1000 /* number of segments of boundary */
#define INITIAL_TIME 0 /* time after which to start saving frames */ #define INITIAL_TIME 0 /* time after which to start saving frames */
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */ #define BOUNDARY_WIDTH 2 /* width of billiard boundary */
@ -182,9 +182,13 @@
/* Parameters of initial condition */ /* Parameters of initial condition */
// #define INITIAL_AMP 0.75 /* amplitude of initial condition */
// #define INITIAL_VARIANCE 0.001 /* variance of initial condition */
// #define INITIAL_WAVELENGTH 0.05 /* wavelength of initial condition */
#define INITIAL_AMP 0.75 /* amplitude of initial condition */ #define INITIAL_AMP 0.75 /* amplitude of initial condition */
#define INITIAL_VARIANCE 0.0005 /* variance of initial condition */ #define INITIAL_VARIANCE 0.0002 /* variance of initial condition */
#define INITIAL_WAVELENGTH 0.1 /* wavelength of initial condition */ #define INITIAL_WAVELENGTH 0.01 /* wavelength of initial condition */
/* Plot type, see list in global_pdes.c */ /* Plot type, see list in global_pdes.c */
@ -199,13 +203,13 @@
#define NON_DIRICHLET_BC 0 /* set to 1 to draw only facets in domain, if field is not zero on boundary */ #define NON_DIRICHLET_BC 0 /* set to 1 to draw only facets in domain, if field is not zero on boundary */
#define FLOOR_ZCOORD 1 /* set to 1 to draw only facets with z not too negative */ #define FLOOR_ZCOORD 1 /* set to 1 to draw only facets with z not too negative */
#define DRAW_BILLIARD 1 /* set to 1 to draw boundary */ #define DRAW_BILLIARD 1 /* set to 1 to draw boundary */
#define DRAW_BILLIARD_FRONT 0 /* set to 1 to draw front of boundary after drawing wave */ #define DRAW_BILLIARD_FRONT 1 /* set to 1 to draw front of boundary after drawing wave */
#define DRAW_CONSTRUCTION_LINES 0 /* set to 1 to draw construction lines of certain domains */ #define DRAW_CONSTRUCTION_LINES 0 /* set to 1 to draw construction lines of certain domains */
#define FADE_IN_OBSTACLE 1 /* set to 1 to fade color inside obstacles */ #define FADE_IN_OBSTACLE 1 /* set to 1 to fade color inside obstacles */
#define DRAW_OUTSIDE_GRAY 0 /* experimental, draw outside of billiard in gray */ #define DRAW_OUTSIDE_GRAY 0 /* experimental, draw outside of billiard in gray */
#define PLOT_SCALE_ENERGY 0.5 /* vertical scaling in energy plot */ #define PLOT_SCALE_ENERGY 0.01 /* vertical scaling in energy plot */
#define PLOT_SCALE_LOG_ENERGY 1.0 /* vertical scaling in log energy plot */ #define PLOT_SCALE_LOG_ENERGY 0.25 /* vertical scaling in log energy plot */
/* 3D representation */ /* 3D representation */
@ -219,24 +223,24 @@
/* Color schemes */ /* Color schemes */
#define COLOR_PALETTE 17 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE 10 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE_B 14 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE_B 16 /* Color palette, see list in global_pdes.c */
#define BLACK 1 /* background */ #define BLACK 1 /* background */
#define COLOR_SCHEME 3 /* choice of color scheme, see list in global_pdes.c */ #define COLOR_SCHEME 3 /* 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 0.5 /* sensitivity of color on wave amplitude */ #define SLOPE 1.0 /* sensitivity of color on wave amplitude */
#define VSCALE_AMPLITUDE 1.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */ #define VSCALE_AMPLITUDE 1.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */
#define VSCALE_ENERGY 60.0 /* additional scaling factor for color scheme P_3D_ENERGY */ #define VSCALE_ENERGY 100.0 /* additional scaling factor for color scheme P_3D_ENERGY */
#define PHASE_FACTOR 20.0 /* factor in computation of phase in color scheme P_3D_PHASE */ #define PHASE_FACTOR 20.0 /* factor in computation of phase in color scheme P_3D_PHASE */
#define PHASE_SHIFT 0.0 /* shift of phase in color scheme P_3D_PHASE */ #define PHASE_SHIFT 0.0 /* shift of phase in color scheme P_3D_PHASE */
#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 250.0 /* scaling factor for energy representation */ #define E_SCALE 100.0 /* scaling factor for energy representation */
#define LOG_SCALE 0.5 /* scaling factor for energy log representation */ #define LOG_SCALE 0.5 /* scaling factor for energy log representation */
#define LOG_SHIFT 0.0 /* shift of colors on log scale */ #define LOG_SHIFT 0.5 /* shift of colors on log scale */
#define LOG_ENERGY_FLOOR -100.0 /* floor value for log of (total) energy */ #define LOG_ENERGY_FLOOR -10.0 /* floor value for log of (total) energy */
#define LOG_MEAN_ENERGY_SHIFT 1.0 /* additional shift for log of mean energy */ #define LOG_MEAN_ENERGY_SHIFT 1.0 /* additional shift for log of mean energy */
#define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */ #define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */
@ -247,13 +251,28 @@
#define HUEMEAN 240.0 /* mean value of hue for color scheme C_HUE */ #define HUEMEAN 240.0 /* mean value of hue for color scheme C_HUE */
#define HUEAMP -200.0 /* amplitude of variation of hue for color scheme C_HUE */ #define HUEAMP -200.0 /* amplitude of variation of hue for color scheme C_HUE */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
// 0, 9, 18, 20, 22
// #define RAND_SHIFT 58 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */ #define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */
#define COLORBAR_RANGE 3.0 /* scale of color scheme bar */ #define COLORBAR_RANGE 2.0 /* scale of color scheme bar */
#define COLORBAR_RANGE_B 15.0 /* scale of color scheme bar for 2nd part */ #define COLORBAR_RANGE_B 5.0 /* scale of color scheme bar for 2nd part */
#define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */ #define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */
#define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */ #define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */
/* for compatibility with sub_wave and sub_maze */
#define ADD_POTENTIAL 0
// #define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
/* For debugging purposes only */ /* For debugging purposes only */
#define FLOOR 1 /* set to 1 to limit wave amplitude to VMAX */ #define FLOOR 1 /* 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 */
@ -264,21 +283,22 @@ double u_3d[2] = {0.75, -0.45}; /* projections of basis vectors for REP_AXO_
double v_3d[2] = {-0.75, -0.45}; double v_3d[2] = {-0.75, -0.45};
double w_3d[2] = {0.0, 0.015}; double w_3d[2] = {0.0, 0.015};
double light[3] = {0.816496581, -0.40824829, 0.40824829}; /* vector of "light" direction for P_3D_ANGLE color scheme */ double light[3] = {0.816496581, -0.40824829, 0.40824829}; /* vector of "light" direction for P_3D_ANGLE color scheme */
double observer[3] = {8.0, 8.0, 6.0}; /* location of observer for REP_PROJ_3D representation */ double observer[3] = {8.0, 8.0, 8.0}; /* location of observer for REP_PROJ_3D representation */
int reset_view = 0; /* switch to reset 3D view parameters (for option ROTATE_VIEW) */ int reset_view = 0; /* switch to reset 3D view parameters (for option ROTATE_VIEW) */
#define Z_SCALING_FACTOR 0.2 /* overall scaling factor of z axis for REP_PROJ_3D representation */ #define Z_SCALING_FACTOR 0.35 /* overall scaling factor of z axis for REP_PROJ_3D representation */
#define XY_SCALING_FACTOR 2.1 /* overall scaling factor for on-screen (x,y) coordinates after projection */ #define XY_SCALING_FACTOR 2.4 /* overall scaling factor for on-screen (x,y) coordinates after projection */
#define ZMAX_FACTOR 1.0 /* max value of z coordinate for REP_PROJ_3D representation */ #define ZMAX_FACTOR 1.0 /* max value of z coordinate for REP_PROJ_3D representation */
#define XSHIFT_3D -0.1 /* overall x shift for REP_PROJ_3D representation */ #define XSHIFT_3D -0.1 /* overall x shift for REP_PROJ_3D representation */
#define YSHIFT_3D 0.1 /* overall y shift for REP_PROJ_3D representation */ #define YSHIFT_3D 0.1 /* overall y shift for REP_PROJ_3D representation */
#include "global_pdes.c" /* constants and global variables */ #include "global_pdes.c" /* constants and global variables */
#include "global_3d.c" /* constants and global variables */
#include "sub_maze.c" /* support for generating mazes */
#include "sub_wave.c" /* common functions for wave_billiard, heat and schrodinger */ #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 "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
#include "global_3d.c" /* constants and global variables */
#include "sub_wave_3d.c" /* graphical functions specific to wave_3d */ #include "sub_wave_3d.c" /* graphical functions specific to wave_3d */
FILE *time_series_left, *time_series_right; FILE *time_series_left, *time_series_right;
@ -961,6 +981,9 @@ void animation()
npolyline = init_polyline(MDEPTH, polyline); npolyline = init_polyline(MDEPTH, polyline);
for (i=0; i<npolyline; i++) printf("vertex %i: (%.3f, %.3f)\n", i, polyline[i].x, polyline[i].y); for (i=0; i<npolyline; i++) printf("vertex %i: (%.3f, %.3f)\n", i, polyline[i].x, polyline[i].y);
if (COMPARISON) npolyline_b = init_polyline(MDEPTH, polyline); if (COMPARISON) npolyline_b = init_polyline(MDEPTH, polyline);
npolyrect = init_polyrect(polyrect);
for (i=0; i<npolyrect; i++) printf("polyrect vertex %i: (%.3f, %.3f) - (%.3f, %.3f)\n", i, polyrect[i].x1, polyrect[i].y1, polyrect[i].x2, polyrect[i].y2);
courant2 = COURANT*COURANT; courant2 = COURANT*COURANT;
courantb2 = COURANTB*COURANTB; courantb2 = COURANTB*COURANTB;
@ -1005,8 +1028,8 @@ void animation()
// init_circular_wave_mod(polyline[85].x, polyline[85].y, phi, psi, xy_in); // init_circular_wave_mod(polyline[85].x, polyline[85].y, phi, psi, xy_in);
// init_circular_wave_mod(0.95, 0.0, phi, psi, xy_in); init_circular_wave_mod(-0.85, 0.0, phi, psi, xy_in);
init_wave_flat_mod(phi, psi, xy_in); // init_wave_flat_mod(phi, psi, xy_in);
// add_circular_wave_mod(1.0, 1.0, 0.0, phi, psi, xy_in); // add_circular_wave_mod(1.0, 1.0, 0.0, phi, psi, xy_in);
// printf("Wave initialized\n"); // printf("Wave initialized\n");

View File

@ -44,14 +44,14 @@
#include <time.h> #include <time.h>
#define MOVIE 0 /* set to 1 to generate movie */ #define MOVIE 0 /* set to 1 to generate movie */
#define DOUBLE_MOVIE 0 /* set to 1 to produce movies for wave height and energy simultaneously */ #define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */
/* General geometrical parameters */ /* General geometrical parameters */
#define WINWIDTH 1920 /* window width */ #define WINWIDTH 1920 /* window width */
#define WINHEIGHT 1000 /* window height */ #define WINHEIGHT 1000 /* window height */
// #define NX 1920 /* number of grid points on x axis */ // #define NX 1920 /* number of grid points on x axis */
// #define NY 1000 /* number of grid points on y axis */ // #define NY 1000 /* number of grid points on x axis */
#define NX 3840 /* number of grid points on x axis */ #define NX 3840 /* number of grid points on x axis */
#define NY 2000 /* number of grid points on y axis */ #define NY 2000 /* number of grid points on y axis */
@ -65,6 +65,8 @@
// #define WINWIDTH 1280 /* window width */ // #define WINWIDTH 1280 /* window width */
// #define WINHEIGHT 720 /* window height */ // #define WINHEIGHT 720 /* window height */
// //
// // #define NX 640 /* number of grid points on x axis */
// // #define NY 360 /* number of grid points on y axis */
// // #define NX 1280 /* number of grid points on x axis */ // // #define NX 1280 /* number of grid points on x axis */
// // #define NY 720 /* number of grid points on y axis */ // // #define NY 720 /* number of grid points on y axis */
// #define NX 2560 /* number of grid points on x axis */ // #define NX 2560 /* number of grid points on x axis */
@ -79,11 +81,11 @@
/* Choice of the billiard table */ /* Choice of the billiard table */
#define B_DOMAIN 20 /* choice of domain shape, see list in global_pdes.c */ #define B_DOMAIN 53 /* choice of domain shape, see list in global_pdes.c */
#define CIRCLE_PATTERN 1 /* pattern of circles or polygons, see list in global_pdes.c */ #define CIRCLE_PATTERN 1 /* pattern of circles or polygons, see list in global_pdes.c */
#define COMPARISON 0 /* set to 1 to compare two different patterns */ #define COMPARISON 0 /* set to 1 to compare two different patterns (beta) */
#define B_DOMAIN_B 20 /* second domain shape, for comparisons */ #define B_DOMAIN_B 20 /* second domain shape, for comparisons */
#define CIRCLE_PATTERN_B 0 /* second pattern of circles or polygons */ #define CIRCLE_PATTERN_B 0 /* second pattern of circles or polygons */
@ -91,10 +93,10 @@
#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 RANDOM_POLY_ANGLE 1 /* set to 1 to randomize angle of polygons */ #define RANDOM_POLY_ANGLE 1 /* set to 1 to randomize angle of polygons */
#define LAMBDA 0.7 /* parameter controlling the dimensions of domain */ #define LAMBDA 1.0 /* parameter controlling the dimensions of domain */
#define MU 0.028 /* parameter controlling the dimensions of domain */ #define MU 0.3 /* parameter controlling the dimensions of domain */
#define NPOLY 3 /* number of sides of polygon */ #define NPOLY 6 /* number of sides of polygon */
#define APOLY 0.3333333333333333 /* angle by which to turn polygon, in units of Pi/2 */ #define APOLY 0.0 /* angle by which to turn polygon, in units of Pi/2 */
#define MDEPTH 6 /* depth of computation of Menger gasket */ #define MDEPTH 6 /* depth of computation of Menger gasket */
#define MRATIO 3 /* ratio defining Menger gasket */ #define MRATIO 3 /* ratio defining Menger gasket */
#define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */ #define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */
@ -120,18 +122,18 @@
/* 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 1 /* set to 1 to replace hardcore boundary by medium with different speed */
#define OSCILLATE_LEFT 1 /* set to 1 to add oscilating boundary condition on the left */ #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 OSCILLATE_TOPBOT 0 /* set to 1 to enforce a planar wave on top and bottom boundary */
#define OSCILLATION_SCHEDULE 3 /* oscillation schedule, see list in global_pdes.c */ #define OSCILLATION_SCHEDULE 1 /* oscillation schedule, see list in global_pdes.c */
#define OMEGA 0.0005 /* frequency of periodic excitation */ #define OMEGA 0.0005 /* frequency of periodic excitation */
#define AMPLITUDE 0.8 /* amplitude of periodic excitation */ #define AMPLITUDE 0.8 /* amplitude of periodic excitation */
#define ACHIRP 0.25 /* acceleration coefficient in chirp */ #define ACHIRP 0.25 /* acceleration coefficient in chirp */
#define DAMPING 0.0 /* damping of periodic excitation */ #define DAMPING 0.0 /* damping of periodic excitation */
#define COURANT 0.05 /* Courant number */ #define COURANT 0.1 /* Courant number */
#define COURANTB 0.0125 /* Courant number in medium B */ #define COURANTB 0.05 /* Courant number in medium B */
#define GAMMA 0.0 /* damping factor in wave equation */ #define GAMMA 0.0 /* damping factor in wave equation */
#define GAMMAB 0.0 /* damping factor in wave equation */ #define GAMMAB 5.0e-3 /* damping factor in wave equation */
#define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */ #define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */
#define GAMMA_TOPBOT 1.0e-7 /* damping factor on boundary */ #define GAMMA_TOPBOT 1.0e-7 /* damping factor on boundary */
#define KAPPA 0.0 /* "elasticity" term enforcing oscillations */ #define KAPPA 0.0 /* "elasticity" term enforcing oscillations */
@ -142,24 +144,26 @@
/* Increasing COURANT speeds up the simulation, but decreases accuracy */ /* Increasing COURANT speeds up the simulation, but decreases accuracy */
/* For similar wave forms, COURANT^2*GAMMA should be kept constant */ /* For similar wave forms, COURANT^2*GAMMA should be kept constant */
#define ADD_OSCILLATING_SOURCE 0 /* set to 1 to add an oscillating wave source */ #define ADD_OSCILLATING_SOURCE 1 /* set to 1 to add an oscillating wave source */
#define OSCILLATING_SOURCE_PERIOD 6 /* period of oscillating source */ #define OSCILLATING_SOURCE_PERIOD 50 /* period of oscillating source */
/* Boundary conditions, see list in global_pdes.c */ /* Boundary conditions, see list in global_pdes.c */
#define B_COND 3 #define B_COND 2
/* Parameters for length and speed of simulation */ /* Parameters for length and speed of simulation */
#define NSTEPS 2700 /* number of frames of movie */ // #define NSTEPS 1000 /* number of frames of movie */
#define NVID 15 /* number of iterations between images displayed on screen */ #define NSTEPS 2400 /* number of frames of movie */
#define NVID 12 /* number of iterations between images displayed on screen */
#define NSEG 1000 /* number of segments of boundary */ #define NSEG 1000 /* number of segments of boundary */
#define INITIAL_TIME 50 /* time after which to start saving frames */ #define INITIAL_TIME 0 /* time after which to start saving frames */
#define BOUNDARY_WIDTH 1 /* width of billiard boundary */ // #define INITIAL_TIME 400 /* time after which to start saving frames */
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */
#define PRINT_SPEED 0 /* print speed of moving source */ #define PRINT_SPEED 0 /* print speed of moving source */
#define PAUSE 200 /* number of frames after which to pause */ #define PAUSE 200 /* number of frames after which to pause */
#define PSLEEP 2 /* sleep time during pause */ #define PSLEEP 1 /* sleep time during pause */
#define SLEEP1 1 /* initial sleeping time */ #define SLEEP1 1 /* initial sleeping time */
#define SLEEP2 1 /* final sleeping time */ #define SLEEP2 1 /* final sleeping time */
#define MID_FRAMES 20 /* number of still frames between parts of two-part movie */ #define MID_FRAMES 20 /* number of still frames between parts of two-part movie */
@ -168,20 +172,22 @@
/* Parameters of initial condition */ /* Parameters of initial condition */
#define INITIAL_AMP 0.75 /* amplitude of initial condition */ // #define INITIAL_AMP 0.75 /* amplitude of initial condition */
#define INITIAL_VARIANCE 0.00005 /* variance of initial condition */ #define INITIAL_AMP 1.0 /* amplitude of initial condition */
#define INITIAL_WAVELENGTH 0.004 /* wavelength of initial condition */ #define INITIAL_VARIANCE 0.0002 /* variance of initial condition */
#define INITIAL_WAVELENGTH 0.01 /* wavelength of initial condition */
/* Plot type, see list in global_pdes.c */ /* Plot type, see list in global_pdes.c */
#define PLOT 1 #define PLOT 0
// #define PLOT 1
#define PLOT_B 0 /* plot type for second movie */ #define PLOT_B 5 /* plot type for second movie */
/* Color schemes */ /* Color schemes */
#define COLOR_PALETTE 13 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE 17 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE_B 11 /* Color palette, see list in global_pdes.c */ #define COLOR_PALETTE_B 13 /* Color palette, see list in global_pdes.c */
#define BLACK 1 /* background */ #define BLACK 1 /* background */
@ -192,7 +198,7 @@
#define PHASE_FACTOR 1.0 /* factor in computation of phase in color scheme P_3D_PHASE */ #define PHASE_FACTOR 1.0 /* factor in computation of phase in color scheme P_3D_PHASE */
#define PHASE_SHIFT 0.0 /* shift of phase in color scheme P_3D_PHASE */ #define PHASE_SHIFT 0.0 /* shift of phase in color scheme P_3D_PHASE */
#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 250.0 /* scaling factor for energy representation */ #define E_SCALE 200.0 /* scaling factor for energy representation */
#define LOG_SCALE 1.0 /* scaling factor for energy log representation */ #define LOG_SCALE 1.0 /* scaling factor for energy log representation */
#define LOG_SHIFT 1.0 /* shift of colors on log scale */ #define LOG_SHIFT 1.0 /* shift of colors on log scale */
#define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */ #define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */
@ -205,17 +211,31 @@
#define HUEAMP -180.0 /* amplitude of variation of hue for color scheme C_HUE */ #define HUEAMP -180.0 /* amplitude of variation of hue for color scheme C_HUE */
#define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */ #define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */
#define COLORBAR_RANGE 5.0 /* scale of color scheme bar */ #define COLORBAR_RANGE 1.5 /* scale of color scheme bar */
#define COLORBAR_RANGE_B 2.0 /* scale of color scheme bar for 2nd part */ #define COLORBAR_RANGE_B 1.5 /* scale of color scheme bar for 2nd part */
#define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */ #define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */
#define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */ #define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
/* for compatibility with sub_wave and sub_maze */
#define ADD_POTENTIAL 0
#define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
/* 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 */
#include "global_pdes.c" /* constants and global variables */ #include "global_pdes.c" /* constants and global variables */
#include "sub_maze.c" /* support for generating mazes */
#include "sub_wave.c" /* common functions for wave_billiard, heat and schrodinger */ #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 "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
@ -548,7 +568,6 @@ void draw_color_bar_palette(int plot, double range, int palette, int fade, doubl
void animation() void animation()
{ {
double time, scale, ratio, startleft[2], startright[2], sign = 1.0, r2, xy[2], fade_value, yshift, speed = 0.0, a, b, c; double time, scale, ratio, startleft[2], startright[2], sign = 1.0, r2, xy[2], fade_value, yshift, speed = 0.0, a, b, c;
// double *phi[NX], *psi[NX], *phi_tmp[NX], *psi_tmp[NX], *total_energy[NX], *color_scale[NX];
double *phi[NX], *psi[NX], *tmp[NX], *total_energy[NX], *color_scale[NX]; double *phi[NX], *psi[NX], *tmp[NX], *total_energy[NX], *color_scale[NX];
short int *xy_in[NX]; short int *xy_in[NX];
int i, j, s, sample_left[2], sample_right[2], period = 0, fade; int i, j, s, sample_left[2], sample_right[2], period = 0, fade;
@ -566,8 +585,6 @@ void animation()
{ {
phi[i] = (double *)malloc(NY*sizeof(double)); phi[i] = (double *)malloc(NY*sizeof(double));
psi[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));
tmp[i] = (double *)malloc(NY*sizeof(double)); tmp[i] = (double *)malloc(NY*sizeof(double));
total_energy[i] = (double *)malloc(NY*sizeof(double)); total_energy[i] = (double *)malloc(NY*sizeof(double));
xy_in[i] = (short int *)malloc(NY*sizeof(short int)); xy_in[i] = (short int *)malloc(NY*sizeof(short int));
@ -582,6 +599,9 @@ void animation()
/* initialise polyline for von Koch and similar domains */ /* initialise polyline for von Koch and similar domains */
npolyline = init_polyline(MDEPTH, polyline); npolyline = init_polyline(MDEPTH, polyline);
for (i=0; i<npolyline; i++) printf("vertex %i: (%.3f, %.3f)\n", i, polyline[i].x, polyline[i].y); for (i=0; i<npolyline; i++) printf("vertex %i: (%.3f, %.3f)\n", i, polyline[i].x, polyline[i].y);
npolyrect = init_polyrect(polyrect);
for (i=0; i<npolyrect; i++) printf("polyrect vertex %i: (%.3f, %.3f) - (%.3f, %.3f)\n", i, polyrect[i].x1, polyrect[i].y1, polyrect[i].x2, polyrect[i].y2);
courant2 = COURANT*COURANT; courant2 = COURANT*COURANT;
courantb2 = COURANTB*COURANTB; courantb2 = COURANTB*COURANTB;
@ -619,10 +639,10 @@ void animation()
// xy_to_ij(startright[0], startright[1], sample_right); // xy_to_ij(startright[0], startright[1], sample_right);
// printf("xleft = (%.3f, %.3f) xright = (%.3f, %.3f)\n", xin_left, yin_left, xin_right, yin_right); // printf("xleft = (%.3f, %.3f) xright = (%.3f, %.3f)\n", xin_left, yin_left, xin_right, yin_right);
init_wave_flat(phi, psi, xy_in); // init_wave_flat(phi, psi, xy_in);
// init_circular_wave(sqrt(LAMBDA*LAMBDA - 1.0), 0.0, phi, psi, xy_in); // init_circular_wave(sqrt(LAMBDA*LAMBDA - 1.0), 0.0, phi, psi, xy_in);
// init_circular_wave(0.0, 0.0, phi, psi, xy_in); init_circular_wave(0.0, 0.3, phi, psi, xy_in);
// init_wave_plus(LAMBDA - 0.3*MU, 0.5*MU, phi, psi, xy_in); // init_wave_plus(LAMBDA - 0.3*MU, 0.5*MU, phi, psi, xy_in);
// init_wave(LAMBDA - 0.3*MU, 0.5*MU, phi, psi, xy_in); // init_wave(LAMBDA - 0.3*MU, 0.5*MU, phi, psi, xy_in);
@ -722,18 +742,20 @@ void animation()
/* add oscillating waves */ /* add oscillating waves */
if ((ADD_OSCILLATING_SOURCE)&&(i%OSCILLATING_SOURCE_PERIOD == OSCILLATING_SOURCE_PERIOD - 1)) if ((ADD_OSCILLATING_SOURCE)&&(i%OSCILLATING_SOURCE_PERIOD == OSCILLATING_SOURCE_PERIOD - 1))
{ {
sign = -sign;
add_circular_wave(sign, 0.0, 0.3, phi, psi, xy_in);
// add_circular_wave(1.0, -1.5*LAMBDA, 0.0, phi, psi, xy_in); // add_circular_wave(1.0, -1.5*LAMBDA, 0.0, phi, psi, xy_in);
// add_circular_wave(-1.0, 0.6*cos((double)(period)*DPI/3.0), 0.6*sin((double)(period)*DPI/3.0), phi, psi, xy_in); // add_circular_wave(-1.0, 0.6*cos((double)(period)*DPI/3.0), 0.6*sin((double)(period)*DPI/3.0), phi, psi, xy_in);
sign = -sign;
period++;
yshift = (double)period*a + (double)(period*period)*b; // period++;
add_circular_wave(sign, -1.5 + yshift, 0.0, phi, psi, xy_in); //
// speed = (a + 2.0*(double)(period)*b)/((double)(NVID)); // yshift = (double)period*a + (double)(period*period)*b;
// speed = 0.55*(a + 2.0*(double)(period)*b)/((double)(NVID*OSCILLATING_SOURCE_PERIOD)); // add_circular_wave(sign, -1.5 + yshift, 0.0, phi, psi, xy_in);
speed = (a + 2.0*(double)(period)*b)/((double)(3*NVID*OSCILLATING_SOURCE_PERIOD)); // // speed = (a + 2.0*(double)(period)*b)/((double)(NVID));
printf("v = %.3lg, c = %.3lg\n", speed, c); // // speed = 0.55*(a + 2.0*(double)(period)*b)/((double)(NVID*OSCILLATING_SOURCE_PERIOD));
speed = speed/c; // speed = (a + 2.0*(double)(period)*b)/((double)(3*NVID*OSCILLATING_SOURCE_PERIOD));
// printf("v = %.3lg, c = %.3lg\n", speed, c);
// speed = speed/c;
// speed = 120.0*speed/((double)NVID*COURANT); // speed = 120.0*speed/((double)NVID*COURANT);
} }
if (PRINT_SPEED) print_speed(speed, 0, 1.0); if (PRINT_SPEED) print_speed(speed, 0, 1.0);

View File

@ -226,7 +226,20 @@
#define DAMPING 0.0 /* damping of periodic excitation */ #define DAMPING 0.0 /* damping of periodic excitation */
/* end of constants only used by wave_billiard and wave_3d */ /* end of constants only used by wave_billiard and wave_3d */
/* for compatibility with sub_wave and sub_maze */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define ADD_POTENTIAL 0
#define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
#include "global_pdes.c" /* constants and global variables */ #include "global_pdes.c" /* constants and global variables */
#include "sub_maze.c" /* support for generating mazes */
#include "sub_wave.c" /* common functions for wave_billiard, heat and schrodinger */ #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 "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
#include "sub_wave_comp.c" /* some functions specific to wave_comparison */ #include "sub_wave_comp.c" /* some functions specific to wave_comparison */

View File

@ -203,7 +203,19 @@
#define DAMPING 0.0 /* damping of periodic excitation */ #define DAMPING 0.0 /* damping of periodic excitation */
/* end of constants only used by wave_billiard and wave_3d */ /* end of constants only used by wave_billiard and wave_3d */
/* for compatibility with sub_wave and sub_maze */
#define NXMAZE 7 /* width of maze */
#define NYMAZE 7 /* height of maze */
#define MAZE_MAX_NGBH 4 /* max number of neighbours of maze cell */
#define RAND_SHIFT 24 /* seed of random number generator */
#define MAZE_XSHIFT 0.0 /* horizontal shift of maze */
#define ADD_POTENTIAL 0
#define POT_MAZE 7
#define POTENTIAL 0
/* end of constants only used by sub_wave and sub_maze */
#include "global_pdes.c" /* constants and global variables */ #include "global_pdes.c" /* constants and global variables */
#include "sub_maze.c" /* support for generating mazes */
#include "sub_wave.c" /* common functions for wave_billiard, heat and schrodinger */ #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 "wave_common.c" /* common functions for wave_billiard, wave_comparison, etc */
#include "sub_wave_comp.c" /* some functions specific to wave_comparison */ #include "sub_wave_comp.c" /* some functions specific to wave_comparison */