68#include <boost/mpi/collectives/all_reduce.hpp>
70#ifdef ESPRESSO_CALIPER
74#ifdef ESPRESSO_VALGRIND
89#ifdef ESPRESSO_WALBERLA
90#ifdef ESPRESSO_WALBERLA_STATIC_ASSERT
91#error "waLberla headers should not be visible to the ESPResSo core"
96volatile std::sig_atomic_t
ctrl_C = 0;
107 assert(m_protocol !=
nullptr);
115 auto &cell_structure = *system.cell_structure;
116 auto &box_geo = *system.box_geo;
118 m_protocol = std::move(protocol);
120 system.propagation->recalc_forces =
true;
126 auto &cell_structure = *system.cell_structure;
127 auto &box_geo = *system.box_geo;
128 m_protocol =
nullptr;
130 system.propagation->recalc_forces =
true;
146#ifdef ESPRESSO_ROTATION
151#ifdef ESPRESSO_ROTATION
156#ifdef ESPRESSO_ROTATION
161#ifdef ESPRESSO_ROTATION
175#ifdef ESPRESSO_ROTATION
179#ifdef ESPRESSO_STOKESIAN_DYNAMICS
185 throw std::runtime_error(
"Unknown value for integ_switch");
192 used_propagations |= p.propagation();
195 used_propagations |=
propagation->default_propagation;
197 used_propagations = boost::mpi::all_reduce(
::comm_cart, used_propagations,
199 propagation->used_propagations = used_propagations;
203void System::System::integrator_sanity_checks()
const {
204 auto const thermo_switch = thermostat->thermo_switch;
205 if (time_step <= 0.) {
211 <<
"The steepest descent integrator is incompatible with thermostats";
217 "currently active combination of thermostats";
229 nptiso->coulomb_dipole_sanity_checks(*
this);
230 }
catch (std::runtime_error
const &err) {
241#ifdef ESPRESSO_STOKESIAN_DYNAMICS
247 if (lb.is_solver_set() and (propagation->used_propagations &
250 if (thermostat->lb ==
nullptr) {
254 if (bonded_ias->get_n_thermalized_bonds() >= 1 and
255 (thermostat->thermalized_bond ==
nullptr or
258 <<
"Thermalized bonds require the thermalized_bond thermostat";
260#ifdef ESPRESSO_BOND_CONSTRAINT
261 if (bonded_ias->get_n_rigid_bonds() >= 1) {
262 if (not propagation->is_inertial()) {
264 <<
"Rigid bonds (RATTLE) require an inertial integrator "
265 "(VV or symplectic Euler); BD and SD are not supported";
270#ifdef ESPRESSO_STOKESIAN_DYNAMICS
273 auto pred = PropagationPredicateStokesian(propagation->default_propagation);
274 stokesian_dynamics->sanity_checks(
275 cell_structure->local_particles().filter(pred));
279#ifdef ESPRESSO_ROTATION
280 for (
auto const &p : cell_structure->local_particles()) {
282 if (p.can_rotate() and not p.is_virtual() and
283 (p.propagation() & (SYSTEM_DEFAULT | ROT_EULER | ROT_LANGEVIN |
284 ROT_BROWNIAN | ROT_STOKESIAN)) == 0) {
286 <<
"Rotating particles must have a rotation propagation mode enabled";
292#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
293#ifdef ESPRESSO_EXTERNAL_FORCES
294 if (propagation->used_propagations &
296 for (
auto const &p : cell_structure->local_particles()) {
298 if ((p.propagation() & TRANS_VS_CENTER_OF_MASS) and
299 p.has_fixed_coordinates()) {
306#ifdef ESPRESSO_BOND_CONSTRAINT
307 if (bonded_ias->get_n_rigid_bonds()) {
309 for (
auto const &p : cell_structure->local_particles()) {
310 if (p.propagation() & TRANS_VS_CENTER_OF_MASS) {
311 for (
auto const bond : p.bonds()) {
312 if (std::holds_alternative<RigidBond>(
313 *bonded_ias->at(bond.bond_id()))) {
324#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
326 for (
auto const &p : cell_structure->local_particles()) {
327 if (p.stoner_wohlfarth_is_enabled()) {
328 runtimeErrorMsg() <<
"The thermal Stoner-Wohlfarth model requires the "
329 "Langevin thermostat";
337#ifdef ESPRESSO_WALBERLA
340 if (time_step <= 0.) {
344 auto const eps =
static_cast<double>(std::numeric_limits<float>::epsilon());
345 if ((tau - time_step) / (tau + time_step) < -eps)
346 throw std::invalid_argument(method +
" tau (" + std::to_string(tau) +
347 ") must be >= MD time_step (" +
348 std::to_string(time_step) +
")");
349 auto const factor = tau / time_step;
350 if (std::fabs(std::round(factor) - factor) / factor > eps)
351 throw std::invalid_argument(method +
" tau (" + std::to_string(tau) +
352 ") must be an integer multiple of the "
354 std::to_string(time_step) +
"). Factor is " +
355 std::to_string(factor));
365 auto const tol = agrid / 1E6;
366 if ((lattice_left - geo_left).norm2() > tol or
367 (lattice_right - geo_right).norm2() > tol) {
368 std::stringstream error_msg;
369 error_msg <<
"waLBerla and ESPResSo disagree about domain decomposition"
371 <<
"left ESPResSo: [" << geo_left <<
"], "
372 <<
"left waLBerla: [" << lattice_left <<
"]"
374 <<
"right ESPResSo: [" << geo_right <<
"], "
375 <<
"right waLBerla: [" << lattice_right <<
"]"
376 <<
"\nfor method: " << method;
377 throw std::runtime_error(error_msg.str());
383#ifdef ESPRESSO_CALIPER
388 *system.
box_geo, cell_structure.get_le_pos_offset_at_last_resort());
389 if (cell_structure.check_resort_required(offset)) {
400#ifdef ESPRESSO_CALIPER
408 auto const kT = thermostat.kT;
410#ifdef ESPRESSO_VIRTUAL_SITES
421#ifdef ESPRESSO_ROTATION
427#ifdef ESPRESSO_ROTATION
437#ifdef ESPRESSO_ROTATION
443#ifdef ESPRESSO_ROTATION
450#ifdef ESPRESSO_ROTATION
472#ifdef ESPRESSO_STOKESIAN_DYNAMICS
503 return [&propagation, time_step](
Particle &p) {
504#ifdef ESPRESSO_VIRTUAL_SITES
515#ifdef ESPRESSO_ROTATION
521#ifdef ESPRESSO_ROTATION
531#ifdef ESPRESSO_ROTATION
537#ifdef ESPRESSO_ROTATION
549#ifdef ESPRESSO_CALIPER
587 double time_step,
bool interior_pass) {
588#ifdef ESPRESSO_CALIPER
594 "integrator_step_2_filtered: steepest-descent is ineligible");
598 "integrator_step_2_filtered: NPT propagation is ineligible");
610#ifdef ESPRESSO_CALIPER
614#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
622#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
628#ifdef ESPRESSO_BOND_CONSTRAINT
629 auto const n_rigid_bonds =
bonded_ias->get_n_rigid_bonds();
645#ifdef ESPRESSO_CALIPER
650#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
655#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
674#ifdef ESPRESSO_CALIPER
685 int n_verlet_updates = 0;
689 auto const singleton_mode =
comm_cart.size() == 1;
690 auto caught_sigint =
false;
691 auto caught_error =
false;
693 auto lb_active =
false;
694 auto ek_active =
false;
696 lb_active =
lb.is_solver_set();
697 ek_active =
ek.is_ready_for_propagation();
699 auto const calc_md_steps_per_tau = [
this](
double tau) {
700 return static_cast<int>(std::round(tau /
time_step));
703#ifdef ESPRESSO_VALGRIND
704 CALLGRIND_START_INSTRUMENTATION;
707#ifdef ESPRESSO_CALIPER
710 int integrated_steps = 0;
711 for (
int step = 0; step < n_steps; step++) {
712#ifdef ESPRESSO_CALIPER
713 auto espresso_cali_integration_iter =
714 espresso_cali_integration_loop.
iteration(step);
717#ifdef ESPRESSO_BOND_CONSTRAINT
733 [&kernel](
Particle &p) { kernel(p); });
745#ifdef ESPRESSO_BOND_CONSTRAINT
752#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
763#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
781#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
787#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
793 "LB-tracer arm must be inactive on the split-phase path");
829 guard.active =
false;
841 [&kernel](
Particle &p) { kernel(p); });
843#ifdef ESPRESSO_BOND_CONSTRAINT
851 if (lb_active and ek_active) {
853 auto const md_steps_per_lb_step = calc_md_steps_per_tau(
lb.get_tau());
854 auto const md_steps_per_ek_step = calc_md_steps_per_tau(
ek.get_tau());
856 if (md_steps_per_lb_step != md_steps_per_ek_step) {
858 <<
"LB and EK are active but with different time steps.";
861 assert(
lb.is_gpu() ==
ek.is_gpu());
867 if (
propagation.lb_skipped_md_steps >= md_steps_per_lb_step) {
870#ifdef ESPRESSO_CALIPER
874 lb.ghost_communication_vel();
875#ifdef ESPRESSO_CALIPER
878#ifdef ESPRESSO_CALIPER
882#ifdef ESPRESSO_CALIPER
886 }
else if (lb_active) {
887 auto const md_steps_per_lb_step = calc_md_steps_per_tau(
lb.get_tau());
889 if (
propagation.lb_skipped_md_steps >= md_steps_per_lb_step) {
891#ifdef ESPRESSO_CALIPER
895#ifdef ESPRESSO_CALIPER
899 }
else if (ek_active) {
900 auto const md_steps_per_ek_step = calc_md_steps_per_tau(
ek.get_tau());
902 if (
propagation.ek_skipped_md_steps >= md_steps_per_ek_step) {
904#ifdef ESPRESSO_CALIPER
908#ifdef ESPRESSO_CALIPER
918#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
921#ifdef ESPRESSO_CALIPER
925 lb.ghost_communication_vel();
928#ifdef ESPRESSO_CALIPER
934#ifdef ESPRESSO_COLLISION_DETECTION
950 if (singleton_mode and ctrl_C == 1) {
951 caught_sigint =
true;
957 lb.ghost_communication();
962#ifdef ESPRESSO_VALGRIND
963 CALLGRIND_STOP_INSTRUMENTATION;
966#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
971#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
993 std::logical_or<>())) {
996 return integrated_steps;
1000 bool update_accumulators) {
1001 assert(n_steps >= 0);
1018 if (not update_accumulators or n_steps == 0) {
1019 return integrate(n_steps, reuse_forces);
1022 for (
int i = 0; i < n_steps;) {
1028 auto const local_retval =
integrate(steps, reuse_forces);
1031 std::remove_const_t<
decltype(local_retval)> global_retval;
1032 boost::mpi::all_reduce(
comm_cart, local_retval, global_retval,
1034 if (global_retval < 0) {
1035 return global_retval;
1040 (*auto_update_accumulators)(
comm_cart, steps);
@ INTEG_METHOD_NPT_ISO_AND
@ INTEG_METHOD_STEEPEST_DESCENT
@ INTEG_METHOD_SYMPLECTIC_EULER
@ INTEG_METHOD_NPT_ISO_MTK
Data structures for bonded interactions.
Zero-overhead Caliper guards for the inactive (no CALI_CONFIG) case.
#define ESPRESSO_CALI_MARK_END(name)
Guarded CALI_MARK_END — no-op when inactive.
#define ESPRESSO_CALI_MARK_BEGIN(name)
Guarded CALI_MARK_BEGIN — no-op when inactive.
#define ESPRESSO_CALI_MARK_FUNCTION
Guarded drop-in replacement for CALI_CXX_MARK_FUNCTION.
This file contains everything related to the global cell structure / cell system.
void lees_edwards_update(double pos_offset, double shear_velocity)
Update the Lees-Edwards parameters of the box geometry for the current simulation time.
Describes a cell structure / cell system.
void for_each_local_particle(ParticleCallback auto &&f, bool parallel=true) const
Run a kernel on all local particles.
void for_each_interior_particle(ParticleCallback auto &&f) const
Run a kernel on interior (non-boundary) local particles only.
bool has_pending_ghost_reduce() const
True when a split-phase force reduction is in flight.
void for_each_boundary_particle(ParticleCallback auto &&f) const
Run a kernel on boundary local particles only.
void ghosts_reduce_forces_finish()
Complete the split-phase ghost force reduction.
ParticleRange local_particles() const
void update_box_params(BoxGeometry &box_geo, double sim_time)
Update the Lees-Edwards parameters of the box geometry for the current simulation time.
void set_protocol(std::shared_ptr< ActiveProtocol > protocol)
Set a new Lees-Edwards protocol.
void unset_protocol()
Delete the currently active Lees-Edwards protocol.
ParticleRangeFiltered< Predicate > filter(Predicate pred) const
void update_default_propagation(int thermo_switch)
bool should_propagate_with(Particle const &p, int mode) const
RAII guard for signal handling.
unsigned get_global_ghost_flags() const
Returns the ghost flags required for running pair kernels for the global state, e....
std::shared_ptr< StokesianDynamics > stokesian_dynamics
std::shared_ptr< LeesEdwards::LeesEdwards > lees_edwards
double sim_time
Molecular dynamics integrator simulation time.
void update_used_propagations()
Update the global propagation bitmask.
std::shared_ptr< LocalBox > local_geo
std::shared_ptr< BondedInteractionsMap > bonded_ias
void set_sim_time(double value)
Set sim_time.
void on_integration_start()
int integrate_with_signal_handler(int n_steps, int reuse_forces, bool update_accumulators)
std::shared_ptr< Accumulators::AutoUpdateAccumulators > auto_update_accumulators
std::shared_ptr< BondBreakage::BondBreakage > bond_breakage
std::shared_ptr< CollisionDetection::CollisionDetection > collision_detection
void integrate_magnetodynamics()
Run magnetodynamics update for local virtual particles.
void synchronize_npt_state()
Synchronize NpT state such as instantaneous and average pressure.
void calculate_forces()
Calculate all forces.
std::shared_ptr< Propagation > propagation
double time_step
Molecular dynamics integrator time step.
std::shared_ptr< SteepestDescent > steepest_descent
int integrate(int n_steps, int reuse_forces)
Integrate equations of motion.
std::shared_ptr< Thermostat::Thermostat > thermostat
std::shared_ptr< CellStructure > cell_structure
bool has_npt_enabled() const
std::shared_ptr< BoxGeometry > box_geo
void vs_com_update_particles(CellStructure &cell_structure, BoxGeometry const &box_geo)
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
This file contains the asynchronous MPI communication.
Implementation in thermostat.cpp.
int check_runtime_errors(boost::mpi::communicator const &comm)
Count runtime errors on all nodes.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
static auto make_step2_particle_kernel(Propagation const &propagation, double time_step)
Build the per-particle half-kick callable for step_2.
static bool integrator_step_1(CellStructure &cell_structure, Propagation const &propagation, System::System &system, double time_step)
Calls the hook for propagation kernels before the force calculation.
void walberla_tau_sanity_checks(std::string const &method, double tau, double time_step)
static void resort_particles_if_needed(System::System &system)
static void integrator_step_2_filtered(CellStructure &cell_structure, Propagation const &propagation, double time_step, bool interior_pass)
Restricted step_2 for the split-phase ghost-force-reduce overlap.
static void integrator_step_2(CellStructure &cell_structure, Propagation const &propagation, System::System &system, double time_step)
void walberla_agrid_sanity_checks(std::string const &method, Utils::Vector3d const &geo_left, Utils::Vector3d const &geo_right, Utils::Vector3d const &lattice_left, Utils::Vector3d const &lattice_right, double agrid)
Molecular dynamics integrator.
#define INTEG_ERROR_RUNTIME
#define INTEG_ERROR_SIGINT
#define INTEG_REUSE_FORCES_NEVER
recalculate forces unconditionally (mostly used for timing)
#define INTEG_REUSE_FORCES_ALWAYS
do not recalculate forces (mostly when reading checkpoints with forces)
void brownian_dynamics_rotator(BrownianThermostat const &brownian, Particle &p, double time_step, double kT)
void brownian_dynamics_propagator(BrownianThermostat const &brownian, Particle &p, double time_step, double kT)
void lb_tracers_propagate(CellStructure &cell_structure, LB::Solver const &lb, double time_step)
void lb_tracers_add_particle_force_to_fluid(CellStructure &cell_structure, BoxGeometry const &box_geo, LocalBox const &local_box, LB::Solver &lb)
@ DATA_PART_PROPERTIES
Particle::p.
Utils::Vector3d verlet_list_offset(BoxGeometry const &box, double pos_offset_at_last_resort)
double get_shear_velocity(double time, ActiveProtocol const &protocol)
Calculation of current velocity.
double get_pos_offset(double time, ActiveProtocol const &protocol)
PropagationMode
Flags to create bitmasks for propagation modes.
@ TRANS_VS_CENTER_OF_MASS
@ TRANS_LB_MOMENTUM_EXCHANGE
volatile std::sig_atomic_t ctrl_C
Various procedures concerning interactions between particles.
Exports for the NpT code.
void correct_velocity_shake(CellStructure &cs, BoxGeometry const &box_geo, BondedInteractionsMap const &bonded_ias)
Correction of current velocities using RATTLE algorithm.
void save_old_position(const ParticleRange &particles, const ParticleRange &ghost_particles)
copy current position
void correct_position_shake(CellStructure &cs, BoxGeometry const &box_geo, BondedInteractionsMap &bonded_ias)
Propagate velocity and position while using SHAKE algorithm for bond constraint.
RATTLE algorithm (andersen83a).
void vs_relative_update_particles(CellStructure &cell_structure, BoxGeometry const &box_geo)
This file contains all subroutines required to process rotational motion.
See durlofsky87a for the Stokesian dynamics method used here.
void stokesian_dynamics_step_1(ParticleRangeStokesian const &particles, StokesianDynamics const &integrator, StokesianThermostat const &stokesian, double time_step, double kT)
RAII loop wrapper replacing the CALI_CXX_MARK_LOOP_BEGIN / CALI_CXX_MARK_LOOP_ITERATION / CALI_CXX_MA...
EspressoCaliIteration iteration(int iter) const
Return an RAII iteration annotation for the current step.
Struct holding all information for one particle.
constexpr auto is_virtual() const
bool propagate(CellStructure &cell_structure) const
Run steepest descent algorithm.
void symplectic_euler_rotator_2(Particle &, double)
void symplectic_euler_rotator_1(Particle &p, double time_step)
void symplectic_euler_propagator_2(Particle &, double)
Final integration step of the Symplectic Euler integrator For symplectic Euler, there is no second st...
void symplectic_euler_propagator_1(Particle &p, double time_step)
Propagate the velocities and positions.
void velocity_verlet_rotator_1(Particle &p, double time_step)
void velocity_verlet_propagator_2(Particle &p, double time_step)
Final integration step of the Velocity Verlet integrator.
void velocity_verlet_propagator_1(Particle &p, double time_step)
Propagate the velocities and positions.
void velocity_verlet_rotator_2(Particle &p, double time_step)
void velocity_verlet_npt_MTK_step_1(ParticleRangeNPT const &particles, IsotropicNptThermostat const &npt_iso, double time_step, System::System &system)
Special propagator for velocity Verlet NpT with the Andersen method.
void velocity_verlet_npt_MTK_step_2(ParticleRangeNPT const &particles, double time_step, System::System &system)
Final integration step of the velocity Verlet NpT integrator with the MTK method.
void velocity_verlet_npt_Andersen_step_1(ParticleRangeNPT const &particles, IsotropicNptThermostat const &npt_iso, double time_step, System::System &system)
Special propagator for velocity Verlet NpT with the Andersen method.
void velocity_verlet_npt_Andersen_step_2(ParticleRangeNPT const &particles, double time_step, System::System &system)
Final integration step of the velocity Verlet NpT integrator with the Andersen method.