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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
//! The loop classes for containers or periodic containers.
#[cxx::bridge(namespace = "voro")]
pub mod ffi {
unsafe extern "C++" {
include!("voro_rs/src/boilerplate.hh");
type container = crate::container::ffi::container;
type container_poly =
crate::container::ffi::container_poly;
type particle_order =
crate::particle_marker::ffi::particle_order;
type c_loop_all;
#[rust_name = "new_c_loop_all_0"]
fn construct(
con: Pin<&mut container>,
) -> UniquePtr<c_loop_all>;
#[rust_name = "new_c_loop_all_1"]
fn construct(
con: Pin<&mut container_poly>,
) -> UniquePtr<c_loop_all>;
fn x(self: Pin<&mut c_loop_all>) -> f64;
fn y(self: Pin<&mut c_loop_all>) -> f64;
fn z(self: Pin<&mut c_loop_all>) -> f64;
fn pid(self: Pin<&mut c_loop_all>) -> i32;
fn start(self: Pin<&mut c_loop_all>) -> bool;
fn inc(self: Pin<&mut c_loop_all>) -> bool;
type c_loop_subset;
#[rust_name = "new_c_loop_subset_0"]
fn construct(
con: Pin<&mut container>,
) -> UniquePtr<c_loop_subset>;
#[rust_name = "new_c_loop_subset_1"]
fn construct(
con: Pin<&mut container_poly>,
) -> UniquePtr<c_loop_subset>;
fn x(self: Pin<&mut c_loop_subset>) -> f64;
fn y(self: Pin<&mut c_loop_subset>) -> f64;
fn z(self: Pin<&mut c_loop_subset>) -> f64;
fn pid(self: Pin<&mut c_loop_subset>) -> i32;
fn start(self: Pin<&mut c_loop_subset>) -> bool;
fn inc(self: Pin<&mut c_loop_subset>) -> bool;
fn setup_sphere(
self: Pin<&mut c_loop_subset>,
vx: f64,
vy: f64,
vz: f64,
r: f64,
bounds_test: bool,
);
fn setup_box(
self: Pin<&mut c_loop_subset>,
xmin: f64,
xmax: f64,
ymin: f64,
ymax: f64,
zmin: f64,
zmax: f64,
bounds_test: bool,
);
fn setup_intbox(
self: Pin<&mut c_loop_subset>,
ai_: i32,
bi_: i32,
aj_: i32,
bj_: i32,
ak_: i32,
bk_: i32,
);
type c_loop_order;
#[rust_name = "new_c_loop_order_0"]
fn construct(
con: Pin<&mut container>,
vo: Pin<&mut particle_order>,
) -> UniquePtr<c_loop_order>;
#[rust_name = "new_c_loop_order_1"]
fn construct(
con: Pin<&mut container_poly>,
vo: Pin<&mut particle_order>,
) -> UniquePtr<c_loop_order>;
fn x(self: Pin<&mut c_loop_order>) -> f64;
fn y(self: Pin<&mut c_loop_order>) -> f64;
fn z(self: Pin<&mut c_loop_order>) -> f64;
fn pid(self: Pin<&mut c_loop_order>) -> i32;
fn start(self: Pin<&mut c_loop_order>) -> bool;
fn inc(self: Pin<&mut c_loop_order>) -> bool;
}
}
use crate::{
container::{ContainerRad, ContainerStd},
particle_marker::ParticleMarker,
};
use cxx::UniquePtr;
type DVec3 = [f64; 3];
type IVec3 = [i32; 3];
pub struct LoopAll {
pub(crate) inner: UniquePtr<ffi::c_loop_all>,
}
impl LoopAll {
/// The constructor copies several necessary constants from the
/// base container class.
pub fn of_container_std(
container: &mut ContainerStd,
) -> Self {
Self {
inner: ffi::new_c_loop_all_0(
container.inner.pin_mut(),
),
}
}
/// The constructor copies several necessary constants from the
/// base container class.
pub fn of_container_rad(
container: &mut ContainerRad,
) -> Self {
Self {
inner: ffi::new_c_loop_all_1(
container.inner.pin_mut(),
),
}
}
}
pub struct LoopSubset {
pub(crate) inner: UniquePtr<ffi::c_loop_subset>,
}
impl LoopSubset {
/// The constructor copies several necessary constants from the
/// base container class.
pub fn of_container_std(
container: &mut ContainerStd,
) -> Self {
Self {
inner: ffi::new_c_loop_subset_0(
container.inner.pin_mut(),
),
}
}
/// The constructor copies several necessary constants from the
/// base container class.
pub fn of_container_rad(
container: &mut ContainerRad,
) -> Self {
Self {
inner: ffi::new_c_loop_subset_1(
container.inner.pin_mut(),
),
}
}
/// Setup a `LoopSubset` object to scan over all particles within a
/// given sphere.
///
/// * `v`: the position vector of the center of the sphere.
/// * `r`: the radius of the sphere.
/// * `bounds_test`: whether to do detailed bounds checking. If this is
/// false then the class will loop over all particles in
/// blocks that overlap the given sphere. If it is true,
/// the particle will only loop over the particles which
/// actually lie within the sphere.
pub fn setup_sphere(
&mut self,
v: DVec3,
r: f64,
bounds_test: bool,
) {
self.inner.pin_mut().setup_sphere(
v[0],
v[1],
v[2],
r,
bounds_test,
);
}
/// Setup a `LoopSubset` object to loop over all particles in a rectangular box.
///
/// * `xyz_min`: the minimum coordinates of the box.
/// * `xyz_max`: the maximum coordinates of the box.
/// * `bounds_test`: whether to do detailed bounds checking. If this is
/// false then the class will loop over all particles in
/// blocks that overlap the given box. If it is true, the
/// particle will only loop over the particles which
/// actually lie within the box.
pub fn setup_box(
&mut self,
xyz_min: DVec3,
xyz_max: DVec3,
bounds_test: bool,
) {
self.inner.pin_mut().setup_box(
xyz_min[0],
xyz_max[0],
xyz_min[1],
xyz_max[1],
xyz_min[2],
xyz_max[2],
bounds_test,
);
}
/// Setup a `LoopSubset` object to loop over all particles in a
/// rectangular subgrid of blocks.
///
/// * `a`: the start of sub-grid range.
/// * `b`: the end of sub-grid range.
pub fn setup_grid(&mut self, a: IVec3, b: IVec3) {
self.inner.pin_mut().setup_intbox(
a[0], b[0], a[1], b[1], a[2], b[2],
);
}
}
pub struct LoopMarked {
pub(crate) inner: UniquePtr<ffi::c_loop_order>,
}
impl LoopMarked {
/// The constructor copies several necessary constants from the
/// base container class.
pub fn with_container_std(
container: &mut ContainerStd,
marker: &mut ParticleMarker,
) -> Self {
Self {
inner: ffi::new_c_loop_order_0(
container.inner.pin_mut(),
marker.inner.pin_mut(),
),
}
}
/// The constructor copies several necessary constants from the
/// base container class.
pub fn with_container_rad(
container: &mut ContainerRad,
marker: &mut ParticleMarker,
) -> Self {
Self {
inner: ffi::new_c_loop_order_1(
container.inner.pin_mut(),
marker.inner.pin_mut(),
),
}
}
}
pub trait ContainerLoop {
/// Returns the x position of the particle currently being
/// considered by the loop.
fn x(&mut self) -> f64;
/// Returns the y position of the particle currently being
/// considered by the loop.
fn y(&mut self) -> f64;
/// Returns the z position of the particle currently being
/// considered by the loop.
fn z(&mut self) -> f64;
/// Returns the position vector of the particle currently being
/// considered by the loop.
fn position(&mut self) -> DVec3 {
[self.x(), self.y(), self.z()]
}
/// Returns the ID of the particle currently being considered
/// by the loop.
fn particle_id(&mut self) -> i32;
/// Sets the class to consider the first particle.
///
/// Return true if there is any particle to consider, false
/// otherwise.
fn start(&mut self) -> bool;
/// Finds the next particle to test.
///
/// Return true if there is another particle, false if no more
/// particles are available.
fn inc(&mut self) -> bool;
}
impl ContainerLoop for LoopAll {
fn x(&mut self) -> f64 {
self.inner.pin_mut().x()
}
fn y(&mut self) -> f64 {
self.inner.pin_mut().y()
}
fn z(&mut self) -> f64 {
self.inner.pin_mut().z()
}
fn particle_id(&mut self) -> i32 {
self.inner.pin_mut().pid()
}
fn start(&mut self) -> bool {
self.inner.pin_mut().start()
}
fn inc(&mut self) -> bool {
self.inner.pin_mut().inc()
}
}
impl ContainerLoop for LoopSubset {
fn x(&mut self) -> f64 {
self.inner.pin_mut().x()
}
fn y(&mut self) -> f64 {
self.inner.pin_mut().y()
}
fn z(&mut self) -> f64 {
self.inner.pin_mut().z()
}
fn particle_id(&mut self) -> i32 {
self.inner.pin_mut().pid()
}
fn start(&mut self) -> bool {
self.inner.pin_mut().start()
}
fn inc(&mut self) -> bool {
self.inner.pin_mut().inc()
}
}
impl ContainerLoop for LoopMarked {
fn x(&mut self) -> f64 {
self.inner.pin_mut().x()
}
fn y(&mut self) -> f64 {
self.inner.pin_mut().y()
}
fn z(&mut self) -> f64 {
self.inner.pin_mut().z()
}
fn particle_id(&mut self) -> i32 {
self.inner.pin_mut().pid()
}
fn start(&mut self) -> bool {
self.inner.pin_mut().start()
}
fn inc(&mut self) -> bool {
self.inner.pin_mut().inc()
}
}