headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
337 stars 102 forks source link

Lorentz Force Integrator #201

Open Ryan-Hedlof opened 7 years ago

Ryan-Hedlof commented 7 years ago

Hello,

I've developed a physics simulation suite that implements the RK78 stepper for tracking charged particles in user defined electromagnetic fields. Due to the explicit nature of the RK78 algorithm, I've been having some issues with energy conservation when particles interact with a combined electric and magnetic field. I've been able to combat the issue, somewhat, by implementing a step-by-step energy based time-step modulation, but I'd prefer to use a method that conserves energy automatically. I was hoping to use the symplectic algorithms you have available, however the Hamiltonian for a charged particle in an electromagnetic field is not separable. Have you guys ever developed, for your own purposes, a symplectic Runge-Kutta scheme that can be used for Hamiltonian systems that aren't separable? If not, would you happen to have any advice on how to solve the issue?

Thank you very much for your time,

Ryan Hedlof

headmyshoulder commented 7 years ago

Unfortunately odeint does not provide solvers for non-separable Hamiltonian systems. I think the book about geometrical integration from E. Hairer could help you with more advances methods for non-separable Hamiltonians. Is you equation written down in terms of classical momentum/positions or with complex states as in nonlinear Schrodinger-like equations?

Ryan-Hedlof commented 7 years ago

Thank you for your suggestion. I'll be sure to find the text ASAP.

I have the equations written down in terms of classical position/momentum right now. Specifically, I just solve the coupled equations of motion for a charged particle moving in an external electromagnetic field according to Newton's second law: F=m dv/dt, v=dr/dt, where F=q( E+ vX B) is the Lorentz force. Currently, all motion is in the non-relativistic regime, and I don't consider any quantum effects, so I don't have to worry about any complex states or anything.

I really appreciate your insights. Thank you.

headmyshoulder commented 7 years ago

Ok, I see. Btw. maybe the Velocity-Verlet integrator fits your needs. I think it was developed for particle methods and it should be energy conserving (at least in the average).

Ryan-Hedlof commented 7 years ago

Thanks for the suggestion. I'll try it, and see what happens.

Anyway, thanks again for your help. I really appreciate it.