-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_config.c
More file actions
77 lines (61 loc) · 2.04 KB
/
Copy pathinit_config.c
File metadata and controls
77 lines (61 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
#include "structs.h"
/*********************************************************************************
this file contains three different functions to create starting configuration of size L declared in params
init_config_rand: set entries using the rand() function from C
init_config_rng: set entries using the rng function from gsl https://www.gnu.org/software/gsl/doc/html/rng.html
init_config_alternate: alternate the entries between 1 and -1
init_config_up: all entries are +1
init_config_down: all entries are -1
**********************************************************************************/
void init_config_rand(char *configuration, parameters params){
long int L= params.L;
for (int i=0; i<L; i++) {
configuration[i] = 2*(rand() % 2) - 1;
}
}
void init_config_rng(char *configuration, unsigned long int seed, parameters params){
long int L= params.L;
gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);
gsl_rng_set(r, seed); // set the seed for the rng
//double r_max = gsl_rng_max(r);
for (int i=0; i<L; i++) {
configuration[i] = 2*(gsl_rng_get(r) % 2) - 1;
}
gsl_rng_free(r);
}
void init_config_alternate(char *configuration, parameters params){
long int L= params.L;
for (int i=0; i<L; i=i+2) {
configuration[i]=1;
}
for (long int i=1; i<L; i=i+2) {
configuration[i]=-1;
}
}
void init_config_up(char *configuration, parameters params){
long int L= params.L;
for (int i=0; i<L; i++) {
configuration[i]=1;
}
}
void init_config_down(char *configuration, parameters params){
long int L= params.L;
for (int i=0; i<L; i++) {
configuration[i]=-1;
}
}
/*void main(){
long int L= 100;
char *configuration = malloc(L * sizeof(char));
gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);
double r_max = gsl_rng_max(r);
for (int i=0; i<L; i++) {
configuration[i] = 2*(gsl_rng_get(r) % 2) - 1;
printf("%d \n",configuration[i]);
}
gsl_rng_free(r);
free(configuration);
}*/