henry2004y / TestParticle.jl

Test particle tracing in electromagnetic field
https://henry2004y.github.io/TestParticle.jl/dev/
MIT License
15 stars 3 forks source link

Add native Boris method #96

Closed henry2004y closed 10 months ago

henry2004y commented 10 months ago

It's time to add some native particle pushers in the package!

Background

The Boris method is the de facto particle pusher in plasma physics, because of its excellent conservation behavior and relative simplicity. The Boris method is a second order method with discrete phase error related to the choice of fixed time step. If the time step is not fixed, this method can still be used, but the conservation of phase space trajectory will be violated.

Why do we need this?

The Boris method is specifically designed for the expression of Lorentz force. A general ODE solver in OrdinaryDiffEq.jl does not take into account the special form of the Lorentz equation, which is also the reason why the Boris method does not exist in OrdinaryDiffEq.jl. With my recent tests on multiple algorithms from OrdinaryDiffEq.jl, the default Tsit5() has poor conservation properties in many cases, and there are only a few options that display nice energy conservation behaviors #73. The Boris method also requires a fixed timestep for conservation, which makes it a bit harder for investigating a new problem, but we should have a version of our own in this package.

Plan

codecov[bot] commented 10 months ago

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (fd5d83e) 47.10% compared to head (7731b61) 52.79%.

Files Patch % Lines
src/pusher.jl 94.52% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #96 +/- ## ========================================== + Coverage 47.10% 52.79% +5.69% ========================================== Files 9 10 +1 Lines 535 608 +73 ========================================== + Hits 252 321 +69 - Misses 283 287 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

TCLiuu commented 10 months ago

This is an exciting idea. Do you have a ToDo list? Maybe I can do something.

henry2004y commented 10 months ago

This is an exciting idea. Do you have a ToDo list? Maybe I can do something.

Yes! I've added a ToDo list above. After I clean up the code a bit more, feel free to directly push to this branch!

Adding the Boris method was not in my original plan for this package. I want to try this now because of some performance issue I encountered recently with a large number of test particles (> 1e7). Tsit5() is fast, at a cost of violation of phase space conservation; Vern9() together with a time step limitation based on local gyroperiod has much nicer conservation behavior, but it consumes a lot of memory with extremely high GC time (>70% in Julia 1.9.3 and 1.10.0-rc1). I frequently encounterd OOM errors running the trials on a cluster.

By adding a native particle pusher, the high GC time may be largely avoided.

github-actions[bot] commented 10 months ago
Benchmark result # Judge result # Benchmark Report for */home/runner/work/TestParticle.jl/TestParticle.jl* ## Job Properties * Time of benchmarks: - Target: 13 Nov 2023 - 23:01 - Baseline: 13 Nov 2023 - 23:02 * Package commits: - Target: 118fcb - Baseline: fd5d83 * Julia commits: - Target: bed2cd - Baseline: bed2cd * Julia command flags: - Target: None - Baseline: None * Environment variables: - Target: None - Baseline: None ## Results A ratio greater than `1.0` denotes a possible regression (marked with :x:), while a ratio less than `1.0` denotes a possible improvement (marked with :white_check_mark:). Only significant results - results that indicate possible regressions or improvements - are shown below (thus, an empty table means that all benchmark results remained invariant between builds). | ID | time ratio | memory ratio | |-----------------------------------------------------|------------|--------------| ## Benchmark Group List Here's a list of all the benchmark groups executed by this job: - `["trace", "analytic field"]` - `["trace", "numerical field"]` - `["trace", "time-dependent field"]` ## Julia versioninfo ### Target ``` Julia Version 1.9.3 Commit bed2cd540a1 (2023-08-24 14:43 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: Linux (x86_64-linux-gnu) Ubuntu 22.04.3 LTS uname: Linux 6.2.0-1015-azure #15~22.04.1-Ubuntu SMP Fri Oct 6 13:20:44 UTC 2023 x86_64 x86_64 CPU: AMD EPYC 7763 64-Core Processor: speed user nice sys idle irq #1 2445 MHz 1692 s 0 s 173 s 4623 s 0 s #2 2746 MHz 1905 s 0 s 154 s 4446 s 0 s #3 2606 MHz 1770 s 0 s 176 s 4549 s 0 s #4 3242 MHz 2021 s 0 s 176 s 4301 s 0 s Memory: 15.606910705566406 GB (13814.3125 MB free) Uptime: 653.15 sec Load Avg: 1.02 1.2 0.72 WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-14.0.6 (ORCJIT, znver3) Threads: 1 on 4 virtual cores ``` ### Baseline ``` Julia Version 1.9.3 Commit bed2cd540a1 (2023-08-24 14:43 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: Linux (x86_64-linux-gnu) Ubuntu 22.04.3 LTS uname: Linux 6.2.0-1015-azure #15~22.04.1-Ubuntu SMP Fri Oct 6 13:20:44 UTC 2023 x86_64 x86_64 CPU: AMD EPYC 7763 64-Core Processor: speed user nice sys idle irq #1 3243 MHz 1792 s 0 s 180 s 5430 s 0 s #2 2445 MHz 1966 s 0 s 167 s 5286 s 0 s #3 2537 MHz 2078 s 0 s 186 s 5147 s 0 s #4 2595 MHz 2452 s 0 s 187 s 4774 s 0 s Memory: 15.606910705566406 GB (13816.4375 MB free) Uptime: 744.8 sec Load Avg: 1.0 1.15 0.75 WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-14.0.6 (ORCJIT, znver3) Threads: 1 on 4 virtual cores ``` --- # Target result # Benchmark Report for */home/runner/work/TestParticle.jl/TestParticle.jl* ## Job Properties * Time of benchmark: 13 Nov 2023 - 23:1 * Package commit: 118fcb * Julia commit: bed2cd * Julia command flags: None * Environment variables: None ## Results Below is a table of this job's results, obtained by running the benchmarks. The values listed in the `ID` column have the structure `[parent_group, child_group, ..., key]`, and can be used to index into the BaseBenchmarks suite to retrieve the corresponding benchmarks. The percentages accompanying time and memory values in the below table are noise tolerances. The "true" time/memory value for a given benchmark is expected to fall within this percentage of the reported value. An empty cell means that the value was zero. | ID | time | GC time | memory | allocations | |-----------------------------------------------------|---------------:|--------:|---------------:|------------:| | `["trace", "analytic field", "in place"]` | 8.336 μs (5%) | | 14.06 KiB (1%) | 158 | | `["trace", "analytic field", "out of place"]` | 7.466 μs (5%) | | 12.28 KiB (1%) | 133 | | `["trace", "numerical field", "in place"]` | 21.220 μs (5%) | | 23.17 KiB (1%) | 173 | | `["trace", "numerical field", "out of place"]` | 17.042 μs (5%) | | 17.56 KiB (1%) | 145 | | `["trace", "time-dependent field", "in place"]` | 10.049 μs (5%) | | 15.27 KiB (1%) | 173 | | `["trace", "time-dependent field", "out of place"]` | 8.285 μs (5%) | | 13.48 KiB (1%) | 148 | ## Benchmark Group List Here's a list of all the benchmark groups executed by this job: - `["trace", "analytic field"]` - `["trace", "numerical field"]` - `["trace", "time-dependent field"]` ## Julia versioninfo ``` Julia Version 1.9.3 Commit bed2cd540a1 (2023-08-24 14:43 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: Linux (x86_64-linux-gnu) Ubuntu 22.04.3 LTS uname: Linux 6.2.0-1015-azure #15~22.04.1-Ubuntu SMP Fri Oct 6 13:20:44 UTC 2023 x86_64 x86_64 CPU: AMD EPYC 7763 64-Core Processor: speed user nice sys idle irq #1 2445 MHz 1692 s 0 s 173 s 4623 s 0 s #2 2746 MHz 1905 s 0 s 154 s 4446 s 0 s #3 2606 MHz 1770 s 0 s 176 s 4549 s 0 s #4 3242 MHz 2021 s 0 s 176 s 4301 s 0 s Memory: 15.606910705566406 GB (13814.3125 MB free) Uptime: 653.15 sec Load Avg: 1.02 1.2 0.72 WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-14.0.6 (ORCJIT, znver3) Threads: 1 on 4 virtual cores ``` --- # Baseline result # Benchmark Report for */home/runner/work/TestParticle.jl/TestParticle.jl* ## Job Properties * Time of benchmark: 13 Nov 2023 - 23:2 * Package commit: fd5d83 * Julia commit: bed2cd * Julia command flags: None * Environment variables: None ## Results Below is a table of this job's results, obtained by running the benchmarks. The values listed in the `ID` column have the structure `[parent_group, child_group, ..., key]`, and can be used to index into the BaseBenchmarks suite to retrieve the corresponding benchmarks. The percentages accompanying time and memory values in the below table are noise tolerances. The "true" time/memory value for a given benchmark is expected to fall within this percentage of the reported value. An empty cell means that the value was zero. | ID | time | GC time | memory | allocations | |-----------------------------------------------------|---------------:|--------:|---------------:|------------:| | `["trace", "analytic field", "in place"]` | 8.406 μs (5%) | | 14.06 KiB (1%) | 158 | | `["trace", "analytic field", "out of place"]` | 7.144 μs (5%) | | 12.28 KiB (1%) | 133 | | `["trace", "numerical field", "in place"]` | 20.970 μs (5%) | | 23.17 KiB (1%) | 173 | | `["trace", "numerical field", "out of place"]` | 16.942 μs (5%) | | 17.56 KiB (1%) | 145 | | `["trace", "time-dependent field", "in place"]` | 10.248 μs (5%) | | 15.27 KiB (1%) | 173 | | `["trace", "time-dependent field", "out of place"]` | 8.372 μs (5%) | | 13.48 KiB (1%) | 148 | ## Benchmark Group List Here's a list of all the benchmark groups executed by this job: - `["trace", "analytic field"]` - `["trace", "numerical field"]` - `["trace", "time-dependent field"]` ## Julia versioninfo ``` Julia Version 1.9.3 Commit bed2cd540a1 (2023-08-24 14:43 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: Linux (x86_64-linux-gnu) Ubuntu 22.04.3 LTS uname: Linux 6.2.0-1015-azure #15~22.04.1-Ubuntu SMP Fri Oct 6 13:20:44 UTC 2023 x86_64 x86_64 CPU: AMD EPYC 7763 64-Core Processor: speed user nice sys idle irq #1 3243 MHz 1792 s 0 s 180 s 5430 s 0 s #2 2445 MHz 1966 s 0 s 167 s 5286 s 0 s #3 2537 MHz 2078 s 0 s 186 s 5147 s 0 s #4 2595 MHz 2452 s 0 s 187 s 4774 s 0 s Memory: 15.606910705566406 GB (13816.4375 MB free) Uptime: 744.8 sec Load Avg: 1.0 1.15 0.75 WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-14.0.6 (ORCJIT, znver3) Threads: 1 on 4 virtual cores ``` --- # Runtime information | Runtime Info | | |:--|:--| | BLAS #threads | 2 | | `BLAS.vendor()` | `lbt` | | `Sys.CPU_THREADS` | 4 | `lscpu` output: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 48 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Vendor ID: AuthenticAMD Model name: AMD EPYC 7763 64-Core Processor CPU family: 25 Model: 1 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 Stepping: 1 BogoMIPS: 4890.86 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy svm cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext invpcid_single vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr rdpru arat npt nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold v_vmsave_vmload umip vaes vpclmulqdq rdpid fsrm Virtualization: AMD-V Hypervisor vendor: Microsoft Virtualization type: full L1d cache: 64 KiB (2 instances) L1i cache: 64 KiB (2 instances) L2 cache: 1 MiB (2 instances) L3 cache: 32 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-3 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Mitigation; safe RET, no microcode Vulnerability Spec store bypass: Vulnerable Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Retpolines, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected | Cpu Property | Value | |:------------------ |:---------------------------------------------------------- | | Brand | AMD EPYC 7763 64-Core Processor | | Vendor | :AMD | | Architecture | :Unknown | | Model | Family: 0xaf, Model: 0x01, Stepping: 0x01, Type: 0x00 | | Cores | 16 physical cores, 16 logical cores (on executing CPU) | | | No Hyperthreading hardware capability detected | | Clock Frequencies | Not supported by CPU | | Data Cache | Level 1:3 : (32, 512, 32768) kbytes | | | 64 byte cache line size | | Address Size | 48 bits virtual, 48 bits physical | | SIMD | 256 bit = 32 byte max. SIMD vector size | | Time Stamp Counter | TSC is accessible via `rdtsc` | | | TSC runs at constant rate (invariant from clock frequency) | | Perf. Monitoring | Performance Monitoring Counters (PMC) are not supported | | Hypervisor | Yes, Microsoft |
henry2004y commented 10 months ago

I'm going to merge this to master in order to test the performance for a specific problem. We can further polish this part afterwards.

TCLiuu commented 10 months ago

Have you read this paper?

PS. Perhaps you have also come across this author.

henry2004y commented 10 months ago

I've heard of this paper recently from a senior member of my group. By briefly scanning through the derivations, I got the impression that $|R|=1$ is based on the assumption that $\Delta t = \textrm{const}$. I will confirm this with some numerical experiments.