Skip to content

Commit

Permalink
core: Call LB integrator in the main integration loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed May 28, 2021
1 parent 5bc1480 commit 37e7e4c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 49 deletions.
21 changes: 1 addition & 20 deletions src/core/grid_based_algorithms/lb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ std::vector<LB_FluidNode> lbfields;

HaloCommunicator update_halo_comm = HaloCommunicator(0);

/** measures the MD time since the last fluid update */
static double fluidstep = 0.0;

/********************** The Main LB Part *************************************/

/**
* @brief Initialize fluid nodes.
* @param[out] fields Vector containing the fluid nodes
Expand Down Expand Up @@ -900,7 +895,7 @@ void lb_stream(LB_Fluid &lb_fluid, const std::array<T, 19> &populations,
}

/* Collisions and streaming (push scheme) */
void lb_collide_stream() {
void lb_integrate() {
ESPRESSO_PROFILER_CXX_MARK_FUNCTION;
/* loop over all lattice cells (halo excluded) */
#ifdef LB_BOUNDARIES
Expand Down Expand Up @@ -976,20 +971,6 @@ void lb_collide_stream() {
#endif
}

/** Update the lattice Boltzmann fluid.
*
* This function is called from the integrator. Since the time step
* for the lattice dynamics can be coarser than the MD time step, we
* monitor the time since the last lattice update.
*/
void lattice_boltzmann_update(int lb_steps_per_md_step) {
fluidstep += 1;
if (fluidstep >= lb_steps_per_md_step) {
fluidstep = 0;
lb_collide_stream();
}
}

/***********************************************************************/
/** \name Coupling part */
/***********************************************************************/
Expand Down
7 changes: 3 additions & 4 deletions src/core/grid_based_algorithms/lb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*
* For performance reasons it is clever to do streaming and collision at the
* same time because every fluid node has to be read and written only once.
* This increases mainly cache efficiency. This is achieved by
* @ref lb_collide_stream.
* This increases mainly cache efficiency.
*
* The hydrodynamic fields, corresponding to density, velocity and pressure,
* are stored in @ref LB_FluidNode in the array @ref lbfields, the populations
Expand Down Expand Up @@ -177,13 +176,13 @@ extern std::vector<LB_FluidNode> lbfields;
/************************************************************/
/**@{*/

/** Update the lattice Boltzmann system for one time step.
/** Integrate the lattice-Boltzmann system for one time step.
* This function performs the collision step and the streaming step.
* If external force densities are present, they are applied prior to the
* collisions. If boundaries are present, it also applies the boundary
* conditions.
*/
void lattice_boltzmann_update(int lb_steps_per_md_step);
void lb_integrate();

void lb_sanity_checks(const LB_Parameters &lb_parameters);

Expand Down
12 changes: 7 additions & 5 deletions src/core/grid_based_algorithms/lb_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,29 @@ struct NoLBActive : public std::exception {
const char *what() const noexcept override { return "LB not activated"; }
};

void lb_lbfluid_update(int lb_steps_per_md_step) {
void lb_lbfluid_integrate() {
if (lattice_switch == ActiveLB::CPU) {
lattice_boltzmann_update(lb_steps_per_md_step);
lb_integrate();
} else if (lattice_switch == ActiveLB::GPU and this_node == 0) {
#ifdef CUDA
#ifdef ELECTROKINETICS
if (ek_initialized) {
ek_integrate();
} else {
#endif
lattice_boltzmann_update_gpu(lb_steps_per_md_step);
lb_integrate_GPU();
#ifdef ELECTROKINETICS
}
#endif
#endif
}
}

void lb_lbfluid_propagate(int lb_steps_per_md_step) {
void lb_lbfluid_propagate(bool integrate_lb) {
if (lattice_switch != ActiveLB::NONE) {
lb_lbfluid_update(lb_steps_per_md_step);
if (integrate_lb) {
lb_lbfluid_integrate();
}
if (lb_lbfluid_get_kT() > 0.0) {
if (lattice_switch == ActiveLB::GPU) {
#ifdef CUDA
Expand Down
3 changes: 2 additions & 1 deletion src/core/grid_based_algorithms/lb_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ extern ActiveLB lattice_switch;

/**
* @brief Propagate the LB fluid.
* @param integrate_lb Whether to run the collide-stream scheme.
*/
void lb_lbfluid_propagate(int lb_steps_per_md_step);
void lb_lbfluid_propagate(bool integrate_lb);

/**
* @brief Event handler for integration start.
Expand Down
16 changes: 0 additions & 16 deletions src/core/grid_based_algorithms/lbgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,8 @@ LB_parameters_gpu lbpar_gpu = {
/** this is the array that stores the hydrodynamic fields for the output */
std::vector<LB_rho_v_pi_gpu> host_values(0);

/** measures the MD time since the last fluid update */
static int fluidstep = 0;

bool ek_initialized = false;

/*-----------------------------------------------------------*/
/** main of lb_gpu_programm */
/*-----------------------------------------------------------*/

/** %Lattice Boltzmann update gpu called from integrate.cpp */
void lattice_boltzmann_update_gpu(int lb_steps_per_md_step) {
fluidstep += 1;
if (fluidstep >= lb_steps_per_md_step) {
fluidstep = 0;
lb_integrate_GPU();
}
}

/** (Re-)initialize the fluid according to the given value of rho. */
void lb_reinit_fluid_gpu() {

Expand Down
3 changes: 2 additions & 1 deletion src/core/grid_based_algorithms/lbgpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ void lb_GPU_sanity_checks();
void lb_get_device_values_pointer(LB_rho_v_gpu **pointer_address);
void lb_get_boundary_force_pointer(float **pointer_address);
void lb_get_para_pointer(LB_parameters_gpu **pointer_address);
void lattice_boltzmann_update_gpu(int lb_steps_per_md_step);

/** Perform a full initialization of the lattice Boltzmann system.
* All derived parameters and the fluid are reset to their default values.
Expand All @@ -169,6 +168,8 @@ void lb_reinit_fluid_gpu();
void reset_LB_force_densities_GPU(bool buffer = true);

void lb_init_GPU(const LB_parameters_gpu &lbpar_gpu);

/** Integrate the lattice-Boltzmann system for one time step. */
void lb_integrate_GPU();

void lb_get_values_GPU(LB_rho_v_pi_gpu *host_values);
Expand Down
13 changes: 11 additions & 2 deletions src/core/integrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ bool recalc_forces = true;

double verlet_reuse = 0.0;

static int fluid_step = 0;

bool set_py_interrupt = false;
namespace {
volatile std::sig_atomic_t ctrl_C = 0;
Expand Down Expand Up @@ -289,9 +291,16 @@ int integrate(int n_steps, int reuse_forces) {
// propagate one-step functionalities
if (integ_switch != INTEG_METHOD_STEEPEST_DESCENT) {
if (lb_lbfluid_get_lattice_switch() != ActiveLB::NONE) {
auto const tau = lb_lbfluid_get_tau();
auto const lb_steps_per_md_step =
static_cast<int>(std::round(lb_lbfluid_get_tau() / time_step));
lb_lbfluid_propagate(lb_steps_per_md_step);
static_cast<int>(std::round(tau / time_step));
bool integrate_lb = false;
fluid_step += 1;
if (fluid_step >= lb_steps_per_md_step) {
fluid_step = 0;
integrate_lb = true;
}
lb_lbfluid_propagate(integrate_lb);
lb_lbcoupling_propagate();
}

Expand Down

0 comments on commit 37e7e4c

Please sign in to comment.