desc.objectives.ToroidalFlux
- class desc.objectives.ToroidalFlux(eq, field, target=None, bounds=None, weight=1, normalize=True, normalize_target=True, loss_function=None, deriv_mode='auto', field_grid=None, eval_grid=None, name='toroidal-flux', jac_chunk_size=None)Source
Target the toroidal flux in an equilibrium from a magnetic field.
This objective is needed when performing stage-two coil optimization on a vacuum equilibrium, to avoid the trivial solution of minimizing Bn by making the coil currents zero. Instead, this objective ensures the coils create the necessary toroidal flux for the equilibrium field.
Will try to use the vector potential method to calculate the toroidal flux (Φ = ∮ 𝐀 ⋅ 𝐝𝐥 over the perimeter of a constant zeta plane) instead of the brute force method using the magnetic field (Φ = ∯ 𝐁 ⋅ 𝐝𝐒 over a constant zeta XS). The vector potential method is much more efficient, however not every
MagneticFieldobject has a vector potential available to compute, so in those cases the magnetic field method is used.- Parameters:
eq (Equilibrium) – Equilibrium for which the toroidal flux will be calculated. The Equilibrium is assumed to be held fixed when using this objective.
field (MagneticField) – MagneticField object, the parameters of this will be optimized to minimize the objective.
field_grid (Grid, optional) – Grid containing the nodes to evaluate field source at on the winding surface. (used if e.g. field is a CoilSet or FourierCurrentPotentialField). Defaults to the default for the given field, see the docstring of the field object for the specific default.
eval_grid (Grid, optional) – Collocation grid containing the nodes to evaluate the normal magnetic field at plasma geometry at. Defaults to a LinearGrid(L=eq.L_grid, M=eq.M_grid, zeta=jnp.array(0.0), NFP=eq.NFP).
target ({float, ndarray}, optional) – Target value(s) of the objective. Only used if bounds is None. Must be broadcastable to Objective.dim_f. Defaults to
target=eq.Psi.bounds (tuple of {float, ndarray}, optional) – Lower and upper bounds on the objective. Overrides target. Both bounds must be broadcastable to Objective.dim_f Defaults to
target=eq.Psi.weight ({float, ndarray}, optional) – Weighting to apply to the Objective, relative to other Objectives. Must be broadcastable to Objective.dim_f
normalize (bool, optional) – Whether to compute the error in physical units or non-dimensionalize.
normalize_target (bool, optional) – Whether target and bounds 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. Note: has no effect for this objective.
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.
name (str, optional) – Name of the objective.
jac_chunk_size (int or "auto", optional) – Will calculate the Jacobian
jac_chunk_sizecolumns at a time, instead of all at once. The memory usage of the Jacobian calculation is roughlymemory usage = m0 + m1*jac_chunk_size: the smaller the chunk size, the less memory the Jacobian calculation will require (with some baseline memory usage). The time it takes to compute the Jacobian is roughlyt= t0 + t1/jac_chunk_size` so the larger the ``jac_chunk_size, the faster the calculation takes, at the cost of requiring more memory. If None, it will use the largest size i.eobj.dim_x. Defaults tochunk_size=None.
Methods
build([use_jit, verbose])Build constant arrays.
compute([field_params, constants])Compute toroidal flux.
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.
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[, args0])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
Lower and upper bounds of the objective.
Whether the transforms have been precomputed (or not).
Constant parameters such as transforms and profiles.
Number of objective equations.
Whether the objective fixes individual parameters (or linear combo).
Whether the objective is a linear function (or nonlinear).
Name of objective (str).
normalizing scale factor.
Whether default "compute" method is a scalar or vector.
Target value(s) of the objective.
Optimizable things that this objective is tied to.
Weighting to apply to the Objective, relative to other Objectives.