Permalink
Browse files

Merge pull request #1749 from RudolfWeeber/vs_switchable

Virtual sites switchable at runtime
  • Loading branch information...
fweik committed Jan 10, 2018
2 parents 0199222 + fbd0564 commit 6f0fadfa21dcd91a018e642fdebdadee25ff97f2
Showing with 1,063 additions and 661 deletions.
  1. +0 −8 .travis.yml
  2. +21 −26 doc/sphinx/part.rst
  3. +8 −2 doc/tutorials/python/05-raspberry_electrophoresis/scripts/simulate_raspberry_electrophoresis.py
  4. +1 −0 maintainer/configs/maxset.hpp
  5. +0 −15 maintainer/configs/rest1.hpp
  6. +0 −5 maintainer/configs/rest2.hpp
  7. +1 −1 maintainer/travis/build_cmake.sh
  8. +2 −2 src/core/CMakeLists.txt
  9. +1 −1 src/core/collision.cpp
  10. +0 −1 src/core/collision.hpp
  11. +1 −1 src/core/communication.cpp
  12. +1 −1 src/core/energy_inline.hpp
  13. +11 −15 src/core/forces.cpp
  14. +3 −3 src/core/ghmc.cpp
  15. +7 −7 src/core/ghosts.cpp
  16. +4 −6 src/core/initialize.cpp
  17. +9 −7 src/core/integrate.cpp
  18. +2 −2 src/core/lb.cpp
  19. +1 −1 src/core/minimize_energy.cpp
  20. +13 −15 src/core/pressure.cpp
  21. +1 −1 src/core/rotation.cpp
  22. +4 −4 src/core/statistics.cpp
  23. +3 −3 src/core/statistics.hpp
  24. +2 −2 src/core/thermostat.hpp
  25. +120 −24 src/core/virtual_sites.cpp
  26. +9 −77 src/core/virtual_sites.hpp
  27. +70 −0 src/core/virtual_sites/VirtualSites.hpp
  28. +30 −0 src/core/virtual_sites/VirtualSitesOff.hpp
  29. +221 −0 src/core/virtual_sites/VirtualSitesRelative.cpp
  30. +58 −0 src/core/virtual_sites/VirtualSitesRelative.hpp
  31. +8 −8 src/core/{ → virtual_sites}/virtual_sites_com.cpp
  32. 0 src/core/{ → virtual_sites}/virtual_sites_com.hpp
  33. +0 −333 src/core/virtual_sites_relative.cpp
  34. +0 −49 src/core/virtual_sites_relative.hpp
  35. +2 −6 src/features.def
  36. +17 −12 src/python/espressomd/analyze.pyx
  37. +2 −1 src/python/espressomd/c_analyze.pxd
  38. +1 −1 src/python/espressomd/particle_data.pxd
  39. +17 −0 src/python/espressomd/system.pyx
  40. +40 −0 src/python/espressomd/virtual_sites.py
  41. +1 −0 src/script_interface/CMakeLists.txt
  42. +2 −0 src/script_interface/initialize.cpp
  43. +56 −0 src/script_interface/virtual_sites/ActiveVirtualSitesHandle.hpp
  44. +55 −0 src/script_interface/virtual_sites/VirtualSites.hpp
  45. +47 −0 src/script_interface/virtual_sites/VirtualSitesOff.hpp
  46. +46 −0 src/script_interface/virtual_sites/VirtualSitesRelative.hpp
  47. +47 −0 src/script_interface/virtual_sites/initialize.cpp
  48. +31 −0 src/script_interface/virtual_sites/initialize.hpp
  49. +87 −21 testsuite/virtual_sites_relative.py
View
@@ -36,14 +36,6 @@ matrix:
- os: osx
osx_image: xcode8
env: myconfig=maxset image=python3
- os: linux
sudo: required
services: docker
env: myconfig=rest1 with_coverage=true
- os: linux
sudo: required
services: docker
env: myconfig=rest2 with_coverage=true
- os: linux
sudo: required
services: docker
View
@@ -315,14 +315,31 @@ according to their respective particle type. Before the next integration
step, the forces accumulated on a virtual site are distributed back to
those particles, from which the virtual site was derived.
There are two distinct types of virtual sites, described in the
following.
There are different schemes for virtual sites, described in the
following sections.
To switch the active scheme, the attribute :attr:`espressomd.system.System.virtual_sites` of the system class can be used::
import espressomd
from espressomd.virtual_sites import VirtualSitesOff, VirtualSitesRelative
s=espressomd.System()
s.virtual_sites=VirtualSitesRelative(have_velocity=True)
# or
s.virtual_sites=VirtualSitesOff()
By default, :class:`espressomd.virtual_sites.VirtualSitesOff` is selected. This means that virtual particles are not touched during integration.
the `have_velocity` attribute determines, whether or not the velocity of virtual sites is calcualted, which carries a performance cost.
.. _Rigid arrangements of particles:
Rigid arrangements of particles
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The relative implementation of virtual sites allows for the simulation
of rigid arrangements of particles. It can be used, , for extended
of rigid arrangements of particles. It can be used, for extended
dipoles and raspberry-particles, but also for more complex
configurations. Position and velocity of a virtual site are obtained
from the position and orientation of exactly one non-virtual particle,
@@ -341,7 +358,7 @@ site is placed at a fixed distance from the non-virtual particle. When
the non-virtual particle rotates, the virtual sites rotates on an orbit
around the non-virtual particles center.
To use this implementation of virtual sites, activate the feature VIRTUAL_SITES_RELATIVE.
To use this implementation of virtual sites, activate the feature VIRTUAL_SITES_RELATIVE. Furthermore, an instance of :class:`espressomd.virtual_sites.VirtualSitesRelative` has to be set as the active virtual sites scheme (see above).
To set up a virtual site,
#. Place the particle to which the virtual site should be related. It
@@ -392,11 +409,6 @@ Please note:
- The presence of rigid bodies constructed by means of virtual sites
adds a contribution to the pressure and stress tensor.
- The use of virtual sites requires that the particles are numbered
consecutively, , the particle ids should go from zero to :math:`N-1`,
where :math:`N` is the number of particles.
Virtual sites in the center of mass of a molecule
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:todo: `This is not implemented in Python, yet`
@@ -451,28 +463,11 @@ that order
integrate 0
Please note that the use of virtual sites requires that the particles
are numbered consecutively. I.e., the particle ids should go from zero
to :math:`N-1`, where :math:`N` is the number of particles.
The type of the molecule you can choose freely, it is only used in
certain analysis functions, namely ``energy_kinetic_mol``,
``pressure_mol`` and ``dipmom_mol``, which compute kinetic energy,
pressure and dipole moment per molecule type, respectively.
Additional features
~~~~~~~~~~~~~~~~~~~
The behaviour of virtual sites can be fine-tuned with the following
switches in ``myconfig.hpp``.
- VIRTUAL_SITES_NO_VELOCITY specifies that the velocity of virtual sites is not computed
- VIRTUAL_SITES_THERMOSTAT specifies that the Langevin thermostat should also act on virtual
sites
- THERMOSTAT_IGNORE_NON_VIRTUAL specifies that the thermostat does not act on non-virtual particles
Grand canonical feature
-----------------------
:mod:`espressomd.grand_canonical`
@@ -89,13 +89,19 @@
system.bonded_inter[0] = interactions.HarmonicBond(k=0, r_0=0)
print("\n# min dist to the center pre moving of surface beads = {}".format(analyze.Analysis(system).mindist([0],[1])))
print("\n# min dist to the center pre moving of surface beads = {}".format(analyze.Analysis(system).min_dist([0],[1])))
#this loop moves the surface beads such that they are once again exactly radius_col away from the center
for i in range(1,n_col_part):
pos = system.part[i].pos
system.part[i].pos=(pos-colPos)/np.linalg.norm(pos-colPos)*radius_col+colPos
print("# min dist to the center past moving of surface beads = {}".format(analyze.Analysis(system).mindist([0],[1])))
print("# min dist to the center past moving of surface beads = {}".format(analyze.Analysis(system).min_dist([0],[1])))
# Select the virtual sites scheme to VirtualSitesRelative
from espressomd.virtual_sites import VirtualSitesRelative
system.virtual_sites= VirtualSitesRelative(have_velocity=True)
#setting min_global_cut is necessary when there is no interaction defined with a range larger than the colloid
#such that the virtual particles are able to communicate their forces to the real particle at the center of the colloid
@@ -25,6 +25,7 @@
#define NPT
#define GHMC
#define DPD
#define METADYNAMICS
#define LB
#define LB_BOUNDARIES

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -151,7 +151,7 @@ end "CONFIGURE"
# BUILD
start "BUILD"
cmd "make -k -j${build_procs}" || exit $?
cmd "make -k -j${build_procs}" || cmd "make -k -j1" || exit $?
end "BUILD"
View
@@ -1,6 +1,6 @@
file(GLOB EspressoCore_SRC
"*.cpp"
)
"*.cpp" "virtual_sites/VirtualSitesRelative.cpp")
if( WITH_COVERAGE )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Og --coverage -fprofile-arcs -ftest-coverage")
View
@@ -26,7 +26,7 @@
#include "grid.hpp"
#include "domain_decomposition.hpp"
#include "rotation.hpp"
#include "virtual_sites/VirtualSitesRelative.hpp"
using namespace std;
View
@@ -21,7 +21,6 @@
#include "particle_data.hpp"
#include "interaction_data.hpp"
#include "virtual_sites_relative.hpp"
#include "virtual_sites.hpp"
#include "integrate.hpp"
@@ -954,7 +954,7 @@ void mpi_send_virtual_slave(int pnode, int part) {
#ifdef VIRTUAL_SITES
if (pnode == this_node) {
Particle *p = local_particles[part];
MPI_Recv(&p->p.isVirtual, 1, MPI_INT, 0, SOME_TAG, comm_cart,
MPI_Recv(&(p->p.isVirtual), 1, MPI_INT, 0, SOME_TAG, comm_cart,
MPI_STATUS_IGNORE);
}
@@ -496,7 +496,7 @@ inline void add_bonded_energy(Particle *p1) {
*/
inline void add_kinetic_energy(Particle *p1) {
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(p1))
if (p1->p.isVirtual)
return;
#endif
View
@@ -97,20 +97,13 @@ void force_calc() {
// VIRTUAL_SITES pos (and vel for DPD) update for security reason !!!
#ifdef VIRTUAL_SITES
update_mol_vel_pos();
ghost_communicator(&cell_structure.update_ghost_pos_comm);
#endif
#if defined(VIRTUAL_SITES_RELATIVE) && defined(LB)
// This is on a workaround stage:
// When using virtual sites relative and LB at the same time, it is necessary
// to reassemble the cell lists after all position updates, also of virtual
// particles.
if ((lattice_switch & LATTICE_LB) &&
cell_structure.type == CELL_STRUCTURE_DOMDEC && (!cell_structure.use_verlet_list))
cells_update_ghosts();
virtual_sites()->update();
if (virtual_sites()->need_ghost_comm_after_pos_update()) {
ghost_communicator(&cell_structure.update_ghost_pos_comm);
}
#endif
espressoSystemInterface.update();
#ifdef COLLISION_DETECTION
@@ -188,9 +181,12 @@ void force_calc() {
// VIRTUAL_SITES distribute forces
#ifdef VIRTUAL_SITES
ghost_communicator(&cell_structure.collect_ghost_force_comm);
init_forces_ghosts();
distribute_mol_force();
if (virtual_sites()->need_ghost_comm_before_back_transfer())
{
ghost_communicator(&cell_structure.collect_ghost_force_comm);
init_forces_ghosts();
}
virtual_sites()->back_transfer_forces_and_torques();
#endif
// Communication Step: ghost forces
View
@@ -163,7 +163,7 @@ void calc_kinetic(double *ek_trans, double *ek_rot) {
for (auto &p : local_cells.particles()) {
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
@@ -236,7 +236,7 @@ void tscale_momentum_update() {
for (auto &p : local_cells.particles()) {
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
@@ -258,7 +258,7 @@ void simple_momentum_update() {
for (auto &p : local_cells.particles()) {
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
View
@@ -76,19 +76,14 @@ inline void add_force(ParticleForce *F_to, ParticleForce *F_add) {
void prepare_comm(GhostCommunicator *comm, int data_parts, int num)
{
int i;
assert(comm);
comm->data_parts = data_parts;
/* if ghosts should have uptodate velocities, they have to be updated like positions
(except for shifting...) */
if (ghosts_have_v && (data_parts & GHOSTTRANS_POSITION))
comm->data_parts |= GHOSTTRANS_MOMENTUM;
GHOST_TRACE(fprintf(stderr, "%d: prepare_comm, data_parts = %d\n", this_node, comm->data_parts));
comm->num = num;
comm->comm = (GhostCommunication*)Utils::malloc(num*sizeof(GhostCommunication));
for(i=0; i<num; i++) {
for(int i=0; i<num; i++) {
comm->comm[i].shift[0]=comm->comm[i].shift[1]=comm->comm[i].shift[2]=0.0;
comm->comm[i].n_part_lists = 0;
comm->comm[i].part_lists = nullptr;
@@ -537,6 +532,11 @@ void ghost_communicator(GhostCommunicator *gc)
MPI_Status status;
int n, n2;
int data_parts = gc->data_parts;
/* if ghosts should have uptodate velocities, they have to be updated like
positions (except for shifting...) */
if (ghosts_have_v && (data_parts & GHOSTTRANS_POSITION))
data_parts |= GHOSTTRANS_MOMENTUM;
GHOST_TRACE(fprintf(stderr, "%d: ghost_comm %p, data_parts %d\n", this_node, (void*) gc, data_parts));
View
@@ -712,8 +712,6 @@ void on_ghost_flags_change() {
/* that's all we change here */
extern int ghosts_have_v;
const int old_have_v = ghosts_have_v;
ghosts_have_v = 0;
/* DPD and LB need also ghost velocities */
@@ -737,10 +735,10 @@ void on_ghost_flags_change() {
ghosts_have_v = 1;
#endif
#ifdef VIRTUAL_SITES
// VIRUTAL_SITES need v to update v of virtual sites
ghosts_have_v = 1;
// If they have velocities, VIRUTAL_SITES need v to update v of virtual sites
if (virtual_sites()->have_velocity()) {
ghosts_have_v = 1;
};
#endif
if (old_have_v != ghosts_have_v)
cells_re_init(CELL_STRUCTURE_CURRENT);
}
View
@@ -485,8 +485,10 @@ void integrate_vv(int n_steps, int reuse_forces) {
#endif
// VIRTUAL_SITES update vel
#ifdef VIRTUAL_SITES
ghost_communicator(&cell_structure.update_ghost_pos_comm);
update_mol_vel();
if (virtual_sites()->need_ghost_comm_before_vel_update()) {
ghost_communicator(&cell_structure.update_ghost_pos_comm);
}
virtual_sites()->update(false); // Recalc positions = false
#endif
// progagate one-step functionalities
@@ -660,7 +662,7 @@ void rescale_forces_propagate_vel() {
this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], p.m.v[2]));
#ifdef VIRTUAL_SITES
// Virtual sites are not propagated during integration
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
for (int j = 0; j < 3; j++) {
@@ -792,7 +794,7 @@ void propagate_press_box_pos_and_rescale_npt() {
/* propagate positions while rescaling positions and velocities */
for (auto &p : local_cells.particles()) {
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
for (int j = 0; j < 3; j++) {
@@ -874,7 +876,7 @@ void propagate_vel() {
// Don't propagate translational degrees of freedom of vs
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
for (int j = 0; j < 3; j++) {
@@ -931,7 +933,7 @@ void propagate_pos() {
else {
for (auto &p : local_cells.particles()) {
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
for (int j = 0; j < 3; j++) {
@@ -973,7 +975,7 @@ void propagate_vel_pos() {
// Don't propagate translational degrees of freedom of vs
#ifdef VIRTUAL_SITES
if (ifParticleIsVirtual(&p))
if (p.p.isVirtual)
continue;
#endif
for (int j = 0; j < 3; j++) {
Oops, something went wrong.

0 comments on commit 6f0fadf

Please sign in to comment.