Skip to content
Permalink
Browse files

Merge branch 'python' into unifdef_vs_ext_flag

  • Loading branch information
kodiakhq committed Jan 8, 2020
2 parents 9ac2f91 + 60a6856 commit 2d81fbdae1c33acb678eab38a80a3c60a1c3a91e
Showing with 325 additions and 381 deletions.
  1. +1 −1 src/core/EspressoSystemInterface.cpp
  2. +49 −53 src/core/cells.cpp
  3. +8 −38 src/core/cells.hpp
  4. +2 −1 src/core/collision.cpp
  5. +0 −1 src/core/communication.cpp
  6. +9 −9 src/core/debug.cpp
  7. +8 −13 src/core/diamond.cpp
  8. +0 −2 src/core/diamond.hpp
  9. +9 −8 src/core/domain_decomposition.cpp
  10. +1 −1 src/core/electrostatics_magnetostatics/coulomb.cpp
  11. +1 −1 src/core/electrostatics_magnetostatics/mdlc_correction.cpp
  12. +68 −50 src/core/electrostatics_magnetostatics/mmm2d.cpp
  13. +1 −1 src/core/electrostatics_magnetostatics/p3m-dipolar.cpp
  14. +1 −1 src/core/electrostatics_magnetostatics/p3m.cpp
  15. +2 −2 src/core/electrostatics_magnetostatics/scafacos.cpp
  16. +2 −2 src/core/energy.cpp
  17. +1 −1 src/core/forces.cpp
  18. +5 −5 src/core/galilei.cpp
  19. +3 −3 src/core/ghosts.hpp
  20. +4 −4 src/core/immersed_boundary/ImmersedBoundaries.cpp
  21. +1 −1 src/core/integrate.cpp
  22. +6 −6 src/core/layered.cpp
  23. +4 −4 src/core/nsquare.cpp
  24. +12 −9 src/core/particle_data.cpp
  25. +36 −48 src/core/polymer.cpp
  26. +2 −23 src/core/polymer.hpp
  27. +1 −1 src/core/pressure.cpp
  28. +1 −1 src/core/rattle.cpp
  29. +4 −2 src/core/short_range_loop.hpp
  30. +1 −1 src/core/statistics.cpp
  31. +1 −1 src/core/statistics.hpp
  32. +7 −27 src/core/statistics_chain.cpp
  33. +35 −28 src/core/statistics_chain.hpp
  34. +4 −4 src/core/virtual_sites/VirtualSitesInertialessTracers.cpp
  35. +3 −3 src/core/virtual_sites/VirtualSitesRelative.cpp
  36. +12 −12 src/core/virtual_sites/lb_inertialess_tracers.cpp
  37. +3 −6 src/python/espressomd/analyze.pxd
  38. +15 −6 src/python/espressomd/analyze.pyx
  39. +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))
@@ -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));

@@ -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"
@@ -37,8 +37,8 @@ void check_particle_consistency() {
int cell_err_cnt = 0;

/* checks: part_id, part_pos, local_particles id */
for (c = 0; c < local_cells.n; c++) {
auto const cell = local_cells.cell[c];
for (c = 0; c < cell_structure.local_cells().n; c++) {
auto const cell = cell_structure.local_cells().cell[c];
cell_part_cnt += cell->n;
for (int n = 0; n < cell->n; n++) {
auto const &p = cell->part[n];
@@ -73,8 +73,8 @@ void check_particle_consistency() {
}
}

for (c = 0; c < ghost_cells.n; c++) {
auto const cell = ghost_cells.cell[c];
for (c = 0; c < cell_structure.ghost_cells().n; c++) {
auto const cell = cell_structure.ghost_cells().cell[c];
if (cell->n > 0) {
ghost_part_cnt += cell->n;
fprintf(stderr,
@@ -112,10 +112,10 @@ void check_particle_consistency() {
"but %d parts in local_particles\n",
this_node, cell_part_cnt, local_part_cnt);

for (c = 0; c < local_cells.n; c++) {
for (int p = 0; p < local_cells.cell[c]->n; p++)
for (c = 0; c < cell_structure.local_cells().n; c++) {
for (int p = 0; p < cell_structure.local_cells().cell[c]->n; p++)
fprintf(stderr, "%d: got particle %d in cell %d\n", this_node,
local_cells.cell[c]->part[p].p.identity, c);
cell_structure.local_cells().cell[c]->part[p].p.identity, c);
}

for (int p = 0; p < n_part; p++)
@@ -136,8 +136,8 @@ void check_particle_consistency() {
}

void check_particle_sorting() {
for (int c = 0; c < local_cells.n; c++) {
auto const cell = local_cells.cell[c];
for (int c = 0; c < cell_structure.local_cells().n; c++) {
auto const cell = cell_structure.local_cells().cell[c];
for (int n = 0; n < cell->n; n++) {
auto const p = cell->part[n];
if (cell_structure.particle_to_cell(p) != cell) {

0 comments on commit 2d81fbd

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