41 auto obs_energy_ptr = std::make_shared<Observable_stat>(
42 1ul,
static_cast<std::size_t
>(bonded_ias->get_next_key()),
43 nonbonded_ias->get_max_seen_particle_type());
45 if (long_range_interactions_sanity_checks()) {
46 return obs_energy_ptr;
49 auto &obs_energy = *obs_energy_ptr;
50#if defined(CUDA) and (defined(ELECTROSTATICS) or defined(DIPOLES))
51 gpu.clear_energy_on_device();
56 auto const local_parts = cell_structure->local_particles();
58 for (
auto const &p : local_parts) {
62 auto const coulomb_kernel = coulomb.pair_energy_kernel();
63 auto const dipoles_kernel = dipoles.pair_energy_kernel();
66 [
this, coulomb_kernel_ptr =
get_ptr(coulomb_kernel), &obs_energy](
67 Particle const &p1,
int bond_id, std::span<Particle *> partners) {
68 auto const &iaparams = *bonded_ias->at(bond_id);
72 obs_energy.bonded_contribution(bond_id)[0] += result.value();
77 [coulomb_kernel_ptr =
get_ptr(coulomb_kernel),
78 dipoles_kernel_ptr =
get_ptr(dipoles_kernel),
this,
80 auto const &ia_params =
81 nonbonded_ias->get_ia_param(p1.
type(), p2.type());
83 ia_params, *bonded_ias, coulomb_kernel_ptr,
84 dipoles_kernel_ptr, obs_energy);
86 *cell_structure, maximal_cutoff(), bonded_ias->maximal_cutoff());
90 obs_energy.coulomb[1] = coulomb.calc_energy_long_range(local_parts);
95 obs_energy.dipolar[1] = dipoles.calc_energy_long_range(local_parts);
98 constraints->add_energy(local_parts, get_sim_time(), obs_energy);
100#if defined(CUDA) and (defined(ELECTROSTATICS) or defined(DIPOLES))
101 auto const energy_host = gpu.copy_energy_to_host();
102 if (!obs_energy.coulomb.empty())
103 obs_energy.coulomb[1] +=
static_cast<double>(energy_host.coulomb);
104 if (!obs_energy.dipolar.empty())
105 obs_energy.dipolar[1] +=
static_cast<double>(energy_host.dipolar);
108 obs_energy.mpi_reduce();
109 return obs_energy_ptr;
114 if (cell_structure->get_resort_particles()) {
115 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
119 if (
auto const p = cell_structure->get_local_particle(pid)) {
120 auto const coulomb_kernel = coulomb.pair_energy_kernel();
121 auto kernel = [coulomb_kernel_ptr =
get_ptr(coulomb_kernel), &ret,
128 auto const &ia_params = nonbonded_ias->get_ia_param(p.type(), p1.type());
131 *bonded_ias, coulomb_kernel_ptr);
133 cell_structure->run_on_particle_short_range_neighbors(*p, kernel);
std::optional< double > calc_bonded_energy(Bonded_IA_Parameters const &iaparams, Particle const &p1, std::span< Particle * > partners, BoxGeometry const &box_geo, Coulomb::ShortRangeEnergyKernel::kernel_type const *kernel)
double calc_non_bonded_pair_energy(Particle const &p1, Particle const &p2, IA_parameters const &ia_params, Utils::Vector3d const &d, double const dist, BondedInteractionsMap const &bonded_ias, Coulomb::ShortRangeEnergyKernel::kernel_type const *coulomb_kernel)
Calculate non-bonded energies between a pair of particles.
void add_non_bonded_pair_energy(Particle const &p1, Particle const &p2, Utils::Vector3d const &d, double const dist, double const dist2, IA_parameters const &ia_params, BondedInteractionsMap const &bonded_ias, Coulomb::ShortRangeEnergyKernel::kernel_type const *coulomb_kernel, Dipoles::ShortRangeEnergyKernel::kernel_type const *dipoles_kernel, Observable_stat &obs_energy)
Add non-bonded and short-range Coulomb energies between a pair of particles to the energy observable.
void short_range_loop(BondKernel bond_kernel, PairKernel pair_kernel, CellStructure &cell_structure, double pair_cutoff, double bond_cutoff, VerletCriterion const &verlet_criterion={})
Struct holding all information for one particle.
auto const & type() const