Add files via upload

This commit is contained in:
Nils Berglund 2023-04-30 17:01:39 +02:00 committed by GitHub
parent b2d7f56e1c
commit b809ce9e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 23373 additions and 5093 deletions

File diff suppressed because it is too large Load Diff

8756
Parameters_April23.md Normal file

File diff suppressed because it is too large Load Diff

6249
Parameters_May23.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -81,6 +81,9 @@
#define I_LJ_DIPOLE 5 /* Lennard-Jones with a dipolar angle dependence */
#define I_LJ_QUADRUPOLE 6 /* Lennard-Jones with a quadropolar angle dependence */
#define I_LJ_WATER 7 /* model for water molecule */
#define I_VICSEK 8 /* Vicsek-type interaction */
#define I_VICSEK_REPULSIVE 9 /* Vicsek-type interaction with harmonic repulsion */
#define I_VICSEK_SPEED 10 /* Vicsek-type interaction with speed adjustment */
/* Boundary conditions */
@ -159,6 +162,8 @@
#define IC_CATALYSIS 4 /* mix of 1 and 2 in left half, only 1 in right half */
#define IC_LAYERS 5 /* layer of 2 below 1 */
#define IC_BZ 6 /* initial state for BZ reaction */
#define IC_SIGNX 7 /* type 1 or 2 depending on sign of x */
#define IC_TWOROCKETS 8 /* type 1 or 2 depending on rocket position */
/* Plot types */
@ -201,6 +206,7 @@
#define COL_TURBO_CYCLIC 101 /* TURBO color palette (by Anton Mikhailov) corrected to be cyclic, beta */
#define VICSEK_INT ((INTERACTION == I_VICSEK)||(INTERACTION == I_VICSEK_REPULSIVE)||(INTERACTION == I_VICSEK_SPEED))
typedef struct
{
@ -216,6 +222,7 @@ typedef struct
double fx; /* x component of force on particle */
double fy; /* y component of force on particle */
double torque; /* torque on particle */
int close_to_boundary; /* has value 1 if particle is close to a boundary */
short int thermostat; /* whether particle is coupled to thermostat */
int hashcell; /* hash cell in which particle is located */
int neighb; /* number of neighbours within given distance */

View File

@ -79,6 +79,7 @@
#define D_WING 70 /* complement of wing-shaped domain */
#define D_TESLA 71 /* Tesla valve */
#define D_TESLA_FOUR 72 /* four Tesla valves */
#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) */
@ -120,6 +121,7 @@
/* Variable index of refraction */
#define IOR_MANDELBROT 1 /* index of refraction depends on escape time in Mandelbrot set (log) */
#define IOR_MANDELBROT_LIN 100 /* index of refraction depends on escape time in Mandelbrot set (linear) */
#define IOR_MANDELBROT_MOD 101 /* index of refraction depends on escape time in Mandelbrot set (linear) */
#define IOR_EARTH 2 /* index of refraction models speed of seismic waves */
#define IOR_EXPLO_LENSING 3 /* explosive lensing */
#define IOR_PERIODIC_WELLS 4 /* periodic superposition of "wells" */
@ -235,11 +237,16 @@
#define Z_EULER_DIRECTION_SPEED 64 /* hut for direction of velocity, luminosity for speed */
/* special boundary conditions for Euler equation */
#define BCE_TOPBOTTOM 1 /* laminar flow at top and bottom */
#define BCE_TOPBOTTOMLEFT 2 /* laminar flow at top, bottom and left side */
#define BCE_CHANNELS 3 /* laminar flow in channels at left and right */
#define BCE_MIDDLE_STRIP 4 /* laminar flow in horizontal strip in the middle */
#define BCE_LEFT 5 /* laminar flow at left side */
#define BCE_TOPBOTTOM 1 /* special flow at top and bottom */
#define BCE_TOPBOTTOMLEFT 2 /* special flow at top, bottom and left side */
#define BCE_CHANNELS 3 /* special flow in channels at left and right */
#define BCE_MIDDLE_STRIP 4 /* special flow in horizontal strip in the middle */
#define BCE_LEFT 5 /* special flow at left side */
#define BCE_FOUR_CHANNELS 6 /* special flow in four channels at left and right */
/* flow types for boundary conditions in Euler equation */
#define BCF_LAMINAR 0 /* laminar flow */
#define BCF_PRESSURE 1 /* laminar flow with pressure gradient */
typedef struct
{
@ -300,6 +307,14 @@ typedef struct
int time_shift; /* time shift */
} t_wave_packet;
typedef struct
{
double xc, yc; /* (x,y) coordinates of center */
double phase; /* phase of source */
double amp; /* amplitude */
int sign;
} t_wave_source;
int ncircles = NMAXCIRCLES; /* actual number of circles, can be decreased e.g. for random patterns */

View File

@ -37,14 +37,14 @@
#include <time.h>
#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 */
#define SAVE_MEMORY 1 /* set to 1 to save memory while saving frames */
#define NO_EXTRA_BUFFER_SWAP 0 /* some OS require one less buffer swap when recording images */
#define NO_EXTRA_BUFFER_SWAP 1 /* some OS require one less buffer swap when recording images */
#define TIME_LAPSE 1 /* set to 1 to add a time-lapse movie at the end */
#define TIME_LAPSE 0 /* set to 1 to add a time-lapse movie at the end */
/* so far incompatible with double movie */
#define TIME_LAPSE_FACTOR 3 /* factor of time-lapse movie */
#define TIME_LAPSE_FIRST 1 /* set to 1 to show time-lapse version first */
#define TIME_LAPSE_FIRST 0 /* set to 1 to show time-lapse version first */
#define SAVE_TIME_SERIES 0 /* set to 1 to save time series of particle positions */
@ -90,22 +90,22 @@
#define CENTER_PY 0 /* set to 1 to center vertical momentum */
#define CENTER_PANGLE 0 /* set to 1 to center angular momentum */
#define INTERACTION 1 /* particle interaction, see list in global_ljones.c */
#define INTERACTION 10 /* particle interaction, see list in global_ljones.c */
#define INTERACTION_B 1 /* particle interaction for second type of particle, see list in global_ljones.c */
#define SPIN_INTER_FREQUENCY 5.0 /* angular frequency of spin-spin interaction */
#define SPIN_INTER_FREQUENCY 1.0 /* angular frequency of spin-spin interaction */
#define SPIN_INTER_FREQUENCY_B 2.0 /* angular frequency of spin-spin interaction for second particle type */
#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 PDISC_DISTANCE 4.2 /* minimal distance in Poisson disc process, controls density of particles */
#define PDISC_DISTANCE 1.3 /* minimal distance in Poisson disc process, controls density of particles */
#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 LAMBDA 0.5 /* parameter controlling the dimensions of domain */
#define MU 0.008 /* parameter controlling radius of particles */
#define MU 0.035 /* parameter controlling radius of particles */
#define MU_B 0.012 /* parameter controlling radius of particles of second type */
#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.0 /* angle by which to turn polygon, in units of Pi/2 */
#define MDEPTH 4 /* depth of computation of Menger gasket */
#define MRATIO 3 /* ratio defining Menger gasket */
#define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */
@ -125,11 +125,10 @@
/* Parameters for length and speed of simulation */
#define NSTEPS 5000 /* number of frames of movie */
// #define NSTEPS 3000 /* number of frames of movie */
#define NVID 175 /* number of iterations between images displayed on screen */
#define NSTEPS 3800 /* number of frames of movie */
#define NVID 50 /* number of iterations between images displayed on screen */
#define NSEG 250 /* number of segments of boundary */
#define INITIAL_TIME 20 /* time after which to start saving frames */
#define INITIAL_TIME 10 /* time after which to start saving frames */
#define OBSTACLE_INITIAL_TIME 200 /* time after which to start moving obstacle */
#define BOUNDARY_WIDTH 1 /* width of particle boundary */
#define LINK_WIDTH 2 /* width of links between particles */
@ -144,22 +143,22 @@
/* Boundary conditions, see list in global_ljones.c */
#define BOUNDARY_COND 0
#define BOUNDARY_COND 3
/* Plot type, see list in global_ljones.c */
#define PLOT 5
#define PLOT_B 0 /* plot type for second movie */
#define PLOT 4
#define PLOT_B 6 /* plot type for second movie */
#define DRAW_BONDS 1 /* set to 1 to draw bonds between neighbours */
#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 0 /* set to 1 to fill triangles between neighbours */
#define ALTITUDE_LINES 0 /* set to 1 to add horizontal lines to show altitude */
#define COLOR_SEG_GROUPS 0 /* set to 1 to collor segment groups differently */
/* Color schemes */
#define COLOR_PALETTE 10 /* Color palette, see list in global_ljones.c */
#define COLOR_PALETTE 0 /* Color palette, see list in global_ljones.c */
#define BLACK 1 /* background */
@ -193,27 +192,30 @@
#define RANDOM_RADIUS 0 /* set to 1 for random circle radius */
#define DT_PARTICLE 3.0e-6 /* time step for particle displacement */
#define KREPEL 12.0 /* constant in repelling force between particles */
#define KREPEL 0.1 /* constant in repelling force between particles */
#define EQUILIBRIUM_DIST 2.0 /* Lennard-Jones equilibrium distance */
#define EQUILIBRIUM_DIST_B 2.0 /* Lennard-Jones equilibrium distance for second type of particle */
#define REPEL_RADIUS 15.0 /* radius in which repelling force acts (in units of particle radius) */
#define DAMPING 200.0 /* damping coefficient of particles */
#define INITIAL_DAMPING 1000.0 /* damping coefficient of particles during initial phase */
#define PARTICLE_MASS 1.0 /* mass of particle of radius MU */
#define DAMPING 0.0 /* damping coefficient of particles */
#define INITIAL_DAMPING 50.0 /* damping coefficient of particles during initial phase */
#define DAMPING_ROT 100.0 /* dampint coefficient for rotation of particles */
#define PARTICLE_MASS 0.25 /* mass of particle of radius MU */
#define PARTICLE_MASS_B 0.5 /* mass of particle of radius MU */
#define PARTICLE_INERTIA_MOMENT 0.02 /* moment of inertia of particle */
#define PARTICLE_INERTIA_MOMENT 0.5 /* moment of inertia 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 OMEGA_INITIAL 10.0 /* initial angular velocity range */
#define V_INITIAL 20.0 /* initial velocity range */
#define OMEGA_INITIAL 5.0 /* initial angular velocity range */
#define VICSEK_VMIN 1.0 /* minimal speed of particles in Vicsek model */
#define VICSEK_VMAX 40.0 /* minimal speed of particles in Vicsek model */
#define THERMOSTAT 1 /* set to 1 to switch on thermostat */
#define THERMOSTAT 0 /* set to 1 to switch on thermostat */
#define VARY_THERMOSTAT 0 /* set to 1 for time-dependent thermostat schedule */
#define SIGMA 5.0 /* noise intensity in thermostat */
#define BETA 0.002 /* initial inverse temperature */
#define MU_XI 0.01 /* friction constant in thermostat */
#define KSPRING_BOUNDARY 1.0e7 /* confining harmonic potential outside simulation region */
#define KSPRING_OBSTACLE 1.0e11 /* harmonic potential of obstacles */
#define NBH_DIST_FACTOR 10.0 /* radius in which to count neighbours */
#define NBH_DIST_FACTOR 3.0 /* radius in which to count neighbours */
#define GRAVITY 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 */
@ -221,17 +223,19 @@
#define GRAVITY_FACTOR 100.0 /* factor by which to increase gravity */
#define GRAVITY_INITIAL_TIME 200 /* time at start of simulation with constant gravity */
#define GRAVITY_RESTORE_TIME 700 /* time at end of simulation with gravity restored to initial value */
#define KSPRING_VICSEK 0.2 /* spring constant for I_VICSEK_SPEED interaction */
#define ROTATION 1 /* set to 1 to include rotation of particles */
#define COUPLE_ANGLE_TO_THERMOSTAT 0 /* set to 1 to couple angular degrees of freedom to thermostat */
#define DIMENSION_FACTOR 1.0 /* scaling factor taking into account number of degrees of freedom */
#define KTORQUE 100.0 /* force constant in angular dynamics */
#define KTORQUE 2.0e3 /* force constant in angular dynamics */
#define KTORQUE_B 10.0 /* force constant in angular dynamics */
#define KTORQUE_DIFF 150.0 /* force constant in angular dynamics for different particles */
#define KTORQUE_BOUNDARY 1.0e6 /* constant in torque from the boundary */
#define DRAW_SPIN 0 /* set to 1 to draw spin vectors of particles */
#define DRAW_SPIN_B 0 /* set to 1 to draw spin vectors of particles */
#define DRAW_CROSS 1 /* set to 1 to draw cross on particles of second type */
#define SPIN_RANGE 7.0 /* range of spin-spin interaction */
#define SPIN_RANGE 10.0 /* range of spin-spin interaction */
#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 */
@ -326,7 +330,7 @@
#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 REACTION_DIFFUSION 1 /* 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) */
#define RD_REACTION 15 /* type of reaction, see list in global_ljones.c */
#define RD_TYPES 5 /* number of types in reaction-diffusion equation */
#define RD_INITIAL_COND 2 /* initial condition of particles */
@ -339,7 +343,7 @@
#define COLLISION_TIME 15 /* time during which collisions are shown */
#define PRINT_PARTICLE_NUMBER 0 /* set to 1 to print total number of particles */
#define PLOT_PARTICLE_NUMBER 1 /* set to 1 to make of plot of particle number over time */
#define PLOT_PARTICLE_NUMBER 0 /* set to 1 to make of plot of particle number over time */
#define PARTICLE_NB_PLOT_FACTOR 0.5 /* expected final number of particles over initial number */
#define PRINT_LEFT 1 /* set to 1 to print certain parameters at the top left instead of right */
#define PLOT_SPEEDS 0 /* set to 1 to add a plot of obstacle speeds (e.g. for rockets) */
@ -361,14 +365,15 @@
#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 MAZE_WIDTH 0.01 /* width of maze walls */
#define FLOOR_FORCE 1 /* set to 1 to limit force on particle to FMAX */
#define FMAX 1.0e10 /* maximal force */
#define FLOOR_OMEGA 0 /* set to 1 to limit particle momentum to PMAX */
#define PMAX 1000.0 /* maximal force */
#define HASHX 100 /* size of hashgrid in x direction */
#define HASHY 50 /* size of hashgrid in y direction */
#define HASHX 60 /* size of hashgrid in x direction */
#define HASHY 30 /* size of hashgrid in y direction */
#define HASHMAX 100 /* maximal number of particles per hashgrid cell */
#define HASHGRID_PADDING 0.1 /* padding of hashgrid outside simulation window */
@ -703,12 +708,13 @@ double evolve_particles(t_particle particle[NMAXCIRCLES], t_hashgrid hashgrid[HA
{
px[j] *= exp(- 0.5*DT_PARTICLE*xi);
py[j] *= exp(- 0.5*DT_PARTICLE*xi);
if (!COUPLE_ANGLE_TO_THERMOSTAT) pangle[j] *= exp(- DT_PARTICLE*DAMPING_ROT);
}
else
{
px[j] *= exp(- DT_PARTICLE*damping);
py[j] *= exp(- DT_PARTICLE*damping);
pangle[j] *= exp(- DT_PARTICLE*damping);
pangle[j] *= exp(- DT_PARTICLE*DAMPING_ROT);
}
if ((THERMOSTAT_ON)&&(COUPLE_ANGLE_TO_THERMOSTAT)&&(particle[j].thermostat))
pangle[j] *= exp(- 0.5*DT_PARTICLE*xi);
@ -895,7 +901,15 @@ void evolve_segment_groups(t_segment segment[NMAXSEGMENTS], int time, t_group_se
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;
static double maxdepth, saturation_depth, xmax;
static int first = 1;
if (first)
{
xmax = XMAX - TRACK_X_PADDING;
if ((PLOT_SPEEDS)||(PLOT_TRAJECTORIES)) xmax -= 1.8;
first = 0;
}
maxdepth = 0.5*GROUP_WIDTH;
saturation_depth = 0.1*GROUP_WIDTH;
@ -1038,8 +1052,8 @@ void evolve_segment_groups(t_segment segment[NMAXSEGMENTS], int time, t_group_se
ymean = ymean/((double)(ngroups-1));
if (ymean > ytrack) ytrack = ymean;
if (xmean > XMAX - TRACK_X_PADDING)
xtrack = xmean - XMAX + TRACK_X_PADDING;
if (xmean > xmax)
xtrack = xmean - xmax;
else if (xmean < XMIN + TRACK_X_PADDING)
xtrack = xmean - XMIN - TRACK_X_PADDING;
}
@ -1048,10 +1062,8 @@ void evolve_segment_groups(t_segment segment[NMAXSEGMENTS], int time, t_group_se
void animation()
{
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,
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, speed_ratio, ymin, ymax, delta_energy;
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, 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, speed_ratio, ymin, ymax, delta_energy, speed, ratio = 1.0, ratioc;
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,
min_nb, max_nb, close, wrapx = 0, wrapy = 0, nactive = 0, nadd_particle = 0, nmove = 0, nsuccess = 0,
@ -1070,7 +1082,8 @@ void animation()
t_hashgrid *hashgrid;
char message[100];
ratioc = 1.0 - ratio;
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_SEGMENTS)
@ -1127,9 +1140,9 @@ void animation()
// printf("1\n");
printf("Initializing configuration\n");
nactive = initialize_configuration(particle, hashgrid, obstacle, px, py, pangle, tracer_n);
nactive = initialize_configuration(particle, hashgrid, obstacle, px, py, pangle, tracer_n, segment);
// xi = 0.0;
@ -1140,8 +1153,9 @@ void animation()
sleep(1);
update_hashgrid(particle, hashgrid, 1);
printf("Updated hashgrid\n");
compute_relative_positions(particle, hashgrid);
printf("Computed relative positions\n");
blank();
// glColor3f(0.0, 0.0, 0.0);
@ -1166,9 +1180,12 @@ void animation()
thermostat_on = thermostat_schedule(i);
printf("Termostat: %i\n", thermostat_on);
}
/* deactivate some segments */
if ((ADD_FIXED_SEGMENTS)&&(DEACTIVATE_SEGMENT)&&(i == INITIAL_TIME + SEGMENT_DEACTIVATION_TIME + 1))
for (j=0; j<nsegments; j++) if (segment[j].inactivate) segment[j].active = 0;
/* recolor particles in case if P_INITIAL_POS color code */
if ((i <= INITIAL_TIME-1)&&(i%10 == 0)&&((PLOT == P_INITIAL_POS)||(PLOT_B == P_INITIAL_POS)))
{
@ -1184,7 +1201,7 @@ void animation()
particle[j].color_hue = 360.0*(particle[j].yc - ymin)/(ymax - ymin);
}
blank();
blank();
fboundary = 0.0;
pleft = 0.0;
@ -1212,7 +1229,6 @@ void animation()
segment[j].torque = 0.0;
}
compute_relative_positions(particle, hashgrid);
update_hashgrid(particle, hashgrid, 0);
@ -1225,10 +1241,27 @@ void animation()
/* compute force from other particles */
compute_particle_force(j, krepel, particle, hashgrid);
/* take care of boundary conditions */
fboundary += compute_boundary_force(j, particle, obstacle, segment, xmincontainer, xmaxcontainer, &pleft, &pright, pressure, wall);
/* align velocities in case of Vicsek models */
// if (VICSEK_INT)
if ((VICSEK_INT)&&(!particle[j].close_to_boundary))
{
speed = module2(particle[j].vx,particle[j].vy);
if ((VICSEK_VMIN > 0.0)&&(speed < VICSEK_VMIN)) speed = VICSEK_VMIN;
if (speed > VICSEK_VMAX) speed = 0.5*(speed + VICSEK_VMAX);
particle[j].vx = speed*cos(particle[j].angle);
particle[j].vy = speed*sin(particle[j].angle);
speed = module2(px[j],py[j]);
if ((VICSEK_VMIN > 0.0)&&(speed < VICSEK_VMIN)) speed = VICSEK_VMIN;
if (speed > VICSEK_VMAX) speed = 0.5*(speed + VICSEK_VMAX);
px[j] = speed*cos(particle[j].angle);
py[j] = speed*sin(particle[j].angle);
}
/* add gravity */
if (INCREASE_GRAVITY) particle[j].fy -= gravity/particle[j].mass_inv;
else
@ -1260,7 +1293,9 @@ void animation()
}
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);
if ((MOVE_SEGMENT_GROUPS)&&(i > INITIAL_TIME + SEGMENT_DEACTIVATION_TIME)) evolve_segment_groups(segment, i, segment_group);
// if ((MOVE_SEGMENT_GROUPS)&&(i > OBSTACLE_INITIAL_TIME)) evolve_segment_groups(segment, i, segment_group);
} /* end of for (n=0; n<NVID; n++) */
if ((i>INITIAL_TIME)&&(SAVE_TIME_SERIES))
@ -1305,7 +1340,7 @@ void animation()
// if ((PARTIAL_THERMO_COUPLING))
if ((PARTIAL_THERMO_COUPLING)&&(i>N_T_AVERAGE))
{
nthermo = partial_thermostat_coupling(particle, xshift + PARTIAL_THERMO_SHIFT);
nthermo = partial_thermostat_coupling(particle, xshift + PARTIAL_THERMO_SHIFT, segment);
printf("%i particles coupled to thermostat out of %i active\n", nthermo, nactive);
mean_energy = compute_mean_energy(particle);
}
@ -1326,7 +1361,6 @@ void animation()
while (particle[j].angle < 0.0) particle[j].angle += DPI;
}
/* update tracer particle trajectory */
if ((TRACER_PARTICLE)&&(i > INITIAL_TIME))
{
@ -1347,7 +1381,7 @@ void animation()
printf("Boundary force: %.3f\n", fboundary/(double)(ncircles*NVID));
if (RESAMPLE_Y) printf("%i succesful moves out of %i trials\n", nsuccess, nmove);
if (INCREASE_GRAVITY) printf("Gravity: %.3f\n", gravity);
total_neighbours = 0;
min_nb = 100;
max_nb = 0;
@ -1509,6 +1543,7 @@ void animation()
{
if (DOUBLE_MOVIE)
{
blank();
if (TRACER_PARTICLE) draw_trajectory(trajectory, traj_position, traj_length);
draw_particles(particle, PLOT, beta, collisions, ncollisions);
draw_container(xmincontainer, xmaxcontainer, obstacle, segment, wall);
@ -1528,9 +1563,14 @@ void animation()
else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle);
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();
if (!NO_EXTRA_BUFFER_SWAP) glutSwapBuffers();
}
glutSwapBuffers();
if (DOUBLE_MOVIE)
{
if (TRACER_PARTICLE) draw_trajectory(trajectory, traj_position, traj_length);

218
rde.c
View File

@ -50,32 +50,17 @@
#define WINHEIGHT 1150 /* window height */
#define NX 960 /* number of grid points on x axis */
#define NY 575 /* number of grid points on y axis */
// #define NX 480 /* number of grid points on x axis */
// #define NY 250 /* number of grid points on y axis */
// #define WINWIDTH 1280 /* window width */
// #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 XMIN -2.0
#define XMAX 2.0 /* x interval */
#define YMIN -1.197916667
#define YMAX 1.197916667 /* y interval for 9/16 aspect ratio */
// #define WINWIDTH 1280 /* window width */
// #define WINHEIGHT 720 /* window height */
//
// // #define NX 320 /* number of grid points on x axis */
// // #define NY 180 /* number of grid points on y axis */
// #define NX 640 /* number of grid points on x axis */
// #define NY 360 /* number of grid points on y axis */
// // #define NX 960 /* number of grid points on x axis */
// // #define NY 540 /* number of grid points on y axis */
//
// // #define NX 1280 /* number of grid points on x axis */
// // #define NY 720 /* number of grid points on y axis */
//
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
// #define YMIN -1.125
// #define YMAX 1.125 /* y interval for 9/16 aspect ratio */
/* Choice of simulated equation */
#define RDE_EQUATION 7 /* choice of reaction term, see list in global_3d.c */
@ -84,15 +69,16 @@
#define ADD_POTENTIAL 0 /* set to 1 to add a potential (for Schrodinger equation) */
#define ADD_MAGNETIC_FIELD 0 /* set to 1 to add a magnetic field (for Schrodinger equation) - then set POTENTIAL 1 */
#define ADD_FORCE_FIELD 1 /* set to 1 to add a foce field (for compressible Euler equation) */
#define ADD_FORCE_FIELD 0 /* set to 1 to add a foce field (for compressible Euler equation) */
#define POTENTIAL 7 /* type of potential or vector potential, see list in global_3d.c */
#define FORCE_FIELD 5 /* type of force field, see list in global_3d.c */
#define ADD_CORIOLIS_FORCE 1 /* set to 1 to add Coriolis force (quasigeostrophic Euler equations) */
#define ANTISYMMETRIZE_WAVE_FCT 0 /* set tot 1 to make wave function antisymmetric */
#define ADAPT_STATE_TO_BC 1 /* to smoothly adapt initial state to obstacles */
#define OBSTACLE_GEOMETRY 71 /* geometry of obstacles, as in B_DOMAIN */
// #define BC_STIFFNESS 100.0 /* controls region of boundary condition control */
#define ADAPT_STATE_TO_BC 0 /* to smoothly adapt initial state to obstacles */
#define OBSTACLE_GEOMETRY 72 /* geometry of obstacles, as in B_DOMAIN */
#define BC_STIFFNESS 50.0 /* controls region of boundary condition control */
// #define BC_STIFFNESS 100.0 /* controls region of boundary condition control */
#define JULIA_SCALE 0.5 /* scaling for Julia sets */
@ -152,7 +138,9 @@
#define BZQ 0.0008 /* parameter in BZ equation */
#define BZF 1.2 /* parameter in BZ equation */
#define B_FIELD 10.0 /* magnetic field */
#define G_FIELD 2.0e-5 /* gravity/constant in repulsive field from obstacles */
#define G_FIELD 0.004 /* gravity/constant in repulsive field from obstacles */
// #define G_FIELD 1.0e-4 /* gravity/constant in repulsive field from obstacles */
// #define G_FIELD 2.0e-5 /* gravity/constant in repulsive field from obstacles */
#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 K_EULER_INC 0.5 /* constant in incompressible Euler equation */
@ -189,14 +177,15 @@
#define RPSLZB_FINAL_TIME 500 /* final time during which rpslzb remains constant */
#define CHANGE_FLOW_SPEED 0 /* set to 1 to change speed of laminar flow */
#define IN_OUT_FLOW_BC 3 /* type of in-flow/out-flow boundary conditions for Euler equation */
#define IN_OUT_BC_FACTOR 0.01 /* factor of convex combination between old and new flow */
#define IN_OUT_FLOW_BC 0 /* type of in-flow/out-flow boundary conditions for Euler equation, 0 for no b.c. */
#define IN_OUT_BC_FACTOR 0.001 /* factor of convex combination between old and new flow */
#define BC_FLOW_TYPE 1 /* type of initial condition */
/* see list in global_pdes.c */
#define IN_OUT_FLOW_MIN_AMP 0.45 /* amplitude of in-flow/out-flow boundary conditions (for Euler equation) - min value */
#define IN_OUT_FLOW_MIN_AMP 0.45 /* amplitude of in-flow/out-flow boundary conditions (for Euler equation) - min value */
#define IN_OUT_FLOW_AMP 0.45 /* amplitude of in-flow/out-flow boundary conditions (for Euler equation) - max value */
#define LAMINAR_FLOW_MODULATION 0.05 /* asymmetry of laminar flow */
#define LAMINAR_FLOW_MODULATION 0.01 /* asymmetry of laminar flow */
#define LAMINAR_FLOW_YPERIOD 1.0 /* period of laminar flow in y direction */
#define PRESSURE_GRADIENT 0.3 /* amplitude of pressure gradient for Euler equation */
#define EULER_GRADIENT_YSHIFT 0.0 /* y-shift in computation of gradient in Euler equation */
@ -206,8 +195,8 @@
/* Parameters for length and speed of simulation */
#define NSTEPS 2000 /* number of frames of movie */
// #define NSTEPS 100 /* number of frames of movie */
#define NSTEPS 2250 /* number of frames of movie */
// #define NSTEPS 500 /* number of frames of movie */
#define NVID 100 /* number of iterations between images displayed on screen */
#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 */
@ -235,14 +224,13 @@
/* Plot type - color scheme */
#define CPLOT 61
#define CPLOT 64
#define CPLOT_B 62
/* Plot type - height of 3D plot */
#define ZPLOT 61 /* z coordinate in 3D plot */
// #define ZPLOT 32 /* z coordinate in 3D plot */
#define ZPLOT_B 62 /* z coordinate in second 3D plot */
#define ZPLOT_B 64 /* z coordinate in second 3D 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 */
@ -261,6 +249,8 @@
#define PRINT_PROBABILITIES 0 /* set to 1 to print probabilities (for Ehrenfest urn configuration) */
#define PRINT_NOISE 0 /* set to 1 to print noise intensity */
#define PRINT_FLOW_SPEED 0 /* set to 1 to print speed of flow */
#define PRINT_AVERAGE_SPEED 0 /* set to 1 to print average speed of flow */
#define PRINT_LEFT 1 /* set to 1 to print parameters at left side */
#define DRAW_FIELD_LINES 0 /* set to 1 to draw field lines */
#define FIELD_LINE_WIDTH 1 /* width of field lines */
@ -279,7 +269,7 @@
/* Color schemes, see list in global_pdes.c */
#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 10 /* Color palette, see list in global_pdes.c */
#define BLACK 1 /* black background */
@ -296,8 +286,8 @@
#define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */
#define SLOPE_SCHROD_LUM 50.0 /* sensitivity of luminosity on module, for color scheme Z_ARGUMENT */
#define MIN_SCHROD_LUM 0.2 /* minimal luminosity in color scheme Z_ARGUMENT*/
#define VSCALE_PRESSURE 0.5 /* additional scaling factor for color scheme Z_EULER_PRESSURE */
#define PRESSURE_SHIFT 25.0 /* shift for color scheme Z_EULER_PRESSURE */
#define VSCALE_PRESSURE 2.0 /* additional scaling factor for color scheme Z_EULER_PRESSURE */
#define PRESSURE_SHIFT 10.0 /* shift for color scheme Z_EULER_PRESSURE */
#define PRESSURE_LOG_SHIFT -2.5 /* shift for color scheme Z_EULER_PRESSURE */
#define COLORHUE 260 /* initial hue of water color for scheme C_LUM */
@ -311,12 +301,12 @@
#define LOG_SCALE 0.5 /* scaling factor for energy log representation */
#define LOG_SHIFT 1.0
#define LOG_MIN 1.0e-3 /* floor value for log vorticity plot */
#define VSCALE_SPEED 15.0 /* additional scaling factor for color scheme Z_EULER_SPEED */
#define VSCALE_SPEED 10.0 /* additional scaling factor for color scheme Z_EULER_SPEED */
#define VMEAN_SPEED 0.0 /* mean value around which to scale for color scheme Z_EULER_SPEED */
#define SHIFT_DENSITY 1.1 /* shift for color scheme Z_EULER_DENSITY */
#define VSCALE_DENSITY 10.0 /* additional scaling factor for color scheme Z_EULER_DENSITY */
#define VSCALE_VORTICITY 10.0 /* additional scaling factor for color scheme Z_EULERC_VORTICITY */
#define VORTICITY_SHIFT 0.3 /* vertical shift of vorticity */
#define SHIFT_DENSITY 2.6 /* shift for color scheme Z_EULER_DENSITY */
#define VSCALE_DENSITY 7.5 /* additional scaling factor for color scheme Z_EULER_DENSITY */
#define VSCALE_VORTICITY 20.0 /* additional scaling factor for color scheme Z_EULERC_VORTICITY */
#define VORTICITY_SHIFT 0.0 /* vertical shift of vorticity */
#define ZSCALE_SPEED 1.0 /* additional scaling factor for z-coord Z_EULER_SPEED */
#define NXMAZE 13 /* width of maze */
@ -327,8 +317,8 @@
#define MAZE_WIDTH 0.03 /* half width of maze walls */
#define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */
#define COLORBAR_RANGE 2.0 /* scale of color scheme bar */
#define COLORBAR_RANGE_B 2.0 /* scale of color scheme bar for 2nd part */
#define COLORBAR_RANGE 2.5 /* scale of color scheme bar */
#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 */
/* only for compatibility with wave_common.c */
@ -382,7 +372,7 @@ int reset_view = 0; /* switch to reset 3D view parameters (for option RO
#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 PRINT_PARAMETERS ((PRINT_TIME)||(PRINT_VISCOSITY)||(PRINT_RPSLZB)||(PRINT_PROBABILITIES)||(PRINT_NOISE)||(PRINT_FLOW_SPEED))
#define PRINT_PARAMETERS ((PRINT_TIME)||(PRINT_VISCOSITY)||(PRINT_RPSLZB)||(PRINT_PROBABILITIES)||(PRINT_NOISE)||(PRINT_FLOW_SPEED)||(PRINT_AVERAGE_SPEED))
#define COMPUTE_PRESSURE ((ZPLOT == Z_EULER_PRESSURE)||(CPLOT == Z_EULER_PRESSURE)||(ZPLOT_B == Z_EULER_PRESSURE)||(CPLOT_B == Z_EULER_PRESSURE))
#define ASYM_SPEED_COLOR (VMEAN_SPEED == 0.0)
@ -609,7 +599,7 @@ void initialize_vector_potential(double vpotential_field[2*NX*NY])
}
}
void initialize_gfield(double gfield[2*NX*NY], double bc_field[NX*NY])
void initialize_gfield(double gfield[2*NX*NY], double bc_field[NX*NY], double bc_field2[NX*NY])
/* initialize the exterior field, e.g. for the compressible Euler equation */
{
int i, j;
@ -623,9 +613,9 @@ void initialize_gfield(double gfield[2*NX*NY], double bc_field[NX*NY])
#pragma omp parallel for private(i,j)
for (i=1; i<NX-1; i++){
for (j=1; j<NY-1; j++){
gfield[i*NY+j] = G_FIELD*(bc_field[(i+1)*NY+j] - bc_field[(i-1)*NY+j])/dx;
gfield[NX*NY+i*NY+j] = G_FIELD*(bc_field[i*NY+j+1] - bc_field[i*NY+j-1])/dy;
printf("gfield at (%i,%i): (%.3lg, %.3lg)\n", i, j, gfield[i*NY+j], gfield[NX*NY+i*NY+j]);
gfield[i*NY+j] = G_FIELD*(bc_field2[(i+1)*NY+j] - bc_field2[(i-1)*NY+j])/dx;
gfield[NX*NY+i*NY+j] = G_FIELD*(bc_field2[i*NY+j+1] - bc_field2[i*NY+j-1])/dy;
// printf("gfield at (%i,%i): (%.3lg, %.3lg)\n", i, j, gfield[i*NY+j], gfield[NX*NY+i*NY+j]);
}
}
@ -662,13 +652,13 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
double gfield[2*NX*NY], t_rde rde[NX*NY])
/* time step of field evolution */
{
int i, j, k, iplus, iminus, jplus, jminus, ropening;
int i, j, k, iplus, iminus, jplus, jminus, ropening, w;
double x, y, z, deltax, deltay, deltaz, rho, rhox, rhoy, pot, u, v, ux, uy, vx, vy, test = 0.0, dx, dy, xy[2], padding, a;
double *delta_phi[NLAPLACIANS], *nabla_phi, *nabla_psi, *nabla_omega, *delta_vorticity, *delta_pressure, *delta_p, *delta_u, *delta_v, *nabla_rho, *nabla_u, *nabla_v;
// double u_bc[NY], v_bc[NY];
static double invsqr3 = 0.577350269; /* 1/sqrt(3) */
static double stiffness = 2.0; /* stiffness of Poisson equation solver */
static int smooth = 0, y_channels, imin, imax, first = 1;
static int smooth = 0, y_channels, y_channels1, imin, imax, first = 1;
if (first) /* for D_MAZE_CHANNELS boundary conditions in Euler equation */
{
@ -678,7 +668,6 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
y = YMIN + 0.02 + dy*((double)ropening);
x = YMAX - padding + MAZE_XSHIFT;
xy_to_pos(x, y, xy);
y_channels = xy[1] - 5;
if ((B_DOMAIN == D_MAZE_CHANNELS)||(OBSTACLE_GEOMETRY == D_MAZE_CHANNELS))
{
imax = xy[0] + 2;
@ -687,15 +676,6 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
imin = xy[0] - 2;
if (imin < 5) imin = 5;
}
else if (OBSTACLE_GEOMETRY == D_TESLA)
{
imin = 0;
imax = NX;
y = -a;
xy_to_pos(XMIN, y, xy);
y_channels = xy[1];
printf("y_channels = %i\n", y_channels);
}
else
{
imin = 0;
@ -912,6 +892,11 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
phi_out[1][i*NY+j] += intstep*gfield[i*NY+j];
phi_out[2][i*NY+j] += intstep*gfield[NX*NY+i*NY+j];
}
if (ADD_CORIOLIS_FORCE)
{
phi_out[1][i*NY+j] += intstep*G_FIELD*v;
phi_out[2][i*NY+j] -= intstep*G_FIELD*u;
}
break;
}
}
@ -920,51 +905,15 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
/* in-flow/out-flow b.c. for incompressible Euler equation */
if (((RDE_EQUATION == E_EULER_INCOMP)||(RDE_EQUATION == E_EULER_COMP))&&(IN_OUT_FLOW_BC > 0))
{
switch (IN_OUT_FLOW_BC) {
case (BCE_LEFT):
{
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, 0.1, 1.0, 0.0, 0.1, phi_out, xy_in, 0, 5, 0, NY, IN_OUT_BC_FACTOR);
break;
}
case (BCE_TOPBOTTOM):
{
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, -0.1, 0.1, phi_out, xy_in, 0, NX, 0, 10, IN_OUT_BC_FACTOR);
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, -0.1, 0.1, phi_out, xy_in, 0, NX, NY-10, NY, IN_OUT_BC_FACTOR);
break;
}
case (BCE_TOPBOTTOMLEFT):
{
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, -0.1, 0.1, phi_out, xy_in, 0, NX, 0, 10, IN_OUT_BC_FACTOR);
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, -0.1, 0.1, phi_out, xy_in, 0, NX, NY-10, NY, IN_OUT_BC_FACTOR);
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, -0.1, 0.1, phi_out, xy_in, 0, 2, 0, NY, IN_OUT_BC_FACTOR);
break;
}
case (BCE_CHANNELS):
{
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, 0, imin+5, NY - y_channels, y_channels, IN_OUT_BC_FACTOR);
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, imax-5, NX - 1, NY- y_channels, y_channels, IN_OUT_BC_FACTOR);
// set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, imin-5, imin+10, NY - y_channels, y_channels);
// set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, imax-10, imax+5, NY- y_channels, y_channels);
break;
}
case (BCE_MIDDLE_STRIP):
{
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, 0, NX, NY/2 - 10, NY/2 + 10, IN_OUT_BC_FACTOR);
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, 0, 2, 0, NY, IN_OUT_BC_FACTOR);
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, LAMINAR_FLOW_YPERIOD, 1.0, 0.0, 0.1, phi_out, xy_in, NX-2, NX, 0, NY, IN_OUT_BC_FACTOR);
break;
}
}
}
set_in_out_flow_bc(phi_out, xy_in, flow_speed);
if (TEST_GRADIENT) {
// 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++){
for (j=0; j<NY; j++){
@ -992,8 +941,6 @@ void evolve_wave_half(double *phi_in[NFIELDS], double *phi_out[NFIELDS], short i
else if (RDE_EQUATION == E_EULER_COMP)
{
free(nabla_rho);
// free(nabla_u);
// free(nabla_v);
}
if (COMPUTE_PRESSURE)
@ -1096,10 +1043,10 @@ void print_level(int level)
void print_parameters(t_rde rde[NX*NY], short int xy_in[NX*NY], double time, short int left, double viscosity, double noise)
void print_parameters(double *phi[NFIELDS], t_rde rde[NX*NY], short int xy_in[NX*NY], double time, short int left, double viscosity, double noise)
{
char message[100];
double density, hue, rgb[3], logratio, x, y, pos[2], probas[2];
char message[100], message2[100];
double density, hue, rgb[3], logratio, x, y, pos[2], probas[2], speed1, speed2;
static double xbox, xtext, boxwidth, boxheight;
static int first = 1;
@ -1172,11 +1119,25 @@ void print_parameters(t_rde rde[NX*NY], short int xy_in[NX*NY], double time, sho
else if (PRINT_RPSLZB) sprintf(message, "b = %.3f", rpslzb);
else if (PRINT_NOISE) sprintf(message, "noise %.3f", noise);
else if (PRINT_FLOW_SPEED) sprintf(message, "Speed %.3f", flow_speed);
else if (PRINT_AVERAGE_SPEED)
{
compute_average_speeds(phi, rde, &speed1, &speed2);
sprintf(message, "Average vx %.3f", speed2);
sprintf(message2, "Average vx %.3f", speed1);
}
if (PLOT_3D) write_text(xtext, y, message);
else
{
xy_to_pos(xtext, y, pos);
write_text(pos[0], pos[1], message);
if (PRINT_AVERAGE_SPEED)
{
y = YMIN + 0.1;
erase_area_hsl(xbox, y + 0.02, boxwidth, boxheight, 0.0, 0.9, 0.0);
glColor3f(1.0, 1.0, 1.0);
xy_to_pos(xtext, y, pos);
write_text(pos[0], pos[1], message2);
}
}
}
}
@ -1278,7 +1239,7 @@ void animation()
{
double time = 0.0, scale, dx, var, jangle, cosj, sinj, sqrintstep,
intstep0, viscosity_printed, fade_value, noise = NOISE_INTENSITY;
double *phi[NFIELDS], *phi_tmp[NFIELDS], *potential_field, *vector_potential_field, *tracers, *gfield, *bc_field;
double *phi[NFIELDS], *phi_tmp[NFIELDS], *potential_field, *vector_potential_field, *tracers, *gfield, *bc_field, *bc_field2;
short int *xy_in;
int i, j, k, s, nvid, field;
static int counter = 0;
@ -1316,12 +1277,13 @@ void animation()
if (ADAPT_STATE_TO_BC)
{
bc_field = (double *)malloc(NX*NY*sizeof(double));
initialize_bcfield(bc_field, polyrect);
bc_field2 = (double *)malloc(NX*NY*sizeof(double));
initialize_bcfield(bc_field, bc_field2, polyrect);
}
if (ADD_FORCE_FIELD)
{
gfield = (double *)malloc(2*NX*NY*sizeof(double));
initialize_gfield(gfield, bc_field);
initialize_gfield(gfield, bc_field, bc_field2);
}
@ -1349,13 +1311,23 @@ void animation()
// 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_vortex_state(0.1, 0.4, 0.0, 0.3, -0.1, phi, xy_in);
// add_vortex_state(0.1, -0.4, 0.0, 0.3, 0.1, phi, xy_in);
// init_vortex_state(0.1, 0.4, 0.1, 0.3, -0.1, phi, xy_in);
// add_vortex_state(0.15, -0.4, -0.1, 0.4, 0.1, phi, xy_in);
// init_shear_flow(1.0, 0.02, 0.15, 1, 1, phi, xy_in);
// init_laminar_flow(flow_speed_schedule(0), LAMINAR_FLOW_MODULATION, LAMINAR_FLOW_YPERIOD, 0.0, phi, xy_in);
// init_laminar_flow(IN_OUT_FLOW_AMP, LAMINAR_FLOW_MODULATION, 0.02, 0.1, 1.0, 0.0, 0.1, phi, xy_in);
init_laminar_flow(flow_speed_schedule(0), LAMINAR_FLOW_MODULATION, 0.02, 0.1, 1.0, 0.0, 0.1, phi, xy_in);
init_laminar_flow(0.05, LAMINAR_FLOW_MODULATION, 0.015, 0.1, 1.0, 0.0, 0.1, phi, xy_in);
// add_vortex_state(0.2, -0.4, -0.1, 0.3, -2.0, phi, xy_in);
// add_vortex_state(0.2, -1.0, -0.1, 0.3, -0.5, phi, xy_in);
// init_vortex_state(0.1, 1.0, 0.1, 0.3, -0.4, phi, xy_in);
// add_vortex_state(0.15, -1.0, -0.1, 0.4, 0.5, phi, xy_in);
add_vortex_state(0.2, 0.75, 0.1, 0.3, -0.5, phi, xy_in);
add_vortex_state(-0.35, -0.75, -0.1, 0.4, 0.5, phi, xy_in);
add_vortex_state(0.1, -0.3, 0.7, 0.1, -0.5, phi, xy_in);
// init_pressure_gradient_flow(flow_speed_schedule(0), 1.0 + PRESSURE_GRADIENT, 1.0 - PRESSURE_GRADIENT, phi, xy_in, bc_field);
// init_shear_flow(-1.0, 0.1, 0.2, 1, 1, 0.2, phi, xy_in);
// init_shear_flow(1.0, 0.02, 0.15, 1, 1, 0.0, phi, xy_in);
@ -1386,7 +1358,7 @@ void animation()
printf("Drawing wave\n");
draw_wave_rde(0, phi, xy_in, rde, potential_field, ZPLOT, CPLOT, COLOR_PALETTE, 0, 1.0, 1);
// draw_billiard();
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, VISCOSITY, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, VISCOSITY, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT, COLORBAR_RANGE, COLOR_PALETTE, 0, 1.0);
@ -1487,7 +1459,7 @@ void animation()
time += nvid*intstep;
// draw_billiard();
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, viscosity_printed, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT, COLORBAR_RANGE, COLOR_PALETTE, 0, 1.0);
// print_level(MDEPTH);
@ -1513,7 +1485,7 @@ void animation()
draw_wave_rde(1, phi, xy_in, rde, potential_field, ZPLOT_B, CPLOT_B, COLOR_PALETTE_B, 0, 1.0, REFRESH_B);
if (ADD_TRACERS) draw_tracers(phi, tracers, i, 0, 1.0);
// draw_billiard();
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, viscosity_printed, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT_B, COLORBAR_RANGE_B, COLOR_PALETTE_B, 0, 1.0);
glutSwapBuffers();
// if (NO_EXTRA_BUFFER_SWAP) glutSwapBuffers();
@ -1545,7 +1517,7 @@ void animation()
draw_wave_rde(0, phi, xy_in, rde, potential_field, ZPLOT, CPLOT, COLOR_PALETTE, 0, 1.0, 1);
if (ADD_TRACERS) draw_tracers(phi, tracers, NSTEPS, 0, 1.0);
// draw_billiard();
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, viscosity_printed, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT, COLORBAR_RANGE, COLOR_PALETTE, 0, 1.0);
// if (!NO_EXTRA_BUFFER_SWAP) glutSwapBuffers();
glutSwapBuffers();
@ -1557,14 +1529,14 @@ void animation()
draw_wave_rde(0, phi, xy_in, rde, potential_field, ZPLOT, CPLOT, COLOR_PALETTE, 1, fade_value, 0);
if (ADD_TRACERS) draw_tracers(phi, tracers, NSTEPS, 1, fade_value);
// draw_billiard();
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, viscosity_printed, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT, COLORBAR_RANGE, COLOR_PALETTE, 1, fade_value);
if (!NO_EXTRA_BUFFER_SWAP) glutSwapBuffers();
save_frame_counter(NSTEPS + i + 1);
}
draw_wave_rde(1, phi, xy_in, rde, potential_field, ZPLOT_B, CPLOT_B, COLOR_PALETTE_B, 0, 1.0, REFRESH_B);
if (ADD_TRACERS) draw_tracers(phi, tracers, NSTEPS, 0, 1.0);
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, viscosity_printed, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT_B, COLORBAR_RANGE_B, COLOR_PALETTE_B, 0, 1.0);
glutSwapBuffers();
@ -1574,7 +1546,7 @@ void animation()
fade_value = 1.0 - (double)i/(double)END_FRAMES;
draw_wave_rde(1, phi, xy_in, rde, potential_field, ZPLOT_B, CPLOT_B, COLOR_PALETTE_B, 1, fade_value, 0);
if (ADD_TRACERS) draw_tracers(phi, tracers, NSTEPS, 1, fade_value);
if (PRINT_PARAMETERS) print_parameters(rde, xy_in, time, 0, viscosity_printed, noise);
if (PRINT_PARAMETERS) print_parameters(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(CPLOT_B, COLORBAR_RANGE_B, COLOR_PALETTE_B, 1, fade_value);
glutSwapBuffers();
save_frame_counter(NSTEPS + MID_FRAMES + 1 + counter + i);
@ -1611,7 +1583,11 @@ void animation()
}
if (ADD_TRACERS) free(tracers);
if (ADD_FORCE_FIELD) free(gfield);
if (ADAPT_STATE_TO_BC) free(bc_field);
if (ADAPT_STATE_TO_BC)
{
free(bc_field);
free(bc_field2);
}
printf("Time %.5lg\n", time);

View File

@ -459,12 +459,14 @@ int wrap_particle(t_particle* particle, double *px, double *py)
x1 += BCXMAX - BCXMIN;
y1 = -y1;
*py *= -1.0;
particle->angle = DPI - particle->angle;
move++;
}
else if (x > BCXMAX)
{
x1 += BCXMIN - BCXMAX;
y1 = -y1;
particle->angle = DPI - particle->angle;
*py *= -1.0;
move++;
}

228
sub_lj.c
View File

@ -511,6 +511,24 @@ void set_type_color(int type, double lum, double rgb[3])
glColor3f(lum*rgb[0], lum*rgb[1], lum*rgb[2]);
}
double distance_to_segment(double x, double y, double x1, double y1, double x2, double y2)
/* distance of (x,y) to segment from (x1,y1) to (x2,y2) */
{
double xp, yp, angle, length, ca, sa;
angle = argument(x2 - x1, y2 - y1);
length = module2(x2 - x1, y2 - y1);
ca = cos(angle);
sa = sin(angle);
xp = ca*(x - x1) + sa*(y - y1);
yp = -sa*(x - x1) + ca*(y - y1);
if ((xp >= 0)&&(xp <= length)) return(vabs(yp));
else if (xp < 0) return(module2(xp, yp));
else return(module2(xp-length, yp));
}
void init_particle_config(t_particle particles[NMAXCIRCLES])
@ -1207,7 +1225,7 @@ void add_rocket_to_segments(t_segment segment[NMAXSEGMENTS], double x0, double y
case (RCK_RECT_HAT): /* rectangular chamber with a hat */
{
a = 0.5*LAMBDA;
b = 0.49*PI*LAMBDA;
b = (0.49*PI-0.25)*LAMBDA;
add_rotated_angle_to_segments(x0+nozx, nozy, x0+a, nozy, 0.02, segment, 0);
add_rotated_angle_to_segments(x0+a, nozy, x0+a, nozy+b, 0.02, segment, 0);
add_rotated_angle_to_segments(x0+a, nozy+b, x0, nozy+b+a, 0.02, segment, 0);
@ -1262,7 +1280,7 @@ int init_maze_segments(t_segment segment[NMAXSEGMENTS])
{
t_maze* maze;
int i, j, n;
double x1, y1, x2, y2, dx, dy, padding = 0.02, width = 0.01;
double x1, y1, x2, y2, dx, dy, padding = 0.02, width = MAZE_WIDTH;
maze = (t_maze *)malloc(NXMAZE*NYMAZE*sizeof(t_maze));
@ -2085,7 +2103,8 @@ int in_rocket(double x, double y, int rocket_shape)
{
l = 0.7*LAMBDA;
y1 = y - YMIN - 1.7*LAMBDA;
return ((x*x + y1*y1)/(l*l) + MU*MU < 0.925);
return ((x*x + y1*y1)/(l*l) + MU*MU < 0.875);
// return ((x*x + y1*y1)/(l*l) + MU*MU < 0.925*LAMBDA*LAMBDA);
}
case (RCK_RECT) :
{
@ -2096,20 +2115,23 @@ int in_rocket(double x, double y, int rocket_shape)
}
case (RCK_RECT_HAT) :
{
// printf("(%.2lg,%.2lg) in rocket?\n", x, y);
a = 0.5*LAMBDA;
b = 0.49*PI*LAMBDA;
b = (0.49*PI-0.25)*LAMBDA;
y1 = y - YMIN - LAMBDA;
if (vabs(x) > 0.95*a) return(0);
if (y1 < 0.05) return(0);
if (y1 < b - 0.05) return(1);
return(y1 < a + b - 0.05 - vabs(x));
// return(1);
}
}
}
int in_segment_region(double x, double y)
int in_segment_region(double x, double y, t_segment segment[NMAXSEGMENTS])
/* returns 1 if (x,y) is inside region delimited by obstacle segments */
{
int i;
double angle, dx, height, width, theta, lx, ly, x1, y1, x2, y2, padding;
if (x >= BCXMAX) return(0);
@ -2231,8 +2253,8 @@ int in_segment_region(double x, double y)
else if ((y1 > YMIN + 3.5*LAMBDA)&&(y2 > YMIN + 3.5*LAMBDA)) return(0);
else
{
if (in_rocket(x - xsegments[0], y1, ROCKET_SHAPE)) return(1);
if (in_rocket(x - xsegments[1], y2, ROCKET_SHAPE_B)) return(1);
if (in_rocket(x - xsegments[0], y1, ROCKET_SHAPE_B)) return(1);
if (in_rocket(x - xsegments[1], y2, ROCKET_SHAPE)) return(1);
}
return(0);
}
@ -2263,6 +2285,14 @@ int in_segment_region(double x, double y)
if ((y > 1.0 - LAMBDA + padding)&&(vabs(x) < LAMBDA - padding)) return(1);
return(0);
}
case (S_MAZE):
{
for (i=0; i<nsegments; i++)
{
if (distance_to_segment(x, y, segment[i].x1, segment[i].y1, segment[i].x2, segment[i].y2) < 5.0*MAZE_WIDTH) return(0);
}
return(1);
}
default: return(1);
}
}
@ -2409,6 +2439,45 @@ double lennard_jones_force(double r, t_particle particle)
}
}
double harmonic_force(double r, t_particle particle)
{
int i;
double rmin = 0.01, rplus, ratio = 1.0;
if (r > REPEL_RADIUS*particle.radius) return(0.0);
else
{
// if (r > rmin) rplus = r;
// else rplus = rmin;
// ratio = rplus/particle.eq_dist*particle.radius;
ratio = r/particle.eq_dist*particle.radius;
if (ratio < 1.0) return(ratio - 1.0);
else return(0.0);
}
}
double coulomb_force(double r, t_particle particle)
{
int i;
double rmin = 0.01, rplus, ratio = 1.0;
if (r > REPEL_RADIUS*particle.radius) return(0.0);
else
{
// if (r > rmin) rplus = r;
// else rplus = rmin;
// ratio = rplus/particle.eq_dist*particle.radius;
ratio = r/particle.eq_dist*particle.radius;
return(-1.0/(ratio*ratio + rmin*rmin));
// if (ratio < 1.0) return(ratio - 1.0);
// else return(0.0);
}
}
void aniso_lj_force(double r, double ca, double sa, double ca_rel, double sa_rel, double force[2], t_particle particle)
{
int i;
@ -2844,7 +2913,7 @@ int compute_particle_interaction(int i, int k, double force[2], double *torque,
{
double x1, y1, x2, y2, r, f, angle, aniso, fx, fy, ff[2], dist_scaled, spin_f, ck, sk, ck_rel, sk_rel;
static double dxhalf = 0.5*(BCXMAX - BCXMIN), dyhalf = 0.5*(BCYMAX - BCYMIN);
int wwrapx, wwrapy;
int wwrapx, wwrapy, twrapx, twrapy;
if (BOUNDARY_COND == BC_GENUS_TWO)
{
@ -2859,6 +2928,8 @@ int compute_particle_interaction(int i, int k, double force[2], double *torque,
wwrapx = ((BOUNDARY_COND == BC_KLEIN)||(BOUNDARY_COND == BC_BOY)||(BOUNDARY_COND == BC_GENUS_TWO))&&(vabs(x2 - x1) > dxhalf);
wwrapy = ((BOUNDARY_COND == BC_BOY)||(BOUNDARY_COND == BC_GENUS_TWO))&&(vabs(y2 - y1) > dyhalf);
twrapx = ((BOUNDARY_COND == BC_KLEIN)||(BOUNDARY_COND == BC_BOY))&&(vabs(x2 - x1) > dxhalf);
twrapy = (BOUNDARY_COND == BC_BOY)&&(vabs(y2 - y1) > dyhalf);
switch (particle[k].interaction) {
case (I_COULOMB):
@ -2917,6 +2988,28 @@ int compute_particle_interaction(int i, int k, double force[2], double *torque,
force[1] = f*sa;
break;
}
case (I_VICSEK):
{
force[0] = 0.0;
force[1] = 0.0;
break;
}
case (I_VICSEK_REPULSIVE):
{
f = krepel*coulomb_force(distance, particle[k]);
// f = krepel*harmonic_force(distance, particle[k]);
// f = krepel*lennard_jones_force(distance, particle[k]);
force[0] = f*ca;
force[1] = f*sa;
break;
}
case (I_VICSEK_SPEED):
{
f = cos(0.5*(particle[k].angle - particle[i].angle));
force[0] = f*KSPRING_VICSEK*(particle[k].vx - particle[i].vx);
force[1] = f*KSPRING_VICSEK*(particle[k].vy - particle[i].vy);
break;
}
}
if (ROTATION)
@ -2939,10 +3032,31 @@ int compute_particle_interaction(int i, int k, double force[2], double *torque,
// printf("force = (%.3lg, %.3lg)\n", ff[0], ff[1]);
break;
}
case (I_VICSEK):
{
if (dist_scaled > 1.0) *torque = 0.0;
else if (twrapx||twrapy) *torque = sin(-particle[k].angle - particle[i].angle);
else *torque = sin(particle[k].angle - particle[i].angle);
break;
}
case (I_VICSEK_REPULSIVE):
{
if (dist_scaled > 1.0) *torque = 0.0;
else if (twrapx||twrapy) *torque = sin(-particle[k].angle - particle[i].angle);
else *torque = sin(particle[k].angle - particle[i].angle);
break;
}
case (I_VICSEK_SPEED):
{
if (dist_scaled > 1.0) *torque = 0.0;
else if (twrapx||twrapy) *torque = sin(-particle[k].angle - particle[i].angle);
else *torque = sin(particle[k].angle - particle[i].angle);
break;
}
default:
{
spin_f = particle[i].spin_freq;
if (wwrapx||wwrapy) *torque = sin(spin_f*(-particle[k].angle - particle[i].angle))/(1.0e-8 + dist_scaled*dist_scaled);
if (twrapx||twrapy) *torque = sin(spin_f*(-particle[k].angle - particle[i].angle))/(1.0e-8 + dist_scaled*dist_scaled);
else
*torque = sin(spin_f*(particle[k].angle - particle[i].angle))/(1.0e-8 + dist_scaled*dist_scaled);
}
@ -3897,7 +4011,7 @@ void draw_one_particle(t_particle particle, double xc, double yc, double radius,
/* specific shapes for chemical reactions */
if (REACTION_DIFFUSION) cont = draw_special_particle(particle, xc1, yc1, radius, angle, nsides, rgb, 1);
if ((particle.interaction == I_LJ_QUADRUPOLE)||(particle.interaction == I_LJ_DIPOLE))
if ((particle.interaction == I_LJ_QUADRUPOLE)||(particle.interaction == I_LJ_DIPOLE)||(particle.interaction == I_VICSEK)||(particle.interaction == I_VICSEK_REPULSIVE)||(particle.interaction == I_VICSEK_SPEED))
draw_colored_rhombus(xc1, yc1, radius, angle + APOLY*PID, rgb);
else if (cont) draw_colored_polygon(xc1, yc1, radius, nsides, angle + APOLY*PID, rgb);
@ -3927,7 +4041,7 @@ void draw_one_particle(t_particle particle, double xc, double yc, double radius,
glColor3f(1.0, 1.0, 1.0);
if (REACTION_DIFFUSION) cont = draw_special_particle(particle, xc1, yc1, radius, angle, nsides, rgb, 0);
if ((particle.interaction == I_LJ_QUADRUPOLE)||(particle.interaction == I_LJ_DIPOLE))
if ((particle.interaction == I_LJ_QUADRUPOLE)||(particle.interaction == I_LJ_DIPOLE)||(particle.interaction == I_VICSEK)||(particle.interaction == I_VICSEK_REPULSIVE)||(particle.interaction == I_VICSEK_SPEED))
draw_rhombus(xc1, yc1, radius, angle + APOLY*PID);
else if (cont) draw_polygon(xc1, yc1, radius, nsides, angle + APOLY*PID);
@ -3946,14 +4060,28 @@ void draw_collisions(t_collision *collisions, int ncollisions)
/* draw discs where collisions happen */
{
int i, j;
double rgb[3], lum;
double rgb[3], lum, x, y, x1, y1;
for (i=0; i<ncollisions; i++) if (collisions[i].time > 0)
{
lum = (double)collisions[i].time/(double)COLLISION_TIME;
if (collisions[i].color == 0.0) for (j=0; j<3; j++) rgb[j] = lum;
else hsl_to_rgb_palette(collisions[i].color, 0.9, lum, rgb, COLOR_PALETTE);
draw_colored_polygon(collisions[i].x, collisions[i].y, 5.0*MU, NSEG, 0.0, rgb);
x = collisions[i].x;
y = collisions[i].y;
if (CENTER_VIEW_ON_OBSTACLE) x1 = x - xshift;
else x1 = x;
if (TRACK_SEGMENT_GROUPS)
{
x1 -= xtrack;
y1 = y - ytrack;
}
else y1 = y;
draw_colored_polygon(x1, y1, 5.0*MU, NSEG, 0.0, rgb);
collisions[i].time--;
}
@ -4939,8 +5067,16 @@ void print_segment_group_speeds(t_group_segments *segment_group)
av_vy *= inv_t_window;
av_omega *= inv_t_window;
xbox = xleftbox + (xrightbox - xleftbox)*(group-1)/(ngroups-2);
xtext = xlefttext + (xrighttext - xlefttext)*(group-1)/(ngroups-2);
if (ngroups > 2)
{
xbox = xleftbox + (xrightbox - xleftbox)*(group-1)/(ngroups-2);
xtext = xlefttext + (xrighttext - xlefttext)*(group-1)/(ngroups-2);
}
else
{
xbox = xrightbox - 0.2;
xtext = xrighttext - 0.2;
}
// printf("xbox = %.2f, xtext = %.2f, av_vy = %.2f\n", xbox, xtext, av_vy);
@ -5013,8 +5149,7 @@ double compute_boundary_force(int j, t_particle particle[NMAXCIRCLES], t_obstacl
double xleft, double xright, double *pleft, double *pright, double pressure[N_PRESSURES], int wall)
{
int i, k;
double xmin, xmax, ymin, ymax, padding, r, rp, r2, cphi, sphi, f, fperp = 0.0, x, y, xtube, distance, dx, dy,
width, ybin, angle, x1, x2, h, ytop, norm, dleft, dplus, dminus, tmp_pleft = 0.0, tmp_pright = 0.0, proj;
double xmin, xmax, ymin, ymax, padding, r, rp, r2, cphi, sphi, f, fperp = 0.0, x, y, xtube, distance, dx, dy, width, ybin, angle, x1, x2, h, ytop, norm, dleft, dplus, dminus, tmp_pleft = 0.0, tmp_pright = 0.0, proj, pscal, pvect, pvmin;
/* compute force from fixed circular obstacles */
if (ADD_FIXED_OBSTACLES) for (i=0; i<nobstacles; i++)
@ -5035,6 +5170,7 @@ double compute_boundary_force(int j, t_particle particle[NMAXCIRCLES], t_obstacl
}
}
/* compute force from fixed linear obstacles */
particle[j].close_to_boundary = 0;
if (ADD_FIXED_SEGMENTS) for (i=0; i<nsegments; i++) if (segment[i].active)
{
x = particle[j].xc;
@ -5042,13 +5178,19 @@ double compute_boundary_force(int j, t_particle particle[NMAXCIRCLES], t_obstacl
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;
distance = segment[i].nx*x + segment[i].ny*y - segment[i].c;
r = 1.5*particle[j].radius;
if (vabs(distance) < r)
{
particle[j].close_to_boundary = 1;
f = KSPRING_OBSTACLE*(r - distance);
particle[j].fx += f*segment[i].nx;
particle[j].fy += f*segment[i].ny;
if ((MOVE_BOUNDARY)||(MOVE_SEGMENT_GROUPS))
{
segment[i].fx -= f*segment[i].nx;
@ -5056,6 +5198,15 @@ double compute_boundary_force(int j, t_particle particle[NMAXCIRCLES], t_obstacl
segment[i].torque -= (x - segment[i].xc)*f*segment[i].ny - (y - segment[i].yc)*f*segment[i].nx;
}
}
if ((VICSEK_INT)&&(vabs(distance) < 1.5*r))
{
pvmin = 2.0;
pvect = cos(particle[j].angle)*segment[i].ny - sin(particle[j].angle)*segment[i].nx;
if ((pvect > 0.0)&&(pvect < pvmin)) pvect = pvmin;
else if ((pvect < 0.0)&&(pvect > -pvmin)) pvect = -pvmin;
// particle[j].torque += KTORQUE_BOUNDARY*pvect;
particle[j].torque += KTORQUE_BOUNDARY*pvect*(1.5*r - vabs(distance));
}
}
/* compute force from concave corners */
@ -5531,7 +5682,7 @@ void compute_particle_force(int j, double krepel, t_particle particle[NMAXCIRCLE
int reorder_particles(t_particle particle[NMAXCIRCLES], double py[NMAXCIRCLES], double pangle[NMAXCIRCLES])
/* keep only active particles */
/* keep only active particles, beta */
{
int i, k, new = 0, nactive = 0;
@ -5580,7 +5731,8 @@ int reorder_particles(t_particle particle[NMAXCIRCLES], double py[NMAXCIRCLES],
int initialize_configuration(t_particle particle[NMAXCIRCLES], t_hashgrid hashgrid[HASHX*HASHY],
t_obstacle obstacle[NMAXOBSTACLES], double px[NMAXCIRCLES], double py[NMAXCIRCLES], double pangle[NMAXCIRCLES], int tracer_n[N_TRACER_PARTICLES])
t_obstacle obstacle[NMAXOBSTACLES], double px[NMAXCIRCLES], double py[NMAXCIRCLES], double pangle[NMAXCIRCLES], int tracer_n[N_TRACER_PARTICLES],
t_segment segment[NMAXSEGMENTS])
/* initialize all particles, obstacles, and the hashgrid */
{
int i, j, k, n, nactive = 0;
@ -5599,6 +5751,7 @@ int initialize_configuration(t_particle particle[NMAXCIRCLES], t_hashgrid hashgr
particle[i].neighb = 0;
particle[i].diff_neighb = 0;
particle[i].thermostat = 1;
particle[i].close_to_boundary = 0;
// particle[i].energy = 0.0;
// y = particle[i].yc;
@ -5671,6 +5824,7 @@ int initialize_configuration(t_particle particle[NMAXCIRCLES], t_hashgrid hashgr
particle[i].eq_dist = EQUILIBRIUM_DIST;
particle[i].spin_range = SPIN_RANGE;
particle[i].spin_freq = SPIN_INTER_FREQUENCY;
particle[i].close_to_boundary = 0;
}
/* add particles at the bottom as seed */
@ -5803,7 +5957,7 @@ int initialize_configuration(t_particle particle[NMAXCIRCLES], t_hashgrid hashgr
/* case of segment obstacles */
if (ADD_FIXED_SEGMENTS) for (i=0; i< ncircles; i++)
if (!in_segment_region(particle[i].xc, particle[i].yc))
if (!in_segment_region(particle[i].xc, particle[i].yc, segment))
particle[i].active = 0;
/* case of reaction-diffusion equation/chemical reactions */
@ -5910,6 +6064,27 @@ int initialize_configuration(t_particle particle[NMAXCIRCLES], t_hashgrid hashgr
}
break;
}
case (IC_SIGNX):
{
if (particle[i].xc < 0.0) particle[i].type = 1;
else
{
particle[i].type = 2;
particle[i].radius = MU_B;
particle[i].mass_inv = 1.0/PARTICLE_MASS_B;
}
break;
}case (IC_TWOROCKETS):
{
if (vabs(particle[i].xc) < SEGMENTS_X0) particle[i].type = 1;
else
{
particle[i].type = 2;
particle[i].radius = MU_B;
particle[i].mass_inv = 1.0/PARTICLE_MASS_B;
}
break;
}
}
}
@ -6012,7 +6187,7 @@ int floor_momentum(double p[NMAXCIRCLES])
return (floor);
}
int partial_thermostat_coupling(t_particle particle[NMAXCIRCLES], double xmin)
int partial_thermostat_coupling(t_particle particle[NMAXCIRCLES], double xmin, t_segment segment[NMAXSEGMENTS])
/* only couple particles satisfying condition PARTIAL_THERMO_REGION to thermostat */
{
int condition, i, nthermo = 0;
@ -6049,7 +6224,7 @@ int partial_thermostat_coupling(t_particle particle[NMAXCIRCLES], double xmin)
}
case (TH_INSEGMENT):
{
condition = (in_segment_region(particle[i].xc, particle[i].yc));
condition = (in_segment_region(particle[i].xc, particle[i].yc, segment));
// condition = (in_segment_region(particle[i].xc - xsegments[0], particle[i].yc - ysegments[0]));
// // condition = (in_segment_region(particle[i].xc - xsegments[0], particle[i].yc - ysegments[0]));
// if (TWO_OBSTACLES)
@ -6776,7 +6951,7 @@ int chem_catalytic_convert(int i, int type2, int newtype, t_particle particle[NM
int update_types(t_particle particle[NMAXCIRCLES], t_collision *collisions, int ncollisions, int *particle_numbers, int time, double *delta_e)
/* update the types in case of reaction-diffusion equation */
{
int i, j, k, n, n3, n4, type, oldncollisions;
int i, j, k, n, n3, n4, type, oldncollisions, delta_n;
double distance, rnd, p1, p2;
static double inv_masses[RD_TYPES+1], radii[RD_TYPES+1];
static int first = 1;
@ -6819,7 +6994,10 @@ int update_types(t_particle particle[NMAXCIRCLES], t_collision *collisions, int
for (i=0; i<ncircles; i++) if ((particle[i].active)&&(particle[i].type == 1))
ncollisions = chem_merge(i, 2, 3, particle, collisions, ncollisions, inv_masses, radii);
printf("%i collisions\n", ncollisions);
if (EXOTHERMIC) *delta_e = (double)(ncollisions - oldncollisions)*DELTA_EKIN;
delta_n = ncollisions - oldncollisions;
printf("delta_n = %i\n", delta_n);
// if (delta_n > 1) delta_n = 1;
if (EXOTHERMIC) *delta_e = (double)(delta_n)*DELTA_EKIN;
return(ncollisions);
}
case (CHEM_A2BC):
@ -7223,6 +7401,8 @@ void draw_trajectory_plot(t_group_data *group_speeds, int i)
glLineWidth(2);
printf("ngroups = %i\n", ngroups);
/* plot trajectories */
for (group=1; group<ngroups; group++)
{

292
sub_rde.c
View File

@ -441,8 +441,8 @@ void add_vortex_state(double amp, double x, double y, double scale, double densi
// phi[0][i*NY+j] = 1.0;
/* nonconstant density to make things more interesting */
phi[0][i*NY+j] += 0.5 + density_mod*sign*module/amp;
phi[1][i*NY+j] += sign*module*(xy[1]-y)/vabs(scale);
phi[2][i*NY+j] -= sign*module*(xy[0]-x)/vabs(scale);
phi[1][i*NY+j] -= sign*module*(xy[1]-y)/vabs(scale);
phi[2][i*NY+j] += sign*module*(xy[0]-x)/vabs(scale);
}
else
{
@ -511,7 +511,7 @@ void init_shear_flow(double amp, double delta, double rho, int nx, int ny, doubl
}
void set_boundary_laminar_flow(double amp, double xmodulation, double ymodulation, double xperiod, double yperiod, double yshift, double density_mod, double *phi[NFIELDS], short int xy_in[NX*NY], int imin, int imax, int jmin, int jmax, double factor)
/* enfoce laminar flow in x direction on top and bottom boundaries */
/* enforce laminar flow in x direction in specified region */
/* phi[0] is stream function, phi[1] is vorticity */
/* amp is global amplitude */
{
@ -631,6 +631,74 @@ void init_laminar_flow(double amp, double xmodulation, double ymodulation, doubl
}
}
void set_boundary_pressure_gradient_flow(double vx, double pmax, double pmin, double *phi[NFIELDS], short int xy_in[NX*NY], int imin, int imax, int jmin, int jmax, double factor)
/* enforce laminar flow in x direction in specified region */
/* pressure/density interpolates between maxamp and minamp */
{
int i, j;
double xy[2], a, comp_factor, cutoff;
comp_factor = 1.0 - factor;
a = (pmax - pmin)/(XMAX - XMIN);
for (i=imin; i<imax; i++)
for (j=jmin; j<jmax; j++)
{
ij_to_xy(i, j, xy);
xy_in[i*NY+j] = xy_in_billiard(xy[0],xy[1]);
if (xy[0] < 0.0) cutoff = tanh(20.0*(xy[0] - XMIN));
else cutoff = tanh(10.0*(XMAX - xy[0]));
if (xy_in[i*NY+j])
{
phi[0][i*NY+j] *= 1.0 - cutoff*factor;
phi[1][i*NY+j] *= 1.0 - cutoff*factor;
phi[2][i*NY+j] *= 1.0 - cutoff*factor;
phi[0][i*NY+j] += cutoff*factor*(pmax - a*(xy[0] - XMIN));
phi[1][i*NY+j] += cutoff*factor*vx;
}
else
{
phi[0][i*NY+j] = 1.0;
phi[1][i*NY+j] = 0.0;
phi[2][i*NY+j] = 0.0;
}
}
}
void init_pressure_gradient_flow(double vx, double pmax, double pmin, double *phi[NFIELDS], short int xy_in[NX*NY], double bc_field[NX*NY])
/* initialise field with a laminar flow in x direction */
/* pressure/density interpolates between maxamp and minamp */
{
int i, j;
double xy[2], a;
a = (pmax - pmin)/(XMAX - XMIN);
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])
{
// phi[0][i*NY+j] = pmax - a*(xy[0] - XMIN);
phi[0][i*NY+j] = (pmax - a*(xy[0] - XMIN))*bc_field[i*NY+j] + pmax*(1.0 - bc_field[i*NY+j]);
phi[1][i*NY+j] = vx;
phi[2][i*NY+j] = 0.0;
}
else
{
phi[0][i*NY+j] = 1.0;
phi[1][i*NY+j] = 0.0;
phi[2][i*NY+j] = 0.0;
}
}
}
double distance_to_segment(double x, double y, double x1, double y1, double x2, double y2)
/* distance of (x,y) to segment from (x1,y1) to (x2,y2) */
{
@ -705,10 +773,10 @@ double tesla_distance(double x, double y, double a, double l, double theta)
return(dmin);
}
void initialize_bcfield(double bc_field[NX*NY], t_rectangle polyrect[NMAXPOLY])
void initialize_bcfield(double bc_field[NX*NY], double bc_field2[NX*NY], t_rectangle polyrect[NMAXPOLY])
/* apply smooth modulation to adapt initial state to obstacles */
{
int i, j, nsides, s;
int i, j, nsides, s, i1, j1, shiftx;
double xy[2], x, y, r, f, a, l, theta, x1, x2, y1, y2, distance, d, d0, length, height, mid, fmin, ct, st;
switch (OBSTACLE_GEOMETRY) {
@ -817,6 +885,63 @@ void initialize_bcfield(double bc_field[NX*NY], t_rectangle polyrect[NMAXPOLY])
f = 0.5*(1.0 + tanh(BC_STIFFNESS*r));
bc_field[i*NY+j] = f;
bc_field2[i*NY+j] = f;
}
break;
}
case (D_TESLA_FOUR):
{
a = 0.16;
l = 1.7;
shiftx = NX/50;
theta = PID/5.0;
ct = cos(theta);
st = sin(theta);
for (i=0; i<NX; i++)
for (j=0; j<NY; j++)
{
i1 = i - shiftx;
i1 *= 2;
j1 = j;
if (j1 > NY/2) j1 -= NY/2;
j1 *= 2;
ij_to_xy(i1, j1, xy);
xy[1] -= 1.5*a;
if (j > NY/2)
{
xy[0] *= -1.0;
xy[0] += 2.0*l*ct;
}
d0 = tesla_distance(xy[0] +l*ct, xy[1], a, l, theta);
d = tesla_distance(xy[0], -l*st-xy[1]-0.5*a, a, l, theta);
if (d < d0) d0 = d;
d = tesla_distance(xy[0] - l*ct -0.2*a, xy[1], a, l, theta);
if (d < d0) d0 = d;
d = tesla_distance(xy[0] - 2.0*l*ct -0.2*a, -l*st-xy[1]-0.5*a, a, l, theta);
if (d < d0) d0 = d;
if ((xy[0] < -l*ct)||(xy[0] > 3*l*ct))
{
d = vabs(xy[1]);
if (d < d0) d0 = d;
}
r = a - d0;
f = 0.5*(1.0 + tanh(BC_STIFFNESS*r));
bc_field[i*NY+j] = f;
r = 0.9*a - d0;
f = 0.5*(1.0 + tanh(0.5*BC_STIFFNESS*r));
bc_field2[i*NY+j] = f;
}
break;
}
@ -886,6 +1011,9 @@ void initialize_bcfield(double bc_field[NX*NY], t_rectangle polyrect[NMAXPOLY])
if (distance < d0) f = fmin*distance/d0;
else f = 0.5*(1.0 + tanh(BC_STIFFNESS*(distance - 1.25*MAZE_WIDTH)));
bc_field[i*NY+j] = f;
if (distance >= d0) f = 0.5*(1.0 + tanh(BC_STIFFNESS*(distance - 1.5*MAZE_WIDTH)));
bc_field2[i*NY+j] = f;
// printf("distance = %.5lg, bcfield = %.5lg\n", distance, f);
}
}
@ -897,12 +1025,15 @@ void adapt_state_to_bc(double *phi[NFIELDS], double bc_field[NX*NY], short int x
/* apply smooth modulation to adapt initial state to obstacles */
{
int i, j, field;
double xy[2], r, f;
double xy[2], r, f;
// double ratio = 1.0e-1;
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++)
for (j=0; j<NY; j++) if (xy_in[i*NY+j])
{
// phi[0][i*NY+j] = 1.3 - bc_field[i*NY+j] + bc_field[i*NY+j]*phi[0][i*NY+j];
// phi[0][i*NY+j] = (1.0 - bc_field[i*NY+j]) + bc_field[i*NY+j]*phi[0][i*NY+j];
for (field = 1; field < NFIELDS; field++)
phi[field][i*NY+j] *= bc_field[i*NY+j];
}
@ -1537,7 +1668,7 @@ void compute_direction(double *phi[NFIELDS], t_rde rde[NX*NY])
}
void compute_vorticity(t_rde rde[NX*NY])
/* compute the log of a field */
/* compute the vorticity of a field */
{
int i, j;
double value;
@ -2837,3 +2968,150 @@ void draw_tracers(double *phi[NFIELDS], double tracers[2*N_TRACERS*NSTEPS], int
}
}
void compute_average_speeds(double *phi[NFIELDS], t_rde rde[NX*NY], double *speed1, double *speed2)
{
int i, j;
double sp1, sp2;
static double ratio;
static int first = 1;
if (first)
{
ratio = 100.0/(double)(NX*NY);
first = 0;
}
sp1 = 0.0;
sp2 = 0.0;
// #pragma omp parallel for private(i,j)
for (i=0; i<NX; i++)
{
for (j=0; j<NY/2; j++) sp1 += phi[1][i*NY+j];
for (j=NY/2; j<NY; j++) sp2 += phi[1][i*NY+j];
// for (j=0; j<NY/2; j++) *speed1 += rde[i*NY+j].field_norm;
// for (j=NY/2; j<NY; j++) *speed2 += rde[i*NY+j].field_norm;
}
*speed1 = sp1*ratio;
*speed2 = sp2*ratio;
}
void set_bc_flow(double flow_speed, double yshift, double *phi_out[NFIELDS], short int xy_in[NX*NY], int imin, int imax, int jmin, int jmax)
/* set fields in given rectangular region */
{
switch (BC_FLOW_TYPE)
{
case (BCF_LAMINAR):
{
set_boundary_laminar_flow(flow_speed, LAMINAR_FLOW_MODULATION, 0.02, yshift, 1.0, 0.0, 0.1, phi_out, xy_in, imin, imax, jmin, jmax, IN_OUT_BC_FACTOR);
break;
}
case (BCF_PRESSURE):
{
set_boundary_pressure_gradient_flow(IN_OUT_FLOW_AMP, 1.0 + PRESSURE_GRADIENT, 1.0 - PRESSURE_GRADIENT, phi_out, xy_in, imin, imax, jmin, jmax, IN_OUT_BC_FACTOR);
break;
}
}
}
void set_in_out_flow_bc(double *phi_out[NFIELDS], short int xy_in[NX*NY], double flow_speed)
/* set fields for particular boundary conditions (flowing in and out for Euler equations) */
{
int ropening, w;
double x, y, dy, xy[2], padding, a;
static int y_channels, y_channels1, imin, imax, first = 1;
if (first) /* for D_MAZE_CHANNELS boundary conditions in Euler equation */
{
ropening = (NYMAZE+1)/2;
padding = 0.02;
dy = (YMAX - YMIN - 2.0*padding)/(double)(NYMAZE);
y = YMIN + 0.02 + dy*((double)ropening);
x = YMAX - padding + MAZE_XSHIFT;
xy_to_pos(x, y, xy);
y_channels = xy[1] - 5;
if ((B_DOMAIN == D_MAZE_CHANNELS)||(OBSTACLE_GEOMETRY == D_MAZE_CHANNELS))
{
imax = xy[0] + 2;
x = YMIN + padding + MAZE_XSHIFT;
xy_to_pos(x, y, xy);
imin = xy[0] - 2;
if (imin < 5) imin = 5;
}
else if (OBSTACLE_GEOMETRY == D_TESLA)
{
imin = 0;
imax = NX;
y = -a;
xy_to_pos(XMIN, y, xy);
y_channels = xy[1];
printf("y_channels = %i\n", y_channels);
}
else if (OBSTACLE_GEOMETRY == D_TESLA_FOUR)
{
imin = 0;
imax = NX;
a = 0.16;
// y = YMIN + 0.25*(YMAX-YMIN) - 0.5*a;
y = YMIN + 0.25*(YMAX-YMIN) + 0.75*a;
xy_to_pos(XMIN, y, xy);
y_channels = xy[1];
y_channels1 = NY/2 + y_channels;
printf("y_channels = %i, interval [%i, %i]\n", y_channels, NY/2 - y_channels, y_channels);
printf("y_channels1 = %i, interval [%i, %i]\n", y_channels1, NY - y_channels1, y_channels1);
}
else
{
imin = 0;
imax = NX;
}
first = 0;
}
switch (IN_OUT_FLOW_BC) {
case (BCE_LEFT):
{
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, 5, 0, NY);
break;
}
case (BCE_TOPBOTTOM):
{
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, NX, 0, 10);
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, NX, NY-10, NY);
break;
}
case (BCE_TOPBOTTOMLEFT):
{
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, NX, 0, 10);
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, NX, NY-10, NY);
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, 2, 0, NY);
break;
}
case (BCE_CHANNELS):
{
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, imin+5, NY - y_channels, y_channels);
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, imax-5, NX - 1, NY- y_channels, y_channels);
break;
}
case (BCE_FOUR_CHANNELS):
{
w = 3;
set_bc_flow(flow_speed, 0.0, phi_out, xy_in, 0, imin+5, y_channels-w, y_channels+w);
set_bc_flow(flow_speed, 0.0, phi_out, xy_in, imax-5, NX - 1, y_channels-w, y_channels+w);
set_bc_flow(flow_speed, 0.0, phi_out, xy_in, 0, imin+5, y_channels1-w, y_channels1+w);
set_bc_flow(flow_speed, 0.0, phi_out, xy_in, imax-5, NX - 1, y_channels1-w, y_channels1+w);
break;
}
case (BCE_MIDDLE_STRIP):
{
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, NX, NY/2 - 10, NY/2 + 10);
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, 0, 2, 0, NY);
set_bc_flow(flow_speed, 0.1, phi_out, xy_in, NX-2, NX, 0, NY);
break;
}
}
}

View File

@ -5077,6 +5077,27 @@ void print_speed(double speed, int fade, double fade_value)
write_text(pos[0], pos[1], message);
}
void print_frequency(double phase_shift, int fade, double fade_value)
{
char message[100];
double y = YMAX - 0.1, pos[2];
static double xleftbox, xlefttext;
static int first = 1;
if (first)
{
xleftbox = XMIN + 0.3;
xlefttext = xleftbox - 0.45;
first = 0;
}
erase_area_hsl(xleftbox, y + 0.025, 0.22, 0.05, 0.0, 0.9, 0.0);
if (fade) glColor3f(fade_value, fade_value, fade_value);
else glColor3f(1.0, 1.0, 1.0);
xy_to_pos(xlefttext + 0.28, y, pos);
sprintf(message, "Frequency %.2f", 25.0*phase_shift);
write_text(pos[0], pos[1], message);
}
void init_laplacian_coords(t_laplacian laplace[NX*NY], double phi[NX*NY])
/* compute coordinates of neighbours to compute Laplacian */

View File

@ -1374,6 +1374,44 @@ void init_speed_dissipation(short int xy_in[NX*NY], double tc[NX*NY], double tcc
}
break;
}
case (IOR_MANDELBROT_MOD):
{
#pragma omp parallel for private(i,j)
for (i=0; i<NX; i++){
for (j=0; j<NY; j++){
ij_to_xy(i, j, xy);
x = xy[0];
y = xy[1];
u = 0.0;
v = 0.0;
k = 0;
while ((k<MANDELLEVEL)&&(u*u+v*v < 1000.0*MANDELLIMIT))
{
u1 = u*u - v*v + x;
v = 2.0*u*v + y;
u = u1;
k++;
}
if (k >= MANDELLEVEL)
{
tc[i*NY+j] = COURANT;
tcc[i*NY+j] = courant2;
tgamma[i*NY+j] = GAMMA;
}
else
{
// speed = 5.0 - 4.0*pow((double)k/(double)MANDELLEVEL, 0.1);
speed = 1.0 + 4.0*log(1.0 - 0.1*log((double)k/(double)MANDELLEVEL));
if (speed < 1.0e-10) speed = 1.0e-10;
else if (speed > 10.0) speed = 10.0;
tcc[i*NY+j] = courantb2*speed;
tc[i*NY+j] = COURANTB*sqrt(speed);
tgamma[i*NY+j] = GAMMAB;
}
}
}
break;
}
case (IOR_EARTH):
{
for (i=0; i<NX; i++){
@ -1432,6 +1470,39 @@ void init_speed_dissipation(short int xy_in[NX*NY], double tc[NX*NY], double tcc
}
break;
}
case (IOR_PERIODIC_WELLS):
{
dx = (XMAX - XMIN)/(double)NGRIDX;
dy = (YMAX - YMIN)/(double)NGRIDY;
sigma = 0.2*dx*dx;
for (i=0; i<NGRIDX; i++)
for (j=0; j<NGRIDY; j++)
{
n = j*NGRIDX + i;
xc[n] = XMIN + dx*((double)i + 0.5);
yc[n] = YMIN + dy*((double)j + 0.5);
if (j%2 == 1) yc[n] += 0.5*dx;
}
for (i=0; i<NX; i++){
for (j=0; j<NY; j++){
ij_to_xy(i, j, xy);
x = xy[0];
y = xy[1];
sum = 0.0;
for (n = 0; n<NGRIDX*NGRIDY; n++)
{
r2 = (x - xc[n])*(x - xc[n]) + (y - yc[n])*(y - yc[n]);
sum += exp(-r2/(sigma));
}
tc[i*NY+j] = COURANT*sum + COURANTB*(1.0-sum);
tcc[i*NY+j] = COURANT*sum + COURANTB*(1.0-sum);
tgamma[i*NY+j] = GAMMA;
}
}
break;
}
case (IOR_RANDOM_WELLS):
{
dx = (XMAX - XMIN)/(double)NGRIDX;
@ -1884,7 +1955,7 @@ void draw_color_scheme_palette_3d(double x1, double y1, double x2, double y2, in
int j, k, ij_botleft[2], ij_topright[2], imin, imax, jmin, jmax;
double y, dy, dy_e, dy_phase, rgb[3], value, lum, amp;
printf("Drawing color bar\n");
// printf("Drawing color bar\n");
xy_to_ij(x1, y1, ij_botleft);
xy_to_ij(x2, y2, ij_topright);
@ -1988,7 +2059,7 @@ void draw_color_scheme_palette_3d(double x1, double y1, double x2, double y2, in
}
case (P_3D_FLUX_DIRECTION):
{
value = 2.0*dy_phase*(double)(j - jmin);
value = dy_phase*(double)(j - jmin);
color_scheme_palette(C_ONEDIM_LINEAR, palette, value, 1.0, 1, rgb);
break;
}

175
wave_3d.c
View File

@ -50,37 +50,45 @@
/* General geometrical parameters */
// #define WINWIDTH 1920 /* window width */
// #define WINHEIGHT 1150 /* window height */
// // // // #define NX 2500 /* number of grid points on x axis */
// // // // #define NY 1250 /* number of grid points on y axis */
#define WINWIDTH 1920 /* window width */
#define WINHEIGHT 1150 /* window height */
// // // #define NX 2500 /* number of grid points on x axis */
// // // #define NY 1250 /* number of grid points on y axis */
// #define NX 2840 /* number of grid points on x axis */
// #define NY 2300 /* number of grid points on y axis */
//
// #define NX 2500 /* number of grid points on x axis */
// #define NY 1250 /* number of grid points on y axis */
#define NX 1700 /* number of grid points on x axis */
#define NY 1700 /* 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 XMIN -1.5
#define XMAX 1.5 /* x interval */
#define YMIN -1.5
#define YMAX 1.5 /* 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 NX 720 /* number of grid points on x axis */
// #define NY 720 /* number of grid points on y axis */
#define NX 2560 /* number of grid points on x axis */
// #define NX 1440 /* number of grid points on x axis */
#define NY 1440 /* number of grid points on y axis */
// #define NX 360 /* number of grid points on x axis */
// #define NY 360 /* number of grid points on y axis */
#define XMIN -2.0
#define XMAX 2.0 /* x interval */
#define YMIN -1.125
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */
// #define WINWIDTH 1280 /* window width */
// #define WINHEIGHT 720 /* window height */
//
// // #define NX 1280 /* number of grid points on x axis */
// // #define NX 720 /* number of grid points on x axis */
// // #define NY 720 /* number of grid points on y axis */
// #define NX 2560 /* number of grid points on x axis */
// // #define NX 1440 /* number of grid points on x axis */
// #define NY 1440 /* number of grid points on y axis */
//
// // #define NX 360 /* number of grid points on x axis */
// // #define NY 360 /* number of grid points on y axis */
//
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
// #define YMIN -1.125
// #define YMAX 1.125 /* y interval for 9/16 aspect ratio */
#define JULIA_SCALE 0.8 /* scaling for Julia sets */
@ -94,8 +102,8 @@
#define B_DOMAIN_B 20 /* second domain shape, for comparisons */
#define CIRCLE_PATTERN_B 0 /* second pattern of circles or polygons */
#define VARIABLE_IOR 1 /* set to 1 for a variable index of refraction */
#define IOR 5 /* choice of index of refraction, see list in global_pdes.c */
#define VARIABLE_IOR 0 /* set to 1 for a variable index of refraction */
#define IOR 101 /* choice of index of refraction, see list in global_pdes.c */
#define IOR_TOTAL_TURNS 1.0 /* total angle of rotation for IOR_PERIODIC_WELLS_ROTATING */
#define MANDEL_IOR_SCALE -0.05 /* parameter controlling dependence of IoR on Mandelbrot escape speed */
@ -109,10 +117,10 @@
#define APOLY 0.0 /* angle by which to turn polygon, in units of Pi/2 */
#define MDEPTH 7 /* depth of computation of Menger gasket */
#define MRATIO 3 /* ratio defining Menger gasket */
#define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */
#define MANDELLIMIT 10.0 /* limit value for approximation of Mandelbrot set */
#define MANDELLEVEL 2000 /* iteration level for Mandelbrot set */
#define MANDELLIMIT 20.0 /* limit value for approximation of Mandelbrot set */
#define FOCI 1 /* set to 1 to draw focal points of ellipse */
#define NGRIDX 14 /* number of grid point for grid of disks */
#define NGRIDX 8 /* number of grid point for grid of disks */
#define NGRIDY 8 /* number of grid point for grid of disks */
#define X_SHOOTER -0.2
@ -138,14 +146,13 @@
#define OSCILLATION_SCHEDULE 3 /* oscillation schedule, see list in global_pdes.c */
#define OMEGA 0.001 /* frequency 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 DAMPING 0.0 /* damping of periodic excitation */
#define COURANT 0.05 /* Courant number */
#define COURANTB 0.0 /* Courant number in medium B */
#define COURANT 0.06 /* Courant number */
#define COURANTB 0.06 /* Courant number in medium B */
#define GAMMA 0.0 /* damping factor in wave equation */
#define GAMMAB 0.0 /* damping factor in wave equation */
#define GAMMAB 1.0e-6 /* damping factor in wave equation */
#define GAMMA_SIDES 1.0e-4 /* damping factor on boundary */
#define GAMMA_TOPBOT 1.0e-7 /* damping factor on boundary */
#define KAPPA 0.0 /* "elasticity" term enforcing oscillations */
@ -157,7 +164,7 @@
/* For similar wave forms, COURANT^2*GAMMA should be kept constant */
#define ADD_OSCILLATING_SOURCE 1 /* set to 1 to add an oscillating wave source */
#define OSCILLATING_SOURCE_PERIOD 75 /* period of oscillating source */
#define OSCILLATING_SOURCE_PERIOD 2 /* period of oscillating source */
#define ALTERNATE_OSCILLATING_SOURCE 1 /* set to 1 to alternate sign of oscillating source */
#define ADD_WAVE_PACKET_SOURCES 0 /* set to 1 to add several sources emitting wave packets */
@ -174,10 +181,11 @@
/* Parameters for length and speed of simulation */
#define NSTEPS 2200 /* number of frames of movie */
// #define NSTEPS 500 /* number of frames of movie */
#define NVID 4 /* number of iterations between images displayed on screen */
#define NSEG 1000 /* number of segments of boundary */
#define NSTEPS 2450 /* number of frames of movie */
// #define NSTEPS 500 /* number of frames of movie */
#define NVID 5 /* number of iterations between images displayed on screen */
// #define NVID 10 /* number of iterations between images displayed on screen */
#define NSEG 1000 /* number of segments of boundary */
#define INITIAL_TIME 0 /* time after which to start saving frames */
#define BOUNDARY_WIDTH 2 /* width of billiard boundary */
#define PRINT_SPEED 0 /* set to 1 to print speed of moving source */
@ -193,22 +201,18 @@
/* Parameters of initial condition */
#define INITIAL_AMP 0.25 /* amplitude of initial condition */
#define INITIAL_VARIANCE 0.00015 /* variance of initial condition */
#define INITIAL_WAVELENGTH 0.0075 /* wavelength of initial condition */
// #define INITIAL_AMP 0.02 /* amplitude of initial condition */
#define INITIAL_AMP 0.007 /* amplitude of initial condition */
#define INITIAL_VARIANCE 0.0003 /* variance of initial condition */
#define INITIAL_WAVELENGTH 0.015 /* wavelength of initial condition */
/* Plot type, see list in global_pdes.c */
#define ZPLOT 103 /* wave height */
#define CPLOT 103 /* color scheme */
// #define ZPLOT 104 /* wave height */
// #define CPLOT 104 /* color scheme */
#define ZPLOT_B 108
#define CPLOT_B 108 /* plot type for second movie */
#define ZPLOT_B 112
#define CPLOT_B 113 /* plot type for second movie */
#define CHANGE_LUMINOSITY 1 /* set to 1 to let luminosity depend on energy flux intensity */
#define FLUX_WINDOW 30 /* size of averaging window of flux intensity */
@ -222,8 +226,8 @@
#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 PLOT_SCALE_ENERGY 0.1 /* vertical scaling in energy plot */
#define PLOT_SCALE_LOG_ENERGY 0.2 /* vertical scaling in log energy plot */
#define PLOT_SCALE_ENERGY 0.4 /* vertical scaling in energy plot */
#define PLOT_SCALE_LOG_ENERGY 0.5 /* vertical scaling in log energy plot */
/* 3D representation */
@ -232,23 +236,23 @@
#define REP_AXO_3D 0 /* linear projection (axonometry) */
#define REP_PROJ_3D 1 /* projection on plane orthogonal to observer line of sight */
#define ROTATE_VIEW 1 /* 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 45.0 /* total angle of rotation during simulation */
/* Color schemes */
#define COLOR_PALETTE 11 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE_B 14 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE 15 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE_B 10 /* Color palette, see list in global_pdes.c */
#define BLACK 1 /* background */
#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 SLOPE 1.0 /* sensitivity of color on wave amplitude */
#define VSCALE_AMPLITUDE 3.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */
#define VSCALE_ENERGY 25.0 /* additional scaling factor for color scheme P_3D_ENERGY */
#define SLOPE 1.0 /* sensitivity of color on wave amplitude */
#define VSCALE_AMPLITUDE 2.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */
#define VSCALE_ENERGY 15.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_SHIFT 0.0 /* shift of phase in color scheme P_3D_PHASE */
#define ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */
@ -257,8 +261,8 @@
#define LOG_SHIFT 0.5 /* shift of colors on log scale */
#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 FLUX_SCALE 20.0 /* scaling factor for energy flux representation */
#define FLUX_CSCALE 500.0 /* scaling factor for color in energy flux representation */
#define FLUX_SCALE 4000.0 /* scaling factor for energy flux representation */
#define FLUX_CSCALE 2.0 /* scaling factor for color in energy flux representation */
#define RESCALE_COLOR_IN_CENTER 0 /* set to 1 to decrease color intentiy in the center (for wave escaping ring) */
#define COLORHUE 260 /* initial hue of water color for scheme C_LUM */
@ -282,10 +286,10 @@
#define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */
#define ADD_POTENTIAL 0 /* set to 1 to add potential to z coordinate */
#define ADD_POTENTIAL 1 /* set to 1 to add potential to z coordinate */
// #define POT_MAZE 7
#define POTENTIAL 10
#define POT_FACT 30.0
#define POT_FACT 400.0
/* end of constants only used by sub_wave and sub_maze */
@ -299,14 +303,14 @@ double u_3d[2] = {0.75, -0.45}; /* projections of basis vectors for REP_AXO_
double v_3d[2] = {-0.75, -0.45};
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 observer[3] = {8.0, 8.0, 7.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) */
#define Z_SCALING_FACTOR 0.15 /* overall scaling factor of z axis for REP_PROJ_3D representation */
#define Z_SCALING_FACTOR 0.5 /* 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 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 YSHIFT_3D 0.1 /* overall y shift for REP_PROJ_3D representation */
#define YSHIFT_3D 0.2 /* overall y shift for REP_PROJ_3D representation */
#include "global_pdes.c" /* constants and global variables */
@ -945,15 +949,16 @@ void viewpoint_schedule(int i)
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, angle, lambda1, y, x1, sign1;
double time, scale, ratio, startleft[2], startright[2], sign = 1.0, r2, xy[2], fade_value, yshift, speed = 0.0, a, b, c, angle = 0.0, lambda1, y, x1, sign1, omega, phase_shift;
double *phi, *psi, *tmp, *color_scale, *tc, *tcc, *tgamma;
// double *total_energy;
short int *xy_in;
int i, j, s, sample_left[2], sample_right[2], period = 0, fade, source_counter = 0, k, p, q;
static int counter = 0;
static int counter = 0, first_source = 1;
long int wave_value;
t_wave *wave;
t_laplacian *laplace, *laplace1, *laplace2;
t_wave_source wave_source[25];
if (SAVE_TIME_SERIES)
{
@ -1063,6 +1068,7 @@ void animation()
// add_circular_wave_mod(1.0, lambda1*cos(((double)j+0.5)*angle), lambda1*sin(((double)j+0.5)*angle), phi, psi, xy_in);
init_wave_flat_mod(phi, psi, xy_in);
// init_circular_wave_mod(0.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");
@ -1146,8 +1152,47 @@ void animation()
// if ((ADD_OSCILLATING_SOURCE)&&(i%OSCILLATING_SOURCE_PERIOD == OSCILLATING_SOURCE_PERIOD - 1))
if ((ADD_OSCILLATING_SOURCE)&&(i%OSCILLATING_SOURCE_PERIOD == 1))
{
if (ALTERNATE_OSCILLATING_SOURCE) sign = -sign;
add_circular_wave_mod(sign, 0.0, 0.0, phi, psi, xy_in);
// if (ALTERNATE_OSCILLATING_SOURCE) sign = -sign;
// add_circular_wave_mod(sign, 0.0, 0.0, phi, psi, xy_in);
phase_shift = 1/30.0;
// phase_shift = 1/60.0;
if (first_source) for (k=0; k<25; k++)
{
angle = 0.0;
omega = DPI/25.0;
wave_source[k].xc = 0.05*cos((double)k*omega);;
wave_source[k].yc = 0.05*sin((double)k*omega);
wave_source[k].phase = 0.99 - 1.4*sin(0.7*(1.0 + wave_source[k].xc/0.05));
wave_source[k].amp = 1.0;
// if (wave_source[k].phase > 0.0) wave_source[k].sign = 1;
// else wave_source[k].sign = -1;
wave_source[k].sign = 1;
}
first_source = 0;
for (k=0; k<25; k++)
wave_source[k].phase += 1.4*sin(0.7*(1.0 + wave_source[k].xc*cos(angle)/0.05 + wave_source[k].yc*sin(angle)/0.05));
angle = DPI*(double)i/(double)NSTEPS;
// phase_shift = 0.02 + 0.08*(double)i/(double)NSTEPS;
// printf("Phase shift = %.3lg\n", phase_shift);
for (k=0; k<25; k++)
{
// wave_source[k].phase += 0.07;
wave_source[k].phase += phase_shift;
wave_source[k].phase -= 1.4*sin(0.7*(1.0 + wave_source[k].xc*cos(angle)/0.05 + wave_source[k].yc*sin(angle)/0.05));
if (wave_source[k].phase > 1.0)
{
add_circular_wave_mod((double)wave_source[k].sign*wave_source[k].amp, wave_source[k].xc, wave_source[k].yc, phi, psi, xy_in);
printf("Adding wave at (%.2lg, %.2lg)\n", wave_source[k].xc, wave_source[k].yc);
wave_source[k].phase -= 1.0;
wave_source[k].sign *= -1;
}
}
// for (j=0; j<NPOLY; j++)
// add_circular_wave_mod(sign, lambda1*cos(((double)j+0.5)*angle), lambda1*sin(((double)j+0.5)*angle), phi, psi, xy_in);

View File

@ -48,40 +48,40 @@
#define SAVE_MEMORY 1 /* set to 1 to save memory when writing tiff images */
#define NO_EXTRA_BUFFER_SWAP 1 /* some OS require one less buffer swap when recording images */
#define VARIABLE_IOR 1 /* set to 1 for a variable index of refraction */
#define IOR 5 /* choice of index of refraction, see list in global_pdes.c */
#define VARIABLE_IOR 0 /* set to 1 for a variable index of refraction */
#define IOR 7 /* choice of index of refraction, see list in global_pdes.c */
#define IOR_TOTAL_TURNS 1.5 /* total angle of rotation for IOR_PERIODIC_WELLS_ROTATING */
#define MANDEL_IOR_SCALE -0.05 /* parameter controlling dependence of IoR on Mandelbrot escape speed */
/* General geometrical parameters */
// #define WINWIDTH 1920 /* window width */
// #define WINHEIGHT 1150 /* window height */
// #define NX 3840 /* number of grid points on x axis */
// #define NY 2300 /* number of grid points on y axis */
//
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
// #define YMIN -1.197916667
// #define YMAX 1.197916667 /* y interval for 9/16 aspect ratio */
#define WINWIDTH 1920 /* window width */
#define WINHEIGHT 1150 /* window height */
#define NX 3840 /* number of grid points on x axis */
#define NY 2300 /* number of grid points on y axis */
#define XMIN -2.0
#define XMAX 2.0 /* x interval */
#define YMIN -1.197916667
#define YMAX 1.197916667 /* y interval for 9/16 aspect ratio */
#define HIGHRES 1 /* 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 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 NY 720 /* number of grid points on y axis */
#define NX 2560 /* number of grid points on x axis */
#define NY 1440 /* number of grid points on y axis */
#define XMIN -2.0
#define XMAX 2.0 /* x interval */
#define YMIN -1.125
#define YMAX 1.125 /* y interval for 9/16 aspect ratio */
// #define WINWIDTH 1280 /* window width */
// #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 NY 720 /* number of grid points on y axis */
// #define NX 2560 /* number of grid points on x axis */
// #define NY 1440 /* number of grid points on y axis */
//
// #define XMIN -2.0
// #define XMAX 2.0 /* x interval */
// #define YMIN -1.125
// #define YMAX 1.125 /* y interval for 9/16 aspect ratio */
#define JULIA_SCALE 1.0 /* scaling for Julia sets */
@ -136,7 +136,7 @@
#define AMPLITUDE 0.8 /* amplitude of periodic excitation */
#define ACHIRP 0.25 /* acceleration coefficient in chirp */
#define DAMPING 0.0 /* damping of periodic excitation */
#define COURANT 0.04 /* Courant number */
#define COURANT 0.06 /* Courant number */
#define COURANTB 0.0 /* Courant number in medium B */
#define GAMMA 0.0 /* damping factor in wave equation */
#define GAMMAB 0.0 /* damping factor in wave equation */
@ -151,7 +151,7 @@
/* For similar wave forms, COURANT^2*GAMMA should be kept constant */
#define ADD_OSCILLATING_SOURCE 1 /* set to 1 to add an oscillating wave source */
#define OSCILLATING_SOURCE_PERIOD 50 /* period of oscillating source */
#define OSCILLATING_SOURCE_PERIOD 2 /* period of oscillating source */
#define ALTERNATE_OSCILLATING_SOURCE 1 /* set to 1 to alternate sign of oscillating source */
#define ADD_WAVE_PACKET_SOURCES 0 /* set to 1 to add several sources emitting wave packets */
@ -165,13 +165,14 @@
/* Parameters for length and speed of simulation */
#define NSTEPS 1800 /* number of frames of movie */
// #define NSTEPS 500 /* number of frames of movie */
#define NSTEPS 2750 /* number of frames of movie */
// #define NSTEPS 2100 /* 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 INITIAL_TIME 0 /* 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_FREQUENCY 0 /* print frequency (for phased array) */
#define PAUSE 200 /* number of frames after which to pause */
#define PSLEEP 1 /* sleep time during pause */
@ -183,7 +184,7 @@
/* Parameters of initial condition */
#define INITIAL_AMP 0.5 /* amplitude of initial condition */
#define INITIAL_AMP 0.007 /* amplitude of initial condition */
#define INITIAL_VARIANCE 0.0003 /* variance of initial condition */
#define INITIAL_WAVELENGTH 0.015 /* wavelength of initial condition */
@ -192,24 +193,24 @@
#define PLOT 0
// #define PLOT 7
#define PLOT_B 5 /* plot type for second movie */
#define PLOT_B 7 /* plot type for second movie */
/* Color schemes */
// #define COLOR_PALETTE 15 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE 17 /* Color palette, see list in global_pdes.c */
#define COLOR_PALETTE_B 13 /* 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 BLACK 1 /* background */
#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 SLOPE 0.75 /* sensitivity of color on wave amplitude */
#define SLOPE 1.0 /* sensitivity of color on wave amplitude */
#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 ATTENUATION 0.0 /* exponential attenuation coefficient of contrast with time */
#define E_SCALE 60.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_SHIFT 3.5 /* shift of colors on log scale */
#define FLUX_SCALE 5.0e3 /* scaling factor for enegy flux represtnation */
@ -222,8 +223,8 @@
#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 DRAW_COLOR_SCHEME 0 /* set to 1 to plot the color scheme */
#define COLORBAR_RANGE 2.0 /* scale of color scheme bar */
#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_B 0.1 /* scale of color scheme bar for 2nd part */
#define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */
@ -581,13 +582,14 @@ void draw_color_bar_palette(int plot, double range, int palette, int fade, doubl
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, x, y, angle, x1, sign1, ior_angle = 0.0;
double time, scale, ratio, startleft[2], startright[2], sign = 1.0, r2, xy[2], fade_value, yshift, speed = 0.0, a, b, c, x, y, angle = 0.0, x1, sign1, ior_angle = 0.0, omega, phase_shift;
double *phi[NX], *psi[NX], *tmp[NX], *total_energy[NX], *color_scale[NX], *total_flux, *tcc_table[NX];
short int *xy_in[NX];
int i, j, k, s, sample_left[2], sample_right[2], period = 0, fade, source_counter = 0, p, q;
int i, j, k, s, sample_left[2], sample_right[2], period = 0, fade, source_counter = 0, p, q, first_source = 1;
static int counter = 0;
long int wave_value;
t_wave_packet *packet;
t_wave_source wave_source[25];
if (SAVE_TIME_SERIES)
{
@ -787,10 +789,44 @@ void animation()
/* add oscillating waves */
if ((ADD_OSCILLATING_SOURCE)&&(i%OSCILLATING_SOURCE_PERIOD == 1))
{
if (ALTERNATE_OSCILLATING_SOURCE) sign = -sign;
add_circular_wave(sign, 0.0, 0.0, phi, psi, xy_in);
// if (ALTERNATE_OSCILLATING_SOURCE) sign = -sign;
// add_circular_wave(sign, 0.0, 0.0, phi, psi, xy_in);
// p = phased_array_schedule(i);
// phase_shift = 0.02 + 0.06*(double)i/(double)NSTEPS;
if (first_source) for (k=0; k<25; k++)
{
omega = DPI/25.0;
wave_source[k].xc = 0.05*cos((double)k*omega);;
wave_source[k].yc = 0.05*sin((double)k*omega);
wave_source[k].phase = 0.99 - 1.4*sin(0.7*(1.0 + wave_source[k].xc/0.05));
wave_source[k].amp = 1.0;
if (wave_source[k].phase) wave_source[k].sign = 1;
else wave_source[k].sign = -1;
first_source = 0;
}
for (k=0; k<25; k++)
wave_source[k].phase += 1.4*sin(0.7*(1.0 + wave_source[k].xc*cos(angle)/0.05 + wave_source[k].yc*sin(angle)/0.05));
angle = DPI*(double)i/(double)NSTEPS;
for (k=0; k<25; k++)
{
wave_source[k].phase += 0.07;
wave_source[k].phase -= 1.4*sin(0.7*(1.0 + wave_source[k].xc*cos(angle)/0.05 + wave_source[k].yc*sin(angle)/0.05));
if (wave_source[k].phase > 1.0)
{
add_circular_wave((double)wave_source[k].sign*wave_source[k].amp, wave_source[k].xc, wave_source[k].yc, phi, psi, xy_in);
printf("Adding wave at (%.2lg, %.2lg)\n", wave_source[k].xc, wave_source[k].yc);
wave_source[k].phase -= 1.0;
wave_source[k].sign *= -1;
}
}
// p = 3;
// y = -1.0;
// sign1 = sign;
@ -834,6 +870,7 @@ void animation()
}
if (ADD_WAVE_PACKET_SOURCES) add_wave_packets(phi, psi, xy_in, packet, i, WAVE_PACKET_RADIUS, 0, 10, 1);
if (PRINT_SPEED) print_speed(speed, 0, 1.0);
if (PRINT_FREQUENCY) print_frequency(phase_shift, 0, 1.0);
if ((VARIABLE_IOR)&&(REFRESH_IOR)&&(i%3 == 0))
{
ior_angle = ior_angle_schedule(i);
@ -858,6 +895,7 @@ void animation()
draw_billiard(0, 1.0);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(PLOT_B, COLORBAR_RANGE_B, COLOR_PALETTE_B, 0, 1.0);
if (PRINT_SPEED) print_speed(speed, 0, 1.0);
if (PRINT_FREQUENCY) print_frequency(phase_shift, 0, 1.0);
glutSwapBuffers();
save_frame_counter(NSTEPS + MID_FRAMES + 1 + counter);
counter++;
@ -886,6 +924,7 @@ void animation()
draw_billiard(0, 1.0);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(PLOT, COLORBAR_RANGE, COLOR_PALETTE, 0, 1.0);
if (PRINT_SPEED) print_speed(speed, 0, 1.0);
if (PRINT_FREQUENCY) print_frequency(phase_shift, 0, 1.0);
glutSwapBuffers();
}
if (!FADE) for (i=0; i<MID_FRAMES; i++) save_frame();
@ -898,6 +937,7 @@ void animation()
draw_billiard(1, fade_value);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(PLOT, COLORBAR_RANGE, COLOR_PALETTE, 1, fade_value);
if (PRINT_SPEED) print_speed(speed, 1, fade_value);
if (PRINT_FREQUENCY) print_frequency(phase_shift, 1, fade_value);
if (!NO_EXTRA_BUFFER_SWAP) glutSwapBuffers();
save_frame_counter(NSTEPS + i + 1);
}
@ -910,6 +950,7 @@ void animation()
draw_billiard(0, 1.0);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(PLOT_B, COLORBAR_RANGE_B, COLOR_PALETTE_B, 0, 1.0);
if (PRINT_SPEED) print_speed(speed, 0, 1.0);
if (PRINT_FREQUENCY) print_frequency(phase_shift, 0, 1.0);
glutSwapBuffers();
if (!FADE) for (i=0; i<END_FRAMES; i++) save_frame_counter(NSTEPS + MID_FRAMES + 1 + counter + i);
@ -922,6 +963,7 @@ void animation()
draw_billiard(1, fade_value);
if (DRAW_COLOR_SCHEME) draw_color_bar_palette(PLOT_B, COLORBAR_RANGE_B, COLOR_PALETTE_B, 1, fade_value);
if (PRINT_SPEED) print_speed(speed, 1, fade_value);
if (PRINT_FREQUENCY) print_frequency(phase_shift, 0, 1.0);
glutSwapBuffers();
save_frame_counter(NSTEPS + MID_FRAMES + 1 + counter + i);
}