rusty_kernel_tools/
particle_container.rs1use crate::RealType;
5use ndarray::{Array2, ArrayView2};
6
7pub trait ParticleContainerAccessor {
10 type FloatingPointType: RealType;
11
12 fn sources(&self) -> ArrayView2<Self::FloatingPointType>;
14 fn targets(&self) -> ArrayView2<Self::FloatingPointType>;
16}
17
18pub struct ParticleContainer<T: RealType> {
20 sources: Array2<T>,
21 targets: Array2<T>,
22}
23
24pub fn make_particle_container_owned<T: RealType>(
26 sources: Array2<T>,
27 targets: Array2<T>,
28) -> ParticleContainer<T> {
29 ParticleContainer { sources, targets }
30}
31
32pub fn make_particle_container<'a, T: RealType>(
34 sources: ArrayView2<'a, T>,
35 targets: ArrayView2<'a, T>,
36) -> ParticleContainerView<'a, T> {
37 ParticleContainerView { sources, targets }
38}
39
40pub struct ParticleContainerView<'a, T: RealType> {
42 sources: ArrayView2<'a, T>,
43 targets: ArrayView2<'a, T>,
44}
45
46impl<T: RealType> ParticleContainerAccessor for ParticleContainer<T> {
47 type FloatingPointType = T;
48
49 fn sources(&self) -> ArrayView2<Self::FloatingPointType> {
51 self.sources.view()
52 }
53
54 fn targets(&self) -> ArrayView2<Self::FloatingPointType> {
56 self.targets.view()
57 }
58}
59
60impl<'a, T: RealType> ParticleContainerAccessor for ParticleContainerView<'a, T> {
61 type FloatingPointType = T;
62
63 fn sources(&self) -> ArrayView2<Self::FloatingPointType> {
65 self.sources.view()
66 }
67
68 fn targets(&self) -> ArrayView2<Self::FloatingPointType> {
70 self.targets.view()
71 }
72}