[−][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 Lattice
[src]
pub fn new(dims: [usize; 2]) -> Self
[src]
Create a new lattice of given dims with randomly generated spins.
pub fn inner(&self) -> ArrayView<i32, Dim<[Ix; 2]>>
[src]
View inner array.
pub fn from_array(array: Array2<i32>) -> Self
[src]
Create a new lattice from provided array.
Examples
let array = Array::from_shape_vec((2, 2), vec![1, -1, 1, -1])?; let lattice = Lattice::from_array(array);
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 lattice = Lattice::from_array(array);
pub fn dims(&self) -> [usize; 2]
[src]
Return lattice's dimensions.
pub fn measure_E_diff<I>(&self, ix: I) -> f64 where
I: NdIndex<Dim<[Ix; 2]>> + Copy,
[src]
I: NdIndex<Dim<[Ix; 2]>> + Copy,
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));
pub fn measure_E_diff_with_h<I>(&self, ix: I, h: &Array2<f64>) -> f64 where
I: NdIndex<Dim<[Ix; 2]>> + Copy,
[src]
I: NdIndex<Dim<[Ix; 2]>> + Copy,
Return the difference of energy that would be caused by
flipping the (ith, jth)
spin in the presence of an external magnetic
field without actually doing it. Used to determine the probability
of a flip.
Lattice: External magnetic field:
##| a|## ##|##|##
-------- --------
b| s| c ##| h|##
-------- --------
##| d|## ##|##|##
E_2 - E_1 =
= ((-J) * (-s) * (a + b + c + d) - h * (-s)) - ((-J) * s * (a + b + c + d) - h * s) =
= ((-s) - s) * (-J) * (a + b + c + d) + ((-s) - s) * (-h) =
= -2 * s * ((-J) * (a + b + c + d) - h) =
= 2 * s * (J * (a + b + c + d) + h)
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));
pub fn measure_E(&self) -> f64
[src]
Return the energy of the lattice.
E = -J * ∑(s_i * s_j)
pub fn measure_E_with_h(&self, h: &Array2<f64>) -> f64
[src]
Return the energy of the lattice in the presence of an external magnetic field.
E = -J * ∑(s_i * s_j) - ∑(s_i * h_i)
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.
I = 1/n * ∑s_i
pub fn flip_spin<I>(&mut self, ix: I) where
I: NdIndex<Dim<[Ix; 2]>> + Copy,
[src]
I: NdIndex<Dim<[Ix; 2]>> + Copy,
pub fn gen_random_index<R: RngCore>(&mut self, rng: &mut R) -> [usize; 2]
[src]
Return a valid, randomly generated spin index.
Auto Trait Implementations
impl Send for Lattice
impl Unpin for Lattice
impl Sync for Lattice
impl UnwindSafe for Lattice
impl RefUnwindSafe for Lattice
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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.
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.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,