Skip to content
Permalink
Browse files

Merge branch 'python' into drude_sample

  • Loading branch information
kodiakhq committed Jan 8, 2020
2 parents f5de2fc + 006b1e7 commit 6b4f756e86ec7745d825014816043349960a9ae1
Showing with 289 additions and 329 deletions.
  1. +1 −1 src/core/EspressoSystemInterface.cpp
  2. +3 −0 src/core/Particle.hpp
  3. +49 −53 src/core/cells.cpp
  4. +8 −38 src/core/cells.hpp
  5. +2 −1 src/core/collision.cpp
  6. +0 −2 src/core/collision.hpp
  7. +0 −1 src/core/communication.cpp
  8. +2 −0 src/core/cuda_interface.hpp
  9. +9 −9 src/core/debug.cpp
  10. +9 −8 src/core/domain_decomposition.cpp
  11. +1 −1 src/core/electrostatics_magnetostatics/coulomb.cpp
  12. +1 −1 src/core/electrostatics_magnetostatics/mdlc_correction.cpp
  13. +68 −50 src/core/electrostatics_magnetostatics/mmm2d.cpp
  14. +1 −1 src/core/electrostatics_magnetostatics/p3m-dipolar.cpp
  15. +1 −1 src/core/electrostatics_magnetostatics/p3m.cpp
  16. +2 −2 src/core/electrostatics_magnetostatics/scafacos.cpp
  17. +2 −2 src/core/energy.cpp
  18. +0 −2 src/core/energy_inline.hpp
  19. +1 −1 src/core/forces.cpp
  20. +5 −5 src/core/galilei.cpp
  21. +3 −3 src/core/ghosts.hpp
  22. +4 −4 src/core/immersed_boundary/ImmersedBoundaries.cpp
  23. +1 −1 src/core/integrate.cpp
  24. +1 −6 src/core/integrators/steepest_descent.cpp
  25. +2 −11 src/core/integrators/velocity_verlet_inline.hpp
  26. +1 −14 src/core/integrators/velocity_verlet_npt.cpp
  27. +6 −6 src/core/layered.cpp
  28. +4 −4 src/core/nsquare.cpp
  29. +12 −9 src/core/particle_data.cpp
  30. +2 −0 src/core/particle_data.hpp
  31. +1 −1 src/core/pressure.cpp
  32. +1 −1 src/core/rattle.cpp
  33. +4 −2 src/core/short_range_loop.hpp
  34. +1 −1 src/core/statistics.cpp
  35. +7 −27 src/core/statistics_chain.cpp
  36. +35 −28 src/core/statistics_chain.hpp
  37. +4 −4 src/core/virtual_sites/VirtualSitesInertialessTracers.cpp
  38. +3 −3 src/core/virtual_sites/VirtualSitesRelative.cpp
  39. +12 −12 src/core/virtual_sites/lb_inertialess_tracers.cpp
  40. +3 −6 src/python/espressomd/analyze.pxd
  41. +15 −6 src/python/espressomd/analyze.pyx
  42. +2 −1 src/script_interface/h5md/h5md.cpp
@@ -32,7 +32,7 @@ void EspressoSystemInterface::gatherParticles() {
#ifdef CUDA
if (m_gpu) {
if (gpu_get_global_particle_vars_pointer_host()->communication_enabled) {
copy_part_data_to_gpu(local_cells.particles());
copy_part_data_to_gpu(cell_structure.local_cells().particles());
reallocDeviceMemory(
gpu_get_global_particle_vars_pointer_host()->number_of_particles);
if (m_splitParticleStructGpu && (this_node == 0))
@@ -167,6 +167,9 @@ struct ParticleProperties {
/** External torque, apply if \ref ParticleProperties::ext_flag == 16. */
Utils::Vector3d ext_torque = {0, 0, 0};
#endif
#else
static constexpr const uint8_t ext_flag =
0; // no external forces and fixed coordinates
#endif

#ifdef ENGINE
@@ -49,15 +49,8 @@
#include <cstdlib>
#include <cstring>

/* Variables */

/** list of all cells. */
std::vector<Cell> cells;
/** list of pointers to all cells containing particles physically on the local
* node. */
CellPList local_cells = {nullptr, 0, 0};
/** list of pointers to all cells containing ghosts. */
CellPList ghost_cells = {nullptr, 0, 0};

/** Type of cell structure in use */
CellStructure cell_structure;
@@ -67,9 +60,13 @@ CellStructure cell_structure;
unsigned resort_particles = Cells::RESORT_NONE;
bool rebuild_verletlist = true;

CellPList CellStructure::local_cells() const { return ::local_cells; }
CellPList CellStructure::local_cells() {
return {m_local_cells.data(), static_cast<int>(m_local_cells.size())};
}

CellPList CellStructure::ghost_cells() const { return ::ghost_cells; }
CellPList CellStructure::ghost_cells() {
return {m_ghost_cells.data(), static_cast<int>(m_ghost_cells.size())};
}

/**
* @brief Get pairs closer than distance from the cells.
@@ -94,31 +91,31 @@ std::vector<std::pair<int, int>> get_pairs(double distance) {

switch (cell_structure.type) {
case CELL_STRUCTURE_DOMDEC:
Algorithm::link_cell(boost::make_indirect_iterator(local_cells.begin()),
boost::make_indirect_iterator(local_cells.end()),
Utils::NoOp{}, pair_kernel,
[](Particle const &p1, Particle const &p2) {
return (p1.r.p - p2.r.p).norm2();
});
Algorithm::link_cell(
boost::make_indirect_iterator(cell_structure.m_local_cells.begin()),
boost::make_indirect_iterator(cell_structure.m_local_cells.end()),
Utils::NoOp{}, pair_kernel, [](Particle const &p1, Particle const &p2) {
return (p1.r.p - p2.r.p).norm2();
});
break;
case CELL_STRUCTURE_NSQUARE:
Algorithm::link_cell(
boost::make_indirect_iterator(local_cells.begin()),
boost::make_indirect_iterator(local_cells.end()), Utils::NoOp{},
pair_kernel, [](Particle const &p1, Particle const &p2) {
boost::make_indirect_iterator(cell_structure.m_local_cells.begin()),
boost::make_indirect_iterator(cell_structure.m_local_cells.end()),
Utils::NoOp{}, pair_kernel, [](Particle const &p1, Particle const &p2) {
return get_mi_vector(p1.r.p, p2.r.p, box_geo).norm2();
});
break;
case CELL_STRUCTURE_LAYERED:
Algorithm::link_cell(boost::make_indirect_iterator(local_cells.begin()),
boost::make_indirect_iterator(local_cells.end()),
Utils::NoOp{}, pair_kernel,
[](Particle const &p1, Particle const &p2) {
auto vec21 = get_mi_vector(p1.r.p, p2.r.p, box_geo);
vec21[2] = p1.r.p[2] - p2.r.p[2];

return vec21.norm2();
});
Algorithm::link_cell(
boost::make_indirect_iterator(cell_structure.m_local_cells.begin()),
boost::make_indirect_iterator(cell_structure.m_local_cells.end()),
Utils::NoOp{}, pair_kernel, [](Particle const &p1, Particle const &p2) {
auto vec21 = get_mi_vector(p1.r.p, p2.r.p, box_geo);
vec21[2] = p1.r.p[2] - p2.r.p[2];

return vec21.norm2();
});
}

/* Sort pairs */
@@ -185,7 +182,7 @@ static void topology_release(int cs) {
}

/** Choose the topology init function of a certain cell system. */
void topology_init(int cs, double range, CellPList *local) {
void topology_init(int cs, double range, CellPList local) {
/** broadcast the flag for using Verlet list */
boost::mpi::broadcast(comm_cart, cell_structure.use_verlet_list, 0);

@@ -198,13 +195,13 @@ void topology_init(int cs, double range, CellPList *local) {
topology_init(cell_structure.type, range, local);
break;
case CELL_STRUCTURE_DOMDEC:
dd_topology_init(local, node_grid, range);
dd_topology_init(&local, node_grid, range);
break;
case CELL_STRUCTURE_NSQUARE:
nsq_topology_init(local);
nsq_topology_init(&local);
break;
case CELL_STRUCTURE_LAYERED:
layered_topology_init(local, node_grid, range);
layered_topology_init(&local, node_grid, range);
break;
default:
fprintf(stderr,
@@ -226,16 +223,16 @@ bool topology_check_resort(int cs, bool local_resort) {
}
}

/** Go through \ref ghost_cells and remove the ghost entries from \ref
/** Go through ghost cells and remove the ghost entries from \ref
local_particles. */
static void invalidate_ghosts() {
for (auto const &p : ghost_cells.particles()) {
for (auto const &p : cell_structure.ghost_cells().particles()) {
if (local_particles[p.identity()] == &p) {
local_particles[p.identity()] = {};
}
}

for (auto &c : ghost_cells) {
for (auto &c : cell_structure.m_ghost_cells) {
c->n = 0;
}
}
@@ -249,26 +246,23 @@ static void invalidate_ghosts() {
/************************************************************/

void cells_re_init(int new_cs, double range) {
CellPList tmp_local;

invalidate_ghosts();

topology_release(cell_structure.type);
/* MOVE old local_cell list to temporary buffer */
memmove(&tmp_local, &local_cells, sizeof(CellPList));
init_cellplist(&local_cells);
std::vector<Cell *> old_local_cells;
std::swap(old_local_cells, cell_structure.m_local_cells);

/* MOVE old cells to temporary buffer */
auto tmp_cells = std::move(cells);

topology_init(new_cs, range, &tmp_local);
topology_init(
new_cs, range,
{old_local_cells.data(), static_cast<int>(old_local_cells.size())});
cell_structure.min_range = range;

clear_particle_node();

/* finally deallocate the old cells */
realloc_cellplist(&tmp_local, 0);

for (auto &cell : tmp_cells) {
cell.resize(0);
}
@@ -302,7 +296,8 @@ unsigned const &get_resort_particles() { return resort_particles; }
/*************************************************/

int cells_get_n_particles() {
return std::accumulate(local_cells.begin(), local_cells.end(), 0,
return std::accumulate(cell_structure.m_local_cells.begin(),
cell_structure.m_local_cells.end(), 0,
[](int n, const Cell *c) { return n + c->n; });
}

@@ -370,7 +365,7 @@ void cells_resort_particles(int global_flag) {
n_verlet_updates++;

ParticleList displaced_parts =
sort_and_fold_parts(cell_structure, local_cells);
sort_and_fold_parts(cell_structure, cell_structure.local_cells());

switch (cell_structure.type) {
case CELL_STRUCTURE_LAYERED: {
@@ -391,7 +386,7 @@ void cells_resort_particles(int global_flag) {
<< " moved more than"
" one local box length in one timestep.";
resort_particles = Cells::RESORT_GLOBAL;
append_indexed_particle(local_cells.cell[0], std::move(part));
append_indexed_particle(cell_structure.m_local_cells[0], std::move(part));
}
} else {
#ifdef ADDITIONAL_CHECKS
@@ -412,7 +407,7 @@ void cells_resort_particles(int global_flag) {

displaced_parts.clear();

on_resort_particles(local_cells.particles());
on_resort_particles(cell_structure.local_cells().particles());
}

/*************************************************/
@@ -440,13 +435,14 @@ void cells_on_geometry_change(int flags) {
void check_resort_particles() {
const double skin2 = Utils::sqr(skin / 2.0);

resort_particles |= (std::any_of(local_cells.particles().begin(),
local_cells.particles().end(),
[&skin2](Particle const &p) {
return (p.r.p - p.l.p_old).norm2() > skin2;
}))
? Cells::RESORT_LOCAL
: Cells::RESORT_NONE;
resort_particles |=
(std::any_of(cell_structure.local_cells().particles().begin(),
cell_structure.local_cells().particles().end(),
[&skin2](Particle const &p) {
return (p.r.p - p.l.p_old).norm2() > skin2;
}))
? Cells::RESORT_LOCAL
: Cells::RESORT_NONE;
}

/*************************************************/
@@ -39,18 +39,6 @@
* - layered: in x and y directions, it uses a nsquared type of
* interaction calculation, but in z it has a domain decomposition
* into layers.
*
* Some structures are common to all cell systems:
*
* - All cells, real cells as well as ghost cells, are stored in the
* vector \ref cells::cells whose size has to be changed with
* \ref realloc_cells.
* - There are two lists of cell pointers to access particles and
* ghost particles on a node: \ref local_cells contains pointers to
* all cells containing the particles physically residing on that
* node. \ref ghost_cells contains pointers to all cells containing
* the ghost particles of that node. The size of these lists has to be
* changed with \ref realloc_cellplist
*/

#include <utility>
@@ -103,7 +91,7 @@ enum Resort : unsigned {
/** \name Flags for cells_on_geometry_change */
/*@{*/

/** Flag for cells_on_geometry_change: the processor grid has changed. */
/** Flag for cells_on_geometry_change: the prozcessor grid has changed. */
#define CELL_FLAG_GRIDCHANGED 1
/** Flag for cells_on_geometry_change: skip shrinking of cells. */
#define CELL_FLAG_FAST 2
@@ -127,9 +115,8 @@ struct CellPList {

Cell *operator[](int i) { return assert(i < n), cell[i]; }

Cell **cell;
int n;
int max;
Cell **cell = nullptr;
int n = 0;
};

/** Describes a cell structure / cell system. Contains information
@@ -140,6 +127,9 @@ struct CellPList {
* be stored in separate structures.
*/
struct CellStructure {
std::vector<Cell *> m_local_cells = {};
std::vector<Cell *> m_ghost_cells = {};

/** type descriptor */
int type = CELL_STRUCTURE_NONEYET;

@@ -152,9 +142,9 @@ struct CellStructure {
double min_range;

/** Return the global local_cells */
CellPList local_cells() const;
CellPList local_cells();
/** Return the global ghost_cells */
CellPList ghost_cells() const;
CellPList ghost_cells();

/** Communicator to exchange ghost particles. */
GhostCommunicator exchange_ghosts_comm;
@@ -180,11 +170,6 @@ struct CellStructure {
/** list of all cells. */
extern std::vector<Cell> cells;

/** list of all cells containing particles physically on the local node */
extern CellPList local_cells;
/** list of all cells containing ghosts */
extern CellPList ghost_cells;

/** Type of cell structure in use. */
extern CellStructure cell_structure;

@@ -210,21 +195,6 @@ void cells_re_init(int new_cs, double range);
/** Reallocate the list of all cells (\ref cells::cells). */
void realloc_cells(int size);

/** Initialize a list of cell pointers */
inline void init_cellplist(CellPList *cpl) {
cpl->n = 0;
cpl->max = 0;
cpl->cell = nullptr;
}

/** Reallocate a list of cell pointers */
inline void realloc_cellplist(CellPList *cpl, int size) {
if (size != cpl->max) {
cpl->max = size;
cpl->cell = (Cell **)Utils::realloc(cpl->cell, sizeof(Cell *) * cpl->max);
}
}

/** Sort the particles into the cells and initialize the ghost particle
* structures.
*/
@@ -367,7 +367,8 @@ void place_vs_and_relate_to_particle(const int current_vs_pid,
Particle new_part;
new_part.p.identity = current_vs_pid;
new_part.r.p = pos;
auto p_vs = append_indexed_particle(local_cells.cell[0], std::move(new_part));
auto p_vs = append_indexed_particle(cell_structure.local_cells().cell[0],
std::move(new_part));

local_vs_relate_to(*p_vs, get_part(relate_to));

@@ -131,11 +131,9 @@ inline void detect_collision(Particle const &p1, Particle const &p2,
if (!glue_to_surface_criterion(p1, p2))
return;

#ifdef VIRTUAL_SITES_RELATIVE
// Ignore virtual particles
if ((p1.p.is_virtual) || (p2.p.is_virtual))
return;
#endif

// Check, if there's already a bond between the particles
if (pair_bond_exists_on(p1, p2, collision_params.bond_centers))
@@ -57,7 +57,6 @@
#include "pressure.hpp"
#include "rotation.hpp"
#include "statistics.hpp"
#include "statistics_chain.hpp"
#include "virtual_sites.hpp"

#include "electrostatics_magnetostatics/coulomb.hpp"
@@ -61,6 +61,8 @@ struct CUDA_particle_data {
int identity;
#ifdef VIRTUAL_SITES
bool is_virtual;
#else
static constexpr const bool is_virtual = false;
#endif

/** particle momentum struct velocity p.m->v*/

0 comments on commit 6b4f756

Please sign in to comment.
You can’t perform that action at this time.