30#include <Cabana_Core.hpp>
74 KOKKOS_INLINE_FUNCTION std::size_t
bonded_idx(
int b)
const {
88 Kokkos::View<double **, Kokkos::LayoutRight, memory_space>
local_energy;
91 Kokkos::View<int *, Kokkos::LayoutRight, memory_space>
mol_id_view;
101 std::vector<Particle *>
const &unique_particles_,
102 Kokkos::View<double **, Kokkos::LayoutRight, memory_space>
const
105 Kokkos::View<int *, memory_space> mol_id_view_,
double system_max_cutoff_)
114 std::size_t j)
const {
115 auto const d =
box_geo.get_mi_vector(
118 auto const dist_sq = d.norm2();
121 auto const dist = std::sqrt(dist_sq);
123 auto const t1 =
aosoa.type(i);
124 auto const t2 =
aosoa.type(j);
128#if defined(ESPRESSO_EXCLUSIONS) or defined(ESPRESSO_THOLE)
129 bool need_particle_pointers =
false;
130#ifdef ESPRESSO_EXCLUSIONS
131 need_particle_pointers |=
aosoa.has_exclusion(i) or
aosoa.has_exclusion(j);
134 need_particle_pointers |=
140 if (need_particle_pointers) {
146 auto const tid = omp_get_thread_num();
149 if (dist <= ia_params.max_cut) {
150#ifdef ESPRESSO_EXCLUSIONS
152 if (
aosoa.has_exclusion(i) or
aosoa.has_exclusion(j))
167#ifdef ESPRESSO_GAY_BERNE
169 auto const dir1 =
aosoa.get_vector_at(
aosoa.director, i);
170 auto const dir2 =
aosoa.get_vector_at(
aosoa.director, j);
179 ?
layout.nb_intra_idx(t1, t2)
180 :
layout.nb_inter_idx(t1, t2);
183#ifdef ESPRESSO_ELECTROSTATICS
185 auto const q1 =
aosoa.charge(i), q2 =
aosoa.charge(j);
186 if (q1 != 0. and q2 != 0.) {
187 auto const pos1 =
aosoa.get_vector_at(
aosoa.position, i);
188 auto const pos2 =
aosoa.get_vector_at(
aosoa.position, j);
189 double const e_c = (*coulomb_u_kernel)(pos1, pos2, q1 * q2, d, dist);
195#ifdef ESPRESSO_DIPOLES
197 if (
aosoa.dipm(i) != 0. and
aosoa.dipm(j) != 0.) {
198 auto const dir1 =
aosoa.get_vector_at(
aosoa.director, i);
199 auto const dir2 =
aosoa.get_vector_at(
aosoa.director, j);
200 double const e_d = (*dipoles_u_kernel)(
201 aosoa.dipm(i) * dir1,
aosoa.dipm(j) * dir2, d, dist, dist_sq);
210 Kokkos::View<double **, Kokkos::LayoutRight, Kokkos::HostSpace>
const
214 auto const nthreads = local_energy.extent(0);
216 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, local_energy);
218 auto sum_bin = [&](std::size_t bin) {
220 for (std::size_t t = 0; t < nthreads; ++t)
225 for (
int b = 0; b < int(layout.
n_bonded); ++b)
228 for (
int t1 = 0; t1 < n_types; ++t1)
229 for (
int t2 = 0; t2 <= t1; ++t2)
233 for (
int t1 = 0; t1 < n_types; ++t1)
234 for (
int t2 = 0; t2 <= t1; ++t2)
Vector implementation and trait types for boost qvm interoperability.
#define ESPRESSO_ATTR_ALWAYS_INLINE
container for bonded interactions.
Observable for the pressure and energy.
auto non_bonded_intra_contribution(int type1, int type2) const
Get contribution from a non-bonded intramolecular interaction.
std::span< double > coulomb
Contribution(s) from Coulomb interactions.
auto non_bonded_inter_contribution(int type1, int type2) const
Get contribution from a non-bonded intermolecular interaction.
std::span< double > bonded_contribution(int bond_id) const
Get contribution from a bonded interaction.
std::span< double > dipolar
Contribution(s) from dipolar interactions.
static void reduce_cabana_energy(Kokkos::View< double **, Kokkos::LayoutRight, Kokkos::HostSpace > const &local_energy, EnergyBinLayout const &layout, Observable_stat &obs, BondedInteractionsMap const &bonded_ias, int n_types)
double calc_central_radial_energy(IA_parameters const &ia_params, double const dist)
bool do_nonbonded(Particle const &p1, Particle const &p2)
Determine if the non-bonded interactions between p1 and p2 should be calculated.
double gb_pair_energy(Utils::Vector3d const &ui, Utils::Vector3d const &uj, IA_parameters const &ia_params, Utils::Vector3d const &d, double dist)
Calculate Gay-Berne energy.
DEVICE_QUALIFIER T lower_triangular(T i, T j)
Linear index into a lower triangular matrix.
ESPRESSO_ATTR_ALWAYS_INLINE KOKKOS_INLINE_FUNCTION bool gay_berne_active(double dist, IA_parameters const &ia_params)
KOKKOS_INLINE_FUNCTION bool thole_active(IA_parameters const &ia_params, bool has_coulomb_kernel)
Solver::ShortRangeEnergyKernel kernel_type
Solver::ShortRangeEnergyKernel kernel_type
ESPRESSO_ATTR_ALWAYS_INLINE KOKKOS_INLINE_FUNCTION std::size_t nb_intra_idx(int t1, int t2) const
EnergyBinLayout(std::size_t n_bonded_, std::size_t n_types_)
KOKKOS_INLINE_FUNCTION std::size_t dipolar_idx() const
KOKKOS_INLINE_FUNCTION std::size_t bonded_idx(int b) const
KOKKOS_INLINE_FUNCTION std::size_t coulomb_idx() const
ESPRESSO_ATTR_ALWAYS_INLINE KOKKOS_INLINE_FUNCTION std::size_t nb_inter_idx(int t1, int t2) const
CellStructure::AoSoA_pack const & aosoa
std::vector< Particle * > const & unique_particles
BondedInteractionsMap const & bonded_ias
Kokkos::View< double **, Kokkos::LayoutRight, memory_space > local_energy
InteractionsNonBonded const & nonbonded_ias
ESPRESSO_ATTR_ALWAYS_INLINE void operator()(std::size_t i, std::size_t j) const
Coulomb::Solver const & coulomb
Dipoles::ShortRangeEnergyKernel::kernel_type const * dipoles_u_kernel
Kokkos::View< int *, Kokkos::LayoutRight, memory_space > mol_id_view
BoxGeometry const & box_geo
Coulomb::ShortRangeEnergyKernel::kernel_type const * coulomb_u_kernel
double system_max_cutoff_sq
EnergyKernel(BondedInteractionsMap const &bonded_ias_, InteractionsNonBonded const &nonbonded_ias_, Coulomb::Solver const &coulomb_, Coulomb::ShortRangeEnergyKernel::kernel_type const *coulomb_u_kernel_, Dipoles::ShortRangeEnergyKernel::kernel_type const *dipoles_u_kernel_, BoxGeometry const &box_geo_, std::vector< Particle * > const &unique_particles_, Kokkos::View< double **, Kokkos::LayoutRight, memory_space > const &local_energy_, EnergyBinLayout layout_, CellStructure::AoSoA_pack const &aosoa_, Kokkos::View< int *, memory_space > mol_id_view_, double system_max_cutoff_)
Kokkos::HostSpace memory_space
Struct holding all information for one particle.
double thole_pair_energy(Particle const &p1, Particle const &p2, IA_parameters const &ia_params, Utils::Vector3d const &d, double dist, BondedInteractionsMap const &bonded_ias, Coulomb::Solver const &coulomb, Coulomb::ShortRangeEnergyKernel::kernel_type const *kernel)
Calculate Thole energy.