Skip to main content

hoomd_md/thermostat/
no_thermostat.rs

1// Copyright (c) 2024-2026 The Regents of the University of Michigan.
2// Part of hoomd-rs, released under the BSD 3-Clause License.
3
4//! Implement `NoThermostat`
5
6use rand::Rng;
7use serde::{Deserialize, Serialize};
8
9use crate::Thermostat;
10
11/// Apply no momentum scaling.
12///
13/// Use [`NoThermostat`] with [`ConstantVolume`] to model the microcanonical (NVE) ensemble.
14///
15/// [`ConstantVolume`]: crate::method::ConstantVolume
16///
17/// # Example
18///
19/// ```
20/// use hoomd_md::thermostat::NoThermostat;
21///
22/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
23/// let thermostat = NoThermostat;
24/// # Ok(())
25/// # }
26/// ```
27#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
28pub struct NoThermostat;
29
30impl<M> Thermostat<M> for NoThermostat {
31    #[inline]
32    fn integrate_half_step_one<R: Rng + ?Sized>(
33        &mut self,
34        _rng: &mut R,
35        _macrostate: &M,
36        _delta_t: f64,
37        _kinetic_energy: f64,
38        _degrees_of_freedom: usize,
39    ) -> f64 {
40        1.0
41    }
42
43    #[inline]
44    fn integrate_half_step_two<R: Rng + ?Sized>(
45        &mut self,
46        _rng: &mut R,
47        _macrostate: &M,
48        _delta_t: f64,
49        _kinetic_energy: f64,
50        _degrees_of_freedom: usize,
51    ) -> f64 {
52        1.0
53    }
54}
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59    use assert2::check;
60    use hoomd_microstate::{Body, Microstate};
61    use hoomd_vector::Cartesian;
62
63    struct Nve;
64
65    #[test]
66    fn test_no_thermostat() -> anyhow::Result<()> {
67        // Instantiation
68        let mut thermostat = NoThermostat;
69
70        // Thermostat Implementation
71        let mut microstate = Microstate::new();
72        microstate.add_body(Body::point(Cartesian::from([0.0, 0.0])))?;
73        let macrostate = Nve;
74        let delta_t = 1.0;
75        let mut rng = microstate.counter().make_rng();
76
77        check!(1.0 == thermostat.integrate_half_step_one(&mut rng, &macrostate, delta_t, 1.0, 3));
78        check!(1.0 == thermostat.integrate_half_step_two(&mut rng, &macrostate, delta_t, 1.0, 3));
79
80        Ok(())
81    }
82}