Skip to content

Commit

Permalink
Make particle property setters MPI-parallel
Browse files Browse the repository at this point in the history
Co-authored-by: Jean-Noël Grad <[email protected]>
  • Loading branch information
pkreissl and jngrad committed Jan 25, 2023
1 parent 6508848 commit 5d7087e
Show file tree
Hide file tree
Showing 27 changed files with 906 additions and 1,145 deletions.
15 changes: 7 additions & 8 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ struct Particle { // NOLINT(bugprone-exception-escape)
constexpr auto &mass() const { return p.mass; }
#endif
#ifdef ROTATION
auto const &rotation() const { return p.rotation; }
auto &rotation() { return p.rotation; }
auto rotation() const { return p.rotation; }
bool can_rotate() const { return static_cast<bool>(p.rotation); }
bool can_rotate_around(int const axis) const {
detail::check_axis_idx_valid(axis);
Expand Down Expand Up @@ -498,8 +498,8 @@ struct Particle { // NOLINT(bugprone-exception-escape)
#endif // EXTERNAL_FORCES
auto calc_director() const { return r.calc_director(); }
#else // ROTATION
bool can_rotate() const { return false; }
bool can_rotate_around(int const axis) const { return false; }
auto can_rotate() const { return false; }
auto can_rotate_around(int const axis) const { return false; }
#endif // ROTATION
#ifdef DIPOLES
auto const &dipm() const { return p.dipm; }
Expand All @@ -523,8 +523,9 @@ struct Particle { // NOLINT(bugprone-exception-escape)
auto &mu_E() { return p.mu_E; }
#endif
#ifdef VIRTUAL_SITES
bool &virtual_flag() { return p.is_virtual; }
bool is_virtual() const { return p.is_virtual; }
auto &virtual_flag() { return p.is_virtual; }
auto const &virtual_flag() const { return p.is_virtual; }
auto is_virtual() const { return p.is_virtual; }
void set_virtual(bool const virt_flag) { p.is_virtual = virt_flag; }
#ifdef VIRTUAL_SITES_RELATIVE
auto const &vs_relative() const { return p.vs_relative; }
Expand All @@ -542,6 +543,7 @@ struct Particle { // NOLINT(bugprone-exception-escape)
#endif // ROTATION
#endif // THERMOSTAT_PER_PARTICLE
#ifdef EXTERNAL_FORCES
auto const &fixed() const { return p.ext_flag; }
auto &fixed() { return p.ext_flag; }
bool has_fixed_coordinates() const { return static_cast<bool>(p.ext_flag); }
bool is_fixed_along(int const axis) const {
Expand Down Expand Up @@ -578,9 +580,6 @@ struct Particle { // NOLINT(bugprone-exception-escape)
#ifdef EXCLUSIONS
Utils::compact_vector<int> &exclusions() { return el; }
Utils::compact_vector<int> const &exclusions() const { return el; }
std::vector<int> const exclusions_as_vector() const {
return {el.begin(), el.end()};
}
bool has_exclusion(int pid) const {
return std::find(el.begin(), el.end(), pid) != el.end();
}
Expand Down
42 changes: 34 additions & 8 deletions src/core/bond_breakage/bond_breakage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "cells.hpp"
#include "communication.hpp"
#include "errorhandling.hpp"
#include "event.hpp"
#include "particle_data.hpp"

#include <utils/mpi/gather_buffer.hpp>
Expand Down Expand Up @@ -153,20 +154,45 @@ ActionSet actions_for_breakage(QueueEntry const &e) {
return {};
}

/**
* @brief Delete specific bond.
*/
static void remove_bond(Particle &p, BondView const &view) {
auto &bond_list = p.bonds();
auto it = std::find(bond_list.begin(), bond_list.end(), view);
if (it != bond_list.end()) {
bond_list.erase(it);
}
}

/**
* @brief Delete pair bonds to a specific partner
*/
static void remove_pair_bonds_to(Particle &p, int other_pid) {
std::vector<std::pair<int, int>> to_delete;
for (auto b : p.bonds()) {
if (b.partner_ids().size() == 1 and b.partner_ids()[0] == other_pid)
to_delete.emplace_back(std::pair<int, int>{b.bond_id(), other_pid});
}
for (auto const &b : to_delete) {
remove_bond(p, BondView(b.first, {&b.second, 1}));
}
}

// Handler for the different delete events
class execute : public boost::static_visitor<> {
public:
void operator()(DeleteBond const &d) const {
auto p = cell_structure.get_local_particle(d.particle_id);
if (!p)
return;
local_remove_bond(*p, {d.bond_type, d.bond_partner_id});
if (auto p = ::cell_structure.get_local_particle(d.particle_id)) {
remove_bond(*p, BondView(d.bond_type, {&d.bond_partner_id, 1}));
}
on_particle_change();
}
void operator()(DeleteAllBonds const &d) const {
auto p = cell_structure.get_local_particle(d.particle_id_1);
if (!p)
return;
local_remove_pair_bonds_to(*p, d.particle_id_2);
if (auto p = ::cell_structure.get_local_particle(d.particle_id_1)) {
remove_pair_bonds_to(*p, d.particle_id_2);
}
on_particle_change();
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/core/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ void place_vs_and_relate_to_particle(const int current_vs_pid,
new_part.id() = current_vs_pid;
new_part.pos() = pos;
auto p_vs = cell_structure.add_particle(std::move(new_part));

local_vs_relate_to(*p_vs, get_part(relate_to));

vs_relate_to(*p_vs, get_part(relate_to));
p_vs->set_virtual(true);
p_vs->type() = collision_params.vs_particle_type;
}
Expand Down
Loading

0 comments on commit 5d7087e

Please sign in to comment.