The logic when creating the basis modes for fitting a Dommaschk potential to a given magnetic field is cumbersome, especially when the field is stellarator symmetric, involving nested for loops and conditionals. It would be better to re-arrange things and refactor to use numpy where statements instead.
Further, it might be that if the field periodicity is known, that only ms which are multiples of NFP are needed, which should also be enforced in the fitting. Currently the fitting includes every l,m up to the specified max l and m.
The logic when creating the basis modes for fitting a Dommaschk potential to a given magnetic field is cumbersome, especially when the field is stellarator symmetric, involving nested for loops and conditionals. It would be better to re-arrange things and refactor to use numpy where statements instead.
Further, it might be that if the field periodicity is known, that only
ms
which are multiples ofNFP
are needed, which should also be enforced in the fitting. Currently the fitting includes every l,m up to the specified max l and m.