spin_sim/lib.rs
1//! Pure-Rust Ising model Monte Carlo on periodic Bravais lattices.
2//!
3//! # Algorithms
4//!
5//! | Move | Function |
6//! |------|----------|
7//! | Metropolis / Gibbs sweep | [`run_sweep_loop`] (`sweep_mode`) |
8//! | Wolff / Swendsen-Wang | [`run_sweep_loop`] (`cluster_mode`) |
9//! | Parallel tempering | [`run_sweep_loop`] (`pt_interval`) |
10//! | Houdayer / Jörg / CMR | [`run_sweep_loop`] (`houdayer_interval`, `houdayer_mode`) |
11//!
12//! Replicas are parallelized over threads with [`rayon`].
13//!
14//! # Quick start
15//!
16//! ```
17//! use spin_sim::{Lattice, Realization, run_sweep_loop};
18//!
19//! let lattice = Lattice::new(vec![16, 16]);
20//! let n_spins = lattice.n_spins;
21//! let n_neighbors = lattice.n_neighbors;
22//! let temps = vec![2.0, 2.27, 2.5];
23//!
24//! // Uniform ferromagnetic couplings
25//! let couplings = vec![1.0f32; n_spins * n_neighbors];
26//! let mut real = Realization::new(&lattice, couplings, &temps, 2, 42);
27//!
28//! let result = run_sweep_loop(
29//! &lattice, &mut real,
30//! 2, temps.len(),
31//! 5000, 1000,
32//! "metropolis",
33//! Some(1), "wolff",
34//! Some(1), None, "houdayer",
35//! false,
36//! &|| {},
37//! );
38//! ```
39//!
40//! For a Python interface, see the [`peapods`](https://pypi.org/project/peapods/) package.
41
42pub mod geometry;
43pub mod simulation;
44pub mod spins;
45pub mod statistics;
46
47mod clusters;
48mod mcmc;
49mod parallel;
50
51pub use geometry::Lattice;
52pub use simulation::{run_sweep_loop, Realization};
53pub use statistics::SweepResult;