I Proton in a magnetic field, numerical simulation

  • Thread starter Thread starter Appelros
  • Start date Start date
  • Tags Tags
    Lorentz force
Click For Summary
The discussion revolves around the challenges of simulating a proton's motion in a magnetic field within a fusion reactor simulator. The user encounters issues with the Lorentz force causing an increase in the proton's velocity magnitude, contradicting the principle that the magnetic field does no work. They propose scaling the velocity vector after applying the force, but this leads to complications with multiple acceleration vectors and inaccuracies in the proton's circular path. Participants suggest using average velocity for more accurate position updates and caution against simulating every particle in a fusion context, advocating for more efficient methods like weighted averages or voxel models. The conversation highlights the balance between precision and computational efficiency in particle simulations.
  • #31
hutchphd said:
You said you wanted accuracy. Toward that end simulations should be done analytically if they can be.
In complex simulations the best that can be done analytically is solving for the force vectors at each time step, and whenever the perpendicular magnetic force vector is added to a velocity the velocity increases, which it shouldn't.

Your microscopic simulation is not time reversal invariant. That should worry you. You introduce that asymmetry artificially by your second difference technique.
That's why I came here for help.

If you wish to communiucate math, please do it in LateX and not Julia.
I tried to use code ticks ``` to signify code, seemed appropriate given the thread is about coding, but apparently they don't work here. Also double $ or # doesn't seem to work either... So I don't know how to input latex on this site, if anyone has a solution that would be great.
 
Physics news on Phys.org
  • #32
Vanadium 50 said:
Then why are you shocked that ## \sqrt{x^2 + \Delta y^2} > x ##?
Uh, I'm not... You seem to misunderstand/misrepresent everything I say and frankly it is not pleasant communicating with you. The primary objective of any communication should be building rapport.
 
  • #33
Appelros said:
You seem to misunderstand/misrepresent everything I say and frankly it is not pleasant communicating with you. The primary objective of any communication should be building rapport.
Or in this case, pointing out your errors so that you can improve... :wink:
 
  • Like
Likes Vanadium 50
  • #34
No one has provided an improved solution to scaling. Rotation would be a candidate.
 
  • #35
Appelros said:
Hi! I am developing a fusion reactor simulator and when a proton spins in a perpendicular magnetic field the Lorentz force qv×B is applied at a right angle, however whenever you add a value to a vector in this way its magnitude increases, which contradicts that the velocity of the proton should remain constant since the magnetic field does no work. To solve this I simply scaled the vector back to its original size after adding the acceleration.
I created a basic particles-in-magnetic-field simulation a little over a year ago using c-sharp and Unity. I believe I ended up using a symplectic integrator such as the Boris Method. See part 3 here: https://www.particleincell.com/2011/vxb-rotation/

This should fix your issue with the magnitude increasing with each time step, but note that there really isn't a way of simplifying things enough to directly simulate more than a few thousand to a few hundred thousand particles at the same time. At least not with personal computers you find at home. With a parallelized program running on my video card I was able to simulate about 100k particles at a time without my program falling below 30 fps, but that was purely a particle-mover without any way to store or analyze the data. It also wasn't computing particle-particle forces, just forces from an external field on each particle. And even at the rate it was running I'm not sure it was fast enough to do anything useful.

Direct simulation is the most accurate, but by far the most resource intensive. You can go further up the scale to particle-in-cell, particle meshes, charged fluid, etc. Each step generally gets more abstract and less accurate while gaining the ability to simulation larger time frames and/or more particles.

Here's my thread asking for resources and posting some insights I gained working on my simulation: https://www.physicsforums.com/threads/resources-on-simulating-charges-in-magnetic-fields.1047935/
 
  • #36
Appelros said:
Also double $ or # doesn't seem to work either... So I don't know how to input latex on this site, if anyone has a solution that would be great.
That's strange. I use double # and it has always worked just fine.

Test: ## Test * Test = Test^2##

Edit: Double # works for me. Remember to put the double # at the start and end of your latex.
 
  • #37
Appelros said:
Also double $ or # doesn't seem to work either... So I don't know how to input latex on this site, if anyone has a solution that would be great.
There is a helpful "LaTeX Guide" link below the Edit window to get you started. Note that you put double-$ delimiters at the start and end of each stand-alone line of LaTeX, and double-# delimiters at the start and end of in-line LaTeX that does not need to be on its own line.

Example of in-line LaTeX: ##v(t) = L \frac{di(t)}{dt}##

Example of stand-alone LaTeX:
$$v(t) = L \frac{di(t)}{dt}$$
Also, if you right-click on a LaTeX equation in a post, you get a pop-up menu to let you view the LaTeX source or view it in other formats.

LaTeX isn't supported in thread titles, so you can use simple text math in titles if you want.

Note also that PF uses a feature called "lazy LaTeX rendering" that speeds up page loads. When you first post your LaTeX in a thread, you will not see it rendered that first time. Just refresh your browser page to force it to be rendered, and then it should render whenever you come back to that page/thread in the future.

If you have trouble using the Preview feature to check your LaTeX, you can use a website such as https://www.quicklatex.com/ or https://latexeditor.lagrida.com/ to preview your LaTeX before you post it.
 
  • Like
Likes Appelros and Drakkith
  • #38
Drakkith said:
I created a basic particles-in-magnetic-field simulation a little over a year ago using c-sharp and Unity. I believe I ended up using a symplectic integrator such as the Boris Method. See part 3 here: https://www.particleincell.com/2011/vxb-rotation/

This should fix your issue with the magnitude increasing with each time step, but note that there really isn't a way of simplifying things enough to directly simulate more than a few thousand to a few hundred thousand particles at the same time. At least not with personal computers you find at home. With a parallelized program running on my video card I was able to simulate about 100k particles at a time without my program falling below 30 fps, but that was purely a particle-mover without any way to store or analyze the data. It also wasn't computing particle-particle forces, just forces from an external field on each particle. And even at the rate it was running I'm not sure it was fast enough to do anything useful.
Yea the Boris method solves most problems, but I can't get it to bounce at the analytical bounce point in a magnetic bottle. I might start a thread about that after I extract a MWE.

Direct simulation is the most accurate, but by far the most resource intensive. You can go further up the scale to particle-in-cell, particle meshes, charged fluid, etc. Each step generally gets more abstract and less accurate while gaining the ability to simulation larger time frames and/or more particles.
Approximations can also be expensive, I found a plasma package that calculates the Vlasov equation but it would have taken weeks to get a solution. I simplified the equations and now it solves in seconds. Reminds me of an episode of Standupmaths where he ran a program for a month and viewers optimized it down to under a second.

Here's my thread asking for resources and posting some insights I gained working on my simulation: https://www.physicsforums.com/threads/resources-on-simulating-charges-in-magnetic-fields.1047935/
Great, I'll check out the resources posted in that thread. Are you still involved in plasma research?
 
  • #39
Drakkith said:
That's strange. I use double # and it has always worked just fine.

Test: ## Test * Test = Test^2##

Edit: Double # works for me. Remember to put the double # at the start and end of your latex.
Your latex switched from rendering to not rendering to rendering again while I posted my reply above, strange indeed.

##x^2##, now it works in preview. Sometimes it doesn't
 
  • #40
Appelros said:
Are you still involved in plasma research?
No, and I never really was. I learned just enough to make some charged particles move around in a magnetic field and that was about it.
 
  • #41
Appelros said:
Your latex switched from rendering to not rendering to rendering again while I posted my reply above, strange indeed.

, now it works in preview. Sometimes it doesn't
One extra note that I should have mentioned about the "lazy LaTeX rendering" is that each time after you edit your post with LaTeX in it, it will not render the first time you save your edits. Just make it a habit to refresh your browser page after you have done the edits, which will force the LaTeX engine to render the page. It's a bit annoying, but it is deterministic and you get used to it after a short while. :smile:
 
  • #42
Drakkith said:
No, and I never really was. I learned just enough to make some charged particles move around in a magnetic field and that was about it.
Oh, okay, are you working on something else interesting?

I constructed the above mentioned MWE and fed the details to ChatGPT and it explained the solution, I thought AI would have huge problems with advanced physics but so far it has been very helpful.
 
  • #43
Appelros said:
Oh, okay, are you working on something else interesting?
Not at this time, no. With only some undergrad education in physics and programming, my capabilities in this area are very limited.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
3K
Replies
5
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
4
Views
1K
Replies
5
Views
4K
Replies
10
Views
2K
Replies
6
Views
2K
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K