aboutsummaryrefslogtreecommitdiff
path: root/src/diffraction-gpu.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-05-17 17:03:48 +0200
committerThomas White <taw@physics.org>2019-05-29 10:42:04 +0200
commit94b0050cc7735c3e1635cbc89c13c6b2c49c69c8 (patch)
tree009039e182541db4544683632c9153ff46fa27ef /src/diffraction-gpu.c
parent36e3370feddeb8dd18f97dc5db4da8e96c9f5c79 (diff)
Use Spectrum API for simulation
Diffstat (limited to 'src/diffraction-gpu.c')
-rw-r--r--src/diffraction-gpu.c26
1 files changed, 15 insertions, 11 deletions
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; i<image->nsamples; 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"