Spaces:
Running
Running
Download src/optimal_wire/physics.py from loluwot/optimal-wire: direct link, hf CLI and curl.
- Browser
- Download file 8.78 kB
-
https://huggingface.co/spaces/loluwot/optimal-wire/resolve/main/src/optimal_wire/physics.py
- Command line
-
hf download hf://spaces/loluwot/optimal-wire/src/optimal_wire/physics.py
-
curl -L -o physics.py https://huggingface.co/spaces/loluwot/optimal-wire/resolve/main/src/optimal_wire/physics.py
8.78 kB
| """Current-crowding formulas from Clem & Berggren, PRB 84, 174510 (2011). | |
| arXiv:1109.4881. Equation numbers in the docstrings refer to that paper. | |
| All functions are pure and use plain floats, so they are easy to test and to | |
| call from other code. Lengths can be in any unit, but all lengths given to one | |
| function must use the same unit. | |
| The key quantity is the reduction factor ``R = Ic(bend) / Ic(straight strip)``. | |
| ``R = 1`` means the bend does not decrease the critical current. | |
| Model limits (from the paper): strip width much smaller than the Pearl length, | |
| and coherence length ``xi`` much smaller than the strip width. | |
| """ | |
| from __future__ import annotations | |
| import math | |
| from scipy.optimize import brentq | |
| PHI0 = 2.067833848e-15 # magnetic flux quantum (Wb) | |
| MU0 = 4e-7 * math.pi # vacuum permeability (H/m) | |
| KB = 1.380649e-23 # Boltzmann constant (J/K) | |
| HBAR = 1.054571817e-34 # reduced Planck constant (J s) | |
| # -------------------------------------------------------------------------- | |
| # Radius-of-curvature effect (Sec. VI) | |
| # -------------------------------------------------------------------------- | |
| def k0c(rho_over_xi: float) -> float: | |
| """Normalised critical sheet current at a point with curvature radius rho. | |
| This is the function ``k0c(rho_c / xi)`` of Eq. (33) and Fig. 3(b). It is | |
| the exact numerical solution of ``G = 0`` and ``dG/d(delta) = 0`` for the | |
| Gibbs free energy of Eq. (32). | |
| With ``t = sqrt(2 delta / rho + 1) - 1`` and ``r = rho / xi`` the two | |
| conditions become:: | |
| ln[2 r t (t + 1)] = (2 t + 1) / (t + 1) | |
| k0c = e (2 t + 1) / [2 r t (t + 1)] | |
| Limits: ``k0c -> 1`` for ``rho >> xi`` (Eq. 37) and | |
| ``k0c -> sqrt(2 xi / rho)`` for ``rho << xi`` (Eq. 35). | |
| """ | |
| r = float(rho_over_xi) | |
| if r <= 0: | |
| raise ValueError("rho_over_xi must be > 0") | |
| def h(log_t: float) -> float: | |
| t = math.exp(log_t) | |
| return math.log(2 * r) + log_t + math.log1p(t) - (2 * t + 1) / (t + 1) | |
| # h is monotonic in t; the root is always inside this bracket. | |
| log_t = brentq(h, -60.0 - abs(math.log(r)), 60.0 + abs(math.log(r))) | |
| t = math.exp(log_t) | |
| return math.e * (2 * t + 1) / (2 * r * t * (t + 1)) | |
| # -------------------------------------------------------------------------- | |
| # 180-degree turnarounds (Sec. VII) | |
| # -------------------------------------------------------------------------- | |
| def hairpin_half_width(width: float, gap: float) -> float: | |
| """Parameter ``a`` of Sec. VII: half the distance between outer edges.""" | |
| return width + gap / 2.0 | |
| def hairpin_crowding(width: float, gap: float) -> float: | |
| """Peak sheet current at the bend apex divided by the straight-strip value. | |
| Eq. (62): ``K(x_W, 0) / K_I = tan(pi W / 2a)`` for a turnaround whose | |
| inner edge is the stream-function contour ``S = K_I W`` (Sec. VII C). | |
| A value of 1 means no current crowding (the optimal bend, gap = 2 W). | |
| A value below 1 means the current density decreases in the bend. | |
| """ | |
| a = hairpin_half_width(width, gap) | |
| return math.tan(math.pi * width / (2 * a)) | |
| def hairpin_min_radius(width: float, gap: float) -> float: | |
| """Minimum radius of curvature of the inner edge, Eq. (61).""" | |
| a = hairpin_half_width(width, gap) | |
| return (2 * a / math.pi) * math.cos(math.pi * width / (2 * a)) ** 2 | |
| def hairpin_apex_x(width: float, gap: float) -> float: | |
| """Distance from the slit end to the inner-edge apex, Eq. (60).""" | |
| a = hairpin_half_width(width, gap) | |
| return (2 * a / math.pi) * math.log(1 / math.sin(math.pi * width / (2 * a))) | |
| def reduction_rounded_hairpin(width: float, gap: float, xi: float) -> float: | |
| """R for the best rounded 180-degree bend at this width and gap, Eq. (63). | |
| ``R = k0c(rho_c / xi) * cot(pi W / 2a)``, limited to 1. When the formula | |
| gives more than 1, vortex entry occurs in the straight strip first, so the | |
| bend does not limit the critical current. | |
| """ | |
| crowding = hairpin_crowding(width, gap) | |
| rho = hairpin_min_radius(width, gap) | |
| return min(1.0, k0c(rho / xi) / crowding) | |
| def reduction_sharp_rect_hairpin(width: float, gap: float, xi: float) -> float: | |
| """R for a sharp rectangular 180-degree turnaround, Eq. (100). | |
| ``R = (3/2) (pi alpha xi / 2W)^(1/3)`` with ``alpha = sqrt(1 - (W/a)^2)``. | |
| Valid when the gap is much larger than ``xi``. | |
| """ | |
| a = hairpin_half_width(width, gap) | |
| alpha = math.sqrt(1 - (width / a) ** 2) | |
| return min(1.0, 1.5 * (math.pi * alpha * xi / (2 * width)) ** (1 / 3)) | |
| def reduction_sharp_slit_hairpin(width: float, xi: float) -> float: | |
| """R for a sharp 180-degree turn around a zero-width slit, Eq. (56).""" | |
| return min(1.0, math.sqrt(math.pi * xi / width)) | |
| # -------------------------------------------------------------------------- | |
| # London-limit bound for constant pitch | |
| # -------------------------------------------------------------------------- | |
| # Derivation (this tool, see METHOD.md section 5). Let the outer edges of the | |
| # bend be the straight lines y = +-a_ch (a_ch = W + g/2, set by the pitch) and | |
| # let the inner edge be ANY curve. In the plane of the complex potential the | |
| # film is the strip 0 < S < I and u = ln(1/K) is harmonic there. The outer | |
| # edge turns by pi at one point, where u = -ln|G| + ln(2 a_ch / pi). The mean | |
| # value theorem for u minus the Green function of the mirrored strip gives | |
| # | |
| # integral over the inner edge of ln K(phi) omega(phi) dphi = ln(2 I / a_ch), | |
| # omega(phi) = sech(pi phi / 2I) / 2I (a probability density). | |
| # | |
| # Thus the weighted geometric mean of K on the inner edge is 2 I / a_ch for | |
| # every inner shape, and | |
| # | |
| # max K / K_I >= 2 W / a_ch, R <= a_ch / 2W = (2W + g) / 4W (xi -> 0). | |
| # | |
| # The finite-xi form of this bound and the shape that gets near to it are in | |
| # ``gibbs.py``. | |
| def reduction_upper_bound(width: float, gap: float) -> float: | |
| """Bound for any inner-edge shape at constant pitch: ``(2W + g) / 4W``. | |
| What is rigorous: the peak sheet current on the inner edge is at least | |
| ``K_I / bound``. This is a bound of R only if Ic is proportional to | |
| 1 / (peak K), which is the London limit (all radii much larger than xi). | |
| It is NOT a bound of the finite-xi models of this module: their curvature | |
| factor ``k0c > 1`` can give a larger R. Other conditions: straight outer | |
| edges, long film behind the bend. | |
| """ | |
| return min(1.0, hairpin_half_width(width, gap) / (2 * width)) | |
| # -------------------------------------------------------------------------- | |
| # 90-degree turns (Sec. VIII) | |
| # -------------------------------------------------------------------------- | |
| def reduction_sharp_90(width: float, xi: float) -> float: | |
| """R for a sharp 90-degree corner, Eq. (108).""" | |
| return min(1.0, 1.5 * (math.pi * xi / (4 * width)) ** (1 / 3)) | |
| OPTIMAL_90_MIN_RADIUS_FACTOR = 4 / math.pi # rho_c = 4W/pi (Sec. VIII B) | |
| def reduction_optimal_90(width: float, xi: float) -> float: | |
| """R for the optimally rounded 90-degree turn of Eq. (111). | |
| The sheet current is constant along the inner edge, so there is no | |
| current crowding. The curvature effect can only increase the local | |
| critical current (``k0c >= 1``), thus ``R = 1``. | |
| """ | |
| return min(1.0, k0c(OPTIMAL_90_MIN_RADIUS_FACTOR * width / xi)) | |
| def optimal_90_inner_edge(width: float, v: float) -> tuple[float, float]: | |
| """Point on the optimal 90-degree inner edge, Eq. (111) with a/2 = W. | |
| ``v > 0`` is the curve parameter. The outer corner is at the origin and | |
| the outer edges are the positive x and y axes. | |
| """ | |
| x = width * (1 + (2 / math.pi) * math.asinh(1 / v)) | |
| y = width * (1 + (2 / math.pi) * math.asinh(v)) | |
| return x, y | |
| def optimal_180_inner_edge(width: float, y: float) -> float: | |
| """x position of the optimal 180-degree inner edge, Eq. (58) with a = 2W. | |
| ``|y| < W``. The outer edges are the lines ``y = +-2W`` and the straight | |
| strips extend to ``x -> -infinity``. | |
| """ | |
| a = 2 * width | |
| return (a / math.pi) * math.log(2 * math.cos(math.pi * y / a)) | |
| # -------------------------------------------------------------------------- | |
| # Critical current of the straight strip | |
| # -------------------------------------------------------------------------- | |
| def pearl_length(lambda_: float, thickness: float) -> float: | |
| """Pearl length ``Lambda = 2 lambda^2 / d`` (same unit as the inputs).""" | |
| return 2 * lambda_**2 / thickness | |
| def critical_sheet_current(xi_m: float, lambda_m: float, thickness_m: float) -> float: | |
| """Vortex-entry critical sheet current of a long straight strip (A/m). | |
| Eq. (14): ``Kc = phi0 / (e pi mu0 xi Lambda)``. Inputs are in metres. | |
| """ | |
| lam = pearl_length(lambda_m, thickness_m) | |
| return PHI0 / (math.e * math.pi * MU0 * xi_m * lam) | |