30#include <boost/mpi/collectives/all_reduce.hpp>
47inline auto error_msg(std::string
const &name, std::string
const &reason) {
48 std::stringstream msg;
49 msg <<
"attribute '" << name <<
"' of 'ParticleHandle' " << reason;
56 throw std::domain_error(
"Invalid particle id: " + std::to_string(p_id));
59 if (ptr !=
nullptr and ptr->is_ghost()) {
62 auto const n_found = boost::mpi::all_reduce(
63 comm,
static_cast<int>(ptr !=
nullptr), std::plus<>());
65 throw std::runtime_error(
"Particle with id " + std::to_string(p_id) +
73 throw std::domain_error(
"Invalid particle id: " + std::to_string(p_id));
76 if (std::isnan(pos[0]) or std::isnan(pos[1]) or std::isnan(pos[2]) or
77 std::isinf(pos[0]) or std::isinf(pos[1]) or std::isinf(pos[2])) {
78 throw std::domain_error(
"Particle position must be finite");
83#ifdef ESPRESSO_EXCLUSIONS
120 throw std::runtime_error(
"Particles cannot exclude themselves (id " +
121 std::to_string(pid1) +
")");
131 mutable std::weak_ptr<CellSystem::CellSystem> m_cell_structure;
132 mutable std::weak_ptr<Interactions::BondedInteractions> m_bonded_ias;
133 mutable std::weak_ptr<::System::System> m_system;
135 auto ptr = m_cell_structure.lock();
136 assert(ptr !=
nullptr);
139 auto get_bonded_ias()
const {
140 auto ptr = m_bonded_ias.lock();
141 assert(ptr !=
nullptr);
144 auto get_system()
const {
145 auto ptr = m_system.lock();
146 assert(ptr !=
nullptr);
150 template <
typename T>
151 T get_particle_property(T
const &(
Particle::*getter)()
const)
const;
152 template <
typename T,
class F> T get_particle_property(F
const &fun)
const;
154 template <
typename T>
155 void set_particle_property(T &(
Particle::*setter)(),
158 template <
class F>
void set_particle_property(F
const &fun)
const;
160 void set_exclusions(
Variant const &value);
161 std::size_t setup_hidden_args(
VariantMap const ¶ms);
172 void attach(std::weak_ptr<::System::System> system) {
173 assert(m_system.expired());
182 auto const n_extra_args = setup_hidden_args(params);
184 throw std::logic_error(
185 "ParticleModifier is not meant to create new particles");
187 m_pid = params.contains(
"id") ?
get_value<int>(params,
"id") : -1;
197 if (
name ==
"remove_particle") {
198 throw std::logic_error(
"ParticleModifier has no method '" +
name +
"'");
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
std::string_view name() const
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
friend class ParticleModifier
void attach(std::weak_ptr<::System::System > system)
void do_construct(VariantMap const ¶ms) override
Thin wrapper to read and write particle attributes in batches.
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
void do_construct(VariantMap const ¶ms) override
void delete_exclusion(Particle &p, int p_id)
Remove exclusion from particle if possible.
void add_exclusion(Particle &p, int p_id)
Insert an exclusion if not already set.
auto get_real_particle(boost::mpi::communicator const &comm, int p_id, ::CellStructure &cell_structure)
void particle_exclusion_sanity_checks(int pid1, int pid2, ::CellStructure &cell_structure, auto const &comm)
void local_remove_exclusion(int pid1, int pid2, ::CellStructure &cell_structure)
Locally remove an exclusion to a particle.
void particle_checks(int p_id, Utils::Vector3d const &pos)
auto error_msg(std::string const &name, std::string const &reason)
void local_add_exclusion(int pid1, int pid2, ::CellStructure &cell_structure)
Locally add an exclusion to a particle.
make_recursive_variant< ObjectRef > Variant
Possible types for parameters.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
static auto & get_cell_structure()
Struct holding all information for one particle.