sparkl3d_core/dynamics/models/
failure_maximum_stress.rs1use crate::math::{Matrix, Real};
2
3#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
4#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
5#[derive(Copy, Clone, Debug, PartialEq)]
6#[repr(C)]
7pub struct MaximumStressFailure {
8 pub max_principal_stress: Real,
9 pub max_shear_stress: Real,
10}
11
12impl MaximumStressFailure {
13 pub fn new(max_principal_stress: Real, max_shear_stress: Real) -> Self {
14 Self {
15 max_principal_stress,
16 max_shear_stress,
17 }
18 }
19
20 pub fn particle_failed(&self, particle_stress: &Matrix<Real>) -> bool {
21 if let Some(eig) = particle_stress.try_symmetric_eigen(1.0e-6, 100) {
22 let min = eig.eigenvalues.min();
23 let max = eig.eigenvalues.max();
24 max > self.max_principal_stress || (max - min) / 2.0 > self.max_shear_stress
25 } else {
26 false
27 }
28 }
29}