Skip to content

Commit

Permalink
get linking current working in single-stage
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-dudt committed Aug 23, 2024
1 parent ad68afa commit e7351d3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions desc/objectives/_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from desc.compute.utils import safenorm
from desc.grid import LinearGrid, _Grid
from desc.integrals import compute_B_plasma
from desc.utils import Timer, errorif, warnif
from desc.utils import Timer, broadcast_tree, errorif, warnif

from .normalization import compute_scaling_factors
from .objective_funs import _Objective
Expand Down Expand Up @@ -1606,13 +1606,15 @@ def build(self, use_jit=True, verbose=1):
self._dim_f = 1
self._data_keys = ["G"]

Check warning on line 1607 in desc/objectives/_coils.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_coils.py#L1606-L1607

Added lines #L1606 - L1607 were not covered by tests

all_params = tree_map(lambda dim: np.arange(dim), coil.dimensions)
current_params = tree_map(lambda idx: {"current": idx}, True)
self._indices = tree_leaves(broadcast_tree(current_params, all_params))
self._num_coils = coil.num_coils

Check warning on line 1612 in desc/objectives/_coils.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_coils.py#L1609-L1612

Added lines #L1609 - L1612 were not covered by tests

profiles = get_profiles(self._data_keys, obj=eq, grid=grid)
transforms = get_transforms(self._data_keys, obj=eq, grid=grid)

Check warning on line 1615 in desc/objectives/_coils.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_coils.py#L1614-L1615

Added lines #L1614 - L1615 were not covered by tests

self._constants = {

Check warning on line 1617 in desc/objectives/_coils.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_coils.py#L1617

Added line #L1617 was not covered by tests
"eq": eq,
"coil": coil,
"grid": grid,
"profiles": profiles,
"transforms": transforms,
"quad_weights": 1.0,
Expand Down Expand Up @@ -1653,9 +1655,12 @@ def compute(self, eq_params, coil_params, constants=None):
profiles=constants["profiles"],
)
eq_linking_current = 2 * jnp.pi * data["G"][0] / mu_0
coil_linking_current = jnp.sum(
coil_linking_current = self._num_coils * jnp.mean(

Check warning on line 1658 in desc/objectives/_coils.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_coils.py#L1657-L1658

Added lines #L1657 - L1658 were not covered by tests
jnp.concatenate(
[jnp.atleast_1d(param["current"]) for param in tree_leaves(coil_params)]
[
jnp.atleast_1d(param[idx])
for param, idx in zip(tree_leaves(coil_params), self._indices)
]
)
)
return eq_linking_current - coil_linking_current

Check warning on line 1666 in desc/objectives/_coils.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_coils.py#L1666

Added line #L1666 was not covered by tests

0 comments on commit e7351d3

Please sign in to comment.