24#ifdef ESPRESSO_BOND_CONSTRAINT
39#include <boost/mpi/collectives/all_reduce.hpp>
40#include <boost/range/algorithm.hpp>
53 static constexpr char const *
const msg =
" failed to converge after ";
67 auto save_pos = [](
Particle &p) { p.pos_last_time_step() = p.pos(); };
69 boost::for_each(particles, save_pos);
70 boost::for_each(ghost_particles, save_pos);
81 auto reset_force = [](
Particle &p) { p.rattle_params().correction.fill(0); };
83 boost::for_each(particles, reset_force);
84 boost::for_each(ghost_particles, reset_force);
102 std::vector<Utils::Vector9d> &rigid_bond_virial) {
104 auto const r_ij2 = r_ij.norm2();
106 if (std::abs(1.0 - r_ij2 / ia_params.
d2) > ia_params.
p_tol) {
109 auto const r_ij_dot = r_ij_t * r_ij;
111 0.50 * (ia_params.
d2 - r_ij2) / r_ij_dot / (p1.
mass() + p2.
mass());
113 auto const pos_corr = G * r_ij_t;
126 rigid_bond_virial[
static_cast<std::size_t
>(bond_id)] +=
Utils::flatten(
144template <
typename Kernel>
149 bool correction =
false;
150 cs.
bond_loop([&correction, &kernel, &box_geo, &bonded_ias](
151 Particle &p1,
int bond_id, std::span<Particle *> partners) {
152 auto const &iaparams = *bonded_ias.
at(bond_id);
154 if (
auto const *bond = std::get_if<RigidBond>(&iaparams)) {
155 auto const corrected = kernel(*bond, box_geo, p1, *partners[0], bond_id);
173 boost::for_each(particles, [](
Particle &p) {
196 cs, box_geo, bonded_ias,
203 boost::mpi::all_reduce(
comm_cart, repeat_, std::logical_or<bool>());
216 auto const resort_level =
233 auto const v_ij = p1.
v() - p2.
v();
236 auto const v_proj = v_ij * r_ij;
237 if (std::abs(v_proj) > ia_params.
v_tol) {
238 auto const K = v_proj / ia_params.
d2 / (p1.
mass() + p2.
mass());
240 auto const vel_corr = K * r_ij;
257 boost::for_each(particles,
272 cs, box_geo, bonded_ias,
278 boost::mpi::all_reduce(
comm_cart, repeat_, std::logical_or<bool>());
Vector implementation and trait types for boost qvm interoperability.
Data structures for bonded interactions.
container for bonded interactions.
mapped_type const & at(key_type const &key) const
std::vector< Utils::Vector9d > rigid_bond_virial
Per-bond-type RATTLE constraint virial.
DEVICE_QUALIFIER auto get_next_key() const
ESPRESSO_ATTR_ALWAYS_INLINE Utils::Vector3< T > get_mi_vector(Utils::Vector3< T > const &a, Utils::Vector3< T > const &b) const noexcept
Get the minimum-image vector between two coordinates.
Describes a cell structure / cell system.
ParticleRange ghost_particles() const
void update_ghosts_and_resort_particle(unsigned data_parts)
Update ghost particles, with particle resort if needed.
void ghosts_update(unsigned data_parts)
Update ghost particles.
bool check_resort_required(Utils::Vector3d const &additional_offset={}) const
Check whether a particle has moved further than half the skin since the last Verlet list update,...
void bond_loop(BondKernel const &bond_kernel)
Bonded pair loop.
void set_resort_particles(Cells::Resort level)
Increase the local resort level at least to level.
ParticleRange local_particles() const
void ghosts_reduce_rattle_correction()
Add rattle corrections from ghost particles to real particles.
static DEVICE_QUALIFIER constexpr Vector< double, N > broadcast(typename Base::value_type const &value) noexcept
boost::mpi::communicator comm_cart
The communicator.
This file contains the asynchronous MPI communication.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
Matrix implementation and trait types for boost qvm interoperability.
@ DATA_PART_MOMENTUM
Particle::m.
@ DATA_PART_PROPERTIES
Particle::p.
@ DATA_PART_POSITION
Particle::r.
void flatten(Range const &v, OutputIterator out)
Flatten a range of ranges.
Matrix< T, N, M > tensor_product(const Vector< T, N > &x, const Vector< T, M > &y)
void correct_velocity_shake(CellStructure &cs, BoxGeometry const &box_geo, BondedInteractionsMap const &bonded_ias)
Correction of current velocities using RATTLE algorithm.
void save_old_position(const ParticleRange &particles, const ParticleRange &ghost_particles)
copy current position
static constexpr auto shake_max_iterations
Maximal number of iterations before the RATTLE algorithm bails out.
static void init_correction_vector(const ParticleRange &particles, const ParticleRange &ghost_particles)
reset correction vectors to zero
static void apply_positional_correction(const ParticleRange &particles)
Apply positional corrections.
static bool calculate_velocity_correction(RigidBond const &ia_params, BoxGeometry const &box_geo, Particle &p1, Particle &p2)
Calculate the velocity correction for the particles.
void correct_position_shake(CellStructure &cs, BoxGeometry const &box_geo, BondedInteractionsMap &bonded_ias)
Propagate velocity and position while using SHAKE algorithm for bond constraint.
static bool calculate_positional_correction(RigidBond const &ia_params, BoxGeometry const &box_geo, Particle &p1, Particle &p2, int bond_id, std::vector< Utils::Vector9d > &rigid_bond_virial)
Calculate the positional correction for the particles.
static void check_convergence(int cnt, char const *const name)
static void apply_velocity_correction(ParticleRange const &particles)
Apply velocity corrections.
static bool compute_correction_vector(CellStructure &cs, BoxGeometry const &box_geo, BondedInteractionsMap const &bonded_ias, Kernel kernel)
Compute the correction vectors using given kernel.
RATTLE algorithm (andersen83a).
Definition of the rigid bond data type for the Rattle algorithm.
Struct holding all information for one particle.
constexpr auto const & pos() const
constexpr auto const & mass() const
constexpr auto const & rattle_params() const
constexpr auto const & pos_last_time_step() const
constexpr auto const & v() const
Parameters for the rigid_bond/SHAKE/RATTLE ALGORITHM.
double d2
Square of the length of Constrained Bond.
double v_tol
Velocity Tolerance/Accuracy for termination of RATTLE/SHAKE iterations during velocity corrections.
double p_tol
Positional Tolerance/Accuracy value for termination of RATTLE/SHAKE iterations during position correc...