67#include <boost/mpi/collectives.hpp>
74#include <initializer_list>
87#ifdef ESPRESSO_EXCLUSIONS
90 p.
call_method(
"set_exclusions", {{
"p_ids", exclusions}});
101 {{
"bond_id", bond_id}, {
"part_id", std::move(
part_id)}});
111#ifdef ESPRESSO_COLLISION_DETECTION
120 std::shared_ptr<Accumulators::AutoUpdateAccumulators>
124#ifdef ESPRESSO_ELECTROSTATICS
127#ifdef ESPRESSO_DIPOLES
130 std::shared_ptr<LB::Container>
lb;
131 std::shared_ptr<EK::Container>
ek;
132 std::shared_ptr<Particles::ParticleList>
part;
154 auto &dst = ptr->*member;
155 if (dst != nullptr) {
156 throw WriteError(key);
159 dst->bind_system(m_instance);
167 context()->parallel_try_catch([&]() {
170 throw std::domain_error(
"Attribute 'box_l' must be > 0");
172 m_instance->veto_boxl_change();
173 m_instance->box_geo->set_length(
new_value);
174 m_instance->on_boxl_change();
177 [
this]() {
return m_instance->box_geo->length(); }},
181 for (
unsigned int i = 0
u; i < 3u; ++i) {
182 m_instance->box_geo->set_periodic(i,
periodicity[i]);
184 context()->parallel_try_catch(
185 [&]() { m_instance->on_periodicity_change(); });
189 m_instance->box_geo->periodic(1),
190 m_instance->box_geo->periodic(2)};
194 context()->parallel_try_catch([&]() {
197 throw std::domain_error(
"Attribute 'min_global_cut' must be >= 0");
199 m_instance->set_min_global_cut(
new_value);
202 [
this]() {
return m_instance->get_min_global_cut(); }},
207 [
this]() {
return m_instance->oif_global->max_oif_objects; }},
219#ifdef ESPRESSO_COLLISION_DETECTION
220 add_parameter(
"collision_detection", &Leaves::collision_detection);
224 add_parameter(
"auto_update_accumulators", &Leaves::auto_update_accumulators);
226 add_parameter(
"non_bonded_inter", &Leaves::non_bonded_inter);
227#ifdef ESPRESSO_ELECTROSTATICS
230#ifdef ESPRESSO_DIPOLES
238 m_leaves->ek->do_call_method(
"deactivate", {});
239 if (
not context()->is_head_node()) {
242 set_parameter(
"ekcontainer",
243 context()->make_shared(
"EK::Container", {}));
245 auto const detach_solver = [
this]() {
246 auto &solver = m_leaves->ek;
248 solver->do_call_method(
"deactivate", {});
249 solver->detach_system();
253 auto const bind_solver = [
this]() {
254 auto &solver = m_leaves->ek;
256 solver->bind_system(m_instance);
257 solver->do_call_method(
"activate", {});
260 auto &solver = m_leaves->ek;
266 context()->parallel_try_catch([&]() { bind_solver(); });
275 [
this]() {
return m_leaves->ek; }},
280template <
typename LeafType>
281void System::do_set_default_parameter(std::string
const &name) {
282 assert(context()->is_head_node());
283 auto const so_name = Utils::demangle<LeafType>().substr(17);
284 set_parameter(name,
Variant{context()->make_shared(
so_name, {})});
297 context()->parallel_try_catch([&]() {
298 if (
not params.contains(
"box_l")) {
299 throw std::domain_error(
"Required argument 'box_l' not provided.");
302 throw std::runtime_error(
303 "You can only have one instance of the system class at a time");
311 do_set_parameter(
"box_l", params.at(
"box_l"));
314 m_instance->lb.bind_system(m_instance);
315 m_instance->ek.bind_system(m_instance);
317 if (params.contains(
"_regular_constructor")) {
319 "box_l",
"min_global_cut",
320 "periodicity",
"time",
321 "time_step",
"force_cap",
322 "max_oif_objects",
"_regular_constructor"};
323 for (
auto const &name : std::views::elements<0>(params)) {
325 context()->parallel_try_catch([&name]() {
326 throw std::domain_error(
327 "Property '" + name +
328 "' cannot be set via argument to System class");
332 for (std::string
attr :
333 {
"min_global_cut",
"periodicity",
"max_oif_objects"}) {
334 if (params.contains(
attr)) {
335 do_set_parameter(
attr, params.at(
attr));
338 if (
not context()->is_head_node()) {
341 auto integrator = std::dynamic_pointer_cast<Integrators::IntegratorHandle>(
342 context()->make_shared(
"Integrators::IntegratorHandle", {}));
343 set_parameter(
"integrator", integrator);
344 for (std::string
attr : {
"time",
"time_step",
"force_cap"}) {
345 if (params.contains(
attr)) {
346 integrator->set_parameter(
attr, params.at(
attr));
354#ifdef ESPRESSO_COLLISION_DETECTION
356 "collision_detection");
364 "auto_update_accumulators");
368#ifdef ESPRESSO_ELECTROSTATICS
371#ifdef ESPRESSO_DIPOLES
378 for (
auto const &
key : get_parameter_insertion_order()) {
379 if (
key !=
"box_l" and params.contains(
key)) {
380 do_set_parameter(
key, params.at(
key));
384 if (
not context()->is_head_node()) {
387 call_method(
"internal_attach_leaves", {});
391 double theta,
double alpha) {
398 for (
auto const &p : particles) {
399 if (
not p.is_virtual()) {
405 auto const total_mass =
412 axis[0] = std::sin(
theta) * std::cos(
phi);
413 axis[1] = std::sin(
theta) * std::sin(
phi);
414 axis[2] = std::cos(
theta);
417 for (
auto &p : particles) {
420#ifdef ESPRESSO_ROTATION
439 p.pos()[dir] *= scale;
446Variant System::do_call_method(std::string
const &name,
448 if (name ==
"lock_system_creation") {
452 if (name ==
"rescale_boxl") {
453 auto &box_geo = *m_instance->box_geo;
458 (box_geo.length()[1] == box_geo.length()[2])));
459 auto const scale = (
coord == 3) ? length * box_geo.length_inv()[0]
460 : length * box_geo.length_inv()[
coord];
461 context()->parallel_try_catch([&]() {
463 throw std::domain_error(
"Parameter 'd_new' must be > 0");
465 m_instance->veto_boxl_change(
true);
477 m_instance->on_particle_change();
479 m_instance->box_geo->set_length(
new_value);
480 m_instance->on_boxl_change();
483 m_instance->on_particle_change();
487 if (name ==
"setup_type_map") {
489 for (
auto const type :
types) {
494 if (name ==
"number_of_particles") {
496 return ::number_of_particles_with_type(type);
498 if (name ==
"velocity_difference") {
503 return m_instance->box_geo->velocity_difference(pos2, pos1,
v2,
v1);
505 if (name ==
"distance_vec") {
508 return m_instance->box_geo->get_mi_vector(pos2, pos1);
510 if (name ==
"rotate_system") {
515 m_instance->on_particle_change();
516 m_instance->update_dependent_particles();
519 if (name ==
"get_propagation_modes_enum") {
522 if (name ==
"session_shutdown") {
527 assert(m_instance.use_count() == 1l);
533 if (name ==
"internal_attach_leaves") {
534 m_leaves->part->attach(m_leaves->cell_system,
535 m_leaves->bonded_interactions);
536#ifdef ESPRESSO_COLLISION_DETECTION
537 m_leaves->collision_detection->attach(m_leaves->bonded_interactions);
550std::string System::get_internal_state()
const {
555 auto p_obj = context()->make_shared(
556 "Particles::ParticleHandle",
557 {{
"id", p_id}, {
"__cell_structure", m_leaves->cell_system}});
562 state.name =
"Particles::ParticleHandle";
565#ifdef ESPRESSO_EXCLUSIONS
566 auto const exclusions =
p_handle.call_method(
"get_exclusions", {});
567 state.params.emplace_back(std::string{
"exclusions"},
pack(exclusions));
569 state.params.emplace_back(std::string{
"__cpt_sentinel"},
pack(
None{}));
576void System::set_internal_state(std::string
const &state) {
577 auto const object_states = Utils::unpack<std::vector<std::string>>(state);
578#ifdef ESPRESSO_EXCLUSIONS
579 std::unordered_map<int, Variant> exclusions = {};
581 std::unordered_map<int, Variant> bonds = {};
583 for (
auto const &packed_object : object_states) {
584 auto state = Utils::unpack<ObjectState>(packed_object);
586 for (
auto const &[name, packed_value] : state.params) {
587 params[name] =
unpack(packed_value, {});
589 auto const p_id = get_value<int>(params.at(
"id"));
590 bonds[p_id] = params.extract(
"bonds").mapped();
591#ifdef ESPRESSO_EXCLUSIONS
592 exclusions[p_id] = params.extract(
"exclusions").mapped();
594 params[
"__cell_structure"] = get_parameter(
"cell_system");
595 context()->make_shared(
"Particles::ParticleHandle", params);
599 auto p_obj = context()->make_shared(
600 "Particles::ParticleHandle",
601 {{
"id", p_id}, {
"__cell_structure", m_leaves->cell_system}});
604#ifdef ESPRESSO_EXCLUSIONS
@ NSQUARE
Atom decomposition (N-square).
@ REGULAR
Regular decomposition.
static int coord(std::string const &s)
Vector implementation and trait types for boost qvm interoperability.
This file contains everything related to the global cell structure / cell system.
Describes a cell structure / cell system.
void update_ghosts_and_resort_particle(unsigned data_parts)
Update ghost particles, with particle resort if needed.
void set_resort_particles(Cells::Resort level)
Increase the local resort level at least to level.
ParticleRange local_particles() const
void add_parameters(std::vector< AutoParameter > &¶ms)
Type to indicate no value in Variant.
std::string serialize() const
Variant call_method(const std::string &name, const VariantMap ¶ms)
Call a method on the object.
static std::shared_ptr< System > create()
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
boost::mpi::communicator comm_cart
The communicator.
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
This file contains the asynchronous MPI communication.
@ DATA_PART_PROPERTIES
Particle::p.
@ DATA_PART_POSITION
Particle::r.
static void set_bonds(Particles::ParticleHandle &p, Variant const &bonds)
static void set_exclusions(Particles::ParticleHandle &p, Variant const &exclusions)
static void rotate_system(CellStructure &cell_structure, double phi, double theta, double alpha)
static bool system_created
static void rescale_particles(CellStructure &cell_structure, int dir, double scale)
Rescale all particle positions in direction dir by a factor scale.
constexpr bool is_none(Variant const &v)
PackedVariant pack(const Variant &v)
Transform a Variant to a PackedVariant.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
Variant unpack(const PackedVariant &v, std::unordered_map< ObjectId, ObjectRef > const &objects)
Unpack a PackedVariant.
make_recursive_variant< ObjectRef > Variant
Possible types for parameters.
void set_system(std::shared_ptr< System > new_instance)
Vector3d vec_rotate(const Vector3d &axis, double angle, const Vector3d &vector)
Rotate a vector around an axis.
std::string pack(T const &v)
Pack a serialize type into a string.
Various procedures concerning interactions between particles.
Exports for the NpT code.
Routines to calculate the OIF global forces for a particle triple (triangle from mesh).
void init_type_map(int type)
std::vector< int > get_particle_ids()
Get all particle ids.
Particles creation and deletion.
std::unordered_map< std::string, int > propagation_flags_map()
Convert PropagationMode::PropagationMode to name/value pairs.
This file contains all subroutines required to process rotational motion.
void local_rotate_particle(Particle &p, const Utils::Vector3d &axis_space_frame, const double phi)
Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi.
Description and getter/setter for a parameter.
Container for leaves of the system class.
std::shared_ptr< Thermostat::Thermostat > thermostat
std::shared_ptr< Integrators::IntegratorHandle > integrator
std::shared_ptr< Dipoles::Container > magnetostatics
std::shared_ptr< CellSystem::CellSystem > cell_system
std::shared_ptr< LB::Container > lb
std::shared_ptr< Galilei::Galilei > galilei
std::shared_ptr< Analysis::Analysis > analysis
std::shared_ptr< Particles::ParticleList > part
std::shared_ptr< EK::Container > ek
std::shared_ptr< BondBreakage::BreakageSpecs > bond_breakage
std::shared_ptr< Constraints::Constraints > constraints
std::shared_ptr< Interactions::BondedInteractions > bonded_interactions
std::shared_ptr< CollisionDetection::CollisionDetection > collision_detection
std::shared_ptr< Interactions::NonBondedInteractions > non_bonded_inter
std::shared_ptr< Coulomb::Container > electrostatics
std::shared_ptr< Galilei::ComFixed > comfixed
std::shared_ptr< Accumulators::AutoUpdateAccumulators > auto_update_accumulators
std::shared_ptr< LeesEdwards::LeesEdwards > lees_edwards
Recursive variant implementation.