Skip to main content

Material

Struct Material 

Source
pub struct Material {
    pub name: String,
    pub relative_permeability: RelativePermeability,
    pub iron_losses: IronLosses,
    pub remanence: VarQuantity<MagneticFluxDensity>,
    pub intrinsic_coercivity: VarQuantity<MagneticFieldStrength>,
    pub electrical_resistivity: VarQuantity<ElectricalResistivity>,
    pub mass_density: VarQuantity<MassDensity>,
    pub heat_capacity: VarQuantity<SpecificHeatCapacity>,
    pub thermal_conductivity: VarQuantity<ThermalConductivity>,
}
Expand description

A substance which constitutes an object, e.g. a magnet or a wire in stem.

This struct is literally just the sum of its parts: It represents a material as a collection of properties such as its mass density, electrical resistivity or heat capacity. Each of its fields can be accessed directly or via its getter and setter methods. Since all fields are defined using the [uom] crate, the type system ensures that the output value is always given in SI units. Every property is thought to be homogeneous (e.g. does not change depending on the orientation of the material) unless explicitly stated otherwise in the field description. All property fields use the VarQuantity enum which can represent the change of properties due to external factors (e.g. the increase of electrical resistivity with temperature).

It is important to note that the material should always return reasonable values for physical properties, otherwise calculations might return non-physical results or even fail completely (for example, returning a negative resistivity would result in negative losses, which would mean that a motor gets colder when its current gets larger). As a general guideline, the property getter function should never return a negative value for any conditions. Since the quantitity functions used in VarQuantity can be arbitrary Rust functions, the stem framework cannot guard against this.

A Material is used as part of motor components within stem. For example, a simple definition of a wire would look like this:

use stem_material::prelude::*;

trait Wire {
    fn resistance(&self, temperature: ThermodynamicTemperature) -> ElectricalResistance;
}

struct RoundWire {
    cross_surface: Area,
    length: Length,
    material: Material,
}

impl Wire for RoundWire {
    fn resistance(&self, temperature: ThermodynamicTemperature) -> ElectricalResistance {
        let resistivity = self.material.electrical_resistivity.get(&[temperature.into()]);
        return self.length * resistivity / self.cross_surface;
    }
}

The Wire trait would then be used inside stem to calculate the resistance, using the wire temperature as a condition input to VarQuantity::get.

Material provides a Default implementation with reasonable defaults for each physical property to allow incremental construction. These default values are also used when a property field is missing during deserialization. It also implements DatabaseEntry which is very useful when maintaining e.g. a database of motors: Commonly used materials such as copper for the wire only need to be defined once and can then be reused across all motors.

Fields§

§name: String

Name of self, e.g. “Copper”

§relative_permeability: RelativePermeability

Relative permeability of self. For vacuum, this value is 1.

Defaults to 1.

§iron_losses: IronLosses

Specific iron losses of self.

Defaults to 0 W/kg.

§remanence: VarQuantity<MagneticFluxDensity>

Remanence of self. This value is usually zero except for permanent magnets. For permanent magnets, this value is expected to be the remance in the magnetization / easy axis.

Defaults to 0 T.

§intrinsic_coercivity: VarQuantity<MagneticFieldStrength>

Intrinsic coercivity of self. This value is usually zero except for permanent magnets. For permanent magnets, this value is expected to be the coercitivity in the magnetization / easy axis.

Defaults to 0 A/m.

§electrical_resistivity: VarQuantity<ElectricalResistivity>

Electrical resistivity of self. For isolators, this value is infinity, for superconductors, it is zero.

Defaults to infinity ohm*meter.

§mass_density: VarQuantity<MassDensity>

Mass density of self.

Defaults to 1000 kg/m³.

§heat_capacity: VarQuantity<SpecificHeatCapacity>

Specific heat capacity of self.

Defaults to 0 J/(kg * K).

§thermal_conductivity: VarQuantity<ThermalConductivity>

Thermal conductivity of self.

Defaults to 0 W/(m * K).

Implementations§

Source§

impl Material

Source

pub fn name(&self) -> &str

Returns the name of self.

Source

pub fn set_name(&mut self, name: String) -> String

Sets a new name for self and returns the old one.

Source

pub fn relative_permeability(&self) -> &RelativePermeability

Returns the relative permeability of self.

Source

pub fn set_relative_permeability( &mut self, property: RelativePermeability, ) -> RelativePermeability

Sets a new relative permeability and returns the old one.

Source

pub fn iron_losses(&self) -> &IronLosses

Returns the specific iron losses of self.

Source

pub fn set_iron_losses(&mut self, property: IronLosses) -> IronLosses

Sets new specific iron losses and returns the old ones.

Source

pub fn remanence(&self) -> &VarQuantity<MagneticFluxDensity>

Returns the remanence of self.

Source

pub fn set_remanence( &mut self, property: VarQuantity<MagneticFluxDensity>, ) -> VarQuantity<MagneticFluxDensity>

Sets a new remanence and returns the old one.

Source

pub fn intrinsic_coercivity(&self) -> &VarQuantity<MagneticFieldStrength>

Returns the intrinsic coercivity of self.

Source

pub fn set_intrinsic_coercivity( &mut self, property: VarQuantity<MagneticFieldStrength>, ) -> VarQuantity<MagneticFieldStrength>

Sets a new intrinsic coercivity and returns the old one.

Source

pub fn electrical_resistivity(&self) -> &VarQuantity<ElectricalResistivity>

Returns the electrical resistivity of self.

Source

pub fn set_electrical_resistivity( &mut self, property: VarQuantity<ElectricalResistivity>, ) -> VarQuantity<ElectricalResistivity>

Sets a new electrical resistivity and returns the old one.

Source

pub fn mass_density(&self) -> &VarQuantity<MassDensity>

Returns the mass density of self.

Source

pub fn set_mass_density( &mut self, property: VarQuantity<MassDensity>, ) -> VarQuantity<MassDensity>

Sets a new mass density and returns the old one.

Source

pub fn heat_capacity(&self) -> &VarQuantity<SpecificHeatCapacity>

Returns the specific heat capacity of self.

Source

pub fn set_heat_capacity( &mut self, property: VarQuantity<SpecificHeatCapacity>, ) -> VarQuantity<SpecificHeatCapacity>

Sets a new specific heat capacity and returns the old one.

Source

pub fn thermal_conductivity(&self) -> &VarQuantity<ThermalConductivity>

Returns the thermal conductivity of self.

Source

pub fn set_thermal_conductivity( &mut self, property: VarQuantity<ThermalConductivity>, ) -> VarQuantity<ThermalConductivity>

Sets a new thermal conductivity and returns the old one.

Trait Implementations§

Source§

impl Clone for Material

Source§

fn clone(&self) -> Material

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DatabaseEntry for Material

Source§

fn name(&self) -> &OsStr

To be uniquely identifiable by a “link”, each DatabaseEntry must provide its own “name”. This name is used both as the link in the serialized representation of the parent struct and also to determine the file name where the actual field contents are stored.
Source§

impl Debug for Material

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Material

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Material

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Material

Source§

fn eq(&self, other: &Material) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Material

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Material

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> SendAlias for T

Source§

impl<T> SyncAlias for T