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

C0 coils with splines #970

Open
wants to merge 103 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
744f6f2
initial commit
kianorr Mar 7, 2024
5bfe0f3
stuff
kianorr Mar 18, 2024
28da0aa
add discontinuous knots to SplineXYZCurve
kianorr Mar 29, 2024
7d45502
Merge branch 'master' into ko/discon_curve
kianorr Mar 29, 2024
18a8e15
fixed taking slices of knots
kianorr Apr 2, 2024
4568169
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Apr 2, 2024
3300c6a
Merge branch 'master' into ko/discon_curve
kianorr Apr 2, 2024
2ba7f7d
correctly get intervals
kianorr Apr 5, 2024
398b6bf
Merge branch 'master' into ko/discon_curve
dpanici Apr 5, 2024
7639ed8
use indices instead of knots for user input
kianorr Apr 7, 2024
7896a56
Merge branch 'master' into ko/discon_curve
dpanici Apr 8, 2024
e281fae
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Apr 11, 2024
b07d62a
address reviews
kianorr Apr 11, 2024
8392252
separate interpolation cases
kianorr Apr 12, 2024
6e4b742
make body simpler
kianorr Apr 12, 2024
b7973de
add discontinuous to x_s
kianorr Apr 12, 2024
958c299
add x_ss and x_sss
kianorr Apr 12, 2024
4db806f
delete shift where unnecessary
kianorr Apr 12, 2024
0ba9a21
Merge branch 'master' into ko/discon_curve
kianorr Apr 13, 2024
3874f04
refactor some things in x
kianorr Apr 13, 2024
79af9d5
add actual test
kianorr Apr 13, 2024
2c8c5a8
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Apr 13, 2024
fdf3e3d
refactor (maybe too much?)
kianorr Apr 14, 2024
be47fdc
refactor compute func for x
kianorr Apr 16, 2024
20bffd7
apply refactor to derivatives
kianorr Apr 17, 2024
331c61e
Merge branch 'master' into ko/discon_curve
dpanici Apr 19, 2024
7373aea
add discontinuous_indices to from_values and to_SplineXYZ
kianorr Apr 19, 2024
d2901d6
move inner funcs outside compute funcs
kianorr May 15, 2024
bf6d6a8
Merge branch 'master' into ko/discon_curve
kianorr May 15, 2024
19f3bef
get method from compute func in Curve
kianorr May 15, 2024
6610243
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr May 15, 2024
20fdcb1
Merge branch 'master' into ko/discon_curve
dpanici May 15, 2024
471c767
replicate daniel's basis code (not working)
kianorr May 15, 2024
a4ed6ac
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr May 15, 2024
bdec0ea
override splinexyz compute function
kianorr May 16, 2024
ca1f51e
Merge branch 'master' into ko/discon_curve
kianorr May 16, 2024
68cb758
move a lot of code out of compute funcs
kianorr May 16, 2024
8af9fd4
use data, params so that test knows that it was used
kianorr May 16, 2024
6dd7e58
use full_f instead of X, Y, Z
kianorr May 16, 2024
e5f9187
simplify inner_body()
kianorr May 16, 2024
a9e05e7
add to docstring for discontinuous_indices
kianorr May 17, 2024
68e39d6
add to compute func docstrings
kianorr May 18, 2024
e98c8b2
merge master into ko/discon_curve
kianorr May 18, 2024
78279c0
update method description
kianorr May 18, 2024
e71b63d
add discontinuous indices to MixedCoilSet
kianorr May 18, 2024
7085d86
check for monotonicity
kianorr May 18, 2024
0b23dc9
use np.all for monotonicity
kianorr May 19, 2024
dd904ba
add error message
kianorr May 19, 2024
d544895
add line after bullet points
kianorr May 19, 2024
7564a1a
indent bullet points
kianorr May 19, 2024
39a5f3b
update test
kianorr May 20, 2024
34aa31e
Merge branch 'master' into ko/discon_curve
ddudt May 23, 2024
58e9999
add transform doc and delete commas
kianorr May 23, 2024
d8f040c
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr May 23, 2024
388b4e1
fix error message
kianorr May 23, 2024
426f5b1
delete method in transforms in length and add knot to opt
kianorr May 27, 2024
cf0770b
Merge branch 'master' into ko/discon_curve
kianorr May 27, 2024
de4b676
add length and torsion tests
kianorr May 30, 2024
777b0f8
Merge branch 'master' into ko/discon_curve
kianorr Jun 6, 2024
95102b3
update docstring for break_indices
kianorr Jun 6, 2024
452aecb
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Jun 6, 2024
ec04147
add compute function for torsion splinexyz
kianorr Jun 7, 2024
867ac44
rename to break_indices
kianorr Jun 7, 2024
2397fb4
change some variable names
kianorr Jun 7, 2024
4f7be20
Merge branch 'master' into ko/discon_curve
kianorr Jun 16, 2024
e5b3591
don't include breakpoints for linear, torsion
kianorr Jun 17, 2024
8b8a935
rename include_breaks
kianorr Jun 17, 2024
f8dba56
Merge branch 'master' into ko/discon_curve
dpanici Jun 19, 2024
c14dd40
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Jun 21, 2024
61f4573
Merge branch 'master' into ko/discon_curve
dpanici Jun 21, 2024
61f8e49
add default to docstring
kianorr Jun 24, 2024
4ce3c9a
add intervals as attribute and getter
kianorr Jun 24, 2024
708f235
add knots to transforms and change variable names
kianorr Jun 24, 2024
f3acb34
fix error message for monotonicity
kianorr Jun 24, 2024
7fe717e
move break_indices up
kianorr Jun 24, 2024
aeb1957
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Jun 24, 2024
9b29fb8
Merge branch 'master' into ko/discon_curve
dpanici Jun 25, 2024
c8fd70a
attempt to fix torsion
kianorr Jun 25, 2024
f7e6932
Merge branch 'ko/discon_curve' of https://github.com/PlasmaControl/DE…
kianorr Jun 25, 2024
7b3dbcd
make torsion zero at break points and fix test
kianorr Jun 26, 2024
0e63107
Merge branch 'master' into ko/discon_curve
kianorr Jun 26, 2024
b3e6972
add assertion of lengths test and change break_indices
kianorr Jun 26, 2024
c197ca5
add grid to test and vectorize compute func
kianorr Jun 27, 2024
c1a364b
get rid of vmap in inner_body
kianorr Jun 27, 2024
53f1302
use vmap and sum instead of fori_loop
kianorr Jun 27, 2024
24c8480
Merge branch 'master' into ko/discon_curve
kianorr Jun 27, 2024
362507d
add grid for computes
kianorr Jul 2, 2024
f908a75
change variable names
kianorr Jul 2, 2024
7b87ccd
merge in master
kianorr Jul 12, 2024
f1d8e0c
Merge branch 'master' into ko/discon_curve
kianorr Jul 15, 2024
f939435
address rory's reviews
kianorr Jul 15, 2024
293bba2
add length compute func for splines
kianorr Jul 15, 2024
50fc5e7
fix wiggle at top of circle
kianorr Jul 19, 2024
89f334d
delete equals sign to get rid of origin point
kianorr Jul 19, 2024
9a9f0a6
change break indices and decrease resolution of grid
kianorr Jul 19, 2024
044cdfc
delete curvature compute func
kianorr Jul 19, 2024
6dfbc38
Merge branch 'master' into ko/discon_curve
kianorr Jul 19, 2024
8594699
Merge branch 'master' into ko/discon_curve
kianorr Jul 22, 2024
3164c4c
merge master
kianorr Aug 27, 2024
9a1c86e
fix intervals bug and query pts start point bug
kianorr Aug 27, 2024
03bbf23
add case for when intervals was not a argument
kianorr Aug 27, 2024
7060fb4
update docstring
kianorr Aug 28, 2024
5bd31ea
Merge branch 'master' into ko/discon_curve
kianorr Sep 17, 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
114 changes: 105 additions & 9 deletions desc/coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ def to_FourierXYZ(self, N=10, grid=None, s=None, name=""):
self.current, coords, N=N, s=s, basis="xyz", name=name
)

def to_SplineXYZ(self, knots=None, grid=None, method="cubic", name=""):
def to_SplineXYZ(
self, knots=None, grid=None, method="cubic", name="", break_indices=None
):
kianorr marked this conversation as resolved.
Show resolved Hide resolved
"""Convert coil to SplineXYZCoil.

Parameters
Expand All @@ -505,6 +507,18 @@ def to_SplineXYZ(self, knots=None, grid=None, method="cubic", name=""):
- `'catmull-rom'`: C1 cubic centripetal "tension" splines
name : str
name for this coil
break_indices : ndarray or None
If supplied, the spline will be a piecewise set of splines.
Indices of knots at which the curve breaks and is only C0 continuous (e.g.
continuous but with "corners" where the derivative jumps). In between each
set of break points, there is an unbroken spline whose start and endpoints
are given by `break_indices[i-1, i]`, where `i` indicates the ith spline.
Each (the ith) spline is interpolated independently of all other unbroken
splines (i+1th, i-1th, etc.) and does not consider their query points
(knots) when interpolating. The boundary conditions are evaluated using
Interpax's default where non-periodicity is assumed.
If None (the default), the spline will be the usual periodic spline with
the continuity dictated by the spline method.

Returns
-------
Expand All @@ -516,7 +530,13 @@ def to_SplineXYZ(self, knots=None, grid=None, method="cubic", name=""):
grid = LinearGrid(zeta=knots)
coords = self.compute("x", grid=grid, basis="xyz")["x"]
return SplineXYZCoil.from_values(
self.current, coords, knots=knots, method=method, name=name, basis="xyz"
self.current,
coords,
knots=knots,
method=method,
name=name,
basis="xyz",
break_indices=break_indices,
)

def to_FourierRZ(self, N=10, grid=None, NFP=None, sym=False, name=""):
Expand Down Expand Up @@ -939,6 +959,18 @@ class SplineXYZCoil(_Coil, SplineXYZCurve):

name : str
name for this curve
break_indices : ndarray or None
If supplied, the spline will be a piecewise set of splines.
Indices are of knots at which the curve breaks and is only C0 continuous (e.g.
continuous but with "corners" where the derivative jumps). In between each set
of break points, there is an unbroken spline whose start and endpoints are
given by `break_indices[i-1, i]`, where `i` indicates the ith spline.
Each (the ith) spline is interpolated independently of all other unbroken
splines (i+1th, i-1th, etc.) and does not consider their query points
(knots) when interpolating. The boundary conditions are evaluated using
interpax's default where non-periodicity is assumed.
If None (the default), the spline will be the usual periodic spline with
the continuity dictated by the spline method.

"""

Expand All @@ -953,8 +985,9 @@ def __init__(
knots=None,
method="cubic",
name="",
break_indices=None,
):
super().__init__(current, X, Y, Z, knots, method, name)
super().__init__(current, X, Y, Z, knots, method, name, break_indices)

def _compute_A_or_B(
self,
Expand Down Expand Up @@ -1109,7 +1142,14 @@ def compute_magnetic_vector_potential(

@classmethod
def from_values(
cls, current, coords, knots=None, method="cubic", name="", basis="xyz"
cls,
current,
coords,
knots=None,
method="cubic",
name="",
basis="xyz",
break_indices=None,
):
"""Create SplineXYZCoil from coordinate values.

kianorr marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -1141,6 +1181,18 @@ def from_values(
name for this curve
basis : {"rpz", "xyz"}
basis for input coordinates. Defaults to "xyz"
break_indices : ndarray or None
If supplied, the spline will be a piecewise set of splines.
Indices of knots at which the curve breaks and is only C0 continuous (e.g.
continuous but with "corners" where the derivative jumps). In between each
set of break points, there is an unbroken spline whose start and endpoints
are given by `break_indices[i-1, i]`, where `i` indicates the ith spline.
Each (the ith) spline is interpolated independently of all other unbroken
splines (i+1th, i-1th, etc.) and does not consider their query points
(knots) when interpolating. The boundary conditions are evaluated using
Interpax's default where non-periodicity is assumed.
If None (the default), the spline will be the usual periodic spline with
the continuity dictated by the spline method.

Returns
-------
Expand All @@ -1159,6 +1211,7 @@ def from_values(
knots=curve.knots,
method=curve.method,
name=name,
break_indices=break_indices,
)


Expand Down Expand Up @@ -2046,9 +2099,15 @@ def to_FourierXYZ(self, N=10, grid=None, s=None, name="", check_intersection=Tru
)

def to_SplineXYZ(
self, knots=None, grid=None, method="cubic", name="", check_intersection=True
self,
knots=None,
grid=None,
method="cubic",
name="",
check_intersection=True,
break_indices=None,
):
"""Convert all coils to SplineXYZCoil representation.
"""Convert all coils to SplineXYZCoil.
kianorr marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
Expand All @@ -2073,14 +2132,29 @@ def to_SplineXYZ(
Name for the new CoilSet.
check_intersection: bool
Whether or not to check the coils in the new coiilset for intersections.
break_indices : ndarray or None
If supplied, the spline will be a piecewise set of splines.
Indices of knots at which the curve breaks and is only C0 continuous (e.g.
continuous but with "corners" where the derivative jumps). In between each
set of break points, there is an unbroken spline whose start and endpoints
are given by `break_indices[i-1, i]`, where `i` indicates the ith spline.
Each (the ith) spline is interpolated independently of all other unbroken
splines (i+1th, i-1th, etc.) and does not consider their query points
(knots) when interpolating. The boundary conditions are evaluated using
Interpax's default where non-periodicity is assumed.
If None (the default), the spline will be the usual periodic spline with
the continuity dictated by the spline method.

Returns
-------
coilset : CoilSet
New representation of the coilset parameterized by a spline for X,Y,Z.

"""
coils = [coil.to_SplineXYZ(knots, grid, method) for coil in self]
coils = [
coil.to_SplineXYZ(knots, grid, method, break_indices=break_indices)
for coil in self
]
return self.__class__(
*coils,
NFP=self.NFP,
Expand Down Expand Up @@ -2552,7 +2626,13 @@ def to_FourierXYZ(self, N=10, grid=None, s=None, name="", check_intersection=Tru
return self.__class__(*coils, name=name, check_intersection=check_intersection)

def to_SplineXYZ(
self, knots=None, grid=None, method="cubic", name="", check_intersection=True
self,
knots=None,
grid=None,
method="cubic",
name="",
check_intersection=True,
break_indices=None,
):
"""Convert all coils to SplineXYZCoil representation.

Expand All @@ -2579,14 +2659,29 @@ def to_SplineXYZ(
Name for the new MixedCoilSet.
check_intersection: bool
Whether or not to check the coils in the new coiilset for intersections.
break_indices : ndarray or None
If supplied, the spline will be a piecewise set of splines.
Indices of knots at which the curve breaks and is only C0 continuous (e.g.
continuous but with "corners" where the derivative jumps). In between each
set of break points, there is an unbroken spline whose start and endpoints
are given by `break_indices[i-1, i]`, where `i` indicates the ith spline.
Each (the ith) spline is interpolated independently of all other unbroken
splines (i+1th, i-1th, etc.) and does not consider their query points
(knots) when interpolating. The boundary conditions are evaluated using
Interpax's default where non-periodicity is assumed.
If None (the default), the spline will be the usual periodic spline with
the continuity dictated by the spline method.

Returns
-------
coilset : MixedCoilSet
New representation of the coilset parameterized by a spline for X,Y,Z.

"""
coils = [coil.to_SplineXYZ(knots, grid, method) for coil in self]
coils = [
coil.to_SplineXYZ(knots, grid, method, break_indices=break_indices)
for coil in self
]
return self.__class__(*coils, name=name, check_intersection=check_intersection)

def __add__(self, other):
Expand Down Expand Up @@ -2640,6 +2735,7 @@ def from_makegrid_coilfile( # noqa: C901 - FIXME: simplify this
the data, and will not introduce new extrema in the interpolated points
- ``'monotonic-0'``: same as `'monotonic'` but with 0 first derivatives at
both endpoints

ignore_groups : bool
If False, return the coils in a nested MixedCoilSet, with a sub coilset per
single coilgroup. If there is only a single group, however, this will not
Expand Down
Loading
Loading