Skip to content
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

from_values method for FourierRZCoil and FourierPlanarCoil #1116

Merged
merged 34 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5274d22
add from_values to FourierRZCoil
dpanici Jul 9, 2024
4a870a4
add missing attrs
dpanici Jul 9, 2024
daf8ec4
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 9, 2024
0189243
fix docstring and reorder args to match init
dpanici Jul 9, 2024
9094c1a
Merge branch 'dp/hotfix-fourierrzcoil-from-values' of github.com:Plas…
dpanici Jul 9, 2024
1217503
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
ddudt Jul 15, 2024
ae2997e
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 17, 2024
4ecae78
add from_values for FourierPlanarCurve
daniel-dudt Jul 17, 2024
638baf3
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 18, 2024
fa98655
more robus planar curve fitting
daniel-dudt Jul 18, 2024
bf30b82
undo debugging change
daniel-dudt Jul 18, 2024
9c849de
be explicit about class
daniel-dudt Jul 19, 2024
14f5793
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
ddudt Jul 19, 2024
35beb2c
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
ddudt Jul 19, 2024
2b6b41b
use SVD to compute normal vector
daniel-dudt Jul 22, 2024
21dba61
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
ddudt Jul 22, 2024
2fdf509
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 22, 2024
efff9d1
add tests, allow normals that are parallel to Zaxis
dpanici Jul 23, 2024
0037d50
avoid error if no resolution is passed to to_XXX methods
dpanici Jul 23, 2024
29b35aa
undo unneeded changes in _curve compute
dpanici Jul 23, 2024
7ba36b7
remove white space
dpanici Jul 23, 2024
801832d
modify test to test a non-centered coil
dpanici Jul 23, 2024
f354986
modify test to test a non-centered coil
dpanici Jul 23, 2024
2a1ba00
Merge branch 'dp/hotfix-fourierrzcoil-from-values' of github.com:Plas…
dpanici Jul 23, 2024
6f6ea23
update changelog
dpanici Jul 24, 2024
cbb6543
remove NFP from grid of to_FourierRZ calls
dpanici Jul 24, 2024
d0eb4e0
add basis option for to_FourierPlanar
daniel-dudt Jul 24, 2024
448d239
ocd formatting
daniel-dudt Jul 24, 2024
9614631
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 24, 2024
57688ef
add basis to coil to_planar method, make sure input coordinates match…
dpanici Jul 24, 2024
6147e7f
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 24, 2024
7d2eeae
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
f0uriest Jul 25, 2024
663894b
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
f0uriest Jul 25, 2024
40f355a
Merge branch 'master' into dp/hotfix-fourierrzcoil-from-values
dpanici Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 91 additions & 9 deletions desc/coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
Parameters
----------
current : float
current through coil, in Amperes
Current through the coil, in Amperes.
R_n, Z_n: array-like
fourier coefficients for R, Z
modes_R : array-like
Expand Down Expand Up @@ -415,14 +415,58 @@
):
super().__init__(current, R_n, Z_n, modes_R, modes_Z, NFP, sym, name)

@classmethod
def from_values(cls, current, coords, N=10, NFP=1, basis="rpz", sym=False, name=""):
"""Fit coordinates to FourierRZCoil representation.

Parameters
----------
current : float
Current through the coil, in Amperes.
coords: ndarray, shape (num_coords,3)
coordinates to fit a FourierRZCurve object with each column
corresponding to xyz or rpz depending on the basis argument.
N : int
Fourier resolution of the new R,Z representation.
NFP : int
Number of field periods, the curve will have a discrete toroidal symmetry
according to NFP.
basis : {"rpz", "xyz"}
basis for input coordinates. Defaults to "rpz"
sym : bool
Whether to enforce stellarator symmetry.
name : str
name for this coil


Returns
-------
coil : FourierRZCoil
New representation of the coil parameterized by Fourier series for R,Z.

"""
curve = super().from_values(

Check warning on line 448 in desc/coils.py

View check run for this annotation

Codecov / codecov/patch

desc/coils.py#L448

Added line #L448 was not covered by tests
coords=coords, N=N, NFP=NFP, basis=basis, sym=sym, name=name
)
return cls(

Check warning on line 451 in desc/coils.py

View check run for this annotation

Codecov / codecov/patch

desc/coils.py#L451

Added line #L451 was not covered by tests
current=current,
R_n=curve.R_n,
Z_n=curve.Z_n,
modes_R=curve.R_basis.modes[:, 2],
modes_Z=curve.Z_basis.modes[:, 2],
NFP=NFP,
sym=curve.sym,
name=name,
)


class FourierXYZCoil(_Coil, FourierXYZCurve):
"""Coil parameterized by fourier series for X,Y,Z in terms of arbitrary angle s.

Parameters
----------
current : float
current through coil, in Amperes
Current through the coil, in Amperes.
X_n, Y_n, Z_n: array-like
fourier coefficients for X, Y, Z
modes : array-like
Expand Down Expand Up @@ -485,7 +529,7 @@
Parameters
----------
current : float
Current through the coil, in Amps.
Current through the coil, in Amperes.
coords: ndarray
Coordinates to fit a FourierXYZCoil object with.
N : int
Expand All @@ -504,12 +548,13 @@
New representation of the coil parameterized by Fourier series for X,Y,Z.

"""
curve = super().from_values(coords, N, s, basis)
curve = super().from_values(coords=coords, N=N, s=s, basis=basis, name=name)

Check warning on line 551 in desc/coils.py

View check run for this annotation

Codecov / codecov/patch

desc/coils.py#L551

Added line #L551 was not covered by tests
return cls(
current,
current=current,
X_n=curve.X_n,
Y_n=curve.Y_n,
Z_n=curve.Z_n,
modes=curve.X_basis.modes[:, 2],
name=name,
)

Expand Down Expand Up @@ -587,14 +632,49 @@
):
super().__init__(current, center, normal, r_n, modes, basis, name)

@classmethod
def from_values(cls, current, coords, N=10, basis="xyz", name=""):
"""Fit coordinates to FourierPlanarCoil representation.

Parameters
----------
current : float
Current through the coil, in Amperes.
coords: ndarray, shape (num_coords,3)
Coordinates to fit a FourierPlanarCurve object with each column
corresponding to xyz or rpz depending on the basis argument.
N : int
Fourier resolution of the new r representation.
basis : {"rpz", "xyz"}
Basis for input coordinates. Defaults to "xyz".
name : str
Name for this curve.

Returns
-------
curve : FourierPlanarCoil
New representation of the coil parameterized by a Fourier series for r.

"""
curve = super().from_values(coords=coords, N=N, basis=basis, name=name)
return cls(

Check warning on line 660 in desc/coils.py

View check run for this annotation

Codecov / codecov/patch

desc/coils.py#L659-L660

Added lines #L659 - L660 were not covered by tests
current=current,
center=curve.center,
normal=curve.normal,
r_n=curve.r_n,
modes=curve.r_basis.modes[:, 2],
basis="xyz",
name=name,
)


class SplineXYZCoil(_Coil, SplineXYZCurve):
"""Coil parameterized by spline points in X,Y,Z.

Parameters
----------
current : float
current through coil, in Amperes
Current through the coil, in Amperes.
X, Y, Z: array-like
Points for X, Y, Z describing the curve. If the endpoint is included
(ie, X[0] == X[-1]), then the final point will be dropped.
Expand Down Expand Up @@ -706,7 +786,7 @@
Parameters
----------
current : float
Current through the coil, in Amps.
Current through the coil, in Amperes.
coords: ndarray
Points for X, Y, Z describing the curve. If the endpoint is included
(ie, X[0] == X[-1]), then the final point will be dropped.
Expand Down Expand Up @@ -738,9 +818,11 @@
New representation of the coil parameterized by splines in X,Y,Z.

"""
curve = super().from_values(coords, knots, method, basis=basis)
curve = super().from_values(

Check warning on line 821 in desc/coils.py

View check run for this annotation

Codecov / codecov/patch

desc/coils.py#L821

Added line #L821 was not covered by tests
coords=coords, knots=knots, method=method, basis=basis, name=name
)
return cls(
current,
current=current,
X=curve.X,
Y=curve.Y,
Z=curve.Z,
Expand Down
Loading
Loading