Trouble running simulation in non-uniform electric field

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

_Geant4 Version:_v11.1.2
_Operating System:_Windows 10
_Compiler/Version:_Visual Studio 17 2022
_CMake Version:_3.26.3


Hello! I’m just getting into Geant4, and currently trying to simulate electrons in an air gap discharge. At the start I used a uniform electric field in my simulation, and it worked perfectly fine. Then I tried to impelment a non-uniform field in my simulation. I generated my field data through COMSOL, and imported it into my simulation via modified codes from the Purge Magnet example. At first everything seemed fine. The field was imported successfully, and could be properly visualized. But when I tried to run the simulation, it just didn’t work. I tried several different electric field layouts. Sometimes the simulation seemingly froze and nothing appeared in the command window. Sometimes I got a warning message like the one below. Could someone enlighten me on this situation?
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : GeomField0003
issued by : G4ChordFinder::FindNextChord()
Exceeded maximum number of trials= 75
Current sagita dist= -nan
Max sagita dist= 0.25
Step sizes (actual and proposed):
Last trial = 1e-73
Next trial = 1e-74
Proposed for chord = 2e-73

*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Hello. In the case of the exception which you report, it seems that the integration accuracy required (requested) cannot be achieved, as the size of the trial step was 1e-73 (millimeters). One reason could be that the electric field is discontinuous - potentially at its edge (between the region which is included and the region outside it.)
Could you use “/event/verbose 1” first to see in which event the problem occurs, and then “/tracking/verbose 1” to print out information about the tracks – it would give a first idea where the problem is occurring.

There may be a problem with the integrator - but I suggest first to check that the evaluation of the electric field provides finite and reasonable values. ( Test it with sample points, but also add some printing in the field evaluation method to report the position (with high precision g4cout.precision(9); ) then run the simulation to see whether the values appear reasonable in general (no NaNs, values which are not huge etc) and how they behave before the warning and when the program is no longer responding.

(You may need to redirect the output to a file and look at it with a program like ‘less’ or an editor if it’s not too large. ) If you can share sample parts of the output, such the last 30-50 lines before a warning, it could enable me to help better.

After this it may be necessary to provide you with a modified version of one or two classes, with additional printing to help debug the problem. Alternatively, if you can share a sample field which fails in Purging Magnet I can investigate myself.

Best regards,
John Apostolakis

Hello John. Thanks for your response. Sorry about my delay in response.

I have tried three sample fields, two of which are the same field generated via COMSOL, with different resolutions (100 by 100 by 130 and 50 by 50 by 65 and 30 by 30 by 39). The third one is one where every point has the exact same field value, and thus should yield a uniform field. Here are one of the fields generated by COMSOL and the uniform tester field.

ElectricFieldSimulation30.txt (3.4 MB)
ElectricFieldSimulationtest.txt (26.4 KB)

I have enabled event verbose and tracking verbose, and this is what I have got in the output before the first exception.

Step# X Y Z KineE dEStep StepLeng TrakLeng Volume Process
0 -1.386 cm 9.149 mm 6.875 cm 75 keV 0 eV 0 fm 0 fm physWorld initStep
1 -1.441 cm 8.698 mm 7.132 cm 80.43 keV 2.1 keV 2.686 mm 2.686 mm physWorld eIoni
2 -1.535 cm 57.52 um 7.333 cm 2.078 TeV 3.104 keV 9.7 mm 1.239 cm physWorld msc
3 -1.886 cm -2.613 cm 7.775 cm 2.078 TeV 6.379 keV 2.679 cm 3.918 cm physWorld eIoni
4 -2.482 cm -7.509 cm 8.597 cm 2.078 TeV 8.75 keV 5 cm 8.918 cm physWorld StepLimiter
5 -3.047 cm -12.41 cm 9.418 cm 2.078 TeV 11.54 keV 5 cm 13.92 cm physWorld StepLimiter
6 -3.278 cm -14.46 cm 9.761 cm 2.078 TeV 2.749 keV 2.09 cm 16.01 cm physWorld eIoni
7 -3.549 cm -17 cm 10.18 cm 2.078 TeV 5.296 keV 2.588 cm 18.6 cm physWorld eIoni
8 -4.016 cm -21.91 cm 10.98 cm 2.078 TeV 8.275 keV 5 cm 23.6 cm physWorld StepLimiter
9 -4.273 cm -24.96 cm 11.29 cm 2.32 TeV 8.036 keV 3.116 cm 26.71 cm physWorld eIoni
10 -4.632 cm -29.71 cm 9.771 cm 2.32 TeV 14.94 keV 5 cm 31.71 cm physWorld StepLimiter
11 -4.931 cm -34.11 cm 8.337 cm 2.32 TeV 5.624 keV 4.639 cm 36.35 cm physWorld eIoni
12 -5.187 cm -38.85 cm 6.765 cm 2.32 TeV 11.2 keV 5 cm 41.35 cm physWorld StepLimiter
13 -5.355 cm -42.94 cm 5.382 cm 2.32 TeV 11.02 keV 4.32 cm 45.67 cm physWorld eIoni
14 -5.471 cm -47.03 cm 3.973 cm 2.32 TeV 7.267 keV 4.321 cm 49.99 cm physWorld eIoni
15 -5.534 cm -51.74 cm 2.314 cm 2.32 TeV 8.013 keV 5 cm 54.99 cm physWorld StepLimiter
16 -5.542 cm -54.86 cm 1.214 cm 2.32 TeV 7.057 keV 3.304 cm 58.29 cm physWorld eIoni
17 -5.483 cm -59.57 cm -4.524 mm 2.32 TeV 12.74 keV 5 cm 63.29 cm physWorld StepLimiter
18 -5.395 cm -64.28 cm -2.12 cm 2.32 TeV 10.99 keV 5 cm 68.29 cm physWorld StepLimiter
19 -5.307 cm -69 cm -3.788 cm 2.32 TeV 10.51 keV 5 cm 73.29 cm physWorld StepLimiter
20 -5.299 cm -69.4 cm -3.931 cm 2.32 TeV 285.7 eV 4.286 mm 73.72 cm physWorld eIoni
21 -5.299 cm -64.7 cm -5.636 cm 6.453e+101 J 10.96 keV 5 cm 78.72 cm physWorld StepLimiter
22 -5.299 cm -60 cm -7.342 cm 6.453e+101 J 10.35 keV 5 cm 83.72 cm physWorld StepLimiter
23 -5.299 cm -58.33 cm -7.948 cm 6.453e+101 J 3.824 keV 1.779 cm 85.5 cm physWorld eIoni
24 -5.299 cm -53.63 cm -9.654 cm 6.453e+101 J 10.03 keV 5 cm 90.5 cm physWorld StepLimiter
25 -5.299 cm -48.93 cm -11.36 cm 6.453e+101 J 7.894 keV 5 cm 95.5 cm physWorld StepLimiter
26 -5.299 cm -44.23 cm -13.06 cm 6.453e+101 J 8.404 keV 5 cm 1.005 m physWorld StepLimiter
27 -5.299 cm -43.56 cm -13.31 cm 6.453e+101 J 622 eV 7.123 mm 1.012 m physWorld eIoni
28 -5.299 cm -38.86 cm -15.01 cm 6.453e+101 J 7.241 keV 5 cm 1.062 m physWorld StepLimiter
29 -5.299 cm -34.36 cm -16.64 cm 6.453e+101 J 9.412 keV 4.78 cm 1.11 m physWorld eIoni
30 -5.299 cm -29.66 cm -18.35 cm 6.453e+101 J 9.231 keV 5 cm 1.16 m physWorld StepLimiter
31 -5.299 cm -29.52 cm -18.4 cm 6.453e+101 J 302.5 eV 1.534 mm 1.161 m physWorld eIoni
32 -5.299 cm -24.82 cm -20.11 cm 6.453e+101 J 10.83 keV 5 cm 1.211 m physWorld StepLimiter
33 -5.299 cm -24.35 cm -20.28 cm 6.453e+101 J 495.7 eV 5.012 mm 1.216 m physWorld eIoni
34 -5.299 cm -19.65 cm -21.98 cm 6.453e+101 J 10.47 keV 5 cm 1.266 m physWorld StepLimiter
35 -5.299 cm -14.95 cm -23.69 cm 6.453e+101 J 12.12 keV 5 cm 1.316 m physWorld StepLimiter
36 -5.299 cm -10.25 cm -25.39 cm 6.453e+101 J 14.54 keV 5 cm 1.366 m physWorld StepLimiter
37 -5.299 cm -5.547 cm -27.1 cm 6.453e+101 J 13.15 keV 5 cm 1.416 m physWorld StepLimiter
38 -5.299 cm -8.472 mm -28.8 cm 6.453e+101 J 10.97 keV 5 cm 1.466 m physWorld StepLimiter
39 -5.299 cm 3.853 cm -30.51 cm 6.453e+101 J 11.99 keV 5 cm 1.516 m physWorld StepLimiter
40 -5.299 cm 7.383 cm -31.79 cm 6.453e+101 J 7.899 keV 3.755 cm 1.554 m physWorld eIoni
41 -5.299 cm 12.08 cm -33.49 cm 6.453e+101 J 8.267 keV 5 cm 1.604 m physWorld StepLimiter
42 -5.299 cm 16.78 cm -35.2 cm 6.453e+101 J 8.098 keV 5 cm 1.654 m physWorld StepLimiter
43 -5.299 cm 21.48 cm -36.9 cm 6.453e+101 J 11.58 keV 5 cm 1.704 m physWorld StepLimiter
44 -5.299 cm 26.18 cm -38.61 cm 6.453e+101 J 9.925 keV 5 cm 1.754 m physWorld StepLimiter
45 -5.299 cm 30.88 cm -40.31 cm 6.453e+101 J 9.677 keV 5 cm 1.804 m physWorld StepLimiter
46 -5.299 cm 35.58 cm -42.02 cm 6.453e+101 J 12.9 keV 5 cm 1.854 m physWorld StepLimiter
47 -5.299 cm 40.28 cm -43.72 cm 6.453e+101 J 10.07 keV 5 cm 1.904 m physWorld StepLimiter
48 -5.299 cm 44.99 cm -45.43 cm 6.453e+101 J 8.967 keV 5 cm 1.954 m physWorld StepLimiter
49 -5.299 cm 47.09 cm -46.19 cm 6.453e+101 J 4.345 keV 2.24 cm 1.976 m physWorld eIoni
50 -5.299 cm 49.2 cm -46.96 cm 6.453e+101 J 1.92 keV 2.246 cm 1.999 m physWorld eIoni
51 -5.299 cm 52.31 cm -48.09 cm 6.453e+101 J 7.259 keV 3.311 cm 2.032 m physWorld eIoni
52 -5.299 cm 55.62 cm -49.29 cm 6.453e+101 J 8.631 keV 3.516 cm 2.067 m physWorld eIoni
53 -5.299 cm 55.69 cm -49.31 cm 6.453e+101 J 108.1 eV 709.8 um 2.068 m physWorld eIoni
54 -5.299 cm 60.39 cm -51.02 cm 6.453e+101 J 9.758 keV 5 cm 2.118 m physWorld StepLimiter
55 -5.299 cm 65.09 cm -52.72 cm 6.453e+101 J 10.96 keV 5 cm 2.168 m physWorld StepLimiter
56 -5.299 cm 68.98 cm -54.14 cm 6.453e+101 J 4.771 keV 4.145 cm 2.209 m physWorld eIoni

From what I can tell, it seems that the kinetic energy of my particle quickly rises to an unreasonable value after just 2 steps. Since the simulated discharge is a 5MV one, and the initial energy of my electron is 75keV, it’s not possible to have an electron reach beyond 2TeV.

All my tests have yielded the same consistent result, with electron kinetic energy reaching exactly 2.078TeV at step #2. What’s the possible cause of this problem? Does this 2.078TeV value have some specific meaning?

Best regards,
Albert

Hello Albino Traz,
Have you fixed this mistake?

Hello, I haven’t solved this problem yet. I’m currently running my program with a uniform field in place.

Can you send your source code to me? I want to use the source as a reference via hungbt1908@gmail.com.
Thank you.