Skip to content

Commit

Permalink
core: Split of non-head-node exclusion code
Browse files Browse the repository at this point in the history
  • Loading branch information
fweik committed Mar 13, 2020
1 parent ca597e8 commit e3b2c01
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set(EspressoCore_SRC
thermostat.cpp
tuning.cpp
virtual_sites.cpp
)
exclusions.cpp)

if(CUDA)
set(EspressoCuda_SRC
Expand Down
47 changes: 47 additions & 0 deletions src/core/bonded_interactions/bonded_interaction_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "bonded_interaction_data.hpp"
#include "communication.hpp"

#include <boost/range/algorithm/copy.hpp>
#include <boost/range/numeric.hpp>

#include <utils/constants.hpp>

std::vector<Bonded_ia_parameters> bonded_ia_params;
Expand Down Expand Up @@ -146,3 +148,48 @@ void remove_all_bonds_to(Particle &p, int id) {
}
assert(i == bl->n);
}

void add_bond(Particle &p, Utils::Span<const int> bond) {
boost::copy(bond, std::back_inserter(p.bl));
}

int delete_bond(Particle *part, const int *bond) {
IntList *bl = &part->bl;
int i, j, type, partners;

// Empty bond means: delete all bonds
if (!bond) {
bl->clear();

return ES_OK;
}

// Go over the bond list to find the bond to delete
for (i = 0; i < bl->n;) {
type = bl->e[i];
partners = bonded_ia_params[type].num;

// If the bond type does not match the one, we want to delete, skip
if (type != bond[0])
i += 1 + partners;
else {
// Go over the bond partners
for (j = 1; j <= partners; j++) {
// Leave the loop early, if the bond to delete and the bond with in the
// particle don't match
if (bond[j] != bl->e[i + j])
break;
}
// If we did not exit from the loop early, all parameters matched
// and we go on with deleting
if (j > partners) {
// New length of bond list
bl->erase(bl->begin() + i, bl->begin() + i + 1 + partners);

return ES_OK;
}
i += 1 + partners;
}
}
return ES_ERROR;
}
2 changes: 0 additions & 2 deletions src/core/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include "event.hpp"
#include "grid.hpp"
#include "nonbonded_interactions/nonbonded_interaction_data.hpp"
#include "particle_data.hpp"
#include "particle_index.hpp"
#include "rotation.hpp"
#include "virtual_sites/VirtualSitesRelative.hpp"

#include <utils/mpi/all_compare.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "electrostatics_magnetostatics/dipole.hpp"
#include "errorhandling.hpp"
#include "grid.hpp"
#include "nonbonded_interactions/nonbonded_interaction_data.hpp"
#include "particle_data.hpp"

#include <utils/constants.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/core/energy_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include "bonded_interactions/bonded_coulomb_sr.hpp"
#include "electrostatics_magnetostatics/coulomb_inline.hpp"
#endif
#include "particle_data.hpp"
#include "exclusions.hpp"
#include "particle_index.hpp"
#include "statistics.hpp"

Expand Down
19 changes: 19 additions & 0 deletions src/core/exclusions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "exclusions.hpp"

#ifdef EXCLUSIONS
void add_exclusion(Particle *part, int part2) {
for (int i = 0; i < part->el.n; i++)
if (part->el.e[i] == part2)
return;

part->el.push_back(part2);
}

void delete_exclusion(Particle *part, int part2) {
IntList &el = part->el;

if (!el.empty()) {
el.erase(std::remove(el.begin(), el.end(), part2), el.end());
};
}
#endif
23 changes: 23 additions & 0 deletions src/core/exclusions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef ESPRESSO_EXCLUSIONS_HPP
#define ESPRESSO_EXCLUSIONS_HPP

#include "Particle.hpp"

#ifdef EXCLUSIONS
/** Determine if the non-bonded interactions between @p p1 and @p p2 should be
* calculated.
*/
inline bool do_nonbonded(Particle const &p1, Particle const &p2) {
/* check for particle 2 in particle 1's exclusion list. The exclusion list is
* symmetric, so this is sufficient. */
return std::none_of(p1.el.begin(), p1.el.end(),
[&p2](int id) { return p2.p.identity == id; });
}

/** Remove exclusion from particle if possible */
void delete_exclusion(Particle *part, int part2);

/** Insert an exclusion if not already set */
void add_exclusion(Particle *part, int part2);
#endif
#endif // ESPRESSO_EXCLUSIONS_HPP
2 changes: 1 addition & 1 deletion src/core/forces_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "bonded_interactions/thermalized_bond.hpp"
#include "bonded_interactions/umbrella.hpp"
#include "errorhandling.hpp"
#include "exclusions.hpp"
#include "forces.hpp"
#include "immersed_boundary/ibm_tribend.hpp"
#include "immersed_boundary/ibm_triel.hpp"
Expand All @@ -59,7 +60,6 @@
#include "npt.hpp"
#include "object-in-fluid/oif_global_forces.hpp"
#include "object-in-fluid/oif_local_forces.hpp"
#include "particle_data.hpp"
#include "particle_index.hpp"
#include "rotation.hpp"
#include "thermostat.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/core/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "nonbonded_interactions/nonbonded_interaction_data.hpp"
#include "npt.hpp"
#include "object-in-fluid/oif_global_forces.hpp"
#include "particle_data.hpp"
#include "rattle.hpp"
#include "thermostat.hpp"
#include "tuning.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/core/grid_based_algorithms/lbgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "grid_based_algorithms/lbgpu.hpp"
#include "integrate.hpp"
#include "nonbonded_interactions/nonbonded_interaction_data.hpp"
#include "particle_data.hpp"
#include "statistics.hpp"

#include <utils/constants.hpp>
Expand Down
2 changes: 2 additions & 0 deletions src/core/pair_criteria/pair_criteria.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "Particle.hpp"
#include "energy_inline.hpp"
#include "particle_data.hpp"

#include <stdexcept>

namespace PairCriteria {
Expand Down
75 changes: 6 additions & 69 deletions src/core/particle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ std::unordered_map<int, int> particle_node;

int delete_bond(Particle *part, const int *bond);

void try_delete_exclusion(Particle *part, int part2);
void delete_exclusion(Particle *part, int part2);

void try_add_exclusion(Particle *part, int part2);
void add_exclusion(Particle *part, int part2);

void auto_exclusion(int distance);

Expand Down Expand Up @@ -955,51 +955,6 @@ void local_rescale_particles(int dir, double scale) {
}
}

void add_bond(Particle &p, Utils::Span<const int> bond) {
boost::copy(bond, std::back_inserter(p.bl));
}

int delete_bond(Particle *part, const int *bond) {
IntList *bl = &part->bl;
int i, j, type, partners;

// Empty bond means: delete all bonds
if (!bond) {
bl->clear();

return ES_OK;
}

// Go over the bond list to find the bond to delete
for (i = 0; i < bl->n;) {
type = bl->e[i];
partners = bonded_ia_params[type].num;

// If the bond type does not match the one, we want to delete, skip
if (type != bond[0])
i += 1 + partners;
else {
// Go over the bond partners
for (j = 1; j <= partners; j++) {
// Leave the loop early, if the bond to delete and the bond with in the
// particle don't match
if (bond[j] != bl->e[i + j])
break;
}
// If we did not exit from the loop early, all parameters matched
// and we go on with deleting
if (j > partners) {
// New length of bond list
bl->erase(bl->begin() + i, bl->begin() + i + 1 + partners);

return ES_OK;
}
i += 1 + partners;
}
}
return ES_ERROR;
}

#ifdef EXCLUSIONS
void local_change_exclusion(int part1, int part2, int _delete) {
if (part1 == -1 && part2 == -1) {
Expand All @@ -1014,39 +969,21 @@ void local_change_exclusion(int part1, int part2, int _delete) {
auto part = get_local_particle_data(part1);
if (part) {
if (_delete)
try_delete_exclusion(part, part2);
delete_exclusion(part, part2);
else
try_add_exclusion(part, part2);
add_exclusion(part, part2);
}

/* part2, if here */
part = get_local_particle_data(part2);
if (part) {
if (_delete)
try_delete_exclusion(part, part1);
delete_exclusion(part, part1);
else
try_add_exclusion(part, part1);
add_exclusion(part, part1);
}
}

void try_add_exclusion(Particle *part, int part2) {
for (int i = 0; i < part->el.n; i++)
if (part->el.e[i] == part2)
return;

part->el.push_back(part2);
}

void try_delete_exclusion(Particle *part, int part2) {
IntList &el = part->el;

if (!el.empty()) {
el.erase(std::remove(el.begin(), el.end(), part2), el.end());
};
}
#endif

#ifdef EXCLUSIONS
namespace {
/* keep a unique list for particle i. Particle j is only added if it is not i
and not already in the list. */
Expand Down
18 changes: 0 additions & 18 deletions src/core/particle_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,24 +384,6 @@ void local_remove_all_particles();
*/
void local_rescale_particles(int dir, double scale);

#ifdef EXCLUSIONS
/** Determine if the non-bonded interactions between @p p1 and @p p2 should be
* calculated.
*/
inline bool do_nonbonded(Particle const &p1, Particle const &p2) {
/* check for particle 2 in particle 1's exclusion list. The exclusion list is
* symmetric, so this is sufficient. */
return std::none_of(p1.el.begin(), p1.el.end(),
[&p2](int id) { return p2.p.identity == id; });
}
#endif

/** Remove exclusion from particle if possible */
void try_delete_exclusion(Particle *part, int part2);

/** Insert an exclusion if not already set */
void try_add_exclusion(Particle *part, int part2);

/** Automatically add the next \<distance\> neighbors in each molecule to the
* exclusion list.
* This uses the bond topology obtained directly from the particles.
Expand Down
1 change: 1 addition & 0 deletions src/core/pressure_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef CORE_PRESSURE_INLINE_HPP
#define CORE_PRESSURE_INLINE_HPP

#include "exclusions.hpp"
#include "forces_inline.hpp"
#include "integrate.hpp"
#include "npt.hpp"
Expand Down

0 comments on commit e3b2c01

Please sign in to comment.