pub struct SpringNetwork { /* private fields */ }Expand description
Sparse undirected collection keyed by particle pairs.
Implementations§
Source§impl SpringNetwork
impl SpringNetwork
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/basic_particle.rs (line 12)
7fn simulate() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8 let mut particles = create_template(2, 2)?;
9 particles.set_attribute_vector(ATTR_R, 0, &[0.25, 0.5])?;
10 particles.set_attribute_vector(ATTR_R, 1, &[0.75, 0.5])?;
11 set_mass(&mut particles, 0, 2.0)?;
12 let mut springs = SpringNetwork::new();
13 springs.insert((0, 1), Spring::new(1.0, 0.4, None)?)?;
14 let boundary = ReflectBox::new(&[0.0, 0.0], &[1.0, 1.0])?;
15 let mut thermostat = LangevinThermostat::new(
16 0.01,
17 0.1,
18 ResolvedRng::new(42, RngMethod::IndexedSplitMix64),
19 ParticleSelection::AliveOnly,
20 )?;
21 let mut integrator = SemiImplicitEuler;
22 for step in 0..20 {
23 // Force modules accumulate acceleration; each step starts from zero.
24 particles.attribute_mut::<f64>(ATTR_A)?.fill(0.0);
25 springs.apply(&mut particles, ParticleSelection::AliveOnly)?;
26 integrator.apply(&mut particles, 0.01)?;
27 boundary.apply_to_particles(&mut particles)?;
28 thermostat.apply(&mut particles, 0.01)?;
29 if (step + 1) % 10 == 0 {
30 let summary = kinetic_summary(&particles, ParticleSelection::AliveOnly)?;
31 println!(
32 "step {}: KE={}, temperature={}",
33 step + 1,
34 summary.energy,
35 summary.temperature
36 );
37 }
38 }
39 Ok(())
40}Sourcepub fn with_capacity(edge_capacity: usize) -> Self
pub fn with_capacity(edge_capacity: usize) -> Self
Reserves edge storage without imposing a particle count.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn minimum_particle_count(&self) -> usize
pub fn minimum_particle_count(&self) -> usize
Smallest particle count capable of containing every current endpoint.
Sourcepub fn insert(
&mut self,
pair: (usize, usize),
law: Spring,
) -> Result<Option<Spring>, SpringNetworkError>
pub fn insert( &mut self, pair: (usize, usize), law: Spring, ) -> Result<Option<Spring>, SpringNetworkError>
Inserts or replaces one pair after validating the complete request.
Examples found in repository?
examples/basic_particle.rs (line 13)
7fn simulate() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8 let mut particles = create_template(2, 2)?;
9 particles.set_attribute_vector(ATTR_R, 0, &[0.25, 0.5])?;
10 particles.set_attribute_vector(ATTR_R, 1, &[0.75, 0.5])?;
11 set_mass(&mut particles, 0, 2.0)?;
12 let mut springs = SpringNetwork::new();
13 springs.insert((0, 1), Spring::new(1.0, 0.4, None)?)?;
14 let boundary = ReflectBox::new(&[0.0, 0.0], &[1.0, 1.0])?;
15 let mut thermostat = LangevinThermostat::new(
16 0.01,
17 0.1,
18 ResolvedRng::new(42, RngMethod::IndexedSplitMix64),
19 ParticleSelection::AliveOnly,
20 )?;
21 let mut integrator = SemiImplicitEuler;
22 for step in 0..20 {
23 // Force modules accumulate acceleration; each step starts from zero.
24 particles.attribute_mut::<f64>(ATTR_A)?.fill(0.0);
25 springs.apply(&mut particles, ParticleSelection::AliveOnly)?;
26 integrator.apply(&mut particles, 0.01)?;
27 boundary.apply_to_particles(&mut particles)?;
28 thermostat.apply(&mut particles, 0.01)?;
29 if (step + 1) % 10 == 0 {
30 let summary = kinetic_summary(&particles, ParticleSelection::AliveOnly)?;
31 println!(
32 "step {}: KE={}, temperature={}",
33 step + 1,
34 summary.energy,
35 summary.temperature
36 );
37 }
38 }
39 Ok(())
40}Sourcepub fn insert_many(
&mut self,
entries: impl IntoIterator<Item = ((usize, usize), Spring)>,
) -> Result<(), SpringNetworkError>
pub fn insert_many( &mut self, entries: impl IntoIterator<Item = ((usize, usize), Spring)>, ) -> Result<(), SpringNetworkError>
Applies a batch atomically. Duplicate pairs in the batch are rejected.
pub fn get(&self, pair: (usize, usize)) -> Option<&Spring>
pub fn remove( &mut self, pair: (usize, usize), ) -> Result<Option<Spring>, SpringNetworkError>
pub fn iter(&self) -> impl Iterator<Item = ((usize, usize), &Spring)> + '_
pub fn clear(&mut self)
Sourcepub fn apply(
&self,
objects: &mut PhysObj,
selection: ParticleSelection,
) -> Result<(), SpringNetworkError>
pub fn apply( &self, objects: &mut PhysObj, selection: ParticleSelection, ) -> Result<(), SpringNetworkError>
Adds Hooke-law acceleration contributions to canonical particle state. Accumulates contributions directly in stable edge-slot order after validating all endpoints and inverse masses. Dense state needs no full scratch. Adding each edge to existing acceleration can round differently from summing a temporary contribution column first. Shared destinations are updated serially; no per-worker full-system buffers are allocated.
Examples found in repository?
examples/basic_particle.rs (line 25)
7fn simulate() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8 let mut particles = create_template(2, 2)?;
9 particles.set_attribute_vector(ATTR_R, 0, &[0.25, 0.5])?;
10 particles.set_attribute_vector(ATTR_R, 1, &[0.75, 0.5])?;
11 set_mass(&mut particles, 0, 2.0)?;
12 let mut springs = SpringNetwork::new();
13 springs.insert((0, 1), Spring::new(1.0, 0.4, None)?)?;
14 let boundary = ReflectBox::new(&[0.0, 0.0], &[1.0, 1.0])?;
15 let mut thermostat = LangevinThermostat::new(
16 0.01,
17 0.1,
18 ResolvedRng::new(42, RngMethod::IndexedSplitMix64),
19 ParticleSelection::AliveOnly,
20 )?;
21 let mut integrator = SemiImplicitEuler;
22 for step in 0..20 {
23 // Force modules accumulate acceleration; each step starts from zero.
24 particles.attribute_mut::<f64>(ATTR_A)?.fill(0.0);
25 springs.apply(&mut particles, ParticleSelection::AliveOnly)?;
26 integrator.apply(&mut particles, 0.01)?;
27 boundary.apply_to_particles(&mut particles)?;
28 thermostat.apply(&mut particles, 0.01)?;
29 if (step + 1) % 10 == 0 {
30 let summary = kinetic_summary(&particles, ParticleSelection::AliveOnly)?;
31 println!(
32 "step {}: KE={}, temperature={}",
33 step + 1,
34 summary.energy,
35 summary.temperature
36 );
37 }
38 }
39 Ok(())
40}Trait Implementations§
Source§impl Clone for SpringNetwork
impl Clone for SpringNetwork
Source§fn clone(&self) -> SpringNetwork
fn clone(&self) -> SpringNetwork
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpringNetwork
impl Debug for SpringNetwork
Source§impl Default for SpringNetwork
impl Default for SpringNetwork
Source§impl<'de> Deserialize<'de> for SpringNetwork
impl<'de> Deserialize<'de> for SpringNetwork
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SpringNetwork
impl RefUnwindSafe for SpringNetwork
impl Send for SpringNetwork
impl Sync for SpringNetwork
impl Unpin for SpringNetwork
impl UnsafeUnpin for SpringNetwork
impl UnwindSafe for SpringNetwork
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more