Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple concurrent reaction methods #4609

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
core: Use O(N) algorithm instead of O(N^2)
  • Loading branch information
jngrad committed Dec 12, 2022
commit 72a029a501b48a61f3af06898004faeb18ae6d98
21 changes: 7 additions & 14 deletions src/core/reaction_methods/ReactionAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,24 +603,17 @@ bool ReactionAlgorithm::displacement_move_for_particles_of_type(int type,
* Cleans the list of empty pids and searches for empty pid in the system
*/
void ReactionAlgorithm::setup_bookkeeping_of_empty_pids() {

// Clean-up the list of empty pids
m_empty_p_ids_smaller_than_max_seen_particle = {};

// Loop from 0 to the maximum particle id in the system

std::vector<signed int> existing_ids = get_particle_ids();
int max_id = *max_element(std::begin(existing_ids), std::end(existing_ids));

for (int pid = 0; pid < max_id; pid++) {
// Search if the pid is in the system

if (std::find(existing_ids.begin(), existing_ids.end(), pid) ==
existing_ids.end()) {
// if the pid is not in the system, add it to the list of empty pids
m_empty_p_ids_smaller_than_max_seen_particle.clear();

auto particle_ids = get_particle_ids();
std::sort(particle_ids.begin(), particle_ids.end());
auto pid1 = -1;
for (auto pid2 : particle_ids) {
for (int pid = pid1 + 1; pid < pid2; ++pid) {
m_empty_p_ids_smaller_than_max_seen_particle.push_back(pid);
}
pid1 = pid2;
}
}

Expand Down
3 changes: 2 additions & 1 deletion testsuite/python/reaction_bookkeeping.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ReactionMethodsBookkeepingTest(ut.TestCase):
def setUpClass(cls):
cls.system.part.add(type=[cls.types["Na"]] * cls.N_SALT,
pos=np.random.rand(cls.N_SALT, 3) * cls.BOX_LENGTH,
q=[cls.charges["Na"]] * cls.N_SALT)
q=[cls.charges["Na"]] * cls.N_SALT,
id=list(range(20, 20 + cls.N_SALT)))
cls.system.part.add(type=[cls.types["Cl"]] * cls.N_SALT,
pos=np.random.rand(cls.N_SALT, 3) * cls.BOX_LENGTH,
q=[cls.charges["Cl"]] * cls.N_SALT)
Expand Down