31#include "collision_detection/CollisionDetection.hpp"
33#include "constraints/Constraints.hpp"
36#include "galilei/ComFixed.hpp"
48#include "system/System.hpp"
57#ifdef ESPRESSO_CALIPER
58#include <caliper/cali.h>
61#include <Cabana_Core.hpp>
74#ifdef ESPRESSO_EXTERNAL_FORCES
76#ifdef ESPRESSO_ROTATION
94#ifdef ESPRESSO_CALIPER
95 CALI_CXX_MARK_FUNCTION;
101 auto const kT = thermostat.kT;
105 bool const langevin_active =
106 thermostat.langevin &&
107 (propagation.used_propagations &
111 cell_structure.for_each_local_particle([&](
Particle &p) {
116 if (langevin_active) {
117 auto const &langevin = *thermostat.langevin;
120#ifdef ESPRESSO_ROTATION
127 cell_structure.reset_local_force_and_torque();
130 cell_structure.ghosts_reset_forces();
134 if (force_cap > 0.) {
135 auto const force_cap_sq =
Utils::sqr(force_cap);
137 [&force_cap, &force_cap_sq](
Particle &p) {
138 auto const force_sq = p.
force().norm2();
139 if (force_sq > force_cap_sq) {
140 p.
force() *= force_cap / std::sqrt(force_sq);
146#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
157 auto scatter_virial = system.
cell_structure->get_scatter_virial();
173 auto const &elc_kernel,
auto const &coulomb_kernel,
174 auto const &dipoles_kernel,
auto const &coulomb_u_kernel) {
176 auto const &unique_particles = system.
cell_structure->get_unique_particles();
179#ifdef ESPRESSO_ROTATION
180 auto scatter_torque = system.
cell_structure->get_scatter_torque();
183 auto scatter_virial = system.
cell_structure->get_scatter_virial();
198#ifdef ESPRESSO_ROTATION
212 auto const &unique_particles = system.
cell_structure->get_unique_particles();
215 Kokkos::Experimental::contribute(local_force, scatter_force);
216#ifdef ESPRESSO_ROTATION
218 auto scatter_torque = system.
cell_structure->get_scatter_torque();
219 Kokkos::Experimental::contribute(local_torque, scatter_torque);
223 auto scatter_virial = system.
cell_structure->get_scatter_virial();
224 Kokkos::Experimental::contribute(local_virial, scatter_virial);
227 using execution_space = Kokkos::DefaultExecutionSpace;
228 Kokkos::RangePolicy<execution_space> policy(std::size_t{0},
229 unique_particles.size());
230 Kokkos::parallel_for(
"reduction", policy,
232#ifdef ESPRESSO_ROTATION
235 &unique_particles](std::size_t
const i) {
237#ifdef ESPRESSO_ROTATION
240 force[0] += local_force(i, 0);
241 force[1] += local_force(i, 1);
242 force[2] += local_force(i, 2);
243#ifdef ESPRESSO_ROTATION
244 torque[0] += local_torque(i, 0);
245 torque[1] += local_torque(i, 1);
246 torque[2] += local_torque(i, 2);
248 unique_particles.at(i)->force() += force;
249#ifdef ESPRESSO_ROTATION
250 unique_particles.at(i)->torque() += torque;
257 (*virial)[0] += local_virial(0);
258 (*virial)[1] += local_virial(1);
259 (*virial)[2] += local_virial(2);
265#ifdef ESPRESSO_CALIPER
266 CALI_CXX_MARK_FUNCTION;
270#ifdef ESPRESSO_CALIPER
271 CALI_MARK_BEGIN(
"copy_particles_to_GPU");
274#ifdef ESPRESSO_CALIPER
275 CALI_MARK_END(
"copy_particles_to_GPU");
280#ifdef ESPRESSO_COLLISION_DETECTION
281 collision_detection->clear_queue();
282 auto const collision_detection_cutoff = collision_detection->cutoff();
286 bond_breakage->clear_queue();
287 auto particles = cell_structure->local_particles();
294#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
301 auto const elc_kernel = coulomb.pair_force_elc_kernel();
302 auto const coulomb_kernel = coulomb.pair_force_kernel();
303 auto const dipoles_kernel = dipoles.pair_force_kernel();
304 auto const coulomb_u_kernel = coulomb.pair_energy_kernel();
305 auto *
const virial = get_npt_virial();
308 cell_structure->get_verlet_skin(),
309 get_interaction_range(),
312 collision_detection_cutoff};
315 get_interaction_range(), propagation->integ_switch);
316#ifdef ESPRESSO_ELECTROSTATICS
317 if (coulomb.impl->extension) {
318 update_icc_particles();
322#ifdef ESPRESSO_CALIPER
323 CALI_MARK_BEGIN(
"calc_long_range_forces");
325#ifdef ESPRESSO_ELECTROSTATICS
326 coulomb.calc_long_range_force();
328#ifdef ESPRESSO_DIPOLES
329 dipoles.calc_long_range_force();
331#ifdef ESPRESSO_CALIPER
332 CALI_MARK_END(
"calc_long_range_forces");
335#ifdef ESPRESSO_CALIPER
336 CALI_MARK_BEGIN(
"cabana_short_range");
338 auto &bs = cell_structure->bond_state();
341 bonds_kernel_data, bs.pair_list, bs.pair_ids,
get_ptr(coulomb_kernel)};
342 auto angle_bonds_kernel =
344 auto dihedral_bonds_kernel =
347 auto first_neighbor_kernel =
349 dipoles_kernel, coulomb_u_kernel);
352 dihedral_bonds_kernel, first_neighbor_kernel,
353 *cell_structure, get_interaction_range(),
354 bonded_ias->maximal_cutoff(), verlet_criterion,
355 propagation->integ_switch);
360#ifdef ESPRESSO_COLLISION_DETECTION
361 auto collision_kernel = [&collision_detection = *collision_detection](
364 collision_detection.detect_collision(p1, p2, d.dist2);
366 if (not collision_detection->is_off()) {
367 cell_structure->non_bonded_loop(collision_kernel, verlet_criterion);
371#ifdef ESPRESSO_CALIPER
372 CALI_MARK_END(
"cabana_short_range");
375 constraints->add_forces(particles, get_sim_time());
376 oif_global->calculate_forces();
379 immersed_boundaries->volume_conservation(*cell_structure);
381 if (thermostat->lb and (propagation->used_propagations &
383#ifdef ESPRESSO_CALIPER
384 CALI_MARK_BEGIN(
"lb_particle_coupling");
386 lb_couple_particles();
387#ifdef ESPRESSO_CALIPER
388 CALI_MARK_END(
"lb_particle_coupling");
394#ifdef ESPRESSO_CALIPER
395 CALI_MARK_BEGIN(
"copy_forces_from_GPU");
397 gpu->copy_forces_to_host(particles,
this_node);
399#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
400 gpu->copy_dip_fld_to_host(particles,
this_node);
403#ifdef ESPRESSO_CALIPER
404 CALI_MARK_END(
"copy_forces_from_GPU");
409#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
410 if (propagation->used_propagations &
416#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
417 if (propagation->used_propagations &
424 cell_structure->ghosts_reduce_forces();
427 comfixed->apply(particles);
433 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.
Describes a cell structure / cell system.
void for_each_local_particle(Callable &&f, bool parallel=true) const
Run a kernel on all local particles.
double maximal_cutoff() const
Calculate the maximal cutoff of all interactions.
auto get_time_step() const
Get time_step.
std::shared_ptr< BondedInteractionsMap > bonded_ias
std::shared_ptr< BondBreakage::BondBreakage > bond_breakage
void calculate_forces()
Calculate all forces.
std::shared_ptr< Propagation > propagation
std::shared_ptr< Thermostat::Thermostat > thermostat
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< BoxGeometry > box_geo
std::shared_ptr< InteractionsNonBonded > nonbonded_ias
Returns true if the particles are to be considered for short range interactions.
void vs_com_back_transfer_forces_and_torques(CellStructure &cell_structure)
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 BondsKernelData create_kokkos_bonds_kernel_data(System::System const &system)
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)
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 &pair_bonds_kernel, auto const &angle_bonds_kernel, auto const &dihedral_bonds_kernel, auto const &nonbonded_kernel, CellStructure &cell_structure, double pair_cutoff, double bond_cutoff, auto const &verlet_criterion, auto const integ_switch)
Distance vector and length handed to pair kernels.
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