Skip to content

Commit

Permalink
Merge branch 'master' into dd/linking_current
Browse files Browse the repository at this point in the history
  • Loading branch information
f0uriest authored Dec 10, 2024
2 parents 815ad41 + 8048085 commit f060c38
Show file tree
Hide file tree
Showing 58 changed files with 5,280 additions and 1,105 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "pip"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
2 changes: 2 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
pwd
lscpu
pip list
cd tests/benchmarks
python -m pytest benchmark_cpu_small.py -vv \
--benchmark-save='Latest_Commit' \
Expand All @@ -108,6 +109,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
pwd
lscpu
pip list
cd tests/benchmarks
python -m pytest benchmark_cpu_small.py -vv \
--benchmark-save='master' \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/jax_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
run: |
pwd
lscpu
pip list
python -m pytest -m unit \
--durations=0 \
--mpl \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mpl_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ jobs:
run: |
pwd
lscpu
pip list
python -m pytest tests/test_plotting.py --durations=0 --mpl --maxfail=1
1 change: 1 addition & 0 deletions .github/workflows/notebook_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
pwd
lscpu
pip list
export PYTHONPATH=$(pwd)
pytest -v --nbmake "./docs/notebooks" \
--nbmake-timeout=2000 \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/regression_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
source .venv-${{ matrix.python-version }}/bin/activate
pwd
lscpu
pip list
python -m pytest -v -m regression\
--durations=0 \
--cov-report xml:cov.xml \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
source .venv-${{ matrix.combos.python_version }}/bin/activate
pwd
lscpu
pip list
python -m pytest -v -m unit \
--durations=0 \
--cov-report xml:cov.xml \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/weekly_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
run: |
pwd
lscpu
pip list
python -m pytest -v -m unit \
--durations=0 \
--splits 4 \
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ New Feature
- Add ``desc.objectives.LinkingCurrent`` for ensuring that coils in a stage 2 or single stage optimization provide the required linking current for a given equilibrium.


Bug Fixes

- Small bug fix to use the correct normalization length ``a`` in the BallooningStability objective

v0.13.0
-------

Expand Down
4 changes: 2 additions & 2 deletions desc/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
from jax.lax import cond, fori_loop, scan, switch, while_loop
from jax.nn import softmax as softargmax
from jax.numpy import bincount, flatnonzero, repeat, take
from jax.numpy.fft import irfft, rfft, rfft2
from jax.numpy.fft import ifft, irfft, irfft2, rfft, rfft2
from jax.scipy.fft import dct, idct
from jax.scipy.linalg import block_diag, cho_factor, cho_solve, qr, solve_triangular
from jax.scipy.special import gammaln
Expand Down Expand Up @@ -434,7 +434,7 @@ def tangent_solve(g, y):
jit = lambda func, *args, **kwargs: func
execute_on_cpu = lambda func: func
import scipy.optimize
from numpy.fft import irfft, rfft, rfft2 # noqa: F401
from numpy.fft import ifft, irfft, irfft2, rfft, rfft2 # noqa: F401
from scipy.fft import dct, idct # noqa: F401
from scipy.integrate import odeint # noqa: F401
from scipy.linalg import ( # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions desc/compute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
_field,
_geometry,
_metric,
_neoclassical,
_omnigenity,
_profiles,
_stability,
Expand Down
50 changes: 47 additions & 3 deletions desc/compute/_basis_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3223,17 +3223,61 @@ def _e_sub_zeta_zz(params, transforms, profiles, data, **kwargs):
transforms={},
profiles=[],
coordinates="rtz",
data=["e^rho", "e^theta", "e^zeta", "alpha_r", "alpha_t", "alpha_z"],
data=["grad(alpha) (periodic)", "grad(alpha) (secular)"],
)
def _grad_alpha(params, transforms, profiles, data, **kwargs):
data["grad(alpha)"] = (
data["alpha_r"] * data["e^rho"].T
data["grad(alpha)"] = data["grad(alpha) (periodic)"] + data["grad(alpha) (secular)"]
return data


@register_compute_fun(
name="grad(alpha) (periodic)",
label="\\mathrm{periodic}(\\nabla \\alpha)",
units="m^{-1}",
units_long="Inverse meters",
description=(
"Gradient of field line label, which is perpendicular to the field line, "
"periodic component"
),
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e^rho", "e^theta", "e^zeta", "alpha_r (periodic)", "alpha_t", "alpha_z"],
)
def _periodic_grad_alpha(params, transforms, profiles, data, **kwargs):
data["grad(alpha) (periodic)"] = (
data["alpha_r (periodic)"] * data["e^rho"].T
+ data["alpha_t"] * data["e^theta"].T
+ data["alpha_z"] * data["e^zeta"].T
).T
return data


@register_compute_fun(
name="grad(alpha) (secular)",
label="\\mathrm{secular}(\\nabla \\alpha)",
units="m^{-1}",
units_long="Inverse meters",
description=(
"Gradient of field line label, which is perpendicular to the field line, "
"secular component"
),
dim=3,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["e^rho", "alpha_r (secular)"],
)
def _secular_grad_alpha(params, transforms, profiles, data, **kwargs):
data["grad(alpha) (secular)"] = (
data["alpha_r (secular)"][:, jnp.newaxis] * data["e^rho"]
)
return data


@register_compute_fun(
name="grad(psi)",
label="\\nabla\\psi",
Expand Down
46 changes: 40 additions & 6 deletions desc/compute/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,14 +1518,48 @@ def _alpha(params, transforms, profiles, data, **kwargs):
transforms={},
profiles=[],
coordinates="rtz",
data=["theta_PEST_r", "phi", "phi_r", "iota", "iota_r"],
data=["alpha_r (periodic)", "alpha_r (secular)"],
)
def _alpha_r(params, transforms, profiles, data, **kwargs):
data["alpha_r"] = (
data["theta_PEST_r"]
- data["iota_r"] * data["phi"]
- data["iota"] * data["phi_r"]
)
data["alpha_r"] = data["alpha_r (periodic)"] + data["alpha_r (secular)"]
return data


@register_compute_fun(
name="alpha_r (periodic)",
label="\\mathrm{periodic}(\\partial_\\rho \\alpha)",
units="~",
units_long="None",
description="Field line label, derivative wrt radial coordinate, "
"periodic component",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["theta_PEST_r", "iota", "phi_r"],
)
def _periodic_alpha_r(params, transforms, profiles, data, **kwargs):
data["alpha_r (periodic)"] = data["theta_PEST_r"] - data["iota"] * data["phi_r"]
return data


@register_compute_fun(
name="alpha_r (secular)",
label="\\mathrm{secular}(\\partial_\\rho \\alpha)",
units="~",
units_long="None",
description="Field line label, derivative wrt radial coordinate, "
"secular component",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["iota_r", "phi"],
)
def _secular_alpha_r(params, transforms, profiles, data, **kwargs):
data["alpha_r (secular)"] = -data["iota_r"] * data["phi"]
return data


Expand Down
4 changes: 2 additions & 2 deletions desc/compute/_equil.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,12 +658,12 @@ def _F_anisotropic(params, transforms, profiles, data, **kwargs):
transforms={"grid": []},
profiles=[],
coordinates="",
data=["|B|", "sqrt(g)"],
data=["|B|^2", "sqrt(g)"],
resolution_requirement="rtz",
)
def _W_B(params, transforms, profiles, data, **kwargs):
data["W_B"] = jnp.sum(
data["|B|"] ** 2 * data["sqrt(g)"] * transforms["grid"].weights
data["|B|^2"] * data["sqrt(g)"] * transforms["grid"].weights
) / (2 * mu_0)
return data

Expand Down
Loading

0 comments on commit f060c38

Please sign in to comment.