Skip to content

Instantly share code, notes, and snippets.

@loganbvh
Created April 11, 2024 18:33
Show Gist options
  • Save loganbvh/ec5dcb06043680a3a13dc2a48a4131f5 to your computer and use it in GitHub Desktop.
Save loganbvh/ec5dcb06043680a3a13dc2a48a4131f5 to your computer and use it in GitHub Desktop.
supercreen-field-from-solution.py
import numpy as np
import superscreen as sc
def field_from_solution(
x: np.ndarray,
y: np.ndarray,
z: np.ndarray,
*,
solution: sc.Solution,
dr: tuple[float, float, float] = (0.0, 0.0, 0.0),
units: str = "mT",
) -> np.ndarray:
"""Evaluates the z-component of the screening field from a ``superscreen.Solution``.
Args:
x: The x values at which to evaluate the field, shape ``(n,)``
y: The y values at which to evaluate the field, shape ``(n,)``
z: The z values at which to evaluate the field, shape ``(n,)``
solution: The ``superscreen.Solution``
dr: The relative position between the coordinate system for ``solution.device``
and the coordinate system for the target ``superscreen.Device``
units: The magnetic field units in which to return the field
Returns:
B_z due to screening currents flowing in ``solution.device``, evaluated
at positions ``[x, y, z]`` in the specified units, shape ``(n, )``
"""
x = np.squeeze(x)
y = np.squeeze(y)
z = np.squeeze(z)
if z.ndim == 0:
z = z.item() * np.ones_like(x)
positions = np.array([x, y, z]).T - np.array([dr])
return solution.screening_field_at_position(
positions, units=units, with_units=False
)
@loganbvh
Copy link
Author

Usage:

sample_solution = sc.solve(
    sample_device,
    applied_field=sc.Parameter(
        field_from_solution,
        solution=squid_solution,
        dr=squid_position,
    ),
    field_units="mT",
)[-1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment