Skip to content

Standardize use of splines in the vacuum module #141

@jhalpern30

Description

@jhalpern30

Making this a subissue to switching to a standardized spline package since there's no use in doing this before.

Right now, our usage of splines is all over the place in the vacuum module. For example:

  1. We have the periodic_cubic_deriv function for the dx/z_dtheta splines (in initialize_plasma_surface!)
    # Plasma boundary theta derivative: length mth with θ = [0, 1)
    θ_grid = range(; start=0, length=mtheta, step=2π/mtheta)
    dx_dtheta = periodic_cubic_deriv(θ_grid, x_plasma)
    dz_dtheta = periodic_cubic_deriv(θ_grid, z_plasma)
  1. Sometimes, we just call cubic_spline_interpolation directly (in kernel!)
    # Used for Z'_θ and X'_θ in eq.(51)
    spline_x = cubic_spline_interpolation(theta_grid, x_sourcepoints; extrapolation_bc=Interpolations.Periodic())
    spline_z = cubic_spline_interpolation(theta_grid, z_sourcepoints; extrapolation_bc=Interpolations.Periodic())
    dx_dtheta = [Interpolations.gradient(spline_x, t)[1] for t in theta_grid]
    dz_dtheta = [Interpolations.gradient(spline_z, t)[1] for t in theta_grid]
  1. Sometimes, we just use cubic_spline_interpolation with no BCs (in interp_to_new_grid)
    # Input grids are from [0, 1] inclusive, since no interpolants will fall outside of this, we don't need periodic extrapolation
    θin = range(0.0, 1.0; length=mtheta_in)
    itp = cubic_spline_interpolation(θin, vecin)
  1. And sometimes, we use the hardcoded lagrange1D interpolation (in distribute_to_equal_arc_grid)
        # Calculate dx/dt and dz/dt using Lagrange interpolation (order 3)
        _, d_xin = lagrange1d(theta_in1, xin1, mtheta1, 3, theta, 1)
        _, d_zin = lagrange1d(theta_in1, zin1, mtheta1, 3, theta, 1)

This is super confusing and could definitely be simplified (and can easily mask hidden bugs), considering we're splining the same thing almost every time and in a nearly identical way (a x/z grid over theta that ranges from [0, 2pi). Once we have a standardized spline package, we should go through and ensure a consistent usage of splines

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions