59 std::vector<int>
const &pids, std::string
const ¶m_name,
60 Container
const &values,
Context *context,
61 std::shared_ptr<CellSystem::CellSystem> cell_structure,
62 std::shared_ptr<Interactions::BondedInteractions> bonded_ias) {
65 auto so = std::dynamic_pointer_cast<ParticleModifier>(context->
make_shared(
66 "Particles::ParticleModifier", {{
"id", -1},
67 {
"__cell_structure", cell_structure},
68 {
"__bonded_ias", bonded_ias}}));
69 for (std::size_t i = 0; i < pids.size(); ++i) {
71 so->do_set_parameter(param_name, values[i]);
74 throw Exception(
"Values must be of type vector, got " +
75 detail::demangle::simplify_symbol(&values));
82 std::function<T(
Particle const &)>
const &getter,
87 std::conditional_t<Variant::has_type<std::vector<T>>::value, T,
Variant>;
88 std::vector<value_type> result;
90 auto const n_ranks =
static_cast<std::size_t
>(context->
get_comm().size());
91 auto const size_hint = pids.size() / n_ranks;
92 std::vector<std::pair<int, T>> parameters;
93 parameters.reserve(size_hint);
94 for (
auto const &pid : pids) {
96 if (p and not p->is_ghost()) {
97 parameters.emplace_back(pid, getter(*p));
108 assert(parameters.size() == pids.size() &&
109 "Missing or duplicate particle ids");
110 std::unordered_map<int, std::size_t> lookup;
111 lookup.reserve(parameters.size());
112 std::size_t p_index = 0u;
113 for (
auto const pid : pids) {
114 lookup[pid] = p_index;
117 result.resize(pids.size());
118 for (
auto &[pid, val] : parameters) {
119 result[lookup[pid]] = std::move(val);
125 std::vector<int> m_id_selection;
127 std::weak_ptr<CellSystem::CellSystem> m_cell_structure;
128 std::weak_ptr<Interactions::BondedInteractions> m_bonded_ias;
129 std::weak_ptr<::System::System> m_system;
132 std::set<std::string_view>
const m_special_parameters{
133 "pos",
"type",
"bonds",
134#ifdef ESPRESSO_ELECTROSTATICS
137#ifdef ESPRESSO_EXCLUSIONS
143 auto cell_structure_ptr = m_cell_structure.lock();
144 assert(cell_structure_ptr !=
nullptr);
145 auto &cell_structure = cell_structure_ptr->get_cell_structure();
146 return &cell_structure;
149 auto get_system()
const {
150 auto ptr = m_system.lock();
151 assert(ptr !=
nullptr);
159 [
this]() {
return m_chunk_size; }},
161 [
this]() {
return m_id_selection; }},
165 void do_construct(
VariantMap const ¶ms)
override;
167 Variant do_call_method(std::string
const &name,
170 void attach(std::weak_ptr<::System::System> system) {
171 assert(m_system.expired());
Context of an object handle.
virtual std::shared_ptr< ObjectHandle > make_shared(std::string const &name, const VariantMap ¶meters)=0
Get a new reference counted instance of a script interface by name.
virtual bool is_head_node() const =0
virtual boost::mpi::communicator const & get_comm() const =0
void attach(std::weak_ptr<::System::System > system)
void set_from_vector_like(std::vector< int > const &pids, std::string const ¶m_name, Container const &values, Context *context, std::shared_ptr< CellSystem::CellSystem > cell_structure, std::shared_ptr< Interactions::BondedInteractions > bonded_ias)
auto get_particles_properties(std::vector< int > const &pids, std::function< T(Particle const &)> const &getter, Context *context, CellStructure const &cell_structure)
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
static auto & get_cell_structure()
Struct holding all information for one particle.