jax_sbgeom.coils.coil_winding_surface module

coil_surface_loss(d_i: Array, coilset: CoilSet, n_coils: int, uniformity_loss_weight: float, repulsive_loss_weight: float)[source]

Compute total coil surface loss.

Parameters:
  • d_i (Array) – Unregularized segment lengths between consecutive points along each coil.

  • coilset (CoilSet) – CoilSet containing the coils.

  • n_coils (int) – Number of coils.

  • uniformity_loss_weight (float) – Weight of the uniformity loss.

  • repulsive_loss_weight (float) – Weight of the repulsion loss.

Returns:

total_loss – Total coil surface loss.

Return type:

float

optimize_coil_surface(coilset: CoilSet, uniformity_penalty: float = 1.0, repulsive_penalty: float = 0.1, n_samples_per_coil: int = 100, optimization_settings=OptimizationSettings(max_iterations=100, tolerance=0.0001))[source]

Optimize the sampling points of a CoilSet for minimum distance between adjacent coils with penalties for non-uniformity and closeness of points. This ensures that the optimizer does not find pathological solutions where points cluster together. The CoilSet is first ordered in phi and ensured to have positive orientation.

Parameters:
  • coilset (CoilSet) – CoilSet containing the coils to optimize.

  • uniformity_penalty (float) – Weight of the uniformity loss.

  • repulsive_penalty (float) – Weight of the repulsion loss.

  • n_samples_per_coil (int) – Number of sample points per coil.

  • optimization_settings (OptimizationSettings) – Settings for the optimization process.

Returns:

  • optimized_params (jnp.ndarray) – Optimized parameters for the coil surface.

  • coilset_ordered_and_positive (CoilSet) – CoilSet with ordered and positively oriented coils.

create_optimized_coil_winding_surface(coilset: CoilSet, n_points_per_coil: int, n_points_phi: int, surface_type: Literal['spline', 'fourier', 'direct'] = 'spline', uniformity_penalty: float = 1.0, repulsive_penalty: float = 0.1, n_samples_per_coil_opt: int = 100, optimization_settings=OptimizationSettings(max_iterations=100, tolerance=0.0001))[source]

Create an optimized coil winding surface mesh from a CoilSet. The CoilSet is first ordered in phi and ensured to have positive orientation.

Parameters:
  • coilset (CoilSet) – CoilSet containing the coils to optimize.

  • n_points_per_coil (int) – Number of points per coil in the output mesh.

  • n_points_phi (int) – Number of points in the toroidal direction if needed.

  • surface_type (Literal['spline', 'fourier', 'direct']) – Method to create the surface: - “spline” uses a 3D periodic spline on each toroidal line, - “fourier” uses a fourier transformation on each toroidal line - “direct” meshes directly between the coils (no intermediate points)

  • uniformity_penalty (float) – Weight of the uniformity loss.

  • repulsive_penalty (float) – Weight of the repulsion loss.

  • n_samples_per_coil_opt (int) – Number of sample points per coil for the optimization.

  • optimization_settings (OptimizationSettings) – Settings for the optimization process.

Returns:

  • positions (jnp.ndarray [n_points, 3]) – Positions of the coil winding surface mesh points.

  • connectivity (jnp.ndarray [n_faces, 3]) – Connectivity of the coil winding surface mesh.

create_coil_winding_surface(coilset: CoilSet, n_points_per_coil: int, n_points_phi: int, surface_type: Literal['spline', 'fourier', 'direct'] = 'spline')[source]

Create a coil winding surface from a CoilSet. The CoilSet is first ordered in phi and ensured to have positive orientation.

Parameters:
  • coilset (CoilSet) – CoilSet containing the coils to optimize.

  • n_points_per_coil (int) – Number of points per coil in the output mesh.

  • n_points_phi (int) – Number of points in the toroidal direction if needed.

  • surface_type (Literal['spline', 'fourier', 'direct']) – Method to create the surface: - “spline” uses a 3D periodic spline on each toroidal line, - “fourier” uses a fourier transformation on each toroidal line - “direct” meshes directly between the coils (no intermediate points)

Returns:

  • positions (jnp.ndarray [n_points, 3]) – Positions of the coil winding surface mesh points.

  • connectivity (jnp.ndarray [n_faces, 3]) – Connectivity of the coil winding surface mesh.

calculate_normals_from_closest_point_on_mesh(coil: Coil | CoilSet, external_mesh, n_coil_samples: int)[source]

Calculate normals at coil positions by finding the closest points on an external mesh and using that normal.

Parameters:
  • coil (Union[Coil, CoilSet]) – Coil or CoilSet containing the coil(s).

  • external_mesh (jax_sbgeom.jax_utils.mesh.Mesh) – External mesh to find closest points on.

  • n_coil_samples (int) – Number of samples along the coil(s).

Returns:

  • positions (jnp.ndarray [n_coils, n_coil_samples, 3]) – Positions along the coil(s).

  • normals (jnp.ndarray [n_coils, n_coil_samples, 3]) – Normals at the coil positions.