Skip to main content

hoomd_interaction/
zero.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 `Zero`
5
6use serde::{Deserialize, Serialize};
7
8use hoomd_microstate::{Body, Microstate, property::Position};
9use hoomd_vector::{Outer, Wedge};
10
11use super::{
12    DeltaEnergyInsert, DeltaEnergyOne, DeltaEnergyRemove, NetSiteForceAndVirial,
13    NetSiteForceVirialAndTorque, TotalEnergy,
14};
15
16/// Hamiltonian with H = 0.
17///
18/// *hoomd-rs* uses [`Zero`] in minimal examples. It evaluates to 0 for all
19/// forces, virials, torques, energies, and delta energies.
20#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
21pub struct Zero;
22
23impl<M> TotalEnergy<M> for Zero {
24    #[inline]
25    fn total_energy(&self, _microstate: &M) -> f64 {
26        0.0
27    }
28}
29
30impl<B, S, X, C> DeltaEnergyOne<B, S, X, C> for Zero {
31    #[inline]
32    fn delta_energy_one(
33        &self,
34        _initial_microstate: &Microstate<B, S, X, C>,
35        _body_index: usize,
36        _final_body: &Body<B, S>,
37    ) -> f64 {
38        0.0
39    }
40}
41
42impl<B, S, X, C> DeltaEnergyInsert<B, S, X, C> for Zero {
43    #[inline]
44    fn delta_energy_insert(
45        &self,
46        _initial_microstate: &Microstate<B, S, X, C>,
47        _new_body: &Body<B, S>,
48    ) -> f64 {
49        0.0
50    }
51}
52
53impl<B, S, X, C> DeltaEnergyRemove<B, S, X, C> for Zero {
54    #[inline]
55    fn delta_energy_remove(
56        &self,
57        _initial_microstate: &Microstate<B, S, X, C>,
58        _body_index: usize,
59    ) -> f64 {
60        0.0
61    }
62}
63
64impl<V, B, S, X, C> NetSiteForceVirialAndTorque<B, S, X, C> for Zero
65where
66    V: Default + Wedge + Outer,
67    V::Bivector: Default,
68    S: Position<Position = V>,
69    V::Tensor: Default,
70{
71    type Force = V;
72
73    #[inline]
74    fn net_site_force_virial_and_torque(
75        &self,
76        _microstate: &Microstate<B, S, X, C>,
77        _site_index: usize,
78    ) -> (V, V::Tensor, V::Bivector) {
79        (V::default(), V::Tensor::default(), V::Bivector::default())
80    }
81}
82
83impl<V, B, S, X, C> NetSiteForceAndVirial<B, S, X, C> for Zero
84where
85    V: Default + Outer,
86    S: Position<Position = V>,
87    V::Tensor: Default,
88{
89    type Force = V;
90
91    #[inline]
92    fn net_site_force_and_virial(
93        &self,
94        _microstate: &Microstate<B, S, X, C>,
95        _site_index: usize,
96    ) -> (V, V::Tensor) {
97        (V::default(), V::Tensor::default())
98    }
99}