![]() |
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
|
#include "particle_node.hpp"#include "BoxGeometry.hpp"#include "Particle.hpp"#include "cell_system/CellStructure.hpp"#include "cells.hpp"#include "communication.hpp"#include "nonbonded_interactions/nonbonded_interaction_data.hpp"#include "system/System.hpp"#include <utils/Cache.hpp>#include <utils/Vector.hpp>#include <utils/mpi/gatherv.hpp>#include <boost/mpi/collectives/all_gather.hpp>#include <boost/mpi/collectives/all_reduce.hpp>#include <boost/mpi/collectives/gather.hpp>#include <boost/mpi/collectives/reduce.hpp>#include <boost/mpi/collectives/scatter.hpp>#include <algorithm>#include <cmath>#include <functional>#include <iterator>#include <ranges>#include <span>#include <stdexcept>#include <string>#include <unordered_map>#include <unordered_set>#include <utility>#include <vector>
Include dependency graph for particle_node.cpp:Go to the source code of this file.
Namespaces | |
| namespace | anonymous_namespace{particle_node.cpp} |
Variables | |
| constexpr auto | some_tag = 42 |
| static bool | type_list_enable |
| Enable particle type tracking in particle_type_map. | |
| static std::unordered_map< int, std::unordered_set< int > > | particle_type_map |
| Mapping particle types to lists of particle ids. | |
| static std::unordered_map< int, int > | particle_node |
| Mapping particle ids to MPI ranks. | |
| static int | max_seen_pid = -1 |
| Keep track of the largest particle id. | |
| std::size_t const | anonymous_namespace{particle_node.cpp}::max_cache_size = (100ul * 1048576ul) / sizeof(Particle) |
| Utils::Cache< int, Particle > | anonymous_namespace{particle_node.cpp}::particle_fetch_cache (max_cache_size) |
Definition at line 120 of file particle_node.cpp.
References particle_type_map, and stream.
Referenced by on_particle_type_change().
Rebuild the particle index.
Definition at line 339 of file particle_node.cpp.
References mpi_who_has_head(), mpi_who_has_local(), and Communication::mpiCallbacks().
Referenced by get_n_part(), get_particle_ids(), get_particle_node(), and particle_exists().
Rebuild the particle index.
Definition at line 347 of file particle_node.cpp.
References mpi_who_has_head(), mpi_who_has_local(), and this_node.
Referenced by get_maximal_particle_id(), get_particle_ids_parallel(), get_particle_node_parallel(), and make_new_particle().
Calculate the largest particle id.
Traversing the particle_node to find the largest particle id scales with O(N). Consider using the cached value in max_seen_pid if possible. This function is only necessary when the cached value is invalidated, for example when removing the particle which has the largest id.
Definition at line 415 of file particle_node.cpp.
References particle_node.
Referenced by remove_particle().
| void clear_particle_node | ( | ) |
Invalidate particle_node.
This has to be done at the beginning of the integration.
Definition at line 396 of file particle_node.cpp.
References max_seen_pid, and particle_node.
Referenced by System::System::on_cell_structure_change(), System::System::on_observable_calc(), and remove_all_particles().
Definition at line 401 of file particle_node.cpp.
References particle_type_map.
Referenced by remove_all_particles().
| std::size_t fetch_cache_max_size | ( | ) |
Return the maximal number of particles that are kept in the fetch cache.
Definition at line 157 of file particle_node.cpp.
References anonymous_namespace{particle_node.cpp}::particle_fetch_cache.
Definition at line 66 of file particle_node.cpp.
References System::System::cell_structure, and System::get_system().
Referenced by ScriptInterface::Particles::ParticleHandle::do_call_method(), ScriptInterface::Particles::ParticleHandle::do_construct(), get_particle_data(), init_type_map(), maybe_insert_particle(), mpi_send_particle_data_local(), mpi_who_has_head(), mpi_who_has_local(), on_particle_type_change(), remove_all_particles(), remove_particle(), and set_particle_pos().
| int get_maximal_particle_id | ( | ) |
Get maximal particle id.
Definition at line 595 of file particle_node.cpp.
References build_particle_node_parallel(), max_seen_pid, and rebuild_needed().
Referenced by ReactionMethods::ReactionAlgorithm::delete_particle(), ScriptInterface::Particles::ParticleList::do_call_method(), and ScriptInterface::Particles::ParticleHandle::do_construct().
| int get_n_part | ( | ) |
Get number of particles.
Definition at line 603 of file particle_node.cpp.
References build_particle_node(), and particle_node.
Referenced by ScriptInterface::Particles::ParticleList::do_call_method().
Get particle data.
| p_id | the identity of the particle to fetch |
Definition at line 172 of file particle_node.cpp.
References Communication::MpiCallbacks::call_all(), comm_cart, get_cell_structure(), get_particle_node(), mpi_send_particle_data_local(), Communication::mpiCallbacks(), anonymous_namespace{particle_node.cpp}::particle_fetch_cache, stream, and this_node.
Referenced by ClusterAnalysis::Cluster::center_of_mass_subcluster(), PairCriteria::PairCriterion::decide(), ScriptInterface::Particles::ParticleHandle::do_call_method(), ClusterAnalysis::Cluster::fractal_dimension(), ClusterAnalysis::Cluster::longest_distance(), ScriptInterface::Particles::ParticleHandle::ParticleHandle(), ClusterAnalysis::Cluster::radius_of_gyration_subcluster(), and ClusterAnalysis::ClusterStructure::run_for_bonded_particles().
| std::vector< int > get_particle_ids | ( | ) |
Get all particle ids.
Definition at line 574 of file particle_node.cpp.
References build_particle_node(), particle_node, and stream.
Referenced by ScriptInterface::Particles::ParticleList::do_call_method(), ScriptInterface::System::System::get_internal_state(), and ScriptInterface::System::System::set_internal_state().
| std::vector< int > get_particle_ids_parallel | ( | ) |
Definition at line 585 of file particle_node.cpp.
References build_particle_node_parallel(), comm_cart, particle_node, rebuild_needed(), and stream.
Referenced by ReactionMethods::ReactionAlgorithm::setup_bookkeeping_of_empty_pids().
Get the MPI rank which owns the a specific particle.
| p_id | identity of the particle |
Definition at line 355 of file particle_node.cpp.
References build_particle_node(), particle_node, and stream.
Referenced by get_particle_data(), mpi_get_particles(), ScriptInterface::Particles::ParticleHandle::ParticleHandle(), and prefetch_particle_data().
Definition at line 373 of file particle_node.cpp.
References build_particle_node_parallel(), particle_node, rebuild_needed(), stream, and this_node.
Find a particle of given type and return its id.
Definition at line 540 of file particle_node.cpp.
References comm_cart, particle_type_map, and stream.
Referenced by ReactionMethods::ReactionAlgorithm::displacement_mc_move(), and ReactionMethods::ReactionAlgorithm::make_reaction_attempt().
Definition at line 89 of file particle_node.cpp.
References comm_cart, get_cell_structure(), System::get_system(), System::System::nonbonded_ias, particle_type_map, stream, and type_list_enable.
Referenced by ReactionMethods::ReactionAlgorithm::add_reaction(), ScriptInterface::System::System::do_call_method(), and ScriptInterface::ReactionMethods::ReactionAlgorithm::do_call_method().
| void invalidate_fetch_cache | ( | ) |
Invalidate the fetch cache for get_particle_data.
Definition at line 156 of file particle_node.cpp.
References anonymous_namespace{particle_node.cpp}::particle_fetch_cache.
Referenced by System::System::on_integration_start(), and System::System::on_particle_change().
| void make_new_particle | ( | int | p_id, |
| Utils::Vector3d const & | pos | ||
| ) |
Create a new particle and attach it to a cell.
| p_id | The identity of the particle to create. |
| pos | The particle position. |
Definition at line 509 of file particle_node.cpp.
References build_particle_node_parallel(), comm_cart, System::get_system(), max_seen_pid, maybe_insert_particle(), mpi_synchronize_max_seen_pid_local(), System::System::on_particle_change(), particle_node, rebuild_needed(), stream, and this_node.
Referenced by ScriptInterface::Particles::ParticleHandle::do_construct().
|
static |
Create a new particle and attach it to a cell.
| p_id | The identity of the particle to create. |
| pos | The particle position. |
Definition at line 427 of file particle_node.cpp.
References System::System::box_geo, get_cell_structure(), System::get_system(), and stream.
Referenced by make_new_particle().
|
static |
Move particle to a new position.
| p_id | The identity of the particle to move. |
| pos | The new particle position. |
Definition at line 448 of file particle_node.cpp.
References System::get_system(), and stream.
Referenced by set_particle_pos().
Get multiple particles at once.
WARNING Particles are returned in an arbitrary order.
| ids | The ids of the particles that should be returned. |
Definition at line 221 of file particle_node.cpp.
References comm_cart, Utils::Mpi::gatherv(), get_particle_node(), mpi_get_particles_local(), Communication::mpiCallbacks(), stream, and this_node.
Referenced by prefetch_particle_data().
Definition at line 195 of file particle_node.cpp.
References comm_cart, Utils::Mpi::gatherv(), and stream.
Referenced by mpi_get_particles().
Definition at line 159 of file particle_node.cpp.
References comm_cart, get_cell_structure(), and stream.
Referenced by get_particle_data().
Definition at line 85 of file particle_node.cpp.
References comm_cart, and max_seen_pid.
Referenced by make_new_particle(), mpi_who_has_head(), mpi_who_has_local(), and remove_particle().
Definition at line 306 of file particle_node.cpp.
References comm_cart, get_cell_structure(), max_seen_pid, mpi_synchronize_max_seen_pid_local(), particle_node, some_tag, stream, and this_node.
Referenced by build_particle_node(), and build_particle_node_parallel().
Definition at line 283 of file particle_node.cpp.
References comm_cart, get_cell_structure(), mpi_synchronize_max_seen_pid_local(), some_tag, and stream.
Referenced by build_particle_node(), and build_particle_node_parallel().
Definition at line 557 of file particle_node.cpp.
References particle_type_map, and stream.
Referenced by ReactionMethods::ReactionAlgorithm::all_reactant_particles_exist(), ReactionMethods::ReactionAlgorithm::displacement_mc_move(), ReactionMethods::ReactionAlgorithm::make_displacement_mc_move_attempt(), and ReactionMethods::ReactionAlgorithm::make_reaction_attempt().
Definition at line 126 of file particle_node.cpp.
References add_id_to_type_map(), type_tracking::any_type, get_cell_structure(), type_tracking::new_part, particle_type_map, remove_id_from_map(), stream, and type_list_enable.
Referenced by ReactionMethods::ReactionAlgorithm::make_reaction_attempt(), ScriptInterface::Particles::ParticleHandle::ParticleHandle(), ReactionMethods::ReactionAlgorithm::restore_old_system_state(), and ScriptInterface::Particles::set_particles_types().
Check if particle exists.
| p_id | identity of the particle |
Definition at line 568 of file particle_node.cpp.
References build_particle_node(), particle_node, and stream.
Referenced by ScriptInterface::Particles::ParticleList::do_call_method(), and ScriptInterface::Particles::ParticleSlice::do_construct().
Fetch a range of particle into the fetch cache.
If the range is larger than the cache size, only the particle that fit into the cache are fetched.
The particles have to exist, an exception it throw if one of the the particles can not be found.
| ids | Ids of the particles that should be fetched. |
Definition at line 257 of file particle_node.cpp.
References comm_cart, get_particle_node(), mpi_get_particles(), anonymous_namespace{particle_node.cpp}::particle_fetch_cache, stream, and this_node.
Referenced by ScriptInterface::Particles::ParticleSlice::do_call_method().
Definition at line 79 of file particle_node.cpp.
References comm_cart, particle_node, and stream.
Referenced by get_maximal_particle_id(), get_particle_ids_parallel(), get_particle_node_parallel(), and make_new_particle().
| void remove_all_particles | ( | ) |
Remove all particles.
Definition at line 463 of file particle_node.cpp.
References clear_particle_node(), clear_particle_type_map(), get_cell_structure(), System::get_system(), and System::System::on_particle_change().
Referenced by ScriptInterface::Particles::ParticleList::do_call_method().
Definition at line 114 of file particle_node.cpp.
References particle_type_map, and stream.
Referenced by on_particle_type_change(), and remove_particle().
Remove particle with a given identity.
Also removes all bonds to the particle.
| p_id | identity of the particle to remove |
Definition at line 470 of file particle_node.cpp.
References calculate_max_seen_id(), comm_cart, get_cell_structure(), System::get_system(), max_seen_pid, mpi_synchronize_max_seen_pid_local(), System::System::on_particle_change(), particle_node, remove_id_from_map(), stream, this_node, and type_list_enable.
Referenced by ReactionMethods::ReactionAlgorithm::delete_particle(), ScriptInterface::Particles::ParticleHandle::do_call_method(), and ScriptInterface::Particles::ParticleHandle::do_construct().
| void set_particle_pos | ( | int | p_id, |
| Utils::Vector3d const & | pos | ||
| ) |
Move particle to a new position.
| p_id | The identity of the particle to move. |
| pos | The new particle position. |
Definition at line 527 of file particle_node.cpp.
References comm_cart, get_cell_structure(), System::get_system(), maybe_move_particle(), System::System::on_particle_change(), Cells::RESORT_GLOBAL, stream, and this_node.
Referenced by ReactionMethods::ReactionAlgorithm::displacement_mc_move(), ScriptInterface::Particles::ParticleHandle::ParticleHandle(), and ScriptInterface::Particles::set_particles_positions().
|
static |
Keep track of the largest particle id.
This book-keeping variable is necessary to make particle insertion run in constant time. Traversing the particle_node to find the largest particle id scales with O(N) and traversing the local cells in parallel followed by a reduction scales with O(N^2).
Definition at line 77 of file particle_node.cpp.
Referenced by clear_particle_node(), get_maximal_particle_id(), make_new_particle(), mpi_synchronize_max_seen_pid_local(), mpi_who_has_head(), and remove_particle().
Mapping particle ids to MPI ranks.
Definition at line 64 of file particle_node.cpp.
Referenced by calculate_max_seen_id(), clear_particle_node(), get_n_part(), get_particle_ids(), get_particle_ids_parallel(), get_particle_node(), get_particle_node_parallel(), make_new_particle(), mpi_who_has_head(), particle_exists(), rebuild_needed(), and remove_particle().
Mapping particle types to lists of particle ids.
Definition at line 61 of file particle_node.cpp.
Referenced by add_id_to_type_map(), clear_particle_type_map(), get_random_p_id(), init_type_map(), number_of_particles_with_type(), on_particle_type_change(), and remove_id_from_map().
Definition at line 55 of file particle_node.cpp.
Referenced by mpi_who_has_head(), and mpi_who_has_local().
|
static |
Enable particle type tracking in particle_type_map.
Definition at line 58 of file particle_node.cpp.
Referenced by init_type_map(), on_particle_type_change(), and remove_particle().