summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fracture.c6
-rw-r--r--src/graph_create.c2
-rw-r--r--src/graph_genfunc.c36
3 files changed, 22 insertions, 22 deletions
diff --git a/src/fracture.c b/src/fracture.c
index 260f04f..dbe9ff5 100644
--- a/src/fracture.c
+++ b/src/fracture.c
@@ -186,9 +186,9 @@ int main(int argc, char *argv[]) {
char *a_filename;
if (save_cluster_dist) {
cluster_size_dist =
- (uint32_t *)malloc(max_verts * sizeof(uint32_t));
+ (uint32_t *)calloc(max_verts, sizeof(uint32_t));
avalanche_size_dist =
- (uint32_t *)malloc(max_edges * sizeof(uint32_t));
+ (uint32_t *)calloc(max_edges, sizeof(uint32_t));
c_filename = (char *)malloc(filename_len * sizeof(char));
a_filename = (char *)malloc(filename_len * sizeof(char));
@@ -241,7 +241,7 @@ int main(int argc, char *argv[]) {
char *d_filename;
if (save_damage) {
damage =
- (uint32_t *)malloc(max_edges * sizeof(uint32_t));
+ (uint32_t *)calloc(max_edges, sizeof(uint32_t));
d_filename = (char *)malloc(filename_len * sizeof(char));
snprintf(d_filename, filename_len, "damg_%c_%c_%c_%d_%g_%g.dat", lattice_c, boundc, boundc2, L, beta, crack_len);
diff --git a/src/graph_create.c b/src/graph_create.c
index fdb1bf6..1c06052 100644
--- a/src/graph_create.c
+++ b/src/graph_create.c
@@ -667,7 +667,7 @@ graph_t *graph_create(lattice_t lattice, bound_t bound, uint_t L, bool dual, cho
bool side_bounds;
switch (lattice) {
case (VORONOI_LATTICE):
- return ini_voro_graph(L, bound, dual, genfunc_hyperuniform, c);
+ return ini_voro_graph(L, bound, dual, genfunc_uniform, c);
case (SQUARE_LATTICE):
if (bound == EMBEDDED_BOUND) side_bounds = true;
else side_bounds = false;
diff --git a/src/graph_genfunc.c b/src/graph_genfunc.c
index 991e127..39a8480 100644
--- a/src/graph_genfunc.c
+++ b/src/graph_genfunc.c
@@ -13,6 +13,10 @@ double *genfunc_uniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned i
return lattice;
}
+double g(double rho, double dist) {
+ return 1 - gsl_sf_exp(-M_PI * rho * dist);
+}
+
double *genfunc_hyperuniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num) {
*num = pow(L / 2 + 1, 2) + pow((L + 1) / 2, 2);
@@ -49,25 +53,21 @@ double *genfunc_hyperuniform(unsigned int L, bound_t boundary, gsl_rng *r, unsig
while(reject) {
x = gsl_ran_flat(r, 0, 1);
y = gsl_ran_flat(r, 0, 1);
- reject = false;
+ double pp = 1;
for (unsigned int j = 0; j < i; j++) {
- double *ds = (double *)malloc(5 * sizeof(double));
- ds[0] = pow(x-lattice[2*j],2)+pow(y-lattice[2*j+1],2);
- ds[1] = pow(x-lattice[2*j] + 1,2)+pow(y-lattice[2*j+1],2);
- ds[2] = pow(x-lattice[2*j] - 1,2)+pow(y-lattice[2*j+1],2);
- ds[3] = pow(x-lattice[2*j],2)+pow(y-lattice[2*j+1] + 1,2);
- ds[4] = pow(x-lattice[2*j],2)+pow(y-lattice[2*j+1] - 1,2);
- double min_val = 100;
- for (unsigned int k = 0; k < 5; k++) {
- if (min_val > ds[k]) {
- min_val = ds[k];
- }
- }
- if (1-gsl_sf_exp(-M_PI * rho * min_val) < gsl_ran_flat(r, 0, 1)) {
- reject = true;
- break;
- }
- }
+ double ds0, ds1, ds2, ds3, ds4, ds5, ds6, ds7, ds8;
+ ds0 = pow(x-lattice[2*j],2)+pow(y-lattice[2*j+1],2);
+ ds1 = pow(x-lattice[2*j] + 1,2)+pow(y-lattice[2*j+1],2);
+ ds2 = pow(x-lattice[2*j] - 1,2)+pow(y-lattice[2*j+1],2);
+ ds3 = pow(x-lattice[2*j],2)+pow(y-lattice[2*j+1] + 1,2);
+ ds4 = pow(x-lattice[2*j],2)+pow(y-lattice[2*j+1] - 1,2);
+ ds5 = pow(x-lattice[2*j] + 1,2)+pow(y-lattice[2*j+1] + 1,2);
+ ds6 = pow(x-lattice[2*j] + 1,2)+pow(y-lattice[2*j+1] - 1,2);
+ ds7 = pow(x-lattice[2*j] - 1,2)+pow(y-lattice[2*j+1] + 1,2);
+ ds8 = pow(x-lattice[2*j] - 1,2)+pow(y-lattice[2*j+1] - 1,2);
+ pp *= g(rho, ds0) * g(rho, ds1) * g(rho, ds2) * g(rho, ds3) * g(rho, ds4) * g(rho, ds5) * g(rho, ds6) * g(rho, ds7) * g(rho, ds8);
+ }
+ if (pp > gsl_ran_flat(r, 0, 1)) reject = false;
}
lattice[2*start + 2 * i] = x;
lattice[2*start + 2 * i + 1] = y;