use crate::Real;
use nalgebra::{Scalar, Vector3};
use std::cell::RefCell;
use std::fmt;
use std::fmt::Debug;
use thread_local::ThreadLocal;
#[derive(Default)]
pub struct ReconstructionWorkspace<R: Scalar + Send> {
filtered_particles: Vec<Vector3<R>>,
local_workspaces: ThreadLocal<RefCell<LocalReconstructionWorkspace<R>>>,
}
impl<R: Real> ReconstructionWorkspace<R> {
pub(crate) fn filtered_particles_mut(&mut self) -> &mut Vec<Vector3<R>> {
&mut self.filtered_particles
}
pub(crate) fn get_local_with_capacity(
&self,
capacity: usize,
) -> &RefCell<LocalReconstructionWorkspace<R>> {
self.local_workspaces
.get_or(|| RefCell::new(LocalReconstructionWorkspace::with_capacity(capacity)))
}
}
impl<R: Scalar + Send + Default> Clone for ReconstructionWorkspace<R> {
fn clone(&self) -> Self {
ReconstructionWorkspace::default()
}
}
impl<R: Scalar + Send> Debug for ReconstructionWorkspace<R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ReconstructionWorkspace").finish()
}
}
pub(crate) struct LocalReconstructionWorkspace<R: Scalar> {
pub particle_neighbor_lists: Vec<Vec<usize>>,
pub particle_densities: Vec<R>,
}
impl<R: Real> Default for LocalReconstructionWorkspace<R> {
fn default() -> Self {
Self::new()
}
}
impl<R: Real> LocalReconstructionWorkspace<R> {
pub(crate) fn new() -> Self {
Self {
particle_neighbor_lists: Default::default(),
particle_densities: Default::default(),
}
}
pub(crate) fn with_capacity(capacity: usize) -> Self {
Self {
particle_neighbor_lists: Vec::with_capacity(capacity),
particle_densities: Vec::with_capacity(capacity),
}
}
}