desc.objectives.PlasmaVesselDistance

class desc.objectives.PlasmaVesselDistance(eq, surface, target=None, bounds=None, weight=1, normalize=True, normalize_target=True, loss_function=None, deriv_mode='auto', surface_grid=None, plasma_grid=None, use_softmin=False, surface_fixed=False, alpha=1.0, name='plasma-vessel distance')Source

Target the distance between the plasma and a surrounding surface.

Computes the minimum distance from each point on the surface grid to a point on the plasma grid. For dense grids, this will approximate the global min, but in general will only be an upper bound on the minimum separation between the plasma and the surrounding surface.

NOTE: By default, assumes the surface is not fixed and its coordinates are computed at every iteration, for example if the winding surface you compare to is part of the optimization and thus changing. If the bounding surface is fixed, set surface_fixed=True to precompute the surface coordinates and improve the efficiency of the calculation

NOTE: for best results, use this objective in combination with either MeanCurvature or PrincipalCurvature, to penalize the tendency for the optimizer to only move the points on surface corresponding to the grid that the plasma-vessel distance is evaluated at, which can cause cusps or regions of very large curvature.

NOTE: When use_softmin=True, ensures that alpha*values passed in is at least >1, otherwise the softmin will return inaccurate approximations of the minimum. Will automatically multiply array values by 2 / min_val if the min of alpha*array is <1. This is to avoid inaccuracies that arise when values <1 are present in the softmin, which can cause inaccurate mins or even incorrect signs of the softmin versus the actual min.

Parameters:
  • eq (Equilibrium, optional) – Equilibrium that will be optimized to satisfy the Objective.

  • surface (Surface) – Bounding surface to penalize distance to.

  • target ({float, ndarray}, optional) – Target value(s) of the objective. Only used if bounds is None. Must be broadcastable to Objective.dim_f.

  • bounds (tuple of {float, ndarray}, optional) – Lower and upper bounds on the objective. Overrides target. Both bounds must be broadcastable to to Objective.dim_f

  • weight ({float, ndarray}, optional) – Weighting to apply to the Objective, relative to other Objectives. Must be broadcastable to to Objective.dim_f

  • normalize (bool, optional) – Whether to compute the error in physical units or non-dimensionalize.

  • normalize_target (bool) – Whether target should be normalized before comparing to computed values. if normalize is True and the target is in physical units, this should also be set to True.

  • loss_function ({None, 'mean', 'min', 'max'}, optional) – Loss function to apply to the objective values once computed. This loss function is called on the raw compute value, before any shifting, scaling, or normalization.

  • deriv_mode ({"auto", "fwd", "rev"}) – Specify how to compute jacobian matrix, either forward mode or reverse mode AD. “auto” selects forward or reverse mode based on the size of the input and output of the objective. Has no effect on self.grad or self.hess which always use reverse mode and forward over reverse mode respectively.

  • surface_grid (Grid, optional) – Collocation grid containing the nodes to evaluate surface geometry at.

  • plasma_grid (Grid, optional) – Collocation grid containing the nodes to evaluate plasma geometry at.

  • use_softmin (bool, optional) – Use softmin or hard min.

  • surface_fixed (bool, optional) – Whether the surface the distance from the plasma is computed to is fixed or not. If True, the surface is fixed and its coordinates are precomputed, which saves on computation time during optimization, and self.things = [eq] only. If False, the surface coordinates are computed at every iteration. False by default, so that self.things = [eq, surface]

  • alpha (float, optional) – Parameter used for softmin. The larger alpha, the closer the softmin approximates the hardmin. softmin -> hardmin as alpha -> infinity. if alpha*array < 1, the underlying softmin will automatically multiply the array by 2/min_val to ensure that alpha*array>1. Making alpha larger than this minimum value will make the softmin a more accurate approximation of the true min.

  • name (str, optional) – Name of the objective function.

Methods

build([use_jit, verbose])

Build constant arrays.

compute(equil_params[, surface_params, ...])

Compute plasma-surface distance.

compute_scalar(*args, **kwargs)

Compute the scalar form of the objective.

compute_scaled(*args, **kwargs)

Compute and apply weighting and normalization.

compute_scaled_error(*args, **kwargs)

Compute and apply the target/bounds, weighting, and normalization.

compute_unscaled(*args, **kwargs)

Compute the raw value of the objective.

copy([deepcopy])

Return a (deep)copy of this object.

equiv(other)

Compare equivalence between DESC objects.

grad(*args, **kwargs)

Compute gradient vector of self.compute_scalar wrt x.

hess(*args, **kwargs)

Compute Hessian matrix of self.compute_scalar wrt x.

jac_scaled(*args, **kwargs)

Compute Jacobian matrix of self.compute_scaled wrt x.

jac_scaled_error(*args, **kwargs)

Compute Jacobian matrix of self.compute_scaled_error wrt x.

jac_unscaled(*args, **kwargs)

Compute Jacobian matrix of self.compute_unscaled wrt x.

jit()

Apply JIT to compute methods, or re-apply after updating self.

jvp_scaled(v, x[, constants])

Compute Jacobian-vector product of self.compute_scaled.

jvp_scaled_error(v, x[, constants])

Compute Jacobian-vector product of self.compute_scaled_error.

jvp_unscaled(v, x[, constants])

Compute Jacobian-vector product of self.compute_unscaled.

load(load_from[, file_format])

Initialize from file.

print_value(*args, **kwargs)

Print the value of the objective.

save(file_name[, file_format, file_mode])

Save the object.

xs(*things)

Return a tuple of args required by this objective from optimizable things.

Attributes

bounds

Lower and upper bounds of the objective.

built

Whether the transforms have been precomputed (or not).

constants

Constant parameters such as transforms and profiles.

dim_f

Number of objective equations.

fixed

Whether the objective fixes individual parameters (or linear combo).

linear

Whether the objective is a linear function (or nonlinear).

name

Name of objective (str).

normalization

normalizing scale factor.

scalar

Whether default "compute" method is a scalar or vector.

target

Target value(s) of the objective.

things

Optimizable things that this objective is tied to.

weight

Weighting to apply to the Objective, relative to other Objectives.