29#include "system/System.hpp"
42 auto obs_energy_ptr = std::make_shared<Observable_stat>(
44 nonbonded_ias->get_max_seen_particle_type());
46 if (long_range_interactions_sanity_checks()) {
47 return obs_energy_ptr;
50 auto &obs_energy = *obs_energy_ptr;
51#if defined(CUDA) and (defined(ELECTROSTATICS) or defined(DIPOLES))
52 gpu.clear_energy_on_device();
57 auto const local_parts = cell_structure->local_particles();
59 for (
auto const &p : local_parts) {
63 auto const coulomb_kernel = coulomb.pair_energy_kernel();
64 auto const dipoles_kernel = dipoles.pair_energy_kernel();
67 [
this, coulomb_kernel_ptr =
get_ptr(coulomb_kernel), &obs_energy](
73 obs_energy.bonded_contribution(bond_id)[0] += result.get();
78 [coulomb_kernel_ptr =
get_ptr(coulomb_kernel),
79 dipoles_kernel_ptr =
get_ptr(dipoles_kernel),
this,
81 auto const &ia_params =
82 nonbonded_ias->get_ia_param(p1.
type(), p2.type());
84 ia_params, coulomb_kernel_ptr,
85 dipoles_kernel_ptr, obs_energy);
91 obs_energy.coulomb[1] = coulomb.calc_energy_long_range(local_parts);
96 obs_energy.dipolar[1] = dipoles.calc_energy_long_range(local_parts);
102#if defined(CUDA) and (defined(ELECTROSTATICS) or defined(DIPOLES))
103 auto const energy_host = gpu.copy_energy_to_host();
104 if (!obs_energy.coulomb.empty())
105 obs_energy.coulomb[1] +=
static_cast<double>(energy_host.coulomb);
106 if (!obs_energy.dipolar.empty())
107 obs_energy.dipolar[1] +=
static_cast<double>(energy_host.dipolar);
110 obs_energy.mpi_reduce();
111 return obs_energy_ptr;
116 if (cell_structure->get_resort_particles()) {
117 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
121 if (
auto const p = cell_structure->get_local_particle(pid)) {
122 auto const coulomb_kernel = coulomb.pair_energy_kernel();
123 auto kernel = [coulomb_kernel_ptr =
get_ptr(coulomb_kernel), &ret,
130 auto const &ia_params = nonbonded_ias->get_ia_param(p.type(), p1.type());
135 cell_structure->run_on_particle_short_range_neighbors(*p, kernel);
140#ifdef DIPOLE_FIELD_TRACKING
142 dipoles.calc_long_range_field(cell_structure->local_particles());
double maximal_cutoff_bonded()
Calculate the maximal cutoff of bonded interactions, required to determine the cell size for communic...
BondedInteractionsMap bonded_ia_params
Field containing the parameters of the bonded ia types.
mapped_type at(key_type const &key) const
double particle_short_range_energy_contribution(int pid)
Compute the short-range energy of a particle.
void calculate_long_range_fields()
Calculate dipole fields.
std::shared_ptr< Observable_stat > calculate_energy()
Calculate the total energy.
A stripped-down version of std::span from C++17.
const T * get_ptr(std::optional< T > const &opt)
double calc_non_bonded_pair_energy(Particle const &p1, Particle const &p2, IA_parameters const &ia_params, Utils::Vector3d const &d, double const dist, Coulomb::ShortRangeEnergyKernel::kernel_type const *coulomb_kernel)
Calculate non-bonded energies between a pair of particles.
double calc_kinetic_energy(Particle const &p)
Calculate kinetic energies for one particle.
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, 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.
boost::optional< double > calc_bonded_energy(Bonded_IA_Parameters const &iaparams, Particle const &p1, Utils::Span< Particle * > partners, BoxGeometry const &box_geo, Coulomb::ShortRangeEnergyKernel::kernel_type const *kernel)
bool do_nonbonded(Particle const &p1, Particle const &p2)
Determine if the non-bonded interactions between p1 and p2 should be calculated.
Constraints< ParticleRange, Constraint > constraints
Various procedures concerning interactions between particles.
void short_range_loop(BondKernel bond_kernel, PairKernel pair_kernel, CellStructure &cell_structure, double pair_cutoff, double bond_cutoff, VerletCriterion const &verlet_criterion={})
Distance vector and length handed to pair kernels.
Struct holding all information for one particle.
auto const & type() const