45#ifdef ESPRESSO_CALIPER
59 Kokkos::View<double **, Kokkos::LayoutRight, execution_space>
local;
69 m_obs_energy->observable = std::make_unique<Observable_stat>(1ul, 0ul, 0);
71 decltype(
m_obs_energy->local)(
"local_energy", n_threads, 1ul);
76 obs_energy.reset(
static_cast<std::size_t
>(
bonded_ias->get_next_key()),
83#if defined(ESPRESSO_CUDA) and \
84 (defined(ESPRESSO_ELECTROSTATICS) or defined(ESPRESSO_DIPOLES))
85 gpu->clear_energy_on_device();
92 for (
auto const &p : local_parts) {
97 auto const coulomb_kernel =
coulomb.pair_energy_kernel();
98 auto const dipoles_kernel =
dipoles.pair_energy_kernel();
100#ifdef ESPRESSO_CALIPER
105 auto const make_verlet_criterion = [&] {
116 static_cast<std::size_t
>(
bonded_ias->get_next_key()),
117 std::size_t(
nonbonded_ias->get_max_seen_particle_type() + 1)};
119 using exec = Kokkos::DefaultHostExecutionSpace;
120 if (local_energy.extent(1) != layout.
total) {
121 Kokkos::realloc(Kokkos::WithoutInitializing, local_energy,
122 exec{}.concurrency(), layout.
total);
126 auto const &unique_particles =
cell_structure->get_unique_particles();
127 auto const n_particles = unique_particles.size();
128 Kokkos::View<int *, Kokkos::LayoutRight, exec> mol_id(
"mol_id", n_particles);
129 for (std::size_t i = 0; i < n_particles; ++i) {
130 mol_id(i) = unique_particles[i]->mol_id();
160 bonded_ias->maximal_cutoff(), make_verlet_criterion,
165#ifdef ESPRESSO_CALIPER
169#ifdef ESPRESSO_ELECTROSTATICS
171 obs_energy.coulomb[1] =
coulomb.calc_energy_long_range();
174#ifdef ESPRESSO_DIPOLES
176 obs_energy.dipolar[1] =
dipoles.calc_energy_long_range();
181#if defined(ESPRESSO_CUDA) and \
182 (defined(ESPRESSO_ELECTROSTATICS) or defined(ESPRESSO_DIPOLES))
183 auto const energy_host =
gpu->copy_energy_to_host();
184 if (!obs_energy.coulomb.empty())
185 obs_energy.coulomb[1] +=
static_cast<double>(energy_host.coulomb);
186 if (!obs_energy.dipolar.empty())
187 obs_energy.dipolar[1] +=
static_cast<double>(energy_host.dipolar);
190 obs_energy.mpi_reduce();
202 auto const coulomb_kernel =
coulomb.pair_energy_kernel();
205#ifdef ESPRESSO_EXCLUSIONS
209 auto const &ia_params =
nonbonded_ias->get_ia_param(p.type(), p1.type());
214 cell_structure->run_on_particle_short_range_neighbors(*p, kernel);
220 std::vector<int> partners) {
227 auto const &iaparams = *
bonded_ias->at(bond_id);
229 auto resolved_partners =
cell_structure->resolve_bond_partners(partners);
230 auto const coulomb_kernel =
coulomb.pair_energy_kernel();
233 std::span(resolved_partners.data(), resolved_partners.size()), *
box_geo,
void bond_broken_error(int id, std::span< const int > partner_ids)
Zero-overhead Caliper guards for the inactive (no CALI_CONFIG) case.
#define ESPRESSO_CALI_MARK_END(name)
Guarded CALI_MARK_END — no-op when inactive.
#define ESPRESSO_CALI_MARK_BEGIN(name)
Guarded CALI_MARK_BEGIN — no-op when inactive.
Observable for the pressure and energy.
double particle_short_range_energy_contribution(int pid)
Compute the short-range energy of a particle.
double get_interaction_range() const
Get the interaction range.
double maximal_cutoff() const
Calculate the maximal cutoff of all interactions.
unsigned get_global_ghost_flags() const
Returns the ghost flags required for running pair kernels for the global state, e....
std::shared_ptr< BondedInteractionsMap > bonded_ias
std::optional< double > particle_bond_energy(int pid, int bond_id, std::vector< int > partners)
Compute the energy of a given bond which has to exist on the given particle.
bool long_range_interactions_sanity_checks() const
Check electrostatic and magnetostatic methods are properly initialized.
std::shared_ptr< Propagation > propagation
void on_observable_calc()
called before calculating observables, i.e.
std::shared_ptr< GpuParticleData > gpu
Observable_stat const & calculate_energy()
Calculate the total energy.
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< Constraints::Constraints > constraints
std::shared_ptr< EnergyObservable > m_obs_energy
auto get_sim_time() const
Get sim_time.
std::shared_ptr< BoxGeometry > box_geo
std::shared_ptr< InteractionsNonBonded > nonbonded_ias
Returns true if the particles are to be considered for short range interactions.
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
const T * get_ptr(std::optional< T > const &opt)
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)
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 translational_kinetic_energy(Particle const &p)
Calculate kinetic energies from translation for one particle.
double rotational_kinetic_energy(Particle const &p)
Calculate kinetic energies from rotation for one particle.
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::Solver const &coulomb, Coulomb::ShortRangeEnergyKernel::kernel_type const *coulomb_kernel)
Calculate non-bonded energies between a pair of particles.
bool do_nonbonded(Particle const &p1, Particle const &p2)
Determine if the non-bonded interactions between p1 and p2 should be calculated.
ESPRESSO_ATTR_ALWAYS_INLINE void kokkos_deep_copy(auto const &exec_space, auto const &view, auto const &value)
Wrapper for Kokkos::deep_copy that skips fork/join when the number of threads is 1.
Various procedures concerning interactions between particles.
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 &make_verlet_criterion, auto const integ_switch, ShortRangeVerletPairLoop const &verlet_pair_loop={})
void update_verlet_state(System::System const &system, double const collision_cut)
Exception indicating that a particle id could not be resolved.
std::unique_ptr< Observable_stat > observable
Kokkos::DefaultHostExecutionSpace execution_space
Kokkos::View< double **, Kokkos::LayoutRight, execution_space > local
Struct holding all information for one particle.
constexpr auto const & id() const
constexpr bool is_ghost() const