[−]Struct lumol::Composition
The system composition contains the number of particles of each kind in the system, as well as the number of molecules of each molecule type.
Implementations
impl Composition
pub fn new() -> Composition
Create a new empty composition
Examples
let composition = Composition::new(); // no particles assert_eq!(composition.all_particles().count(), 0); // no molecules assert_eq!(composition.all_molecules().count(), 0);
pub fn add_particle(&mut self, kind: ParticleKind)
Add a particle with the given kind
to the internal counter
Examples
let mut composition = Composition::new(); composition.add_particle(ParticleKind(3)); composition.add_particle(ParticleKind(3)); assert_eq!(composition.particles(ParticleKind(3)), 2);
pub fn remove_particle(&mut self, kind: ParticleKind)
Remove a particle with the given kind
to the internal counter
Examples
let mut composition = Composition::new(); composition.add_particle(ParticleKind(3)); composition.add_particle(ParticleKind(3)); assert_eq!(composition.particles(ParticleKind(3)), 2); composition.remove_particle(ParticleKind(3)); assert_eq!(composition.particles(ParticleKind(3)), 1);
pub fn particles(&self, kind: ParticleKind) -> usize
Get the number of particles with a given kind
Examples
let mut composition = Composition::new(); assert_eq!(composition.particles(ParticleKind(3)), 0); composition.add_particle(ParticleKind(3)); composition.add_particle(ParticleKind(3)); assert_eq!(composition.particles(ParticleKind(3)), 2);
pub fn all_particles(
&'a self
) -> impl Iterator<Item = (ParticleKind, usize)> + 'a
&'a self
) -> impl Iterator<Item = (ParticleKind, usize)> + 'a
Get an iterator over the particles kind and count
Examples
let mut composition = Composition::new(); composition.add_particle(ParticleKind(10)); composition.add_particle(ParticleKind(4)); composition.add_particle(ParticleKind(4)); let mut iter = composition.all_particles(); assert_eq!(iter.next(), Some((ParticleKind(4), 2))); assert_eq!(iter.next(), Some((ParticleKind(10), 1))); assert_eq!(iter.next(), None);
pub fn add_molecule(&mut self, hash: MoleculeHash)
Add a molecule with the given moltype
to the internal counter
Examples
// Getting a molecule hash let he = Molecule::new(Particle::new("He")).hash(); let mut composition = Composition::new(); assert_eq!(composition.molecules(he), 0); composition.add_molecule(he); composition.add_molecule(he); assert_eq!(composition.molecules(he), 2);
pub fn remove_molecule(&mut self, hash: MoleculeHash)
Add a molecule with the given moltype
to the internal counter
Examples
// Getting a molecule hash let he = Molecule::new(Particle::new("He")).hash(); let mut composition = Composition::new(); assert_eq!(composition.molecules(he), 0); composition.add_molecule(he); composition.add_molecule(he); assert_eq!(composition.molecules(he), 2); composition.remove_molecule(he); assert_eq!(composition.molecules(he), 1);
pub fn molecules(&self, hash: MoleculeHash) -> usize
Get the number of particles with the given hash
Examples
// Getting some molecules hashes let he = Molecule::new(Particle::new("He")).hash(); let ar = Molecule::new(Particle::new("Ar")).hash(); let mut n2 = Molecule::new(Particle::new("N")); n2.add_particle_bonded_to(0, Particle::new("N")); let n2 = n2.hash(); let mut composition = Composition::new(); composition.add_molecule(he); composition.add_molecule(he); composition.add_molecule(n2); assert_eq!(composition.molecules(he), 2); assert_eq!(composition.molecules(n2), 1); assert_eq!(composition.molecules(ar), 0);
pub fn all_molecules(
&'a self
) -> impl Iterator<Item = (MoleculeHash, usize)> + 'a
&'a self
) -> impl Iterator<Item = (MoleculeHash, usize)> + 'a
Get an iterator over the molecules hashes and count
Examples
let mut composition = Composition::new(); let he = Molecule::new(Particle::new("He")).hash(); let ar = Molecule::new(Particle::new("Ar")).hash(); composition.add_molecule(he); composition.add_molecule(he); composition.add_molecule(ar); let mut iter = composition.all_molecules(); assert_eq!(iter.next(), Some((he, 2))); assert_eq!(iter.next(), Some((ar, 1))); assert_eq!(iter.next(), None);
Trait Implementations
impl Clone for Composition
pub fn clone(&self) -> Composition
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Composition
impl Eq for Composition
impl PartialEq<Composition> for Composition
pub fn eq(&self, other: &Composition) -> bool
pub fn ne(&self, other: &Composition) -> bool
impl StructuralEq for Composition
impl StructuralPartialEq for Composition
Auto Trait Implementations
impl RefUnwindSafe for Composition
impl Send for Composition
impl Sync for Composition
impl Unpin for Composition
impl UnwindSafe for Composition
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,