31#include <Cabana_Core.hpp>
32#include <Cabana_NeighborList.hpp>
34#ifdef ESPRESSO_CALIPER
35#include <caliper/cali.h>
42template <
class KokkosRangePolicy = Kokkos::RangePolicy<>>
46 if (Kokkos::num_threads() > 1) {
48 Kokkos::parallel_for(name, policy, kernel);
61#ifdef ESPRESSO_ELECTROSTATICS
65#if defined(ESPRESSO_GAY_BERNE) or defined(ESPRESSO_DIPOLES)
69#ifdef ESPRESSO_DIPOLES
75 aosoa.
id(index) = p.
id();
84#ifdef ESPRESSO_EXCLUSIONS
87 aosoa.
flags(index) = 0;
103 auto &local_particles = cells[i]->particles();
104 for (
auto it = local_particles.begin();
it != local_particles.end(); ++
it) {
105 auto const &
p1 = *
it;
110 for (
auto jt = std::next(
it);
jt != local_particles.end(); ++
jt) {
111 if ((*jt).id() <=
max_id) {
128 auto &local_particles = cells[i]->particles();
129 for (
auto const &
p1 : local_particles) {
134 for (
auto &
neighbor : cells[i]->neighbors().red()) {
135 for (
auto const &
p2 :
neighbor->particles()) {
152 Kokkos::parallel_for(
"intra", cells.size(),
intra_kernel);
155 Kokkos::parallel_for(
"inter", cells.size(),
inter_kernel);
161 double const pair_cutoff,
auto const integ_switch) {
162#ifdef ESPRESSO_CALIPER
166 using policy_type = Kokkos::RangePolicy<execution_space>;
169 auto const n_part = unique_particles.size();
171 auto &aosoa = cell_structure.
get_aosoa();
179#ifdef ESPRESSO_CALIPER
184 int dihedral_count = 0;
186 "AoSoA write", std::size_t{0}, n_part,
187 [&unique_particles, &aosoa, &
id_to_index, &cell_structure, &pair_count,
188 &angle_count, &dihedral_count](
int const index) {
189 auto const &p = *unique_particles.at(index);
192 if (
not p.is_ghost()) {
193 cell_structure.update_bond_storage(pair_count, angle_count,
198 auto &
bs = cell_structure.bond_state();
200 Kokkos::parallel_for(
"resolve_pair_bond_indices", pair_count,
202 for (
int col = 0; col < 2; ++col) {
208 Kokkos::parallel_for(
"resolve_angle_bond_indices", angle_count,
210 for (
int col = 0; col < 3; ++col) {
216 Kokkos::parallel_for(
"resolve_dihedral_bond_indices", dihedral_count,
218 for (
int col = 0; col < 4; ++col) {
224#ifdef ESPRESSO_CALIPER
232 cell_structure.use_verlet_list);
233#ifdef ESPRESSO_CALIPER
236 cell_structure.rebuild_verlet_list_cabana(
237 [&](std::span<Cell *const> cells,
BoxGeometry const &box,
241 [&](
const int i,
const int j) {
245 [&](
const int i,
const int j) {
251 cell_structure.use_verlet_list =
false;
253 <<
"Verlet list overflow detected: neighbor count exceeded "
254 "max_counts. Falling back to the link cell algorithm. "
256 << Cabana::NeighborList<CellStructure::ListType>::maxNeighbor(
261#ifdef ESPRESSO_CALIPER
268#ifdef ESPRESSO_CALIPER
272 "AoSoA write", std::size_t{0}, n_part,
273 [&unique_particles, &aosoa](
int const index) {
274 auto const &p = *unique_particles.at(index);
278#ifdef ESPRESSO_CALIPER
284#ifdef ESPRESSO_ELECTROSTATICS
288 using policy_type = Kokkos::RangePolicy<execution_space>;
290 auto const n_part = unique_particles.size();
291 auto &aosoa = cell_structure.
get_aosoa();
294 "Views update charges", std::size_t{0}, n_part,
295 [&unique_particles, &aosoa](std::size_t
const index) {
296 aosoa.charge(index) = unique_particles.at(index)->q();
307 auto const integ_switch) {
312#ifdef ESPRESSO_CALIPER
320 Kokkos::parallel_for(
325 Kokkos::parallel_for(
330 Kokkos::parallel_for(
335#ifdef ESPRESSO_CALIPER
342#ifdef ESPRESSO_CALIPER
348 Kokkos::RangePolicy<execution_space> policy(
351 Cabana::FirstNeighborsTag(),
352 Cabana::SerialOpTag());
355 [&](std::span<Cell *const> cells,
BoxGeometry const &box) {
360 [&](
const int i,
const int j) {
362 nonbonded_kernel(i, j);
364 [&](
const int i,
const int j) {
366 nonbonded_kernel(i, j);
371#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.
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()
Vector< T, 3 > convert_quaternion_to_director(Quaternion< T > const &quat)
Convert quaternion to director.
ESPRESSO_ATTR_ALWAYS_INLINE void update_cabana_state(CellStructure &cell_structure, auto const &verlet_criterion, double const pair_cutoff, auto const integ_switch)
ESPRESSO_ATTR_ALWAYS_INLINE void link_cell_kokkos(std::span< Cell *const > cells, BoxGeometry const &box_geo, auto const &verlet_criterion, Kokkos::View< int * > 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 &verlet_criterion, auto const integ_switch)
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_aosoa_charges(CellStructure &cell_structure)
ESPRESSO_ATTR_ALWAYS_INLINE void kokkos_parallel_range_for(auto const &name, auto start, auto end, auto const &kernel)
void set_vector_at(Kokkos::View< T *[N], array_layout, Kokkos::HostSpace > &view, std::size_t i, Utils::Vector< T, N > const &value)
PositionViewType position
void set_has_exclusion(std::size_t i, bool value)
DirectorViewType director
VelocityViewType velocity
Struct holding all information for one particle.
auto const & mass() const
Utils::compact_vector< int > & exclusions()
auto const & quat() const
auto const & image_box() const
auto const & type() const
auto const & dipm() const