McStasMcXtrace / McCode

The home of the McStas (neutrons) and McXtrace (x-rays) Monte-Carlo ray-tracing instrument simulation codes.
https://github.com/McStasMcXtrace/McCode/wiki
GNU General Public License v3.0
77 stars 54 forks source link

GPUHack Polarisation: magnetic field stack needs to be redesigned. #1072

Open ebknudsen opened 3 years ago

ebknudsen commented 3 years ago

The construction with a global mcMagnet which is toggled by MAGNET_ON/OFF macros does not work anymore. Instead the magnet functions need to deal with the particle mcMagnet directly instead of through the MAGNET_ON/OFF macros.

In general it can't work with a global stack since field push and pop are thread functions (obviously) as they follow the particle.

ebknudsen commented 3 years ago

subissue of #948

ebknudsen commented 3 years ago

Working proposal (A):

  1. INITIALIZE-time, components that wish to use the subsystem may call a function that injects the function, its parameters, and the position of the component into a list of fields. This function returns a unique ID of the function (binary sequence for instance).
  2. TRACE-time particles may activate/deactivate that particular field simply by adding/subtracting the ID of the field to _particle->mcMagnet.
  3. The precession routine should then pick fields+parameters from the stack according to the active IDs. One upshot is that this can allow paths that exit fields out of sequence. This way mcMagnet stays a single number tagged on to the particle (i.e. we avoid pulling one stack per particle along).

Working proposal B: we make _particle->mcMagnet a **magnetic_field_info. When a particle encounters a field_push an alloc would occur and a new stack item would get put in line. when Popped, this would be removed again. Care would have to be taken for adding/removing the first field such that pointers get updated correctly. Downside is that this would generate lots of alloc's.