31#include <Cabana_Core.hpp>
32#include <Cabana_NeighborList.hpp>
34#ifdef ESPRESSO_CALIPER
35#include <caliper/cali.h>
43 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>>
47 if (Kokkos::num_threads() > 1) {
49 Kokkos::parallel_for(name, policy, kernel);
62#ifdef ESPRESSO_ELECTROSTATICS
66#if defined(ESPRESSO_GAY_BERNE) or defined(ESPRESSO_DIPOLES)
70#ifdef ESPRESSO_DIPOLES
76 aosoa.
id(index) = p.
id();
85#ifdef ESPRESSO_EXCLUSIONS
88 aosoa.
flags(index) = 0;
93 std::span<Cell *const> cells,
BoxGeometry const &box_geo,
95 Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace>
const &
id_to_index,
104 auto &local_particles = cells[i]->particles();
105 for (
auto it = local_particles.begin();
it != local_particles.end(); ++
it) {
106 auto const &
p1 = *
it;
111 for (
auto jt = std::next(
it);
jt != local_particles.end(); ++
jt) {
112 if ((*jt).id() <=
max_id) {
129 auto &local_particles = cells[i]->particles();
130 for (
auto const &
p1 : local_particles) {
135 for (
auto &
neighbor : cells[i]->neighbors().red()) {
136 for (
auto const &
p2 :
neighbor->particles()) {
153 Kokkos::parallel_for(
"intra",
154 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
155 std::size_t{0}, cells.size()),
159 Kokkos::parallel_for(
"inter",
160 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
161 std::size_t{0}, cells.size()),
166template <
class execution_space = Kokkos::DefaultHostExecutionSpace>
169 double const pair_cutoff,
auto const integ_switch) {
170#ifdef ESPRESSO_CALIPER
173 using policy_type = Kokkos::RangePolicy<execution_space>;
176 auto const n_part = unique_particles.size();
178 auto &aosoa = cell_structure.
get_aosoa();
186#ifdef ESPRESSO_CALIPER
191 int dihedral_count = 0;
193 "AoSoA write", std::size_t{0}, n_part,
194 [&unique_particles, &aosoa, &
id_to_index, &cell_structure, &pair_count,
195 &angle_count, &dihedral_count](
int const index) {
196 auto const &p = *unique_particles.at(index);
199 if (
not p.is_ghost()) {
200 cell_structure.update_bond_storage(pair_count, angle_count,
205 auto &
bs = cell_structure.bond_state();
207 Kokkos::parallel_for(
"resolve_pair_bond_indices",
208 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
209 std::size_t{0}, pair_count),
211 for (
int col = 0; col < 2; ++col) {
217 Kokkos::parallel_for(
"resolve_angle_bond_indices",
218 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
219 std::size_t{0}, angle_count),
221 for (
int col = 0; col < 3; ++col) {
227 Kokkos::parallel_for(
"resolve_dihedral_bond_indices",
228 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
229 std::size_t{0}, dihedral_count),
231 for (
int col = 0; col < 4; ++col) {
237#ifdef ESPRESSO_CALIPER
245 cell_structure.use_verlet_list);
246#ifdef ESPRESSO_CALIPER
249 cell_structure.rebuild_verlet_list_cabana(
250 [&](std::span<Cell *const> cells,
BoxGeometry const &box,
254 [&](
const int i,
const int j) {
258 [&](
const int i,
const int j) {
264 cell_structure.use_verlet_list =
false;
266 <<
"Verlet list overflow detected: neighbor count exceeded "
267 "max_counts. Falling back to the link cell algorithm. "
269 << Cabana::NeighborList<CellStructure::ListType>::maxNeighbor(
274#ifdef ESPRESSO_CALIPER
281#ifdef ESPRESSO_CALIPER
285 "AoSoA write", std::size_t{0}, n_part,
286 [&unique_particles, &aosoa](
int const index) {
287 auto const &p = *unique_particles.at(index);
291#ifdef ESPRESSO_CALIPER
297#ifdef ESPRESSO_ELECTROSTATICS
298template <
class execution_space = Kokkos::DefaultHostExecutionSpace>
301 using policy_type = Kokkos::RangePolicy<execution_space>;
303 auto const n_part = unique_particles.size();
304 auto &aosoa = cell_structure.
get_aosoa();
307 "Views update charges", std::size_t{0}, n_part,
308 [&unique_particles, &aosoa](std::size_t
const index) {
309 aosoa.charge(index) = unique_particles.at(index)->q();
314template <
class execution_space = Kokkos::DefaultHostExecutionSpace>
321 auto const integ_switch) {
325#ifdef ESPRESSO_CALIPER
333 Kokkos::parallel_for(
334 "for_each_local_pair_bonds",
335 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(std::size_t{0},
341 Kokkos::parallel_for(
342 "for_each_local_angle_bonds",
343 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(std::size_t{0},
349 Kokkos::parallel_for(
350 "for_each_local_dihedral_bonds",
351 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
356#ifdef ESPRESSO_CALIPER
363#ifdef ESPRESSO_CALIPER
369 Kokkos::RangePolicy<execution_space> policy(
372 Cabana::FirstNeighborsTag(),
373 Cabana::SerialOpTag());
376 [&](std::span<Cell *const> cells,
BoxGeometry const &box) {
381 [&](
const int i,
const int j) {
383 nonbonded_kernel(i, j);
385 [&](
const int i,
const int j) {
387 nonbonded_kernel(i, j);
392#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()
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)
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 kokkos_parallel_range_for(auto const &name, auto start, auto end, auto const &kernel)
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 update_aosoa_charges(CellStructure &cell_structure)
ESPRESSO_ATTR_ALWAYS_INLINE void update_cabana_state(CellStructure &cell_structure, auto const &verlet_criterion, double const pair_cutoff, auto const integ_switch)
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)
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