From d5be739977ef6e01aa662f338a5010852bd044c0 Mon Sep 17 00:00:00 2001 From: Nils Berglund <83530463+nilsberglund-orleans@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:17:55 +0100 Subject: [PATCH] Add files via upload --- global_3d.c | 4 + global_ljones.c | 50 +- global_pdes.c | 18 + heat.c | 9 + lennardjones.c | 485 ++++++++----- mangrove.c | 16 + rde.c | 269 +++++--- schrodinger.c | 9 + sub_lj.c | 1685 ++++++++++++++++++++++++++++++++++++++++----- sub_rde.c | 1039 +++++++++++++++++++++++++++- sub_sphere.c | 531 +++++++++++--- sub_wave.c | 666 ++++++++++++++++-- sub_wave_3d.c | 6 +- sub_wave_3d_rde.c | 269 +++++++- wave_3d.c | 105 +-- wave_billiard.c | 297 ++++---- wave_common.c | 586 ++++++++++++++-- wave_comparison.c | 16 + wave_energy.c | 16 + wave_sphere.c | 366 ++++++---- 20 files changed, 5382 insertions(+), 1060 deletions(-) diff --git a/global_3d.c b/global_3d.c index 998059b..c4e0bbd 100644 --- a/global_3d.c +++ b/global_3d.c @@ -86,6 +86,7 @@ int global_time = 0; double max_depth = 1.0; +int moon_position; /* structure used for color and height representations */ /* possible extra fields: zfield, cfield, interpolated coordinates */ @@ -148,12 +149,15 @@ typedef struct double ctheta, stheta, cottheta; /* cos, sin and cotangent of theta */ double x, y, z; /* x, y, z coordinates of point on sphere */ double radius; /* radius with wave height */ + double radius_dem; /* radius with digital elevation model */ double r, g, b; /* RGB values for image */ short int indomain; /* has value 1 if lattice point is in domain */ + short int draw_wave; /* has value 1 if wave instead of DEM is drawn */ double x2d, y2d; /* x and y coordinates for 2D representation */ double altitude; /* altitude in case of Earth with digital elevation model */ double cos_angle; /* cosine of light angle */ double cos_angle_sphere; /* cosing of light angle for perfect sphere */ + double force; /* external forcing */ } t_wave_sphere; diff --git a/global_ljones.c b/global_ljones.c index bb1938a..9fa3d4d 100644 --- a/global_ljones.c +++ b/global_ljones.c @@ -17,7 +17,7 @@ #define NMAXSEGMENTS 1000 /* max number of repelling segments */ #define NMAXGROUPS 50 /* max number of groups of segments */ #define NMAXCOLLISIONS 200000 /* max number of collisions */ -#define NMAXPARTNERS 10 /* max number of partners in molecule */ +#define NMAXPARTNERS 30 /* max number of partners in molecule */ #define C_SQUARE 0 /* square grid of circles */ #define C_HEX 1 /* hexagonal/triangular grid of circles */ @@ -75,6 +75,7 @@ #define S_HLINE_HOLE_SPOKES 181 /* horizontal line with a hole in the bottom and extra spokes */ #define S_EXT_CIRCLE_RECT 19 /* particles outside a circle and a rectangle */ #define S_BIN_OPENING 20 /* bin containing particles opening at deactivation time */ +#define S_BIN_LARGE 201 /* larger bin */ #define S_POLYGON_EXT 21 /* exterior of a regular polygon */ #define S_WEDGE_EXT 22 /* exterior of a wedge */ #define S_MIXER 23 /* exterior of a blender made of rectangles */ @@ -83,6 +84,7 @@ #define S_COANDA_SHORT 26 /* shorter wall for Coanda effect */ #define S_CYLINDER 27 /* walls at top and bottom, for cylindrical b.c. */ #define S_TREE 28 /* Christmas tree(s) */ +#define S_CONE 29 /* cone */ /* particle interaction */ @@ -127,11 +129,26 @@ #define TH_INBOX 2 /* only particles in a given box are coupled */ #define TH_LAYER 3 /* only particles above PARTIAL_THERMO_HEIGHT are coupled */ #define TH_LAYER_TYPE2 4 /* only particles above highest type 2 particle are coupled */ +#define TH_RING 5 /* only particles outside disc of radius PARTIAL_THERMO_WIDTH are coupled */ +#define TH_RING_EXPAND 6 /* only particles outside disc of radius changing from PARTIAL_THERMO_RIN to PARTIAL_THERMO_RFIN are coupled */ +#define TH_INIT 7 /* only particles in region defined by INITXMIN, etc are coupled */ +#define TH_THERMO 8 /* only particles in region defined by THERMOXMIN, etc are coupled */ +#define TH_CONE 9 /* cone defined by S_CONE */ + +/* temperature schedules */ + +#define TS_EXPONENTIAL 0 /* temperature follows an exponential in time */ +#define TS_CYCLING 1 /* temperature cycling */ +#define TS_PERIODIC 2 /* periodic time dependence */ +#define TS_LINEAR 3 /* linear time dependence */ +#define TS_COSINE 4 /* periodic time dependence, cosine */ +#define TS_EXPCOS 5 /* periodic time dependence, exponential of cosine */ +#define TS_ASYM_EXPCOS 6 /* periodic time dependence, asymmetric exponential of cosine */ /* Gravity schedules */ #define G_INCREASE_RELEASE 1 /* slow increase and instant release */ -#define G_INCREASE_DECREASE 2 /* slow increase an decrease */ +#define G_INCREASE_DECREASE 2 /* slow increase and decrease */ /* Rocket shapes */ @@ -170,9 +187,14 @@ #define CHEM_BZ 14 /* simplified Belousov-Zhabotinski reaction with 6 types (Oregonator) */ #define CHEM_BRUSSELATOR 15 /* Brusselator oscillating reaction */ #define CHEM_ABDACBE 16 /* A + B -> D, A + C -> B + E */ +#define CHEM_H2O_H_OH 20 /* H2O <-> H+ + OH- */ +#define CHEM_2H2O_H3O_OH 21 /* 2 H2O <-> H3O+ + OH- */ +#define CHEM_AGGREGATION 22 /* agregation of molecules coming close */ +#define CHEM_AGGREGATION_CHARGE 23 /* agregation of charged molecules coming close */ /* Initial conditions for chemical reactions */ +#define IC_NOTHING 99 /* do not change particle types */ #define IC_UNIFORM 0 /* all particles have type 1 */ #define IC_UNIFORM2 20 /* all particles have type 2 */ #define IC_RANDOM_UNIF 1 /* particle type chosen uniformly at random */ @@ -212,8 +234,13 @@ #define P_INITIAL_POS 11 /* colors depend on initial position of particle */ #define P_NUMBER 12 /* colors depend on particle number */ #define P_EMEAN 13 /* averaged kinetic energy (with exponential damping) */ +#define P_LOG_EMEAN 131 /* log of averaged kinetic energy (with exponential damping) */ #define P_DIRECT_EMEAN 14 /* averaged version of P_DIRECT_ENERGY */ #define P_NOPARTICLE 15 /* particles are not drawn (only the links between them) */ +#define P_NPARTNERS 16 /* number of partners */ +#define P_CHARGE 17 /* colors represent charge */ +#define P_MOL_ANGLE 18 /* orientation of molecule defined by partners */ +#define P_CLUSTER 19 /* colors depend on connected component */ /* Rotation schedules */ @@ -230,6 +257,12 @@ #define POLY_STAR 0 /* star-shaped graph (central molecule attracts outer ones) */ #define POLY_ALL 1 /* all-to-all coupling */ #define POLY_WATER 2 /* star-shaped with a 120° separation between anions */ +#define POLY_SOAP 3 /* polymers with all-to-all coupling and polar end */ +#define POLY_SOAP_B 4 /* polymers with pairwise coupling and polar end */ +#define POLY_PLUSMINUS 5 /* polymers with ends of opposite charge */ +#define POLY_HYDRA 6 /* star-shaped with longer arms */ +#define POLY_HYDRA_RIGID 61 /* star-shaped with longer arms and rigid first ring */ +// #define POLY_GLUE 99 /* dummy value for option CHEM_AGGREGATION */ /* Background color schemes */ @@ -239,6 +272,11 @@ #define BG_EKIN 3 /* background color depends on kinetic energy */ #define BG_FORCE 4 /* background color depends on total force */ +/* Particle add regions */ + +#define ADD_RECTANGLE 0 /* rectangular region, defined by ADDXMIN, etc */ +#define ADD_RING 1 /* ring_shaped region, defined by ADDRMIN, ADDRMAX */ + /* Color schemes */ #define C_LUM 0 /* color scheme modifies luminosity (with slow drift of hue) */ @@ -300,9 +338,12 @@ typedef struct double spin_freq; /* angular frequency of spin-spin interaction */ double color_hue; /* color hue of particle, for P_INITIAL_POS plot type */ int color_rgb[3]; /* RGB colors code of particle, for use in ljones_movie.c */ - int partner[NMAXPARTNERS]; /* partners particle for option PAIR_PARTICLES */ + int partner[NMAXPARTNERS]; /* partner particles for option PAIR_PARTICLES */ short int npartners; /* number of partner particles */ double partner_eqd[NMAXPARTNERS]; /* equilibrium distances between partners */ + int p0, p1; /* numbers of two first partners (for P_MOL_ANGLE color scheme) */ + int cluster; /* number of cluster */ + short int tested, cactive; /* for cluster search */ } t_particle; typedef struct @@ -410,7 +451,10 @@ typedef struct double bdry_fx, bdry_fy; /* components of boundary force */ double efield, bfield; /* electric and magnetic field */ double prop; /* proportion of types */ + double thermo_radius; /* radius of thermostat region */ } t_lj_parameters; + + int ncircles, nobstacles, nsegments, ngroups = 1, counter = 0; diff --git a/global_pdes.c b/global_pdes.c index 540e7ea..c803139 100644 --- a/global_pdes.c +++ b/global_pdes.c @@ -69,6 +69,9 @@ #define D_WAVEGUIDES_W 521 /* two W-shaped wave guides */ #define D_WAVEGUIDES_COUPLED 522 /* two coupled wave guides */ #define D_WAVEGUIDE_S 523 /* S-shaped wave guide */ +#define D_WAVEGUIDE_S_SHORT 524 /* short S-shaped wave guide */ +#define D_WAVEGUIDES_COUPLED_N 525 /* two coupled wave guides, narrow variant */ +#define D_WAVEGUIDE_BADSPLICE 526 /* badly spliced fibers, to use with IOR_WAVE_GUIDE_COATED */ #define D_MAZE 53 /* maze */ #define D_MAZE_CLOSED 54 /* closed maze */ #define D_MAZE_CHANNELS 541 /* maze with two channels attached */ @@ -95,6 +98,9 @@ #define D_TESLA_FOUR 72 /* four Tesla valves */ #define D_TREE 73 /* Christmas tree, to use with IOR_TREE */ +#define D_MICHELSON 74 /* Michelson interferometer, to use with IOR_MICHELSON */ +#define D_MICHELSON_MOVING 741 /* moving Michelson interferometer, to use with IOR_MICHELSON */ +#define D_RITCHEY_CHRETIEN 75 /* Ritchey-Chrétien telescope */ /* for wave_sphere.c */ @@ -176,6 +182,9 @@ #define IOR_LENS_CONVEX_CONCAVE 13 /* lens with separating wall (to use with D_LENS_CONVEX_CONCAVE) */ #define IOR_TREE 14 /* Christmas tree, to use with D_TREE */ #define IOR_WAVE_GUIDES_COUPLED 15 /* coupled wave guides */ +#define IOR_WAVE_GUIDES_COUPLED_B 151 /* coupled wave guides, variant where only corners are reflecting */ +#define IOR_WAVE_GUIDE_COATED 16 /* short coated S-shaped optical fiber, to use with D_WAVEGUIDE_S_SHORT */ +#define IOR_MICHELSON 17 /* Michelson interferometer, to use with D_MICHELSON */ #define IOR_EARTH_DEM 20 /* digital elevation model (for waves on sphere) */ @@ -196,12 +205,17 @@ #define OSC_SLOWING 1 /* oscillation of slowing frequency (anti-chirp) */ #define OSC_WAVE_PACKET 2 /* Gaussian wave packet */ #define OSC_CHIRP 3 /* chirp (linearly accelerating frequency) */ +#define OSC_BEAM 4 /* periodic oscillation modulated by y cut-off */ +#define OSC_BEAM_GAUSSIAN 41 /* periodic oscillation modulated by Gaussian in y */ +#define OSC_BEAM_SINE 42 /* periodic oscillation modulated by sine in y */ +#define OSC_BEAM_TWOPERIODS 5 /* sum of two periodic oscillations modulated by y cut-off */ /* Wave packet types */ #define WP_RANDOM1 0 /* random, variant 1 */ #define WP_RANDOM2 1 /* random, variant 2 */ #define WP_PAIR 2 /* 2 sources */ +#define WP_FIVE 3 /* 5 sources with different envelope */ /* Wave packet envelope types */ @@ -224,6 +238,8 @@ #define P_LOG_MEAN_ENERGY 5 /* log of energy averaged over time */ #define P_ENERGY_FLUX 6 /* energy flux */ #define P_TOTAL_ENERGY_FLUX 7 /* energy flux averaged over time */ +#define P_AVERAGE_ENERGY 8 /* energy averaged over sliding window */ +#define P_LOG_AVERAGE_ENERGY 9 /* log of energy averaged over sliding window */ /* For Schrodinger equation */ #define P_MODULE 10 /* plot module of wave function squared */ @@ -425,3 +441,5 @@ t_vertex polyline_b[NMAXPOLY]; /* vertices of polygonal line */ // double julia_x = -0.5, julia_y = 0.5; /* parameters for Julia sets */ // double julia_x = 0.33267, julia_y = 0.06395; /* parameters for Julia sets */ double julia_x = 0.37468, julia_y = 0.21115; /* parameters for Julia sets */ +double wave_source_x, wave_source_y; /* position of wave source */ +double michelson_position = 0.0; /* position of mirror in Michelson interferometer */ diff --git a/heat.c b/heat.c index 2a0e991..f93ee6f 100644 --- a/heat.c +++ b/heat.c @@ -218,6 +218,15 @@ #define GAMMAB 0.0 /* damping factor in wave equation */ #define DRAW_WAVE_PROFILE 0 /* set to 1 to draw a profile of the wave */ #define VERTICAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ +#define WALL_WIDTH 0.1 /* width of wall separating lenses */ +#define INITIAL_TIME 50 /* time after which to start saving frames */ +#define OSCIL_YMAX 0.35 /* defines oscillation range */ +#define MESSAGE_LDASH 14 /* length of dash for Morse code message */ +#define MESSAGE_LDOT 8 /* length of dot for Morse code message */ +#define MESSAGE_LINTERVAL 54 /* length of interval between dashes/dots for Morse code message */ +#define MESSAGE_LINTERLETTER 60 /* length of interval between letters for Morse code message */ +#define MESSAGE_LSPACE 48 /* length of space for Morse code message */ +#define MESSAGE_INITIAL_TIME 100 /* initial time before starting message for Morse code message */ /* end of constants only used by sub_wave and sub_maze */ #include "global_pdes.c" diff --git a/lennardjones.c b/lennardjones.c index f9c33e3..7653aec 100644 --- a/lennardjones.c +++ b/lennardjones.c @@ -36,8 +36,8 @@ #include #include -#define MOVIE 0 /* set to 1 to generate movie */ -#define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */ +#define MOVIE 0 /* set to 1 to generate movie */ +#define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */ #define SAVE_MEMORY 1 /* set to 1 to save memory while saving frames */ #define NO_EXTRA_BUFFER_SWAP 1 /* some OS require one less buffer swap when recording images */ @@ -50,23 +50,32 @@ /* General geometrical parameters */ -#define WINWIDTH 1600 /* window width */ -#define WINHEIGHT 900 /* window height */ +// #define WINWIDTH 1440 /* window width */ +// #define WINHEIGHT 810 /* window height */ +#define WINWIDTH 1760 /* window width */ +#define WINHEIGHT 990 /* window height */ #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 INITXMIN -2.0 -#define INITXMAX 2.0 /* x interval for initial condition */ -#define INITYMIN -1.125 -#define INITYMAX 1.125 /* y interval for initial condition */ +#define INITXMIN -1.9 +#define INITXMAX 2.1 /* x interval for initial condition */ +#define INITYMIN -1.0 +#define INITYMAX 1.0 /* y interval for initial condition */ -#define ADDXMIN 1.9 -#define ADDXMAX 2.0 /* x interval for adding particles */ -#define ADDYMIN -0.9 -#define ADDYMAX 0.9 /* y interval for adding particles */ +#define THERMOXMIN -1.25 +#define THERMOXMAX 1.25 /* x interval for initial condition */ +#define THERMOYMIN 0.0 +#define THERMOYMAX 0.75 /* y interval for initial condition */ + +#define ADDXMIN -1.95 +#define ADDXMAX 1.95 /* x interval for adding particles */ +#define ADDYMIN 1.4 +#define ADDYMAX 3.7 /* y interval for adding particles */ +#define ADDRMIN 4.75 +#define ADDRMAX 6.0 /* r interval for adding particles */ #define BCXMIN -2.0 #define BCXMAX 2.0 /* x interval for boundary condition */ @@ -85,34 +94,37 @@ #define OBSTACLE_PATTERN 6 /* pattern of obstacles, see list in global_ljones.c */ #define ADD_FIXED_SEGMENTS 0 /* set to 1 to add fixed segments as obstacles */ -#define SEGMENT_PATTERN 27 /* pattern of repelling segments, see list in global_ljones.c */ +#define SEGMENT_PATTERN 29 /* pattern of repelling segments, see list in global_ljones.c */ #define ROCKET_SHAPE 3 /* shape of rocket combustion chamber, see list in global_ljones.c */ #define ROCKET_SHAPE_B 3 /* shape of second rocket */ #define NOZZLE_SHAPE 6 /* shape of nozzle, see list in global_ljones.c */ #define NOZZLE_SHAPE_B 6 /* shape of nozzle for second rocket, see list in global_ljones.c */ #define TWO_TYPES 1 /* set to 1 to have two types of particles */ -#define TYPE_PROPORTION 1.0 /* proportion of particles of first type */ +#define TYPE_PROPORTION 0.5 /* proportion of particles of first type */ #define TWOTYPE_CONFIG 0 /* choice of types, see TTC_ list in global_ljones.c */ #define SYMMETRIZE_FORCE 1 /* set to 1 to symmetrize two-particle interaction, only needed if particles are not all the same */ #define CENTER_PX 0 /* set to 1 to center horizontal momentum */ #define CENTER_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_B 1 /* particle interaction for second type of particle, see list in global_ljones.c */ #define INTERACTION 12 /* particle interaction, see list in global_ljones.c */ #define INTERACTION_B 12 /* particle interaction for second type of particle, see list in global_ljones.c */ #define SPIN_INTER_FREQUENCY 4.0 /* angular frequency of spin-spin interaction */ #define SPIN_INTER_FREQUENCY_B 4.0 /* angular frequency of spin-spin interaction for second particle type */ +#define MOL_ANGLE_FACTOR 4.0 /* rotation angle for P_MOL_ANGLE color scheme */ #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 2.8 /* minimal distance in Poisson disc process, controls density of particles */ +#define PDISC_DISTANCE 9.0 /* 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.2 /* parameter controlling the dimensions of domain */ -#define MU 0.01 /* parameter controlling radius of particles */ -#define MU_B 0.012 /* parameter controlling radius of particles of second type */ +#define LAMBDA 0.75 /* parameter controlling the dimensions of domain */ +#define MU 0.009 /* parameter controlling radius of particles */ +#define MU_B 0.009 /* parameter controlling radius of particles of second type */ #define NPOLY 40 /* number of sides of polygon */ #define APOLY 0.0 /* angle by which to turn polygon, in units of Pi/2 */ #define AWEDGE 0.5 /* opening angle of wedge, in units of Pi/2 */ @@ -121,14 +133,14 @@ #define MANDELLEVEL 1000 /* iteration level for Mandelbrot set */ #define MANDELLIMIT 10.0 /* limit value for approximation of Mandelbrot set */ #define FOCI 1 /* set to 1 to draw focal points of ellipse */ -#define NGRIDX 60 /* number of grid point for grid of disks */ -#define NGRIDY 30 /* number of grid point for grid of disks */ +#define NGRIDX 20 /* number of grid point for grid of disks */ +#define NGRIDY 10 /* number of grid point for grid of disks */ #define EHRENFEST_RADIUS 0.9 /* radius of container for Ehrenfest urn configuration */ #define EHRENFEST_WIDTH 0.035 /* width of tube for Ehrenfest urn configuration */ #define TWO_CIRCLES_RADIUS_RATIO 0.8 /* ratio of radii for S_TWO_CIRCLES_EXT segment configuration */ #define DAM_WIDTH 0.05 /* width of dam for S_DAM segment configuration */ -#define NOBSX 30 -#define NOBSY 20 /* obstacles for O_HEX obstacle pattern */ +#define NOBSX 10 +#define NOBSY 5 /* obstacles for O_HEX obstacle pattern */ #define NTREES 15 /* number of trees in S_TREES */ #define X_SHOOTER -0.2 @@ -138,11 +150,12 @@ /* Parameters for length and speed of simulation */ -#define NSTEPS 2400 /* number of frames of movie */ -#define NVID 30 /* number of iterations between images displayed on screen */ -#define NSEG 25 /* number of segments of boundary of circles */ +#define NSTEPS 1600 /* number of frames of movie */ +// #define NSTEPS 7275 /* number of frames of movie */ +#define NVID 65 /* number of iterations between images displayed on screen */ +#define NSEG 25 /* number of segments of boundary of circles */ #define INITIAL_TIME 0 /* time after which to start saving frames */ -#define OBSTACLE_INITIAL_TIME 150 /* time after which to start moving obstacle */ +#define OBSTACLE_INITIAL_TIME 0 /* time after which to start moving obstacle */ #define BOUNDARY_WIDTH 1 /* width of particle boundary */ #define LINK_WIDTH 2 /* width of links between particles */ #define CONTAINER_WIDTH 2 /* width of container boundary */ @@ -152,7 +165,8 @@ #define SLEEP1 1 /* initial sleeping time */ #define SLEEP2 1 /* final sleeping time */ #define MID_FRAMES 20 /* number of still frames between parts of two-part movie */ -#define END_FRAMES 250 /* number of still frames at end of movie */ +// #define END_FRAMES 250 /* number of still frames at end of movie */ +#define END_FRAMES 100 /* number of still frames at end of movie */ /* Boundary conditions, see list in global_ljones.c */ @@ -160,14 +174,15 @@ /* Plot type, see list in global_ljones.c */ -#define PLOT 5 -#define PLOT_B 13 /* plot type for second movie */ +#define PLOT 19 +// #define PLOT_B 1 /* plot type for second movie */ +#define PLOT_B 18 /* plot type for second movie */ /* Background color depending on particle properties */ -#define COLOR_BACKGROUND 1 /* set to 1 to color background */ -#define BG_COLOR 2 /* type of background coloring, see list in global_ljones.c */ -#define BG_COLOR_B 0 /* type of background coloring, see list in global_ljones.c */ +#define COLOR_BACKGROUND 0 /* set to 1 to color background */ +#define BG_COLOR 0 /* type of background coloring, see list in global_ljones.c */ +#define BG_COLOR_B 2 /* type of background coloring, see list in global_ljones.c */ #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 */ @@ -175,19 +190,21 @@ #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 */ #define N_PARTICLE_COLORS 200 /* number of colors for P_NUMBER color scheme */ -#define INITIAL_POS_TYPE 0 /* type of initial position dependence */ +#define INITIAL_POS_TYPE 0 /* type of initial position dependence */ #define ERATIO 0.995 /* ratio for time-averaging in P_EMEAN color scheme */ #define DRATIO 0.995 /* ratio for time-averaging in P_DIRECT_EMEAN color scheme */ /* Color schemes */ -#define COLOR_PALETTE 10 /* Color palette, see list in global_ljones.c */ -#define COLOR_PALETTE_EKIN 10 /* Color palette for kinetic energy */ -#define COLOR_PALETTE_ANGLE 10 /* Color palette for angle representation */ -#define COLOR_PALETTE_DIRECTION 17 /* Color palette for direction representation */ -#define COLOR_PALETTE_INITIAL_POS 0 /* Color palette for initial position representation */ +#define COLOR_PALETTE 10 /* Color palette, see list in global_ljones.c */ +#define COLOR_PALETTE_EKIN 10 /* Color palette for kinetic energy */ +#define COLOR_PALETTE_ANGLE 0 /* Color palette for angle representation */ +#define COLOR_PALETTE_DIRECTION 0 /* Color palette for direction representation */ +#define COLOR_PALETTE_INITIAL_POS 10 /* Color palette for initial position representation */ #define COLOR_PALETTE_DIFFNEIGH 10 /* Color palette for different neighbours representation */ -#define COLOR_PALETTE_PRESSURE 11 /* Color palette for different neighbours representation */ +#define COLOR_PALETTE_PRESSURE 11 /* Color palette for different neighbours representation */ +#define COLOR_PALETTE_CHARGE 18 /* Color palette for charge representation */ +#define COLOR_PALETTE_CLUSTER 0 /* Color palette for cluster representation */ #define BLACK 1 /* background */ @@ -222,27 +239,29 @@ #define ENERGY_HUE_MAX 50.0 /* color of saturated particle */ #define PARTICLE_HUE_MIN 359.0 /* color of original particle */ #define PARTICLE_HUE_MAX 0.0 /* color of saturated particle */ -#define PARTICLE_EMAX 10000.0 /* energy of particle with hottest color */ -#define HUE_TYPE0 60.0 /* hue of particles of type 0 */ +// #define PARTICLE_EMAX 50000.0 /* energy of particle with hottest color */ +#define PARTICLE_EMIN 10.0 /* energy of particle with coolest color */ +#define PARTICLE_EMAX 50000.0 /* energy of particle with hottest color */ +#define HUE_TYPE0 280.0 /* hue of particles of type 0 */ #define HUE_TYPE1 280.0 /* hue of particles of type 1 */ -#define HUE_TYPE2 140.0 /* hue of particles of type 2 */ -#define HUE_TYPE3 200.0 /* hue of particles of type 3 */ +#define HUE_TYPE2 70.0 /* hue of particles of type 2 */ +#define HUE_TYPE3 60.0 /* hue of particles of type 3 */ #define BG_FORCE_SLOPE 7.5e-8 /* contant in BG_FORCE backgound color scheme*/ #define RANDOM_RADIUS 0 /* set to 1 for random circle radius */ #define DT_PARTICLE 3.0e-6 /* time step for particle displacement */ -#define KREPEL 50.0 /* constant in repelling force between particles */ +#define KREPEL 150.0 /* constant in repelling force between particles */ #define EQUILIBRIUM_DIST 5.0 /* Lennard-Jones equilibrium distance */ #define EQUILIBRIUM_DIST_B 5.0 /* Lennard-Jones equilibrium distance for second type of particle */ -#define REPEL_RADIUS 20.0 /* radius in which repelling force acts (in units of particle radius) */ -#define DAMPING 3000.0 /* damping coefficient of particles */ +#define REPEL_RADIUS 25.0 /* radius in which repelling force acts (in units of particle radius) */ +#define DAMPING 20.0 /* damping coefficient of particles */ #define INITIAL_DAMPING 5000.0 /* damping coefficient of particles during initial phase */ #define DAMPING_ROT 100.0 /* dampint coefficient for rotation of particles */ -#define PARTICLE_MASS 2.0 /* mass of particle of radius MU */ -#define PARTICLE_MASS_B 1.0 /* mass of particle of radius MU */ +#define PARTICLE_MASS 1.0 /* mass of particle of radius MU */ +#define PARTICLE_MASS_B 2.0 /* mass of particle of radius MU_B */ #define PARTICLE_INERTIA_MOMENT 0.2 /* moment of inertia of particle */ #define PARTICLE_INERTIA_MOMENT_B 0.02 /* moment of inertia of second type of particle */ -#define V_INITIAL -50.0 /* initial velocity range */ +#define V_INITIAL 50.0 /* initial velocity range */ #define OMEGA_INITIAL 10.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 */ @@ -252,32 +271,33 @@ #define THERMOSTAT 1 /* 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.00004 /* initial inverse temperature */ -#define MU_XI 0.01 /* friction constant in thermostat */ +#define BETA 0.0005 /* initial inverse temperature */ +#define MU_XI 0.005 /* friction constant in thermostat */ #define KSPRING_BOUNDARY 2.0e11 /* confining harmonic potential outside simulation region */ #define KSPRING_OBSTACLE 2.0e11 /* harmonic potential of obstacles */ -#define NBH_DIST_FACTOR 3.2 /* radius in which to count neighbours */ +#define NBH_DIST_FACTOR 5.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 CIRCULAR_GRAVITY 0 /* set to 1 to have gravity directed to center */ #define INCREASE_GRAVITY 0 /* set to 1 to increase gravity during the simulation */ -#define GRAVITY_SCHEDULE 2 /* type of gravity schedule, see list in global_ljones.c */ -#define GRAVITY_FACTOR 100.0 /* factor by which to increase gravity */ +#define GRAVITY_SCHEDULE 1 /* type of gravity schedule, see list in global_ljones.c */ +#define GRAVITY_FACTOR 10.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 GRAVITY_RESTORE_TIME 500 /* time at end of simulation with gravity restored to initial value */ #define KSPRING_VICSEK 0.2 /* spring constant for I_VICSEK_SPEED interaction */ #define VICSEK_REPULSION 10.0 /* repulsion between particles in Vicsek model */ #define ADD_EFIELD 0 /* set to 1 to add an electric field */ -#define EFIELD 200000.0 /* value of electric field */ +#define EFIELD 50000.0 /* value of electric field */ #define ADD_BFIELD 0 /* set to 1 to add a magnetic field */ -#define BFIELD 10000.0 /* value of magnetic field */ -#define CHARGE 1.5 /* charge of particles of first type */ -#define CHARGE_B -1.0 /* charge of particles of second type */ +#define BFIELD 2.666666667 /* value of magnetic field */ +#define CHARGE -0.0 /* charge of particles of first type */ +#define CHARGE_B 0.0 /* charge of particles of second type */ #define INCREASE_E 0 /* set to 1 to increase electric field */ -#define EFIELD_FACTOR 1000000.0 /* factor by which to increase electric field */ +// #define EFIELD_FACTOR 2500000.0 /* factor by which to increase electric field */ +#define EFIELD_FACTOR 5000000.0 /* factor by which to increase electric field */ #define INCREASE_B 0 /* set to 1 to increase magnetic field */ -#define BFIELD_FACTOR 10000.0 /* factor by which to increase magnetic field */ +#define BFIELD_FACTOR 20000.0 /* factor by which to increase magnetic field */ #define CHARGE_OBSTACLES 1 /* set to 1 for obstacles to be charged */ #define OBSTACLE_CHARGE 3.0 /* charge of obstacles */ #define KCOULOMB_OBSTACLE 1000.0 /* Coulomb force constant for charged obstacles */ @@ -292,23 +312,27 @@ #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 DRAW_MINUS 1 /* set to 1 to draw cross on particles of negative charge */ #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 */ -#define INCREASE_BETA 1 /* set to 1 to increase BETA during simulation */ -#define BETA_FACTOR 5.0 /* factor by which to change BETA during simulation */ -#define N_TOSCILLATIONS 2.5 /* number of temperature oscillations in BETA schedule */ +#define INCREASE_BETA 0 /* set to 1 to increase BETA during simulation */ +#define BETA_SCHEDULE 0 /* type of temperature schedule, see TS_* in global_ljones */ +// #define BETA_FACTOR 0.000001 /* factor by which to change BETA during simulation */ +#define BETA_FACTOR 1000.0 /* factor by which to change BETA during simulation */ +#define N_TOSCILLATIONS 1.0 /* number of temperature oscillations in BETA schedule */ #define NO_OSCILLATION 0 /* set to 1 to have exponential BETA change only */ #define MIDDLE_CONSTANT_PHASE 0 /* final phase in which temperature is constant */ #define FINAL_DECREASE_PHASE 0 /* final phase in which temperature decreases */ #define FINAL_CONSTANT_PHASE -1 /* final phase in which temperature is constant */ #define DECREASE_CONTAINER_SIZE 0 /* set to 1 to decrease size of container */ +#define SMOOTH_CONTAINER_DECREASE 1 /* set to 1 to decrease size smoothly at each simulation step */ #define SYMMETRIC_DECREASE 0 /* set tp 1 to decrease container symmetrically */ -#define COMPRESSION_RATIO 0.3 /* final size of container */ +#define COMPRESSION_RATIO 0.25 /* final size of container */ #define RESTORE_CONTAINER_SIZE 1 /* set to 1 to restore container to initial size at end of simulation */ -#define RESTORE_TIME 1200 /* time before end of sim at which to restore size */ +#define RESTORE_TIME 800 /* time before end of sim at which to restore size */ #define MOVE_OBSTACLE 0 /* set to 1 to have a moving obstacle */ #define CENTER_VIEW_ON_OBSTACLE 0 /* set to 1 to center display on moving obstacle */ @@ -324,10 +348,12 @@ #define N_T_AVERAGE 1 /* size of temperature averaging window */ #define MAX_PRESSURE 3.0e10 /* pressure shown in "hottest" color */ #define PARTIAL_THERMO_COUPLING 0 /* set to 1 to couple only some particles to thermostat */ -#define PARTIAL_THERMO_REGION 1 /* region for partial thermostat coupling (see list in global_ljones.c) */ +#define PARTIAL_THERMO_REGION 9 /* region for partial thermostat coupling (see list in global_ljones.c) */ #define PARTIAL_THERMO_SHIFT 0.2 /* distance from obstacle at the right of which particles are coupled to thermostat */ -#define PARTIAL_THERMO_WIDTH 0.5 /* vertical size of partial thermostat coupling */ -#define PARTIAL_THERMO_HEIGHT 0.25 /* vertical size of partial thermostat coupling */ +#define PARTIAL_THERMO_WIDTH 1.0 /* vertical size of partial thermostat coupling */ +#define PARTIAL_THERMO_HEIGHT 0.0 /* vertical size of partial thermostat coupling */ +#define PARTIAL_THERMO_RIN 0.5 /* initial radius of region without coupling */ +#define PARTIAL_THERMO_RFIN 1.3 /* final radius of region without coupling */ #define INCREASE_KREPEL 0 /* set to 1 to increase KREPEL during simulation */ #define KREPEL_FACTOR 1000.0 /* factor by which to change KREPEL during simulation */ @@ -337,11 +363,12 @@ #define NPART_BOTTOM 100 /* number of particles at the bottom */ #define ADD_PARTICLES 0 /* set to 1 to add particles */ +#define ADD_REGION 0 /* shape of add regions, cf ADD_* in global_ljones */ #define ADD_TIME 0 /* time at which to add first particle */ -#define ADD_PERIOD 4 /* time interval between adding further particles */ -#define N_ADD_PARTICLES 3 /* number of particles to add */ +#define ADD_PERIOD 5 /* time interval between adding further particles */ +#define N_ADD_PARTICLES 5 /* number of particles to add */ #define FINAL_NOADD_PERIOD 0 /* final period where no particles are added */ -#define SAFETY_FACTOR 2.0 /* no particles are added at distance less than MU*SAFETY_FACTOR of other particles */ +#define SAFETY_FACTOR 4.0 /* no particles are added at distance less than MU*SAFETY_FACTOR of other particles */ #define TRACER_PARTICLE 0 /* set to 1 to have a tracer particle */ #define N_TRACER_PARTICLES 3 /* number of tracer particles */ @@ -368,7 +395,7 @@ #define SEGMENTS_VX0 0.0 /* initial velocity of segments */ #define SEGMENTS_VY0 0.0 /* initial velocity of segments */ #define DAMP_SEGS_AT_NEGATIVE_Y 0 /* set to 1 to dampen segments when y coordinate is negative */ -#define SHOW_SEGMENTS_PRESSURE 1 /* set to 1 to show (averaged) pressure acting on segments */ +#define SHOW_SEGMENTS_PRESSURE 0 /* set to 1 to show (averaged) pressure acting on segments */ #define SEGMENT_PMAX 7.5e7 /* pressure of segment with hottest color */ #define P_AVRG_FACTOR 0.02 /* factor in computation of mean pressure */ @@ -390,24 +417,27 @@ #define POSITION_DEP_X -0.625 /* threshold value for position-dependent type */ #define PRINT_ENTROPY 0 /* set to 1 to compute entropy */ -#define REACTION_DIFFUSION 0 /* set to 1 to simulate a chemical reaction (particles may change type) */ -#define RD_REACTION 16 /* type of reaction, see list in global_ljones.c */ -#define RD_TYPES 5 /* number of types in reaction-diffusion equation */ -#define RD_INITIAL_COND 9 /* initial condition of particles */ -#define REACTION_DIST 4.0 /* maximal distance for reaction to occur */ -#define REACTION_PROB 1.0 /* probability controlling reaction term */ -#define DISSOCIATION_PROB 0.002 /* probability controlling dissociation reaction */ +#define REACTION_DIFFUSION 1 /* set to 1 to simulate a chemical reaction (particles may change type) */ +#define RD_REACTION 23 /* type of reaction, see list in global_ljones.c */ +#define RD_TYPES 2 /* number of types in reaction-diffusion equation */ +#define RD_INITIAL_COND 99 /* initial condition of particles */ +#define REACTION_DIST 3.5 /* maximal distance for reaction to occur */ +#define REACTION_PROB 1.0 /* probability controlling reaction term */ +#define DISSOCIATION_PROB 0.0001 /* probability controlling dissociation reaction */ #define CENTER_COLLIDED_PARTICLES 0 /* set to 1 to recenter particles upon reaction (may interfere with thermostat) */ -#define EXOTHERMIC 1 /* set to 1 to make reaction exo/endothermic */ -#define DELTA_EKIN 2000.0 /* change of kinetic energy in reaction */ -#define COLLISION_TIME 15 /* time during which collisions are shown */ +#define EXOTHERMIC 0 /* set to 1 to make reaction exo/endothermic */ +#define DELTA_EKIN 2000.0 /* change of kinetic energy in reaction */ +#define COLLISION_TIME 25 /* time during which collisions are shown */ +#define DELTAVMAX 150.0 /* maximal deltav allowed for pairing molecules */ +#define AGREGMAX 6 /* maximal number of partners for CHEM_AGGREGATION reaction */ +#define AGREG_DECOUPLE 10 /* minimal number of partners to decouple from thermostat */ #define CHANGE_RADIUS 0 /* set to 1 to change particle radius during simulation */ #define MU_RATIO 0.666666667 /* ratio by which to increase radius */ #define PRINT_PARTICLE_NUMBER 0 /* set to 1 to print total number of particles */ #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 PARTICLE_NB_PLOT_FACTOR 1.0 /* expected final number of particles over initial number */ #define PRINT_LEFT 0 /* 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) */ #define PLOT_TRAJECTORIES 0 /* set to 1 to add a plot of obstacle trajectories (e.g. for rockets) */ @@ -419,7 +449,7 @@ #define LID_WIDTH 0.1 /* width of lid for BC_RECTANGLE_LID b.c. */ #define WALL_MASS 2000.0 /* mass of wall for BC_RECTANGLE_WALL b.c. */ #define WALL_FRICTION 0.0 /* friction on wall for BC_RECTANGLE_WALL b.c. */ -#define WALL_WIDTH 0.1 /* width of wall for BC_RECTANGLE_WALL b.c. */ +#define WALL_WIDTH 0.025 /* width of wall for BC_RECTANGLE_WALL b.c. */ #define WALL_VMAX 100.0 /* max speed of wall */ #define WALL_TIME 0 /* time during which to keep wall */ @@ -428,10 +458,29 @@ #define PROP_MAX 0.9 /* max proportion of type 1 particles */ #define PAIR_PARTICLES 1 /* set to 1 to form particles pairs */ -#define KSPRING_PAIRS 1.0e10 /* spring constant for pair interaction */ -#define NPARTNERS 2 /* number of partners of particles */ -#define PAIRING_TYPE 1 /* type of pairing, see POLY_ in global_ljones.c */ -#define PARTNER_ANGLE 104.45 /* angle (in degrees) between anions for POLY_WATER case */ +#define RANDOMIZE_ANGLE 1 /* set to 1 for random orientation */ +#define DEACIVATE_CLOSE_PAIRS 0 /* set to 1 to test for closeness to other particles */ +#define PAIR_SAFETY_FACTOR 1.2 /* distance to deactivate divided by sum of radii */ +#define KSPRING_PAIRS 2.0e10 /* spring constant for pair interaction */ +#define NPARTNERS 16 /* number of partners of particles */ +#define NARMS 4 /* number of "arms" for certain paring types */ +#define PAIRING_TYPE 61 /* type of pairing, see POLY_ in global_ljones.c */ +#define PARTNER_ANGLE 104.45 /* angle (in degrees) between ions for POLY_WATER case */ +#define PAIR_DRATIO 1.0 /* ratio between equilibrium distance and radius (default: 1.0) */ +#define MU_C 0.014 /* radius of partner particle */ +#define PARTICLE_MASS_C 2.0 /* mass or partner particle */ +#define CHARGE_C 1.5 /* charge of partner particle */ +#define CLUSTER_COLOR_FACTOR 400 /* factor for initialization of cluster colors */ +#define ALTERNATE_POLY_CHARGE 1 /* set to 1 for alternating charges in molecule */ + +#define PAIR_TYPEB_PARTICLES 1 /* set to 1 to pair particle of type 1 */ +#define NPARTNERS_B 16 /* number of partners of particles */ +#define NARMS_B 4 /* number of "arms" for certain paring types */ +#define PAIRING_TYPE_B 61 /* type of pairing, see POLY_ in global_ljones.c */ +#define MU_D 0.014 /* radius of partner particle */ +#define PARTICLE_MASS_D 2.0 /* mass or partner particle */ +#define CHARGE_D -1.5 /* charge of partner particle */ +// #define PARTNER_ANGLE_B 104.45 /* angle (in degrees) between anions for POLY_WATER case */ #define NXMAZE 12 /* width of maze */ #define NYMAZE 12 /* height of maze */ @@ -445,8 +494,8 @@ #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 */ @@ -460,8 +509,10 @@ #define NO_WRAP_BC ((BOUNDARY_COND != BC_PERIODIC)&&(BOUNDARY_COND != BC_PERIODIC_CIRCLE)&&(BOUNDARY_COND != BC_PERIODIC_TRIANGLE)&&(BOUNDARY_COND != BC_KLEIN)&&(BOUNDARY_COND != BC_PERIODIC_FUNNEL)&&(BOUNDARY_COND != BC_BOY)&&(BOUNDARY_COND != BC_GENUS_TWO)) #define PERIODIC_BC ((BOUNDARY_COND == BC_PERIODIC)||(BOUNDARY_COND == BC_PERIODIC_CIRCLE)||(BOUNDARY_COND == BC_PERIODIC_FUNNEL)||(BOUNDARY_COND == BC_PERIODIC_TRIANGLE)) #define TWO_OBSTACLES ((SEGMENT_PATTERN == S_TWO_CIRCLES_EXT)||(SEGMENT_PATTERN == S_TWO_ROCKETS)) -#define COMPUTE_EMEAN ((PLOT == P_EMEAN)||(PLOT_B == P_EMEAN)||(PLOT == P_DIRECT_EMEAN)||(PLOT_B == P_DIRECT_EMEAN)) +#define COMPUTE_EMEAN ((PLOT == P_EMEAN)||(PLOT_B == P_EMEAN)||(PLOT == P_LOG_EMEAN)||(PLOT_B == P_LOG_EMEAN)||(PLOT == P_DIRECT_EMEAN)||(PLOT_B == P_DIRECT_EMEAN)) #define COMPUTE_DIRMEAN ((PLOT == P_DIRECT_EMEAN)||(PLOT_B == P_DIRECT_EMEAN)) +#define COUNT_PARTNER_TYPE ((RD_REACTION == CHEM_H2O_H_OH)||(RD_REACTION == CHEM_2H2O_H3O_OH)) +#define PAIR_FORCE ((PAIR_PARTICLES)||((REACTION_DIFFUSION)&&(RD_REACTION == CHEM_AGGREGATION))) double xshift = 0.0; /* x shift of shown window */ double xspeed = 0.0; /* x speed of obstacle */ @@ -519,10 +570,11 @@ double efield_schedule(int i) if (first) { - efactor = EFIELD_FACTOR/(double)(INITIAL_TIME + NSTEPS); + efactor = EFIELD_FACTOR/(double)(NSTEPS); first = 0; } - efield = EFIELD*(double)i*efactor; + if (i < INITIAL_TIME) efield = EFIELD; + else efield = EFIELD*(double)(i-INITIAL_TIME)*efactor; printf("E = %.3lg\n", efield); return(efield); } @@ -536,10 +588,11 @@ double bfield_schedule(int i) if (first) { - bfactor = BFIELD_FACTOR/(double)(INITIAL_TIME + NSTEPS); + bfactor = BFIELD_FACTOR/(double)(NSTEPS); first = 0; } - bfield = BFIELD*(double)i*bfactor; + if (i < INITIAL_TIME) bfield = BFIELD; + else bfield = BFIELD*(double)(i-INITIAL_TIME)*bfactor; printf("B = %.3lg\n", bfield); return(bfield); } @@ -547,9 +600,9 @@ double bfield_schedule(int i) double temperature_schedule(int i) { - static double bexponent, omega, bexp2; + static double bexponent, omega, bexp2, factor2, logf, ac, bc; static int first = 1, t1, t2, t3; - double beta; + double beta, t; if (first) { @@ -558,16 +611,103 @@ double temperature_schedule(int i) t3 = NSTEPS - FINAL_CONSTANT_PHASE; bexponent = log(BETA_FACTOR)/(double)(t1); omega = N_TOSCILLATIONS*DPI/(double)(t1); - bexp2 = -log(BETA_FACTOR)/(double)(FINAL_DECREASE_PHASE); + logf = log(BETA_FACTOR); + + switch (BETA_SCHEDULE) + { + case (TS_EXPONENTIAL): + { + factor2 = BETA_FACTOR; + break; + } + case (TS_CYCLING): + { + factor2 = BETA_FACTOR*2.0/(1.0 + cos(N_TOSCILLATIONS*DPI)); + break; + } + case (TS_PERIODIC): + { + factor2 = exp(logf*sin(N_TOSCILLATIONS*DPI)); + break; + } + case (TS_LINEAR): + { + factor2 = BETA_FACTOR; + break; + } + case (TS_COSINE): + { + factor2 = BETA_FACTOR; + ac = 2.0*BETA*BETA_FACTOR/(1.0 + BETA_FACTOR); + bc = (BETA_FACTOR - 1.0)/(1.0 + BETA_FACTOR); + break; + } + case (TS_EXPCOS): + { + factor2 = BETA_FACTOR; + bc = -0.5*log(BETA_FACTOR); + break; + } + case (TS_ASYM_EXPCOS): + { + factor2 = BETA_FACTOR; + bc = -0.5*log(BETA_FACTOR); + break; + } + } + bexp2 = -log(factor2)/(double)(FINAL_DECREASE_PHASE); first = 0; + +// printf("t1 = %i, factor2 = %.3lg\n", t1, factor2); } if (i < INITIAL_TIME) beta = BETA; else if (i < INITIAL_TIME + t1) { - beta = BETA*exp(bexponent*(double)(i - INITIAL_TIME)); - if (!NO_OSCILLATION) beta = beta*2.0/(1.0 + cos(omega*(double)(i - INITIAL_TIME))); + switch (BETA_SCHEDULE) + { + case (TS_EXPONENTIAL): + { + beta = BETA*exp(bexponent*(double)(i - INITIAL_TIME)); + break; + } + case (TS_CYCLING): + { + beta = BETA*exp(bexponent*(double)(i - INITIAL_TIME)); + beta = beta*2.0/(1.0 + cos(omega*(double)(i - INITIAL_TIME))); + break; + } + case (TS_PERIODIC): + { + beta = BETA*exp(logf*sin(omega*(double)(i - INITIAL_TIME))); + break; + } + case (TS_LINEAR): + { + beta = BETA/(1.0 + (1.0/BETA_FACTOR - 1.0)*(double)(i - INITIAL_TIME)/(double)(t1)); +// printf("i = %i, beta = %.3lg\n", i, beta); + break; + } + case (TS_COSINE): + { + beta = ac/(1.0 + bc*cos(omega*(double)(i - INITIAL_TIME))); + printf("i = %i, beta = %.3lg\n", i, beta); + break; + } + case (TS_EXPCOS): + { + beta = BETA*exp(bc*(-1.0 + cos(omega*(double)(i - INITIAL_TIME)))); +// printf("i = %i, beta = %.3lg\n", i, beta); + break; + } + case (TS_ASYM_EXPCOS): + { + t = (double)(i - INITIAL_TIME)/(double)(t1); + beta = BETA*exp(bc*(-1.0 + cos(N_TOSCILLATIONS*DPI*(t - 0.5*t*(1.0-t))))); + break; + } + } } - else if (i < INITIAL_TIME + t2) beta = BETA*BETA_FACTOR; + else if (i < INITIAL_TIME + t2) beta = BETA*factor2; else if (i < INITIAL_TIME + t3) { beta = BETA*exp(bexp2*(double)(i - INITIAL_TIME - t3)); @@ -584,6 +724,18 @@ double container_size_schedule(int i) return(INITXMIN + (1.0-COMPRESSION_RATIO)*(INITXMAX-INITXMIN)*(double)(i-INITIAL_TIME)/(double)(NSTEPS-RESTORE_TIME)); } +double container_size_schedule_smooth(int i, int j) +{ + double t; + + if ((i < INITIAL_TIME)||(i > INITIAL_TIME + NSTEPS - RESTORE_TIME)) return(INITXMIN); + else + { + t = (double)(i-INITIAL_TIME) + (double)j/(double)NVID; + return(INITXMIN + (1.0-COMPRESSION_RATIO)*(INITXMAX-INITXMIN)*t/(double)(NSTEPS-RESTORE_TIME)); + } +} + double obstacle_schedule_old(int i) { double time; @@ -1213,7 +1365,7 @@ 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, pos[2], prop, vx, xi = 0.0, torque, torque_ij, pleft = 0.0, pright = 0.0, entropy[2], speed_ratio, ymin, ymax, delta_energy, speed, ratio = 1.0, ratioc, cum_etot = 0.0, emean = 0.0, radius_ratio, t; + a, b, length, fx, fy, force[2], totalenergy = 0.0, pos[2], prop, vx, xi = 0.0, torque, torque_ij, pleft = 0.0, pright = 0.0, entropy[2], speed_ratio, xmin, xmax, ymin, ymax, delta_energy, speed, ratio = 1.0, ratioc, cum_etot = 0.0, emean = 0.0, radius_ratio, t; 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, nadd_particle = 0, nmove = 0, nsuccess = 0, @@ -1340,6 +1492,8 @@ void animation() if (INCREASE_BETA) params.beta = temperature_schedule(i); if (INCREASE_E) params.efield = efield_schedule(i); if (INCREASE_B) params.bfield = bfield_schedule(i); + if ((PARTIAL_THERMO_COUPLING)&&(PARTIAL_THERMO_REGION == TH_RING_EXPAND)) + params.thermo_radius = PARTIAL_THERMO_RIN + (double)i/(double)NSTEPS*(PARTIAL_THERMO_RFIN - PARTIAL_THERMO_RIN); if (DECREASE_CONTAINER_SIZE) { params.xmincontainer = container_size_schedule(i); @@ -1361,15 +1515,31 @@ void animation() if ((i <= INITIAL_TIME-1)&&(i%10 == 0)&&((PLOT == P_INITIAL_POS)||(PLOT_B == P_INITIAL_POS))) { printf("Recoloring particles\n"); + xmin = particle[0].xc; + xmax = particle[0].xc; ymin = particle[0].yc; ymax = particle[0].yc; for (j=1; j xmax) xmax = particle[j].xc; if (particle[j].yc < ymin) ymin = particle[j].yc; if (particle[j].yc > ymax) ymax = particle[j].yc; } for (j=0; jN_T_AVERAGE)) { - nthermo = partial_thermostat_coupling(particle, xshift + PARTIAL_THERMO_SHIFT, segment); + nthermo = partial_thermostat_coupling(particle, xshift + PARTIAL_THERMO_SHIFT, segment, params); printf("%i particles coupled to thermostat out of %i active\n", nthermo, params.nactive); params.mean_energy = compute_mean_energy(particle); } @@ -1643,14 +1827,14 @@ void animation() } if (TRACER_PARTICLE) draw_trajectory(trajectory, traj_position, traj_length); - draw_particles(particle, PLOT, params.beta, collisions, ncollisions, BG_COLOR, hashgrid); + draw_particles(particle, PLOT, params.beta, collisions, ncollisions, BG_COLOR, hashgrid, params); draw_container(params.xmincontainer, params.xmaxcontainer, obstacle, segment, wall); /* add a particle */ if ((ADD_PARTICLES)&&(i > ADD_TIME)&&((i - INITIAL_TIME - ADD_TIME)%ADD_PERIOD == 1)&&(i < NSTEPS - FINAL_NOADD_PERIOD)) { for (k=0; k INITIAL_TIME + WALL_TIME)&&(PRINT_ENTROPY)) { compute_entropy(particle, entropy); @@ -1688,20 +1862,19 @@ void animation() print_entropy(entropy); } - if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i); - if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i); - - else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle); - else if (PRINT_SEGMENTS_SPEEDS) + /* these should be moved to draw_frame */ + if (PRINT_SEGMENTS_SPEEDS) { if (MOVE_BOUNDARY) print_segments_speeds(vxsegments, vysegments); else print_segment_group_speeds(segment_group); } + if ((i > INITIAL_TIME)&&(PLOT_PARTICLE_NUMBER)) - { count_particle_number(particle, particle_numbers, i - INITIAL_TIME); - draw_particle_nb_plot(particle_numbers, i - INITIAL_TIME); - } + + draw_frame(i, PLOT, BG_COLOR, ncollisions, traj_position, traj_length, + wall, pressure, pleft, pright, particle_numbers, 1, params, particle, + collisions, hashgrid, trajectory, obstacle, segment, group_speeds, segment_group); if (!((NO_EXTRA_BUFFER_SWAP)&&(MOVIE))) glutSwapBuffers(); @@ -1731,22 +1904,9 @@ void animation() if ((i >= INITIAL_TIME)&&(DOUBLE_MOVIE)) { - if (TRACER_PARTICLE) draw_trajectory(trajectory, traj_position, traj_length); - draw_particles(particle, PLOT_B, params.beta, collisions, ncollisions, BG_COLOR_B, hashgrid); - draw_container(params.xmincontainer, params.xmaxcontainer, obstacle, segment, wall); - if (PRINT_PARAMETERS) print_parameters(params, PRINT_LEFT, pressure, 0); - if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i); - if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i); - if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright); - else if (PRINT_PARTICLE_NUMBER) - { - if (REACTION_DIFFUSION) - print_particle_types_number(particle, RD_TYPES); - else print_particle_number(ncircles); - } - 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); + draw_frame(i, PLOT_B, BG_COLOR_B, ncollisions, traj_position, traj_length, + wall, pressure, pleft, pright, particle_numbers, 0, params, particle, + collisions, hashgrid, trajectory, obstacle, segment, group_speeds, segment_group); glutSwapBuffers(); save_frame_lj_counter(NSTEPS + MID_FRAMES + 1 + counter); counter++; @@ -1783,23 +1943,9 @@ void animation() if (DOUBLE_MOVIE) { blank(); - if (TRACER_PARTICLE) draw_trajectory(trajectory, traj_position, traj_length); - draw_particles(particle, PLOT, params.beta, collisions, ncollisions, BG_COLOR, hashgrid); - draw_container(params.xmincontainer, params.xmaxcontainer, obstacle, segment, wall); - if (PRINT_PARAMETERS) print_parameters(params, PRINT_LEFT, pressure, 1); - if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i); - if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i); - if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright); - else if (PRINT_PARTICLE_NUMBER) - { - if (REACTION_DIFFUSION) - print_particle_types_number(particle, RD_TYPES); - else print_particle_number(ncircles); - } - 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(); + draw_frame(NSTEPS, PLOT, BG_COLOR, ncollisions, traj_position, traj_length, + wall, pressure, pleft, pright, particle_numbers, 0, params, particle, + collisions, hashgrid, trajectory, obstacle, segment, group_speeds, segment_group); } for (i=0; i 1.0) sum = 1.0; + if (sum < -1.0) sum = -1.0; + for (i=0; i 1.0) sum = 1.0; + if (sum < -1.0) sum = -1.0; + for (i=0; i= INITIAL_TIME)&&(DOUBLE_MOVIE)) { - draw_wave_rde(1, phi, xy_in, rde, potential_field, ZPLOT_B, CPLOT_B, COLOR_PALETTE_B, 0, 1.0, REFRESH_B); + draw_wave_rde(1, phi, xy_in, rde, wsphere, 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(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise); @@ -1880,7 +1938,7 @@ void animation() { if (DOUBLE_MOVIE) { - draw_wave_rde(0, phi, xy_in, rde, potential_field, ZPLOT, CPLOT, COLOR_PALETTE, 0, 1.0, 1); + draw_wave_rde(0, phi, xy_in, rde, wsphere, 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(phi, rde, xy_in, time, PRINT_LEFT, viscosity_printed, noise); @@ -1892,7 +1950,7 @@ void animation() else for (i=0; i 7) nnbg = 7; + switch(nnbg){ + case (7): return(340.0); + case (6): return(310.0); + case (5): return(260.0); + case (4): return(200.0); + case (3): return(140.0); + case (2): return(100.0); + case (1): return(70.0); + default: return(30.0); + } +} + + +double partner_color(int np) +{ + switch(np){ + case (0): return(70.0); + case (1): return(200.0); + case (2): return(280.0); + case (3): return(140.0); + case (4): return(320.0); + default: return(20.0); + } +} + + double type_hue(int type) { int hue; @@ -523,9 +579,12 @@ double type_hue(int type) switch (type) { case (0): return(HUE_TYPE0); - case (1): return(HUE_TYPE0); - case (2): return(HUE_TYPE1); - case (3): return(HUE_TYPE2); + case (1): return(HUE_TYPE1); + case (2): return(HUE_TYPE2); + case (3): return(HUE_TYPE3); +// case (1): return(HUE_TYPE0); +// case (2): return(HUE_TYPE1); +// case (3): return(HUE_TYPE2); default: { if (RD_REACTION == CHEM_BZ) @@ -546,7 +605,8 @@ void set_type_color(int type, double lum, double rgb[3]) { int hue; - hue = type_hue(type); + if (COUNT_PARTNER_TYPE) hue = partner_color(type-1); + else hue = type_hue(type); hsl_to_rgb_palette(hue, 0.9, 0.5, rgb, COLOR_PALETTE); glColor3f(lum*rgb[0], lum*rgb[1], lum*rgb[2]); } @@ -2478,6 +2538,22 @@ void init_segment_config(t_segment segment[NMAXSEGMENTS]) } break; } + case (S_BIN_LARGE): + { + add_rectangle_to_segments(LAMBDA, -MU, -LAMBDA, 0.0, segment, 0); + add_rectangle_to_segments(LAMBDA, -MU, LAMBDA - MU, 0.25, segment, 0); + add_rectangle_to_segments(-LAMBDA + MU, -MU, -LAMBDA, 0.25, segment, 0); + + cycle = 0; + concave = 0; /* add_rectangle_to_segments already deals with concave corners */ + + for (i=0; i 0) + { + printf("Deactivating particle cluster %i\n", i); + particle[i].active = 0; + for (l=0; l NMAXCIRCLES) + { + printf("Error: NMAXCIRCLES is too small\n"); + exit(1); + } + + for (i=0; i p) + { + particle[q].p0 = p; + particle[q].p1 = particle[p].partner[0]; + } + } + } + + printf("ncircles = %i\n", ncircles); + +// for (i=0; i 7) nnbg = 7; - switch(nnbg){ - case (7): return(340.0); - case (6): return(310.0); - case (5): return(260.0); - case (4): return(200.0); - case (3): return(140.0); - case (2): return(100.0); - case (1): return(70.0); - default: return(30.0); - } -} - - void compute_entropy(t_particle particle[NMAXCIRCLES], double entropy[2]) { int i, nleft1 = 0, nleft2 = 0; @@ -4193,10 +4735,10 @@ void compute_entropy(t_particle particle[NMAXCIRCLES], double entropy[2]) } -void compute_particle_colors(t_particle particle, int plot, double rgb[3], double rgbx[3], double rgby[3], double *radius, int *width) +void compute_particle_colors(t_particle particle, int plot, double rgb[3], double rgbx[3], double rgby[3], double *radius, int *width, t_particle other_particle[NMAXCIRCLES]) { - double ej, angle, hue, huex, huey, lum; - int i; + double ej, angle, hue, huex, huey, lum, x, y, cluster; + int i, k, p, q; switch (plot) { case (P_KINETIC): @@ -4326,6 +4868,22 @@ void compute_particle_colors(t_particle particle, int plot, double rgb[3], doubl *width = BOUNDARY_WIDTH; break; } + case (P_LOG_EMEAN): + { + ej = particle.emean; + if (ej > 0.0) + { + ej = log(ej/PARTICLE_EMIN)/log(PARTICLE_EMAX/PARTICLE_EMIN); + if (ej < 0.0) ej = 0.0; + else if (ej > 1.0) ej = 1.0; + hue = ENERGY_HUE_MIN + (ENERGY_HUE_MAX - ENERGY_HUE_MIN)*ej; +// if (hue > ENERGY_HUE_MIN) hue = ENERGY_HUE_MIN; +// if (hue < ENERGY_HUE_MAX) hue = ENERGY_HUE_MAX; + } + *radius = particle.radius; + *width = BOUNDARY_WIDTH; + break; + } case (P_DIRECT_EMEAN): { hue = particle.dirmean + COLOR_HUESHIFT*PI; @@ -4346,6 +4904,47 @@ void compute_particle_colors(t_particle particle, int plot, double rgb[3], doubl *width = BOUNDARY_WIDTH; break; } + case (P_NPARTNERS): + { + hue = partner_color(particle.npartners); + *radius = particle.radius; + *width = BOUNDARY_WIDTH; + break; + } + case (P_CHARGE): + { + hue = (-tanh(0.5*particle.charge)+1.0)*180.0; + *radius = particle.radius; + *width = BOUNDARY_WIDTH; + break; + } + case (P_MOL_ANGLE): + { + p = particle.p0; + q = particle.p1; + x = other_particle[q].xc - other_particle[p].xc; + y = other_particle[q].yc - other_particle[p].yc; + /* deal with periodic boundary conditions */ + if (x > 0.5*(XMAX - XMIN)) x -= (XMAX - XMIN); + else if (x < 0.5*(XMIN - XMAX)) x += (XMAX - XMIN); + if (y > 0.5*(YMAX - YMIN)) y -= (YMAX - YMIN); + else if (y < 0.5*(YMIN - YMAX)) y += (YMAX - YMIN); + angle = argument(x, y)*MOL_ANGLE_FACTOR; + while (angle > DPI) angle -= DPI; + while (angle < 0.0) angle += DPI; + hue = PARTICLE_HUE_MIN + (PARTICLE_HUE_MAX - PARTICLE_HUE_MIN)*(angle)/DPI; + *radius = particle.radius; + *width = BOUNDARY_WIDTH; + break; + } + case (P_CLUSTER): + { + cluster = (double)particle.cluster/(double)ncircles; + hue = PARTICLE_HUE_MIN + (PARTICLE_HUE_MAX - PARTICLE_HUE_MIN)*cluster; + *radius = particle.radius; + *width = BOUNDARY_WIDTH; + break; + } } switch (plot) { @@ -4417,6 +5016,13 @@ void compute_particle_colors(t_particle particle, int plot, double rgb[3], doubl hsl_to_rgb_palette(hue, 0.9, 0.5, rgby, COLOR_PALETTE_EKIN); break; } + case (P_LOG_EMEAN): + { + hsl_to_rgb_palette(hue, 0.9, 0.5, rgb, COLOR_PALETTE_EKIN); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgbx, COLOR_PALETTE_EKIN); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgby, COLOR_PALETTE_EKIN); + break; + } case (P_DIRECT_EMEAN): { hsl_to_rgb_palette(hue, 0.9, 0.5, rgb, COLOR_PALETTE_DIRECTION); @@ -4430,6 +5036,27 @@ void compute_particle_colors(t_particle particle, int plot, double rgb[3], doubl } break; } + case (P_CHARGE): + { + hsl_to_rgb_palette(hue, 0.9, 0.5, rgb, COLOR_PALETTE_CHARGE); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgbx, COLOR_PALETTE_CHARGE); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgby, COLOR_PALETTE_CHARGE); + break; + } + case (P_MOL_ANGLE): + { + hsl_to_rgb_palette(hue, 0.9, 0.5, rgb, COLOR_PALETTE_ANGLE); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgbx, COLOR_PALETTE_ANGLE); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgby, COLOR_PALETTE_ANGLE); + break; + } + case (P_CLUSTER): + { + hsl_to_rgb_palette(hue, 0.9, 0.5, rgb, COLOR_PALETTE_CLUSTER); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgbx, COLOR_PALETTE_CLUSTER); + hsl_to_rgb_palette(hue, 0.9, 0.5, rgby, COLOR_PALETTE_CLUSTER); + break; + } default: { hsl_to_rgb(hue, 0.9, 0.5, rgb); @@ -4569,7 +5196,7 @@ void draw_triangles(t_particle particle[NMAXCIRCLES], int plot) } else { - compute_particle_colors(particle[i], plot, rgb, rgbx, rgby, &radius, &width); + compute_particle_colors(particle[i], plot, rgb, rgbx, rgby, &radius, &width, particle); } glColor3f(rgb[0], rgb[1], rgb[2]); @@ -4979,7 +5606,7 @@ int draw_special_particle(t_particle particle, double xc1, double yc1, double ra void draw_one_particle(t_particle particle, double xc, double yc, double radius, double angle, int nsides, double width, double rgb[3]) /* draw one of the particles */ { - double x1, x2, y1, y2, xc1, yc1, wangle, newradius = radius; + double x1, x2, y1, y2, xc1, yc1, wangle, newradius = radius, pradius; int wsign, cont = 1, draw = 1; static double ca, sa; static int first = 1; @@ -5013,11 +5640,12 @@ void draw_one_particle(t_particle particle, double xc, double yc, double radius, else draw_colored_polygon(xc1, yc1, radius, nsides, angle + APOLY*PID, rgb); } - /* draw crosses on particles of second type */ - if ((TWO_TYPES)&&(DRAW_CROSS)) -// if (particle.type == 2) - if (particle.charge > 0.0) + /* draw crosses/bars on charged particles */ + if (TWO_TYPES) + { + if ((DRAW_CROSS)&&(particle.charge > 0.0)) { + pradius = particle.radius; if (ROTATION) { angle = angle + APOLY*PID; @@ -5026,17 +5654,35 @@ void draw_one_particle(t_particle particle, double xc, double yc, double radius, } glLineWidth(2); glColor3f(1.0, 1.0, 1.0); - x1 = xc1 - MU_B*ca; - y1 = yc1 - MU_B*sa; - x2 = xc1 + MU_B*ca; - y2 = yc1 + MU_B*sa; + x1 = xc1 - pradius*ca; + y1 = yc1 - pradius*sa; + x2 = xc1 + pradius*ca; + y2 = yc1 + pradius*sa; draw_line(x1, y1, x2, y2); - x1 = xc1 - MU_B*sa; - y1 = yc1 + MU_B*ca; - x2 = xc1 + MU_B*sa; - y2 = yc1 - MU_B*ca; + x1 = xc1 - pradius*sa; + y1 = yc1 + pradius*ca; + x2 = xc1 + pradius*sa; + y2 = yc1 - pradius*ca; draw_line(x1, y1, x2, y2); } + if ((DRAW_MINUS)&&(particle.charge < 0.0)) + { + pradius = particle.radius; + if (ROTATION) + { + angle = angle + APOLY*PID; + ca = cos(angle); + sa = sin(angle); + } + glLineWidth(2); + glColor3f(1.0, 1.0, 1.0); + x1 = xc1 - pradius*ca; + y1 = yc1 - pradius*sa; + x2 = xc1 + pradius*ca; + y2 = yc1 + pradius*sa; + draw_line(x1, y1, x2, y2); + } + } glLineWidth(width); glColor3f(1.0, 1.0, 1.0); @@ -5059,6 +5705,9 @@ void draw_one_particle(t_particle particle, double xc, double yc, double radius, glColor3f(1.0, 1.0, 1.0); draw_polygon(x1, y1, 0.5*radius, nsides, angle + APOLY*PID); } + +// printf("Particle radius %.3f, pradius %.3f, mass %.3f\n", radius, particle.radius, 1.0/particle.mass_inv); +// sleep(1); } void draw_collisions(t_collision *collisions, int ncollisions) @@ -5308,7 +5957,7 @@ void color_background(t_particle particle[NMAXCIRCLES], int bg_color, t_hashgrid } -void draw_particles(t_particle particle[NMAXCIRCLES], int plot, double beta, t_collision *collisions, int ncollisions, int bg_color, t_hashgrid hashgrid[HASHX*HASHY]) +void draw_particles(t_particle particle[NMAXCIRCLES], int plot, double beta, t_collision *collisions, int ncollisions, int bg_color, t_hashgrid hashgrid[HASHX*HASHY], t_lj_parameters params) { int i, j, k, m, width, nnbg, nsides; double ej, hue, huex, huey, rgb[3], rgbx[3], rgby[3], radius, x1, y1, x2, y2, angle, ca, sa, length, linkcolor, sign = 1.0, angle1, signy = 1.0, periodx, periody, x, y, lum, logratio; @@ -5325,23 +5974,77 @@ void draw_particles(t_particle particle[NMAXCIRCLES], int plot, double beta, t_c /* show region of partial thermostat */ if (PARTIAL_THERMO_COUPLING) { - if (PARTIAL_THERMO_REGION == TH_INBOX) - { - if (INCREASE_BETA) + switch (PARTIAL_THERMO_REGION) { + case (TH_INBOX): { - logratio = log(beta/BETA)/log(0.5*BETA_FACTOR); - if (logratio > 1.0) logratio = 1.0; - else if (logratio < 0.0) logratio = 0.0; - if (BETA_FACTOR > 1.0) hue = PARTICLE_HUE_MAX - (PARTICLE_HUE_MAX - PARTICLE_HUE_MIN)*logratio; - else hue = PARTICLE_HUE_MIN - (PARTICLE_HUE_MIN - PARTICLE_HUE_MAX)*logratio; + if (INCREASE_BETA) + { + logratio = log(beta/BETA)/log(0.5*BETA_FACTOR); + if (logratio > 1.0) logratio = 1.0; + else if (logratio < 0.0) logratio = 0.0; + if (BETA_FACTOR > 1.0) hue = PARTICLE_HUE_MAX - (PARTICLE_HUE_MAX - PARTICLE_HUE_MIN)*logratio; + else hue = PARTICLE_HUE_MIN - (PARTICLE_HUE_MIN - PARTICLE_HUE_MAX)*logratio; + } + else hue = 0.25*PARTICLE_HUE_MIN + 0.75*PARTICLE_HUE_MAX; + erase_area_hsl_turbo(0.0, YMIN, 2.0*PARTIAL_THERMO_WIDTH, PARTIAL_THERMO_HEIGHT*(YMAX - YMIN), hue, 0.9, 0.15); + break; + } + case(TH_LAYER): + { + hue = 0.75*PARTICLE_HUE_MIN + 0.25*PARTICLE_HUE_MAX; + erase_area_hsl_turbo(0.0, YMIN, XMAX, PARTIAL_THERMO_HEIGHT - YMIN, hue, 0.9, 0.15); + break; + } + case (TH_RING): + { + hue = 0.75*PARTICLE_HUE_MIN + 0.25*PARTICLE_HUE_MAX; + hsl_to_rgb_turbo(hue, 0.9, 0.15, rgb); + draw_colored_circle(0.0, 0.0, PARTIAL_THERMO_WIDTH, 180, rgb); + break; + } + case (TH_RING_EXPAND): + { + hue = 0.75*PARTICLE_HUE_MIN + 0.25*PARTICLE_HUE_MAX; + hsl_to_rgb_turbo(hue, 0.9, 0.15, rgb); + draw_colored_circle(0.0, 0.0, params.thermo_radius, 180, rgb); + break; + } + case(TH_INIT): + { + hue = 0.75*PARTICLE_HUE_MIN + 0.25*PARTICLE_HUE_MAX; + erase_rectangle_hsl_turbo(INITXMIN, INITYMIN, INITXMAX, INITYMAX, hue, 0.9, 0.15); + break; + } + case(TH_THERMO): + { + if (INCREASE_BETA) + { + logratio = log(beta/BETA)/log(0.5*BETA_FACTOR); + if (logratio > 1.0) logratio = 1.0; + else if (logratio < 0.0) logratio = 0.0; + if (BETA_FACTOR > 1.0) hue = PARTICLE_HUE_MAX - (PARTICLE_HUE_MAX - PARTICLE_HUE_MIN)*logratio; + else hue = PARTICLE_HUE_MIN - (PARTICLE_HUE_MIN - PARTICLE_HUE_MAX)*logratio; + } + else hue = 0.25*PARTICLE_HUE_MIN + 0.75*PARTICLE_HUE_MAX; + erase_rectangle_hsl_turbo(THERMOXMIN, THERMOYMIN, THERMOXMAX, THERMOYMAX, hue, 0.9, 0.15); + break; + } + case (TH_CONE): + { + if (INCREASE_BETA) + { + logratio = log(beta/BETA)/log(0.5*BETA_FACTOR); + if (logratio > 1.0) logratio = 1.0; + else if (logratio < 0.0) logratio = 0.0; + if (BETA_FACTOR > 1.0) hue = PARTICLE_HUE_MAX - (PARTICLE_HUE_MAX - PARTICLE_HUE_MIN)*logratio; + else hue = PARTICLE_HUE_MIN - (PARTICLE_HUE_MIN - PARTICLE_HUE_MAX)*logratio; + } + else hue = 0.25*PARTICLE_HUE_MIN + 0.75*PARTICLE_HUE_MAX; + + draw_colored_triangle_turbo(0.05, -0.2, LAMBDA, LAMBDA, -LAMBDA, LAMBDA, hue, 0.9, 0.15); + draw_colored_triangle_turbo(0.05, -0.2, -LAMBDA, LAMBDA, -0.04, -0.2, hue, 0.9, 0.15); + break; } - else hue = 0.25*PARTICLE_HUE_MIN + 0.75*PARTICLE_HUE_MAX; - erase_area_hsl_turbo(0.0, YMIN, 2.0*PARTIAL_THERMO_WIDTH, PARTIAL_THERMO_HEIGHT*(YMAX - YMIN), hue, 0.9, 0.15); - } - else if (PARTIAL_THERMO_REGION == TH_LAYER) - { - hue = 0.75*PARTICLE_HUE_MIN + 0.25*PARTICLE_HUE_MAX; - erase_area_hsl_turbo(0.0, YMIN, XMAX, PARTIAL_THERMO_HEIGHT - YMIN, hue, 0.9, 0.15); } } @@ -5364,7 +6067,7 @@ void draw_particles(t_particle particle[NMAXCIRCLES], int plot, double beta, t_c /* determine particle color and size */ for (j=0; j NMAXCIRCLES) - { - printf("Error: NMAXCIRCLES is too small\n"); - exit(1); - } - - for (i=0; i height); break; } + case (TH_RING): + { + x = particle[i].xc; + y = particle[i].yc; + condition = x*x + y*y > PARTIAL_THERMO_WIDTH*PARTIAL_THERMO_WIDTH; + break; + } + case (TH_RING_EXPAND): + { + x = particle[i].xc; + y = particle[i].yc; + condition = x*x + y*y > params.thermo_radius*params.thermo_radius; + break; + } + case (TH_INIT): + { + x = particle[i].xc; + y = particle[i].yc; + condition = ((x > INITXMIN)&&(x < INITXMAX)&&(y > INITYMIN)&&(y < INITYMAX)); + break; + } + case (TH_THERMO): + { + x = particle[i].xc; + y = particle[i].yc; + condition = ((x > THERMOXMIN)&&(x < THERMOXMAX)&&(y > THERMOYMIN)&&(y < THERMOYMAX)); + break; + } + case (TH_CONE): + { + x = particle[i].xc; + y = particle[i].yc; + a = (LAMBDA + 0.2)/(LAMBDA - 0.05); + b = LAMBDA*(1.0 - a); + condition = ((y < LAMBDA)&&(y > 0.0)&&(y > a*vabs(x) + b)); + break; + } default: condition = 1; } if (condition) @@ -8559,6 +9248,446 @@ int chem_catalytic_convert(int i, int type2, int newtype, t_particle particle[NM return(ncollisions); } +// int chem_dissociate_water_old(int i, t_particle particle[NMAXCIRCLES], t_collision *collisions, int ncollisions, double reaction_prob) +// /* dissociation of water molecule i into a pair H+, OH- */ +// { +// int j, k, p, q, closeby = 0, reaction = 0; +// double distance, move_factor, xnew, ynew, vxnew, vynew, mr1, mr2; +// +// if ((particle[i].npartners == 2)&&((double)rand()/RAND_MAX < reaction_prob)) +// { +// /* choose particle k to dissociate */ +// if (rand()%2 == 0) +// { +// j = particle[i].partner[0]; +// k = particle[i].partner[1]; +// } +// else +// { +// j = particle[i].partner[1]; +// k = particle[i].partner[0]; +// } +// +// /* propose moving dissociated particles further away */ +// move_factor = 2.0; +// xnew = particle[i].xc + move_factor*(particle[k].xc - particle[i].xc); +// ynew = particle[i].yc + move_factor*(particle[k].yc - particle[i].yc); +// +// /* test distance to other particles */ +// closeby = 0; +// for (p=0; p maxpartners) return(ncollisions); + + m1 = 1.0/particle[i].mass_inv; + for (p=0; pactive) return(-1); + + pstack[position]->cluster = cluster; + + for (k=0; knpartners; k++) + { + n = pstack[position]->partner[k]; + if ((particle[n].active)&&(particle[n].cluster != cluster)) + { + particle[n].tested = 1; + particle[n].cluster = cluster; + particle[n].cactive = 1; + nopen++; + if (*stacksize < ncircles) + { + (*stacksize)++; + pstack[*stacksize-1] = &particle[n]; + } + } + } + + if (nopen == 0) + { + pstack[position]->cactive = 0; + return(-1); + } + else return(nopen); +} + +int update_cluster_color(t_particle particle[NMAXCIRCLES]) +/* update the colors of clusters */ +{ + int i, k, p, position, nactive, stacksize, nclusters = 0; + t_particle **cstack; + + cstack = (t_particle* *)malloc(ncircles*sizeof(struct t_particle *)); + + #pragma omp parallel for private(i) + for (i=0; i 0) + { + while (!cstack[position]->cactive) position++; + if (position == stacksize) position = 0; + + /* find an active partner in stack */ + nactive += find_partners(particle, position, cstack, &stacksize, particle[i].cluster); + } + nclusters++; + } + + free(cstack); + return(nclusters); +} + 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, delta_n; + int i, j, k, n, n3, n4, p, type, oldncollisions, delta_n; double distance, rnd, p1, p2; static double inv_masses[RD_TYPES+1], radii[RD_TYPES+1]; static int first = 1; @@ -8649,7 +9849,6 @@ int update_types(t_particle particle[NMAXCIRCLES], t_collision *collisions, int distance = module2(particle[i].deltax[j], particle[i].deltay[j]); if ((distance < EQUILIBRIUM_DIST)&&((double)rand()/RAND_MAX < REACTION_PROB)) particle[k].type = particle[i].type; -// printf("Changed particle type to %i\n", particle[k].type); } } return(0); @@ -8932,6 +10131,93 @@ int update_types(t_particle particle[NMAXCIRCLES], t_collision *collisions, int if (EXOTHERMIC) *delta_e = (double)(delta_n)*DELTA_EKIN; return(ncollisions); } + case (CHEM_H2O_H_OH): + { + for (i=0; i= AGREG_DECOUPLE) particle[i].thermostat = 0; + } + + /* update cluster color scheme */ + if ((PLOT == P_CLUSTER)||(PLOT_B == P_CLUSTER)) + update_cluster_color(particle); + + + printf("%i collisions\n", ncollisions); + delta_n = ncollisions - oldncollisions; + printf("delta_n = %i\n", delta_n); + return(ncollisions); + } + case (CHEM_AGGREGATION_CHARGE): + { + for (i=0; i= AGREG_DECOUPLE) particle[i].thermostat = 0; + } + + /* update cluster color scheme */ + if ((PLOT == P_CLUSTER)||(PLOT_B == P_CLUSTER)) + update_cluster_color(particle); + + + printf("%i collisions\n", ncollisions); + delta_n = ncollisions - oldncollisions; + printf("delta_n = %i\n", delta_n); + return(ncollisions); + } } } @@ -9156,9 +10442,9 @@ void draw_particle_nb_plot(int *particle_numbers, int i) char message[100]; static double xmin, xmax, ymin, ymax, xmid, ymid, dx, dy, plotxmin, plotxmax, plotymin, plotymax; double pos[2], x1, y1, x2, y2, rgb[3]; - static int first = 1, gshift = INITIAL_TIME + NSTEPS, nmax, ygrad, largewin; + static int second = 2, gshift = INITIAL_TIME + NSTEPS, nmax, ygrad, largewin; - if (first) + if (second > 0) { xmin = XMAX - 1.05; xmax = XMAX - 0.05; @@ -9187,7 +10473,7 @@ void draw_particle_nb_plot(int *particle_numbers, int i) largewin = (WINWIDTH > 1280); - first = 0; + second--; } erase_area_hsl(xmid, ymid, dx, dy, 0.0, 0.9, 0.0); @@ -9315,3 +10601,32 @@ void reset_energy(t_particle particle[NMAXCIRCLES], double px[NMAXCIRCLES], doub printf("\n\n"); } + +void draw_frame(int i, int plot, int bg_color, int ncollisions, int traj_position, int traj_length, + int wall, double pressure[N_PRESSURES], double pleft, double pright, + int *particle_numbers, short int refresh, + t_lj_parameters params, t_particle particle[NMAXCIRCLES], + t_collision *collisions, t_hashgrid hashgrid[HASHX*HASHY], + t_tracer trajectory[TRAJECTORY_LENGTH*N_TRACER_PARTICLES], + t_obstacle obstacle[NMAXOBSTACLES], t_segment segment[NMAXSEGMENTS], + t_group_data *group_speeds, t_group_segments *segment_group) +/* draw a movie frame */ +{ + if (TRACER_PARTICLE) draw_trajectory(trajectory, traj_position, traj_length); + draw_particles(particle, plot, params.beta, collisions, ncollisions, bg_color, hashgrid, params); + draw_container(params.xmincontainer, params.xmaxcontainer, obstacle, segment, wall); + if (PRINT_PARAMETERS) print_parameters(params, PRINT_LEFT, pressure, refresh); + if (PLOT_SPEEDS) draw_speed_plot(group_speeds, i); + if (PLOT_TRAJECTORIES) draw_trajectory_plot(group_speeds, i); + if ((i > INITIAL_TIME)&&(PLOT_PARTICLE_NUMBER)) draw_particle_nb_plot(particle_numbers, i - INITIAL_TIME); +// if (PLOT_PARTICLE_NUMBER) draw_particle_nb_plot(particle_numbers, i - INITIAL_TIME); + if (BOUNDARY_COND == BC_EHRENFEST) print_ehrenfest_parameters(particle, pleft, pright); + else if (PRINT_PARTICLE_NUMBER) + { + if (REACTION_DIFFUSION) print_particle_types_number(particle, RD_TYPES); + else print_particle_number(ncircles); + } + else if (PRINT_PARTICLE_SPEEDS) print_particles_speeds(particle); + else if (PRINT_SEGMENTS_SPEEDS) print_segment_group_speeds(segment_group); +} + diff --git a/sub_rde.c b/sub_rde.c index c533574..82ea9a8 100644 --- a/sub_rde.c +++ b/sub_rde.c @@ -3,7 +3,7 @@ double dx2; /* spatial step size squared */ double intstep; /* integration step */ double intstep1; /* integration step used in absorbing boundary conditions */ double viscosity; /* viscosity (parameter in front of Laplacian) */ -double rpslzb; /* second parameter in Rock-Paper-Scissors-Lizard-Spock equation */ +double rpslzb = RPSLZB; /* second parameter in Rock-Paper-Scissors-Lizard-Spock equation */ double flow_speed; /* flow speed for laminar boundary conditions in Euler equation */ // double gaussian() @@ -33,7 +33,7 @@ double flow_speed; /* flow speed for laminar boundary conditions in Euler equat // return X; // } -void init_random(double mean, double amplitude, double *phi[NFIELDS], short int xy_in[NX*NY]) +void init_random(double mean, double amplitude, double *phi[NFIELDS], short int xy_in[NX*NY], t_wave_sphere wsphere[NX*NY]) /* initialise field with gaussian at position (x,y) */ { int i, j, k, in; @@ -47,7 +47,9 @@ void init_random(double mean, double amplitude, double *phi[NFIELDS], short int for (j=0; j 1.0) y1 -= 2.0; + while (y1 < -1.0) y1 += 2.0; + + if (xy_in[i*NY+j]) + { + f = delta*cos(a*xy[0]); + cplus = cosh((y1 + b)/rho); + cminus = cosh((y1 - b)/rho); + stheta = wsphere[i*NY + j].stheta; + + if (y1 > 0.0) + { + phi[1][i*NY+j] = amp*stheta*(f + 1.0/(rho*cminus*cminus)); + phi[0][i*NY+j] = amp*stheta*(f/(a*a) + rho/(cminus*cminus)); + } + else + { + phi[1][i*NY+j] = amp*stheta*(f - 1.0/(rho*cplus*cplus)); + phi[0][i*NY+j] = amp*stheta*(f/(a*a) - rho/(cplus*cplus)); + } + + phi[2][i*NY+j] = 0.0; + } + else + { + phi[0][i*NY+j] = 0.0; + phi[1][i*NY+j] = 0.0; + phi[2][i*NY+j] = 0.0; + } + } +} + 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) /* enforce laminar flow in x direction in specified region */ /* phi[0] is stream function, phi[1] is vorticity */ @@ -1542,7 +1701,7 @@ void compute_gradient_xy(double phi[NX*NY], double gradient[2*NX*NY]) } } -void compute_gradient_euler(double phi[NX*NY], double gradient[2*NX*NY], double yshift) +void compute_gradient_euler_plane(double phi[NX*NY], double gradient[2*NX*NY], double yshift) /* compute the gradient of the field */ { int i, j, iplus, iminus, jplus, jminus, padding = 0; @@ -1636,6 +1795,107 @@ void compute_gradient_euler(double phi[NX*NY], double gradient[2*NX*NY], double } +void compute_gradient_euler_sphere(double phi[NX*NY], double gradient[2*NX*NY], t_wave_sphere wsphere[NX*NY], double yshift) +/* compute the gradient of the field */ +{ + int i, j, iplus, iminus, jplus, jminus, padding = 0; + double deltaphi, maxgradient = 1.0e10, sintheta, invstheta; +// double dx = (XMAX-XMIN)/((double)NX); + static short int first = 1; + static double dphi, dtheta, cphiphi, ctheta, dt, vdrift; + + if (first) + { + dphi = DPI/(double)NX; + dtheta = PI/(double)NY; + + first = 0; + } + +// dx = (XMAX-XMIN)/((double)NX); + + #pragma omp parallel for private(i,j,iplus,iminus,jplus,jminus) + for (j=1; j RMAX) r = RMAX; + if (r < RMIN) r = RMIN; + wsphere[i*NY+j].radius = r; + +// printf("radius = %.3lg\n", r); + +// if (FLOODING) +// wsphere[i*NY+j].draw_wave = (phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift); +// wsphere[i*NY+j].draw_wave = ((wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift)); + } + /* TODO ? Avoid artifacts due to singularity at north pole */ + for (j=NY - DPOLE; j RMAX) r = RMAX; +// if (r < RMIN) r = RMIN; + if (r < 1.0) r = 1.0; + wsphere[i*NY+j].radius = r; + } + for (j=0; j RMAX) r = RMAX; +// if (r < RMIN) r = RMIN; + if (r < 1.0) r = 1.0; + wsphere[i*NY+j].radius = r; + } + } + + if (SHADE_3D) + { + #pragma omp parallel for private(i,j,norm,pscal,deltar,deltai,deltaj,n) + for (i=0; i DPI) value -= DPI; color_scheme_palette(C_ONEDIM_LINEAR, palette, value/DPI, 1.0, 1, rgb); break; } @@ -3751,7 +4428,7 @@ void compute_cfield_rde(short int xy_in[NX*NY], int cplot, int palette, t_rde rd // if ((cplot == Z_ARGUMENT)||(cplot == Z_EULER_DIRECTION_SPEED)) if ((cplot == Z_ARGUMENT)||(cplot == Z_EULER_DIRECTION_SPEED)||(cplot == Z_SWATER_DIRECTION_SPEED)) { - lum = tanh(SLOPE_SCHROD_LUM*rde[i*NY+j].field_norm); + lum = MIN_SCHROD_LUM + tanh(SLOPE_SCHROD_LUM*rde[i*NY+j].field_norm); for (k=0; k<3; k++) rde[i*NY+j].rgb[k] *= lum; // if ((i==0)&&(j==0)) printf("Luminosity multiplied by %.3lg\n", lum); } @@ -3770,7 +4447,8 @@ void compute_cfield_rde(short int xy_in[NX*NY], int cplot, int palette, t_rde rd void draw_wave_2d_rde(short int xy_in[NX*NY], t_rde rde[NX*NY]) { - int i, j; + int i, j, k; + double ca; glBegin(GL_QUADS); @@ -3779,7 +4457,13 @@ void draw_wave_2d_rde(short int xy_in[NX*NY], t_rde rde[NX*NY]) { if (xy_in[i*NY+j]) { - glColor3f(rde[i*NY+j].rgb[0], rde[i*NY+j].rgb[1], rde[i*NY+j].rgb[2]); + if (SHADE_2D) + { + ca = rde[i*NY+j].cos_angle; + ca = (ca + 1.0)*0.4 + 0.2; + glColor3f(rde[i*NY+j].rgb[0]*ca, rde[i*NY+j].rgb[1]*ca, rde[i*NY+j].rgb[2]*ca); + } + else glColor3f(rde[i*NY+j].rgb[0], rde[i*NY+j].rgb[1], rde[i*NY+j].rgb[2]); glVertex2i(i, j); glVertex2i(i+1, j); @@ -3791,6 +4475,247 @@ void draw_wave_2d_rde(short int xy_in[NX*NY], t_rde rde[NX*NY]) if (DRAW_BILLIARD) draw_billiard(0, 1.0); } +void draw_wave_sphere_rde_ij(int i, int iplus, int j, int jplus, int jcolor, int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t_rde rde[NX*NY], t_wave_sphere wsphere[NX*NY], int zplot, int cplot, int palette, int fade, double fade_value) +/* draw wave at simulation grid point (i,j) */ +{ + int k, l; + short int draw, notdraw, draw_bc=1; + double xyz[3], ca; + + if (NON_DIRICHLET_BC) + draw_bc = (xy_in[i*NY+j])&&(xy_in[iplus*NY+j])&&(xy_in[i*NY+jplus])&&(xy_in[iplus*NY+jplus]); + +// if (FLOODING) draw = wsphere[i*NY+j].draw_wave; +// else draw = ((TWOSPEEDS)||(xy_in[i*NY+j])); +// else + draw = (xy_in[i*NY+j]); + if (draw) glColor3f(rde[i*NY+jcolor].rgb[0], rde[i*NY+jcolor].rgb[1], rde[i*NY+jcolor].rgb[2]); + else + { + ca = wsphere[i*NY+j].cos_angle; + ca = (ca + 1.0)*0.4 + 0.2; + if (fade) ca *= fade_value; +// if (PLANET) +// glColor3f(wsphere[i*NY+j].r*ca, wsphere[i*NY+j].g*ca, wsphere[i*NY+j].b*ca); +// else + glColor3f(COLOR_OUT_R*ca, COLOR_OUT_G*ca, COLOR_OUT_B*ca); + } +// if (FLOODING) +// { +// glBegin(GL_TRIANGLE_FAN); +// if (ij_to_sphere(i, j, *wave[i*NY+j].p_zfield[movie], wsphere, xyz, wsphere[i*NY+j].draw_wave)) +// draw_vertex_sphere(xyz); +// if (ij_to_sphere(iplus, j, *wave[iplus*NY+j].p_zfield[movie], wsphere, xyz, wsphere[iplus*NY+j].draw_wave)) +// draw_vertex_sphere(xyz); +// if (ij_to_sphere(iplus, jplus, *wave[iplus*NY+j+1].p_zfield[movie], wsphere, xyz, wsphere[iplus*NY+j+1].draw_wave)) +// draw_vertex_sphere(xyz); +// if (ij_to_sphere(i, jplus, *wave[i*NY+j+1].p_zfield[movie], wsphere, xyz, wsphere[i*NY+j+1].draw_wave)) +// draw_vertex_sphere(xyz); +// glEnd (); +// } +// else + if (draw_bc) + { + glBegin(GL_TRIANGLE_FAN); + if (ij_to_sphere(i, j, *rde[i*NY+j].p_zfield[movie], wsphere, xyz, 1)) + draw_vertex_sphere(xyz); + if (ij_to_sphere(iplus, j, *rde[iplus*NY+j].p_zfield[movie], wsphere, xyz, 1)) + draw_vertex_sphere(xyz); + if (ij_to_sphere(iplus, jplus, *rde[iplus*NY+j+1].p_zfield[movie], wsphere, xyz, 1)) + draw_vertex_sphere(xyz); + if (ij_to_sphere(i, jplus, *rde[i*NY+j+1].p_zfield[movie], wsphere, xyz, 1)) + draw_vertex_sphere(xyz); + glEnd (); + } +} + + +void draw_wave_sphere_3d_rde(int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t_rde rde[NX*NY], t_wave_sphere wsphere[NX*NY], double potential[NX*NY], int zplot, int cplot, int palette, int fade, double fade_value, int refresh) +{ + int i, j, imax, imin, jmax, imid, jmid; + double observer_angle, angle2, observer_latitude; + + blank(); + +// if (refresh) +// { +// compute_wave_fields(phi, psi, xy_in, zplot, cplot, wave); +// if (SHADE_3D) compute_light_angle_sphere(phi, xy_in, wave, wsphere, movie, TRANSPARENT_WAVE); +// else if (SHADE_2D) compute_light_angle_sphere_2d(xy_in, phi, wave, wsphere, movie, TRANSPARENT_WAVE); +// compute_cfield_sphere(xy_in, cplot, palette, wave, fade, fade_value, movie); +// } + + observer_angle = argument(observer[0], observer[1]); + if (observer_angle < 0.0) observer_angle += DPI; + + angle2 = observer_angle + PI; + if (angle2 > DPI) angle2 -= DPI; + + observer_latitude = asin(observer[2]/module2(observer[0], observer[1])); + + imin = (int)(observer_angle*(double)NX/DPI); + imax = (int)(angle2*(double)NX/DPI); + if (imin >= NX-1) imin = NX-2; + if (imax >= NX-1) imax = NX-2; + + jmax = NY-3; +// jmax = NY - 50; + jmid = (int)((double)NY*(observer_latitude + PID)/PI); + imid = (imin + imax)/2; + + printf("Angle = %.5lg, angle2 = %.5lg, imin = %i, imax = %i\n", observer_angle, angle2, imin, imax); + + if (observer[2] > 0.0) + { + if (imin < imax) + { + for (i=imax; i>imid; i--) + { + for (j=0; j<=jmax; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + for (i=imid; i>imin; i--) + { + for (j=0; j<=jmid; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + for (j=jmax; j>=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (i=imax+1; i=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + } + else + { + for (i=imax; i=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (i=imax-1; i>=0; i--) + { + for (j=0; j<=jmax; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (j=0; j<=jmax; j++) + draw_wave_sphere_rde_ij(NX-1, 0, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + + for (i=NX-2; i>=imin; i--) + { + for (j=0; j<=jmid; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + for (j=jmax; j>=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + } + + /* North pole */ + for (i=0; iimid; i--) + { + for (j=jmax; j>=0; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (i=imid; i>imin; i--) + { + for (j=jmax; j>=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + for (j=0; j<=jmid; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (i=imax+1; i=0; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (j=jmax; j>=0; j--) + draw_wave_sphere_rde_ij(NX-1, 0, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + + for (i=0; i<=imin; i++) + { + for (j=jmax; j>=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + for (j=0; j<=jmid; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + } + else + { + for (i=imax; i=0; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (i=imid; i=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + for (j=0; j<=jmid; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (i=imax-1; i>=0; i--) + { + for (j=jmax; j>=0; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + + for (j=jmax; j>=0; j--) + draw_wave_sphere_rde_ij(NX-1, 0, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + + for (i=NX-2; i>=imin-1; i--) + { + for (j=jmax; j>=jmid; j--) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + for (j=0; j<=jmid; j++) + draw_wave_sphere_rde_ij(i, i+1, j, j+1, j+1, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } + } + + /* South pole */ + for (i=0; i0; j--) + draw_wave_sphere_rde_ij(i, i+1, j-1, j, j, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + + for (j=2; j>0; j--) + draw_wave_sphere_rde_ij(NX-1, 0, j-1, j, DPOLE, movie, phi, xy_in, rde, wsphere, zplot, cplot, palette, fade, fade_value); + } +} void draw_wave_3d_ij_rde(int i, int j, int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t_rde rde[NX*NY], double potential[NX*NY], int zplot, int cplot, int palette, int fade, double fade_value) { @@ -4028,8 +4953,9 @@ void draw_periodicised_wave_3d(int movie, double *phi[NFIELDS], short int xy_in[ } -void draw_wave_rde(int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t_rde rde[NX*NY], - double potential[NX*NY], int zplot, int cplot, int palette, int fade, double fade_value, int refresh) +void draw_wave_rde(int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t_rde rde[NX*NY], + t_wave_sphere wsphere[NX*NY], double potential[NX*NY], int zplot, + int cplot, int palette, int fade, double fade_value, int refresh) { int i, j, k, l, draw = 1; double xy[2], xy_screen[2], rgb[3], pos[2], ca, rgb_e[3], rgb_w[3], rgb_n[3], rgb_s[3]; @@ -4042,13 +4968,22 @@ void draw_wave_rde(int movie, double *phi[NFIELDS], short int xy_in[NX*NY], t_rd // printf("Computing fields\n"); compute_rde_fields(phi, xy_in, zplot, cplot, rde); // printf("Computed fields\n"); - if ((PLOT_3D)&&(SHADE_3D)) compute_light_angle_rde(xy_in, rde, potential, movie); + if ((PLOT_3D)&&(SHADE_3D)) + { + if (SPHERE) + compute_light_angle_sphere_rde(xy_in, rde, wsphere, potential, movie, 0); + else compute_light_angle_rde(xy_in, rde, potential, movie); + } + else if (SHADE_2D) + compute_light_angle_sphere_rde_2d(xy_in, rde, wsphere, potential, movie, 0); } compute_cfield_rde(xy_in, cplot, palette, rde, fade, fade_value, movie); if (PLOT_3D) { - if (DRAW_PERIODICISED) + if (PLOT_SPHERE) + draw_wave_sphere_3d_rde(movie, phi, xy_in, rde, wsphere, potential, zplot, cplot, palette, fade, fade_value, 0); + else if (DRAW_PERIODICISED) draw_periodicised_wave_3d(movie, phi, xy_in, rde, potential, zplot, cplot, palette, fade, fade_value); else draw_wave_3d_rde(movie, phi, xy_in, rde, potential, zplot, cplot, palette, fade, fade_value); } @@ -4233,3 +5168,79 @@ void set_in_out_flow_bc(double *phi_out[NFIELDS], short int xy_in[NX*NY], double } } + + +void smooth_row(int j, double phi_in[NX*NY], double phi_out[NX*NY]) +{ + int i; + + #pragma omp parallel for private(i) + for (i=1; i COS_VISIBLE); } @@ -1421,24 +1435,54 @@ void init_speed_dissipation_sphere(short int xy_in[NX*NY], double tc[NX*NY], dou switch (IOR) { case (IOR_EARTH_DEM): { - #pragma omp parallel for private(i,j) +// #pragma omp parallel for private(i,j,courant2,courantb2,speed) for (i=0; i RMAX) r = RMAX; if (r < RMIN) r = RMIN; wsphere[i*NY+j].radius = r; + + if (FLOODING) + wsphere[i*NY+j].draw_wave = (phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift); +// wsphere[i*NY+j].draw_wave = ((wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift)); } /* TODO ? Avoid artifacts due to singularity at north pole */ - for (j=NY - DPOLE; j RMAX) r = RMAX; if (r < 1.0) r = 1.0; wsphere[i*NY+j].radius = r; + + if (FLOODING) + wsphere[i*NY+j].draw_wave = (phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift); +// wsphere[i*NY+j].draw_wave = ((wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift)); } } @@ -1624,27 +1788,53 @@ void compute_light_angle_sphere(short int xy_in[NX*NY], t_wave wave[NX*NY], t_wa if ((TWOSPEEDS)||(xy_in[i*NY+j])) { /* computation of tangent vectors */ - deltar = (wsphere[(i+1)*NY+j].radius - wsphere[i*NY+j].radius)/dphi; + if (transparent) + { + deltar = (wsphere[(i+1)*NY+j].radius_dem - wsphere[i*NY+j].radius_dem)/dphi; - deltai[0] = -wsphere[i*NY+j].radius*wsphere[i*NY+j].sphi; - deltai[0] += deltar*wsphere[i*NY+j].cphi; + deltai[0] = -wsphere[i*NY+j].radius_dem*wsphere[i*NY+j].sphi; + deltai[0] += deltar*wsphere[i*NY+j].cphi; - deltai[1] = wsphere[i*NY+j].radius*wsphere[i*NY+j].cphi; - deltai[1] += deltar*wsphere[i*NY+j].sphi; + deltai[1] = wsphere[i*NY+j].radius_dem*wsphere[i*NY+j].cphi; + deltai[1] += deltar*wsphere[i*NY+j].sphi; - deltai[2] = -deltar*wsphere[i*NY+j].cottheta; + deltai[2] = -deltar*wsphere[i*NY+j].cottheta; - deltar = (wsphere[i*NY+j+1].radius - wsphere[i*NY+j].radius)/dtheta; + deltar = (wsphere[i*NY+j+1].radius_dem - wsphere[i*NY+j].radius_dem)/dtheta; - deltaj[0] = wsphere[i*NY+j].radius*wsphere[i*NY+j].cphi*wsphere[i*NY+j].ctheta; - deltaj[0] += deltar*wsphere[i*NY+j].cphi*wsphere[i*NY+j].stheta; + deltaj[0] = wsphere[i*NY+j].radius_dem*wsphere[i*NY+j].cphi*wsphere[i*NY+j].ctheta; + deltaj[0] += deltar*wsphere[i*NY+j].cphi*wsphere[i*NY+j].stheta; - deltaj[1] = wsphere[i*NY+j].radius*wsphere[i*NY+j].sphi*wsphere[i*NY+j].ctheta; - deltaj[1] += deltar*wsphere[i*NY+j].sphi*wsphere[i*NY+j].stheta; + deltaj[1] = wsphere[i*NY+j].radius_dem*wsphere[i*NY+j].sphi*wsphere[i*NY+j].ctheta; + deltaj[1] += deltar*wsphere[i*NY+j].sphi*wsphere[i*NY+j].stheta; - deltaj[2] = wsphere[i*NY+j].radius*wsphere[i*NY+j].stheta; - deltaj[2] += -deltar*wsphere[i*NY+j].ctheta; + deltaj[2] = wsphere[i*NY+j].radius_dem*wsphere[i*NY+j].stheta; + deltaj[2] += -deltar*wsphere[i*NY+j].ctheta; + } + else + { + deltar = (wsphere[(i+1)*NY+j].radius - wsphere[i*NY+j].radius)/dphi; + deltai[0] = -wsphere[i*NY+j].radius*wsphere[i*NY+j].sphi; + deltai[0] += deltar*wsphere[i*NY+j].cphi; + + deltai[1] = wsphere[i*NY+j].radius*wsphere[i*NY+j].cphi; + deltai[1] += deltar*wsphere[i*NY+j].sphi; + + deltai[2] = -deltar*wsphere[i*NY+j].cottheta; + + deltar = (wsphere[i*NY+j+1].radius - wsphere[i*NY+j].radius)/dtheta; + + deltaj[0] = wsphere[i*NY+j].radius*wsphere[i*NY+j].cphi*wsphere[i*NY+j].ctheta; + deltaj[0] += deltar*wsphere[i*NY+j].cphi*wsphere[i*NY+j].stheta; + + deltaj[1] = wsphere[i*NY+j].radius*wsphere[i*NY+j].sphi*wsphere[i*NY+j].ctheta; + deltaj[1] += deltar*wsphere[i*NY+j].sphi*wsphere[i*NY+j].stheta; + + deltaj[2] = wsphere[i*NY+j].radius*wsphere[i*NY+j].stheta; + deltaj[2] += -deltar*wsphere[i*NY+j].ctheta; + } + /* computation of normal vector */ n[0] = deltai[1]*deltaj[2] - deltai[2]*deltaj[1]; n[1] = deltai[2]*deltaj[0] - deltai[0]*deltaj[2]; @@ -1666,8 +1856,81 @@ void compute_light_angle_sphere(short int xy_in[NX*NY], t_wave wave[NX*NY], t_wa } for (i=0; i= wsphere[i*NY+j].altitude + 0.001)) - if (FLOODING) draw = ((wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude + 0.001)); - else draw = ((TWOSPEEDS)||(xy_in[i*NY+j])); + if (FLOODING) + { + draw = (phi[i*NY+j] >= wsphere[i*NY+j].altitude - vshift); + wsphere[i*NY+j].draw_wave = draw; + } +// else draw = ((TWOSPEEDS)||(xy_in[i*NY+j])); + else draw = ((xy_in[i*NY+j])); if (draw) { - gradx = (*wave[(i+1)*NY+j].p_zfield[movie] - *wave[(i-1)*NY+j].p_zfield[movie])/dx; - grady = (*wave[i*NY+j+1].p_zfield[movie] - *wave[i*NY+j-1].p_zfield[movie])/dy; + if (transparent) + { + gradx = (wsphere[(i+1)*NY+j].radius_dem - wsphere[(i-1)*NY+j].radius_dem)/dx; + grady = (wsphere[i*NY+j+1].radius_dem - wsphere[i*NY+j-1].radius_dem)/dy; + } + else + { + gradx = (*wave[(i+1)*NY+j].p_zfield[movie] - *wave[(i-1)*NY+j].p_zfield[movie])/dx; + grady = (*wave[i*NY+j+1].p_zfield[movie] - *wave[i*NY+j-1].p_zfield[movie])/dy; + } norm = sqrt(vscale2 + gradx*gradx + grady*grady); pscal = -gradx*light[0] - grady*light[1] + SHADE_SCALE_2D; @@ -1727,11 +2004,26 @@ void compute_light_angle_sphere_2d(short int xy_in[NX*NY], double phi[NX*NY], t_ for (j=1; j= wsphere[j].altitude + 0.001)) + if (FLOODING) { - gradx = (*wave[NY+j].p_zfield[movie] - *wave[(NY-1)*NY+j].p_zfield[movie])/dx; - grady = (*wave[j+1].p_zfield[movie] - *wave[j-1].p_zfield[movie])/dy; - + draw = (phi[j] >= wsphere[j].altitude - vshift); + wsphere[j].draw_wave = draw; + } + else draw = ((xy_in[j])); + + if (draw) + { + if (transparent) + { + gradx = (wsphere[NY+j].radius_dem - wsphere[(NX-1)*NY+j].radius_dem)/dx; + grady = (wsphere[j+1].radius_dem - wsphere[j-1].radius_dem)/dy; + } + else + { + gradx = (*wave[NY+j].p_zfield[movie] - *wave[(NY-1)*NY+j].p_zfield[movie])/dx; + grady = (*wave[j+1].p_zfield[movie] - *wave[j-1].p_zfield[movie])/dy; + } + norm = sqrt(vscale2 + gradx*gradx + grady*grady); pscal = -gradx*light[0] - grady*light[1] + SHADE_SCALE_2D; @@ -1744,11 +2036,26 @@ void compute_light_angle_sphere_2d(short int xy_in[NX*NY], double phi[NX*NY], t_ for (j=1; j= wsphere[(NX-1)*NY+j].altitude + 0.001)) + if (FLOODING) { - gradx = (*wave[j].p_zfield[movie] - *wave[(NX-2)*NY+j].p_zfield[movie])/dx; - grady = (*wave[(NX-1)*NY+j+1].p_zfield[movie] - *wave[(NX-1)*NY+j-1].p_zfield[movie])/dy; - + draw = (phi[(NX-1)*NY+j] >= wsphere[(NX-1)*NY+j].altitude - vshift); + wsphere[(NX-1)*NY+j].draw_wave = draw; + } + else draw = ((xy_in[(NX-1)*NY+j])); + + if (draw) + { + if (transparent) + { + gradx = (wsphere[j].radius_dem - wsphere[(NX-2)*NY+j].radius_dem)/dx; + grady = (wsphere[(NX-1)*NY+j+1].radius_dem - wsphere[(NX-1)*NY+j-1].radius_dem)/dy; + } + else + { + gradx = (*wave[NY+j].p_zfield[movie] - *wave[(NY-1)*NY+j].p_zfield[movie])/dx; + grady = (*wave[j+1].p_zfield[movie] - *wave[j-1].p_zfield[movie])/dy; + } + norm = sqrt(vscale2 + gradx*gradx + grady*grady); pscal = -gradx*light[0] - grady*light[1] + SHADE_SCALE_2D; @@ -1798,11 +2105,12 @@ void draw_wave_sphere_2D(int movie, double phi[NX*NY], double psi[NX*NY], short static int ishift; static double dx, dy; - if (refresh) + if (1) { compute_wave_fields(phi, psi, xy_in, zplot, cplot, wave); - if (SHADE_3D) compute_light_angle_sphere(xy_in, wave, wsphere, movie); - else if (SHADE_2D) compute_light_angle_sphere_2d(xy_in, phi, wave, wsphere, movie); + if (SHADE_3D) compute_light_angle_sphere(phi, xy_in, wave, wsphere, movie, TRANSPARENT_WAVE); + else if (SHADE_2D) + compute_light_angle_sphere_2d(xy_in, phi, wave, wsphere, movie, TRANSPARENT_WAVE); compute_cfield_sphere(xy_in, cplot, palette, wave, fade, fade_value, movie); dx = (XMAX - XMIN)/(double)NX; dy = (YMAX - YMIN)/(double)(NY-2*DPOLE); @@ -1814,8 +2122,10 @@ void draw_wave_sphere_2D(int movie, double phi[NX*NY], double psi[NX*NY], short for (i=0; i= wsphere[i*NY+j].altitude + 0.001); - else draw = (TWOSPEEDS)||(xy_in[i*NY+j]); +// if (FLOODING) draw = (wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude + 0.001); +// else draw = (TWOSPEEDS)||(xy_in[i*NY+j]); + if (FLOODING) draw = wsphere[i*NY+j].draw_wave; + else draw = (xy_in[i*NY+j]); if (draw) glColor3f(wave[i*NY+j].rgb[0], wave[i*NY+j].rgb[1], wave[i*NY+j].rgb[2]); else @@ -1840,13 +2150,25 @@ void draw_wave_sphere_2D(int movie, double phi[NX*NY], double psi[NX*NY], short glVertex2i(ii, j+1); } glEnd (); + + if (DRAW_MOON_POSITION) + { + ii = NX-moon_position-1+ishift; + if (ii > NX) ii -= NX; + else if (ii < 0) ii += NX; + glColor3f(fade_value, fade_value, fade_value); + glBegin(GL_LINE_STRIP); + glVertex2i(ii, 0); + glVertex2i(ii, NY); + glEnd(); + } } void draw_wave_sphere_ij(int i, int iplus, int j, int jplus, int jcolor, int movie, double phi[NX*NY], double psi[NX*NY], short int xy_in[NX*NY], t_wave wave[NX*NY], t_wave_sphere wsphere[NX*NY], int zplot, int cplot, int palette, int fade, double fade_value) /* draw wave at simulation grid point (i,j) */ { int k, l; - short int draw, draw_bc=1; + short int draw, notdraw, draw_bc=1; double xyz[3], ca; if (NON_DIRICHLET_BC) @@ -1855,8 +2177,11 @@ void draw_wave_sphere_ij(int i, int iplus, int j, int jplus, int jcolor, int mov // if ((TWOSPEEDS)||(xy_in[i*NY+j])) // if (wsphere[i*NY+j].indomain) // if ((wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude + 0.001)) - if (FLOODING) draw = (wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude + 0.001); - else draw = ((TWOSPEEDS)||(xy_in[i*NY+j])); +// if (FLOODING) draw = (wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude + 0.001); +// if (FLOODING) draw = (wsphere[i*NY+j].indomain)||(phi[i*NY+j] >= wsphere[i*NY+j].altitude); + if (FLOODING) draw = wsphere[i*NY+j].draw_wave; +// else draw = ((TWOSPEEDS)||(xy_in[i*NY+j])); + else draw = (xy_in[i*NY+j]); if (draw) glColor3f(wave[i*NY+jcolor].rgb[0], wave[i*NY+jcolor].rgb[1], wave[i*NY+jcolor].rgb[2]); else { @@ -1868,16 +2193,30 @@ void draw_wave_sphere_ij(int i, int iplus, int j, int jplus, int jcolor, int mov glColor3f(wsphere[i*NY+j].r*ca, wsphere[i*NY+j].g*ca, wsphere[i*NY+j].b*ca); else glColor3f(COLOR_OUT_R*ca, COLOR_OUT_G*ca, COLOR_OUT_B*ca); } - if (draw_bc) + if (FLOODING) { glBegin(GL_TRIANGLE_FAN); - if (ij_to_sphere(i, j, *wave[i*NY+j].p_zfield[movie], wsphere, xyz)) + if (ij_to_sphere(i, j, *wave[i*NY+j].p_zfield[movie], wsphere, xyz, wsphere[i*NY+j].draw_wave)) draw_vertex_sphere(xyz); - if (ij_to_sphere(iplus, j, *wave[iplus*NY+j].p_zfield[movie], wsphere, xyz)) + if (ij_to_sphere(iplus, j, *wave[iplus*NY+j].p_zfield[movie], wsphere, xyz, wsphere[iplus*NY+j].draw_wave)) draw_vertex_sphere(xyz); - if (ij_to_sphere(iplus, jplus, *wave[iplus*NY+j+1].p_zfield[movie], wsphere, xyz)) + if (ij_to_sphere(iplus, jplus, *wave[iplus*NY+j+1].p_zfield[movie], wsphere, xyz, wsphere[iplus*NY+j+1].draw_wave)) draw_vertex_sphere(xyz); - if (ij_to_sphere(i, jplus, *wave[i*NY+j+1].p_zfield[movie], wsphere, xyz)) + if (ij_to_sphere(i, jplus, *wave[i*NY+j+1].p_zfield[movie], wsphere, xyz, wsphere[i*NY+j+1].draw_wave)) + draw_vertex_sphere(xyz); + glEnd (); + } + else if (draw_bc) + { + notdraw = (!draw); + glBegin(GL_TRIANGLE_FAN); + if (ij_to_sphere(i, j, *wave[i*NY+j].p_zfield[movie], wsphere, xyz, notdraw)) + draw_vertex_sphere(xyz); + if (ij_to_sphere(iplus, j, *wave[iplus*NY+j].p_zfield[movie], wsphere, xyz, notdraw)) + draw_vertex_sphere(xyz); + if (ij_to_sphere(iplus, jplus, *wave[iplus*NY+j+1].p_zfield[movie], wsphere, xyz, notdraw)) + draw_vertex_sphere(xyz); + if (ij_to_sphere(i, jplus, *wave[i*NY+j+1].p_zfield[movie], wsphere, xyz, notdraw)) draw_vertex_sphere(xyz); glEnd (); } @@ -1894,8 +2233,8 @@ void draw_wave_sphere_3D(int movie, double phi[NX*NY], double psi[NX*NY], short if (refresh) { compute_wave_fields(phi, psi, xy_in, zplot, cplot, wave); - if (SHADE_3D) compute_light_angle_sphere(xy_in, wave, wsphere, movie); - else if (SHADE_2D) compute_light_angle_sphere_2d(xy_in, phi, wave, wsphere, movie); + if (SHADE_3D) compute_light_angle_sphere(phi, xy_in, wave, wsphere, movie, TRANSPARENT_WAVE); + else if (SHADE_2D) compute_light_angle_sphere_2d(xy_in, phi, wave, wsphere, movie, TRANSPARENT_WAVE); compute_cfield_sphere(xy_in, cplot, palette, wave, fade, fade_value, movie); } diff --git a/sub_wave.c b/sub_wave.c index 1903ece..d4dabbf 100644 --- a/sub_wave.c +++ b/sub_wave.c @@ -632,6 +632,15 @@ void draw_tpolygon(t_polygon polygon) glEnd(); } +double michelson_schedule(int i) +{ + double t; + + t = (double)(i - INITIAL_TIME)/(double)NSTEPS; + return(4.0*t*WALL_WIDTH); +// return(2.0*t*WALL_WIDTH); +} + int init_circle_config_pattern(t_circle circles[NMAXCIRCLES], int circle_pattern) /* initialise the arrays circlex, circley, circlerad and circleactive */ @@ -2444,7 +2453,7 @@ int xy_in_arc(double x, double y, t_arc arc) int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_circle *circles) /* returns 1 if (x,y) represents a point in the billiard */ { - double l2, r2, r2mu, omega, b, c, angle, z, x1, y1, x2, y2, y3, u, v, u1, v1, dx, dy, width, alpha, s, a, r, height, ca, sa, l, ht, xshift, zz[9][2], x5, x6, f, fp; + double l2, r1, r2, r2mu, omega, b, c, d, angle, z, x1, y1, x2, y2, y3, u, v, u1, v1, dx, dy, width, alpha, s, a, r, height, ca, sa, l, ht, xshift, zz[9][2], x5, x6, f, fp, h1; int i, j, k, k1, k2, condition = 0, m; static int first = 1, nsides; static double h, hh, ra, rb, ll, salpha; @@ -3067,7 +3076,7 @@ int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_ } case (D_WAVEGUIDES_COUPLED): { - x1 = vabs(x); + x1 = vabs(x)*2.0/XMAX; y1 = vabs(y); width = 0.03; @@ -3082,6 +3091,26 @@ int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_ return(vabs(f - y1) < MU*sqrt(1.0 + fp*fp)); } + case (D_WAVEGUIDES_COUPLED_N): + { + x1 = vabs(x); + y1 = vabs(y); + + width = 0.01; + b = 1.0*(1.0 - 2.0*MU - width); + a = MU + 0.5*width - b; + c = 15.0; + x6 = x1*x1*x1; + x5 = x6*x1*x1; + x6 = x5*x1; + + f = a + b*(1.0 + 2.0*c*x6)/(1.0 + c*x6); + fp = 6.0*b*c*x5/((1.0 + c*x6)*(1.0 + c*x6)); + + if (vabs(f - y1) < 0.9*MU*sqrt(1.0 + fp*fp)) return(1); + if (vabs(f - y1) < MU*sqrt(1.0 + fp*fp)) return(2); + return(0); + } case (D_WAVEGUIDE_S): { a = 0.5*(1.0 - MU); @@ -3099,7 +3128,40 @@ int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_ } r = module2(x-LAMBDA, y-a); return(vabs(r - a) < MU); - + } + case (D_WAVEGUIDE_S_SHORT): + { + a = -1.0 + MU; + if (y < 0.0) + { + x = -x; + y = -y; + } + if (x < -LAMBDA) + { + if (vabs(y - 1.0 + MU) > MU) return(0); + if (vabs(y - 1.0 + MU) > 0.8*MU) return(2); + return(1); + } + r = module2(x-a, y); + if (vabs(r - 1.0 + MU) < 0.8*MU) return(1); + if (vabs(r - 1.0 + MU) < MU) return(2); + return(0); + } + case (D_WAVEGUIDE_BADSPLICE): + { + if (x < 0.0) + { + y1 = vabs(vabs(y) - 0.5); + } + else + { + if (y > 0.0) y1 = vabs(y - 0.5 - MU); + else y1 = vabs(y + 0.5 - MU_B); + } + if (y1 < 0.9*LAMBDA) return(1); + if (y1 < LAMBDA) return(2); + return(0); } case (D_MAZE): { @@ -3226,6 +3288,7 @@ int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_ a = 1.9; b = 1.9 - 2.0*LAMBDA + 2.0*width; x1 = vabs(x); + if ((x1 < WALL_WIDTH)&&(vabs(y) > MU)) return(2); if (module2(x1 - a, y) > LAMBDA) return(1); if (module2(x1 - b, y) > LAMBDA) return(1); return(0); @@ -3332,6 +3395,54 @@ int xy_in_billiard_single_domain(double x, double y, int b_domain, int ncirc, t_ return(1); } + case (D_MICHELSON): + { + if ((vabs(x) > LAMBDA)&&(vabs(y) > LAMBDA)) return(2); + r = 0.5*sqrt(2.0); + h = YMAX - 0.5*WALL_WIDTH; + x1 = (x + y)*r; + y1 = (-x + y)*r; + if ((vabs(y1) < 0.5*WALL_WIDTH)&&(vabs(x1) < LAMBDA*sqrt(2.0))) return(1); + if ((vabs(x - h) < 0.5*WALL_WIDTH)&&(vabs(y) < LAMBDA)) return(2); + if ((vabs(x) < LAMBDA)&&(vabs(y - h) < 0.5*WALL_WIDTH)) return(2); + return(0); + } + case (D_MICHELSON_MOVING): + { + if ((vabs(x) > LAMBDA)&&(vabs(y) > LAMBDA)) return(2); + r = 0.5*sqrt(2.0); + h = YMAX - MU - 0.5*WALL_WIDTH; + h1 = YMAX - MU - 0.5*WALL_WIDTH + michelson_position; + x1 = (x + y)*r; + y1 = (-x + y)*r; + if ((vabs(y1) < 0.5*WALL_WIDTH)&&(vabs(x1) < LAMBDA*sqrt(2.0))) return(1); + if ((vabs(x - h1) < 0.5*WALL_WIDTH)&&(vabs(y) < LAMBDA)) return(2); + if ((vabs(x) < LAMBDA)&&(vabs(y - h) < 0.5*WALL_WIDTH)) return(2); + return(0); + } + case (D_RITCHEY_CHRETIEN): + { + /* LAMBDA is magnification M */ + d = 2.5; + b = 3.5; + r1 = 2.0*(d + b/LAMBDA); + r2 = 6.0/(LAMBDA - 1.0); + x1 = 0.5*d - r1; + x2 = -0.5*d - r2; + y1 = vabs(y); + if (x < 0.0) + { + if (y1 > 0.3) return(1); + if (x < -0.5*d - WALL_WIDTH) return(1); + return(module2(x-x2, y1) > r2); + } + else + { + if (y1 < MU) return(1); + if (x > 0.5*d + WALL_WIDTH) return(1); + return(module2(x-x1, y1) < r1); + } + } case (D_MENGER): { x1 = 0.5*(x+1.0); @@ -3542,10 +3653,11 @@ void hex_transfo(double u, double v, double *x, double *y) void draw_billiard(int fade, double fade_value) /* draws the billiard boundary */ { - double x0, y0, x, y, x1, y1, x2, y2, dx, dy, phi, r = 0.01, pos[2], pos1[2], alpha, dphi, omega, z, l, width, a, b, c, ymax, height, xmax, ca, sa, xshift, x5, x6, f, fp; + double x0, y0, x, y, x1, y1, x2, y2, dx, dy, phi, r = 0.01, pos[2], pos1[2], alpha, dphi, omega, z, l, width, a, b, c, d, r1, r2, ymax, height, xmin, xmax, ca, sa, xshift, x5, x6, f, fp, xratio, w; int i, j, k, k1, k2, mr2, ntiles; static int first = 1, nsides; static double h, hh, sqr3, ll, salpha, arcangle; + char message[100]; if (fade) { @@ -4542,18 +4654,21 @@ void draw_billiard(int fade, double fade_value) /* draws the billiard bound case (D_WAVEGUIDES_COUPLED): { width = 0.03; + xratio = XMAX/2.0; b = 1.0*(1.0 - 2.0*MU - width); a = MU + 0.5*width - b; if ((DRAW_WAVE_PROFILE)&&(VERTICAL_WAVE_PROFILE)) dx = (XMAX - XMIN - 0.06)/(double)NSEG; else dx = (XMAX - XMIN + 0.1)/(double)NSEG; + dx = dx/xratio; + xmin = XMIN/xratio; - x1 = XMIN - 0.1; + x1 = xmin - 0.1; y1 = 1.0; for (i=0; i= COL_TURBO) color_scheme_asym_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); + else color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); + break; + } + case (P_LOG_AVERAGE_ENERGY): + { + value = LOG_SCALE*log(dy_e*(double)(j - jmin)*100.0/E_SCALE); + color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); + break; + } case (P_PHASE): { value = min + 1.0*dy*(double)(j - jmin); @@ -5783,9 +6144,9 @@ void draw_color_scheme_palette_fade(double x1, double y1, double x2, double y2, void draw_circular_color_scheme_palette_fade(double x1, double y1, double radius, int plot, double min, double max, int palette, int fade, double fade_value) { int j, k; - double x, y, dy, dy_e, dy_phase, rgb[3], value, lum, amp, dphi, pos[2], phi, xy[2]; + double x, y, dy, dy_e, dy_phase, rgb[3], value, lum, amp, dphi, pos[2], phi, xy[2], zscale = 0.9; - glBegin(GL_TRIANGLE_FAN); +// glBegin(GL_TRIANGLE_FAN); xy_to_pos(x1, y1, xy); glVertex2d(xy[0], xy[1]); dy = (max - min)/360.0; @@ -5841,6 +6202,19 @@ void draw_circular_color_scheme_palette_fade(double x1, double y1, double radius color_scheme_palette(C_ONEDIM_LINEAR, palette, value, 1.0, 1, rgb); break; } + case (P_AVERAGE_ENERGY): + { + value = dy_e*(double)(j)*100.0/E_SCALE; + if (COLOR_PALETTE >= COL_TURBO) color_scheme_asym_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); + else color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); + break; + } + case (P_LOG_AVERAGE_ENERGY): + { + value = LOG_SCALE*log(dy_e*(double)(j)*100.0/E_SCALE); + color_scheme_palette(COLOR_SCHEME, palette, value, 1.0, 1, rgb); + break; + } case (P_PHASE): { value = min + 1.0*dy*(double)(j); @@ -5908,12 +6282,18 @@ void draw_circular_color_scheme_palette_fade(double x1, double y1, double radius if (fade) for (k=0; k<3; k++) rgb[k] *= fade_value; glColor3f(rgb[0], rgb[1], rgb[2]); - xy_to_pos(x1 + radius*cos(dphi*(double)j), y1 + radius*sin(dphi*(double)j), xy); + glBegin(GL_TRIANGLE_FAN); + xy_to_pos(x1, y1, xy); glVertex2d(xy[0], xy[1]); + xy_to_pos(x1 + radius*cos(dphi*(double)(j-1)), y1 + zscale*radius*sin(dphi*(double)(j-1)), xy); + glVertex2d(xy[0], xy[1]); + xy_to_pos(x1 + radius*cos(dphi*(double)j), y1 + zscale*radius*sin(dphi*(double)j), xy); + glVertex2d(xy[0], xy[1]); + glEnd (); } xy_to_pos(x1 + radius*cos(dphi), y1 + radius*sin(dphi), xy); - glVertex2d(xy[0], xy[1]); - glEnd (); +// glVertex2d(xy[0], xy[1]); +// glEnd (); if (fade) glColor3f(fade_value, fade_value, fade_value); else glColor3f(1.0, 1.0, 1.0); @@ -5924,7 +6304,7 @@ void draw_circular_color_scheme_palette_fade(double x1, double y1, double radius glBegin(GL_LINE_LOOP); for (j = 0; j < NSEG; j++) { - xy_to_pos(x1 + radius*cos(dphi*(double)j), y1 + radius*sin(dphi*(double)j), xy); + xy_to_pos(x1 + radius*cos(dphi*(double)j), y1 + zscale*radius*sin(dphi*(double)j), xy); glVertex2d(xy[0], xy[1]); glVertex2d(xy[0], xy[1]); } @@ -6388,7 +6768,8 @@ void compute_laplacian(double phi[NX*NY], t_laplacian laplace[NX*NY], double del double oscillating_bc(int time, int j) { - double t, phase, a, envelope, omega; + int ij[2], jmin, jmax; + double t, phase, a, envelope, omega, amp, dist2; switch (OSCILLATION_SCHEDULE) { @@ -6413,7 +6794,8 @@ double oscillating_bc(int time, int j) { t = (double)time*OMEGA; // a = 10.0; - a = 0.02/OMEGA; +// a = 0.02/OMEGA; + a = sqrt(INITIAL_VARIANCE)/OMEGA; phase = AMPLITUDE*cos(t); envelope = exp(-(t-0.2)*(t-0.2)/(a*a))*sqrt(DPI/a); return(phase*envelope); @@ -6425,6 +6807,56 @@ double oscillating_bc(int time, int j) phase = t + ACHIRP*t*t; return(AMPLITUDE*sin(phase)*exp(-phase*DAMPING)); } + case (OSC_BEAM): + { + xy_to_ij(0.0, OSCIL_YMAX, ij); + jmax = ij[1]; + jmin = NY - jmax; + if (j < jmin) dist2 = (double)(jmin-1-j)*(YMAX-YMIN)/(double)NY; + else if (j > jmax) dist2 = (double)(j - jmax)*(YMAX-YMIN)/(double)NY; + else dist2 = 0.0; + dist2 = 500.0*dist2*dist2; + t = (double)time*OMEGA; + amp = AMPLITUDE*cos(t)*exp(-(double)t*DAMPING); + amp *= exp(-dist2/INITIAL_VARIANCE); + return(amp); + } + case (OSC_BEAM_GAUSSIAN): + { + dist2 = (double)(j - NY/2)*(YMAX-YMIN)/(double)NY; + dist2 = dist2*dist2; + t = (double)time*OMEGA; + amp = AMPLITUDE*cos(t)*exp(-(double)t*DAMPING); + amp *= exp(-dist2/INITIAL_VARIANCE); + return(amp); + } + case (OSC_BEAM_SINE): + { + xy_to_ij(0.0, OSCIL_YMAX, ij); + jmax = ij[1]; + jmin = NY - jmax; + dist2 = (double)(j - NY/2)/(double)(jmax - NY/2); + if (j > jmax) return(0.0); + if (j < jmin) return(0.0); + t = (double)time*OMEGA; + amp = AMPLITUDE*cos(t)*exp(-(double)t*DAMPING); + amp *= cos(PID*dist2); + return(amp); + } + case (OSC_BEAM_TWOPERIODS): + { + xy_to_ij(0.0, OSCIL_YMAX, ij); + jmax = ij[1]; + jmin = NY - jmax; + if (j < jmin) dist2 = (double)(jmin-1-j)*(YMAX-YMIN)/(double)NY; + else if (j > jmax) dist2 = (double)(j - jmax)*(YMAX-YMIN)/(double)NY; + else dist2 = 0.0; + dist2 = 500.0*dist2*dist2; + t = (double)time*OMEGA; + amp = AMPLITUDE*(0.5*cos(t) + 0.5*cos(sqrt(7.0)*t))*exp(-(double)t*DAMPING); + amp *= exp(-dist2/INITIAL_VARIANCE); + return(amp); + } } } @@ -6433,7 +6865,7 @@ void init_ior_2d(short int *xy_in[NX], double *tcc_table[NX], double *tgamma_tab /* should be at some point merged with 3D version in suv_wave_3d.c */ { int i, j, k, n, inlens, ncircles; - double courant2 = COURANT*COURANT, courantb2 = COURANTB*COURANTB, lambda1, mu1; + double courant2 = COURANT*COURANT, courantb2 = COURANTB*COURANTB, lambda1, mu1, courant_med, courant_med2; double a, u, v, u1, x, y, xy[2], norm2, speed, r2, c, salpha, h, ll, ca, sa, x1, y1, dx, dy, sum, sigma, x0, y0, rgb[3]; double xc[NGRIDX*NGRIDY], yc[NGRIDX*NGRIDY], height[NGRIDX*NGRIDY]; static double xc_stat[NGRIDX*NGRIDY], yc_stat[NGRIDX*NGRIDY], sigma_stat; @@ -6835,16 +7267,21 @@ void init_ior_2d(short int *xy_in[NX], double *tcc_table[NX], double *tgamma_tab } else { - if (xy_in[i][j] != 0) + if (xy_in[i][j] == 1) { tcc_table[i][j] = courant2; tgamma_table[i][j] = GAMMA; } - else + else if (xy_in[i][j] == 0) { tcc_table[i][j] = courantb2; tgamma_table[i][j] = GAMMAB; } + else + { + tcc_table[i][j] = 0.0; + tgamma_table[i][j] = 1.0; + } } } } @@ -6985,7 +7422,7 @@ void init_ior_2d(short int *xy_in[NX], double *tcc_table[NX], double *tgamma_tab ij_to_xy(i, j, xy); x = xy[0]; y = xy[1]; - if (xy_in[i][j]) + if (xy_in[i][j] == 1) { tcc_table[i][j] = courant2; tgamma_table[i][j] = GAMMA; @@ -7004,6 +7441,83 @@ void init_ior_2d(short int *xy_in[NX], double *tcc_table[NX], double *tgamma_tab } break; } + case (IOR_WAVE_GUIDES_COUPLED_B): + { + for (i=0; i LAMBDA)&&(vabs(y) > 0.7)) + { + tcc_table[i][j] = 0.0; + tgamma_table[i][j] = 1.0; + } + else + { + tcc_table[i][j] = courantb2; + tgamma_table[i][j] = GAMMAB; + } + } + } + break; + } + case (IOR_WAVE_GUIDE_COATED): + { + courant_med = 0.8*COURANT + 0.2*COURANTB; + courant_med2 = courant_med*courant_med; + for (i=0; i (double)packet[i].var_envelope) amp *= exp(-0.1*(t - (double)packet[i].var_envelope)); - if (t < (double)packet[i].var_envelope + 100.0) - add_circular_wave_loc(amp, packet[i].xc, packet[i].yc, phi, psi, xy_in, xmin, xmax, ymin, ymax); + wave_height = wave_packet_height(t, packet[i], type_envelope); + add_circular_wave_loc(wave_height, packet[i].xc, packet[i].yc, phi, psi, xy_in, xmin, xmax, ymin, ymax); + +// omega = DPI/packet[i].period; +// amp = packet[i].amp*omega*sin(omega*t + packet[i].phase); +// if (t > (double)packet[i].var_envelope) amp *= exp(-0.1*(t - (double)packet[i].var_envelope)); +// if (t < (double)packet[i].var_envelope + 100.0) +// add_circular_wave_loc(amp, packet[i].xc, packet[i].yc, phi, psi, xy_in, xmin, xmax, ymin, ymax); } } @@ -7300,7 +7833,7 @@ void add_wave_packets(double *phi[NX], double *psi[NX], short int * xy_in[NX], t /* add some wave packet sources */ { if (local) add_wave_packets_locally(phi, psi, packet, time, radius, add_period, type_envelope); - else add_wave_packets_globally(phi, psi, xy_in, packet, time); + else add_wave_packets_globally(phi, psi, xy_in, packet, time, add_period, type_envelope); } int old_source_schedule(int i) @@ -7323,16 +7856,14 @@ void old_init_input_signal() int init_input_signal() { - int i, j, k, mod, ldash, ldot, lspace, linter, initial_time; - char text[200] = "dddd_dD_dDDd_dDDd_DdDD__Dd_d_dDD__DdDD_d_dD_dDd__ddDDD_DDDDD_ddDDD_ddddD", c; - - ldash = 12; - ldot = 3; - linter = 30; - lspace = 36; - initial_time = 200; - - for (i=0; i LOG_ENERGY_FLOOR) wave[i*NY+j].log_mean_energy = LOG_SHIFT + PLOT_SCALE_LOG_ENERGY*logenergy; - else wave[i*NY+j].mean_energy = LOG_SHIFT + PLOT_SCALE_LOG_ENERGY*LOG_ENERGY_FLOOR; + else wave[i*NY+j].log_mean_energy = LOG_SHIFT + PLOT_SCALE_LOG_ENERGY*LOG_ENERGY_FLOOR; } if (COMPUTE_ENERGY_FLUX) diff --git a/sub_wave_3d_rde.c b/sub_wave_3d_rde.c index b4f4e12..7c362a0 100644 --- a/sub_wave_3d_rde.c +++ b/sub_wave_3d_rde.c @@ -14,6 +14,108 @@ void init_3d() /* initialisation of window */ glOrtho(XMIN, XMAX, YMIN, YMAX , -1.0, 1.0); } + +void init_wave_sphere_rde(t_wave_sphere wsphere[NX*NY]) +/* initialize sphere data, taken from sub_sphere.c */ +{ + int i, j; + double dphi, dtheta, theta0, xy[2], phishift; + + printf("Initializing wsphere\n"); + + dphi = DPI/(double)NX; + dtheta = PI/(double)NY; +// dtheta = PI/(double)(NY-2*(DPOLE)); +// theta0 = (double)(DPOLE)*dtheta; + theta0 = 0; + phishift = PHISHIFT*(XMAX-XMIN)/360.0; + + #pragma omp parallel for private(i,j) + for (i=0; i XMAX) xy[0] += XMIN - XMAX; + + xy[1] *= (double)NY/(double)(NY-2*DPOLE); + + wsphere[i*NY+j].x2d = xy[0]; + wsphere[i*NY+j].y2d = xy[1]; + + wsphere[i*NY+j].cos_angle_sphere = wsphere[i*NY+j].x*light[0] + wsphere[i*NY+j].y*light[1] + wsphere[i*NY+j].z*light[2]; + } + + /* cotangent, taking care of not dividing by zero */ + /* TODO clean up cottheta range ? */ + for (j=DPOLE; j COS_VISIBLE); +} + void xyz_to_xy(double x, double y, double z, double xy_out[2]) { int i; @@ -63,6 +165,127 @@ void xyz_to_xy(double x, double y, double z, double xy_out[2]) } } +int xy_in_billiard_sphere(int i, int j, t_wave_sphere wsphere[NX*NY]) +/* returns 1 if (x,y) represents a point in the billiard */ +{ + int k; + double pscal, dist, r, u, v, u1, v1; + static double cos_rot, sin_rot; + static int first = 1; + + if (first) + { +// if (B_DOMAIN == D_SPHERE_EARTH) init_earth_map(wsphere); +// else if (OTHER_PLANET) init_planet_map(wsphere, B_DOMAIN); +// else + if ((B_DOMAIN == D_SPHERE_JULIA)||(B_DOMAIN == D_SPHERE_JULIA_INV)||(B_DOMAIN == D_SPHERE_JULIA_CUBIC)) + { + cos_rot = cos(JULIA_ROT*DPI/360.0); + sin_rot = sin(JULIA_ROT*DPI/360.0); + } +// else if (B_DOMAIN == D_SPHERE_MAZE) init_sphere_maze(wsphere, 0, 0, 0); +// else if (B_DOMAIN == D_SPHERE_MAZE_SPIRAL) init_sphere_maze(wsphere, 1, 0, 1); +// else if (B_DOMAIN == D_SPHERE_MAZE_WAVE) init_sphere_maze(wsphere, 0, 1, 1); + first = 0; + } + + switch (B_DOMAIN) { + case (D_NOTHING): + { + return(1); + } + case (D_LATITUDE): + { + return(vabs(wsphere[i*NY+j].theta - PID) < LAMBDA*PID); + } + case (D_SPHERE_CIRCLES): + { + for (k=0; k #define MOVIE 0 /* set to 1 to generate movie */ -#define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */ +#define DOUBLE_MOVIE 0 /* set to 1 to produce movies for wave height and energy simultaneously */ #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 */ @@ -52,21 +52,21 @@ #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 1920 /* number of grid points on x axis */ -#define NY 1150 /* number of grid points on y axis */ -// #define NX 2840 /* number of grid points on x axis */ +// // #define NX 1920 /* number of grid points on x axis */ +// #define NY 1150 /* number of grid points on y axis */ +#define NX 3000 /* number of grid points on x axis */ +#define NY 1600 /* number of grid points on y axis */ +// #define NX 3840 /* 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 -1.0 -#define XMAX 3.0 /* x interval */ -#define YMIN -1.041666667 -#define YMAX 1.041666667 /* y interval for 9/16 aspect ratio */ +// #define XMIN -2.0 +// #define XMAX 2.0 /* x interval */ +// #define YMIN -1.197916667 +// #define YMAX 1.197916667 /* y interval for 9/16 aspect ratio */ +#define XMIN -1.669565217 +#define XMAX 1.669565217 /* x interval */ +#define YMIN -1.0 +#define YMAX 1.0 /* y interval for 9/16 aspect ratio */ #define HIGHRES 0 /* set to 1 if resolution of grid is double that of displayed image */ @@ -92,7 +92,7 @@ /* Choice of the billiard table */ -#define B_DOMAIN 10 /* choice of domain shape, see list in global_pdes.c */ +#define B_DOMAIN 17 /* choice of domain shape, see list in global_pdes.c */ #define CIRCLE_PATTERN 2 /* pattern of circles or polygons, see list in global_pdes.c */ @@ -109,17 +109,18 @@ #define NPOISSON 1000 /* number of points for Poisson C_RAND_POISSON arrangement */ #define RANDOM_POLY_ANGLE 1 /* set to 1 to randomize angle of polygons */ -#define LAMBDA 0.1197916667 /* parameter controlling the dimensions of domain */ -#define MU 0.035 /* parameter controlling the dimensions of domain */ +#define LAMBDA 3.0 /* parameter controlling the dimensions of domain */ +#define MU 0.14 /* parameter controlling the dimensions of domain */ #define NPOLY 6 /* number of sides of polygon */ #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 MDEPTH 2 /* depth of computation of Menger gasket */ #define MRATIO 3 /* ratio defining Menger gasket */ #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 30 /* number of grid point for grid of disks */ -#define NGRIDY 18 /* number of grid point for grid of disks */ +#define NGRIDX 30 /* number of grid point for grid of disks */ +#define NGRIDY 18 /* number of grid point for grid of disks */ +#define WALL_WIDTH 0.1 /* width of wall separating lenses */ #define X_SHOOTER -0.2 #define Y_SHOOTER -0.6 @@ -139,12 +140,13 @@ /* Physical parameters of wave equation */ #define TWOSPEEDS 0 /* set to 1 to replace hardcore boundary by medium with different speed */ -#define OSCILLATE_LEFT 0 /* set to 1 to add oscilating boundary condition on the left */ +#define OSCILLATE_LEFT 1 /* set to 1 to add oscilating boundary condition on the left */ #define OSCILLATE_TOPBOT 0 /* set to 1 to enforce a planar wave on top and bottom boundary */ #define OSCILLATION_SCHEDULE 3 /* oscillation schedule, see list in global_pdes.c */ +#define OSCIL_YMAX 0.35 /* defines oscillation range */ -#define OMEGA 0.001 /* frequency of periodic excitation */ -#define AMPLITUDE 0.8 /* amplitude of periodic excitation */ +#define OMEGA 0.015 /* frequency of periodic excitation */ +#define AMPLITUDE 1.0 /* amplitude of periodic excitation */ #define ACHIRP 0.2 /* acceleration coefficient in chirp */ #define DAMPING 0.0 /* damping of periodic excitation */ #define COURANT 0.1 /* Courant number */ @@ -162,7 +164,7 @@ /* Increasing COURANT speeds up the simulation, but decreases accuracy */ /* 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 ADD_OSCILLATING_SOURCE 0 /* set to 1 to add an oscillating wave source */ #define OSCILLATING_SOURCE_PERIOD 30 /* period of oscillating source */ #define ALTERNATE_OSCILLATING_SOURCE 1 /* set to 1 to alternate sign of oscillating source */ @@ -174,15 +176,15 @@ /* Boundary conditions, see list in global_pdes.c */ // #define B_COND 1 -#define B_COND 2 +#define B_COND 3 #define PRECOMPUTE_BC 0 /* set to 1 to compute neighbours for Laplacian in advance */ /* Parameters for length and speed of simulation */ -#define NSTEPS 2300 /* number of frames of movie */ +#define NSTEPS 1000 /* number of frames of movie */ // #define NSTEPS 300 /* number of frames of movie */ -#define NVID 4 /* number of iterations between images displayed on screen */ +#define NVID 20 /* 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 */ @@ -200,7 +202,7 @@ /* Parameters of initial condition */ -#define INITIAL_AMP 2.0 /* amplitude of initial condition */ +#define INITIAL_AMP 0.75 /* amplitude of initial condition */ // #define INITIAL_VARIANCE 0.000025 /* variance of initial condition */ #define INITIAL_VARIANCE 0.00005 /* variance of initial condition */ #define INITIAL_WAVELENGTH 0.05 /* wavelength of initial condition */ @@ -208,11 +210,11 @@ /* Plot type, see list in global_pdes.c */ -#define ZPLOT 103 /* wave height */ -#define CPLOT 103 /* color scheme */ +#define ZPLOT 108 /* wave height */ +#define CPLOT 108 /* color scheme */ -#define ZPLOT_B 107 -#define CPLOT_B 107 /* plot type for second movie */ +#define ZPLOT_B 103 +#define CPLOT_B 103 /* 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 */ @@ -242,8 +244,8 @@ /* Color schemes */ -#define COLOR_PALETTE 11 /* Color palette, see list in global_pdes.c */ -#define COLOR_PALETTE_B 13 /* Color palette, see list in global_pdes.c */ +#define COLOR_PALETTE 13 /* Color palette, see list in global_pdes.c */ +#define COLOR_PALETTE_B 17 /* Color palette, see list in global_pdes.c */ #define BLACK 1 /* background */ @@ -252,17 +254,18 @@ #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 2.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */ -#define VSCALE_ENERGY 10.0 /* additional scaling factor for color scheme P_3D_ENERGY */ +#define VSCALE_ENERGY 1.5 /* 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 */ -#define E_SCALE 20.0 /* scaling factor for energy representation */ +#define E_SCALE 50.0 /* scaling factor for energy representation */ #define LOG_SCALE 0.75 /* scaling factor for energy log representation */ #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 4000.0 /* scaling factor for energy flux representation */ #define FLUX_CSCALE 2.0 /* scaling factor for color in energy flux representation */ +#define AVRG_E_FACTOR 0.95 /* controls time window size in P_AVERAGE_ENERGY scheme */ #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 */ @@ -272,6 +275,13 @@ #define HUEMEAN 240.0 /* mean value of hue for color scheme C_HUE */ #define HUEAMP -200.0 /* amplitude of variation of hue for color scheme C_HUE */ +#define MESSAGE_LDASH 14 /* length of dash for Morse code message */ +#define MESSAGE_LDOT 8 /* length of dot for Morse code message */ +#define MESSAGE_LINTERVAL 54 /* length of interval between dashes/dots for Morse code message */ +#define MESSAGE_LINTERLETTER 60 /* length of interval between letters for Morse code message */ +#define MESSAGE_LSPACE 48 /* length of space for Morse code message */ +#define MESSAGE_INITIAL_TIME 100 /* initial time before starting message for Morse code message */ + #define NXMAZE 8 /* width of maze */ #define NYMAZE 32 /* height of maze */ #define MAZE_MAX_NGBH 5 /* max number of neighbours of maze cell */ @@ -280,8 +290,8 @@ #define MAZE_WIDTH 0.02 /* half width of maze walls */ #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.5 /* scale of color scheme bar for 2nd part */ +#define COLORBAR_RANGE 1.0 /* scale of color scheme bar */ +#define COLORBAR_RANGE_B 1.5 /* scale of color scheme bar for 2nd part */ #define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */ #define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */ @@ -292,8 +302,15 @@ #define POT_FACT 20.0 #define DRAW_WAVE_PROFILE 0 /* set to 1 to draw a profile of the wave */ #define MU_B 1.0 /* parameter controlling the dimensions of domain */ +#define HORIZONTAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ #define VERTICAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ #define DRAW_WAVE_TIMESERIES 0 /* set to 1 to draw a time series of the wave */ +#define WAVE_PROFILE_X 2.1 /* value of x to sample wave profile */ +#define WAVE_PROFILE_Y -1.0 /* value of y to sample wave profile */ +#define PROFILE_AT_BOTTOM 1 /* draw wave profile at bottom instead of top */ +#define AVERAGE_WAVE_PROFILE 1 /* set to 1 to draw time-average of wave profile squared*/ +#define TIMESERIES_NVALUES 400 /* number of values plotted in time series */ +#define DRAW_WAVE_SOURCE 0 /* set to 1 to draw source of wave at (wave_source_x, wave_source_y) */ /* end of constants only used by sub_wave and sub_maze */ @@ -307,14 +324,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, 6.0, 5.0}; /* location of observer for REP_PROJ_3D representation */ +double observer[3] = {8.0, 6.0, 6.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.1 /* overall scaling factor of z axis for REP_PROJ_3D representation */ +#define Z_SCALING_FACTOR 0.15 /* overall scaling factor of z axis for REP_PROJ_3D representation */ #define XY_SCALING_FACTOR 1.7 /* 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.2 /* overall x shift for REP_PROJ_3D representation */ -#define YSHIFT_3D 0.5 /* overall y shift for REP_PROJ_3D representation */ +#define XSHIFT_3D 0.1 /* overall x shift for REP_PROJ_3D representation */ +#define YSHIFT_3D 0.1 /* overall y shift for REP_PROJ_3D representation */ #include "global_pdes.c" /* constants and global variables */ @@ -1071,8 +1088,8 @@ void animation() // for (j=1; j 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; -// printf("p = %i\n", p); -// for (k=-12; k<13; k++) +// if (input_signal[i]) // { -// x1 = 0.05*((double)source_counter/(double)p + (double)k); -// if ((x1 > 0.1*XMIN)&&(x1 < 0.1*XMAX)) -// { -// add_circular_wave(sign1, x1, y, phi, psi, xy_in); -// printf("Adding wave at (%.2lg, %.2lg)\n", x1, y); -// } -// sign1 = -sign1; +// add_vertical_wave(sign, -2.0, 0.5 - y, 0.5 + y, phi, psi, xy_in); +// add_vertical_wave(sign, -2.0, -0.5 - y, -0.5 + y, phi, psi, xy_in); // } -// source_counter++; -// if (p > 0) q = p; -// else q = -p; -// if (source_counter >= q) -// { -// source_counter = 0; -// sign = -sign; +// else +// { +// damp_vertical_wave(0.01, 20, -2.0, 0.5 - y, 0.5 + y, phi, psi); +// damp_vertical_wave(0.01, 20, -2.0, -0.5 - y, -0.5 + y, phi, psi); // } -// for (j=0; j NX-1) imax = NX-1; + jmin = ij[1] - range; + if (jmin < 0) jmin = 0; + jmax = ij[1] + range; + if (jmax > NY-1) jmax = NY-1; + v = (double)(range*range); + + for (i=imin; i 0 - phi is wave height, psi is phi at time t-1 */ { @@ -151,6 +213,84 @@ void init_planar_wave(double x, double y, double *phi[NX], double *psi[NX], shor } +void init_planar_travelling_wave(double x, double y, double vx, double *phi[NX], double *psi[NX], short int * xy_in[NX]) +/* initialise field with drop at (x,y) - phi is wave height, psi is phi at time t-1 */ +/* beta version, works for vertical planar wave only so far */ +{ + int i, j, ij[2], jmin, jmax; + double xy[2], dist2, dist2_shifted, xshift, y1; + + xy_to_ij(x, y, ij); + jmax = ij[1]; + jmin = NY - jmax; + + xshift = vx*COURANT/(double)NX; + for (i=0; i y2) dist2 = (xy[0]-x)*(xy[0]-x) + (xy[1]-y2)*(xy[1]-y2); + else dist2 = (xy[0]-x)*(xy[0]-x); + if ((xy_in[i][j])||(TWOSPEEDS)) + phi[i][j] += INITIAL_AMP*factor*exp(-dist2/INITIAL_VARIANCE)*cos(-sqrt(dist2)/INITIAL_WAVELENGTH); + } +} + + +void damp_vertical_wave(double factor, int range, double x, double y1, double y2, double *phi[NX], double *psi[NX]) +/* damp field around (x,y) - phi is wave height, psi is phi at time t-1 */ +{ + int i, j, ij1[2], ij2[2], imin, imax, jmin, jmax; + double r2, v; + + xy_to_ij(x, y1, ij1); + xy_to_ij(x, y2, ij2); + imin = ij1[0] - range; + if (imin < 0) imin = 0; + imax = ij2[0] + range; + if (imax > NX-1) imax = NX-1; + jmin = ij1[1] - range; + if (jmin < 0) jmin = 0; + jmax = ij2[1] + range; + if (jmax > NY-1) jmax = NY-1; + v = (double)(range*range); + + for (i=imin; i ij2[1]) r2 = (double)((i - ij2[0])*(i - ij2[0]) + (j - ij2[1])*(j - ij2[1])); + else r2 = (double)((i - ij1[0])*(i - ij1[0])); + factor *= 1.0 - exp(-0.5*r2/v); + phi[i][j] *= factor; + psi[i][j] *= factor; + } + } +} + void oscillate_linear_wave(double amplitude, double t, double x1, double y1, double x2, double y2, double *phi[NX], double *psi[NX]) /* oscillating boundary condition at (x,y), beta version */ @@ -720,9 +911,7 @@ void draw_wave_highres_diss(int size, double *phi[NX], double *psi[NX], double * } -void draw_wave_epalette(double *phi[NX], double *psi[NX], double *total_energy[NX], double *total_flux, - double *color_scale[NX], - short int *xy_in[NX], double scale, int time, int plot, int palette, int fade, double fade_value) +void draw_wave_epalette(double *phi[NX], double *psi[NX], double *total_energy[NX], double *average_energy[NX], double *total_flux, double *color_scale[NX], short int *xy_in[NX], double scale, int time, int plot, int palette, int fade, double fade_value) /* same as draw_wave_e, but with color scheme specification */ { int i, j, k, iplus, iminus, jplus, jminus; @@ -853,7 +1042,7 @@ void draw_wave_epalette(double *phi[NX], double *psi[NX], double *total_energy[N } -double wave_value(int i, int j, double *phi[NX], double *psi[NX], double *total_energy[NX], double *total_flux, short int *xy_in[NX], double scale, int time, int plot, int palette, double rgb[3]) +double wave_value(int i, int j, double *phi[NX], double *psi[NX], double *total_energy[NX], double *average_energy[NX], double *total_flux, short int *xy_in[NX], double scale, int time, int plot, int palette, double rgb[3]) /* compute value of wave and color */ { int k; @@ -940,52 +1129,100 @@ double wave_value(int i, int j, double *phi[NX], double *psi[NX], double *total_ for (k=0; k<3; k++) rgb[k] *= flux_factor; break; } + case (P_AVERAGE_ENERGY): + { + energy = compute_energy(phi, psi, xy_in, i, j); + average_energy[i][j] = AVRG_E_FACTOR*average_energy[i][j] + (1.0 - AVRG_E_FACTOR)*energy; + value = average_energy[i][j]; + if (COLOR_PALETTE >= COL_TURBO) + color_scheme_asym_palette(COLOR_SCHEME, palette, value, scale, time, rgb); + else color_scheme_palette(COLOR_SCHEME, palette, value, scale, time, rgb); + break; + } + case (P_LOG_AVERAGE_ENERGY): + { + energy = compute_energy(phi, psi, xy_in, i, j); + average_energy[i][j] = AVRG_E_FACTOR*average_energy[i][j] + (1.0 - AVRG_E_FACTOR)*energy; + if (average_energy[i][j] == 0.0) value = LOG_SHIFT - 10.0*LOG_SCALE; + else value = LOG_SHIFT + LOG_SCALE*log(average_energy[i][j]); + color_scheme_palette(COLOR_SCHEME, palette, value, scale, time, rgb); + break; + } } return(value); } -void draw_wave_profile_horizontal(double *values, int size, int fade, double fade_value) +void draw_wave_profile_horizontal(double *values, int size, int average, int pnb, int fade, double fade_value) /* draw a horizontal profile of the wave, if option DRAW_WAVE_PROFILE is active */ { - int i, k; - double vmin, vmax, deltav, a, b, y; - static int imin, imax, jmin, jmax, jmid, d, first = 1; - static double deltaj, ymin; + int i, k, ij[2]; + double deltav, a, b, y; + static int imin, imax, jmin, jmax, jmid, jval, d, first = 1; + static double vmin[2], vmax[2], deltaj, ymin, average_vals[NX]; if (first) { imin = 100; imax = NX - 250; - jmin = NY - 150; - jmax = NY - 50; + if (PROFILE_AT_BOTTOM) + { + jmin = 50; + jmax = 150; + } + else + { + jmin = NY - 150; + jmax = NY - 50; + } jmid = (jmin + jmax)/2; jmid -= (jmid%size); + xy_to_ij(0.0, WAVE_PROFILE_Y, ij); + jval = ij[1]; + jval -= (jval%size); d = (jmax - jmin)/10 + 1; deltaj = (double)(jmax - jmin - 2*d); ymin = (double)(jmin + d); + for (i=0; i vmax) vmax = values[i*NY+jmin]; - if (values[i*NY+jmin] < vmin) vmin = values[i*NY+jmin]; + for (i=imin; i vmax[pnb]) vmax[pnb] = average_vals[i]; + + } + else + { + for (i=imin; i vmax) vmax = values[i*NY+jmin]; +// if (values[i*NY+jmin] < vmin) vmin = values[i*NY+jmin]; + if (values[i*NY+jval] > vmax[pnb]) vmax[pnb] = values[i*NY+jval]; + if (values[i*NY+jval] < vmin[pnb]) vmin[pnb] = values[i*NY+jval]; + } } // if (vmax <= vmin) vmax = vmin + 0.01; - if ((vmin < 0.0)&&(vmax > 0.0)) + if ((vmin[pnb] < 0.0)&&(vmax[pnb] > 0.0)) { - if (vmax > -vmin) vmin = -vmax; - else if (vmax < -vmin) vmax = -vmin; + if (vmax[pnb] > -vmin[pnb]) vmin[pnb] = -vmax[pnb]; + else if (vmax[pnb] < -vmin[pnb]) vmax[pnb] = -vmin[pnb]; } // printf("vmin = %.3lg, vmax = %.3lg\n", vmin, vmax); - deltav = vmax-vmin; + deltav = vmax[pnb]-vmin[pnb]; if (deltav <= 0.0) deltav = 0.01; a = deltaj/deltav; - b = ymin - a*vmin; + b = ymin - a*vmin[pnb]; erase_area_ij(imin, jmin, imax, jmax); @@ -994,8 +1231,10 @@ void draw_wave_profile_horizontal(double *values, int size, int fade, double fad glBegin(GL_LINE_STRIP); for (i=imin; i ymin) glVertex2d((double)i, y); } glEnd(); @@ -1005,16 +1244,20 @@ void draw_wave_profile_horizontal(double *values, int size, int fade, double fad glVertex2i(imax, jmax); glVertex2i(imin, jmax); glEnd(); + + /* slightly decrease extramal values in case signal gets weaker */ + vmax[pnb] *= 0.99; + vmin[pnb] *= 0.99; } -void draw_wave_profile_vertical(double *values, int size, int fade, double fade_value) +void draw_wave_profile_vertical(double *values, int size, int average, int pnb, int fade, double fade_value) /* draw a vertical profile of the wave, if option DRAW_WAVE_PROFILE is active */ { - int j, k; - double vmin, vmax, deltav, a, b, x; - static int imin, imax, jmin, jmax, imid, d, first = 1; - static double deltai, xmin; + int j, k, ij[2]; + double deltav, a, b, x; + static int imin, imax, ival, jmin, jmax, imid, d, first = 1; + static double vmin[2], vmax[2], deltai, xmin, average_vals[NY]; if (first) { @@ -1024,31 +1267,56 @@ void draw_wave_profile_vertical(double *values, int size, int fade, double fade_ imax = NX - 50; imid = (imin + imax)/2; imid -= (imid%size); + xy_to_ij(WAVE_PROFILE_X, 0.0, ij); + ival = ij[0]; + ival -= (ival%size); d = (imax - imin)/10 + 1; deltai = (double)(imax - imin - 2*d); xmin = (double)(imin + d); + for (j=0; j vmax) vmax = values[imin*NY+j]; - if (values[imin*NY+j] < vmin) vmin = values[imin*NY+j]; + for (j=jmin; j vmax[pnb]) vmax[pnb] = average_vals[j]; + } -// if ((vmin < 0.0)&&(vmax > 0.0)) + else { - if (vmax > -vmin) vmin = -vmax; - else if (vmax < -vmin) vmax = -vmin; + for (j=jmin; j vmax) vmax = values[imin*NY+j]; +// if (values[imin*NY+j] < vmin) vmin = values[imin*NY+j]; + if (values[ival*NY+j] > vmax[pnb]) vmax[pnb] = values[ival*NY+j]; + if (values[ival*NY+j] < vmin[pnb]) vmin[pnb] = values[ival*NY+j]; + } + /* symmetrize output */ +// if ((vmin[pnb] < 0.0)&&(vmax[pnb] > 0.0)) +// { +// if (vmax[pnb] > -vmin[pnb]) vmin[pnb] = -vmax[pnb]; +// else if (vmax[pnb] < -vmin[pnb]) vmax[pnb] = -vmin[pnb]; +// } + +// if (vmax > -vmin) vmin = -vmax; +// else if (vmax < -vmin) vmax = -vmin; } -// else if (vmax > 0.0) vmin = 0.0; -// else if (vmin < 0.0) vmax = 0.0; -// printf("vmin = %.3lg, vmax = %.3lg\n", vmin, vmax); - deltav = vmax-vmin; + +// printf("vmin = %.3lg, vmax = %.3lg\n", vmin[pnb], vmax[pnb]); + + deltav = vmax[pnb]-vmin[pnb]; if (deltav <= 0.0) deltav = 0.01; a = deltai/deltav; - b = xmin - a*vmin; + b = xmin - a*vmin[pnb]; erase_area_ij(imin, jmin, imax, jmax); @@ -1057,8 +1325,10 @@ void draw_wave_profile_vertical(double *values, int size, int fade, double fade_ glBegin(GL_LINE_STRIP); for (j=jmin; j= xmin) glVertex2d(x, (double)j); } glEnd(); @@ -1068,29 +1338,187 @@ void draw_wave_profile_vertical(double *values, int size, int fade, double fade_ glVertex2i(imax, jmax); glVertex2i(imin, jmax); glEnd(); + + /* slightly decrease extramal values in case signal gets weaker */ + vmax[pnb] *= 0.99; + vmin[pnb] *= 0.99; +} + + +void draw_wave_profile(double *values, int size, int p_number, int fade, double fade_value) +/* draw a profile of the wave, if option DRAW_WAVE_PROFILE is active */ +{ + if (VERTICAL_WAVE_PROFILE) + draw_wave_profile_vertical(values, size, AVERAGE_WAVE_PROFILE, p_number, fade, fade_value); + if (HORIZONTAL_WAVE_PROFILE) + draw_wave_profile_horizontal(values, size, AVERAGE_WAVE_PROFILE, p_number, fade, fade_value); +} + +void draw_exit_timeseries(double xleft, double yleft, double xtest, double ytest, double *values, int size, int top, int symmetrize, int fade, double fade_value) +/* draw a profile of the wave, if option DRAW_WAVE_TIMESERIES is active */ +{ + int t, t1, s, padding = 50, nvals = TIMESERIES_NVALUES; + double a, b, deltav, x, y, wmin, wmax; + static int ij[2], ij_test[2], imin, imax, jmintop, jmaxtop, jminbot, jmaxbot, jmin, jmax, itest, jtest, jtesttop, jtestbot, counter[2], first = 1, window = 5; + static double timeseries[TIMESERIES_NVALUES][2], average[TIMESERIES_NVALUES][2], vmin[2], vmax[2], ymin, deltaj, deltai; + + if (first) + { + xy_to_ij(xleft, yleft, ij); + xy_to_ij(xtest, ytest, ij_test); + jmaxtop = NY - padding; + jmintop = 2*ij[1] - jmaxtop; + jtesttop = ij_test[1]; + +// printf("jmintop = %i, jmaxtop = %i\n", jmintop, jmaxtop); + + xy_to_ij(xleft, -yleft, ij); + xy_to_ij(xtest, -ytest, ij_test); + jminbot = padding; + jmaxbot = 2*ij[1] - jminbot; + jtestbot = ij_test[1]; + +// printf("jminbot = %i, jmaxbot = %i\n", jminbot, jmaxbot); + + imin = ij[0]; + imax = NX - padding; + deltai = (double)(imax - imin)/(double)nvals; + + vmin[0] = 1.0e10; + vmax[0] = -vmin[0]; + vmin[1] = 1.0e10; + vmax[1] = -vmin[1]; + for (t=0; t vmax[top]) vmax[top] = timeseries[t][top]; + if (timeseries[t][top] < vmin[top]) vmin[top] = timeseries[t][top]; + } + if (symmetrize) + { + if (vmax[top] > -vmin[top]) vmin[top] = -vmax[top]; + else if (vmax[top] < -vmin[top]) vmax[top] = -vmin[top]; + } + +// printf("vmin = %.3lg, vmax = %.3lg\n", vmin[top], vmax[top]); + deltav = vmax[top]-vmin[top]; + if (deltav <= 0.0) deltav = 0.01; + a = deltaj/deltav; + b = ymin - a*vmin[top]; + + /* compute average */ + for (t=window; t nvals-1) t1 -= nvals; + average[t][top] += timeseries[t1][top]*timeseries[t1][top]; + } + average[t][top] = sqrt(average[t][top]*0.5/(double)window); + } + + erase_area_ij(imin, jmin, imax, jmax); + + if (fade) glColor3f(fade_value, 0.0, 0.0); + else glColor3f(1.0, 0.0, 0.0); + + + glBegin(GL_LINE_STRIP); + for (t=0; t= imin) glVertex2d(x, y); + } + glEnd(); + if (symmetrize) + { + glBegin(GL_LINE_STRIP); + for (t1=window; t1= imin) glVertex2d(x, y); } glEnd(); glBegin(GL_LINE_STRIP); @@ -1189,10 +1618,10 @@ void draw_exit_timeseries(double *values, int size, int fade, double fade_value) } -void draw_entrance_timeseries(double *values, int size, int fade, double fade_value) +void draw_entrance_timeseries(double xleft, double yleft, double *values, int size, int fade, double fade_value) /* draw a profile of the wave, if option DRAW_WAVE_TIMESERIES is active */ { - int t, t1, padding = 50, nvals = 200; + int t, t1, padding = 50, nvals = TIMESERIES_NVALUES, ishift = 4; double vmin, vmax, deltav, x, y; static int ij[2], imin, imax, jmin, jmax, jmid, itest, jtest, counter = 0, first = 1, time = 0; @@ -1200,7 +1629,7 @@ void draw_entrance_timeseries(double *values, int size, int fade, double fade_va if (first) { - xy_to_ij(-LAMBDA, 1.0 - MU, ij); + xy_to_ij(-xleft, yleft, ij); imin = padding; imax = ij[0]; jmax = NY - padding; @@ -1225,13 +1654,14 @@ void draw_entrance_timeseries(double *values, int size, int fade, double fade_va // glEnable(GL_SCISSOR_TEST); // glScissor(imin, jmin, imax-imin, jmax-jmin); glBegin(GL_LINE_STRIP); - for (t=0; t= NSTEPS) t1 = NSTEPS; - x = (double)imin + deltai*(double)t; +// x = (double)imin + deltai*(double)t; + x = (double)imin + deltai*(double)(t-ishift); y = a*(double)input_signal[t1] + b; - glVertex2d(x, y); + if (t > ishift) glVertex2d(x, y); } glEnd(); // glDisable(GL_SCISSOR_TEST); @@ -1244,14 +1674,25 @@ void draw_entrance_timeseries(double *values, int size, int fade, double fade_va glEnd(); } -void draw_wave_timeseries(double *values, int size, int fade, double fade_value) +void draw_wave_timeseries(double xleft, double yleft, double xtest, double ytest, double *values, int size, int fade, double fade_value) /* draw a profile of the wave, if option DRAW_WAVE_TIMESERIES is active */ { - draw_exit_timeseries(values, size, fade, fade_value); - draw_entrance_timeseries(values, size, fade, fade_value); + int symmetrize = 1; + + draw_exit_timeseries(xleft, yleft, xtest, ytest, values, size, 0, symmetrize, fade, fade_value); + if (DRAW_WAVE_TIMESERIES == 2) + draw_exit_timeseries(xleft, yleft, xtest, ytest, values, size, 1, symmetrize, fade, fade_value); + draw_entrance_timeseries(xleft, yleft, values, size, fade, fade_value); } -void draw_wave_highres_palette(int size, double *phi[NX], double *psi[NX], double *total_energy[NX], double *total_flux, short int *xy_in[NX], double scale, int time, int plot, int palette, int fade, double fade_value) +void draw_wave_timeseries_old(double *values, int size, int fade, double fade_value) +/* draw a profile of the wave, if option DRAW_WAVE_TIMESERIES is active */ +{ + draw_exit_timeseries_old(values, size, fade, fade_value); + draw_entrance_timeseries(1.0, 1.0, values, size, fade, fade_value); +} + +void draw_wave_highres_palette(int size, double *phi[NX], double *psi[NX], double *total_energy[NX], double *average_energy[NX], double *total_flux, short int *xy_in[NX], double scale, int time, int plot, int palette, int pnumber, int fade, double fade_value) /* same as draw_wave_highres, but with color scheme option */ { int i, j, k, iplus, iminus, jplus, jminus; @@ -1271,7 +1712,7 @@ void draw_wave_highres_palette(int size, double *phi[NX], double *psi[NX], doubl { if ((TWOSPEEDS)||(xy_in[i][j])) { - value = wave_value(i, j, phi, psi, total_energy, total_flux, xy_in, scale, time, plot, palette, rgb); + value = wave_value(i, j, phi, psi, total_energy, average_energy, total_flux, xy_in, scale, time, plot, palette, rgb); if ((DRAW_WAVE_PROFILE)||(DRAW_WAVE_TIMESERIES)) values[i*NY+j] = value; @@ -1287,9 +1728,16 @@ void draw_wave_highres_palette(int size, double *phi[NX], double *psi[NX], doubl glEnd (); - if (DRAW_WAVE_TIMESERIES) draw_wave_timeseries(values, size, fade, fade_value); - if (DRAW_WAVE_PROFILE) draw_wave_profile(values, size, fade, fade_value); + draw_billiard(fade, fade_value); + + if (DRAW_WAVE_TIMESERIES) draw_wave_timeseries(1.0, 1.0, 1.0, 0.5, values, size, fade, fade_value); + if (DRAW_WAVE_PROFILE) draw_wave_profile(values, size, pnumber, fade, fade_value); if ((DRAW_WAVE_PROFILE)||(DRAW_WAVE_TIMESERIES)) free(values); + if (DRAW_WAVE_SOURCE) + { + glColor3f(0.0, 0.0, 0.0); + draw_circle(wave_source_x, wave_source_y, 0.005, 100); + } } diff --git a/wave_comparison.c b/wave_comparison.c index 64c61d2..1125c23 100644 --- a/wave_comparison.c +++ b/wave_comparison.c @@ -254,6 +254,22 @@ #define MU_B 1.0 /* parameter controlling the dimensions of domain */ #define VERTICAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ #define DRAW_WAVE_TIMESERIES 0 /* set to 1 to draw a time series of the wave */ +#define WALL_WIDTH 0.1 /* width of wall separating lenses */ +#define OSCIL_YMAX 0.35 /* defines oscillation range */ +#define MESSAGE_LDASH 14 /* length of dash for Morse code message */ +#define MESSAGE_LDOT 8 /* length of dot for Morse code message */ +#define MESSAGE_LINTERVAL 54 /* length of interval between dashes/dots for Morse code message */ +#define MESSAGE_LINTERLETTER 60 /* length of interval between letters for Morse code message */ +#define MESSAGE_LSPACE 48 /* length of space for Morse code message */ +#define MESSAGE_INITIAL_TIME 100 /* initial time before starting message for Morse code message */ +#define AVRG_E_FACTOR 0.95 /* controls time window size in P_AVERAGE_ENERGY scheme */ +#define HORIZONTAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ +#define WAVE_PROFILE_X 2.1 /* value of x to sample wave profile */ +#define WAVE_PROFILE_Y -1.0 /* value of y to sample wave profile */ +#define PROFILE_AT_BOTTOM 1 /* draw wave profile at bottom instead of top */ +#define AVERAGE_WAVE_PROFILE 1 /* set to 1 to draw time-average of wave profile squared*/ +#define TIMESERIES_NVALUES 400 /* number of values plotted in time series */ +#define DRAW_WAVE_SOURCE 0 /* set to 1 to draw source of wave at (wave_source_x, wave_source_y) */ /* end of constants only used by sub_wave and sub_maze */ diff --git a/wave_energy.c b/wave_energy.c index 46179be..e3c17b2 100644 --- a/wave_energy.c +++ b/wave_energy.c @@ -228,6 +228,22 @@ #define DRAW_WAVE_PROFILE 0 /* set to 1 to draw a profile of the wave */ #define VERTICAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ #define DRAW_WAVE_TIMESERIES 0 /* set to 1 to draw a time series of the wave */ +#define WALL_WIDTH 0.1 /* width of wall separating lenses */ +#define OSCIL_YMAX 0.35 /* defines oscillation range */ +#define MESSAGE_LDASH 14 /* length of dash for Morse code message */ +#define MESSAGE_LDOT 8 /* length of dot for Morse code message */ +#define MESSAGE_LINTERVAL 54 /* length of interval between dashes/dots for Morse code message */ +#define MESSAGE_LINTERLETTER 60 /* length of interval between letters for Morse code message */ +#define MESSAGE_LSPACE 48 /* length of space for Morse code message */ +#define MESSAGE_INITIAL_TIME 100 /* initial time before starting message for Morse code message */ +#define AVRG_E_FACTOR 0.95 /* controls time window size in P_AVERAGE_ENERGY scheme */ +#define HORIZONTAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ +#define WAVE_PROFILE_X 2.1 /* value of x to sample wave profile */ +#define WAVE_PROFILE_Y -1.0 /* value of y to sample wave profile */ +#define PROFILE_AT_BOTTOM 1 /* draw wave profile at bottom instead of top */ +#define AVERAGE_WAVE_PROFILE 1 /* set to 1 to draw time-average of wave profile squared*/ +#define TIMESERIES_NVALUES 400 /* number of values plotted in time series */ +#define DRAW_WAVE_SOURCE 0 /* set to 1 to draw source of wave at (wave_source_x, wave_source_y) */ /* end of constants only used by sub_wave and sub_maze */ #include "global_pdes.c" /* constants and global variables */ diff --git a/wave_sphere.c b/wave_sphere.c index 96cd1c8..1a706d5 100644 --- a/wave_sphere.c +++ b/wave_sphere.c @@ -40,7 +40,7 @@ #include #define MOVIE 0 /* set to 1 to generate movie */ -#define DOUBLE_MOVIE 1 /* set to 1 to produce movies for wave height and energy simultaneously */ +#define DOUBLE_MOVIE 0 /* set to 1 to produce movies for wave height and energy simultaneously */ #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 */ @@ -48,22 +48,16 @@ #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 2560 /* number of grid points on x axis */ #define NY 1280 /* number of grid points on y axis */ -// #define NX 1280 /* number of grid points on x axis */ -// #define NY 640 /* number of grid points on y axis */ -// #define NX 2048 /* number of grid points on x axis */ -// #define NY 1024 /* number of grid points on y axis */ -// #define NX 3064 /* number of grid points on x axis */ -// #define NY 1536 /* number of grid points on y axis */ -// #define NX 1024 /* number of grid points on x axis */ -// #define NY 512 /* number of grid points on y axis */ +// #define NX 2048 /* number of grid points on x axis */ +// #define NY 1024 /* number of grid points on y axis */ +// #define NX 1024 /* number of grid points on x axis */ +// #define NY 512 /* number of grid points on y axis */ -#define DPOLE 20 /* safety distance to poles */ +#define DPOLE 30 /* safety distance to poles */ #define SMOOTHPOLE 0.1 /* smoothing coefficient at poles */ -#define ZERO_MERIDIAN 180.0 /* choice of zero meridian (will be at left/right boundary of 2d plot) */ +#define ZERO_MERIDIAN 190.0 /* choice of zero meridian (will be at left/right boundary of 2d plot) */ #define XMIN -2.0 #define XMAX 2.0 /* x interval */ @@ -80,6 +74,7 @@ /* Choice of the billiard table */ +// #define B_DOMAIN 999 /* choice of domain shape, see list in global_pdes.c */ #define B_DOMAIN 84 /* choice of domain shape, see list in global_pdes.c */ #define CIRCLE_PATTERN 33 /* pattern of circles or polygons, see list in global_pdes.c */ @@ -88,8 +83,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 0 /* set to 1 for a variable index of refraction */ -#define IOR 10 /* choice of index of refraction, see list in global_pdes.c */ +#define VARIABLE_IOR 1 /* set to 1 for a variable index of refraction */ +#define IOR 20 /* 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,6 +104,7 @@ #define FOCI 1 /* set to 1 to draw focal points of ellipse */ #define NGRIDX 30 /* number of grid point for grid of disks */ #define NGRIDY 18 /* number of grid point for grid of disks */ +#define WALL_WIDTH 0.6 /* width of wall separating lenses */ #define X_SHOOTER -0.2 #define Y_SHOOTER -0.6 @@ -136,10 +132,11 @@ #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.002 /* Courant number in medium B */ -#define GAMMA 0.0 /* damping factor in wave equation */ -#define GAMMAB 1.0e-2 /* damping factor in wave equation */ +#define COURANT 0.08 /* Courant number */ +#define COURANTB 0.005 /* Courant number in medium B */ +// #define GAMMA 2.0e-6 /* damping factor in wave equation */ +#define GAMMA 0.0 /* damping factor in wave equation */ +#define GAMMAB 0.0 /* 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 */ @@ -160,19 +157,29 @@ #define N_WAVE_PACKETS 15 /* number of wave packets */ #define WAVE_PACKET_RADIUS 20 /* radius of wave packets */ +#define ADD_FORCING 0 /* set to 1 to add periodic forcing */ +#define FORCING_AMP 0.0 /* amplitude of periodic forcing */ +#define FORCING_CONST_AMP 1.0-10 /* amplitude of periodic forcing */ +#define FORCING_PERIOD 2400 /* period of forcing */ + +#define DRIFT_WAVE 0 /* add drift of wave to the right (experimental) */ +#define DRIFT_FREQ 5 /* frequency of drift adding (experimental) */ + +#define MOVING_FRAME 0 /* set to 1 to use wave equation in moving frame */ +#define VOVERC 0.025 /* moving frame speed over wave speed */ + /* Boundary conditions, see list in global_pdes.c */ -// #define B_COND 1 #define B_COND 2 #define PRECOMPUTE_BC 0 /* set to 1 to compute neighbours for Laplacian in advance */ /* Parameters for length and speed of simulation */ -#define NSTEPS 2400 /* number of frames of movie */ +#define NSTEPS 1500 /* 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 NVID 10 /* number of iterations between images displayed on screen */ +// #define NVID 6 /* 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 */ @@ -188,7 +195,7 @@ /* Parameters of initial condition */ -#define INITIAL_AMP 1.0 /* amplitude of initial condition */ +#define INITIAL_AMP 0.03 /* amplitude of initial condition */ #define INITIAL_VARIANCE 0.00005 /* variance of initial condition */ #define INITIAL_WAVELENGTH 0.002 /* wavelength of initial condition */ @@ -203,8 +210,8 @@ #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 */ #define AMPLITUDE_HIGH_RES 1 /* set to 1 to increase resolution of plot */ -#define SHADE_3D 1 /* set to 1 to change luminosity according to normal vector */ -#define SHADE_2D 0 /* set to 1 to change luminosity according to normal vector to plane */ +#define SHADE_3D 0 /* set to 1 to change luminosity according to normal vector */ +#define SHADE_2D 1 /* set to 1 to change luminosity according to normal vector to plane */ #define SHADE_WAVE 1 /* set to 1 to have luminosity depend on wave height */ #define NON_DIRICHLET_BC 0 /* set to 1 to draw only facets in domain, if field is not zero on boundary */ #define FLOOR_ZCOORD 1 /* set to 1 to draw only facets with z not too negative */ @@ -223,7 +230,7 @@ /* 3D representation */ #define REPRESENTATION_3D 1 /* choice of 3D representation */ -#define PLOT_2D 0 /* switch to 2D representation, equirectangular projection */ +#define PLOT_2D 1 /* switch to 2D representation, equirectangular projection */ #define PHISHIFT 0.0 /* shift of phi in 2D plot (in degrees) */ #define FLOODING 1 /* set to 1 to draw waves above altitude (for Earth representations) */ @@ -231,7 +238,7 @@ #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_ANGLE 720.0 /* total angle of rotation during simulation */ +#define ROTATE_ANGLE -360.0 /* total angle of rotation during simulation */ // #define ROTATE_ANGLE -50.0 /* total angle of rotation during simulation */ #define ROTATE_VIEW_WHILE_FADE 1 /* set to 1 to keep rotating viewpoint during fade */ @@ -251,8 +258,8 @@ #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.5 /* sensitivity of color on wave amplitude */ -#define VSCALE_AMPLITUDE 1.5 /* additional scaling factor for color scheme P_3D_AMPLITUDE */ +#define SLOPE 1.0 /* sensitivity of color on wave amplitude */ +#define VSCALE_AMPLITUDE 50.0 /* additional scaling factor for color scheme P_3D_AMPLITUDE */ #define VSCALE_ENERGY 5.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 */ @@ -273,6 +280,13 @@ #define HUEMEAN 240.0 /* mean value of hue for color scheme C_HUE */ #define HUEAMP -200.0 /* amplitude of variation of hue for color scheme C_HUE */ +#define MESSAGE_LDASH 14 /* length of dash for Morse code message */ +#define MESSAGE_LDOT 8 /* length of dot for Morse code message */ +#define MESSAGE_LINTERVAL 54 /* length of interval between dashes/dots for Morse code message */ +#define MESSAGE_LINTERLETTER 60 /* length of interval between letters for Morse code message */ +#define MESSAGE_LSPACE 48 /* length of space for Morse code message */ +#define MESSAGE_INITIAL_TIME 100 /* initial time before starting message for Morse code message */ + #define NXMAZE 8 /* width of maze */ #define NYMAZE 32 /* height of maze */ #define MAZE_MAX_NGBH 5 /* max number of neighbours of maze cell */ @@ -280,17 +294,28 @@ #define MAZE_XSHIFT 0.0 /* horizontal shift of maze */ #define MAZE_WIDTH 0.02 /* half width of maze walls */ -#define DRAW_COLOR_SCHEME 1 /* set to 1 to plot the color scheme */ -#define COLORBAR_RANGE 6.0 /* scale of color scheme bar */ +#define DRAW_COLOR_SCHEME 0 /* set to 1 to plot the color scheme */ +#define COLORBAR_RANGE 3.0 /* scale of color scheme bar */ #define COLORBAR_RANGE_B 6.0 /* scale of color scheme bar for 2nd part */ #define ROTATE_COLOR_SCHEME 0 /* set to 1 to draw color scheme horizontally */ #define CIRC_COLORBAR 0 /* set to 1 to draw circular color scheme */ #define CIRC_COLORBAR_B 0 /* set to 1 to draw circular color scheme */ +#define DRAW_MOON_POSITION 0 /* set to 1 to draw position of Moon (for tide simulation) */ #define DRAW_WAVE_PROFILE 0 /* set to 1 to draw a profile of the wave */ #define VERTICAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ #define DRAW_WAVE_TIMESERIES 0 /* set to 1 to draw a time series of the wave */ +#define TIMESERIES_NVALUES 400 /* number of values plotted in time series */ #define SAVE_TIME_SERIES 0 /* set to 1 to save wave time series at a point */ +#define OSCIL_YMAX 0.35 /* defines oscillation range */ +#define AVRG_E_FACTOR 0.95 /* controls time window size in P_AVERAGE_ENERGY scheme */ +#define HORIZONTAL_WAVE_PROFILE 0 /* set to 1 to draw wave profile vertically */ +#define WAVE_PROFILE_X 2.1 /* value of x to sample wave profile */ +#define WAVE_PROFILE_Y -1.0 /* value of y to sample wave profile */ +#define PROFILE_AT_BOTTOM 0 /* draw wave profile at bottom instead of top */ +#define AVERAGE_WAVE_PROFILE 0 /* set to 1 to draw time-average of wave profile squared*/ +#define TIMESERIES_NVALUES 400 /* number of values plotted in time series */ +#define DRAW_WAVE_SOURCE 0 /* set to 1 to draw source of wave at (wave_source_x, wave_source_y) */ #define ADD_POTENTIAL 0 /* set to 1 to add potential to z coordinate */ #define POTENTIAL 10 @@ -299,7 +324,7 @@ /* For debugging purposes only */ #define FLOOR 1 /* set to 1 to limit wave amplitude to VMAX */ -#define VMAX 10.0 /* max value of wave amplitude */ +#define VMAX 5.0 /* max value of wave amplitude */ /* Parameters controlling 3D projection */ @@ -307,29 +332,31 @@ 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] = {-6.0, -3.0, 4.5}; /* location of observer for REP_PROJ_3D representation */ +double observer[3] = {-5.0, -5.0, 3.5}; /* location of observer for REP_PROJ_3D representation */ int reset_view = 0; /* switch to reset 3D view parameters (for option ROTATE_VIEW) */ #define ADD_DEM 1 /* add DEM (digital elevation model) */ -#define ADD_NEGATIVE_DEM 0 /* add DEM with bathymetric data */ -#define RSCALE_DEM 0.075 /* scaling factor of radial component for DEM */ -#define SMOOTH_DEM 0 /* set to 1 to smoothen DEM (to make altitude less constant) */ -#define DEM_SMOOTH_STEPS 5 /* number of smoothening steps */ -#define DEM_SMOOTH_HEIGHT 0.5 /* relative height below which to smoothen */ +#define ADD_NEGATIVE_DEM 1 /* add DEM with bathymetric data */ +#define RSCALE_DEM 0.1 /* scaling factor of radial component for DEM */ +#define SMOOTH_DEM 5 /* set to 1 to smoothen DEM (to make altitude less constant) */ +#define DEM_SMOOTH_STEPS 1 /* number of smoothening steps */ +#define DEM_SMOOTH_HEIGHT 2.0 /* relative height below which to smoothen */ #define DEM_MAXHEIGHT 9000.0 /* max height of DEM (estimated from Everest/Olympus Mons) */ +#define DEM_MAXDEPTH -10000 /* max depth of DEM */ #define PLANET_SEALEVEL 0.0 /* sea level for flooded planet */ -// #define PLANET_SEALEVEL 3850.0 /* sea level for flooded planet */ #define VENUS_NODATA_FACTOR 0.5 /* altitude to assign to DEM points without data (fraction of mean altitude) */ +#define TRANSPARENT_WAVE 0 /* set to 1 for waves to be "transparent" */ -#define RSCALE 0.025 /* scaling factor of radial component */ -#define RMAX 1.5 /* max value of radial component */ +#define RSCALE 1.0 /* scaling factor of radial component */ +#define RMAX 10.0 /* max value of radial component */ +#define Z_SCALING_FACTOR 0.8 /* overall scaling factor of z axis for REP_PROJ_3D representation */ #define RMIN 0.5 /* min value of radial component */ #define Z_SCALING_FACTOR 0.8 /* overall scaling factor of z axis for REP_PROJ_3D representation */ #define XY_SCALING_FACTOR 2.2 /* 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.0 /* overall x shift for REP_PROJ_3D representation */ #define YSHIFT_3D 0.0 /* overall y shift for REP_PROJ_3D representation */ -#define COS_VISIBLE -0.7 /* limit on cosine of normal to shown facets */ +#define COS_VISIBLE -0.3 /* limit on cosine of normal to shown facets */ #include "global_pdes.c" /* constants and global variables */ #include "global_3d.c" /* constants and global variables */ @@ -344,18 +371,88 @@ FILE *time_series_left, *time_series_right, *image_file; double courant2, courantb2; /* Courant parameters squared */ +void compute_forcing_schedule(int t, t_wave_sphere wsphere[NX*NY]) +/* compute periodic forcing */ +{ + int i, j; + double phase; + + phase = DPI*(double)t/(double)FORCING_PERIOD + ZERO_MERIDIAN*PI/180.0 + 0.5*PID; + + for (i=0; i= NX) moon_position -= NX; + +// i = NX/2; + i = moon_position; + printf("Phase = %.5lg, Forcing at i = %i: %.5lg, Moon position = %i\n", phase, i, wsphere[i*NY+NY/2].force, moon_position); +} + + +void shift_fields(double phi[NX*NY], short int xy_in[NX*NY]) +/* EXPERIMENTAL */ +{ + int i, j; + double temp; + + #pragma omp parallel for private(j,i) +// for (j=DPOLE; j1; i--) if (xy_in[i*NY+j]) +// { +// phi[i*NY+j] = phi[(i-1)*NY+j]; +// } +// if (xy_in[j]) +// { +// phi[j] = temp; +// } +// } + + /* smoothing at poles */ + for (j=0; j