-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coil currents don't change much when using FixSumCoilCurrent
#1155
Comments
On a related note, I'm skeptical that we don't need to use the coil current constraints for finite-beta equilibria. Using the final W7-X solution in the
This coil set has relatively low field errors and that is still two orders of magnitude off. Maybe if the |
not really sure what you mean by
|
For example, say we have two coils each with a current of 1e6 Amps, and we want to constraint the sum of their currents:
This yields the following: Then the initial optimization variables in this case will be The "real" parameters are recovered as |
I think this might be as simple as redefining things as
or
where Lines 285 to 287 in 5b245a4
|
I may have found an additional wrinkle to this problem, or else I'm not understanding something. As the simplest possible example, say we have a
The linear constraint matrix corresponding to the
Then the null space matrix that determines the optimization variables is the following matrix of shape (6, 5):
It is apparent that the coil currents Interestingly, if we were to redefine the order of the full state vector such that the coil current is listed first, we get the following result:
This makes much more sense: the two coil currents are functions of a single optimization variable, and all of the curve parameters are independent variables. Why does the order of our state vector matter, and how can we consistently get the behavior we want? Is this an artifact of the SVD algorithm? Is there a solution besides changing the hard-coded order of the optimizable parameters? Please help. |
In general the SVD is unique up to a permutation of the columns of That said, can't we just apply any scaling to the full state vector so that the order of the reduced vector doesn't matter (assuming we scale everything to O(1)) |
OK that probably explains it. But I still don't think this can be completely solved by scaling the variables. Because in my example above, the original ordering of the state vector results in an unphysical optimization vector Also I can't figure out how to weight the full state vector instead of the reduced variables. Because |
Redefine |
Maybe this is different than your original scaling problem but can we add a logic to do what you want like this A = np.array([[0, 0, 1., 0, 0, 1.]])
# This for general loop, actually for this case we can just use the A for v0
# Find the row of A which has two non-zero elements
# (we need to change this to find 2 ones in a row)
v0 = A[np.where(np.count_nonzero(A, axis=1) == 2)[0][0]]
idx_second1 = np.where(v0 == 1)[0][1]
# set second 1 as -1 to satify A@v0=0
v0[idx_second1] = -1
# normalize v0
v0 = v0 / np.linalg.norm(v0)
# delete the column of A which has the second 1
A = np.delete(A, idx_second1, axis=1)
Ainv, Z = svd_inv_null(A)
# we have to add a zero row to Z to make it compatible with the original A
Z = np.vstack((Z, np.zeros((1, Z.shape[1]))))
Z = np.hstack((Z, v0[:, np.newaxis]))
print(Z) So, in |
@dpanici has mentioned this issue offline, but I want to document it:
The linear constraint
FixSumCoilCurrent
does what it is intended to do, but when used in an optimization does not allow the coil currents to change much relative to their nominal values on the order of 1e6 Amps. I have noticed that using the nonlinear constraintToroidalFlux
allows the coil currents to change much more and gives better results in practice.When the linear constraint is included,
factorize_linear_constraints
normalizes the optimization variablesx_reduced
to order unity, while the particular solutionxp
is order 1e6 so that the full state vectorx_full = xp + Z @ x_reduced
has the proper magnitude in Amperes. The null space matrixZ
is also order unity, so even large changes in the optimization space result in very small changes to the true coil currents.A hacky solution would be to redefine the units of the coil currents to be in MA instead of Amps. Alternatively, it would be nice if the rows of
Z
were scaled proportionally toxp
, such that relative changes in the optimization variablesx_reduced
yield similar relative changes in the full state vectorx_full
.The text was updated successfully, but these errors were encountered: