Skip to content

Commit

Permalink
small PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LemurPwned committed Nov 11, 2024
1 parent f2735b8 commit f952c2f
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions cmtj/utils/resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import numpy as np
import sympy as sym

from new_sb import EPS

from .filters import Filters

EPS = np.finfo("float64").resolution


def compute_sd(dynamic_r: np.ndarray, dynamic_i: np.ndarray, integration_step: float) -> np.ndarray:
def compute_sd(
dynamic_r: np.ndarray, dynamic_i: np.ndarray, integration_step: float
) -> np.ndarray:
"""Computes the SD voltage.
:param dynamic_r: magnetoresistance from log
:param dynamic_i: excitation current
Expand Down Expand Up @@ -49,7 +51,11 @@ def compute_resistance(
for i in range(number_of_layers):
w_l = w[i] / l[i]
SxAll[i] = Rx0[i] + (AMR[i] * m[i, 0] ** 2 + SMR[i] * m[i, 1] ** 2)
SyAll[i] = Ry0[i] + 0.5 * AHE[i] * m[i, 2] + (w_l) * (SMR[i] - AMR[i]) * m[i, 0] * m[i, 1]
SyAll[i] = (
Ry0[i]
+ 0.5 * AHE[i] * m[i, 2]
+ (w_l) * (SMR[i] - AMR[i]) * m[i, 0] * m[i, 1]
)
return SxAll, SyAll


Expand All @@ -71,7 +77,10 @@ def calculate_magnetoresistance(Rp: float, Rap: float, m: np.ndarray):
if not isinstance(m, np.ndarray):
m = np.asarray(m)
if m.shape[0] != 2:
raise ValueError("The magnetoresistance can only be computed for 2 layers" f". Current shape {m.shape}")
raise ValueError(
"The magnetoresistance can only be computed for 2 layers"
f". Current shape {m.shape}"
)
return Rp + 0.5 * (Rap - Rp) * np.sum(m[0] * m[1], axis=0)


Expand Down Expand Up @@ -227,7 +236,9 @@ def calculate_linearised_resistance_parallel(
t02, p02 = stationary_angles[2:]
dt1, dp1 = linearised_angles[:2]
dt2, dp2 = linearised_angles[2:]
Rxx1, Rxx2, GMR_resistance, theta1, phi1, theta2, phi2 = calculate_linearised_resistance(GMR, AMR, SMR)
Rxx1, Rxx2, GMR_resistance, theta1, phi1, theta2, phi2 = (
calculate_linearised_resistance(GMR, AMR, SMR)
)
Rparallel = GMR_resistance
if any(AMR) or any(SMR):
Rparallel += (Rxx1 * Rxx2) / (Rxx1 + Rxx2 + EPS)
Expand Down Expand Up @@ -276,7 +287,9 @@ def calculate_linearised_resistance_series(
t02, p02 = stationary_angles[2:]
dt1, dp1 = linearised_angles[:2]
dt2, dp2 = linearised_angles[2:]
Rxx1, Rxx2, GMR_resistance, theta1, phi1, theta2, phi2 = calculate_linearised_resistance(GMR, AMR, SMR)
Rxx1, Rxx2, GMR_resistance, theta1, phi1, theta2, phi2 = (
calculate_linearised_resistance(GMR, AMR, SMR)
)
Rseries = GMR_resistance + Rxx1 + Rxx2
dRseries = (
sym.diff(Rseries, theta1) * dt1
Expand Down

0 comments on commit f952c2f

Please sign in to comment.