|
51 | 51 | * target_z: [m] position of target to focus at. Straight ahead. |
52 | 52 | * target_index: [1] relative index of component to focus at, e.g. next is +1 |
53 | 53 | * gap: [meV] Bandgap energy (unphysical) |
54 | | -* e_steps_low [50] Amount of possible intersections beneath the elastic line |
55 | | -* e_steps_high [50] Amount of possible intersections above the elastic line |
| 54 | +* e_steps_low [1] Amount of possible intersections beneath the elastic line |
| 55 | +* e_steps_high [1] Amount of possible intersections above the elastic line |
56 | 56 | * |
57 | 57 | * |
58 | 58 | * CALCULATED PARAMETERS: |
@@ -307,7 +307,7 @@ double zridd_gpu(double x1, double x2, struct neutron_params *neutron, struct ph |
307 | 307 | double root; |
308 | 308 | // Energy gain and energy loss spaces are not equally big. We check uniformly |
309 | 309 | // So we use two different ranges |
310 | | - double range_low = brack_mid - brack_low; |
| 310 | + double range_low = brack_mid - brack_low; |
311 | 311 | double range_high = brack_high - brack_mid; |
312 | 312 | // First in energy loss for the neutron |
313 | 313 | for (int i=0; i<phonon->e_steps_low_; i++){ |
@@ -335,25 +335,33 @@ double zridd_gpu(double x1, double x2, struct neutron_params *neutron, struct ph |
335 | 335 | void findroots_gpu(double brack_low, double brack_mid, double brack_high, |
336 | 336 | double *list, int* index, struct neutron_params *neutron, struct phonon_params *phonon) |
337 | 337 | { |
338 | | - double root,range=brack_mid-brack_low; |
339 | | - int i, steps=100; |
340 | | - |
341 | | - for (i=0; i<steps; i++) |
342 | | - { |
343 | | - root = zridd_gpu(brack_low+range*i/(int)steps, |
344 | | - brack_low+range*(i+1)/(int)steps, |
345 | | - neutron,phonon, ROOTACC); |
| 338 | + double root; |
| 339 | + // Energy gain and energy loss spaces are not equally big. We check uniformly |
| 340 | + // So we use two different ranges |
| 341 | + double range_low = brack_mid - brack_low; |
| 342 | + double range_high = brack_high - brack_mid; |
| 343 | + // First in energy loss for the neutron |
| 344 | + for (int i=0; i<phonon->e_steps_low_; i++){ |
| 345 | + root = zridd_gpu(brack_low+range_low*i/ phonon->e_steps_low_, |
| 346 | + brack_low+range_low*(i+1)/ phonon->e_steps_low_, |
| 347 | + neutron, phonon, ROOTACC); |
346 | 348 | if (root != UNUSED) |
347 | 349 | { |
348 | 350 | list[(*index)++]=root; |
349 | 351 | } |
350 | 352 | } |
351 | | - root = zridd_gpu(brack_mid, brack_high, neutron,phonon, ROOTACC); |
352 | | - if (root != UNUSED) |
353 | | - { |
| 353 | + |
| 354 | + // Then in energy gain for the neutron |
| 355 | + for (int i=0; i<phonon->e_steps_high_; i++){ |
| 356 | + root = zridd_gpu(brack_low+range_high*i/ phonon->e_steps_high_, |
| 357 | + brack_low+range_high*(i+1)/ phonon->e_steps_high_, |
| 358 | + neutron, phonon, ROOTACC); |
| 359 | + if (root != UNUSED){ |
354 | 360 | list[(*index)++]=root; |
355 | 361 | } |
| 362 | + } |
356 | 363 | } |
| 364 | + |
357 | 365 |
|
358 | 366 | #undef UNUSED |
359 | 367 | #undef MAXRIDD |
@@ -401,7 +409,22 @@ INITIALIZE |
401 | 409 | %} |
402 | 410 | TRACE |
403 | 411 | %{ |
404 | | - double* vf_list = (double *)calloc( e_steps_low*e_steps_high, sizeof(double)); // List of allowed final velocities. Has length of scan_steps |
| 412 | + double* vf_list; |
| 413 | + #ifdef OPENACC |
| 414 | + vf_list = (double *)malloc( (e_steps_low + e_steps_high)* sizeof(double)); // List of allowed final velocities. Has length of scan_steps |
| 415 | + #else |
| 416 | + vf_list = (double *)calloc( e_steps_low + e_steps_high, sizeof(double)); // List of allowed final velocities. Has length of scan_steps |
| 417 | + #endif |
| 418 | + if (!vf_list) { |
| 419 | + printf("Memory allocation failed, fatal error!\n"); |
| 420 | + exit(-1); |
| 421 | + } |
| 422 | + #ifdef OPENACC |
| 423 | + for (int ii=0; ii<e_steps_low+e_steps_high; ii++) { |
| 424 | + vf_list[ii]=0; |
| 425 | + } |
| 426 | + #endif |
| 427 | + |
405 | 428 | struct neutron_params neutron; |
406 | 429 | double t0, t1; /* Entry/exit time for cylinder */ |
407 | 430 | double v_i, v_f; /* Neutron velocities: initial, final */ |
|
0 commit comments