[−][src]Struct ising_lib::lattice::Lattice
A struct encapsulating the spin lattice and all the operations performed on it.
The lattice behaves like a torus - spins on opposite edges are considered each other's neighbors.
Methods
impl<R: RngCore> Lattice<R>
[src]
pub fn from_rng(size: (usize, usize), rng: R) -> Self
[src]
Create a new lattice from provided RNG with randomly generated spins.
pub fn from_array_rng(array: Array2<i32>, rng: R) -> Self
[src]
Create a new lattice from provided array and RNG.
Examples
let array = Array::from_shape_vec((2, 2), vec![1, -1, 1, -1])?; let rng = SmallRng::from_entropy(); let lattice = Lattice::from_array_rng(array, rng);
Panics
The function will panic if or if any of the spins has incorrect value
(neither -1
nor 1
).
let array = Array::from_shape_vec((2, 2), vec![5, -1, 1, -1])?; // ↑ incorrect spin value let rng = SmallRng::from_entropy(); let lattice = Lattice::from_array_rng(array, rng);
pub fn dims(&self) -> (usize, usize)
[src]
Return lattice's dimensions.
pub fn measure_E_diff(&self, (i, j): (usize, usize), J: f64) -> f64
[src]
Return the difference of energy that would be caused by
flipping the (ith, jth)
spin without actually doing it.
Used to determine the probability of a flip.
Lattice before flip: Lattice after flip:
##| a|## ##| a|##
-------- --------
b| s| c b|-s| c
-------- --------
##| d|## ##| d|##
E_2 - E_1 =
= ((-J) * (-s) * (a + b + c + d)) - ((-J) * s * (a + b + c + d)) =
= -J * ((-s) - s) * (a + b + c + d) =
= -J * -2 * s * (a + b + c + d) =
= 2 * J * s * (a + b + c + d)
Panics
This function will panic if the index is out of bounds.
let lattice = Lattice::new((10, 10)); let _ = lattice.measure_E_diff((42, 0), 1.0);
pub fn measure_E(&self, J: f64) -> f64
[src]
Return the energy of the lattice.
pub fn measure_I(&self) -> f64
[src]
Return the magnetization of the lattice. The magnetization is
a value in range [0.0, 1.0]
and it is the absolute value of the mean
spin value.
pub fn flip_spin(&mut self, ix: (usize, usize))
[src]
pub fn gen_random_index(&mut self) -> (usize, usize)
[src]
Return a valid, randomly generated spin index.
impl Lattice<SmallRng>
[src]
pub fn new(dims: (usize, usize)) -> Self
[src]
Create a new of certain dimensions with randomly generated
spins. SmallRng
is used as a RNG.
pub fn from_array(array: Array2<i32>) -> Self
[src]
Create a new lattice from provided array of spins.
SmallRng
is used as a RNG.
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,