aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-12-07 11:51:56 +0100
committerThomas White <taw@physics.org>2018-02-27 17:12:41 +0100
commit911a5a47ecee5fce2ad3d16bd1460f779011c083 (patch)
tree539204221aceafd73c8ce6ba140e6c5c59b3628a
parent0f24c4fb9451f1c32fb89534b37bf7f804e37d99 (diff)
pattern_sim: Add --flat
-rw-r--r--src/diffraction-gpu.c15
-rw-r--r--src/diffraction-gpu.h8
-rw-r--r--src/diffraction.c15
-rw-r--r--src/diffraction.h2
-rw-r--r--src/pattern_sim.c11
-rw-r--r--tests/gpu_sim_check.c4
6 files changed, 32 insertions, 23 deletions
diff --git a/src/diffraction-gpu.c b/src/diffraction-gpu.c
index 22abcfd2..ea50b3fa 100644
--- a/src/diffraction-gpu.c
+++ b/src/diffraction-gpu.c
@@ -72,7 +72,8 @@ struct gpu_context
};
-static void check_sinc_lut(struct gpu_context *gctx, int n, int no_fringes)
+static void check_sinc_lut(struct gpu_context *gctx, int n,
+ int no_fringes, int flat)
{
cl_int err;
cl_image_format fmt;
@@ -105,8 +106,10 @@ static void check_sinc_lut(struct gpu_context *gctx, int n, int no_fringes)
for ( i=1; i<SINC_LUT_ELEMENTS; i++ ) {
double x, val;
x = (double)i/SINC_LUT_ELEMENTS;
- if ( no_fringes && (x > 1.0/n) && (1.0-x > 1.0/n) ) {
+ if ( (flat || no_fringes) && (x > 1.0/n) && (1.0-x > 1.0/n) ) {
val = 0.0;
+ } else if ( flat ) {
+ val = n;
} else {
val = fabs(sin(M_PI*n*x)/sin(M_PI*x));
}
@@ -279,7 +282,7 @@ static int do_panels(struct gpu_context *gctx, struct image *image,
int get_diffraction_gpu(struct gpu_context *gctx, struct image *image,
int na, int nb, int nc, UnitCell *ucell,
- int no_fringes)
+ int no_fringes, int flat)
{
double ax, ay, az;
double bx, by, bz;
@@ -297,9 +300,9 @@ int get_diffraction_gpu(struct gpu_context *gctx, struct image *image,
}
/* Ensure all required LUTs are available */
- check_sinc_lut(gctx, na, no_fringes);
- check_sinc_lut(gctx, nb, no_fringes);
- check_sinc_lut(gctx, nc, no_fringes);
+ check_sinc_lut(gctx, na, no_fringes, flat);
+ check_sinc_lut(gctx, nb, no_fringes, flat);
+ check_sinc_lut(gctx, nc, no_fringes, flat);
/* Unit cell */
cell_get_cartesian(ucell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz);
diff --git a/src/diffraction-gpu.h b/src/diffraction-gpu.h
index c313859f..0b0e364b 100644
--- a/src/diffraction-gpu.h
+++ b/src/diffraction-gpu.h
@@ -3,11 +3,11 @@
*
* Calculate diffraction patterns by Fourier methods (GPU version)
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2010-2014 Thomas White <taw@physics.org>
+ * 2010-2017 Thomas White <taw@physics.org>
*
* This file is part of CrystFEL.
*
@@ -42,7 +42,7 @@ struct gpu_context;
extern int get_diffraction_gpu(struct gpu_context *gctx, struct image *image,
int na, int nb, int nc, UnitCell *ucell,
- int no_fringes);
+ int no_fringes, int flat);
extern struct gpu_context *setup_gpu(int no_sfac,
const double *intensities,
const unsigned char *flags,
@@ -53,7 +53,7 @@ extern void cleanup_gpu(struct gpu_context *gctx);
static int get_diffraction_gpu(struct gpu_context *gctx, struct image *image,
int na, int nb, int nc, UnitCell *ucell,
- int no_fringes)
+ int no_fringes, int flat)
{
/* Do nothing */
ERROR("This copy of CrystFEL was not compiled with OpenCL support.\n");
diff --git a/src/diffraction.c b/src/diffraction.c
index 93674f52..4cceba0e 100644
--- a/src/diffraction.c
+++ b/src/diffraction.c
@@ -48,7 +48,7 @@
#define SINC_LUT_ELEMENTS (4096)
-static double *get_sinc_lut(int n, int no_fringes)
+static double *get_sinc_lut(int n, int no_fringes, int flat)
{
int i;
double *lut;
@@ -63,8 +63,10 @@ static double *get_sinc_lut(int n, int no_fringes)
for ( i=1; i<SINC_LUT_ELEMENTS; i++ ) {
double x, val;
x = (double)i/SINC_LUT_ELEMENTS;
- if ( no_fringes && (x > 1.0/n) && (1.0-x > 1.0/n) ) {
+ if ( (flat || no_fringes) && (x > 1.0/n) && (1.0-x > 1.0/n) ) {
val = 0.0;
+ } else if ( flat ) {
+ val = n;
} else {
val = fabs(sin(M_PI*n*x)/sin(M_PI*x));
}
@@ -716,7 +718,8 @@ struct sample *generate_twocolour(struct image *image)
void get_diffraction(struct image *image, int na, int nb, int nc,
const double *intensities, const double *phases,
const unsigned char *flags, UnitCell *cell,
- GradientMethod m, const SymOpList *sym, int no_fringes)
+ GradientMethod m, const SymOpList *sym,
+ int no_fringes, int flat)
{
double ax, ay, az;
double bx, by, bz;
@@ -728,9 +731,9 @@ void get_diffraction(struct image *image, int na, int nb, int nc,
cell_get_cartesian(cell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz);
- lut_a = get_sinc_lut(na, no_fringes);
- lut_b = get_sinc_lut(nb, no_fringes);
- lut_c = get_sinc_lut(nc, no_fringes);
+ lut_a = get_sinc_lut(na, no_fringes, flat);
+ lut_b = get_sinc_lut(nb, no_fringes, flat);
+ lut_c = get_sinc_lut(nc, no_fringes, flat);
for ( i=0; i<image->nsamples; i++ ) {
diff --git a/src/diffraction.h b/src/diffraction.h
index 28f3ec0a..ca4e3bde 100644
--- a/src/diffraction.h
+++ b/src/diffraction.h
@@ -52,7 +52,7 @@ extern void get_diffraction(struct image *image, int na, int nb, int nc,
const double *intensities, const double *phases,
const unsigned char *flags, UnitCell *cell,
GradientMethod m, const SymOpList *sym,
- int no_fringes);
+ int no_fringes, int flat);
extern struct sample *generate_tophat(struct image *image);
diff --git a/src/pattern_sim.c b/src/pattern_sim.c
index a3fea8e3..52ed6d48 100644
--- a/src/pattern_sim.c
+++ b/src/pattern_sim.c
@@ -3,11 +3,11 @@
*
* Simulate diffraction patterns from small crystals
*
- * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2009-2016 Thomas White <taw@physics.org>
+ * 2009-2017 Thomas White <taw@physics.org>
* 2013-2014 Chun Hong Yoon <chun.hong.yoon@desy.de>
* 2014 Valerio Mariani
* 2013 Alexandra Tolstikova
@@ -95,6 +95,7 @@ static void show_help(const char *s)
" --background=<N> Add N photons of Poisson background (default 0).\n"
" --template=<file> Take orientations from stream <file>.\n"
" --no-fringes Exclude the side maxima of Bragg peaks.\n"
+" --flat Make Bragg peaks flat.\n"
" --beam-bandwidth Beam bandwidth as a fraction. Default 1%%.\n"
" --photon-energy Photon energy in eV. Default 9000.\n"
" --nphotons Number of photons per X-ray pulse. Default 1e12.\n"
@@ -388,6 +389,7 @@ int main(int argc, char *argv[])
char *template_file = NULL;
Stream *st = NULL;
int no_fringes = 0;
+ int flat = 0;
double nphotons = 1e12;
double beam_radius = 1e-6; /* metres */
double bandwidth = 0.01;
@@ -417,6 +419,7 @@ int main(int argc, char *argv[])
{"spectrum", 1, NULL, 'x'},
{"really-random", 0, &config_random, 1},
{"no-fringes", 0, &no_fringes, 1},
+ {"flat", 0, &flat, 1},
{"gpu-dev", 1, NULL, 2},
{"min-size", 1, NULL, 3},
@@ -990,11 +993,11 @@ int main(int argc, char *argv[])
gpu_dev);
}
err = get_diffraction_gpu(gctx, &image, na, nb, nc,
- cell, no_fringes);
+ cell, no_fringes, flat);
} else {
get_diffraction(&image, na, nb, nc, intensities, phases,
- flags, cell, grad, sym, no_fringes);
+ flags, cell, grad, sym, no_fringes, flat);
}
if ( err ) {
ERROR("Diffraction calculation failed.\n");
diff --git a/tests/gpu_sim_check.c b/tests/gpu_sim_check.c
index ba51b8db..8c666775 100644
--- a/tests/gpu_sim_check.c
+++ b/tests/gpu_sim_check.c
@@ -171,7 +171,7 @@ int main(int argc, char *argv[])
gpu_image.spectrum = generate_tophat(&gpu_image);
start = get_hires_seconds();
- if ( get_diffraction_gpu(gctx, &gpu_image, 8, 8, 8, cell, 1) ) {
+ if ( get_diffraction_gpu(gctx, &gpu_image, 8, 8, 8, cell, 0, 0) ) {
return 1;
}
end = get_hires_seconds();
@@ -195,7 +195,7 @@ int main(int argc, char *argv[])
start = get_hires_seconds();
get_diffraction(&cpu_image, 8, 8, 8, NULL, NULL, NULL, cell,
- GRADIENT_MOSAIC, sym, 1);
+ GRADIENT_MOSAIC, sym, 0, 0);
end = get_hires_seconds();
cpu_time = end - start;