SIMSOPT generated coils files are not compliant with SCALED mode
When the SIMSOPT code writes a coils.ext file (colloquillial called an MGRID files, althought originally defined by the ONSET code) the mirrored coils are not wound in the correct direction so the code flips the sign of the mirrored coils current. This has the unfortunate consequence that the coils can only be treated in the 'so-called' RAW mode. The fix should be straightforward to implement in src/simsopt/field/coil.py:
https://github.com/hiddenSymmetries/simsopt/blob/f2288c4940c15f2935f85d3947235c0f962b4393/src/simsopt/field/coil.py#L236
Two modifications are proposed:
- If the current is negative the winding order of the coil should be reversed before writing.
- The current field should only reference the value in the first coil of a group. Thus all coils in a given group have the same current.
It looks like I am the one to "blame". I was lazy and noticed the limitations. So I left a comment #should be careful. SIMSOPT flips the current, but actually should change coil order.
Want me to fix it, or will you (@zhucaoxiang) take care of it?
@lazersos You can go ahead. Unless you want to wait for me. :)
@zhucaoxiang I'm going to ask you do the work. I started to look at how to implement it but realized I'd have to touch more basic code. The relevant section of code is:
for icoil in range(ncoils):
x = coils[icoil].curve.gamma()[:, 0]
y = coils[icoil].curve.gamma()[:, 1]
z = coils[icoil].curve.gamma()[:, 2]
for iseg in range(len(x)): # the last point matches the first one;
wfile.write(
"{:23.15E} {:23.15E} {:23.15E} {:23.15E}\n".format(
x[iseg], y[iseg], z[iseg], coils[icoil].current.get_value()
)
)
The issue is that the function gamma() applies the rotation matrix to the coordinate set. So until this point the ordering of the coil is just the base ordering. I think the correct thing to do is modify gamma() in magneticfieldclasses.py so that if the [2,2] element of the rotation matrix is -1 then .gamma() returns the coordinates in reverse order. Then I suspect the apply_symmetries_to_currents function no longer needs to do any flipping. This is imporant becasue it is possible that a negative current in one coil group is meaningful relative to other groups. Thus the reversing of the coil winding needs to be done based on the rotation matrix and not simply if the current is negative.