pub trait DeltaEnergyInsert<B, S, X, C> {
// Required method
fn delta_energy_insert(
&self,
initial_microstate: &Microstate<B, S, X, C>,
new_body: &Body<B, S>,
) -> f64;
}Expand description
Compute the change in energy when a single body is inserted.
Some trial moves insert a single body at a time and use a Hamiltonian that
implements DeltaEnergyInsert to efficiently compute the change in energy.
The generic type names are:
B: TheBody::propertiestype.S: TheSite::propertiestype.X: The spatial data structure type.C: Theboundarycondition type.
See the Implementors section below for examples.
§Derive macro
Use the DeltaEnergyInsert derive macro to
automatically implement the DeltaEnergyInsert trait on a type. The derived
implementation sums the result of delta_energy_insert over all fields in the
struct (in the order in which fields are named in the struct definition).
The sum short circuits and returns f64::INFINITY when any one field
returns infinity.
use hoomd_interaction::{
DeltaEnergyInsert, External, PairwiseCutoff, external::Linear,
pairwise::Isotropic, univariate::Boxcar,
};
use hoomd_microstate::{Body, Microstate, property::Point};
use hoomd_vector::Cartesian;
#[derive(DeltaEnergyInsert)]
struct Hamiltonian {
linear: External<Linear<Cartesian<2>>>,
pairwise_cutoff: PairwiseCutoff<Isotropic<Boxcar>>,
}
let mut microstate = Microstate::new();
microstate.extend_bodies([Body::point(Cartesian::from([0.0, 4.0]))])?;
let epsilon = 2.0;
let (left, right) = (0.0, 1.5);
let boxcar = Boxcar {
epsilon,
left,
right,
};
let pairwise_cutoff = PairwiseCutoff(Isotropic {
interaction: boxcar,
r_cut: right,
});
let linear = External(Linear {
alpha: 1.0,
plane_origin: Cartesian::default(),
plane_normal: [0.0, 1.0].try_into()?,
});
let hamiltonian = Hamiltonian {
pairwise_cutoff,
linear,
};
let new_body = Body::point(Cartesian::from([1.0, 4.0]));
let delta_energy = hamiltonian.delta_energy_insert(µstate, &new_body);
assert_eq!(delta_energy, 6.0);Required Methods§
Sourcefn delta_energy_insert(
&self,
initial_microstate: &Microstate<B, S, X, C>,
new_body: &Body<B, S>,
) -> f64
fn delta_energy_insert( &self, initial_microstate: &Microstate<B, S, X, C>, new_body: &Body<B, S>, ) -> f64
Compute the change in energy.
initial_microstate describes the initial configuration and new_body
describes the new body configuration. The final configuration includes
all bodies in the initial microstate and new_body.
Returns:
\Delta E = E_\mathrm{final} - E_\mathrm{initial}