Skip to content

Commit

Permalink
Refactor globals.cpp:bcast_parameter (#4261)
Browse files Browse the repository at this point in the history
Fixes #4133

- created MPI-Callbacks for each variable in the old `global.hpp:field`
- removed `globals.hpp` file
- removed the `kT=None, gamma=None` default logic in thermostats.pyx
  • Loading branch information
kodiakhq[bot] authored May 30, 2021
2 parents 6d93c8d + 0116928 commit 0327d9a
Show file tree
Hide file tree
Showing 35 changed files with 415 additions and 677 deletions.
1 change: 0 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set(EspressoCore_SRC
forces.cpp
galilei.cpp
ghosts.cpp
global.cpp
grid.cpp
immersed_boundaries.cpp
interactions.cpp
Expand Down
4 changes: 1 addition & 3 deletions src/core/EspressoSystemStandAlone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "EspressoSystemStandAlone.hpp"
#include "communication.hpp"
#include "global.hpp"
#include "grid.hpp"
#include "integrate.hpp"
#include "virtual_sites.hpp"
Expand Down Expand Up @@ -66,6 +65,5 @@ void EspressoSystemStandAlone::set_time_step(double time_step) const {
void EspressoSystemStandAlone::set_skin(double new_skin) const {
if (!head_node)
return;
skin = new_skin;
mpi_bcast_parameter(FIELD_SKIN);
mpi_set_skin(new_skin);
}
15 changes: 12 additions & 3 deletions src/core/bonded_interactions/rigid_bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

#include "rigid_bond.hpp"
#include "global.hpp"
#include "communication.hpp"

#include <utils/Vector.hpp>

Expand All @@ -35,6 +35,15 @@ RigidBond::RigidBond(double d, double p_tol, double v_tol) {
this->p_tol = 2.0 * p_tol;
this->v_tol = v_tol;

n_rigidbonds += 1;
mpi_bcast_parameter(FIELD_RIGIDBONDS);
mpi_set_n_rigidbonds(n_rigidbonds + 1);
}

void mpi_set_n_rigidbonds_local(int n_rigidbonds) {
::n_rigidbonds = n_rigidbonds;
}

REGISTER_CALLBACK(mpi_set_n_rigidbonds_local)

void mpi_set_n_rigidbonds(int n_rigidbonds) {
mpi_call_all(mpi_set_n_rigidbonds_local, n_rigidbonds);
}
1 change: 1 addition & 0 deletions src/core/bonded_interactions/rigid_bond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ struct RigidBond {
}
};

void mpi_set_n_rigidbonds(int n_rigidbonds);
#endif
18 changes: 13 additions & 5 deletions src/core/bonded_interactions/thermalized_bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
*/

#include "thermalized_bond.hpp"

#include "communication.hpp"
#include "event.hpp"
#include "global.hpp"

#include <cmath>

Expand All @@ -46,7 +45,16 @@ ThermalizedBond::ThermalizedBond(double temp_com, double gamma_com,
pref1_dist = -1.;
pref2_dist = -1.;

n_thermalized_bonds += 1;
mpi_bcast_parameter(FIELD_THERMALIZEDBONDS);
on_parameter_change(FIELD_THERMALIZEDBONDS);
mpi_set_n_thermalized_bonds(n_thermalized_bonds + 1);
}

void mpi_set_n_thermalized_bonds_local(int n_thermalized_bonds) {
::n_thermalized_bonds = n_thermalized_bonds;
on_thermostat_param_change();
}

REGISTER_CALLBACK(mpi_set_n_thermalized_bonds_local)

void mpi_set_n_thermalized_bonds(int n_thermalized_bonds) {
mpi_call_all(mpi_set_n_thermalized_bonds_local, n_thermalized_bonds);
}
1 change: 1 addition & 0 deletions src/core/bonded_interactions/thermalized_bond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ ThermalizedBond::forces(Particle const &p1, Particle const &p2,
return std::make_tuple(force1, force2);
}

void mpi_set_n_thermalized_bonds(int n_thermalized_bonds);
#endif
1 change: 0 additions & 1 deletion src/core/electrostatics_magnetostatics/mdlc_correction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "electrostatics_magnetostatics/dipole.hpp"
#include "electrostatics_magnetostatics/p3m-dipolar.hpp"
#include "errorhandling.hpp"
#include "global.hpp"
#include "grid.hpp"
#include "particle_data.hpp"

Expand Down
1 change: 0 additions & 1 deletion src/core/electrostatics_magnetostatics/p3m_gpu_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include "cuda_interface.hpp"
#include "cuda_utils.cuh"
#include "electrostatics_magnetostatics/coulomb.hpp"
#include "global.hpp"

#include <utils/math/bspline.hpp>
#include <utils/math/int_pow.hpp>
Expand Down
52 changes: 14 additions & 38 deletions src/core/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "electrostatics_magnetostatics/coulomb.hpp"
#include "electrostatics_magnetostatics/dipole.hpp"
#include "errorhandling.hpp"
#include "global.hpp"
#include "grid.hpp"
#include "grid_based_algorithms/electrokinetics.hpp"
#include "grid_based_algorithms/lb_boundaries.hpp"
Expand Down Expand Up @@ -151,7 +150,6 @@ void on_integration_start(double time_step) {
runtimeErrorMsg() << "Nodes disagree about dipolar long range method";
#endif
#endif
check_global_consistency();
#endif /* ADDITIONAL_CHECKS */

on_observable_calc();
Expand Down Expand Up @@ -309,42 +307,20 @@ void on_skin_change() {
on_coulomb_change();
}

void on_parameter_change(int field) {
switch (field) {
case FIELD_MIN_GLOBAL_CUT:
case FIELD_SKIN:
on_skin_change();
break;
case FIELD_NODEGRID:
grid_changed_n_nodes();
cells_re_init(cell_structure.decomposition_type());
break;
case FIELD_TEMPERATURE:
on_temperature_change();
reinit_thermo = true;
break;
case FIELD_TIMESTEP:
lb_lbfluid_reinit_parameters();
case FIELD_LANGEVIN_GAMMA:
case FIELD_LANGEVIN_GAMMA_ROTATION:
case FIELD_NPTISO_G0:
case FIELD_NPTISO_GV:
case FIELD_NPTISO_PISTON:
case FIELD_THERMALIZEDBONDS:
reinit_thermo = true;
break;
case FIELD_FORCE_CAP:
/* If the force cap changed, forces are invalid */
recalc_forces = true;
break;
case FIELD_THERMO_SWITCH:
case FIELD_LATTICE_SWITCH:
case FIELD_RIGIDBONDS:
break;
case FIELD_SIMTIME:
recalc_forces = true;
break;
}
void on_thermostat_param_change() { reinit_thermo = true; }

void on_timestep_change() {
lb_lbfluid_reinit_parameters();
on_thermostat_param_change();
}

void on_simtime_change() { recalc_forces = true; }

void on_forcecap_change() { recalc_forces = true; }

void on_nodegrid_change() {
grid_changed_n_nodes();
cells_re_init(cell_structure.decomposition_type());
}

/**
Expand Down
29 changes: 20 additions & 9 deletions src/core/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
/** \name Hook procedures
* These procedures are called if several significant changes to
* the system happen which may make a reinitialization of subsystems
* necessary. Note that all these functions are called on ALL nodes.
* If you need to do something only on the master node, check
* \ref this_node == 0. The use of the asynchronous mpi_* functions
* (e.g. mpi_bcast_parameter) on the master node is possible.
* necessary.
*/
/**@{*/

Expand Down Expand Up @@ -104,12 +101,26 @@ void on_periodicity_change();
*/
void on_skin_change();

/** called every time other parameters (timestep,...) are changed. Note that
* this does not happen automatically. The callback procedure of the changed
* variable is responsible for that.
* @param parameter is the @ref Fields identifier of the field changed.
/** @brief Called when parameters of thermostats are changed.
*/
void on_parameter_change(int parameter);
void on_thermostat_param_change();

/** @brief Called when the timestep changed. Internally calls @ref
* on_thermostat_param_change.
*/
void on_timestep_change();

/** @brief Called when the simulation time changed.
*/
void on_simtime_change();

/** @brief Called when the force cap changed.
*/
void on_forcecap_change();

/** @brief Called when the node_grid changed.
*/
void on_nodegrid_change();

unsigned global_ghost_flags();

Expand Down
19 changes: 13 additions & 6 deletions src/core/forcecap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@
#include "forcecap.hpp"

#include "Particle.hpp"
#include "global.hpp"
#include "communication.hpp"
#include "event.hpp"

#include <utils/Vector.hpp>

#include <cmath>

double force_cap = 0.0;

void forcecap_set(double forcecap) {
force_cap = forcecap;
mpi_bcast_parameter(FIELD_FORCE_CAP);
}

double forcecap_get() { return force_cap; }

void forcecap_cap(ParticleRange particles) {
Expand All @@ -60,3 +56,14 @@ void forcecap_cap(ParticleRange particles) {
}
}
}

void mpi_set_forcecap_local(double force_cap) {
::force_cap = force_cap;
on_forcecap_change();
}

REGISTER_CALLBACK(mpi_set_forcecap_local)

void mpi_set_forcecap(double force_cap) {
mpi_call_all(mpi_set_forcecap_local, force_cap);
}
3 changes: 2 additions & 1 deletion src/core/forcecap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

#include "ParticleRange.hpp"

void forcecap_set(double forcecap);
double forcecap_get();

void forcecap_cap(ParticleRange particles);

void mpi_set_forcecap(double force_cap);

#endif
Loading

0 comments on commit 0327d9a

Please sign in to comment.