Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jean-Noël Grad <[email protected]>
  • Loading branch information
jhossbach and jngrad authored Apr 8, 2022
1 parent 1669db6 commit d039c79
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
11 changes: 6 additions & 5 deletions src/core/CellStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,12 @@ struct CellStructure {
* @brief Run kernel on all particles inside cell and neighbors.
*
* @param p Particle to identify cell and neighbors
* @param kernel Function with (Particle, Particle, Vector)
* @return false if cell is not found via particle_to_cell, otherwise true
* @param kernel Function with signature <tt>double(Particle, Particle, Vector)</tt>
* @return false if cell is not found via @ref particle_to_cell, otherwise true
*/
template <class Kernel>
bool run_on_particle_short_range_neighbors(Particle const &p, Kernel kernel) {
bool run_on_particle_short_range_neighbors(Particle const &p,
Kernel &kernel) {
auto const cell = find_current_cell(p);

if (cell == nullptr) {
Expand All @@ -694,8 +695,8 @@ struct CellStructure {

private:
template <class Kernel, class DistanceFunc>
void short_range_neighbor_loop(Particle const &p, Cell *cell, Kernel kernel,
DistanceFunc df) {
void short_range_neighbor_loop(Particle const &p, Cell *const cell,
Kernel &kernel, DistanceFunc const &df) {
/* Iterate over particles inside cell */
for (auto const &part : cell->particles()) {
if (&part == &p) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ mpi_get_short_range_neighbors_local(int const pid, double const distance) {
auto kernel = [&ret, cutoff2](Particle const &p, Particle const &p1,
Utils::Vector3d const &vec) {
if (vec.norm2() < cutoff2) {
ret.emplace_back(p1.p.identity);
};
ret.emplace_back(p1.id());
}
};
cell_structure.run_on_particle_short_range_neighbors(*p, kernel);
return ret;
Expand Down
9 changes: 6 additions & 3 deletions src/core/energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ double particle_short_range_energy_contribution_local(int pid) {
if (p) {
auto kernel = [&ret](Particle const &p, Particle const &p1,
Utils::Vector3d const &vec) {
auto const dist = sqrt(vec.norm2());
auto const &ia_params = *get_ia_param(p.p.type, p1.p.type);
#ifdef EXCLUSIONS
if (not do_nonbonded(p, p1))
return;
#endif
auto const &ia_params = *get_ia_param(p.type(), p1.type());
// Add energy for current particle pair to result
ret += calc_non_bonded_pair_energy(p, p1, ia_params, vec, dist);
ret += calc_non_bonded_pair_energy(p, p1, ia_params, vec, vec.norm());
};
cell_structure.run_on_particle_short_range_neighbors(*p, kernel);
}
Expand Down
7 changes: 4 additions & 3 deletions src/python/espressomd/analyze.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,18 @@ class Analysis:
utils.handle_errors("calculate_energy() failed")
return obs

def particle_energy(self, ParticleHandle particle):
def particle_energy(self, particle):
"""
Calculate the non-bonded energy of a single given particle.
Parameters
----------
particle : :attr:`~espressomd.particle_data.ParticleHandle.type`
particle : :class:`~espressomd.particle_data.ParticleHandle`
Returns
-------
:obj: `float` non-bonded energy of that particle
:obj: `float`
non-bonded energy of that particle
"""
energy_contribution = particle_short_range_energy_contribution(
Expand Down
5 changes: 0 additions & 5 deletions src/python/espressomd/cellsystem.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ cdef extern from "CellStructureType.hpp":
CELL_STRUCTURE_REGULAR "CellStructureType::CELL_STRUCTURE_REGULAR"
CELL_STRUCTURE_NSQUARE "CellStructureType::CELL_STRUCTURE_NSQUARE"

cdef extern from "particle_data.hpp":
ctypedef struct particle "Particle"
const particle & get_particle_data(int pid) except +


cdef extern from "cells.hpp":
ctypedef struct CellStructure:
CellStructureType decomposition_type()
Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/cellsystem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ cdef class CellSystem:
handle_errors("Error in get_pairs()")
return pairs

def get_neighbors(self, ParticleHandle particle, distance):
def get_neighbors(self, particle, distance):
"""
Get neighbors of a given particle up to distance
Parameters
----------
particle : :attr:`~espressomd.particle_data.ParticleHandle.type`
particle : :class:`~espressomd.particle_data.ParticleHandle`
distance : :obj:`float`
Pairs of particles closer than ``distance`` are found.
Expand Down

0 comments on commit d039c79

Please sign in to comment.