40#include "accumulators/AutoUpdateAccumulators.hpp"
46#include "collision_detection/CollisionDetection.hpp"
58#include "system/System.hpp"
68#include <boost/mpi/collectives/all_reduce.hpp>
70#ifdef ESPRESSO_CALIPER
71#include <caliper/cali.h>
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);
114 auto &
system = get_system();
115 auto &cell_structure = *
system.cell_structure;
116 auto &box_geo = *
system.box_geo;
118 m_protocol = std::move(protocol);
119 update_box_params(box_geo,
system.get_sim_time());
120 system.propagation->recalc_forces =
true;
125 auto &
system = get_system();
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");
191 for (
auto &p : cell_structure->local_particles()) {
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;
200 propagation->recalc_used_propagations =
false;
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";
261#ifdef ESPRESSO_ROTATION
262 for (
auto const &p : cell_structure->local_particles()) {
264 if (p.can_rotate()
and not p.is_virtual()
and
265 (p.propagation() & (SYSTEM_DEFAULT | ROT_EULER | ROT_LANGEVIN |
266 ROT_BROWNIAN | ROT_STOKESIAN)) == 0) {
268 <<
"Rotating particles must have a rotation propagation mode enabled";
274#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
275#ifdef ESPRESSO_EXTERNAL_FORCES
276 if (propagation->used_propagations &
278 for (
auto const &p : cell_structure->local_particles()) {
280 if ((p.propagation() & TRANS_VS_CENTER_OF_MASS)
and
281 p.has_fixed_coordinates()) {
288#ifdef ESPRESSO_BOND_CONSTRAINT
289 if (bonded_ias->get_n_rigid_bonds()) {
291 for (
auto const &p : cell_structure->local_particles()) {
292 if (p.propagation() & TRANS_VS_CENTER_OF_MASS) {
293 for (
auto const bond : p.bonds()) {
294 if (std::holds_alternative<RigidBond>(
295 *bonded_ias->at(
bond.bond_id()))) {
306#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
308 for (
auto const &p : cell_structure->local_particles()) {
309 if (p.stoner_wohlfarth_is_enabled()) {
310 runtimeErrorMsg() <<
"The thermal Stoner-Wohlfarth model requires the "
311 "Langevin thermostat";
319#ifdef ESPRESSO_WALBERLA
322 if (time_step <= 0.) {
326 auto const eps =
static_cast<double>(std::numeric_limits<float>::epsilon());
327 if ((tau - time_step) / (tau + time_step) < -eps)
328 throw std::invalid_argument(
method +
" tau (" + std::to_string(tau) +
329 ") must be >= MD time_step (" +
330 std::to_string(time_step) +
")");
331 auto const factor = tau / time_step;
333 throw std::invalid_argument(
method +
" tau (" + std::to_string(tau) +
334 ") must be an integer multiple of the "
336 std::to_string(time_step) +
"). Factor is " +
350 std::stringstream error_msg;
351 error_msg <<
"waLBerla and ESPResSo disagree about domain decomposition"
353 <<
"left ESPResSo: [" <<
geo_left <<
"], "
356 <<
"right ESPResSo: [" <<
geo_right <<
"], "
358 <<
"\nfor method: " <<
method;
359 throw std::runtime_error(error_msg.str());
365#ifdef ESPRESSO_CALIPER
368 auto &cell_structure = *
system.cell_structure;
370 *
system.box_geo, cell_structure.get_le_pos_offset_at_last_resort());
371 if (cell_structure.check_resort_required(offset)) {
382#ifdef ESPRESSO_CALIPER
387 return system.steepest_descent->propagate(cell_structure);
389 auto const &thermostat = *
system.thermostat;
390 auto const kT = thermostat.kT;
392#ifdef ESPRESSO_VIRTUAL_SITES
403#ifdef ESPRESSO_ROTATION
409#ifdef ESPRESSO_ROTATION
419#ifdef ESPRESSO_ROTATION
425#ifdef ESPRESSO_ROTATION
432#ifdef ESPRESSO_ROTATION
454#ifdef ESPRESSO_STOKESIAN_DYNAMICS
459 *
system.stokesian_dynamics, *thermostat.stokesian,
471#ifdef ESPRESSO_CALIPER
478#ifdef ESPRESSO_VIRTUAL_SITES
489#ifdef ESPRESSO_ROTATION
495#ifdef ESPRESSO_ROTATION
505#ifdef ESPRESSO_ROTATION
511#ifdef ESPRESSO_ROTATION
534#ifdef ESPRESSO_CALIPER
537 auto &propagation = *this->propagation;
538#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
540 return propagation.used_propagations &
546#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
548 return propagation.used_propagations &
552#ifdef ESPRESSO_BOND_CONSTRAINT
553 auto const n_rigid_bonds = bonded_ias->get_n_rigid_bonds();
557 propagation.update_default_propagation(thermostat->thermo_switch);
558 update_used_propagations();
559 on_integration_start();
568 propagation.recalc_forces)) {
569#ifdef ESPRESSO_CALIPER
572 thermostat->lb_coupling_deactivate();
574#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
579#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
586 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
591#ifdef ESPRESSO_ROTATION
596#ifdef ESPRESSO_CALIPER
601 thermostat->lb_coupling_activate();
619 ek_active = ek.is_ready_for_propagation();
622 return static_cast<int>(std::round(tau / time_step));
625#ifdef ESPRESSO_VALGRIND
629#ifdef ESPRESSO_CALIPER
634#ifdef ESPRESSO_CALIPER
638#ifdef ESPRESSO_BOND_CONSTRAINT
641 cell_structure->ghost_particles());
644 lees_edwards->update_box_params(*box_geo, sim_time);
650 sim_time += time_step;
653 cell_structure->for_each_local_particle(
654 [&kernel](
Particle &p) { kernel(p); });
658 if (
not has_npt_enabled())
664 thermostat->philox_counter_increment();
666#ifdef ESPRESSO_BOND_CONSTRAINT
673#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
676 if (has_npt_enabled()) {
677 cell_structure->update_ghosts_and_resort_particle(
684#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
687 if (has_npt_enabled()) {
688 cell_structure->update_ghosts_and_resort_particle(
700 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
702#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
703 integrate_magnetodynamics();
708#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
709 if (thermostat->lb
and
721 cell_structure->for_each_local_particle(
722 [&kernel](
Particle &p) { kernel(p); });
724#ifdef ESPRESSO_BOND_CONSTRAINT
739 <<
"LB and EK are active but with different time steps.";
742 assert(lb.is_gpu() == ek.is_gpu());
743 assert(propagation.lb_skipped_md_steps ==
744 propagation.ek_skipped_md_steps);
746 propagation.lb_skipped_md_steps += 1;
747 propagation.ek_skipped_md_steps += 1;
749 propagation.lb_skipped_md_steps = 0;
750 propagation.ek_skipped_md_steps = 0;
751#ifdef ESPRESSO_CALIPER
755 lb.ghost_communication_vel();
756#ifdef ESPRESSO_CALIPER
759#ifdef ESPRESSO_CALIPER
763#ifdef ESPRESSO_CALIPER
769 propagation.lb_skipped_md_steps += 1;
771 propagation.lb_skipped_md_steps = 0;
772#ifdef ESPRESSO_CALIPER
776#ifdef ESPRESSO_CALIPER
782 propagation.ek_skipped_md_steps += 1;
784 propagation.ek_skipped_md_steps = 0;
785#ifdef ESPRESSO_CALIPER
789#ifdef ESPRESSO_CALIPER
796 thermostat->lb->rng_increment();
799#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
800 if (thermostat->lb
and
802#ifdef ESPRESSO_CALIPER
806 lb.ghost_communication_vel();
809#ifdef ESPRESSO_CALIPER
815#ifdef ESPRESSO_COLLISION_DETECTION
816 cell_structure->clear_new_bonds();
817 collision_detection->handle_collisions();
818 cell_structure->rebuild_bond_list();
820 bond_breakage->process_queue(*
this);
838 lb.ghost_communication();
840 lees_edwards->update_box_params(*box_geo, sim_time);
841#ifdef ESPRESSO_CALIPER
845#ifdef ESPRESSO_VALGRIND
849#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
854#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
864 if (has_npt_enabled()) {
865 synchronize_npt_state();
875 if (boost::mpi::all_reduce(
::comm_cart,
not cell_structure->use_verlet_list,
876 std::logical_or<>())) {
877 cell_structure->use_verlet_list =
false;
890 if (
not cell_structure->is_verlet_skin_set()) {
892 cell_structure->set_verlet_skin_heuristic();
905 for (
int i = 0; i <
n_steps;) {
909 std::min((
n_steps - i), auto_update_accumulators->next_update());
933 propagation->recalc_forces =
true;
934 lees_edwards->update_box_params(*box_geo, sim_time);
@ INTEG_METHOD_NPT_ISO_AND
@ INTEG_METHOD_STEEPEST_DESCENT
@ INTEG_METHOD_SYMPLECTIC_EULER
@ INTEG_METHOD_NPT_ISO_MTK
Data structures for bonded interactions.
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(Callable &&f, bool parallel=true) const
Run a kernel on all local particles.
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.
void update_used_propagations()
Update the global propagation bitmask.
void set_sim_time(double value)
Set sim_time.
int integrate_with_signal_handler(int n_steps, int reuse_forces, bool update_accumulators)
int integrate(int n_steps, int reuse_forces)
Integrate equations of motion.
void vs_com_update_particles(CellStructure &cell_structure, BoxGeometry const &box_geo)
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
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 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(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)
@ 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 const &bonded_ias)
Propagate velocity and position while using SHAKE algorithm for bond constraint.
void vs_relative_update_particles(CellStructure &cell_structure, BoxGeometry const &box_geo)
void convert_initial_torques(const ParticleRange &particles)
Convert torques to the body-fixed frame before the integration loop.
This file contains all subroutines required to process rotational motion.
See 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)
Struct holding all information for one particle.
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.