Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ENGINE shear torque calculation #3277

Merged
merged 6 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions doc/sphinx/particles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ Lattice Boltzmann (LB) swimmers
system = espressomd.System()

system.part.add(id=1, pos=[2, 0, 0], rotation=[1, 1, 1], swimming={
'f_swim': 0.01, 'mode': 'pusher', 'dipole_length': 2.0, 'rotational_friction': 20})
'f_swim': 0.01, 'mode': 'pusher', 'dipole_length': 2.0})

For an explanation of the parameters ``v_swim`` and ``f_swim`` see the previous
item. In lattice Boltzmann self-propulsion is less trivial than for regular MD,
Expand All @@ -549,11 +549,7 @@ nature of the particle's flow field by using one of the modes: ``pusher`` or
``puller``. You will also need to specify a ``dipole_length`` which determines
the distance of the source of propulsion from the particle's center. Note that
you should not put this distance to zero; |es| (currently) does not support
mathematical dipole flow fields. The key ``rotational_friction`` can be used to
set the friction that causes the orientation of the particle to change in shear
flow. The torque on the particle is determined by taking the cross product of
the difference between the fluid velocity at the center of the particle and at
the source point and the vector connecting the center and source.
mathematical dipole flow fields.

You may ask: "Why are there two methods ``v_swim`` and ``f_swim`` for the
self-propulsion using the lattice Boltzmann algorithm?" The answer is
Expand All @@ -566,10 +562,3 @@ reaches a constant speed (given by ``v_swim``) this monopolar moment is gone
and the flow field is zero! In contrast, ``f_swim`` always, i.e., while
accelerating *and* while swimming at constant force possesses a dipolar flow
field.

.. warning::

Please note that even though swimming is interoperable with the
CPU version of LB it is only supported on *one* MPI
rank, i.e. ``n_nodes`` = 1.

8 changes: 1 addition & 7 deletions doc/tutorials/06-active_matter/06-active_matter.tex
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,7 @@ \subsection{\label{sub:lattice}Self-Propulsion with Hydrodynamics}
flow,~\textit{e.g.}, a swimmer in a Posseuille flow. If the thermostat is
switched on, the rotational degrees of freedom will also be thermalized, but
there is still no contribution of rotation due to `external' flow fields. A
rather unsatisfying solution to this problem is offered by the
\codees{rotational_friction} option, which allows one to include the effect of
fluid flow on the rotation. The algorithm computes the difference in fluid flow
velocity between the center of the particle and the coupling point, and takes
the cross product of that with the dipole length. This quantity is then
converted into a torque using the \codees{rotational_friction}. It is
recommended to use an alternative means of obtaining rotations in your LB
It is recommended to use an alternative means of obtaining rotations in your LB
swimming simulations. For example, by constructing a raspberry
particle~\cite{lobaskin04,chatterji05,fischer15,degraaf15,degraaf16b}.

Expand Down
44 changes: 16 additions & 28 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ enum : uint8_t {
ROTATION_Z = 4u
};

struct ParticleParametersSwimming {
bool swimming = false;
double f_swim = 0.;
double v_swim = 0.;
int push_pull = 0;
double dipole_length = 0.;

template <class Archive> void serialize(Archive &ar, long int /* version */) {
ar &swimming &f_swim &v_swim &push_pull &dipole_length;
}
};

/** Properties of a particle which are not supposed to
* change during the integration, but have to be known
* for all ghosts. Ghosts are particles which are
Expand Down Expand Up @@ -156,6 +168,10 @@ struct ParticleProperties {
Utils::Vector3d ext_torque = {0, 0, 0};
#endif
#endif

#ifdef ENGINE
ParticleParametersSwimming swim;
#endif
};

/** Positional information on a particle. Information that is
Expand Down Expand Up @@ -240,27 +256,6 @@ struct ParticleLocal {
Utils::Vector3i i = {0, 0, 0};
};

struct ParticleParametersSwimming {
// ifdef inside because we need this type for some MPI prototypes
#ifdef ENGINE
bool swimming = false;
double f_swim = 0.;
double v_swim = 0.;
int push_pull = 0;
double dipole_length = 0.;
Utils::Vector3d v_center;
Utils::Vector3d v_source;
double rotational_friction = 0.;
#endif

template <typename Archive> void serialize(Archive &ar, long int) {
#ifdef ENGINE
ar &swimming &f_swim &v_swim &push_pull &dipole_length &v_center &v_source
&rotational_friction;
#endif
}
};

/** Struct holding all information for one particle. */
struct Particle {
int &identity() { return p.identity; }
Expand Down Expand Up @@ -292,9 +287,6 @@ struct Particle {
ret.m = m;
ret.f = f;
ret.l = l;
#ifdef ENGINE
ret.swim = swim;
#endif

return ret;
}
Expand Down Expand Up @@ -346,10 +338,6 @@ struct Particle {
*/
IntList el;
#endif

#ifdef ENGINE
ParticleParametersSwimming swim;
#endif
};

#endif
1 change: 0 additions & 1 deletion src/core/communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@

#include "serialization/IA_parameters.hpp"
#include "serialization/Particle.hpp"
#include "serialization/ParticleParametersSwimming.hpp"

#include <utils/Counter.hpp>
#include <utils/u32_to_u64.hpp>
Expand Down
26 changes: 0 additions & 26 deletions src/core/cuda_common_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ std::vector<float> particle_forces_host;
CUDA_energy energy_host;

std::vector<float> particle_torques_host;
#ifdef ENGINE
std::vector<CUDA_v_cs> host_v_cs;
#endif

/**cuda streams for parallel computing on cpu and gpu */
cudaStream_t stream[1];
Expand Down Expand Up @@ -187,9 +184,6 @@ void gpu_change_number_of_part_to_comm() {
particle_data_device = nullptr;
}

#ifdef ENGINE
host_v_cs.clear();
#endif
#ifdef ROTATION
particle_torques_host.clear();
#endif
Expand All @@ -210,9 +204,6 @@ void gpu_change_number_of_part_to_comm() {
cudaHostAllocWriteCombined));
particle_forces_host.resize(3 *
global_part_vars_host.number_of_particles);
#ifdef ENGINE
host_v_cs.resize(global_part_vars_host.number_of_particles);
#endif
#if (defined DIPOLES || defined ROTATION)
particle_torques_host.resize(3 *
global_part_vars_host.number_of_particles);
Expand Down Expand Up @@ -352,23 +343,6 @@ void copy_forces_from_GPU(ParticleRange particles) {
}
}

#if defined(ENGINE) && defined(CUDA)
// setup and call kernel to copy v_cs to host
void copy_v_cs_from_GPU(ParticleRange particles) {
if (global_part_vars_host.communication_enabled == 1 &&
global_part_vars_host.number_of_particles) {
// Copy result from device memory to host memory
if (this_node == 0) {
cuda_safe_mem(cudaMemcpy2D(
host_v_cs.data(), sizeof(CUDA_v_cs), particle_data_device,
sizeof(CUDA_particle_data), sizeof(CUDA_v_cs),
global_part_vars_host.number_of_particles, cudaMemcpyDeviceToHost));
}
cuda_mpi_send_v_cs(particles, host_v_cs);
}
}
#endif

void clear_energy_on_GPU() {
if (!global_part_vars_host.communication_enabled)
// || !global_part_vars_host.number_of_particles )
Expand Down
43 changes: 6 additions & 37 deletions src/core/cuda_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ static void pack_particles(ParticleRange particles,
#endif

#ifdef ENGINE
buffer[i].swim.v_swim = static_cast<float>(part.swim.v_swim);
buffer[i].swim.f_swim = static_cast<float>(part.swim.f_swim);
buffer[i].swim.v_swim = static_cast<float>(part.p.swim.v_swim);
buffer[i].swim.f_swim = static_cast<float>(part.p.swim.f_swim);
buffer[i].swim.director = buffer[i].director;

buffer[i].swim.push_pull = part.swim.push_pull;
buffer[i].swim.dipole_length = static_cast<float>(part.swim.dipole_length);
buffer[i].swim.swimming = part.swim.swimming;
buffer[i].swim.push_pull = part.p.swim.push_pull;
buffer[i].swim.dipole_length =
static_cast<float>(part.p.swim.dipole_length);
buffer[i].swim.swimming = part.p.swim.swimming;
#endif
i++;
}
Expand Down Expand Up @@ -162,38 +163,6 @@ void cuda_mpi_send_forces(ParticleRange particles,
}
}

#if defined(ENGINE) && defined(CUDA)
namespace {
void set_v_cs(ParticleRange particles, const std::vector<CUDA_v_cs> &v_cs) {
int ind = 0;
for (auto &p : particles) {
for (int i = 0; i < 3; i++) {
p.swim.v_center[i] = v_cs[ind].v_cs[0 + i];
p.swim.v_source[i] = v_cs[ind].v_cs[3 + i];
}
ind++;
}
}
} // namespace

void cuda_mpi_send_v_cs(ParticleRange particles,
std::vector<CUDA_v_cs> host_v_cs) {
// first collect number of particles on each node
auto const n_part = particles.size();

// call slave functions to provide the slave data
if (this_node > 0) {
std::vector<CUDA_v_cs> buffer(n_part);

Utils::Mpi::scatter_buffer(buffer.data(), n_part, comm_cart);
set_v_cs(particles, buffer);
} else {
Utils::Mpi::scatter_buffer(host_v_cs.data(), n_part, comm_cart);
set_v_cs(particles, host_v_cs);
}
}
#endif // ifdef ENGINE

/** Takes a CUDA_energy struct and adds it to the core energy struct.
This cannot be done from inside cuda_common_cuda.cu:copy_energy_from_GPU()
because energy.hpp indirectly includes on mpi.h while .cu files may not depend
Expand Down
18 changes: 0 additions & 18 deletions src/core/cuda_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@
#include <utils/Span.hpp>
#include <utils/Vector.hpp>

#ifdef ENGINE
// velocities which need to be copied from the GPU to the CPU to calculate a
// torque
typedef struct {

// center and source velocity of the md part
float v_cs[6];

} CUDA_v_cs;
#endif

// Parameters for swimmers
#ifdef ENGINE
struct CUDA_ParticleParametersSwimming {
Expand Down Expand Up @@ -156,13 +145,6 @@ void cuda_mpi_send_forces(ParticleRange particles,
void cuda_bcast_global_part_params();
void cuda_copy_to_device(void *host_data, void *device_data, size_t n);
void cuda_copy_to_host(void *host_device, void *device_host, size_t n);

#ifdef ENGINE
void copy_v_cs_from_GPU(ParticleRange particles);
void cuda_mpi_send_v_cs(ParticleRange particles,
std::vector<CUDA_v_cs> host_v_cs);
#endif

#endif /* ifdef CUDA */

#endif /* ifdef CUDA_INTERFACE_HPP */
4 changes: 2 additions & 2 deletions src/core/forces_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ inline ParticleForce external_force(Particle const &p) {
#ifdef ENGINE
// apply a swimming force in the direction of
// the particle's orientation axis
if (p.swim.swimming) {
f.f += p.swim.f_swim * p.r.calc_director();
if (p.p.swim.swimming) {
f.f += p.p.swim.f_swim * p.r.calc_director();
}
#endif

Expand Down
21 changes: 0 additions & 21 deletions src/core/ghosts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ static int calc_transmit_size(GhostCommunication &ghost_comm,
if (data_parts & GHOSTTRANS_FORCE)
n_buffer_new += sizeof(ParticleForce);

#ifdef ENGINE
if (data_parts & GHOSTTRANS_SWIMMING)
n_buffer_new += sizeof(ParticleParametersSwimming);
#endif
int count = 0;
for (auto const &pl : ghost_comm.part_lists)
count += pl->n;
Expand Down Expand Up @@ -231,12 +227,6 @@ static void prepare_send_buffer(CommBuf &send_buffer,
if (data_parts & GHOSTTRANS_FORCE) {
archiver << part.f;
}

#ifdef ENGINE
if (data_parts & GHOSTTRANS_SWIMMING) {
archiver << part.swim;
}
#endif
}
}
}
Expand Down Expand Up @@ -311,12 +301,6 @@ static void put_recv_buffer(CommBuf &recv_buffer,
if (data_parts & GHOSTTRANS_FORCE) {
archiver >> part.f;
}

#ifdef ENGINE
if (data_parts & GHOSTTRANS_SWIMMING) {
archiver >> part.swim;
}
#endif
}
}
}
Expand Down Expand Up @@ -368,11 +352,6 @@ static void cell_cell_transfer(GhostCommunication &ghost_comm,
}
if (data_parts & GHOSTTRANS_FORCE)
part2.f += part1.f;

#ifdef ENGINE
if (data_parts & GHOSTTRANS_SWIMMING)
part2.swim = part1.swim;
#endif
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/ghosts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ enum : unsigned {
/// transfer \ref ParticleForce
GHOSTTRANS_FORCE = 16u,
/// resize the receiver particle arrays to the size of the senders
GHOSTTRANS_PARTNUM = 64u,
/// transfer \ref ParticleParametersSwimming
GHOSTTRANS_SWIMMING = 128u
GHOSTTRANS_PARTNUM = 64u
};

/** \name Data Types */
Expand Down
Loading