ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Galilei.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "galilei/Galilei.hpp"
23
24#include "BoxGeometry.hpp"
25#include "Particle.hpp"
26#include "ParticleRange.hpp"
28#include "communication.hpp"
29#include "config/config.hpp"
30#include "system/System.hpp"
31
32#include <boost/mpi/collectives/all_reduce.hpp>
33
34#include <utils/Vector.hpp>
35
36#include <tuple>
37
38void Galilei::kill_particle_motion(System::System &system, bool omega) const {
39#ifndef ROTATION
40 std::ignore = omega;
41#endif
42 for (auto &p : system.cell_structure->local_particles()) {
43 p.v() = {};
44#ifdef ROTATION
45 if (omega) {
46 p.omega() = {};
47 }
48#endif // ROTATION
49 }
50 system.on_particle_change();
51}
52
54#ifndef ROTATION
55 std::ignore = torque;
56#endif
57 for (auto &p : system.cell_structure->local_particles()) {
58 p.force() = {};
59#ifdef ROTATION
60 if (torque) {
61 p.torque() = {};
62 }
63#endif // ROTATION
64 }
65 system.on_particle_change();
66}
67
70 auto const &box_geo = *system.box_geo;
71 auto total_mass = 0.;
72 auto cms_pos = Utils::Vector3d{};
73 for (auto const &p : system.cell_structure->local_particles()) {
74 if (not p.is_virtual()) {
75 total_mass += p.mass();
76 cms_pos += p.mass() * box_geo.unfolded_position(p.pos(), p.image_box());
77 }
78 }
79 total_mass = boost::mpi::all_reduce(comm_cart, total_mass, std::plus<>());
80 cms_pos = boost::mpi::all_reduce(comm_cart, cms_pos, std::plus<>());
81 cms_pos /= total_mass;
82 return cms_pos;
83}
84
87 auto total_mass = 0.;
88 auto cms_vel = Utils::Vector3d{};
89 for (auto const &p : system.cell_structure->local_particles()) {
90 if (not p.is_virtual()) {
91 total_mass += p.mass();
92 cms_vel += p.mass() * p.v();
93 }
94 }
95 total_mass = boost::mpi::all_reduce(comm_cart, total_mass, std::plus<>());
96 cms_vel = boost::mpi::all_reduce(comm_cart, cms_vel, std::plus<>());
97 cms_vel /= total_mass;
98 return cms_vel;
99}
100
102 auto const cms_vel = calc_system_cms_velocity(system);
103 for (auto &p : system.cell_structure->local_particles()) {
104 p.v() -= cms_vel;
105 }
106 system.on_particle_change();
107}
Vector implementation and trait types for boost qvm interoperability.
__global__ float float * torque
void kill_particle_motion(System::System &system, bool omega) const
Stop particle motion by setting the velocity of each particle to zero.
Definition Galilei.cpp:38
void galilei_transform(System::System &system) const
Remove the CMS velocity.
Definition Galilei.cpp:101
Utils::Vector3d calc_system_cms_velocity(System::System const &system) const
Calculate the CMS velocity of the system.
Definition Galilei.cpp:86
Utils::Vector3d calc_system_cms_position(System::System const &system) const
Calculate the CMS of the system.
Definition Galilei.cpp:69
void kill_particle_forces(System::System &system, bool torque) const
Set all the forces acting on the particles to zero.
Definition Galilei.cpp:53
Main system class.
void on_particle_change()
Called every time a particle property changes.
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< BoxGeometry > box_geo
boost::mpi::communicator comm_cart
The communicator.
This file contains the defaults for ESPResSo.