#![cfg_attr(feature = "doc-images", doc = "")]
#![cfg_attr(
feature = "doc-images",
doc = "![Plain linear and rotary core][lin_and_rot_core_plain.svg]"
)]
#![cfg_attr(feature = "doc-images",
cfg_attr(all(),
doc = ::embed_doc_image::embed_image!("lin_and_rot_core_plain.svg", "docs/img/lin_and_rot_core_plain.svg"),
))]
#![cfg_attr(
not(feature = "doc-images"),
doc = "**Doc images not enabled**. Compile docs with `cargo doc --features 'doc-images'` and Rust version >= 1.54."
)]
use std::f64::consts::PI;
use crate::{
magnets::{surface_magnet_assembly_shapes_lin, surface_magnet_assembly_shapes_rot},
planar_geo,
};
use compare_variables::compare_variables;
use stem_magnet::assembly::MagnetAssembly;
use stem_slot::{
prelude::stem_material::prelude::*,
stem_types::{CoilLayout, SpatialOrder},
};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use planar_geo::prelude::*;
use crate::{
air_gap::AirGap,
core::{CoreExt, CoreRef},
error::Error,
magnets::{Magnets, MagnetsPeriodic},
winding_zones::{WindingZones, WindingZonesPeriodic},
};
#[cfg(feature = "serde")]
fn deserialize_winding_coverage<'de, D>(deserializer: D) -> Result<f64, D::Error>
where
D: serde::Deserializer<'de>,
{
let value = f64::deserialize(deserializer)?;
Ok(value.clamp(0.0, 1.0))
}
#[doc = ""]
#[cfg_attr(
feature = "doc-images",
doc = "![Linear and rotary core with a plain air gap][lin_and_rot_core_plain]"
)]
#[cfg_attr(
feature = "doc-images",
embed_doc_image::embed_doc_image(
"lin_and_rot_core_plain",
"docs/img/lin_and_rot_core_plain.svg"
)
)]
#[cfg_attr(
not(feature = "doc-images"),
doc = "**Doc images not enabled**. Compile docs with
`cargo doc --features 'doc-images'` and Rust version >= 1.54."
)]
#[doc = ""]
#[cfg_attr(
feature = "doc-images",
doc = "![Plain air gap with surface winding and magnets][magnets_and_winding_plain]"
)]
#[cfg_attr(
feature = "doc-images",
embed_doc_image::embed_doc_image(
"magnets_and_winding_plain",
"docs/img/magnets_and_winding_plain.svg"
)
)]
#[cfg_attr(
not(feature = "doc-images"),
doc = "**Doc images not enabled**. Compile docs with
`cargo doc --features 'doc-images'` and Rust version >= 1.54."
)]
#[doc = ""]
#[cfg_attr(
feature = "doc-images",
doc = "![Air gap winding dimensions][cad_plain_air_gap_winding]"
)]
#[cfg_attr(
feature = "doc-images",
embed_doc_image::embed_doc_image(
"cad_plain_air_gap_winding",
"docs/img/cad_plain_air_gap_winding.svg"
)
)]
#[cfg_attr(
not(feature = "doc-images"),
doc = "**Doc images not enabled**. Compile docs with
`cargo doc --features 'doc-images'` and Rust version >= 1.54."
)]
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PlainAirGap {
#[cfg_attr(feature = "serde", serde(default = "usize::default"))]
pub num_segments: usize,
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_quantity"))]
#[cfg_attr(
feature = "serde",
serde(
deserialize_with = "super::deserialize_nonnegative_length",
default = "super::zero_length"
)
)]
pub air_gap_winding_height: Length,
#[cfg_attr(
feature = "serde",
serde(
deserialize_with = "deserialize_winding_coverage",
default = "Default::default"
)
)]
pub winding_coverage: f64,
#[cfg_attr(feature = "serde", serde(default = "bool::default"))]
pub starts_in_slot_middle: bool,
#[cfg_attr(feature = "serde", serde(default = "u16::default"))]
pub slots: u16,
}
impl PlainAirGap {
pub fn with_num_segments(num_segments: usize) -> Self {
Self {
air_gap_winding_height: Length::new::<meter>(0.0),
winding_coverage: 0.0,
num_segments,
slots: 0,
starts_in_slot_middle: true,
}
}
}
#[cfg_attr(feature = "serde", typetag::serde)]
impl AirGap for PlainAirGap {
fn num_segments(&self, _: CoreRef<'_>) -> usize {
return self.num_segments;
}
fn winding_zones(&self, core: CoreRef<'_>, coil_layout: &CoilLayout) -> WindingZones {
match core {
CoreRef::Lin(lin) => WindingZonesPeriodic::<Contour, true>::from_air_gap_winding(
lin.air_gap_length(),
lin.slots(),
self.air_gap_winding_height,
self.winding_coverage,
coil_layout,
self.starts_in_slot_middle,
true,
)
.into(),
CoreRef::Rot(rot) => WindingZonesPeriodic::<Contour, false>::from_air_gap_winding(
rot.air_gap_length(),
rot.slots(),
self.air_gap_winding_height,
self.winding_coverage,
coil_layout,
self.starts_in_slot_middle,
rot.is_outer(),
)
.into(),
}
}
fn slots(&self, _: CoreRef<'_>) -> u16 {
let m = u16::from(
self.air_gap_winding_height > super::zero_length() && self.winding_coverage > 0.0,
);
return m * self.slots;
}
fn surface_magnets(
&self,
core: CoreRef<'_>,
magnet_assembly: &MagnetAssembly,
split: bool,
) -> Magnets {
match core {
CoreRef::Lin(_) => {
let magnets = surface_magnet_assembly_shapes_lin(magnet_assembly, split, None);
MagnetsPeriodic::<true>::new(
core.air_gap_length(),
magnets,
core.poles().get().into(),
core.d_axis_offset(),
)
.into()
}
CoreRef::Rot(core_rot) => {
let magnets = surface_magnet_assembly_shapes_rot(
magnet_assembly,
split,
core_rot.air_gap_radius(),
core_rot.is_outer(),
None,
);
MagnetsPeriodic::<false>::new(
core.air_gap_length(),
magnets,
core.poles().get().into(),
core.d_axis_offset(),
)
.into()
}
}
}
fn combine(&mut self, core: CoreRef<'_>) -> Result<Shape, Error> {
let zero_length = super::zero_length();
compare_variables!(self.air_gap_winding_height >= zero_length)?;
let shape = match core {
CoreRef::Lin(core) => {
let contour = Contour::rectangle(
[0.0, 0.0],
[core.width().get::<meter>(), core.height().get::<meter>()],
);
Shape::new(vec![contour])?
}
CoreRef::Rot(core) => {
if core.is_outer() {
let air_gap_radius = core.air_gap_radius();
compare_variables!(self.air_gap_winding_height <= air_gap_radius)?;
}
let air_gap = ArcSegment::from_center_radius_start_sweep_angle(
[0.0, 0.0],
core.air_gap_radius().get::<meter>(),
0.0,
2.0_f64 * PI,
)?
.into();
let yoke = ArcSegment::from_center_radius_start_sweep_angle(
[0.0, 0.0],
core.yoke_radius().get::<meter>(),
0.0,
2.0_f64 * PI,
)?
.into();
super::combine_air_gap_and_yoke_to_shape(air_gap, yoke, core.is_outer())?
}
};
self.winding_coverage = self.winding_coverage.clamp(0.0, 1.0);
return Ok(shape);
}
fn slot_opening_factor(&self, core: CoreRef<'_>, spatial_order: SpatialOrder) -> f64 {
let slot_pitch = core.slot_pitch();
return super::slot_opening_factor(
slot_pitch,
slot_pitch * self.winding_coverage,
self.slots,
core.pole_pairs(),
spatial_order,
);
}
fn carter_factor(&self, _core: CoreRef<'_>, _geometrical_air_gap: Length) -> f64 {
return 1.0;
}
fn slot(&self, _core: CoreRef<'_>) -> Option<&dyn stem_slot::slot::Slot> {
return None;
}
fn slot_middle_offset(&self, core: CoreRef<'_>) -> f64 {
if self.starts_in_slot_middle {
0.0
} else {
f64::from(core.pole_pairs().get()) * PI / f64::from(self.slots(core))
}
}
}