65#include <boost/mpi/collectives.hpp>
72#include <initializer_list>
87 p.
call_method(
"set_exclusions", {{
"p_ids", exclusions}});
98 {{
"bond_id", bond_id}, {
"part_id", std::move(
part_id)}});
108#ifdef COLLISION_DETECTION
117 std::shared_ptr<Accumulators::AutoUpdateAccumulators>
127 std::shared_ptr<Particles::ParticleList>
part;
149 auto &dst = ptr->*member;
150 if (dst != nullptr) {
151 throw WriteError(key);
154 dst->bind_system(m_instance);
162 context()->parallel_try_catch([&]() {
165 throw std::domain_error(
"Attribute 'box_l' must be > 0");
167 m_instance->veto_boxl_change();
168 m_instance->box_geo->set_length(
new_value);
169 m_instance->on_boxl_change();
172 [
this]() {
return m_instance->box_geo->length(); }},
176 for (
unsigned int i = 0
u; i < 3u; ++i) {
177 m_instance->box_geo->set_periodic(i,
periodicity[i]);
179 context()->parallel_try_catch(
180 [&]() { m_instance->on_periodicity_change(); });
184 m_instance->box_geo->periodic(1),
185 m_instance->box_geo->periodic(2)};
189 context()->parallel_try_catch([&]() {
192 throw std::domain_error(
"Attribute 'min_global_cut' must be >= 0");
194 m_instance->set_min_global_cut(
new_value);
197 [
this]() {
return m_instance->get_min_global_cut(); }},
202 [
this]() {
return m_instance->oif_global->max_oif_objects; }},
213#ifdef COLLISION_DETECTION
214 add_parameter(
"collision_detection", &Leaves::collision_detection);
218 add_parameter(
"auto_update_accumulators", &Leaves::auto_update_accumulators);
220 add_parameter(
"non_bonded_inter", &Leaves::non_bonded_inter);
230template <
typename LeafType>
231void System::do_set_default_parameter(std::string
const &name) {
232 assert(context()->is_head_node());
233 auto const so_name = Utils::demangle<LeafType>().substr(17);
234 set_parameter(name,
Variant{context()->make_shared(
so_name, {})});
247 context()->parallel_try_catch([&]() {
249 throw std::domain_error(
"Required argument 'box_l' not provided.");
252 throw std::runtime_error(
253 "You can only have one instance of the system class at a time");
261 do_set_parameter(
"box_l",
params.at(
"box_l"));
264 m_instance->lb.bind_system(m_instance);
265 m_instance->ek.bind_system(m_instance);
267 if (
params.contains(
"_regular_constructor")) {
269 "box_l",
"min_global_cut",
270 "periodicity",
"time",
271 "time_step",
"force_cap",
272 "max_oif_objects",
"_regular_constructor"};
273 for (
auto const &kv :
params) {
275 context()->parallel_try_catch([&kv]() {
276 throw std::domain_error(
277 "Property '" + kv.first +
278 "' cannot be set via argument to System class");
282 for (std::string
attr :
283 {
"min_global_cut",
"periodicity",
"max_oif_objects"}) {
288 if (
not context()->is_head_node()) {
291 auto integrator = std::dynamic_pointer_cast<Integrators::IntegratorHandle>(
292 context()->make_shared(
"Integrators::IntegratorHandle", {}));
293 set_parameter(
"integrator", integrator);
294 for (std::string
attr : {
"time",
"time_step",
"force_cap"}) {
304#ifdef COLLISION_DETECTION
306 "collision_detection");
314 "auto_update_accumulators");
326 for (
auto const &
key : get_parameter_insertion_order()) {
332 if (
not context()->is_head_node()) {
335 call_method(
"internal_attach_leaves", {});
339 double theta,
double alpha) {
346 for (
auto const &p : particles) {
347 if (
not p.is_virtual()) {
360 axis[0] = std::sin(
theta) * std::cos(
phi);
361 axis[1] = std::sin(
theta) * std::sin(
phi);
362 axis[2] = std::cos(
theta);
365 for (
auto &p : particles) {
387 p.pos()[dir] *= scale;
394Variant System::do_call_method(std::string
const &name,
396 if (name ==
"lock_system_creation") {
400 if (name ==
"rescale_boxl") {
401 auto &box_geo = *m_instance->box_geo;
406 (box_geo.length()[1] == box_geo.length()[2])));
407 auto const scale = (
coord == 3) ? length * box_geo.length_inv()[0]
408 : length * box_geo.length_inv()[
coord];
409 context()->parallel_try_catch([&]() {
411 throw std::domain_error(
"Parameter 'd_new' must be > 0");
413 m_instance->veto_boxl_change(
true);
425 m_instance->on_particle_change();
427 m_instance->box_geo->set_length(
new_value);
428 m_instance->on_boxl_change();
431 m_instance->on_particle_change();
435 if (name ==
"setup_type_map") {
437 for (
auto const type :
types) {
442 if (name ==
"number_of_particles") {
444 return ::number_of_particles_with_type(type);
446 if (name ==
"velocity_difference") {
451 return m_instance->box_geo->velocity_difference(pos2, pos1,
v2,
v1);
453 if (name ==
"distance_vec") {
456 return m_instance->box_geo->get_mi_vector(pos2, pos1);
458 if (name ==
"rotate_system") {
463 m_instance->on_particle_change();
464 m_instance->update_dependent_particles();
467 if (name ==
"get_propagation_modes_enum") {
470 if (name ==
"session_shutdown") {
475 assert(m_instance.use_count() == 1l);
481 if (name ==
"internal_attach_leaves") {
482 m_leaves->part->attach(m_leaves->cell_system,
483 m_leaves->bonded_interactions);
484#ifdef COLLISION_DETECTION
485 m_leaves->collision_detection->attach(m_leaves->bonded_interactions);
394Variant System::do_call_method(std::string
const &name, {
…}
498std::string System::get_internal_state()
const {
503 auto p_obj = context()->make_shared(
504 "Particles::ParticleHandle",
505 {{
"id", p_id}, {
"__cell_structure", m_leaves->cell_system}});
510 state.name =
"Particles::ParticleHandle";
514 auto const exclusions =
p_handle.call_method(
"get_exclusions", {});
515 state.params.emplace_back(std::string{
"exclusions"},
pack(exclusions));
517 state.params.emplace_back(std::string{
"__cpt_sentinel"},
pack(
None{}));
498std::string System::get_internal_state()
const {
…}
524void System::set_internal_state(std::string
const &state) {
525 auto const object_states = Utils::unpack<std::vector<std::string>>(state);
527 std::unordered_map<int, Variant> exclusions = {};
529 std::unordered_map<int, Variant> bonds = {};
531 for (
auto const &packed_object : object_states) {
532 auto state = Utils::unpack<ObjectState>(packed_object);
534 for (
auto const &kv : state.params) {
537 auto const p_id = get_value<int>(
params.at(
"id"));
538 bonds[p_id] =
params.extract(
"bonds").mapped();
540 exclusions[p_id] =
params.extract(
"exclusions").mapped();
542 params[
"__cell_structure"] = get_parameter(
"cell_system");
543 context()->make_shared(
"Particles::ParticleHandle",
params);
547 auto p_obj = context()->make_shared(
548 "Particles::ParticleHandle",
549 {{
"id", p_id}, {
"__cell_structure", m_leaves->cell_system}});
524void System::set_internal_state(std::string
const &state) {
…}
@ 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.
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.
This file contains the defaults for ESPResSo.
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.
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)
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Variant unpack(const PackedVariant &v, std::unordered_map< ObjectId, ObjectRef > const &objects)
Unpack a PackedVariant.
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.
constexpr double INACTIVE_CUTOFF
Cutoff for deactivated interactions.
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.
static SteepestDescentParameters params
Currently active steepest descent instance.
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
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< Galilei::Galilei > galilei
std::shared_ptr< Analysis::Analysis > analysis
std::shared_ptr< Particles::ParticleList > part
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