Skip to content

Local Field Solve

device_inductance.local

Local flux solve in the vicinity of a collection of filaments with polygon sections that do not necessarily fall on a rectangular grid by allocating the fraction of intersecting polygon area to each mesh cell.

N_INSIDE module-attribute

N_INSIDE = 8

Target number of grid points inside filament extent

N_OUTSIDE module-attribute

N_OUTSIDE = 9

Target number of grid points on either side of filament extent

RMIN module-attribute

RMIN = 0.02

[m] minimum r-value to allow in local solver grid

LocalFields dataclass

LocalFields(
    jtor_per_amp: NDArray,
    psi_per_amp: NDArray,
    br_per_amp: NDArray,
    bz_per_amp: NDArray,
    psi_per_amp_interpolator: MulticubicRegular,
    br_per_amp_interpolator: MulticubicRegular,
    bz_per_amp_interpolator: MulticubicRegular,
    grids: tuple[NDArray, NDArray],
    meshes: tuple[NDArray, NDArray],
)

Outputs of local field solve

br_per_amp instance-attribute

br_per_amp: NDArray

[T/A] normalized flux density, r-component

br_per_amp_interpolator instance-attribute

br_per_amp_interpolator: MulticubicRegular

[T/A] normalized flux density, r-component, hermite spline interpolator

bz_per_amp instance-attribute

bz_per_amp: NDArray

[T/A] normalized flux density, z-component

bz_per_amp_interpolator instance-attribute

bz_per_amp_interpolator: MulticubicRegular

[T/A] normalized flux density, z-component, hermite spline interpolator

grids instance-attribute

grids: tuple[NDArray, NDArray]

[m] 1D computational grids

jtor_per_amp instance-attribute

jtor_per_amp: NDArray

[1/m^2] normalized current density map

meshes instance-attribute

meshes: tuple[NDArray, NDArray]

[m] 2D computational meshgrids

psi_per_amp instance-attribute

psi_per_amp: NDArray

[Wb/A] normalized poloidal flux

psi_per_amp_interpolator instance-attribute

psi_per_amp_interpolator: MulticubicRegular

[Wb/A] normalized poloidal flux, hermite spline interpolator

local_fields

local_fields(
    fil_rzn: tuple[NDArray, NDArray, NDArray],
    polygons: list[Polygon],
) -> LocalFields

Estimate local self-field of a collection of filaments with polygon representations.

Parameters:

Name Type Description Default
fil_rzn tuple[NDArray, NDArray, NDArray]

r-coord, z-coord, and number of turns for each filament

required
polygons list[Polygon]

polygon section of each filament

required

Returns:

Type Description
LocalFields

Structure containing local field map components and interpolators

Source code in src/device_inductance/local.py
def local_fields(fil_rzn: tuple[NDArray, NDArray, NDArray], polygons: list[Polygon]) -> LocalFields:
    """
    Estimate local self-field of a collection of filaments with polygon representations.

    Args:
        fil_rzn: r-coord, z-coord, and number of turns for each filament
        polygons: polygon section of each filament

    Returns:
        Structure containing local field map components and interpolators
    """
    rs, zs, ns = fil_rzn
    grids_regular = _make_grids_regular(rs, zs)

    # If the winding pack lands on a regular grid, use the corresponding regular grid.
    # Otherwise, fall back on a heuristic grid that spans the winding pack.
    grids = grids_regular or _make_grids_irregular(polygons)

    meshes = _make_mesh(grids)
    dr = grids[0][1] - grids[0][0]
    dz = grids[1][1] - grids[1][0]
    dxgrid = (dr, dz)

    if grids_regular is not None:
        # Just put all the current for each filament on its corresponding mesh cell
        jtor_per_amp = _allocate_current_regular(fil_rzn, grids, meshes)
    else:
        # Split polygons between mesh cells, run flux solve, and back-out B-fields
        jtor_per_amp = _allocate_current_irregular(fil_rzn, polygons, meshes, dxgrid)

    psi_per_amp, br_per_amp, bz_per_amp = _local_fields(jtor_per_amp, grids, meshes)

    # Make interpolators
    dims = [len(grids[0]), len(grids[1])]
    starts = np.array([grids[0][0], grids[1][0]])
    steps = np.array(dxgrid)
    psi_per_amp_interpolator = MulticubicRegular.new(dims, starts, steps, psi_per_amp.flatten())
    br_per_amp_interpolator = MulticubicRegular.new(dims, starts, steps, br_per_amp.flatten())
    bz_per_amp_interpolator = MulticubicRegular.new(dims, starts, steps, bz_per_amp.flatten())

    # Pack numerous outputs into a struct
    result = LocalFields(
        jtor_per_amp,
        psi_per_amp,
        br_per_amp,
        bz_per_amp,
        psi_per_amp_interpolator,
        br_per_amp_interpolator,
        bz_per_amp_interpolator,
        grids,
        meshes,
    )

    return result