//  ISS_VAR.H
//  Variable declarations and initializations.
//  © 2021 Peter J. Meyer

//  M is #defined only in ISM.C.

double version_no 
#ifdef M
= 1.93
//  Last version at U. of D.: 1.93
#endif
;

clock_t task_start, task_end;

int dimensionality;         //  lattice dimension
int size;				    //  lattice size
int num_sites;              //  number of sites in the lattice
int coord_num;              //  coordination number
int q;                      //  q-value for q-state Potts model

int major_axis              //  used with honeycomb and diamond lattices
#ifdef M
= 0
#endif
;

 //  maximum size of lattice based on dimensionality and dynamics algorithm
int max_size[][MAX_DIMENSIONALITY+1]             
#ifdef M
= {
  { 0, 0, 4096, 256, 64 },      //  Metropolis
  { 0, 0, 4096, 256, 64 },      //  Glauber
  { 0, 0, 2048, 128, 48 },      //  Swendsen-Wang
  { 0, 0, 1028,  96, 32 }       //  Wolff
  }   //  1200 with 2d and Wolff leads to stack overflow with 1 MB stack
#endif
;

char lattice_type[4];               //  lattice structure type, SQU, TRI, HY4, etc.
char dilution_type[3];              //  dilution type, SI, BO or NO
char dynamics[3];                   //  dynamics, Glauber, etc.
char goal[3];                       //  equilibration or percolation threshold
char model[3];                      //  Ising, q-state Potts
char spin_seln[3];                  //  random or checkerboard
     
double site_concentration;          //  probability of occupied site
double bond_concentration;          //  probability of open bond
double precision;                   //  used in determination of percolation threshold
double temperature;
double site_perc_thr;               //  site percolation threshold
double bond_perc_thr;               //  bond percolation threshold
double initial_magnetization;       //  when spin model initialized
double ising_square_critical_temp;
double ising_honeycomb_critical_temp;
double ising_triangular_critical_temp;
double ising_cubic_critical_temp;
double ising_diamond_critical_temp;
double ising_4d_hypercubic_critical_temp;
double num_samples;
double run_time;
double v_bond_probability;          //  virtual bond probability in Swendsen-Wang and in Wolff

//  indices for goal, lattice, dilution, algorithm, spin selection;
int l_type;     //  lattice     
int d_type;     //  dynamics
int g_type;     //  goal
int m_type;     //  model
int ss_type;    //  spin selection

//  Critical temperatures for the honeycomb, triangular and diamond lattices
//  are taken from Fisher, 1967, p671.  (Should be replaced by newer values.)
//  Critical temperature for the cubic lattice is from Heuer, 1993.
const struct lattice_type lattice_types[NUM_LATTICE_TYPES]
#ifdef M
= {  { "HON", "honeycomb",             2,  3, 1.5187,   0.6962,   0.65271 },    
     { "SQU", "square",                2,  4, 2.2692, 0.592746, 0.5 }, 
     { "TRI", "triangular",            2,  6, 3.6410,   0.5,      0.34729 }, 
     { "DTR", "double triangular",     2,  8, -1,       -1,       -1 }, 
     { "DIA", "diamond",               3,  4, 2.7040,   0.428,    0.388 },
     { "CUB", "cubic",                 3,  6, 4.5115,   0.3116,   0.2488 }, 
     { "QUA", "quadrilateral",         3,  8, -1, -1,       -1 }, 
     { "HD4", "hyperdiamond (4d)",     4,  5, -1, -1,       -1 },      
     { "HC4", "hypercubic (4d)",       4,  8, -1, 0.197,    0.160 }
     #if TETRAHEDRAL_LATTICE_IMPLEMENTED
     ,
     { "TET", "tetrahedral",           3, 12, -1, -1,       -1 }
     #endif
     }
#endif
;
//  Percolation thresholds not necessarily exactly correct (-1 means unknown).

const char models[][2][30]
#ifdef M
= {  { "IS", "Ising" }, { "Q-", "%d-state Potts" }, { "", "" } }
#endif
;
//  Cf. #defines for ISING and for Q_STATE_POTTS in ISS_DEF.H

const char dynamics_types[][2][30]
#ifdef M
= {  { "ME", "Metropolis" },    { "GL", "Glauber" }, 
     { "SW", "Swendsen-Wang" }, { "WO", "Wolff" }, { "", "" } }
#endif
;

const char goals[][2][30]
#ifdef M
= { 
    { "SI", "site percolation threshold" }, 
    { "BO", "bond percolation threshold" }, 
    { "SP", "spin model dynamics" }, 
    { "EQ", "equilibration" },   //  EQ = SP, for compatibility with previous version
    { "", "" } }
#endif
;

const char spin_selns[][2][30]
#ifdef M
= {  { "CH", "checkerboard" }, { "RA", "random" }, { "", "" } }
#endif
;

//  Pointers for dynamically allocated arrays.

A2(unsigned char) sites2;               //  See ALLOC.C
A2(unsigned char) bonds2;
A2(unsigned char) v_bonds2;             //  Used only with Swendsen-Wang dynamics.
A2(unsigned char) initial_sites2;       //  Used only if measuring correlation function. 
A2(unsigned short int)cluster_numbers2;  
A2(unsigned short int)spin_distances2;
A4(short int)precomp_nn_sites2;         //  For precomputed nn sites.

A3(unsigned char) sites3;
A3(unsigned char) bonds3;
A3(unsigned char) v_bonds3;
A3(unsigned char) initial_sites3;
A3(unsigned short int)cluster_numbers3;
A3(unsigned short int)spin_distances3;
A5(short int)precomp_nn_sites3;

A4(unsigned char) sites4;
A4(unsigned char) bonds4;
A4(unsigned char) v_bonds4;
A4(unsigned char) initial_sites4;
A4(unsigned short int)cluster_numbers4;
A4(unsigned short int)spin_distances4;
A6(short int)precomp_nn_sites4;

A2(double) magnetization; 
A2(double) potts_magnetization_squares;
A2(double) autocorrelation;  
A2(double) internal_energy; 

A2(char) edge;                      //  Used in CLUSTERS.C

int input_file_num;
int num_input_files;
int num_spins;             //  S&B.C
int num_opened_bonds;
int num_pairs_nn;                   //  number of pairs of nearest neighbour sites

int abs_magnetization;              //  number of up spins minus number of other spins
int abs_internal_energy;            //  the actual internal energy of the model
int num_configurations;
int num_spin_assignments;
int num_repetitions;
int step_length;
int num_time_slices;
int num_time_slices_done;
int num_temperatures;               //  normally 1
int percentage_range_for_mean;      //  Used in RESULTS.C
int num_divisors;                   //  SETPARAM.C
int num_decimal_places;             //  used in determination of percolation threshold
int ct_spin_value, ct_new_spin_value;
int ct_size_of_cluster;
int temperature_num;                //  for use with multiple temperatures

short int ct_i, ct_j, ct_k, ct_l, ct_r;
short int nn_i, nn_j, nn_k, nn_l;
short unsigned int ct_cluster_number;
int ct_cluster_number_overflow;
int max_cluster_size;
unsigned int num_clusters_traced_this_sweep;
unsigned int num_clusters_traced;
unsigned int num_clusters_traced_overflow;

unsigned int seed;                  //  the random seed

unsigned int num_spin_visits;
unsigned int num_spin_visits_overflow;
unsigned int num_spin_flips;
unsigned int num_spin_flips_overflow;
unsigned int num_sweeps;
unsigned int num_sweeps_overflow;

unsigned int num_spins_visited_this_sweep;
unsigned int num_spins_flipped_this_sweep;

unsigned long mcs_num;             //  EQUIL.C
//  unsigned long num_mcs_to_do;
unsigned long mcs_done;
unsigned long pause_time;

char exe_name[16];                //  name of executable
char input_filepath[128];         //  pathname of input data file
char output_filepath[128];        //  pathname of output data file
char map_filepath[128];           //  pathname of map file
char measurements_filepath[128];  //  pathname for measurements file
//  char spin_ass_filepath[128];      //  pathname for spin assignment file

char temp[128];                   //  miscellaneous temporary string storage
char temp1[128];
char temp2[128];
char line[128];

char session_start_date[16];
char session_start_time[16];
char session_end_date[16];
char session_end_time[16];
char run_start_date[16];
char run_start_time[16];
char run_end_date[16];
char run_end_time[16];

int dir[MAX_COORD_NUM][MAX_DIMENSIONALITY];   //  Defines up to 8 directions.
                                              //  Values depend on lattice type
                                              //  and are set in DIRTABLE.C.

short int nn_sites[MAX_COORD_NUM][MAX_DIMENSIONALITY];  //  Holds indices of 
                                                        //  nearest neighbour sites.
                                                        //  See get_nn_site() in Q&A.C.

short int nn_site[MAX_DIMENSIONALITY];  //  Holds indices of nearest neighbour site
                                        //  in a given direction.  
                                        //  See get_nn_site_in_dir() in Q&A.C

int directionality[MAX_COORD_NUM];

int divisors[MAX_DIVISORS];                       //  Used in spin selection.

unsigned short int spanning_cluster_list[MAX_NUM_SPANNING_CLUSTERS];

//  Transition probabilities
double w[4*MAX_COORD_NUM+1];            //  So as to handle -16, -15, ..., 15, 16

double temperatur[MAX_NUM_TEMPERATURES];
double multiple_temperature_results[MAX_NUM_TEMPERATURES][NUM_MULTIPLE_RESULTS][2];
//  Array for saving averages over final values for magnetization, Binder cumulant, 
//  internal energy and specific heat (plus the standard deviations).

unsigned char spin_value_mask;          //  Depends on model.

//  Struct for cluster tracing.
struct _all_cluster_trace_data ct_data;

//  Array of structs used in determination of percolation thresholds.
struct _perc_thr_iter iterations[MAX_ITERATIONS];

//  Variables connected with cluster-trace stack.
//  This is a stack of short unsigned ints
//  intended for storage of indices in the range 0-65535.

int stack_size;
A1(short int) stack;

const unsigned char bit[8]              //  bit patterns
#ifdef M 
= { 
    /* 0 */   BIT1_0,   //  00000001     See #defines for bit masks
    /* 1 */   BIT1_1,   //  00000010     in ISS_DEF.H
    /* 2 */   BIT1_2,   //  00000100
    /* 3 */   BIT1_3,   //  00001000 
    /* 4 */   BIT1_4,   //  00010000
    /* 5 */   BIT1_5,   //  00100000 
    /* 6 */   BIT1_6,   //  01000000
    /* 7 */   BIT1_7    //  10000000 
}
#endif
;

const unsigned char unbit[8]                   //  bit patterns
#ifdef M 
= { 
    /* 0 */  254,  //  11111110
    /* 1 */  253,  //  11111101
    /* 2 */  251,  //  11111011
    /* 3 */  247,  //  11110111 
    /* 4 */  239,  //  11101111
    /* 5 */  223,  //  11011111 
    /* 6 */  191,  //  10111111
    /* 7 */  127   //  01111111 
}
#endif
;