30#include "collision_detection/CollisionDetection.hpp"
32#include "constraints/Constraints.hpp"
35#include "galilei/ComFixed.hpp"
47#include "system/System.hpp"
56#ifdef ESPRESSO_CALIPER
57#include <caliper/cali.h>
60#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
61#include <Cabana_Core.hpp>
75#ifdef ESPRESSO_EXTERNAL_FORCES
77#ifdef ESPRESSO_ROTATION
95#ifdef ESPRESSO_CALIPER
99 auto &cell_structure = *
system.cell_structure;
100 auto const &propagation = *
system.propagation;
101 auto const &thermostat = *
system.thermostat;
102 auto const kT = thermostat.kT;
103 auto const time_step =
system.get_time_step();
107 thermostat.langevin &&
108 (propagation.used_propagations &
112 cell_structure.for_each_local_particle([&](
Particle &p) {
118 auto const &langevin = *thermostat.langevin;
121#ifdef ESPRESSO_ROTATION
128#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
129 cell_structure.reset_local_force();
133 cell_structure.ghosts_reset_forces();
137 if (force_cap > 0.) {
149#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
156#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
159 auto const &elc_kernel,
auto const &coulomb_kernel,
160 auto const &dipoles_kernel,
auto const &coulomb_u_kernel) {
162 auto const &unique_particles =
system.cell_structure->get_unique_particles();
163 auto const &local_force =
system.cell_structure->get_local_force();
164#ifdef ESPRESSO_ROTATION
165 auto const &local_torque =
system.cell_structure->get_local_torque();
168 auto const &local_virial =
system.cell_structure->get_local_virial();
170 auto const &aosoa =
system.cell_structure->get_aosoa();
183#ifdef ESPRESSO_ROTATION
196 auto const &unique_particles =
system.cell_structure->get_unique_particles();
197 auto const &local_force =
system.cell_structure->get_local_force();
198#ifdef ESPRESSO_ROTATION
199 auto const &local_torque =
system.cell_structure->get_local_torque();
202 auto const &local_virial =
system.cell_structure->get_local_virial();
207 Kokkos::RangePolicy<execution_space> policy(std::size_t{0},
208 unique_particles.size());
209 Kokkos::parallel_for(
"reduction", policy,
214 &unique_particles,
num_threads](std::size_t
const i) {
216#ifdef ESPRESSO_ROTATION
220 force[0] += local_force(i,
tid, 0);
221 force[1] += local_force(i,
tid, 1);
222 force[2] += local_force(i,
tid, 2);
223#ifdef ESPRESSO_ROTATION
224 torque[0] += local_torque(i,
tid, 0);
225 torque[1] += local_torque(i,
tid, 1);
226 torque[2] += local_torque(i,
tid, 2);
229 unique_particles.at(i)->force() += force;
230#ifdef ESPRESSO_ROTATION
231 unique_particles.at(i)->torque() += torque;
239 (*virial)[0] += local_virial(
tid, 0);
240 (*virial)[1] += local_virial(
tid, 1);
241 (*virial)[2] += local_virial(
tid, 2);
249#ifdef ESPRESSO_CALIPER
254#ifdef ESPRESSO_CALIPER
258#ifdef ESPRESSO_CALIPER
264#ifdef ESPRESSO_COLLISION_DETECTION
265 collision_detection->clear_queue();
270 bond_breakage->clear_queue();
271 auto particles = cell_structure->local_particles();
278#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
285 auto const elc_kernel = coulomb.pair_force_elc_kernel();
286 auto const coulomb_kernel = coulomb.pair_force_kernel();
287 auto const dipoles_kernel = dipoles.pair_force_kernel();
288 auto const coulomb_u_kernel = coulomb.pair_energy_kernel();
289 auto *
const virial = get_npt_virial();
293 &bonded_ias = *bonded_ias,
294 &bond_breakage = *bond_breakage,
virial,
295 &box_geo = *box_geo](
Particle &
p1,
int bond_id,
302 cell_structure->get_verlet_skin(),
303 get_interaction_range(),
308#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
310 get_interaction_range(), propagation->integ_switch);
312#ifdef ESPRESSO_ELECTROSTATICS
313 if (coulomb.impl->extension) {
314 update_icc_particles();
318#ifdef ESPRESSO_CALIPER
321#ifdef ESPRESSO_ELECTROSTATICS
322 coulomb.calc_long_range_force();
324#ifdef ESPRESSO_DIPOLES
325 dipoles.calc_long_range_force();
327#ifdef ESPRESSO_CALIPER
331#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
332#ifdef ESPRESSO_CALIPER
338 dipoles_kernel, coulomb_u_kernel);
341 get_interaction_range(), bonded_ias->maximal_cutoff(),
347#ifdef ESPRESSO_COLLISION_DETECTION
351 collision_detection.detect_collision(
p1,
p2, d.dist2);
353 if (
not collision_detection->is_off()) {
358#ifdef ESPRESSO_CALIPER
364#ifdef ESPRESSO_CALIPER
372 &nonbonded_ias = *nonbonded_ias,
373 &thermostat = *thermostat, &bonded_ias = *bonded_ias,
375#ifdef ESPRESSO_COLLISION_DETECTION
376 &collision_detection = *collision_detection,
383 auto const &
ia_params = nonbonded_ias.get_ia_param(
p1.type(),
p2.type());
388#ifdef ESPRESSO_COLLISION_DETECTION
389 if (
not collision_detection.is_off()) {
390 collision_detection.detect_collision(
p1,
p2, d.dist2);
398#ifdef ESPRESSO_CALIPER
404 constraints->add_forces(particles, get_sim_time());
405 oif_global->calculate_forces();
408 immersed_boundaries->volume_conservation(*cell_structure);
410 if (thermostat->lb
and (propagation->used_propagations &
412#ifdef ESPRESSO_CALIPER
415 lb_couple_particles();
416#ifdef ESPRESSO_CALIPER
423#ifdef ESPRESSO_CALIPER
426 gpu->copy_forces_to_host(particles,
this_node);
428#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
429 gpu->copy_dip_fld_to_host(particles,
this_node);
432#ifdef ESPRESSO_CALIPER
438#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
439 if (propagation->used_propagations &
445#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
446 if (propagation->used_propagations &
453 cell_structure->ghosts_reduce_forces();
456 comfixed->apply(particles);
462 propagation->recalc_forces =
false;
Vector implementation and trait types for boost qvm interoperability.
This file contains everything related to the global cell structure / cell system.
double maximal_cutoff() const
Calculate the maximal cutoff of bonded interactions, required to determine the cell size for communic...
Describes a cell structure / cell system.
void for_each_local_particle(ParticleUnaryOp &&f, bool parallel=true) const
Run a kernel on all local particles.
void calculate_forces()
Calculate all forces.
Returns true if the particles are to be considered for short range interactions.
void vs_com_back_transfer_forces_and_torques(CellStructure &cell_structure)
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
int this_node
The number of this node.
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
const T * get_ptr(std::optional< T > const &opt)
static void reinit_dip_fld(CellStructure const &cell_structure)
static void force_capping(CellStructure &cell_structure, double force_cap)
static void init_forces_and_thermostat(System::System const &system)
Combined force initialization and Langevin noise application.
static ParticleForce external_force(Particle const &p)
External particle forces.
static ForcesKernel create_cabana_neighbor_kernel(System::System const &system, Utils::Vector3d *virial, auto const &elc_kernel, auto const &coulomb_kernel, auto const &dipoles_kernel, auto const &coulomb_u_kernel)
static void reduce_cabana_forces_and_torques(System::System const &system, Utils::Vector3d *virial)
void add_non_bonded_pair_force(Particle &p1, Particle &p2, Utils::Vector3d const &d, double dist, double dist2, double q1q2, IA_parameters const &ia_params, Thermostat::Thermostat const &thermostat, BoxGeometry const &box_geo, BondedInteractionsMap const &bonded_ias, Utils::Vector3d *const virial, Coulomb::ShortRangeForceKernel::kernel_type const *coulomb_kernel, Dipoles::ShortRangeForceKernel::kernel_type const *dipoles_kernel, Coulomb::ShortRangeForceCorrectionsKernel::kernel_type const *elc_kernel, Coulomb::ShortRangeEnergyKernel::kernel_type const *coulomb_u_kernel)
Calculate non-bonded forces between a pair of particles and update their forces and torques.
bool add_bonded_force(Particle &p1, int bond_id, std::span< Particle * > partners, BondedInteractionsMap const &bonded_ia_params, BondBreakage::BondBreakage &bond_breakage, BoxGeometry const &box_geo, Utils::Vector3d *const virial, Coulomb::ShortRangeForceKernel::kernel_type const *kernel)
ICC is a method that allows to take into account the influence of arbitrarily shaped dielectric inter...
Utils::Vector3d friction_thermo_langevin(LangevinThermostat const &langevin, Particle const &p, double time_step, double kT)
Langevin thermostat for particle translational velocities.
Utils::Vector3d friction_thermo_langevin_rotation(LangevinThermostat const &langevin, Particle const &p, double time_step, double kT)
Langevin thermostat for particle angular velocities.
@ TRANS_VS_CENTER_OF_MASS
@ TRANS_LB_MOMENTUM_EXCHANGE
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Various procedures concerning interactions between particles.
Exports for the NpT code.
void vs_relative_back_transfer_forces_and_torques(CellStructure &cell_structure)
This file contains all subroutines required to process rotational motion.
Utils::Vector3d convert_vector_body_to_space(const Particle &p, const Utils::Vector3d &vec)
ESPRESSO_ATTR_ALWAYS_INLINE void update_cabana_state(CellStructure &cell_structure, auto const &verlet_criterion, double const pair_cutoff, auto const integ_switch)
void cabana_short_range(auto const &bond_kernel, auto const &forces_kernel, CellStructure &cell_structure, double pair_cutoff, double bond_cutoff, auto const &verlet_criterion, auto const integ_switch)
void short_range_loop(BondKernel bond_kernel, PairKernel pair_kernel, CellStructure &cell_structure, double pair_cutoff, double bond_cutoff, VerletCriterion const &verlet_criterion={})
Distance vector and length handed to pair kernels.
BondedInteractionsMap const & bonded_ias
Force information on a particle.
Utils::Vector3d torque
torque.
Struct holding all information for one particle.
auto const & dip_fld() const
auto const & swimming() const
auto const & force_and_torque() const
auto const & torque() const
auto const & ext_force() const
auto const & ext_torque() const
auto const & force() const
auto calc_director() const