1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use crate::math::{Matrix, Point, Real, Vector};
use crate::utils::RealStruct;
#[cfg(not(feature = "std"))]
use na::ComplexField;
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticlePosition {
pub point: Point<Real>,
}
unsafe impl RealStruct for ParticlePosition {}
impl ParticlePosition {
pub fn closest_grid_pos(&self, cell_width: Real) -> Point<Real> {
(self.point / cell_width).map(|e| e.round()) * cell_width
}
pub fn associated_cell_index_in_block_off_by_two(&self, cell_width: Real) -> Point<u32> {
(self.point / cell_width).map(|e| {
let assoc_cell = e.round() as i32 - 2;
let assoc_block = (assoc_cell as Real / 4.0).floor() as i32 * 4;
(assoc_cell - assoc_block) as u32 })
}
pub fn associated_grid_pos(&self, cell_width: Real) -> Point<Real> {
((self.point / cell_width).map(|e| e.round()) - Vector::repeat(1.0)) * cell_width
}
pub fn dir_to_closest_grid_node(&self, cell_width: Real) -> Vector<Real> {
self.closest_grid_pos(cell_width) - self.point
}
pub fn dir_to_associated_grid_node(&self, cell_width: Real) -> Vector<Real> {
self.associated_grid_pos(cell_width) - self.point
}
}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticleVelocity {
pub vector: Vector<Real>,
}
unsafe impl RealStruct for ParticleVelocity {}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticleVolume {
pub mass: Real,
pub volume0: Real,
pub radius0: Real,
pub deformation_gradient: Matrix<Real>, pub plastic_deformation_gradient_det: Real, }
unsafe impl RealStruct for ParticleVolume {}
impl Default for ParticleVolume {
fn default() -> Self {
Self {
mass: 0.0,
volume0: 0.0,
radius0: 0.0,
deformation_gradient: Matrix::identity(),
plastic_deformation_gradient_det: 1.0,
}
}
}
impl ParticleVolume {
pub fn density0(&self) -> Real {
self.mass / self.volume0
}
pub fn fluid_deformation_gradient_det(&self) -> Real {
self.deformation_gradient[(0, 0)]
}
pub fn volume_fluid(&self) -> Real {
self.volume0 * self.fluid_deformation_gradient_det()
}
pub fn volume_def_grad(&self) -> Real {
self.volume0 * self.deformation_gradient.determinant()
}
pub fn density_fluid(&self) -> Real {
self.density0() / self.fluid_deformation_gradient_det()
}
pub fn density_def_grad(&self) -> Real {
self.density0() / self.deformation_gradient.determinant()
}
}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticleStatus {
pub failed: bool,
pub is_static: bool,
pub kinematic_vel_enabled: bool,
pub kinematic_vel: Vector<Real>,
pub model_index: usize,
}
impl Default for ParticleStatus {
fn default() -> Self {
Self {
failed: false,
is_static: false,
kinematic_vel_enabled: false,
kinematic_vel: Vector::zeros(),
model_index: 0,
}
}
}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticlePhase {
pub phase: Real,
pub psi_pos: Real,
}
impl Default for ParticlePhase {
fn default() -> Self {
Self {
phase: 1.0,
psi_pos: 0.0,
}
}
}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticleContact {
pub boundary_normal: Vector<Real>,
pub boundary_dist: Real, }
unsafe impl RealStruct for ParticleContact {}
impl Default for ParticleContact {
fn default() -> Self {
Self {
boundary_normal: Vector::zeros(),
boundary_dist: 0.0,
}
}
}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticleFracture {
pub crack_propagation_factor: Real,
pub crack_threshold: Real,
}
unsafe impl RealStruct for ParticleFracture {}
impl Default for ParticleFracture {
fn default() -> Self {
Self {
crack_propagation_factor: 0.0,
crack_threshold: Real::MAX,
}
}
}
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct ParticleData {
pub nacc_alpha: Real,
pub plastic_hardening: Real,
pub elastic_hardening: Real,
pub log_vol_gain: Real,
}
unsafe impl RealStruct for ParticleData {}
impl Default for ParticleData {
fn default() -> Self {
Self {
nacc_alpha: -0.01,
plastic_hardening: 1.0,
elastic_hardening: 1.0,
log_vol_gain: 0.0,
}
}
}