move vec, vecu into coremem_types
- this will allow it to be used from within the spirv code. - had to change some coremem code which was previously peering into privates or now-unrestricted constraints. - may need to put the serde stuff behind a feature flag (or force nostd?)
This commit is contained in:
@@ -2,8 +2,6 @@ mod line;
|
|||||||
mod polygon;
|
mod polygon;
|
||||||
pub mod region;
|
pub mod region;
|
||||||
mod units;
|
mod units;
|
||||||
mod vec;
|
|
||||||
mod vecu;
|
|
||||||
|
|
||||||
pub use line::Line2d;
|
pub use line::Line2d;
|
||||||
pub use polygon::Polygon2d;
|
pub use polygon::Polygon2d;
|
||||||
@@ -11,6 +9,6 @@ pub use region::{
|
|||||||
Cube, CylinderZ, Dilate, InvertedRegion, Memoize, Region, Sphere, Spiral, SwapXZ, SwapYZ, Torus, Translate, Union, WorldRegion, Wrap
|
Cube, CylinderZ, Dilate, InvertedRegion, Memoize, Region, Sphere, Spiral, SwapXZ, SwapYZ, Torus, Translate, Union, WorldRegion, Wrap
|
||||||
};
|
};
|
||||||
pub use units::{Coord, Meters, OrdMeters, Index};
|
pub use units::{Coord, Meters, OrdMeters, Index};
|
||||||
pub use vec::{Vec2, Vec3};
|
pub use coremem_types::vec::{Vec2, Vec3};
|
||||||
pub use vecu::Vec3u;
|
pub use coremem_types::vecu::Vec3u;
|
||||||
|
|
||||||
|
@@ -12,11 +12,24 @@ pub struct Conductor<V> {
|
|||||||
pub conductivity: V,
|
pub conductivity: V,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type IsomorphicConductor<R> = Conductor<R>;
|
pub type IsomorphicConductor<R> = Conductor<(R,)>;
|
||||||
pub type AnisomorphicConductor<R> = Conductor<Vec3<R>>;
|
pub type AnisomorphicConductor<R> = Conductor<Vec3<R>>;
|
||||||
|
|
||||||
impl<V> Conductor<V> {
|
impl<V> IsomorphicConductor<V> {
|
||||||
pub fn new(conductivity: V) -> Self {
|
pub fn new(conductivity: V) -> Self {
|
||||||
|
Self {
|
||||||
|
conductivity: (conductivity,)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<V: Clone> IsomorphicConductor<V> {
|
||||||
|
pub fn iso_conductivity(&self) -> V {
|
||||||
|
self.conductivity.0.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<R> AnisomorphicConductor<R> {
|
||||||
|
pub fn new(conductivity: Vec3<R>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
conductivity
|
conductivity
|
||||||
}
|
}
|
||||||
@@ -25,7 +38,7 @@ impl<V> Conductor<V> {
|
|||||||
|
|
||||||
impl<R: Real> Into<AnisomorphicConductor<R>> for IsomorphicConductor<R> {
|
impl<R: Real> Into<AnisomorphicConductor<R>> for IsomorphicConductor<R> {
|
||||||
fn into(self) -> AnisomorphicConductor<R> {
|
fn into(self) -> AnisomorphicConductor<R> {
|
||||||
AnisomorphicConductor::new(Vec3::uniform(self.conductivity))
|
AnisomorphicConductor::new(Vec3::uniform(self.conductivity.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +58,7 @@ impl<R: Real> Material<R> for AnisomorphicConductor<R> {
|
|||||||
|
|
||||||
impl<R: Real> Material<R> for IsomorphicConductor<R> {
|
impl<R: Real> Material<R> for IsomorphicConductor<R> {
|
||||||
fn step_parameters_mut<'a>(&'a mut self) -> StepParametersMut<'a, R> {
|
fn step_parameters_mut<'a>(&'a mut self) -> StepParametersMut<'a, R> {
|
||||||
StepParametersMut::default().with_conductivity(Vec3::uniform(self.conductivity))
|
StepParametersMut::default().with_conductivity(Vec3::uniform(self.conductivity.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -132,7 +132,7 @@ impl<R> From<AnisomorphicConductor<R>> for GenericMaterial<R> {
|
|||||||
|
|
||||||
impl<R: Real, V: Real> From<IsomorphicConductor<V>> for GenericMaterial<R> {
|
impl<R: Real, V: Real> From<IsomorphicConductor<V>> for GenericMaterial<R> {
|
||||||
fn from(inner: IsomorphicConductor<V>) -> Self {
|
fn from(inner: IsomorphicConductor<V>) -> Self {
|
||||||
let iso_r = IsomorphicConductor::new(inner.conductivity.cast::<R>());
|
let iso_r = IsomorphicConductor::new(inner.iso_conductivity().cast::<R>());
|
||||||
Self::Conductor(iso_r.into())
|
Self::Conductor(iso_r.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ impl<R: Real> Material<R> for GenericMaterial<R> {
|
|||||||
// #[enum_dispatch(Material)]
|
// #[enum_dispatch(Material)]
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub enum GenericMaterialNoPml<R> {
|
pub enum GenericMaterialNoPml<R> {
|
||||||
Conductor(Conductor<R>),
|
Conductor(AnisomorphicConductor<R>),
|
||||||
LinearMagnet(LinearMagnet<R>),
|
LinearMagnet(LinearMagnet<R>),
|
||||||
MBFerromagnet(MBFerromagnet<R>),
|
MBFerromagnet(MBFerromagnet<R>),
|
||||||
Ferroxcube3R1(Ferroxcube3R1<R>),
|
Ferroxcube3R1(Ferroxcube3R1<R>),
|
||||||
@@ -217,12 +217,12 @@ pub enum GenericMaterialNoPml<R> {
|
|||||||
|
|
||||||
impl<R: Real> Default for GenericMaterialNoPml<R> {
|
impl<R: Real> Default for GenericMaterialNoPml<R> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Conductor::default().into()
|
AnisomorphicConductor::default().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> From<Conductor<R>> for GenericMaterialNoPml<R> {
|
impl<R> From<AnisomorphicConductor<R>> for GenericMaterialNoPml<R> {
|
||||||
fn from(inner: Conductor<R>) -> Self {
|
fn from(inner: AnisomorphicConductor<R>) -> Self {
|
||||||
Self::Conductor(inner)
|
Self::Conductor(inner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,19 +267,19 @@ impl<R: Real> Material<R> for GenericMaterialNoPml<R> {
|
|||||||
// #[enum_dispatch(Material)]
|
// #[enum_dispatch(Material)]
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub enum GenericMaterialOneField<R> {
|
pub enum GenericMaterialOneField<R> {
|
||||||
Conductor(Conductor<R>),
|
Conductor(AnisomorphicConductor<R>),
|
||||||
Ferroxcube3R1(Ferroxcube3R1<R>),
|
Ferroxcube3R1(Ferroxcube3R1<R>),
|
||||||
MinimalSquare(MinimalSquare<R>),
|
MinimalSquare(MinimalSquare<R>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Real> Default for GenericMaterialOneField<R> {
|
impl<R: Real> Default for GenericMaterialOneField<R> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Conductor::default().into()
|
AnisomorphicConductor::default().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> From<Conductor<R>> for GenericMaterialOneField<R> {
|
impl<R> From<AnisomorphicConductor<R>> for GenericMaterialOneField<R> {
|
||||||
fn from(inner: Conductor<R>) -> Self {
|
fn from(inner: AnisomorphicConductor<R>) -> Self {
|
||||||
Self::Conductor(inner)
|
Self::Conductor(inner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1066,12 +1066,12 @@ impl<'a, R: Real, M: Material<R>> HCell<'a, R, M> {
|
|||||||
let aux = &mut pml.aux_h;
|
let aux = &mut pml.aux_h;
|
||||||
// (S^-1 \nabla) x E
|
// (S^-1 \nabla) x E
|
||||||
Vec3::from((
|
Vec3::from((
|
||||||
aux.sy_conv_dfz_dy.step_only_sigma(e.y, delta_ez_y)
|
aux.sy_conv_dfz_dy.step_only_sigma(e.y(), delta_ez_y)
|
||||||
- aux.sz_conv_dfy_dz.step_only_sigma(e.z, delta_ey_z),
|
- aux.sz_conv_dfy_dz.step_only_sigma(e.z(), delta_ey_z),
|
||||||
aux.sz_conv_dfx_dz.step_only_sigma(e.z, delta_ex_z)
|
aux.sz_conv_dfx_dz.step_only_sigma(e.z(), delta_ex_z)
|
||||||
- aux.sx_conv_dfz_dx.step_only_sigma(e.x, delta_ez_x),
|
- aux.sx_conv_dfz_dx.step_only_sigma(e.x(), delta_ez_x),
|
||||||
aux.sx_conv_dfy_dx.step_only_sigma(e.x, delta_ey_x)
|
aux.sx_conv_dfy_dx.step_only_sigma(e.x(), delta_ey_x)
|
||||||
- aux.sy_conv_dfx_dy.step_only_sigma(e.y, delta_ex_y),
|
- aux.sy_conv_dfx_dy.step_only_sigma(e.y(), delta_ex_y),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1183,12 +1183,12 @@ impl<'a, R: Real, M: Material<R>> ECell<'a, R, M> {
|
|||||||
let aux = &mut pml.aux_e;
|
let aux = &mut pml.aux_e;
|
||||||
// (S^-1 \nabla) x H
|
// (S^-1 \nabla) x H
|
||||||
Vec3::from((
|
Vec3::from((
|
||||||
aux.sy_conv_dfz_dy.step_only_sigma(e.y, delta_hz_y)
|
aux.sy_conv_dfz_dy.step_only_sigma(e.y(), delta_hz_y)
|
||||||
- aux.sz_conv_dfy_dz.step_only_sigma(e.z, delta_hy_z),
|
- aux.sz_conv_dfy_dz.step_only_sigma(e.z(), delta_hy_z),
|
||||||
aux.sz_conv_dfx_dz.step_only_sigma(e.z, delta_hx_z)
|
aux.sz_conv_dfx_dz.step_only_sigma(e.z(), delta_hx_z)
|
||||||
- aux.sx_conv_dfz_dx.step_only_sigma(e.x, delta_hz_x),
|
- aux.sx_conv_dfz_dx.step_only_sigma(e.x(), delta_hz_x),
|
||||||
aux.sx_conv_dfy_dx.step_only_sigma(e.x, delta_hy_x)
|
aux.sx_conv_dfy_dx.step_only_sigma(e.x(), delta_hy_x)
|
||||||
- aux.sy_conv_dfx_dy.step_only_sigma(e.y, delta_hx_y),
|
- aux.sy_conv_dfx_dy.step_only_sigma(e.y(), delta_hx_y),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -275,7 +275,7 @@ impl<F: IntoLib> IntoLib for ffi::IsoConductorOr<F> {
|
|||||||
impl<M: Default> From<IsomorphicConductor<f32>> for IsoConductorOr<M> {
|
impl<M: Default> From<IsomorphicConductor<f32>> for IsoConductorOr<M> {
|
||||||
fn from(m: IsomorphicConductor<f32>) -> Self {
|
fn from(m: IsomorphicConductor<f32>) -> Self {
|
||||||
IsoConductorOr {
|
IsoConductorOr {
|
||||||
value: m.conductivity,
|
value: m.iso_conductivity(),
|
||||||
mat: Default::default(),
|
mat: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1,3 @@
|
|||||||
pub mod real;
|
pub mod real;
|
||||||
|
pub mod vec;
|
||||||
|
pub mod vecu;
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
use crate::real::{Real, ToFloat};
|
use crate::real::{Real, ToFloat};
|
||||||
use super::Vec3u;
|
use super::vecu::Vec3u;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::convert::From;
|
use core::convert::From;
|
||||||
use std::fmt;
|
use core::fmt;
|
||||||
use std::iter::Sum;
|
use core::iter::Sum;
|
||||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub};
|
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Vec2<R=f32> {
|
pub struct Vec2<R=f32> {
|
@@ -1,9 +1,9 @@
|
|||||||
use crate::geom::Vec3;
|
use super::vec::Vec3;
|
||||||
use crate::real::Real;
|
use super::real::Real;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::fmt::{self, Display};
|
use core::fmt::{self, Display};
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
use core::ops::{Add, Div, Mul, Sub};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||||
pub struct Vec3u {
|
pub struct Vec3u {
|
||||||
@@ -29,7 +29,7 @@ impl Vec3u {
|
|||||||
self.z
|
self.z
|
||||||
}
|
}
|
||||||
/// Convert for use with ndarray indexing
|
/// Convert for use with ndarray indexing
|
||||||
pub(crate) fn row_major_idx(&self) -> [usize; 3] {
|
pub fn row_major_idx(&self) -> [usize; 3] {
|
||||||
[self.z as _, self.y as _, self.x as _]
|
[self.z as _, self.y as _, self.x as _]
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user