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

Reduce usage of local_cells #3065

Merged
merged 14 commits into from
Aug 9, 2019
2 changes: 1 addition & 1 deletion src/core/cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void cells_resort_particles(int global_flag) {
resort_particles = Cells::RESORT_NONE;
rebuild_verletlist = 1;

on_resort_particles();
on_resort_particles(local_cells.particles());

CELL_TRACE(
fprintf(stderr, "%d: leaving cells_resort_particles\n", this_node));
Expand Down
71 changes: 37 additions & 34 deletions src/core/electrostatics_magnetostatics/coulomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void pressure_n(int &n_coulomb) {
}

void calc_pressure_long_range(Observable_stat &virials,
Observable_stat &p_tensor) {
Observable_stat &p_tensor,
const ParticleRange &particles) {
switch (coulomb.method) {
#ifdef P3M
case COULOMB_ELC_P3M:
Expand All @@ -54,9 +55,9 @@ void calc_pressure_long_range(Observable_stat &virials,
"WARNING: pressure calculated, but GPU P3M pressure not implemented\n");
break;
case COULOMB_P3M: {
p3m_charge_assign();
virials.coulomb[1] = p3m_calc_kspace_forces(0, 1);
p3m_charge_assign();
p3m_charge_assign(particles);
virials.coulomb[1] = p3m_calc_kspace_forces(0, 1, particles);
p3m_charge_assign(particles);
p3m_calc_kspace_stress(p_tensor.coulomb + 9);
break;
}
Expand Down Expand Up @@ -220,15 +221,15 @@ void on_coulomb_change() {
}
}

void on_resort_particles() {
void on_resort_particles(const ParticleRange &particles) {
switch (coulomb.method) {
#ifdef P3M
case COULOMB_ELC_P3M:
ELC_on_resort_particles();
break;
#endif
case COULOMB_MMM2D:
MMM2D_on_resort_particles();
MMM2D_on_resort_particles(particles);
break;
default:
break;
Expand Down Expand Up @@ -287,23 +288,23 @@ void init() {
}
}

void calc_long_range_force() {
void calc_long_range_force(const ParticleRange &particles) {
switch (coulomb.method) {
#ifdef P3M
case COULOMB_ELC_P3M:
if (elc_params.dielectric_contrast_on) {
ELC_P3M_modify_p3m_sums_both();
ELC_p3m_charge_assign_both();
ELC_P3M_self_forces();
ELC_P3M_modify_p3m_sums_both(particles);
ELC_p3m_charge_assign_both(particles);
ELC_P3M_self_forces(particles);
} else
p3m_charge_assign();
p3m_charge_assign(particles);

p3m_calc_kspace_forces(1, 0);
p3m_calc_kspace_forces(1, 0, particles);

if (elc_params.dielectric_contrast_on)
ELC_P3M_restore_p3m_sums();
ELC_P3M_restore_p3m_sums(particles);

ELC_add_force();
ELC_add_force(particles);

break;
#endif
Expand All @@ -320,17 +321,17 @@ void calc_long_range_force() {
#endif
#ifdef P3M
case COULOMB_P3M:
p3m_charge_assign();
p3m_charge_assign(particles);
#ifdef NPT
if (integ_switch == INTEG_METHOD_NPT_ISO)
nptiso.p_vir[0] += p3m_calc_kspace_forces(1, 1);
nptiso.p_vir[0] += p3m_calc_kspace_forces(1, 1, particles);
else
#endif
p3m_calc_kspace_forces(1, 0);
p3m_calc_kspace_forces(1, 0, particles);
break;
#endif
case COULOMB_MMM2D:
MMM2D_add_far_force();
MMM2D_add_far_force(particles);
MMM2D_dielectric_layers_force_contribution();
break;
#ifdef SCAFACOS
Expand All @@ -351,43 +352,45 @@ void calc_long_range_force() {
#endif
}

void calc_energy_long_range(Observable_stat &energy) {
void calc_energy_long_range(Observable_stat &energy,
const ParticleRange &particles) {
switch (coulomb.method) {
#ifdef P3M
case COULOMB_P3M_GPU:
runtimeWarningMsg()
<< "long range energy calculation not implemented for GPU P3M";
break;
case COULOMB_P3M:
p3m_charge_assign();
energy.coulomb[1] = p3m_calc_kspace_forces(0, 1);
p3m_charge_assign(particles);
energy.coulomb[1] = p3m_calc_kspace_forces(0, 1, particles);
break;
case COULOMB_ELC_P3M:
// assign the original charges first
// they may not have been assigned yet
p3m_charge_assign();
p3m_charge_assign(particles);
if (!elc_params.dielectric_contrast_on)
energy.coulomb[1] = p3m_calc_kspace_forces(0, 1);
energy.coulomb[1] = p3m_calc_kspace_forces(0, 1, particles);
else {
energy.coulomb[1] = 0.5 * p3m_calc_kspace_forces(0, 1);
energy.coulomb[1] += 0.5 * ELC_P3M_dielectric_layers_energy_self();
energy.coulomb[1] = 0.5 * p3m_calc_kspace_forces(0, 1, particles);
energy.coulomb[1] +=
0.5 * ELC_P3M_dielectric_layers_energy_self(particles);

// assign both original and image charges now
ELC_p3m_charge_assign_both();
ELC_P3M_modify_p3m_sums_both();
ELC_p3m_charge_assign_both(particles);
ELC_P3M_modify_p3m_sums_both(particles);

energy.coulomb[1] += 0.5 * p3m_calc_kspace_forces(0, 1);
energy.coulomb[1] += 0.5 * p3m_calc_kspace_forces(0, 1, particles);

// assign only the image charges now
ELC_p3m_charge_assign_image();
ELC_P3M_modify_p3m_sums_image();
ELC_p3m_charge_assign_image(particles);
ELC_P3M_modify_p3m_sums_image(particles);

energy.coulomb[1] -= 0.5 * p3m_calc_kspace_forces(0, 1);
energy.coulomb[1] -= 0.5 * p3m_calc_kspace_forces(0, 1, particles);

// restore modified sums
ELC_P3M_restore_p3m_sums();
ELC_P3M_restore_p3m_sums(particles);
}
energy.coulomb[2] = ELC_energy();
energy.coulomb[2] = ELC_energy(particles);
break;
#endif
#ifdef SCAFACOS
Expand All @@ -397,7 +400,7 @@ void calc_energy_long_range(Observable_stat &energy) {
break;
#endif
case COULOMB_MMM2D:
*energy.coulomb += MMM2D_far_energy();
*energy.coulomb += MMM2D_far_energy(particles);
*energy.coulomb += MMM2D_dielectric_layers_energy_contribution();
break;
default:
Expand Down
11 changes: 7 additions & 4 deletions src/core/electrostatics_magnetostatics/coulomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifdef ELECTROSTATICS
#include "Observable_stat.hpp"

#include <ParticleRange.hpp>
#include <utils/Vector.hpp>

/** \name Type codes for the type of Coulomb interaction
Expand Down Expand Up @@ -51,7 +52,8 @@ extern Coulomb_parameters coulomb;
namespace Coulomb {
void pressure_n(int &n_coulomb);
void calc_pressure_long_range(Observable_stat &virials,
Observable_stat &p_tensor);
Observable_stat &p_tensor,
const ParticleRange &particles);

void sanity_checks(int &state);
double cutoff(const Utils::Vector3d &box_l);
Expand All @@ -60,13 +62,14 @@ void deactivate();
void integrate_sanity_check();
void on_observable_calc();
void on_coulomb_change();
void on_resort_particles();
void on_resort_particles(const ParticleRange &particles);
void on_boxl_change();
void init();

void calc_long_range_force();
void calc_long_range_force(const ParticleRange &particles);

void calc_energy_long_range(Observable_stat &energy);
void calc_energy_long_range(Observable_stat &energy,
const ParticleRange &particles);
int energy_n();

int iccp3m_sanity_check();
Expand Down
39 changes: 21 additions & 18 deletions src/core/electrostatics_magnetostatics/dipole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,34 @@ void init() {
}
}

void calc_long_range_force() {
void calc_long_range_force(const ParticleRange &particles) {
switch (dipole.method) {
#ifdef DP3M
case DIPOLAR_MDLC_P3M:
add_mdlc_force_corrections();
add_mdlc_force_corrections(particles);
// fall through
case DIPOLAR_P3M:
dp3m_dipole_assign();
dp3m_dipole_assign(particles);
#ifdef NPT
if (integ_switch == INTEG_METHOD_NPT_ISO) {
nptiso.p_vir[0] += dp3m_calc_kspace_forces(1, 1);
nptiso.p_vir[0] += dp3m_calc_kspace_forces(1, 1, particles);
fprintf(stderr, "dipolar_P3M at this moment is added to p_vir[0]\n");
} else
#endif
dp3m_calc_kspace_forces(1, 0);
dp3m_calc_kspace_forces(1, 0, particles);

break;
#endif
case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA:
dawaanr_calculations(1, 0);
dawaanr_calculations(1, 0, particles);
break;
#ifdef DP3M
case DIPOLAR_MDLC_DS:
add_mdlc_force_corrections();
add_mdlc_force_corrections(particles);
// fall through
#endif
case DIPOLAR_DS:
magnetic_dipolar_direct_sum_calculations(1, 0);
magnetic_dipolar_direct_sum_calculations(1, 0, particles);
break;
case DIPOLAR_DS_GPU:
// Do nothing. It's an actor
Expand All @@ -205,30 +205,33 @@ void calc_long_range_force() {
}
}

void calc_energy_long_range(Observable_stat &energy) {
void calc_energy_long_range(Observable_stat &energy,
const ParticleRange &particles) {
switch (dipole.method) {
#ifdef DP3M
case DIPOLAR_P3M:
dp3m_dipole_assign();
energy.dipolar[1] = dp3m_calc_kspace_forces(0, 1);
dp3m_dipole_assign(particles);
energy.dipolar[1] = dp3m_calc_kspace_forces(0, 1, particles);
break;
case DIPOLAR_MDLC_P3M:
dp3m_dipole_assign();
energy.dipolar[1] = dp3m_calc_kspace_forces(0, 1);
energy.dipolar[2] = add_mdlc_energy_corrections();
dp3m_dipole_assign(particles);
energy.dipolar[1] = dp3m_calc_kspace_forces(0, 1, particles);
energy.dipolar[2] = add_mdlc_energy_corrections(particles);
break;
#endif
case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA:
energy.dipolar[1] = dawaanr_calculations(0, 1);
energy.dipolar[1] = dawaanr_calculations(0, 1, particles);
break;
#ifdef DP3M
case DIPOLAR_MDLC_DS:
energy.dipolar[1] = magnetic_dipolar_direct_sum_calculations(0, 1);
energy.dipolar[2] = add_mdlc_energy_corrections();
energy.dipolar[1] =
magnetic_dipolar_direct_sum_calculations(0, 1, particles);
energy.dipolar[2] = add_mdlc_energy_corrections(particles);
break;
#endif
case DIPOLAR_DS:
energy.dipolar[1] = magnetic_dipolar_direct_sum_calculations(0, 1);
energy.dipolar[1] =
magnetic_dipolar_direct_sum_calculations(0, 1, particles);
break;
case DIPOLAR_DS_GPU:
break;
Expand Down
6 changes: 4 additions & 2 deletions src/core/electrostatics_magnetostatics/dipole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern double dipolar_cutoff;

#include <utils/Vector.hpp>

#include <ParticleRange.hpp>
#include <boost/mpi/communicator.hpp>

/** \name Compounds for Dipole interactions */
Expand Down Expand Up @@ -69,9 +70,10 @@ void on_coulomb_change();
void on_boxl_change();
void init();

void calc_long_range_force();
void calc_long_range_force(const ParticleRange &particles);

void calc_energy_long_range(Observable_stat &energy);
void calc_energy_long_range(Observable_stat &energy,
const ParticleRange &particles);
void energy_n(int &n_dipolar);

int set_mesh();
Expand Down
Loading