31#include "collision_detection/CollisionDetection.hpp"
33#include "constraints/Constraints.hpp"
37#include "galilei/ComFixed.hpp"
50#include "system/System.hpp"
58#ifdef ESPRESSO_CALIPER
59#include <caliper/cali.h>
62#include <Cabana_Core.hpp>
84#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
97 auto const &aosoa =
system.cell_structure->get_aosoa();
111 auto const &elc_kernel,
auto const &coulomb_kernel,
112 auto const &dipoles_kernel,
auto const &coulomb_u_kernel) {
114 auto const &unique_particles =
system.cell_structure->get_unique_particles();
117#ifdef ESPRESSO_ROTATION
120#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
126 auto const &aosoa =
system.cell_structure->get_aosoa();
139#ifdef ESPRESSO_ROTATION
142#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
155template <
bool HasCoulomb>
171 std::size_t
const n) {
179#ifdef ESPRESSO_ELECTROSTATICS
188 Kokkos::parallel_for(
"specialized_nonbonded_pairs",
189 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
205 [[
maybe_unused]]
auto const &elc_kernel,
auto const &coulomb_kernel,
213#ifdef ESPRESSO_DIPOLES
214 if (
get_ptr(dipoles_kernel) !=
nullptr)
217#ifdef ESPRESSO_ELECTROSTATICS
218 if (
get_ptr(elc_kernel) !=
nullptr)
221 auto const &nonbonded_ias = *
system.nonbonded_ias;
227 if ((nonbonded_ias.combined_active_pair_mask() &
232 if (nonbonded_ias.any_thole_configured())
235 auto &cell_structure = *
system.cell_structure;
236 auto const &aosoa = cell_structure.get_aosoa();
237#ifdef ESPRESSO_EXCLUSIONS
242 if (aosoa.has_any_exclusion())
247 auto const minimum_image =
system.box_geo->cuboid_minimum_image();
250#ifdef ESPRESSO_ELECTROSTATICS
263 static_cast<void>(coulomb_kernel);
273 auto const &unique_particles =
system.cell_structure->get_unique_particles();
274 auto &local_force =
system.cell_structure->get_local_force();
276 Kokkos::Experimental::contribute(local_force,
scatter_force);
277#ifdef ESPRESSO_ROTATION
278 auto &local_torque =
system.cell_structure->get_local_torque();
282#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
283 auto &local_dip_fld =
system.cell_structure->get_local_dip_fld();
288 auto &local_virial =
system.cell_structure->get_local_virial();
293 using execution_space = Kokkos::DefaultHostExecutionSpace;
294 Kokkos::RangePolicy<execution_space> policy(std::size_t{0},
295 unique_particles.size());
296 Kokkos::parallel_for(
"reduction", policy,
304 &unique_particles](std::size_t
const i) {
306#ifdef ESPRESSO_ROTATION
309#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
312 force[0] += local_force(i, 0);
313 force[1] += local_force(i, 1);
314 force[2] += local_force(i, 2);
315#ifdef ESPRESSO_ROTATION
316 torque[0] += local_torque(i, 0);
317 torque[1] += local_torque(i, 1);
318 torque[2] += local_torque(i, 2);
320#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
321 dip_fld[0] += local_dip_fld(i, 0);
322 dip_fld[1] += local_dip_fld(i, 1);
323 dip_fld[2] += local_dip_fld(i, 2);
325 unique_particles.at(i)->force() += force;
326#ifdef ESPRESSO_ROTATION
327 unique_particles.at(i)->torque() += torque;
329#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
330 unique_particles.at(i)->dip_fld() += dip_fld;
337 (*virial)[0] += local_virial(0);
338 (*virial)[1] += local_virial(1);
339 (*virial)[2] += local_virial(2);
345#ifdef ESPRESSO_CALIPER
350#ifdef ESPRESSO_CALIPER
354#ifdef ESPRESSO_CALIPER
360#ifdef ESPRESSO_COLLISION_DETECTION
361 collision_detection->clear_queue();
366 bond_breakage->clear_queue();
367 auto particles = cell_structure->local_particles();
374#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
375 if (dipoles.impl->solver.has_value()) {
382 auto const elc_kernel = coulomb.pair_force_elc_kernel();
383 auto const coulomb_kernel = coulomb.pair_force_kernel();
384 auto const dipoles_kernel = dipoles.pair_force_kernel();
385 auto const coulomb_u_kernel = coulomb.pair_energy_kernel();
386 auto *
const virial = get_npt_virial();
393 cell_structure->get_verlet_skin(),
394 get_interaction_range(),
401#ifdef ESPRESSO_ELECTROSTATICS
402 if (coulomb.impl->extension) {
403 update_icc_particles();
407#ifdef ESPRESSO_CALIPER
410#ifdef ESPRESSO_ELECTROSTATICS
411 coulomb.calc_long_range_force();
413#ifdef ESPRESSO_DIPOLES
414 dipoles.calc_long_range_force();
416#ifdef ESPRESSO_CALIPER
420#ifdef ESPRESSO_CALIPER
423 auto &
bs = cell_structure->bond_state();
434 dipoles_kernel, coulomb_u_kernel);
437 *
this,
virial, elc_kernel, coulomb_kernel, dipoles_kernel);
441 *cell_structure, get_interaction_range(),
448#ifdef ESPRESSO_COLLISION_DETECTION
452 collision_detection.detect_collision(
p1,
p2, d.dist2);
454 if (
not collision_detection->is_off()) {
460#ifdef ESPRESSO_CALIPER
464 constraints->add_forces(particles, get_sim_time());
465 oif_global->calculate_forces();
468 immersed_boundaries->volume_conservation(*cell_structure);
470 if (thermostat->lb
and (propagation->used_propagations &
472#ifdef ESPRESSO_CALIPER
475 lb_couple_particles();
476#ifdef ESPRESSO_CALIPER
483#ifdef ESPRESSO_CALIPER
486 gpu->copy_forces_to_host(particles,
this_node);
488#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
489 gpu->copy_dip_fld_to_host(particles,
this_node);
492#ifdef ESPRESSO_CALIPER
498#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
499 if (propagation->used_propagations &
505#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
506 if (propagation->used_propagations &
513 cell_structure->ghosts_reduce_forces();
514#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
515 if (dipoles.impl->solver.has_value()) {
516 cell_structure->ghosts_reduce_dipole_field();
521 comfixed->apply(particles);
527 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.
Kokkos::Experimental::ScatterView< double *[3], Kokkos::LayoutRight, memory_space > ScatterForce
void for_each_local_particle(Callable &&f, bool parallel=true) const
Run a kernel on all local particles.
Cuboid minimum-image fold parameters for hot pair loops.
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 BondsKernelData create_kokkos_bonds_kernel_data(System::System const &system)
static ShortRangeVerletPairLoop create_specialized_verlet_pair_loop(System::System const &system, Utils::Vector3d const *virial, auto const &elc_kernel, auto const &coulomb_kernel, auto const &dipoles_kernel)
static void reinit_dip_fld(CellStructure const &cell_structure)
static void force_capping(CellStructure &cell_structure, double force_cap)
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 ShortRangeVerletPairLoop make_specialized_verlet_pair_loop(InteractionsNonBonded const &nonbonded_ias, CellStructure::AoSoA_pack const &aosoa, CellStructure::ScatterForce scatter_force, CuboidMinimumImage const &minimum_image, double const max_cutoff_sq, Coulomb::ShortRangeForceKernel::kernel_type const *coulomb_ptr=nullptr, CoulombP3M const *p3m=nullptr)
static void reduce_cabana_forces_and_torques(System::System const &system, Utils::Vector3d *virial)
CoulombP3M const * get_toplevel_p3m_solver(Coulomb::Solver const &coulomb)
The active P3M solver, or nullptr.
constexpr unsigned specialized_kernel_pair_mask
Pair potentials fully handled by SpecializedForcesKernel, i.e.
void init_forces_and_thermostat(System::System const &system)
Combined force initialization and Langevin noise application.
ICC is a method that allows to take into account the influence of arbitrarily shaped dielectric inter...
@ 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.
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 &make_verlet_criterion, auto const integ_switch, ShortRangeVerletPairLoop const &verlet_pair_loop={})
std::function< void(CellStructure::ListType const &, std::size_t)> ShortRangeVerletPairLoop
void update_verlet_state(System::System const &system, double const collision_cut)
BondedInteractionsMap const & bonded_ias
Solver::ShortRangeForceKernel kernel_type
Distance vector and length handed to pair kernels.
BondedInteractionsMap const & bonded_ias
Struct holding all information for one particle.
constexpr auto const & dip_fld() const
constexpr auto const & force() const
Own-the-loop specialization of the non-bonded pair kernel.