From 94b0050cc7735c3e1635cbc89c13c6b2c49c69c8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 17 May 2019 17:03:48 +0200 Subject: Use Spectrum API for simulation --- src/diffraction-gpu.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/diffraction-gpu.c') diff --git a/src/diffraction-gpu.c b/src/diffraction-gpu.c index 9cbfdf33..e2bce0cc 100644 --- a/src/diffraction-gpu.c +++ b/src/diffraction-gpu.c @@ -283,7 +283,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 flat) + int no_fringes, int flat, int n_samples) { double ax, ay, az; double bx, by, bz; @@ -294,6 +294,8 @@ int get_diffraction_gpu(struct gpu_context *gctx, struct image *image, int n_neg = 0; int n_nan = 0; int i; + double kmin, kmax, step; + double tot = 0.0; if ( gctx == NULL ) { ERROR("GPU setup failed.\n"); @@ -338,23 +340,25 @@ int get_diffraction_gpu(struct gpu_context *gctx, struct image *image, } } - double tot = 0.0; - for ( i=0; insamples; i++ ) { + spectrum_get_range(image->spectrum, &kmin, &kmax); + step = (kmax-kmin)/n_samples; + for ( i=0; i<=n_samples; i++ ) { + + double k = kmin + i*step; + double prob; - printf("%.3f eV, weight = %.5f\n", - ph_lambda_to_eV(1.0/image->spectrum0[i].k), - image->spectrum0[i].weight); + /* Probability = p.d.f. times step width */ + prob = step * spectrum_get_density_at_k(image->spectrum, k); - err = do_panels(gctx, image, image->spectrum0[i].k, - image->spectrum0[i].weight, - &n_inf, &n_neg, &n_nan); + STATUS("Wavelength: %e m, weight = %.5f\n", 1.0/k, prob); + err = do_panels(gctx, image, k, prob, &n_inf, &n_neg, &n_nan); if ( err ) return 1; - tot += image->spectrum0[i].weight; + tot += prob; } - printf("total weight = %f\n", tot); + STATUS("Total weight = %f\n", tot); if ( n_neg + n_inf + n_nan ) { ERROR("WARNING: The GPU calculation produced %i negative" -- cgit v1.2.3