aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-07-14 15:10:37 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:33 +0100
commitc6af54b9a326119ab43a06fd209d2009df64f07e (patch)
tree8115216e90662a06cc802267b53fb9e5a6117085
parent812bce99717e18289b02f515180c8d9ae8ca1827 (diff)
partial_sim: Use flat noise in cell parameters
-rw-r--r--src/partial_sim.c18
-rw-r--r--src/utils.c13
-rw-r--r--src/utils.h2
3 files changed, 24 insertions, 9 deletions
diff --git a/src/partial_sim.c b/src/partial_sim.c
index ee48f0f6..6dafc4ba 100644
--- a/src/partial_sim.c
+++ b/src/partial_sim.c
@@ -44,15 +44,15 @@ static void mess_up_cell(UnitCell *cell)
//cell_print(cell);
cell_get_reciprocal(cell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz);
- ax = gaussian_noise(ax, cnoise*fabs(ax)/100.0);
- ay = gaussian_noise(ay, cnoise*fabs(ay)/100.0);
- az = gaussian_noise(az, cnoise*fabs(az)/100.0);
- bx = gaussian_noise(bx, cnoise*fabs(bx)/100.0);
- by = gaussian_noise(by, cnoise*fabs(by)/100.0);
- bz = gaussian_noise(bz, cnoise*fabs(bz)/100.0);
- cx = gaussian_noise(cx, cnoise*fabs(cx)/100.0);
- cy = gaussian_noise(cy, cnoise*fabs(cy)/100.0);
- cz = gaussian_noise(cz, cnoise*fabs(cz)/100.0);
+ ax = flat_noise(ax, cnoise*fabs(ax)/100.0);
+ ay = flat_noise(ay, cnoise*fabs(ay)/100.0);
+ az = flat_noise(az, cnoise*fabs(az)/100.0);
+ bx = flat_noise(bx, cnoise*fabs(bx)/100.0);
+ by = flat_noise(by, cnoise*fabs(by)/100.0);
+ bz = flat_noise(bz, cnoise*fabs(bz)/100.0);
+ cx = flat_noise(cx, cnoise*fabs(cx)/100.0);
+ cy = flat_noise(cy, cnoise*fabs(cy)/100.0);
+ cz = flat_noise(cz, cnoise*fabs(cz)/100.0);
cell_set_reciprocal(cell, ax, ay, az, bx, by, bz, cx, cy, cz);
//STATUS("Changed:\n");
diff --git a/src/utils.c b/src/utils.c
index 4b4bfb51..6b29627f 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -121,6 +121,19 @@ void progress_bar(int val, int total, const char *text)
}
+double random_flat(double max)
+{
+ return max * (double)random()/RAND_MAX;
+}
+
+
+double flat_noise(double expected, double width)
+{
+ double noise = random_flat(2.0*width);
+ return expected+noise-width;
+}
+
+
double gaussian_noise(double expected, double stddev)
{
double x1, x2, noise;
diff --git a/src/utils.h b/src/utils.h
index 5e05a7f3..1179a57f 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -91,6 +91,8 @@ extern int assplode(const char *a, const char *delims, char ***pbits,
AssplodeFlag flags);
extern void progress_bar(int val, int total, const char *text);
+extern double random_flat(double max);
+extern double flat_noise(double expected, double width);
extern double gaussian_noise(double expected, double stddev);
extern int poisson_noise(double expected);