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

add basic coil objectives #853

Merged
merged 87 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
24fdbc6
initial commit
kianorr Feb 3, 2024
dd1c024
Merge branch 'master' into ko/coil_length
kianorr Feb 3, 2024
68301c0
add simple test
kianorr Feb 4, 2024
1b8306f
Merge branch master into ko/coil_length
kianorr Feb 4, 2024
834b6d0
add default args plus todos
kianorr Feb 4, 2024
45b7282
Merge branch 'master' into ko/coil_length
kianorr Feb 5, 2024
06bef53
add to objectives __init__
kianorr Feb 5, 2024
aea78c1
merge PR#840 into ko/coil_length
kianorr Feb 5, 2024
2d64ab5
delete comments and change grid
kianorr Feb 5, 2024
a64ce35
add docstrings and grid option
kianorr Feb 6, 2024
30e72ad
Merge branch 'master' into ko/coil_length
dpanici Feb 6, 2024
5541546
Merge branch 'origin/ko/coil_length' into ko/coil_length
kianorr Feb 7, 2024
6026cf6
merge dd/curve into ko/coil_length
kianorr Feb 7, 2024
5c8823b
Merge branch 'master' into ko/coil_length
kianorr Feb 8, 2024
2ddc10f
initial commit
kianorr Feb 3, 2024
6326552
add simple test
kianorr Feb 4, 2024
c424ec1
add default args plus todos
kianorr Feb 4, 2024
22b4b63
add to objectives __init__
kianorr Feb 5, 2024
c874e84
delete comments and change grid
kianorr Feb 5, 2024
b1e34eb
add docstrings and grid option
kianorr Feb 6, 2024
0e2315d
Merge branch 'ko/coil_length' into ko/coil_length
kianorr Feb 8, 2024
ffc857c
Revert "Merge branch 'ko/coil_length' into ko/coil_length"
kianorr Feb 8, 2024
09fe488
add logic for CoilSet
kianorr Feb 9, 2024
e612fb4
add test for CoilSet
kianorr Feb 9, 2024
c21305c
add mixed coil functionality
kianorr Feb 10, 2024
edae7b8
correct dim_f
kianorr Feb 10, 2024
bc0e23e
Merge branch 'master' into ko/coil_length
kianorr Feb 10, 2024
1ab2e75
add base class for coil objectives
kianorr Feb 11, 2024
dbfb77d
add kwargs
kianorr Feb 11, 2024
6f2cf35
Merge branch 'ko/coil_length' of https://github.com/PlasmaControl/DES…
kianorr Feb 11, 2024
39bff34
Merge branch 'master' into ko/coil_length
kianorr Feb 19, 2024
01c872b
address easy reviews
kianorr Feb 21, 2024
fc6cfd9
Merge branch 'ko/coil_length' of https://github.com/PlasmaControl/DES…
kianorr Feb 21, 2024
05bf325
Merge branch 'master' into ko/coil_length
kianorr Feb 21, 2024
b0658af
Merge branch 'master' into ko/coil_length
kianorr Feb 24, 2024
a6ef1c2
add tree_flatten for nested coilsets
kianorr Feb 24, 2024
209ea6d
fix import bug
kianorr Feb 24, 2024
9d378be
Merge branch 'master' into ko/coil_length
dpanici Mar 6, 2024
47f615f
Merge branch 'master' into ko/coil_length
kianorr Mar 7, 2024
2559aa1
add nested coil sets functionality
kianorr Mar 7, 2024
af3a424
use tree_flatten from backend and import jax
kianorr Mar 7, 2024
024f0f2
use tree_map for transforms
kianorr Mar 7, 2024
7535497
add logic for default grid
kianorr Mar 7, 2024
00c7bcd
add torsion objective and tests
kianorr Mar 7, 2024
73eafa4
update docstrings
kianorr Mar 7, 2024
dabdba1
change curvature target to bounds
kianorr Mar 7, 2024
2acba22
correct self._dim_f
kianorr Mar 7, 2024
be8fcb4
add normalization
kianorr Mar 7, 2024
bc129d0
move everything to _coils.py
kianorr Mar 7, 2024
2c36497
Merge branch 'master' into ko/coil_length
kianorr Mar 8, 2024
7beb157
import from _coils
kianorr Mar 8, 2024
337c0fd
Merge branch 'ko/coil_length' of https://github.com/PlasmaControl/DES…
kianorr Mar 8, 2024
3523178
addressed reviews
kianorr Mar 9, 2024
cdd348e
fix logic for type checking
kianorr Mar 10, 2024
fdb6cae
add actual nested coilset
kianorr Mar 11, 2024
7c06e13
change grid logic
kianorr Mar 12, 2024
7e7c1c9
refactor
kianorr Mar 12, 2024
c471948
Merge branch 'master' into ko/coil_length
kianorr Mar 12, 2024
a3ffe3b
Merge branch 'ko/coil_length' of https://github.com/PlasmaControl/DES…
kianorr Mar 12, 2024
77645c5
add comments
kianorr Mar 13, 2024
d071f8c
change if to elif statements
kianorr Mar 13, 2024
752fec9
refactor
kianorr Mar 13, 2024
86537fd
Merge branch 'master' into ko/coil_length
f0uriest Mar 14, 2024
e6712f0
add missing names
dpanici Mar 15, 2024
118b1cc
fix current setting of coils, which could fail if a size 1 dim 1 ndar…
dpanici Mar 15, 2024
cf0ddef
add missing print value fmt, units and whether coil objs are scalar
dpanici Mar 15, 2024
0de46f1
add test for objectives, though torsion test is not working
dpanici Mar 15, 2024
e6814b3
fix torsion test
dpanici Mar 15, 2024
51d2f02
remove unneeded print
dpanici Mar 15, 2024
3c59c73
make test a little faster and more compact
dpanici Mar 15, 2024
1000d9d
Merge branch 'master' into ko/coil_length
dpanici Mar 17, 2024
e8522bd
Merge branch 'master' into ko/coil_length
kianorr Mar 18, 2024
14095f6
adress reviews
kianorr Mar 18, 2024
2dc0510
Merge branch 'ko/coil_length' of https://github.com/PlasmaControl/DES…
kianorr Mar 18, 2024
5dd7ca3
merge master and resolve import conflict
kianorr Mar 18, 2024
53a2a20
add quad_weights to constants
kianorr Mar 19, 2024
24c393e
add quad_weights with spacing
kianorr Mar 19, 2024
2a4dd3b
concatenate quad_weights
kianorr Mar 19, 2024
24afec7
Merge branch 'master' into ko/coil_length
kianorr Mar 19, 2024
c630ca9
update docstrings
kianorr Mar 20, 2024
d6a498e
Merge branch 'ko/coil_length' of https://github.com/PlasmaControl/DES…
kianorr Mar 20, 2024
321851b
fix docstring
kianorr Mar 21, 2024
4ab1518
Merge branch 'master' into ko/coil_length
kianorr Mar 21, 2024
01a6bc2
delete scalar comments
kianorr Mar 27, 2024
caaae44
Merge branch 'master' into ko/coil_length
f0uriest Mar 27, 2024
442fc96
Merge branch 'master' into ko/coil_length
ddudt Mar 28, 2024
b0662cc
Merge branch 'master' into ko/coil_length
kianorr Mar 28, 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
75 changes: 75 additions & 0 deletions desc/objectives/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,81 @@ def compute(self, params, constants=None):
return data["V"]


class CoilLength(_Objective):
"""Coil length."""

def __init__(
self,
coil,
target=2 * np.pi,
bounds=None,
weight=1,
normalize=True,
normalize_target=True,
loss_function=None,
deriv_mode="auto",
name="coil-length",
):
super().__init__(
things=coil,
target=target,
bounds=bounds,
weight=weight,
normalize=normalize,
normalize_target=normalize_target,
loss_function=loss_function,
deriv_mode=deriv_mode,
name=name,
)

def build(self, use_jit=True, verbose=1):
"""Build objective function."""
coil = self.things[0]
self._dim_f = 1
# TODO: is this the correct data key?
# seems like it because it gives the circumference of a circular coil?
self._data_keys = ["length"]

timer = Timer()
if verbose > 0:
print("Precomputing transforms")
timer.start("Precomputing transforms")

grid = LinearGrid(L=4, M=4)
# TODO: what grid is supposed to be used here?
f0uriest marked this conversation as resolved.
Show resolved Hide resolved
# TODO: am I supposed to use obj=coil?
f0uriest marked this conversation as resolved.
Show resolved Hide resolved
profiles = get_profiles(self._data_keys, obj=coil, grid=grid)
transforms = get_transforms(self._data_keys, obj=coil, grid=grid)
self._constants = {
"transforms": transforms,
"profiles": profiles,
}

timer.stop("Precomputing transforms")
if verbose > 1:
timer.disp("Precomputing transforms")

super().build(use_jit=use_jit, verbose=verbose)

def compute(self, params, constants=None):
"""Compute length of coil."""
if constants is None:
constants = self._constants

# TODO: gets KeyError with 'rotmat' when computing 'x_s'.
f0uriest marked this conversation as resolved.
Show resolved Hide resolved
# why does coil.compute("length") work and not this?
data = compute_fun(
self.things[0],
self._data_keys,
params=params,
transforms=constants["transforms"],
profiles=constants["profiles"],
)

f = data["length"]
return f


class PlasmaVesselDistance(_Objective):
"""Target the distance between the plasma and a surrounding surface.

Expand Down
11 changes: 11 additions & 0 deletions tests/test_objective_funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import desc.examples
from desc.backend import jnp
from desc.coils import FourierPlanarCoil
from desc.compute import get_transforms
from desc.equilibrium import Equilibrium
from desc.examples import get
Expand All @@ -21,6 +22,7 @@
AspectRatio,
BootstrapRedlConsistency,
BScaleLength,
CoilLength,
CurrentDensity,
Elongation,
Energy,
Expand Down Expand Up @@ -493,6 +495,15 @@ def test(eq):
test(get("DSHAPE"))
test(get("HELIOTRON"))

@pytest.mark.unit
def test_coil_length(self):
"""Tests coil length."""
coil = FourierPlanarCoil(r_n=1)
obj = CoilLength(coil)
obj.build()
f = obj.compute(params=coil.params_dict)
np.testing.assert_allclose(f, 2 * np.pi, rtol=1e-8)


@pytest.mark.unit
def test_derivative_modes():
Expand Down
Loading