fdtd-coremem/crates/coremem/src/stim/fields.rs

124 lines
2.5 KiB
Rust

//! supporting types for basic Stimulus trait/impls
use crate::real::Real;
use crate::cross::vec::Vec3;
/// field densities
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Fields<R> {
pub e: Vec3<R>,
pub h: Vec3<R>,
}
impl<R> Fields<R> {
pub fn new_eh(e: Vec3<R>, h: Vec3<R>) -> Self {
Self { e, h}
}
}
impl<R: Real> Fields<R> {
pub fn e(&self) -> Vec3<R> {
self.e
}
pub fn h(&self) -> Vec3<R> {
self.h
}
pub fn new_e(e: Vec3<R>) -> Self {
Self::new_eh(e, Vec3::zero())
}
pub fn new_h(h: Vec3<R>) -> Self {
Self::new_eh(Vec3::zero(), h)
}
pub fn elem_mul(self, other: FieldMags<R>) -> Fields<R> {
Fields {
e: self.e * other.e,
h: self.h * other.h,
}
}
}
impl<R: Real> std::ops::AddAssign for Fields<R> {
fn add_assign(&mut self, other: Self) {
self.e += other.e;
self.h += other.h;
}
}
impl<R: Real> std::ops::Add for Fields<R> {
type Output = Self;
fn add(mut self, other: Self) -> Self::Output {
self += other;
self
}
}
impl<R: Real> std::ops::Mul<R> for Fields<R> {
type Output = Self;
fn mul(self, scale: R) -> Self::Output {
Fields {
e: self.e * scale,
h: self.h * scale,
}
}
}
/// field magnitude densities (really, signed magnitude)
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct FieldMags<R> {
pub e: R,
pub h: R,
}
impl<R: Real> std::ops::AddAssign for FieldMags<R> {
fn add_assign(&mut self, other: Self) {
self.e += other.e;
self.h += other.h;
}
}
impl<R: Real> std::ops::Add for FieldMags<R> {
type Output = Self;
fn add(mut self, other: Self) -> Self::Output {
self += other;
self
}
}
impl<R: Real> std::ops::Mul<R> for FieldMags<R> {
type Output = Self;
fn mul(self, scale: R) -> Self::Output {
FieldMags {
e: self.e * scale,
h: self.h * scale,
}
}
}
impl<R> FieldMags<R> {
pub fn new_eh(e: R, h: R) -> Self {
Self { e, h }
}
}
impl<R: Real> FieldMags<R> {
pub fn e(&self) -> R {
self.e
}
pub fn h(&self) -> R {
self.h
}
pub fn new_e(e: R) -> Self {
Self::new_eh(e, R::zero())
}
pub fn new_h(h: R) -> Self {
Self::new_eh(R::zero(), h)
}
pub fn elem_mul(self, other: Self) -> Self {
FieldMags {
e: self.e * other.e,
h: self.h * other.h,
}
}
}