Add simul-lattice crate for discrete space simulations
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -2923,6 +2923,7 @@ dependencies = [
|
||||
"rand 0.9.2",
|
||||
"simul-core",
|
||||
"simul-euclidean",
|
||||
"simul-lattice",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2957,6 +2958,17 @@ dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simul-lattice"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"nalgebra",
|
||||
"rand 0.9.2",
|
||||
"rand_distr",
|
||||
"simul-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
|
||||
@@ -4,7 +4,7 @@ members = [
|
||||
"simul-core",
|
||||
"simul-euclidean",
|
||||
"simul-io",
|
||||
"simul",
|
||||
"simul", "simul-lattice",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
@@ -30,4 +30,5 @@ approx = "0.5"
|
||||
# Internal crates
|
||||
simul-core = { path = "simul-core" }
|
||||
simul-euclidean = { path = "simul-euclidean" }
|
||||
simul-io = { path = "simul-io" }
|
||||
simul-io = { path = "simul-io" }
|
||||
simul-lattice = { path = "simul-lattice" }
|
||||
|
||||
16
simul-lattice/Cargo.toml
Normal file
16
simul-lattice/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "simul-lattice"
|
||||
description = "Lattice space simulations (MD, Brownian, Langevin) for the simul framework"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
simul-core = { workspace = true }
|
||||
nalgebra = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
rand_distr = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
approx = { workspace = true }
|
||||
nalgebra = { workspace = true }
|
||||
1
simul-lattice/src/dynamics/mod.rs
Normal file
1
simul-lattice/src/dynamics/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
10
simul-lattice/src/lib.rs
Normal file
10
simul-lattice/src/lib.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
//! simul-lattice: Discrete space simulations
|
||||
//!
|
||||
//! This crate provides implementations for simulations in discrete space:
|
||||
//! - Molecular dynamics (Verlet integrator)
|
||||
//! - Langevin dynamics (stochastic)
|
||||
//! - Brownian dynamics (overdamped)
|
||||
|
||||
pub mod dynamics;
|
||||
pub mod prelude;
|
||||
pub mod space;
|
||||
1
simul-lattice/src/prelude.rs
Normal file
1
simul-lattice/src/prelude.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
60
simul-lattice/src/space.rs
Normal file
60
simul-lattice/src/space.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
//! Lattice space implementation
|
||||
|
||||
use nalgebra::SVector;
|
||||
use simul_core::space::StateSpace;
|
||||
|
||||
/// D-dimensional Lattice space
|
||||
///
|
||||
/// This is the standard discrete space for molecular dynamics and Brownian motion.
|
||||
/// Points are represented as D-dimensional vectors of i32.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Lattice<const D: usize>;
|
||||
|
||||
impl<const D: usize> StateSpace for Lattice<D> {
|
||||
const DIM: usize = D;
|
||||
|
||||
type Point = SVector<i32, D>;
|
||||
type Momentum = SVector<i32, D>;
|
||||
|
||||
fn is_continuous() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn name() -> &'static str {
|
||||
match D {
|
||||
1 => "Lattice 1D",
|
||||
2 => "Lattice 2D",
|
||||
3 => "Lattice 3D",
|
||||
_ => "Lattice ND",
|
||||
}
|
||||
}
|
||||
|
||||
fn zero_point() -> Self::Point {
|
||||
SVector::zeros()
|
||||
}
|
||||
|
||||
fn zero_momentum() -> Self::Momentum {
|
||||
SVector::zeros()
|
||||
}
|
||||
}
|
||||
|
||||
/// Type alias for 1D Lattice space
|
||||
pub type Space1D = Lattice<1>;
|
||||
|
||||
/// Type alias for 2D Lattice space
|
||||
pub type Space2D = Lattice<2>;
|
||||
|
||||
/// Type alias for 3D Lattice space
|
||||
pub type Space3D = Lattice<3>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_lattice_3d() {
|
||||
assert_eq!(Lattice::<3>::DIM, 3);
|
||||
assert!(!Lattice::<3>::is_continuous());
|
||||
assert_eq!(Lattice::<3>::name(), "Lattice 3D");
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,15 @@ license.workspace = true
|
||||
[features]
|
||||
default = ["euclidean"]
|
||||
euclidean = ["simul-euclidean"]
|
||||
# lattice = ["simul-lattice"] # Future
|
||||
lattice = ["simul-lattice"]
|
||||
|
||||
[dependencies]
|
||||
simul-core = { workspace = true }
|
||||
simul-euclidean = { workspace = true, optional = true }
|
||||
simul-lattice = { workspace = true, optional = true }
|
||||
nalgebra = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
# simul-lattice = { workspace = true, optional = true } # Future
|
||||
|
||||
|
||||
[[example]]
|
||||
name = "hello_argon"
|
||||
|
||||
@@ -27,6 +27,10 @@ pub use simul_core as core;
|
||||
#[cfg(feature = "euclidean")]
|
||||
pub use simul_euclidean as euclidean;
|
||||
|
||||
// Re-export lattice (when feature enabled)
|
||||
#[cfg(feature = "lattice")]
|
||||
pub use simul_lattice as lattice;
|
||||
|
||||
pub mod prelude {
|
||||
//! Convenient re-exports for common use
|
||||
//!
|
||||
@@ -43,4 +47,8 @@ pub mod prelude {
|
||||
// Euclidean types (when enabled)
|
||||
#[cfg(feature = "euclidean")]
|
||||
pub use simul_euclidean::prelude::*;
|
||||
|
||||
// Lattice types (when enabled)
|
||||
#[cfg(feature = "lattice")]
|
||||
pub use simul_lattice::prelude::*;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user