1#[cfg(all(feature = "dim2", feature = "f32"))]
2pub extern crate parry2d as parry;
3#[cfg(all(feature = "dim2", feature = "f64"))]
4pub extern crate parry2d_f64 as parry;
5#[cfg(all(feature = "dim3", feature = "f32"))]
6pub extern crate parry3d as parry;
7#[cfg(all(feature = "dim3", feature = "f64"))]
8pub extern crate parry3d_f64 as parry;
9
10#[cfg(all(feature = "dim2", feature = "f32"))]
11pub extern crate rapier2d as rapier;
12#[cfg(all(feature = "dim2", feature = "f64"))]
13pub extern crate rapier2d_f64 as rapier;
14#[cfg(all(feature = "dim3", feature = "f32"))]
15pub extern crate rapier3d as rapier;
16#[cfg(all(feature = "dim3", feature = "f64"))]
17pub extern crate rapier3d_f64 as rapier;
18
19#[cfg(all(feature = "dim2", feature = "rapier-testbed"))]
20extern crate rapier_testbed2d as rapier_testbed;
21#[cfg(all(feature = "dim3", feature = "rapier-testbed"))]
22extern crate rapier_testbed3d as rapier_testbed;
23
24#[cfg(feature = "dim2")]
25pub extern crate sparkl2d_core;
26#[cfg(all(feature = "dim2", feature = "cuda"))]
27pub extern crate sparkl2d_kernels as kernels;
28
29#[cfg(feature = "cuda")]
30pub extern crate cust;
31#[cfg(feature = "dim3")]
32pub extern crate sparkl3d_core;
33#[cfg(all(feature = "dim3", feature = "cuda"))]
34pub extern crate sparkl3d_kernels as kernels;
35
36pub extern crate nalgebra as na;
37
38#[macro_use]
39extern crate log;
40
41#[cfg(feature = "serde")]
42#[macro_use]
43extern crate serde;
44
45#[cfg(feature = "dim2")]
46pub use sparkl2d_core as core;
47#[cfg(feature = "dim3")]
48pub use sparkl3d_core as core;
49
50pub mod prelude {
51 pub use crate::dynamics::models::*;
52 pub use crate::dynamics::solver::*;
53 pub use crate::dynamics::*;
54 pub use crate::geometry::*;
55 pub use crate::math::*;
56}
57
58pub mod math {
59 pub use super::parry::math::*;
60 pub type Kernel = crate::core::dynamics::solver::QuadraticKernel;
61
62 #[derive(Copy, Clone, Debug, PartialEq)]
63 pub struct DecomposedTensor {
64 pub deviatoric_part: Matrix<Real>,
65 pub spherical_part: Real,
66 }
67
68 impl DecomposedTensor {
69 pub fn decompose(tensor: &Matrix<Real>) -> Self {
70 let spherical_part = tensor.trace() / (DIM as Real);
71 let mut deviatoric_part = *tensor;
72
73 for i in 0..DIM {
74 deviatoric_part[(i, i)] -= spherical_part;
75 }
76
77 Self {
78 deviatoric_part,
79 spherical_part,
80 }
81 }
82
83 pub fn zero() -> Self {
84 Self {
85 deviatoric_part: Matrix::zeros(),
86 spherical_part: 0.0,
87 }
88 }
89
90 pub fn recompose(&self) -> Matrix<Real> {
91 self.deviatoric_part + Matrix::identity() * self.spherical_part
92 }
93 }
94
95 impl std::ops::Add<DecomposedTensor> for DecomposedTensor {
96 type Output = DecomposedTensor;
97
98 #[inline]
99 fn add(self, rhs: DecomposedTensor) -> DecomposedTensor {
100 DecomposedTensor {
101 deviatoric_part: self.deviatoric_part + rhs.deviatoric_part,
102 spherical_part: self.spherical_part + rhs.spherical_part,
103 }
104 }
105 }
106
107 impl std::ops::AddAssign<DecomposedTensor> for DecomposedTensor {
108 #[inline]
109 fn add_assign(&mut self, rhs: DecomposedTensor) {
110 self.deviatoric_part += rhs.deviatoric_part;
111 self.spherical_part += rhs.spherical_part;
112 }
113 }
114
115 impl std::ops::Mul<Vector<Real>> for DecomposedTensor {
116 type Output = Vector<Real>;
117
118 #[inline]
119 fn mul(self, rhs: Vector<Real>) -> Self::Output {
120 self.deviatoric_part * rhs + self.spherical_part * rhs
121 }
122 }
123}
124
125#[cfg(feature = "cuda")]
126pub mod cuda;
127pub mod dynamics;
128pub mod geometry;
129pub mod pipelines;
130pub mod third_party;
131pub mod utils;