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 Coils and magnetic fields to docs api #615

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
99 changes: 99 additions & 0 deletions desc/coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ class FourierRZCoil(Coil, FourierRZCurve):
whether to enforce stellarator symmetry
name : str
name for this coil

Examples
--------
.. code-block:: python

from desc.coils import FourierRZCoil
from desc.grid import LinearGrid
import numpy as np

I = 10
mu0 = 4 * np.pi * 1e-7
R_coil = 10
# circular coil given by R(phi) = 10
coil = FourierRZCoil(
current=I, R_n=R_coil, Z_n=0, modes_R=[0], grid=LinearGrid(N=100)
)
z0 = 10
field_evaluated = coil.compute_magnetic_field(
np.array([[0, 0, 0], [0, 0, z0]]), basis="rpz"
)
np.testing.assert_allclose(
field_evaluated[0, :], np.array([0, 0, mu0 * I / 2 / R_coil]), atol=1e-8
)
np.testing.assert_allclose(
field_evaluated[1, :],
np.array(
[0, 0, mu0 * I / 2 * R_coil**2 / (R_coil**2 + z0**2) ** (3 / 2)]
),
atol=1e-8,
)

"""

_io_attrs_ = Coil._io_attrs_ + FourierRZCurve._io_attrs_
Expand Down Expand Up @@ -150,6 +181,40 @@ class FourierXYZCoil(Coil, FourierXYZCurve):
name : str
name for this coil

Examples
--------
.. code-block:: python

from desc.coils import FourierXYZCoil
from desc.grid import LinearGrid
import numpy as np

I = 10
mu0 = 4 * np.pi * 1e-7
R_coil = 10
# circular coil given by X(phi) = 10*cos(phi), Y(phi) = 10*sin(phi)
coil = FourierXYZCoil(
current=I,
X_n=[0, R_coil, 0],
Y_n=[0, 0, R_coil],
Z_n=[0, 0, 0],
modes=[0, 1, -1],
grid=LinearGrid(N=100),
)
z0 = 10
field_evaluated = coil.compute_magnetic_field(
np.array([[0, 0, 0], [0, 0, z0]]), basis="rpz"
)
np.testing.assert_allclose(
field_evaluated[0, :], np.array([0, 0, mu0 * I / 2 / R_coil]), atol=1e-8
)
np.testing.assert_allclose(
field_evaluated[1, :],
np.array([0, 0, mu0 * I / 2 * R_coil**2 / (R_coil**2 + z0**2) ** (3 / 2)]),
atol=1e-8,
)


"""

_io_attrs_ = Coil._io_attrs_ + FourierXYZCurve._io_attrs_
Expand Down Expand Up @@ -188,6 +253,40 @@ class FourierPlanarCoil(Coil, FourierPlanarCurve):
name : str
name for this coil

Examples
--------
.. code-block:: python

from desc.coils import FourierPlanarCoil
from desc.grid import LinearGrid
import numpy as np

I = 10
mu0 = 4 * np.pi * 1e-7
R_coil = 10
# circular coil given by center at (0,0,0)
# and normal vector in Z direction (0,0,1) and radius 10
coil = FourierPlanarCoil(
current=I,
center=[0, 0, 0],
normal=[0, 0, 1],
r_n=R_coil,
modes=[0],
grid=LinearGrid(N=100),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I'm not sure about having grid objects assigned to each coil. I was considering getting rid of it in #583 but felt we should discuss it first. I think it would be better to add something like source_grid as an optional argument to compute_magnetic_field, especially since after #583 whatever grid you assign to the coil won't be used by the underlying Curve.compute method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that is something we can change in #494 when I update the coil stuff to reflect the #583 changes. This PR though is just for the docs

)
z0 = 10
field_evaluated = coil.compute_magnetic_field(
np.array([[0, 0, 0], [0, 0, z0]]), basis="rpz"
)
np.testing.assert_allclose(
field_evaluated[0, :], np.array([0, 0, mu0 * I / 2 / R_coil]), atol=1e-8
)
np.testing.assert_allclose(
field_evaluated[1, :],
np.array([0, 0, mu0 * I / 2 * R_coil**2 / (R_coil**2 + z0**2) ** (3 / 2)]),
atol=1e-8,
)

"""

_io_attrs_ = Coil._io_attrs_ + FourierPlanarCurve._io_attrs_
Expand Down
28 changes: 28 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ Basis
desc.basis.ChebyshevDoubleFourierBasis
desc.basis.FourierZernikeBasis

Coils
*****

.. autosummary::
:toctree: _api/basis/
dpanici marked this conversation as resolved.
Show resolved Hide resolved
:recursive:
:template: class.rst

desc.coils.FourierRZCoil
desc.coils.FourierXYZCoil
desc.coils.FourierPlanarCoil
desc.coils.CoilSet

Continuation
************
Expand Down Expand Up @@ -104,6 +116,22 @@ IO
desc.io.InputReader
desc.io.load

Magnetic Fields
***************

.. autosummary::
:toctree: _api/basis/
dpanici marked this conversation as resolved.
Show resolved Hide resolved
:recursive:

desc.magnetic_fields.ScaledMagneticField
desc.magnetic_fields.SumMagneticField
desc.magnetic_fields.ToroidalMagneticField
desc.magnetic_fields.VerticalMagneticField
desc.magnetic_fields.PoloidalMagneticField
desc.magnetic_fields.SplineMagneticField
desc.magnetic_fields.ScalarPotentialField
desc.magnetic_fields.field_line_integrate

Objective Functions
*******************

Expand Down