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: StringName of self, e.g. “Copper”
relative_permeability: RelativePermeabilityRelative permeability of self. For vacuum, this value is 1.
Defaults to 1.
iron_losses: IronLossesSpecific 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
impl Material
Sourcepub fn set_name(&mut self, name: String) -> String
pub fn set_name(&mut self, name: String) -> String
Sets a new name for self and returns the old one.
Sourcepub fn relative_permeability(&self) -> &RelativePermeability
pub fn relative_permeability(&self) -> &RelativePermeability
Returns the relative permeability of self.
Sourcepub fn set_relative_permeability(
&mut self,
property: RelativePermeability,
) -> RelativePermeability
pub fn set_relative_permeability( &mut self, property: RelativePermeability, ) -> RelativePermeability
Sets a new relative permeability and returns the old one.
Sourcepub fn iron_losses(&self) -> &IronLosses
pub fn iron_losses(&self) -> &IronLosses
Returns the specific iron losses of self.
Sourcepub fn set_iron_losses(&mut self, property: IronLosses) -> IronLosses
pub fn set_iron_losses(&mut self, property: IronLosses) -> IronLosses
Sets new specific iron losses and returns the old ones.
Sourcepub fn remanence(&self) -> &VarQuantity<MagneticFluxDensity>
pub fn remanence(&self) -> &VarQuantity<MagneticFluxDensity>
Returns the remanence of self.
Sourcepub fn set_remanence(
&mut self,
property: VarQuantity<MagneticFluxDensity>,
) -> VarQuantity<MagneticFluxDensity>
pub fn set_remanence( &mut self, property: VarQuantity<MagneticFluxDensity>, ) -> VarQuantity<MagneticFluxDensity>
Sets a new remanence and returns the old one.
Sourcepub fn intrinsic_coercivity(&self) -> &VarQuantity<MagneticFieldStrength>
pub fn intrinsic_coercivity(&self) -> &VarQuantity<MagneticFieldStrength>
Returns the intrinsic coercivity of self.
Sourcepub fn set_intrinsic_coercivity(
&mut self,
property: VarQuantity<MagneticFieldStrength>,
) -> VarQuantity<MagneticFieldStrength>
pub fn set_intrinsic_coercivity( &mut self, property: VarQuantity<MagneticFieldStrength>, ) -> VarQuantity<MagneticFieldStrength>
Sets a new intrinsic coercivity and returns the old one.
Sourcepub fn electrical_resistivity(&self) -> &VarQuantity<ElectricalResistivity>
pub fn electrical_resistivity(&self) -> &VarQuantity<ElectricalResistivity>
Returns the electrical resistivity of self.
Sourcepub fn set_electrical_resistivity(
&mut self,
property: VarQuantity<ElectricalResistivity>,
) -> VarQuantity<ElectricalResistivity>
pub fn set_electrical_resistivity( &mut self, property: VarQuantity<ElectricalResistivity>, ) -> VarQuantity<ElectricalResistivity>
Sets a new electrical resistivity and returns the old one.
Sourcepub fn mass_density(&self) -> &VarQuantity<MassDensity>
pub fn mass_density(&self) -> &VarQuantity<MassDensity>
Returns the mass density of self.
Sourcepub fn set_mass_density(
&mut self,
property: VarQuantity<MassDensity>,
) -> VarQuantity<MassDensity>
pub fn set_mass_density( &mut self, property: VarQuantity<MassDensity>, ) -> VarQuantity<MassDensity>
Sets a new mass density and returns the old one.
Sourcepub fn heat_capacity(&self) -> &VarQuantity<SpecificHeatCapacity>
pub fn heat_capacity(&self) -> &VarQuantity<SpecificHeatCapacity>
Returns the specific heat capacity of self.
Sourcepub fn set_heat_capacity(
&mut self,
property: VarQuantity<SpecificHeatCapacity>,
) -> VarQuantity<SpecificHeatCapacity>
pub fn set_heat_capacity( &mut self, property: VarQuantity<SpecificHeatCapacity>, ) -> VarQuantity<SpecificHeatCapacity>
Sets a new specific heat capacity and returns the old one.
Sourcepub fn thermal_conductivity(&self) -> &VarQuantity<ThermalConductivity>
pub fn thermal_conductivity(&self) -> &VarQuantity<ThermalConductivity>
Returns the thermal conductivity of self.
Sourcepub fn set_thermal_conductivity(
&mut self,
property: VarQuantity<ThermalConductivity>,
) -> VarQuantity<ThermalConductivity>
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 DatabaseEntry for Material
impl DatabaseEntry for Material
Source§fn name(&self) -> &OsStr
fn name(&self) -> &OsStr
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.