64#include <boost/mpi/collectives.hpp>
71#include <initializer_list>
86 p.
call_method(
"set_exclusions", {{
"p_ids", exclusions}});
97 {{
"bond_id", bond_id}, {
"part_id", std::move(
part_id)}});
107#ifdef COLLISION_DETECTION
116 std::shared_ptr<Accumulators::AutoUpdateAccumulators>
126 std::shared_ptr<Particles::ParticleList>
part;
148 auto &dst = ptr->*member;
149 if (dst != nullptr) {
150 throw WriteError(key);
153 dst->bind_system(m_instance);
161 context()->parallel_try_catch([&]() {
164 throw std::domain_error(
"Attribute 'box_l' must be > 0");
166 m_instance->veto_boxl_change();
167 m_instance->box_geo->set_length(
new_value);
168 m_instance->on_boxl_change();
171 [
this]() {
return m_instance->box_geo->length(); }},
175 for (
unsigned int i = 0
u; i < 3u; ++i) {
176 m_instance->box_geo->set_periodic(i,
periodicity[i]);
178 context()->parallel_try_catch(
179 [&]() { m_instance->on_periodicity_change(); });
183 m_instance->box_geo->periodic(1),
184 m_instance->box_geo->periodic(2)};
188 context()->parallel_try_catch([&]() {
191 throw std::domain_error(
"Attribute 'min_global_cut' must be >= 0");
193 m_instance->set_min_global_cut(
new_value);
196 [
this]() {
return m_instance->get_min_global_cut(); }},
201 [
this]() {
return m_instance->oif_global->max_oif_objects; }},
212#ifdef COLLISION_DETECTION
213 add_parameter(
"collision_detection", &Leaves::collision_detection);
217 add_parameter(
"auto_update_accumulators", &Leaves::auto_update_accumulators);
219 add_parameter(
"non_bonded_inter", &Leaves::non_bonded_inter);
229template <
typename LeafType>
230void System::do_set_default_parameter(std::string
const &name) {
231 assert(context()->is_head_node());
232 auto const so_name = Utils::demangle<LeafType>().substr(17);
233 set_parameter(name,
Variant{context()->make_shared(
so_name, {})});
246 context()->parallel_try_catch([&]() {
248 throw std::domain_error(
"Required argument 'box_l' not provided.");
251 throw std::runtime_error(
252 "You can only have one instance of the system class at a time");
260 do_set_parameter(
"box_l",
params.at(
"box_l"));
263 m_instance->lb.bind_system(m_instance);
264 m_instance->ek.bind_system(m_instance);
266 if (
params.contains(
"_regular_constructor")) {
268 "box_l",
"min_global_cut",
269 "periodicity",
"time",
270 "time_step",
"force_cap",
271 "max_oif_objects",
"_regular_constructor"};
272 for (
auto const &kv :
params) {
274 context()->parallel_try_catch([&kv]() {
275 throw std::domain_error(
276 "Property '" + kv.first +
277 "' cannot be set via argument to System class");
281 for (std::string
attr :
282 {
"min_global_cut",
"periodicity",
"max_oif_objects"}) {
287 if (
not context()->is_head_node()) {
290 auto integrator = std::dynamic_pointer_cast<Integrators::IntegratorHandle>(
291 context()->make_shared(
"Integrators::IntegratorHandle", {}));
292 set_parameter(
"integrator", integrator);
293 for (std::string
attr : {
"time",
"time_step",
"force_cap"}) {
303#ifdef COLLISION_DETECTION
305 "collision_detection");
313 "auto_update_accumulators");
325 for (
auto const &
key : get_parameter_insertion_order()) {
331 if (
not context()->is_head_node()) {
334 call_method(
"internal_attach_leaves", {});
338 double theta,
double alpha) {
345 for (
auto const &p : particles) {
346 if (
not p.is_virtual()) {
359 axis[0] = std::sin(
theta) * std::cos(
phi);
360 axis[1] = std::sin(
theta) * std::sin(
phi);
361 axis[2] = std::cos(
theta);
364 for (
auto &p : particles) {
386 p.pos()[dir] *= scale;
393Variant System::do_call_method(std::string
const &name,
395 if (name ==
"lock_system_creation") {
399 if (name ==
"rescale_boxl") {
400 auto &box_geo = *m_instance->box_geo;
405 (box_geo.length()[1] == box_geo.length()[2])));
406 auto const scale = (
coord == 3) ? length * box_geo.length_inv()[0]
407 : length * box_geo.length_inv()[
coord];
408 context()->parallel_try_catch([&]() {
410 throw std::domain_error(
"Parameter 'd_new' must be > 0");
412 m_instance->veto_boxl_change(
true);
424 m_instance->on_particle_change();
426 m_instance->box_geo->set_length(
new_value);
427 m_instance->on_boxl_change();
430 m_instance->on_particle_change();
434 if (name ==
"setup_type_map") {
436 for (
auto const type :
types) {
441 if (name ==
"number_of_particles") {
443 return ::number_of_particles_with_type(type);
445 if (name ==
"velocity_difference") {
450 return m_instance->box_geo->velocity_difference(pos2, pos1,
v2,
v1);
452 if (name ==
"distance_vec") {
455 return m_instance->box_geo->get_mi_vector(pos2, pos1);
457 if (name ==
"rotate_system") {
462 m_instance->on_particle_change();
463 m_instance->update_dependent_particles();
466 if (name ==
"get_propagation_modes_enum") {
469 if (name ==
"session_shutdown") {
474 assert(m_instance.use_count() == 1l);
480 if (name ==
"internal_attach_leaves") {
481 m_leaves->part->attach(m_leaves->cell_system,
482 m_leaves->bonded_interactions);
483#ifdef COLLISION_DETECTION
484 m_leaves->collision_detection->attach(m_leaves->bonded_interactions);
497std::string System::get_internal_state()
const {
502 auto p_obj = context()->make_shared(
503 "Particles::ParticleHandle",
504 {{
"id", p_id}, {
"__cell_structure", m_leaves->cell_system}});
509 state.name =
"Particles::ParticleHandle";
513 auto const exclusions =
p_handle.call_method(
"get_exclusions", {});
514 state.params.emplace_back(std::string{
"exclusions"},
pack(exclusions));
516 state.params.emplace_back(std::string{
"__cpt_sentinel"},
pack(
None{}));
523void System::set_internal_state(std::string
const &state) {
524 auto const object_states = Utils::unpack<std::vector<std::string>>(state);
526 std::unordered_map<int, Variant> exclusions = {};
528 std::unordered_map<int, Variant> bonds = {};
530 for (
auto const &packed_object : object_states) {
531 auto state = Utils::unpack<ObjectState>(packed_object);
533 for (
auto const &kv : state.params) {
536 auto const p_id = get_value<int>(
params.at(
"id"));
537 bonds[p_id] =
params.extract(
"bonds").mapped();
539 exclusions[p_id] =
params.extract(
"exclusions").mapped();
541 params[
"__cell_structure"] = get_parameter(
"cell_system");
542 context()->make_shared(
"Particles::ParticleHandle",
params);
546 auto p_obj = context()->make_shared(
547 "Particles::ParticleHandle",
548 {{
"id", p_id}, {
"__cell_structure", m_leaves->cell_system}});
@ 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.
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