Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ New Features
- Adds an optional attribute `ion_density` to the `Equilibrium` class, to allow the ion density profile to be set independently of the electron density and effective atomic number. Also adds compute functions for ``"ni_rr"`` and ``"Zeff_rr"``.
- Modernizes dependencies to use [``nvidia-ml-py``](https://pypi.org/project/nvidia-ml-py/) in place of [``nvgpu``](https://github.com/rossumai/nvgpu).
If you are updating an existing software environment uninstall ``pynvml`` first and then reinstall the dependencies to correctly get ``nvidia-ml-py``.
- Option for ``eq_fixed`` added to ``BoundaryError`` to remove equilibrium as a degree of freedom from boundary error objective.
Comment thread
YigitElma marked this conversation as resolved.
Outdated

Bug Fixes

Expand Down
190 changes: 145 additions & 45 deletions desc/objectives/_free_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@
"_B_plasma_chunk_size",
"_bs_chunk_size",
"_eq_data_keys",
"_eq_fixed",
"_field_fixed",
"_q",
"_sheet_current",
Expand Down Expand Up @@ -478,6 +479,7 @@
eval_grid=None,
field_grid=None,
field_fixed=False,
eq_fixed=False,
name="Boundary error",
jac_chunk_size=None,
*,
Expand All @@ -487,12 +489,20 @@
):
if target is None and bounds is None:
target = 0
self._eq = eq
self._source_grid = source_grid
self._eval_grid = eval_grid
self._st, self._sz = s if isinstance(s, (tuple, list)) else (s, s)
self._q = q
self._field = [field] if not isinstance(field, list) else field
self._field_grid = field_grid
errorif(
field_fixed and eq_fixed,
ValueError,
"At least one of eq_fixed or field_fixed must be false.",
)
self._field_fixed = field_fixed
self._eq_fixed = eq_fixed
self._bs_chunk_size = bs_chunk_size
B_plasma_chunk_size = parse_argname_change(
B_plasma_chunk_size, kwargs, "loop", "B_plasma_chunk_size"
Expand All @@ -501,7 +511,9 @@
B_plasma_chunk_size = None
self._B_plasma_chunk_size = B_plasma_chunk_size
self._sheet_current = hasattr(eq.surface, "Phi_mn")
things = [eq]
things = []
if not eq_fixed:
things.append(self._eq)
if not field_fixed:
things.append(self._field)
super().__init__(
Expand Down Expand Up @@ -628,6 +640,9 @@

neq = 3 if self._sheet_current else 2 # number of equations we're using

if self._eq_fixed:
Comment thread
YigitElma marked this conversation as resolved.
Outdated
eq = self._eq

Check warning on line 644 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L644

Added line #L644 was not covered by tests

self._constants = {
"eval_transforms": eval_transforms,
"eval_profiles": eval_profiles,
Expand All @@ -651,6 +666,74 @@
)
)

if self._eq_fixed:
source_data = compute_fun(

Check warning on line 670 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L670

Added line #L670 was not covered by tests
"desc.equilibrium.equilibrium.Equilibrium",
self._eq_data_keys,
params=self._eq.params_dict,
transforms=source_transforms,
profiles=source_profiles,
)
eval_data = (

Check warning on line 677 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L677

Added line #L677 was not covered by tests
source_data
if self._use_same_grid
else compute_fun(
"desc.equilibrium.equilibrium.Equilibrium",
self._eq_data_keys,
params=self._eq.params_dict,
transforms=eval_transforms,
profiles=eval_profiles,
)
)

Bplasma = virtual_casing_biot_savart(

Check warning on line 689 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L689

Added line #L689 was not covered by tests
eval_data,
source_data,
interpolator,
chunk_size=self._B_plasma_chunk_size,
)
# need extra factor of B/2 bc we're evaluating on plasma surface
Bplasma = Bplasma + eval_data["B"] / 2

Check warning on line 696 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L696

Added line #L696 was not covered by tests

self._constants["source_data"] = source_data
self._constants["eval_data"] = eval_data
self._constants["Bplasma"] = Bplasma

Check warning on line 700 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L698-L700

Added lines #L698 - L700 were not covered by tests

# sheet current stuff
if self._sheet_current:
p = (

Check warning on line 704 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L703-L704

Added lines #L703 - L704 were not covered by tests
"desc.magnetic_fields._current_potential."
"FourierCurrentPotentialField"
)
sheet_params = {

Check warning on line 708 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L708

Added line #L708 was not covered by tests
"R_lmn": self._eq.params_dict["Rb_lmn"],
"Z_lmn": self._eq.params_dict["Zb_lmn"],
"I": self._eq.params_dict["I"],
"G": self._eq.params_dict["G"],
"Phi_mn": self._eq.params_dict["Phi_mn"],
}
sheet_source_data = compute_fun(

Check warning on line 715 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L715

Added line #L715 was not covered by tests
p,
self._sheet_data_keys,
params=sheet_params,
transforms=self._constants["sheet_source_transforms"],
profiles={},
)
sheet_eval_data = (

Check warning on line 722 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L722

Added line #L722 was not covered by tests
sheet_source_data
if self._use_same_grid
else compute_fun(
p,
self._sheet_data_keys,
params=sheet_params,
transforms=self._constants["sheet_eval_transforms"],
profiles={},
)
)

self._constants["sheet_eval_data"] = sheet_eval_data
source_data["K_vc"] += sheet_source_data["K"]

Check warning on line 735 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L734-L735

Added lines #L734 - L735 were not covered by tests

timer.stop("Precomputing transforms")
if verbose > 1:
timer.disp("Precomputing transforms")
Expand Down Expand Up @@ -680,7 +763,8 @@
Parameters
----------
eq_params : dict
Dictionary of equilibrium degrees of freedom, eg Equilibrium.params_dict
Dictionary of equilibrium degrees of freedom, eg Equilibrium.params_dict,
Comment thread
IssraAli marked this conversation as resolved.
Outdated
if equilibrium is not fixed
field_params : dict
Dictionary of field parameters, if field is not fixed.
constants : dict
Expand All @@ -697,62 +781,78 @@
"""
if field_params == (): # common case for field_fixed=True
field_params = None
if eq_params == ():
eq_params = None

Check warning on line 785 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L785

Added line #L785 was not covered by tests

constants = self._get_deprecated_constants(constants)
source_data = compute_fun(
"desc.equilibrium.equilibrium.Equilibrium",
self._eq_data_keys,
params=eq_params,
transforms=constants["source_transforms"],
profiles=constants["source_profiles"],
)
eval_data = (
source_data
if self._use_same_grid
else compute_fun(

if self._eq_fixed:
source_data = constants["source_data"]
eval_data = constants["eval_data"]
Bplasma = constants["Bplasma"]
if self._sheet_current:
sheet_eval_data = constants["sheet_eval_data"]

Check warning on line 794 in desc/objectives/_free_boundary.py

View check run for this annotation

Codecov / codecov/patch

desc/objectives/_free_boundary.py#L790-L794

Added lines #L790 - L794 were not covered by tests
else:
source_data = compute_fun(
"desc.equilibrium.equilibrium.Equilibrium",
self._eq_data_keys,
params=eq_params,
transforms=constants["eval_transforms"],
profiles=constants["eval_profiles"],
transforms=constants["source_transforms"],
profiles=constants["source_profiles"],
)
)
if self._sheet_current:
p = "desc.magnetic_fields._current_potential.FourierCurrentPotentialField"
sheet_params = {
"R_lmn": eq_params["Rb_lmn"],
"Z_lmn": eq_params["Zb_lmn"],
"I": eq_params["I"],
"G": eq_params["G"],
"Phi_mn": eq_params["Phi_mn"],
}
sheet_source_data = compute_fun(
p,
self._sheet_data_keys,
params=sheet_params,
transforms=constants["sheet_source_transforms"],
profiles={},
)
sheet_eval_data = (
sheet_source_data
eval_data = (
source_data
if self._use_same_grid
else compute_fun(
"desc.equilibrium.equilibrium.Equilibrium",
self._eq_data_keys,
params=eq_params,
transforms=constants["eval_transforms"],
profiles=constants["eval_profiles"],
)
)

Bplasma = virtual_casing_biot_savart(
eval_data,
source_data,
constants["interpolator"],
chunk_size=self._B_plasma_chunk_size,
)
# need extra factor of B/2 bc we're evaluating on plasma surface
Bplasma = Bplasma + eval_data["B"] / 2

if self._sheet_current:
p = (
"desc.magnetic_fields._current_potential."
"FourierCurrentPotentialField"
)
sheet_params = {
"R_lmn": eq_params["Rb_lmn"],
"Z_lmn": eq_params["Zb_lmn"],
"I": eq_params["I"],
"G": eq_params["G"],
"Phi_mn": eq_params["Phi_mn"],
}
sheet_source_data = compute_fun(
p,
self._sheet_data_keys,
params=sheet_params,
transforms=constants["sheet_eval_transforms"],
transforms=constants["sheet_source_transforms"],
profiles={},
)
)
source_data["K_vc"] += sheet_source_data["K"]
sheet_eval_data = (
sheet_source_data
if self._use_same_grid
else compute_fun(
p,
self._sheet_data_keys,
params=sheet_params,
transforms=constants["sheet_eval_transforms"],
profiles={},
)
)
source_data["K_vc"] += sheet_source_data["K"]

Bplasma = virtual_casing_biot_savart(
eval_data,
source_data,
constants["interpolator"],
chunk_size=self._B_plasma_chunk_size,
)
# need extra factor of B/2 bc we're evaluating on plasma surface
Bplasma = Bplasma + eval_data["B"] / 2
x = jnp.array([eval_data["R"], eval_data["phi"], eval_data["Z"]]).T
# can always pass in field params. If they're None, it just uses the
# defaults for the given field.
Expand Down
Loading