leon-vv / Traceon

Electromagnetic solver and electron tracer
https://traceon.org/
GNU Affero General Public License v3.0
3 stars 4 forks source link

Good interpolation techniques for 3D and planar symmetry #30

Closed leon-vv closed 1 year ago

leon-vv commented 1 year ago

For axial symmetry we have an elegant interpolation technique relying on high order axial derivatives of the potential. However, the computation time can quickly be dominated by the computation of the derivatives. Also, for the 3D and planar symmetric cases it's not obvious the computation of the high order derivatives will be equally elegant.

For this reason we need a new, reliable interpolation technique which is not as cumbersome to set up. Hermite interpolation seems the most obvious.

leon-vv commented 1 year ago

I think we should definitely support something like Hermite interpolation for a simple and easy to use interpolation.

However, the optimal approach I think is the one taken for axial symmetry (radial series expansion). It seems like the method can be extended to 3D and planar symmetry as explained by Hawkes[1] chapter 7 and chapter 13.

[1] Peter Hawkes. Principles of Electron Optics. Volume one. 2018.

leon-vv commented 1 year ago

I looked into it, the radial series expansion in the 3D case is complicated. In theory, if we could effectively calculate the axial harmonics along the optical axis we can do very fast 3D traces. However, how to calculate the axial harmonics is not obvious. The formula in Hawkes is I think incorrect, since it misses the sinus terms that are needed to describe a potential in 3D in full generality.

Implementing Hermite interpolation was a lot of work, and it was not obvious whether it's best to calculate the derivatives analytically or using a finite difference scheme. I figured out in the end that using a finite difference scheme directly on the field components (so not on the potential) is the best option in terms of accuracy/computation. This now works for radial symmetric geometries. See validation/dohi.py.

leon-vv commented 1 year ago

Hermite interpolation is now fully implemented for 3D and for radial symmetry. In both cases I think it performs very poorly..

I was finally able to generalize the radial series expansion method to 3D. It looks like it will be an extremely accurate and fast method. If it really works as well as I hope I need to write it down in a paper someday.

leon-vv commented 1 year ago

I have validated the new method in validation/simple-mirror.py. It seems to work really well.