fn real_space_forces(&self, configuration: &Configuration, forces: &mut [Vector3D]) {
        assert_eq!(forces.len(), configuration.size());

        let natoms = configuration.size();
        let charges = configuration.particles().charge;
        // Each thread (and not each iteration of the loop below) get its own
        // storage in a `ThreadLocalVec`.
        let thread_local_forces = ThreadLocalVec::with_size(natoms);

        (0..natoms).into_par_iter().for_each(|i| {
            // Get the thread local forces Vec
            let mut forces = thread_local_forces.borrow_mut();

            let mut force_i = Vector3D::zero();
            let qi = charges[i];
            if qi == 0.0 {
                return;
            }

            for j in i + 1..natoms {
                let qj = charges[j];
                if qj == 0.0 {
                    continue;
                }

                let path = configuration.bond_path(i, j);
                let info = self.restriction.information(path);

                let rij = configuration.nearest_image(i, j);
                let force = self.real_space_force_pair(info, qi * qj, rij.norm()) * rij;
                force_i += force;
                forces[j] -= force;
            }
            forces[i] += force_i;
        });

        // At this point all the forces are computed, but the results are
        // scattered across all thread local Vec, here we gather them.
        thread_local_forces.sum_into(forces);
    }
/// Real space contribution to the forces
Real space contribution to the forces
Real space contribution to the forces
fn real_space_forces(&self, configuration: &Configuration, forces: &mut [Vector3D]) {
        assert_eq!(forces.len(), configuration.size());
        let natoms = configuration.size();
        let charges = configuration.particles().charge;
        // Each thread (and not each iteration of the loop below) get its own
        // storage in a `ThreadLocalVec`.
        let thread_local_forces = ThreadLocalVec::with_size(natoms);
        (0..natoms).into_par_iter().for_each(|i| {
            // Get the thread local forces Vec
            let mut forces = thread_local_forces.borrow_mut();
            let mut force_i = Vector3D::zero();
            let qi = charges[i];
            if qi == 0.0 {
                return;
            }
            for j in i + 1..natoms {
                let qj = charges[j];
                if qj == 0.0 {
                    continue;
                }
                let path = configuration.bond_path(i, j);
                let info = self.restriction.information(path);
                let rij = configuration.nearest_image(i, j);
                let force = self.real_space_force_pair(info, qi * qj, rij.norm()) * rij;
                force_i += force;
                forces[j] -= force;
            }
            forces[i] += force_i;
        });
        // At this point all the forces are computed, but the results are
        // scattered across all thread local Vec, here we gather them.
        thread_local_forces.sum_into(forces);
    }
fn real_space_forces ( & self , configuration : & Configuration , forces : & mut [ Vector3D ] ) { assert_eq ! ( forces len ( ) configuration size ( ) ) ; let natoms = configuration . size ( ) ; let charges = configuration . particles ( ) . charge ; // Each thread (and not each iteration of the loop below) get its own // storage in a `ThreadLocalVec`. let thread_local_forces = ThreadLocalVec :: with_size ( natoms ) ; ( 0 .. natoms ) . into_par_iter ( ) . for_each ( | i | { // Get the thread local forces Vec let mut forces = thread_local_forces . borrow_mut ( ) ; let mut force_i = Vector3D :: zero ( ) ; let qi = charges [ i ] ; if qi == 0.0 { return ; } for j in i + 1 .. natoms { let qj = charges [ j ] ; if qj == 0.0 { continue ; } let path = configuration . bond_path ( i , j ) ; let info = self . restriction . information ( path ) ; let rij = configuration . nearest_image ( i , j ) ; let force = self . real_space_force_pair ( info , qi * qj , rij . norm ( ) ) * rij ; force_i += force ; forces [ j ] -= force ; } forces [ i ] += force_i ; } ) ; // At this point all the forces are computed, but the results are // scattered across all thread local Vec, here we gather them. thread_local_forces . sum_into ( forces ) ; }
Real space contribution to the forces
Real space contribution to the forces
&self
configuration
&Configuration
forces
&mut [Vector3D]