From 0f6782c9e5a9171d69d8e62dff33a558ba542d58 Mon Sep 17 00:00:00 2001 From: pants Date: Wed, 31 Aug 2016 11:57:40 -0400 Subject: did some refactoring --- src/randfuncs.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/randfuncs.c') diff --git a/src/randfuncs.c b/src/randfuncs.c index 260c047..35b9f56 100644 --- a/src/randfuncs.c +++ b/src/randfuncs.c @@ -1,7 +1,7 @@ #include "fracture.h" -double *genfunc_uniform(unsigned int L, gsl_rng *r, unsigned int *num) { +double *genfunc_uniform(unsigned int L, bound_t boundary, gsl_rng *r, unsigned int *num) { *num = pow(L / 2 + 1, 2) + pow((L + 1) / 2, 2); double *lattice = (double *)malloc(2 * (*num) * sizeof(double)); @@ -13,7 +13,7 @@ double *genfunc_uniform(unsigned int L, gsl_rng *r, unsigned int *num) { return lattice; } -double *genfunc_hyperuniform(unsigned int L, gsl_rng *r, unsigned int *num) { +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); // necessary to prevent crashing when underflow occurs @@ -21,7 +21,27 @@ double *genfunc_hyperuniform(unsigned int L, gsl_rng *r, unsigned int *num) { double *lattice = (double *)malloc(2 * (*num) * sizeof(double)); double rho = *num; - for (unsigned int i = 0; i < (*num); i++) { + unsigned int to_gen = *num; + + if (boundary == EMBEDDED_BOUND) { + for (unsigned int i = 0; i < L / 2; i++) { + lattice[2 * i] = 0; + lattice[2 * i + 1] = (2. * i + 1.) / L; + + lattice[L / 2 + 2 * i] = 1; + lattice[L / 2 + 2 * i + 1] = (2. * i + 1.) / L; + + lattice[L + 2 * i] = (2. * i + 1.) / L; + lattice[L + 2 * i + 1] = 0; + + lattice[3 * L / 2 + 2 * i] = (2. * i + 1.) / L; + lattice[3 * L / 2 + 2 * i + 1] = 1; + } + + to_gen -= 2 * L; + } + + for (unsigned int i = 0; i < to_gen; i++) { bool reject = true; double x, y; while(reject) { -- cgit v1.2.3-70-g09d2