desc.objectives.BoundaryError

class desc.objectives.BoundaryError(eq, field, target=None, bounds=None, weight=1, normalize=True, normalize_target=True, loss_function=None, deriv_mode='auto', s=None, q=None, source_grid=None, eval_grid=None, field_grid=None, field_fixed=False, loop=True, name='Boundary error')Source

Target for free boundary conditions on LCFS for finite beta equilibrium.

Computes the residual of the following:

𝐁ₒᵤₜ ⋅ 𝐧 = 0 𝐁ₒᵤₜ² - 𝐁ᵢₙ² - p = 0 μ₀∇Φ − 𝐧 × [𝐁ₒᵤₜ − 𝐁ᵢₙ]

Where 𝐁ᵢₙ is the total field inside the LCFS (from fixed boundary calculation) 𝐁ₒᵤₜ is the total field outside the LCFS (from coils and virtual casing principle), 𝐧 is the outward surface normal, p is the plasma pressure, and Φ is the surface current potential on the LCFS. All residuals are weighted by the local area element ||𝐞_θ × 𝐞_ζ|| Δθ Δζ

The third equation is only included if a sheet current is supplied by making the equilibrium.surface object a FourierCurrentPotentialField, otherwise it is trivially satisfied. If it is known that the external field accurately reproduces the target equilibrium with low normal field error and pressure at the edge is zero, then the sheet current will generally be negligible and can be omitted to save effort.

This objective also works for vacuum equilibria, though in that case VacuumBoundaryError will be much faster as it avoids the singular virtual casing integral.

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

  • field (MagneticField) – External field produced by coils.

  • target (float, ndarray, optional) – Target value(s) of the objective. Only used if bounds is None. len(target) must be equal to Objective.dim_f

  • bounds (tuple, optional) – Lower and upper bounds on the objective. Overrides target. len(bounds[0]) and len(bounds[1]) must be equal to Objective.dim_f

  • weight (float, ndarray, optional) – Weighting to apply to the Objective, relative to other Objectives. len(weight) must be equal to Objective.dim_f

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

  • normalize_target (bool) – 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.

  • 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.

  • s (integer) – Hyperparameters for singular integration scheme, s is roughly equal to the size of the local singular grid with respect to the global grid, q is the order of integration on the local grid

  • q (integer) – Hyperparameters for singular integration scheme, s is roughly equal to the size of the local singular grid with respect to the global grid, q is the order of integration on the local grid

  • source_grid (Grid, optional) – Collocation grid containing the nodes to evaluate at for source terms for Biot- Savart integral and where to evaluate errors. source_grid should not be stellarator symmetric, and both should be at rho=1.

  • eval_grid (Grid, optional) – Collocation grid containing the nodes to evaluate at for source terms for Biot- Savart integral and where to evaluate errors. source_grid should not be stellarator symmetric, and both should be at rho=1.

  • field_grid (Grid, optional) – Grid used to discretize field.

  • field_fixed (bool) – Whether to assume the field is fixed. For free boundary solve, should be fixed. For single stage optimization, should be False (default).

  • loop (bool) – If True, evaluate integral using loops, as opposed to vmap. Slower, but uses less memory.

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

Examples

Assigning a surface current to the equilibrium:

from desc.magnetic_fields import FourierCurrentPotentialField
# turn the regular FourierRZToroidalSurface into a current potential on the
# last closed flux surface
eq.surface = FourierCurrentPotentialField.from_surface(eq.surface,
                                                      M_Phi=eq.M,
                                                      N_Phi=eq.N,
                                                      )
objective = BoundaryError(eq, field)

Methods

build([use_jit, verbose])

Build constant arrays.

compute(eq_params[, field_params, constants])

Compute boundary force error.

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.