30#include "system/System.hpp"
36#include <boost/mpi/collectives/all_gather.hpp>
37#include <boost/mpi/collectives/all_reduce.hpp>
38#include <boost/mpi/collectives/gather.hpp>
39#include <boost/mpi/collectives/reduce.hpp>
40#include <boost/mpi/collectives/scatter.hpp>
50#include <unordered_map>
51#include <unordered_set>
91 throw std::runtime_error(
"Types may not be negative");
95 nonbonded_ias.make_particle_type_exist(type);
99 if (p.type() == type) {
130 auto it = kv.second.find(
p_id);
131 if (
it != kv.second.end()) {
135 assert(p->type() == kv.first);
164 "Particle not found");
191 ::comm_cart.recv(boost::mpi::any_source, boost::mpi::any_tag, result);
201 auto const p = get_cell_structure().get_local_particle(p_id);
202 assert(p != nullptr);
224 std::vector<Particle>
parts(ids.size());
232 for (
auto const &
p_id : ids) {
241 static std::vector<int>
ignore;
249 std::size<std::vector<int>>);
263 static std::vector<int> ids;
265 auto out_ids = std::back_inserter(ids);
284 static std::vector<int>
sendbuf;
287 auto const n_part =
static_cast<int>(local_particles.size());
288 boost::mpi::gather(
comm_cart, n_part, 0);
297 std::transform(local_particles.begin(), local_particles.end(),
309 static std::vector<int>
n_parts;
310 boost::mpi::gather(
comm_cart,
static_cast<int>(local_particles.size()),
313 static std::vector<int>
pdata;
320 for (
auto const &p : local_particles) {
357 throw std::domain_error(
"Invalid particle id: " + std::to_string(
p_id));
367 throw std::runtime_error(
"Particle node for id " + std::to_string(
p_id) +
375 throw std::domain_error(
"Invalid particle id: " + std::to_string(
p_id));
390 throw std::runtime_error(
"Particle node for id " + std::to_string(
p_id) +
416 return std::accumulate(
418 [](
int max,
auto const &kv) { return std::max(max, kv.first); });
434 new_part.id() =
p_id;
436 new_part.image_box() = image_box;
450 auto const &box_geo = *
system.box_geo;
451 auto p =
system.cell_structure->get_local_particle(
p_id);
459 p->image_box() = image_box;
474 if (p !=
nullptr and not p->is_ghost()) {
535 throw std::runtime_error(
"Particle node for id " + std::to_string(
p_id) +
543 throw std::runtime_error(
"The provided particle type " +
544 std::to_string(type) +
545 " is currently not tracked by the system.");
549 throw std::runtime_error(
"The provided index exceeds the number of "
550 "particle types listed in the particle_type_map");
560 throw std::runtime_error(
"The provided particle type " +
561 std::to_string(type) +
562 " is currently not tracked by the system.");
565 return static_cast<int>(
it->second.size());
578 std::vector<int>
pids{};
580 std::ranges::sort(
pids);
589 std::vector<int>
pids{};
#define REGISTER_CALLBACK(cb)
Register a static callback without return value.
Vector implementation and trait types for boost qvm interoperability.
This file contains everything related to the global cell structure / cell system.
auto call_all(void(*fp)(Args...), ArgRef &&...args) const
Call a callback on all nodes.
void on_particle_change()
Called every time a particle property changes.
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< BoxGeometry > box_geo
std::shared_ptr< InteractionsNonBonded > nonbonded_ias
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
MpiCallbacks & mpiCallbacks()
Returns a reference to the global callback class instance.
void gatherv(const boost::mpi::communicator &comm, const T *in_values, int in_size, T *out_values, const int *sizes, const int *displs, int root)
std::size_t const max_cache_size
Utils::Cache< int, Particle > particle_fetch_cache(max_cache_size)
Various procedures concerning interactions between particles.
std::vector< int > get_particle_ids_parallel()
static int max_seen_pid
Keep track of the largest particle id.
static void add_id_to_type_map(int p_id, int type)
static bool maybe_move_particle(int p_id, Utils::Vector3d const &pos)
Move particle to a new position.
static void build_particle_node()
Rebuild the particle index.
void make_new_particle(int p_id, Utils::Vector3d const &pos)
Create a new particle and attach it to a cell.
const Particle & get_particle_data(int p_id)
Get particle data.
static std::unordered_map< int, int > particle_node
Mapping particle ids to MPI ranks.
int get_particle_node(int p_id)
Get the MPI rank which owns the a specific particle.
int number_of_particles_with_type(int type)
void set_particle_pos(int p_id, Utils::Vector3d const &pos)
Move particle to a new position.
void init_type_map(int type)
static void remove_id_from_map(int p_id, int type)
static void mpi_synchronize_max_seen_pid_local()
void remove_all_particles()
Remove all particles.
int get_random_p_id(int type, int random_index_in_type_map)
Find a particle of given type and return its id.
static int calculate_max_seen_id()
Calculate the largest particle id.
void remove_particle(int p_id)
Remove particle with a given identity.
static void mpi_get_particles_local()
static void mpi_who_has_head()
static std::vector< Particle > mpi_get_particles(std::span< const int > ids)
Get multiple particles at once.
int get_maximal_particle_id()
Get maximal particle id.
int get_particle_node_parallel(int p_id)
std::vector< int > get_particle_ids()
Get all particle ids.
std::size_t fetch_cache_max_size()
Return the maximal number of particles that are kept in the fetch cache.
void prefetch_particle_data(std::span< const int > in_ids)
Fetch a range of particle into the fetch cache.
void invalidate_fetch_cache()
Invalidate the fetch cache for get_particle_data.
static auto rebuild_needed()
static auto & get_cell_structure()
static void build_particle_node_parallel()
Rebuild the particle index.
static bool maybe_insert_particle(int p_id, Utils::Vector3d const &pos)
Create a new particle and attach it to a cell.
void clear_particle_node()
Invalidate particle_node.
static bool type_list_enable
Enable particle type tracking in particle_type_map.
static void mpi_who_has_local()
void on_particle_type_change(int p_id, int old_type, int new_type)
static void mpi_send_particle_data_local(int p_id)
int get_n_part()
Get number of particles.
static void clear_particle_type_map()
static std::unordered_map< int, std::unordered_set< int > > particle_type_map
Mapping particle types to lists of particle ids.
bool particle_exists(int p_id)
Check if particle exists.
Particles creation and deletion.
Struct holding all information for one particle.