iwhoppock / boris-algorithm

The Boris algorithm for numerically tracing non-relativistic charged particles in electromagnetic fields, written in C, matlab, and python
10 stars 2 forks source link

Meaning of vAc #2

Open jhlq opened 5 months ago

jhlq commented 5 months ago

Is vAc volts AC power? What is its physical interpretation in the algorithm?

iwhoppock commented 4 months ago

No, it is the alfven velocity divided by the speed of light, and you can see this in the C code in the repo.

I am not sure I understand what you mean by the interpretation in the algorithm. Look at equation 3.1 here: https://arxiv.org/pdf/1811.08873 you can go to the original paper by Boris which you can find in the citations.

On Fri, 28 Jun 2024 at 21:19, Marcus Appelros @.***> wrote:

Is vAc volts AC power? What is its physical interpretation in the algorithm?

— Reply to this email directly, view it on GitHub https://github.com/iwhoppock/boris-algorithm/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGBR3ZAIMFT7IKKULRFIGF3ZJWZNTAVCNFSM6AAAAABKCMJBFKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM4DCMBTGU2DGNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jhlq commented 4 months ago

Ok, thanks. This article: https://edutinker.com/glossary/alfven-speed/ Says: "The Alfvén speed is given by the equation: V_A = B / (4πρ)^(1/2) where B is the magnetic field, and ρ is the mass density of the plasma." Is that what I should set vAc to? Why did you divide by the speed of light?

iwhoppock commented 4 months ago

You divide velocity by c to make the code dimensionless, which allows for normalization. Dig into the C code: You’ll see how things are set up (eg mass is just 1 — normalized and dimensionless). It’s much more efficient for the computer to not carry absurdly small numbers that can cause issues with the machine precision. You can make the alfven speed / speed of light ratio what ever you want, but it’s probably good to keep it physical and non-relativistic. I believe Boris is not the standard for relativistic particle tracing. Again, if you look in the code, it’s there. You can also look at the blogs and get a more basic version of this. There is one linked in the readme that is great.

On Sun, 30 Jun 2024 at 18:18, Marcus Appelros @.***> wrote:

Ok, thanks. This article: https://edutinker.com/glossary/alfven-speed/ Says: "The Alfvén speed is given by the equation: V_A = B / (4πρ)^(1/2) where B is the magnetic field, and ρ is the mass density of the plasma." Is that what I should set vAc to? Why did you divide by the speed of light?

— Reply to this email directly, view it on GitHub https://github.com/iwhoppock/boris-algorithm/issues/2#issuecomment-2198611414, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGBR3ZA7M2SORI7LTUZKCXLZKAVXBAVCNFSM6AAAAABKCMJBFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGYYTCNBRGQ . You are receiving this because you commented.Message ID: @.***>

iwhoppock commented 4 months ago

Here is this snippet from the dipole code:

The units are normalised: speed is in terms of the Alfven speed, frequencies the proton cyclotron frequency, lengths the proton inertial length, etc. To change to an alpha, replace mass with 4 and charge with 2. Change the velocities gradually. This code implements the Boris algorithm for non-relativistic particle tracing. The quantity vAc is the ratio of the alfven speed by the speed of light (c).

On Sun, 30 Jun 2024 at 18:18, Marcus Appelros @.***> wrote:

Ok, thanks. This article: https://edutinker.com/glossary/alfven-speed/ Says: "The Alfvén speed is given by the equation: V_A = B / (4πρ)^(1/2) where B is the magnetic field, and ρ is the mass density of the plasma." Is that what I should set vAc to? Why did you divide by the speed of light?

— Reply to this email directly, view it on GitHub https://github.com/iwhoppock/boris-algorithm/issues/2#issuecomment-2198611414, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGBR3ZA7M2SORI7LTUZKCXLZKAVXBAVCNFSM6AAAAABKCMJBFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGYYTCNBRGQ . You are receiving this because you commented.Message ID: @.***>

jhlq commented 4 months ago

Alright, thanks.

Another question, can the Boris algorithm handle spatially varying magnetic fields? It doesn't take into account the gradient of B so I guess not? I set up a magnetic mirror simulation and particles don't bounce no matter how large B gets.

iwhoppock commented 4 months ago

Of course it can: Just put what ever magnetic field you want in. The magnetic dipole repo is this exact thing.

On Mon, 1 Jul 2024 at 09:02, Marcus Appelros @.***> wrote:

Alright, thanks.

Another question, can the Boris algorithm handle spatially varying magnetic fields? It doesn't take into account the gradient of B so I guess not? I set up a magnetic mirror simulation and particles don't bounce no matter how large B gets.

— Reply to this email directly, view it on GitHub https://github.com/iwhoppock/boris-algorithm/issues/2#issuecomment-2199389208, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGBR3ZADZWSVZIOVKFBWEL3ZKD5H7AVCNFSM6AAAAABKCMJBFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJZGM4DSMRQHA . You are receiving this because you commented.Message ID: @.***>

jhlq commented 4 months ago

I cloned your dipole.py and plugged in a magnetic mirror field: https://gitlab.com/marcus.appelros/fusion/-/blob/main/dipole.py

There is no bounce..: noMirror

jhlq commented 4 months ago

The magnetic field I used was unphysical, when I fixed it so divergence is zero the Boris algorithm does bounce, but not at the correct place, also the point it bounces at shifts..: Screenshot from 2024-07-02 09-16-33 It should bounce back and fourth between x=1 and -1

jhlq commented 4 months ago

I used the mirror field from this repo: https://github.com/BoschSamuel/Simulation-of-a-Tokamak-Fusion-Reactor/blob/master/B1.m I turned off the central coil and scaled so B=1 at the origin. Now it bounces between fixed points but it still doesn't bounce when B=2 but rather when B=45... The code is here: https://gitlab.com/marcus.appelros/fusion/-/blob/main/Bosch/t0.jl