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

signed curvature #1085

Merged
merged 28 commits into from
Jul 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
72195f8
initial commit
daniel-dudt Jun 27, 2024
572766a
Merge branch 'yge/rpz2xyz' into dd/curvature
daniel-dudt Jun 27, 2024
10ff1d9
Merge branch 'yge/rpz2xyz' into dd/curvature
daniel-dudt Jun 27, 2024
fc4bbf6
fix formulas
daniel-dudt Jun 27, 2024
bc3f2b9
Merge branch 'yge/rpz2xyz' into dd/curvature
ddudt Jun 28, 2024
3a768d3
Merge branch 'yge/rpz2xyz' into dd/curvature
dpanici Jul 3, 2024
50bea28
Merge branch 'yge/rpz2xyz' into dd/curvature
ddudt Jul 10, 2024
d6d4b4b
fix bug and test for compute center
daniel-dudt Jul 10, 2024
64f48fb
Merge branch 'master' into dd/curvature
ddudt Jul 11, 2024
9c4b3b1
Merge branch 'master' into dd/curvature
ddudt Jul 11, 2024
9591eb2
debugging curvature sign
daniel-dudt Jul 12, 2024
fe0d15b
Merge branch 'master' into dd/curvature
ddudt Jul 12, 2024
bc38b60
fix bug in center computations
daniel-dudt Jul 12, 2024
9a6e278
update test even though it doesn't really matter
daniel-dudt Jul 12, 2024
6715aef
make the code more readable
daniel-dudt Jul 12, 2024
e8b95aa
Merge branch 'master' into dd/curvature
ddudt Jul 12, 2024
5fa3338
fixing tests
daniel-dudt Jul 12, 2024
abc4a42
test frenet in xyz basis
daniel-dudt Jul 12, 2024
2c4ad5c
consistent naming convention of coil/coils
daniel-dudt Jul 15, 2024
ca62ef1
fix bug in coil objective build order
daniel-dudt Jul 15, 2024
f293c62
generalize LinearObjectiveFromUser to work with OptimizableCollection
daniel-dudt Jul 15, 2024
a40ea3b
remove unused code
daniel-dudt Jul 15, 2024
8801c4d
fix coil kwargs in tests
daniel-dudt Jul 15, 2024
6fe0663
Merge branch 'master' into dd/curvature
ddudt Jul 16, 2024
da23cc4
making requested changes
daniel-dudt Jul 16, 2024
12465c1
clarify CoilCurvature sign convention in docs
daniel-dudt Jul 16, 2024
5ed70e0
update master compute data, again
daniel-dudt Jul 16, 2024
fc5d105
fix test
dpanici Jul 16, 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
51 changes: 24 additions & 27 deletions desc/objectives/_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def compute(self, params, constants=None):
if constants is None:
constants = self._constants

coils = self.things[0]
data = coils.compute(
coil = self.things[0]
data = coil.compute(
self._data_keys,
params=params,
transforms=constants["transforms"],
Expand Down Expand Up @@ -261,7 +261,7 @@ class CoilLength(_CoilObjective):

def __init__(
self,
coils,
coil,
target=None,
bounds=None,
weight=1,
Expand All @@ -272,12 +272,11 @@ def __init__(
grid=None,
name="coil length",
):
self._coils = coils
if target is None and bounds is None:
target = 2 * np.pi

super().__init__(
coils,
coil,
["length"],
target=target,
bounds=bounds,
Expand Down Expand Up @@ -703,8 +702,8 @@ class CoilSetMinDistance(_Objective):

Parameters
----------
coils : CoilSet
Coils that are to be optimized.
coil : CoilSet
Coil(s) that are to be optimized.
target : float, ndarray, optional
Target value(s) of the objective. Only used if bounds is None.
Must be broadcastable to Objective.dim_f. If array, it has to
Expand Down Expand Up @@ -746,7 +745,7 @@ class CoilSetMinDistance(_Objective):

def __init__(
self,
coils,
coil,
ddudt marked this conversation as resolved.
Show resolved Hide resolved
target=None,
bounds=None,
weight=1,
Expand All @@ -761,7 +760,7 @@ def __init__(
bounds = (1, np.inf)
self._grid = grid
super().__init__(
things=coils,
things=coil,
target=target,
bounds=bounds,
weight=weight,
Expand Down Expand Up @@ -854,8 +853,8 @@ class PlasmaCoilSetMinDistance(_Objective):
eq : Equilibrium or FourierRZToroidalSurface
Equilibrium (or FourierRZToroidalSurface) that will be optimized
to satisfy the Objective.
coils : CoilSet
Coils that are to be optimized.
coil : CoilSet
Coil(s) that are to be optimized.
target : float, ndarray, optional
Target value(s) of the objective. Only used if bounds is None.
Must be broadcastable to Objective.dim_f. If array, it has to
Expand Down Expand Up @@ -893,15 +892,15 @@ class PlasmaCoilSetMinDistance(_Objective):
eq_fixed: bool, optional
Whether the equilibrium is fixed or not. If True, the last closed flux surface
is fixed and its coordinates are precomputed, which saves on computation time
during optimization, and self.things = [coils] only.
during optimization, and self.things = [coil] only.
If False, the surface coordinates are computed at every iteration.
False by default, so that self.things = [coils, eq].
False by default, so that self.things = [coil, eq].
coils_fixed: bool, optional
Whether the coils are fixed or not. If True, the coils
are fixed and their coordinates are precomputed, which saves on computation time
during optimization, and self.things = [eq] only.
If False, the coil coordinates are computed at every iteration.
False by default, so that self.things = [coils, eq].
False by default, so that self.things = [coil, eq].
name : str, optional
Name of the objective function.

Expand All @@ -914,7 +913,7 @@ class PlasmaCoilSetMinDistance(_Objective):
def __init__(
self,
eq,
coils,
coil,
target=None,
bounds=None,
weight=1,
Expand All @@ -931,17 +930,17 @@ def __init__(
if target is None and bounds is None:
bounds = (1, np.inf)
self._eq = eq
self._coils = coils
self._coil = coil
self._plasma_grid = plasma_grid
self._coil_grid = coil_grid
self._eq_fixed = eq_fixed
self._coils_fixed = coils_fixed
errorif(eq_fixed and coils_fixed, ValueError, "Cannot fix both eq and coils")
errorif(eq_fixed and coils_fixed, ValueError, "Cannot fix both eq and coil")
things = []
if not eq_fixed:
things.append(eq)
if not coils_fixed:
things.append(coils)
things.append(coil)
super().__init__(
things=things,
target=target,
Expand All @@ -967,13 +966,13 @@ def build(self, use_jit=True, verbose=1):
"""
if self._eq_fixed:
eq = self._eq
coils = self.things[0]
coil = self.things[0]
elif self._coils_fixed:
eq = self.things[0]
coils = self._coils
coil = self._coil
else:
eq = self.things[0]
coils = self.things[1]
coil = self.things[1]
plasma_grid = self._plasma_grid or LinearGrid(M=eq.M_grid, N=eq.N_grid)
coil_grid = self._coil_grid or None
warnif(
Expand All @@ -982,15 +981,15 @@ def build(self, use_jit=True, verbose=1):
"Plasma/Surface grid includes interior points, should be rho=1.",
)

self._dim_f = coils.num_coils
self._dim_f = coil.num_coils
ddudt marked this conversation as resolved.
Show resolved Hide resolved
ddudt marked this conversation as resolved.
Show resolved Hide resolved
self._eq_data_keys = ["R", "phi", "Z"]

eq_profiles = get_profiles(self._eq_data_keys, obj=eq, grid=plasma_grid)
eq_transforms = get_transforms(self._eq_data_keys, obj=eq, grid=plasma_grid)

self._constants = {
"eq": eq,
"coils": coils,
"coil": coil,
"coil_grid": coil_grid,
"eq_profiles": eq_profiles,
"eq_transforms": eq_transforms,
Expand All @@ -1009,9 +1008,7 @@ def build(self, use_jit=True, verbose=1):
plasma_pts = rpz2xyz(jnp.array([data["R"], data["phi"], data["Z"]]).T)
self._constants["plasma_coords"] = plasma_pts
if self._coils_fixed:
coils_pts = coils._compute_position(
params=coils.params_dict, grid=coil_grid
)
coils_pts = coil._compute_position(params=coil.params_dict, grid=coil_grid)
self._constants["coil_coords"] = coils_pts

if self._normalize:
Expand Down Expand Up @@ -1057,7 +1054,7 @@ def compute(self, params_1, params_2=None, constants=None):
if self._coils_fixed:
coils_pts = constants["coil_coords"]
else:
coils_pts = constants["coils"]._compute_position(
coils_pts = constants["coil"]._compute_position(
params=coils_params, grid=constants["coil_grid"]
)

Expand Down