Skip to content

Commit

Permalink
Merge branch 'python' into fix-4143
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Apr 1, 2021
2 parents 899e981 + 051c5b8 commit 4d518ae
Show file tree
Hide file tree
Showing 124 changed files with 2,291 additions and 2,520 deletions.
2 changes: 0 additions & 2 deletions doc/sphinx/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ Fluid dynamics and fluid structure interaction
- ``EK_DEBUG``
- ``EK_DOUBLE_PREC``
.. _Interaction features:
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/active_matter/active_matter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Active Matter Tutorial\n",
"# Active Matter\n",
"## Table of Contents\n",
"1. [Introduction](#Introduction)\n",
"2. [Active particles](#Active-particles)\n",
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorials/charged_system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
configure_tutorial_target(TARGET tutorial_crg DEPENDS charged_system-1.ipynb)
configure_tutorial_target(TARGET tutorial_crg DEPENDS charged_system.ipynb)

nb_export(TARGET tutorial_crg SUFFIX "1" FILE "charged_system-1.ipynb" HTML_RUN)
nb_export(TARGET tutorial_crg SUFFIX "1" FILE "charged_system.ipynb" HTML_RUN)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 2: Charged Systems: Counterion Condensation\n",
"# A Charged System: Counterion Condensation\n",
"\n",
"## Table of contents\n",
"* [Introduction](#Introduction)\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/constant_pH/constant_pH.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 12: The Reaction-Ensemble Method"
"# The Reaction-Ensemble Method"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/electrokinetics/electrokinetics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 7: Electrokinetics"
"# Electrokinetics"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/ferrofluid/ferrofluid_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Ferrofluid - Part I"
"# Ferrofluid - Part 1"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/ferrofluid/ferrofluid_part2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Ferrofluid - Part II"
"# Ferrofluid - Part 2"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/ferrofluid/ferrofluid_part3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Ferrofluid - Part III "
"# Ferrofluid - Part 3 "
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 4 : The lattice-Boltzmann method in ESPResSo - Part 1\n",
"# The Lattice-Boltzmann Method in ESPResSo - Part 1\n",
"\n",
"#### Before you start:\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 4 : The lattice-Boltzmann method in ESPResSo - Part 2"
"# The Lattice-Boltzmann Method in ESPResSo - Part 2"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 4 : The lattice-Boltzmann method in ESPResSo - Part 3"
"# The Lattice-Boltzmann Method in ESPResSo - Part 3"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 4 : The lattice-Boltzmann method in ESPResSo - Part 4"
"# The Lattice-Boltzmann Method in ESPResSo - Part 4"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/lennard_jones/lennard_jones.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 1: Lennard-Jones Liquid"
"# Introductory Tutorial: Lennard-Jones Liquid"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 5: Raspberry Electrophoresis"
"# Raspberry Electrophoresis"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/visualization/visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 8: Visualization"
"# Visualization"
]
},
{
Expand Down
1 change: 0 additions & 1 deletion src/config/features.def
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ ELECTROKINETICS requires CUDA
EK_BOUNDARIES implies ELECTROKINETICS, LB_BOUNDARIES_GPU, EXTERNAL_FORCES, ELECTROSTATICS
EK_BOUNDARIES requires CUDA
EK_DEBUG requires ELECTROKINETICS
EK_DOUBLE_PREC requires ELECTROKINETICS

/* Interaction features */
TABULATED
Expand Down
9 changes: 9 additions & 0 deletions src/core/CellStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ static unsigned map_data_parts(unsigned data_parts) {
| ((DATA_PART_POSITION & data_parts) ? GHOSTTRANS_POSITION : 0u)
| ((DATA_PART_MOMENTUM & data_parts) ? GHOSTTRANS_MOMENTUM : 0u)
| ((DATA_PART_FORCE & data_parts) ? GHOSTTRANS_FORCE : 0u)
#ifdef BOND_CONSTRAINT
| ((DATA_PART_RATTLE & data_parts) ? GHOSTTRANS_RATTLE : 0u)
#endif
| ((DATA_PART_BONDS & data_parts) ? GHOSTTRANS_BONDS : 0u);
/* clang-format on */
}
Expand All @@ -166,6 +169,12 @@ void CellStructure::ghosts_reduce_forces() {
ghost_communicator(decomposition().collect_ghost_force_comm(),
GHOSTTRANS_FORCE);
}
#ifdef BOND_CONSTRAINT
void CellStructure::ghosts_reduce_rattle_correction() {
ghost_communicator(decomposition().collect_ghost_force_comm(),
GHOSTTRANS_RATTLE);
}
#endif

Utils::Span<Cell *> CellStructure::local_cells() {
return decomposition().local_cells();
Expand Down
11 changes: 10 additions & 1 deletion src/core/CellStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ enum DataPart : unsigned {
DATA_PART_POSITION = 2u, /**< Particle::r */
DATA_PART_MOMENTUM = 8u, /**< Particle::m */
DATA_PART_FORCE = 16u, /**< Particle::f */
DATA_PART_BONDS = 32u /**< Particle::bonds */
#ifdef BOND_CONSTRAINT
DATA_PART_RATTLE = 32u, /**< Particle::rattle */
#endif
DATA_PART_BONDS = 64u /**< Particle::bonds */
};
} // namespace Cells

Expand Down Expand Up @@ -369,6 +372,12 @@ struct CellStructure {
* @brief Add forces from ghost particles to real particles.
*/
void ghosts_reduce_forces();
#ifdef BOND_CONSTRAINT
/**
* @brief Add rattle corrections from ghost particles to real particles.
*/
void ghosts_reduce_rattle_correction();
#endif

private:
/**
Expand Down
28 changes: 26 additions & 2 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ struct ParticlePosition {

#ifdef BOND_CONSTRAINT
/** particle position at the previous time step (RATTLE algorithm) */
Utils::Vector3d p_old = {0., 0., 0.};
Utils::Vector3d p_last_timestep = {0., 0., 0.};
#endif

template <class Archive> void serialize(Archive &ar, long int /* version */) {
Expand All @@ -277,7 +277,7 @@ struct ParticlePosition {
ar &quat;
#endif
#ifdef BOND_CONSTRAINT
ar &p_old;
ar &p_last_timestep;
#endif
}
};
Expand Down Expand Up @@ -365,6 +365,26 @@ struct ParticleLocal {
}
};

#ifdef BOND_CONSTRAINT
struct ParticleRattle {
/** position/velocity correction */
Utils::Vector3d correction = {0, 0, 0};

friend ParticleRattle operator+(ParticleRattle const &lhs,
ParticleRattle const &rhs) {
return {lhs.correction + rhs.correction};
}

ParticleRattle &operator+=(ParticleRattle const &rhs) {
return *this = *this + rhs;
}

template <class Archive> void serialize(Archive &ar, long int /* version */) {
ar &correction;
}
};
#endif

/** Struct holding all information for one particle. */
struct Particle { // NOLINT(bugprone-exception-escape)
int &identity() { return p.identity; }
Expand All @@ -391,6 +411,10 @@ struct Particle { // NOLINT(bugprone-exception-escape)
ParticleForce f;
///
ParticleLocal l;
#ifdef BOND_CONSTRAINT
///
ParticleRattle rattle;
#endif

private:
BondList bl;
Expand Down
3 changes: 0 additions & 3 deletions src/core/actor/DipolarBarnesHut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@

#include <memory>

// This needs to be done in the .cu file too
typedef float dds_float;

class DipolarBarnesHut : public Actor {
public:
DipolarBarnesHut(SystemInterface &s, float epssq, float itolsq) {
Expand Down
28 changes: 12 additions & 16 deletions src/core/actor/DipolarBarnesHut_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@

#include <cuda.h>

typedef float dds_float;

#define IND (blockDim.x * blockIdx.x + threadIdx.x)

using namespace std;

// Method performance/accuracy parameters
__constant__ float epssqd[1], itolsqd[1];
// blkcntd is a factual blocks' count.
Expand All @@ -57,7 +53,7 @@ __device__ __constant__ volatile BHData bhpara[1];
// The "half-convolution" multi-thread reduction.
// The thread with a lower index will operate longer and
// final result (here: the sum) is flowing down towards zero thread.
__device__ void dds_sumReduction_BH(dds_float *input, dds_float *sum) {
__device__ void dds_sumReduction_BH(float *input, float *sum) {
auto tid = static_cast<int>(threadIdx.x);
for (auto i = static_cast<int>(blockDim.x); i > 1; i /= 2) {
__syncthreads();
Expand Down Expand Up @@ -690,7 +686,7 @@ __global__ __launch_bounds__(THREADS4, FACTOR4) void sortKernel() {
/******************************************************************************/

__global__ __launch_bounds__(THREADS5, FACTOR5) void forceCalculationKernel(
dds_float pf, float *force, float *torque) {
float pf, float *force, float *torque) {
int i, j, k, l, n, depth, base, sbase, diff, t;
float tmp;
// dr is a distance between particles.
Expand Down Expand Up @@ -902,7 +898,7 @@ __global__ __launch_bounds__(THREADS5, FACTOR5) void forceCalculationKernel(
/******************************************************************************/

__global__ __launch_bounds__(THREADS5, FACTOR5) void energyCalculationKernel(
dds_float pf, dds_float *energySum) {
float pf, float *energySum) {
// NOTE: the algorithm of this kernel is almost identical to
// forceCalculationKernel. See comments there.

Expand All @@ -912,8 +908,8 @@ __global__ __launch_bounds__(THREADS5, FACTOR5) void energyCalculationKernel(
__shared__ int pos[MAXDEPTH * THREADS5 / WARPSIZE],
node[MAXDEPTH * THREADS5 / WARPSIZE];
__shared__ float dq[MAXDEPTH * THREADS5 / WARPSIZE];
dds_float sum = 0.0;
extern __shared__ dds_float res[];
float sum = 0.0;
extern __shared__ float res[];

float b, d1, dd5;

Expand Down Expand Up @@ -1120,7 +1116,7 @@ void sortBH(int blocks) {
}

// Force calculation.
int forceBH(BHData *bh_data, dds_float k, float *f, float *torque) {
int forceBH(BHData *bh_data, float k, float *f, float *torque) {
int error_code = 0;
dim3 grid(1, 1, 1);
dim3 block(1, 1, 1);
Expand All @@ -1137,26 +1133,26 @@ int forceBH(BHData *bh_data, dds_float k, float *f, float *torque) {
}

// Energy calculation.
int energyBH(BHData *bh_data, dds_float k, float *E) {
int energyBH(BHData *bh_data, float k, float *E) {
int error_code = 0;
dim3 grid(1, 1, 1);
dim3 block(1, 1, 1);

grid.x = bh_data->blocks * FACTOR5;
block.x = THREADS5;

dds_float *energySum;
cuda_safe_mem(cudaMalloc(&energySum, (int)(sizeof(dds_float) * grid.x)));
float *energySum;
cuda_safe_mem(cudaMalloc(&energySum, (int)(sizeof(float) * grid.x)));
// cleanup the memory for the energy sum
cuda_safe_mem(cudaMemset(energySum, 0, (int)(sizeof(dds_float) * grid.x)));
cuda_safe_mem(cudaMemset(energySum, 0, (int)(sizeof(float) * grid.x)));

KERNELCALL_shared(energyCalculationKernel, grid, block,
block.x * sizeof(dds_float), k, energySum);
block.x * sizeof(float), k, energySum);
cuda_safe_mem(cudaDeviceSynchronize());

// Sum the results of all blocks
// One energy part per block in the prev kernel
thrust::device_ptr<dds_float> t(energySum);
thrust::device_ptr<float> t(energySum);
float x = thrust::reduce(t, t + grid.x);
cuda_safe_mem(cudaMemcpy(E, &x, sizeof(float), cudaMemcpyHostToDevice));

Expand Down
6 changes: 2 additions & 4 deletions src/core/actor/DipolarBarnesHut_cuda.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#ifdef DIPOLAR_BARNES_HUT

typedef float dds_float;

typedef struct {
/// CUDA blocks
int blocks;
Expand Down Expand Up @@ -117,10 +115,10 @@ void summarizeBH(int blocks);
void sortBH(int blocks);

/// Barnes-Hut force calculation.
int forceBH(BHData *bh_data, dds_float k, float *f, float *torque);
int forceBH(BHData *bh_data, float k, float *f, float *torque);

/// Barnes-Hut energy calculation.
int energyBH(BHData *bh_data, dds_float k, float *E);
int energyBH(BHData *bh_data, float k, float *E);

#endif // DIPOLAR_BARNES_HUT
#endif /* DIPOLARBARNESHUT_CUH_ */
Loading

0 comments on commit 4d518ae

Please sign in to comment.