Created
April 11, 2024 18:33
-
-
Save loganbvh/ec5dcb06043680a3a13dc2a48a4131f5 to your computer and use it in GitHub Desktop.
supercreen-field-from-solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: