use pyo3::prelude::*;
use super::vector::PyVector3;
use crate::material::{Ferromagnet, SpinInterface};
use crate::vector3::Vector3;
#[pyclass(name = "Ferromagnet")]
#[derive(Clone)]
pub struct PyFerromagnet {
inner: Ferromagnet,
}
#[pymethods]
impl PyFerromagnet {
#[new]
#[pyo3(signature = (alpha, ms, anisotropy_k=0.0, easy_axis=(0.0, 0.0, 1.0), exchange_a=1e-11))]
pub fn new(
alpha: f64,
ms: f64,
anisotropy_k: f64,
easy_axis: (f64, f64, f64),
exchange_a: f64,
) -> Self {
Self {
inner: Ferromagnet {
alpha,
ms,
anisotropy_k,
easy_axis: Vector3::new(easy_axis.0, easy_axis.1, easy_axis.2).normalize(),
exchange_a,
},
}
}
#[getter]
pub fn alpha(&self) -> f64 {
self.inner.alpha
}
#[getter]
pub fn ms(&self) -> f64 {
self.inner.ms
}
#[getter]
pub fn anisotropy_k(&self) -> f64 {
self.inner.anisotropy_k
}
#[getter]
pub fn easy_axis(&self) -> PyVector3 {
PyVector3::from_inner(self.inner.easy_axis)
}
#[getter]
pub fn exchange_a(&self) -> f64 {
self.inner.exchange_a
}
#[staticmethod]
pub fn yig() -> Self {
Self {
inner: Ferromagnet::yig(),
}
}
#[staticmethod]
pub fn permalloy() -> Self {
Self {
inner: Ferromagnet::permalloy(),
}
}
#[staticmethod]
pub fn cofe() -> Self {
Self {
inner: Ferromagnet::cofe(),
}
}
#[staticmethod]
pub fn cofeb() -> Self {
Self {
inner: Ferromagnet::cofeb(),
}
}
#[staticmethod]
pub fn iron() -> Self {
Self {
inner: Ferromagnet::iron(),
}
}
#[staticmethod]
pub fn cobalt() -> Self {
Self {
inner: Ferromagnet::cobalt(),
}
}
#[staticmethod]
pub fn nickel() -> Self {
Self {
inner: Ferromagnet::nickel(),
}
}
pub fn __repr__(&self) -> String {
format!(
"Ferromagnet(alpha={:.4}, ms={:.2e}, anisotropy_k={:.2e}, exchange_a={:.2e})",
self.inner.alpha, self.inner.ms, self.inner.anisotropy_k, self.inner.exchange_a
)
}
}
impl PyFerromagnet {
pub fn inner(&self) -> &Ferromagnet {
&self.inner
}
}
#[pyclass(name = "SpinInterface")]
#[derive(Clone)]
pub struct PySpinInterface {
inner: SpinInterface,
}
#[pymethods]
impl PySpinInterface {
#[new]
#[pyo3(signature = (g_r, g_i=0.0, normal=(0.0, 1.0, 0.0), area=1e-12))]
pub fn new(g_r: f64, g_i: f64, normal: (f64, f64, f64), area: f64) -> Self {
Self {
inner: SpinInterface {
g_r,
g_i,
normal: Vector3::new(normal.0, normal.1, normal.2),
area,
},
}
}
#[getter]
pub fn g_r(&self) -> f64 {
self.inner.g_r
}
#[getter]
pub fn g_i(&self) -> f64 {
self.inner.g_i
}
#[getter]
pub fn normal(&self) -> PyVector3 {
PyVector3::from_inner(self.inner.normal)
}
#[getter]
pub fn area(&self) -> f64 {
self.inner.area
}
#[staticmethod]
pub fn yig_pt() -> Self {
Self {
inner: SpinInterface::yig_pt(),
}
}
#[staticmethod]
pub fn py_pt() -> Self {
Self {
inner: SpinInterface::py_pt(),
}
}
pub fn __repr__(&self) -> String {
format!(
"SpinInterface(g_r={:.2e}, g_i={:.2e}, area={:.2e})",
self.inner.g_r, self.inner.g_i, self.inner.area
)
}
}
impl PySpinInterface {
pub fn inner(&self) -> &SpinInterface {
&self.inner
}
}