unitforge/quantities/
stress.rs

1use crate::impl_macros::macros::*;
2use crate::prelude::*;
3use crate::quantities::*;
4use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
5use num_traits::identities::Zero;
6use num_traits::FromPrimitive;
7use std::cmp::Ordering;
8use std::fmt;
9use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
10
11#[derive(Copy, Clone, PartialEq)]
12pub enum StressUnit {
13    Pa,
14    kPa,
15    bar,
16    MPa,
17    GPa,
18}
19
20impl PhysicsUnit for StressUnit {
21    fn name(&self) -> &str {
22        match &self {
23            StressUnit::Pa => "Pa",
24            StressUnit::kPa => "kPa",
25            StressUnit::bar => "bar",
26            StressUnit::MPa => "MPa",
27            StressUnit::GPa => "GPa",
28        }
29    }
30
31    fn base_per_x(&self) -> (f64, i32) {
32        match self {
33            StressUnit::Pa => (1., 0),
34            StressUnit::kPa => (1., 3),
35            StressUnit::MPa => (1., 6),
36            StressUnit::bar => (1., 5),
37            StressUnit::GPa => (1., 9),
38        }
39    }
40}
41
42impl_quantity!(Stress, StressUnit, StressUnit::MPa);
43impl_div_with_self_to_f64!(Stress);
44impl_mul_with_self!(Stress, StressSquared);
45impl_div!(Stress, Strain, Stress);
46impl_mul!(Stress, Strain, Stress);
47impl_mul!(Stress, AreaOfMoment, ForceArea);