Thread safety of the ComponentAnalyticField and ComponentConstant classes

Hello,

I faintly remember both ComponentAnalyticField and ComponentConstant being thread safe once, but I could be mistaken. Running a sequential job on the drift of electrons with attachment turned off yields the expect results: the electrons drift the entirety of the drift gap (from gap to 0[cm]) and leave the drift medium. Meanwhile, the electrons will randomly cease their drift when running the same thing in parallel.

These are the histograms of the endpoint coordinate of some electrons, marked along the drift axis. The same behaviour can be observed for both ComponentAnalyticField and ComponentConstant. Using ComponentComsol yields flawless results in both parallel and sequential modes.

I’ve attached some files that will hopefully enable you to reproduce this behaviour. The file analytic.cpp contains the ComponentAnalyticField version and the file constant.cpp contains the ComponentConstant version.

thread_safe.zip (18.2 KB)

Sincerely,
Gabriel

EDIT:

I’ll have to correct myself on this statement: the same behaviour can also be observed with both ComponentComsol and ComponentAnsys123, it is just that for some reason they are a lot loss frequent so I did not notice the occurrences when visually inspecting the histograms at first.

I’m at home and I don’t have access to either software at the moment, so I had to improvise a slightly modified version of the Comsol and Gem examples. I had to increase the number of events and set the std output "# failed: " to actually be able to notice the behaviour, which could be related to the shorter drift distance that I had to use.

thread_safe_field.zip (1.5 MB)

Something strange that I’m noticing with the ViewDrift class in these modified examples is that I’m getting a lot less “kinks” when running in sequential mode. Seeing these new results makes me think that it is less of a component class problem and maybe something with one of the locks in MediumMagboltz?

Hi! Adding in the loop @hschindl

Hi @gabrielribcesario, thanks a lot for uncovering/reporting! Very interesting… Indeed, ComponentComsol is a rather trivial class so my gut feeling would also be that the issue lies somewhere else… I will try to run your example and debug…