Skip to main content

use_elasticity_basic_usage/
basic_usage.rs

1use use_elasticity::{
2    ElasticBar, ElasticMaterial, axial_deformation, elastic_energy_density, normal_stress,
3};
4
5fn main() {
6    let Some(material) = ElasticMaterial::with_poisson_ratio(260.0, 0.3) else {
7        panic!("expected valid ElasticMaterial");
8    };
9    let Some(bar) = ElasticBar::new(10.0, 2.0, 1_000.0) else {
10        panic!("expected valid ElasticBar");
11    };
12
13    assert_eq!(normal_stress(100.0, 2.0), Some(50.0));
14    assert_eq!(axial_deformation(100.0, 10.0, 2.0, 1_000.0), Some(0.5));
15    assert_eq!(bar.deformation_under_force(100.0), Some(0.5));
16    assert!(matches!(material.shear_modulus(), Some(value) if (value - 100.0).abs() < 1.0e-12));
17    assert_eq!(elastic_energy_density(100.0, 0.01), Some(0.5));
18}