use crate::constants::GAMMA;
use crate::vector3::Vector3;
#[derive(Debug, Clone)]
pub struct BarnettField {
pub gamma: f64,
}
impl Default for BarnettField {
fn default() -> Self {
Self { gamma: GAMMA }
}
}
impl BarnettField {
pub fn new(gamma: f64) -> Self {
Self { gamma }
}
pub fn field_from_rotation(&self, omega: Vector3<f64>) -> Vector3<f64> {
let mu0 = 1.256637e-6;
omega * (-1.0 / (self.gamma * mu0))
}
pub fn field_from_vorticity(&self, vorticity: Vector3<f64>) -> Vector3<f64> {
let omega = vorticity * 0.5;
self.field_from_rotation(omega)
}
pub fn spin_polarization(&self, omega: Vector3<f64>, temperature: f64) -> f64 {
use crate::constants::{KB, MU_B};
if temperature < 1.0 {
return 0.0;
}
let omega_mag = omega.magnitude();
let thermal_energy = KB * temperature;
(MU_B * omega_mag) / (self.gamma * thermal_energy)
}
pub fn spin_current_from_vorticity_gradient(
&self,
vorticity_gradient: f64,
density: f64,
) -> f64 {
use crate::constants::HBAR;
(HBAR * density / 2.0) * vorticity_gradient
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_barnett_field_creation() {
let barnett = BarnettField::default();
assert_eq!(barnett.gamma, GAMMA);
}
#[test]
fn test_field_from_rotation() {
let barnett = BarnettField::default();
let omega = Vector3::new(0.0, 0.0, 100.0);
let h_field = barnett.field_from_rotation(omega);
assert!(h_field.z < 0.0);
assert!(h_field.magnitude() > 0.0);
}
#[test]
fn test_zero_rotation() {
let barnett = BarnettField::default();
let omega = Vector3::new(0.0, 0.0, 0.0);
let h_field = barnett.field_from_rotation(omega);
assert!(h_field.magnitude() < 1e-20);
}
#[test]
fn test_vorticity_to_field() {
let barnett = BarnettField::default();
let vorticity = Vector3::new(0.0, 0.0, 1000.0);
let h_field = barnett.field_from_vorticity(vorticity);
assert!(h_field.magnitude() > 0.0);
}
#[test]
fn test_spin_polarization() {
let barnett = BarnettField::default();
let omega = Vector3::new(0.0, 0.0, 1000.0);
let temperature = 300.0;
let polarization = barnett.spin_polarization(omega, temperature);
assert!(polarization > 0.0);
assert!(polarization < 1.0); }
}