32#include <Cabana_Core.hpp>
33#include <Cabana_NeighborList.hpp>
35#ifdef ESPRESSO_CALIPER
36#include <caliper/cali.h>
49#ifdef ESPRESSO_ELECTROSTATICS
53#if defined(ESPRESSO_GAY_BERNE) or defined(ESPRESSO_DIPOLES)
57#ifdef ESPRESSO_DIPOLES
63 aosoa.
id(index) = p.
id();
72#ifdef ESPRESSO_EXCLUSIONS
82 aosoa.
flags(index) = 0;
87 std::span<Cell *const> cells,
BoxGeometry const &box_geo,
89 Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace>
const &
id_to_index,
106 : cuboid_minimum_image.dist2(a, b);
111 auto &local_particles = cells[i]->particles();
112 for (
auto it = local_particles.begin();
it != local_particles.end(); ++
it) {
113 auto const &
p1 = *
it;
118 for (
auto jt = std::next(
it);
jt != local_particles.end(); ++
jt) {
119 if ((*jt).id() <=
max_id) {
136 auto &local_particles = cells[i]->particles();
137 for (
auto const &
p1 : local_particles) {
142 for (
auto &
neighbor : cells[i]->neighbors().red()) {
143 for (
auto const &
p2 :
neighbor->particles()) {
172template <
class execution_space = Kokkos::DefaultHostExecutionSpace>
176 auto const integ_switch) {
177#ifdef ESPRESSO_CALIPER
182 auto const n_part = unique_particles.size();
184 auto &aosoa = cell_structure.
get_aosoa();
192#ifdef ESPRESSO_CALIPER
197 int dihedral_count = 0;
198#ifdef ESPRESSO_EXCLUSIONS
201 aosoa.reset_any_exclusion();
204 "AoSoA write", std::size_t{0}, n_part,
205 [&unique_particles, &aosoa, &
id_to_index, &cell_structure, &pair_count,
206 &angle_count, &dihedral_count](
int const index) {
207 auto const &p = *unique_particles.at(index);
210 if (
not p.is_ghost()) {
211 cell_structure.update_bond_storage(pair_count, angle_count,
216 using host_space = Kokkos::DefaultHostExecutionSpace;
217 auto &
bs = cell_structure.bond_state();
221 "resolve_pair_bond_indices", std::size_t{0}, pair_count,
223 for (
int col = 0; col < 2; ++col) {
231 "resolve_angle_bond_indices", std::size_t{0}, angle_count,
233 for (
int col = 0; col < 3; ++col) {
239 if (dihedral_count) {
242 "resolve_dihedral_bond_indices", std::size_t{0}, dihedral_count,
244 for (
int col = 0; col < 4; ++col) {
250 if (pair_count != 0
or angle_count != 0
or dihedral_count != 0) {
253#ifdef ESPRESSO_CALIPER
261 cell_structure.use_verlet_list);
262#ifdef ESPRESSO_CALIPER
265 cell_structure.rebuild_verlet_list_cabana(
266 [&](std::span<Cell *const> cells,
BoxGeometry const &box,
271 [&](
const int i,
const int j) {
275 [&](
const int i,
const int j) {
281 cell_structure.use_verlet_list =
false;
283 <<
"Verlet list overflow detected: neighbor count exceeded "
284 "max_counts. Falling back to the link cell algorithm. "
286 << Cabana::NeighborList<CellStructure::ListType>::maxNeighbor(
291#ifdef ESPRESSO_CALIPER
298#ifdef ESPRESSO_CALIPER
301#ifdef ESPRESSO_EXCLUSIONS
304 aosoa.reset_any_exclusion();
307 "AoSoA write", std::size_t{0}, n_part,
308 [&unique_particles, &aosoa](
int const index) {
309 auto const &p = *unique_particles.at(index);
313#ifdef ESPRESSO_CALIPER
319#ifdef ESPRESSO_ELECTROSTATICS
320template <
class execution_space = Kokkos::DefaultHostExecutionSpace>
324 auto const n_part = unique_particles.size();
325 auto &aosoa = cell_structure.
get_aosoa();
328 "Views update charges", std::size_t{0}, n_part,
329 [&unique_particles, &aosoa](std::size_t
const index) {
330 aosoa.charge(index) = unique_particles.at(index)->q();
347template <
class execution_space = Kokkos::DefaultHostExecutionSpace>
354 auto const integ_switch,
359#ifdef ESPRESSO_CALIPER
362 using host_space = Kokkos::DefaultHostExecutionSpace;
385#ifdef ESPRESSO_CALIPER
392#ifdef ESPRESSO_CALIPER
401 }
else if (Kokkos::num_threads() == 1) {
402 using NL = Cabana::NeighborList<CellStructure::ListType>;
403 for (std::size_t i = 0; i < n_particles; ++i) {
405 for (std::size_t n = 0; n <
nn; ++n) {
410 Kokkos::RangePolicy<execution_space> policy(std::size_t{0},
413 Cabana::FirstNeighborsTag(),
414 Cabana::SerialOpTag());
418 [&](std::span<Cell *const> cells,
BoxGeometry const &box) {
424 [&](
const int i,
const int j) {
426 nonbonded_kernel(i, j);
428 [&](
const int i,
const int j) {
430 nonbonded_kernel(i, j);
435#ifdef ESPRESSO_CALIPER
@ INTEG_METHOD_STEEPEST_DESCENT
#define ESPRESSO_ATTR_ALWAYS_INLINE
ESPRESSO_ATTR_ALWAYS_INLINE T get_mi_dist2(Utils::Vector3< T > const &a, Utils::Vector3< T > const &b) const
Get the squared minimum-image distance between two coordinates.
auto cuboid_minimum_image() const
Cuboid minimum-image fold parameters for hoisting into kernels.
Describes a cell structure / cell system.
int get_local_angle_bond_numbers() const
int get_local_pair_bond_numbers() const
auto prepare_verlet_list_cabana(double cutoff)
Reset local properties of the Verlet list.
int get_local_dihedral_bond_numbers() const
int get_cached_max_local_particle_id() const
auto const & get_unique_particles() const
unsigned get_resort_particles() const
Get the currently scheduled resort level.
void cell_list_loop(auto &&kernel)
auto const & get_verlet_list_cabana() const
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
#define runtimeWarningMsg()
constexpr Vector< T, 3 > convert_quaternion_to_director(Quaternion< T > const &quat)
Convert quaternion to director.
ESPRESSO_ATTR_ALWAYS_INLINE void link_cell_kokkos(std::span< Cell *const > cells, BoxGeometry const &box_geo, auto const &verlet_criterion, Kokkos::View< int *, Kokkos::DefaultHostExecutionSpace > const &id_to_index, int const max_id, auto const &intra_operator, auto const &inter_operator)
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={})
ESPRESSO_ATTR_ALWAYS_INLINE void commit_particle(Particle const &p, auto const index, CellStructure::AoSoA_pack &aosoa, bool const rebuild)
ESPRESSO_ATTR_ALWAYS_INLINE void update_cabana_state(CellStructure &cell_structure, auto const &make_verlet_criterion, double const pair_cutoff, auto const integ_switch)
std::function< void(CellStructure::ListType const &, std::size_t)> ShortRangeVerletPairLoop
ESPRESSO_ATTR_ALWAYS_INLINE void update_aosoa_charges(CellStructure &cell_structure)
DEVICE_QUALIFIER void set_has_exclusion(std::size_t i, bool value)
PositionViewType position
DEVICE_QUALIFIER void set_vector_at(Kokkos::View< T *[N], array_layout, Kokkos::HostSpace > &view, std::size_t i, Utils::Vector< T, N > const &value)
void mark_any_exclusion()
DirectorViewType director
VelocityViewType velocity
Struct holding all information for one particle.
constexpr auto const & quat() const
constexpr auto const & pos() const
constexpr auto const & mass() const
constexpr auto const & dipm() const
Utils::compact_vector< int > & exclusions()
constexpr auto const & type() const
constexpr auto const & image_box() const
constexpr auto const & id() const
constexpr auto const & q() const
constexpr auto const & v() const