#[derive(Debug, Clone)]
pub struct SpinResistor {
pub r_up: f64,
pub r_down: f64,
pub length: f64,
pub area: f64,
}
impl SpinResistor {
pub fn new(r_up: f64, r_down: f64, length: f64, area: f64) -> Self {
Self {
r_up,
r_down,
length,
area,
}
}
pub fn from_bulk(rho: f64, beta: f64, length: f64, area: f64) -> Self {
let r_avg = rho * length / area;
let r_up = r_avg * (1.0 - beta);
let r_down = r_avg * (1.0 + beta);
Self {
r_up,
r_down,
length,
area,
}
}
pub fn total_resistance(&self) -> f64 {
1.0 / (1.0 / self.r_up + 1.0 / self.r_down)
}
pub fn current_polarization(&self) -> f64 {
(self.r_down - self.r_up) / (self.r_down + self.r_up)
}
pub fn spin_accumulation(&self, current: f64) -> f64 {
let r_s = (self.r_up - self.r_down).abs() / 2.0;
current * r_s
}
}
#[derive(Debug, Clone)]
pub struct SpinConductance {
pub g_up: f64,
pub g_down: f64,
}
impl SpinConductance {
pub fn from_resistor(resistor: &SpinResistor) -> Self {
Self {
g_up: 1.0 / resistor.r_up,
g_down: 1.0 / resistor.r_down,
}
}
pub fn total(&self) -> f64 {
self.g_up + self.g_down
}
pub fn spin(&self) -> f64 {
self.g_up - self.g_down
}
pub fn polarization(&self) -> f64 {
(self.g_up - self.g_down) / (self.g_up + self.g_down)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spin_resistor_creation() {
let resistor = SpinResistor::new(100.0, 200.0, 1.0e-6, 1.0e-12);
assert_eq!(resistor.r_up, 100.0);
assert_eq!(resistor.r_down, 200.0);
}
#[test]
fn test_from_bulk() {
let resistor = SpinResistor::from_bulk(1.0e-7, 0.5, 1.0e-6, 1.0e-12);
assert!(resistor.r_down > resistor.r_up);
}
#[test]
fn test_total_resistance() {
let resistor = SpinResistor::new(100.0, 200.0, 1.0e-6, 1.0e-12);
let r_total = resistor.total_resistance();
let expected = 1.0 / (1.0 / 100.0 + 1.0 / 200.0);
assert!((r_total - expected).abs() < 1e-10);
}
#[test]
fn test_current_polarization() {
let resistor = SpinResistor::new(100.0, 200.0, 1.0e-6, 1.0e-12);
let p = resistor.current_polarization();
assert!((p - 1.0 / 3.0).abs() < 1e-10);
}
#[test]
fn test_conductance_conversion() {
let resistor = SpinResistor::new(100.0, 200.0, 1.0e-6, 1.0e-12);
let conductance = SpinConductance::from_resistor(&resistor);
assert!((conductance.g_up - 0.01).abs() < 1e-10);
assert!((conductance.g_down - 0.005).abs() < 1e-10);
}
}