40#include "accumulators/AutoUpdateAccumulators.hpp"
45#include "collision_detection/CollisionDetection.hpp"
57#include "system/System.hpp"
65#include <boost/mpi/collectives/all_reduce.hpp>
67#ifdef ESPRESSO_CALIPER
68#include <caliper/cali.h>
71#ifdef ESPRESSO_VALGRIND
86#ifdef ESPRESSO_WALBERLA
87#ifdef ESPRESSO_WALBERLA_STATIC_ASSERT
88#error "waLberla headers should not be visible to the ESPResSo core"
93volatile std::sig_atomic_t
ctrl_C = 0;
104 assert(m_protocol !=
nullptr);
111 auto &
system = get_system();
112 auto &cell_structure = *
system.cell_structure;
113 auto &box_geo = *
system.box_geo;
115 m_protocol = std::move(protocol);
116 update_box_params(box_geo,
system.get_sim_time());
117 system.propagation->recalc_forces =
true;
122 auto &
system = get_system();
123 auto &cell_structure = *
system.cell_structure;
124 auto &box_geo = *
system.box_geo;
125 m_protocol =
nullptr;
127 system.propagation->recalc_forces =
true;
143#ifdef ESPRESSO_ROTATION
148#ifdef ESPRESSO_ROTATION
153#ifdef ESPRESSO_ROTATION
158#ifdef ESPRESSO_ROTATION
172#ifdef ESPRESSO_ROTATION
176#ifdef ESPRESSO_STOKESIAN_DYNAMICS
182 throw std::runtime_error(
"Unknown value for integ_switch");
188 for (
auto &p : cell_structure->local_particles()) {
189 used_propagations |= p.propagation();
192 used_propagations |= propagation->default_propagation;
194 used_propagations = boost::mpi::all_reduce(
::comm_cart, used_propagations,
196 propagation->used_propagations = used_propagations;
197 propagation->recalc_used_propagations =
false;
200void System::System::integrator_sanity_checks()
const {
201 auto const thermo_switch = thermostat->thermo_switch;
202 if (time_step <= 0.) {
208 <<
"The steepest descent integrator is incompatible with thermostats";
214 "currently active combination of thermostats";
226 nptiso->coulomb_dipole_sanity_checks(*
this);
227 }
catch (std::runtime_error
const &
err) {
238#ifdef ESPRESSO_STOKESIAN_DYNAMICS
244 if (lb.is_solver_set()
and (propagation->used_propagations &
247 if (thermostat->lb ==
nullptr) {
251 if (bonded_ias->get_n_thermalized_bonds() >= 1
and
252 (thermostat->thermalized_bond ==
nullptr or
255 <<
"Thermalized bonds require the thermalized_bond thermostat";
258#ifdef ESPRESSO_ROTATION
259 for (
auto const &p : cell_structure->local_particles()) {
261 if (p.can_rotate()
and not p.is_virtual()
and
262 (p.propagation() & (SYSTEM_DEFAULT | ROT_EULER | ROT_LANGEVIN |
263 ROT_BROWNIAN | ROT_STOKESIAN)) == 0) {
265 <<
"Rotating particles must have a rotation propagation mode enabled";
271#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
272#ifdef ESPRESSO_EXTERNAL_FORCES
273 if (propagation->used_propagations &
275 for (
auto const &p : cell_structure->local_particles()) {
277 if ((p.propagation() & TRANS_VS_CENTER_OF_MASS)
and
278 p.has_fixed_coordinates()) {
285#ifdef ESPRESSO_BOND_CONSTRAINT
286 if (bonded_ias->get_n_rigid_bonds()) {
288 for (
auto const &p : cell_structure->local_particles()) {
289 if (p.propagation() & TRANS_VS_CENTER_OF_MASS) {
290 for (
auto const bond : p.bonds()) {
291 if (std::holds_alternative<RigidBond>(
292 *bonded_ias->at(
bond.bond_id()))) {
303#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
305 for (
auto const &p : cell_structure->local_particles()) {
306 if (p.stoner_wohlfarth_is_enabled()) {
307 runtimeErrorMsg() <<
"The thermal Stoner-Wohlfarth model requires the "
308 "Langevin thermostat";
316#ifdef ESPRESSO_WALBERLA
319 if (time_step <= 0.) {
323 auto const eps =
static_cast<double>(std::numeric_limits<float>::epsilon());
324 if ((tau - time_step) / (tau + time_step) < -eps)
325 throw std::invalid_argument(
method +
" tau (" + std::to_string(tau) +
326 ") must be >= MD time_step (" +
327 std::to_string(time_step) +
")");
328 auto const factor = tau / time_step;
330 throw std::invalid_argument(
method +
" tau (" + std::to_string(tau) +
331 ") must be an integer multiple of the "
333 std::to_string(time_step) +
"). Factor is " +
347 std::stringstream error_msg;
348 error_msg <<
"waLBerla and ESPResSo disagree about domain decomposition"
350 <<
"left ESPResSo: [" <<
geo_left <<
"], "
353 <<
"right ESPResSo: [" <<
geo_right <<
"], "
355 <<
"\nfor method: " <<
method;
356 throw std::runtime_error(error_msg.str());
362#ifdef ESPRESSO_CALIPER
365 auto &cell_structure = *
system.cell_structure;
367 *
system.box_geo, cell_structure.get_le_pos_offset_at_last_resort());
368 if (cell_structure.check_resort_required(offset)) {
379#ifdef ESPRESSO_CALIPER
384 return system.steepest_descent->propagate(cell_structure);
386 auto const &thermostat = *
system.thermostat;
387 auto const kT = thermostat.kT;
389#ifdef ESPRESSO_VIRTUAL_SITES
400#ifdef ESPRESSO_ROTATION
406#ifdef ESPRESSO_ROTATION
416#ifdef ESPRESSO_ROTATION
422#ifdef ESPRESSO_ROTATION
429#ifdef ESPRESSO_ROTATION
451#ifdef ESPRESSO_STOKESIAN_DYNAMICS
456 *
system.stokesian_dynamics, *thermostat.stokesian,
468#ifdef ESPRESSO_CALIPER
475#ifdef ESPRESSO_VIRTUAL_SITES
486#ifdef ESPRESSO_ROTATION
492#ifdef ESPRESSO_ROTATION
502#ifdef ESPRESSO_ROTATION
508#ifdef ESPRESSO_ROTATION
531#ifdef ESPRESSO_CALIPER
534 auto &propagation = *this->propagation;
535#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
537 return propagation.used_propagations &
543#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
545 return propagation.used_propagations &
549#ifdef ESPRESSO_BOND_CONSTRAINT
550 auto const n_rigid_bonds = bonded_ias->get_n_rigid_bonds();
554 propagation.update_default_propagation(thermostat->thermo_switch);
555 update_used_propagations();
556 on_integration_start();
565 propagation.recalc_forces)) {
566#ifdef ESPRESSO_CALIPER
569 thermostat->lb_coupling_deactivate();
571#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
576#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
583 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
588#ifdef ESPRESSO_ROTATION
593#ifdef ESPRESSO_CALIPER
598 thermostat->lb_coupling_activate();
616 ek_active = ek.is_ready_for_propagation();
619 return static_cast<int>(std::round(tau / time_step));
622#ifdef ESPRESSO_VALGRIND
626#ifdef ESPRESSO_CALIPER
631#ifdef ESPRESSO_CALIPER
635#ifdef ESPRESSO_BOND_CONSTRAINT
638 cell_structure->ghost_particles());
641 lees_edwards->update_box_params(*box_geo, sim_time);
647 sim_time += time_step;
650 cell_structure->for_each_local_particle(
651 [&kernel](
Particle &p) { kernel(p); });
655 if (
not has_npt_enabled())
661 thermostat->philox_counter_increment();
663#ifdef ESPRESSO_BOND_CONSTRAINT
670#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
673 if (has_npt_enabled()) {
674 cell_structure->update_ghosts_and_resort_particle(
681#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
684 if (has_npt_enabled()) {
685 cell_structure->update_ghosts_and_resort_particle(
697 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
699#ifdef ESPRESSO_THERMAL_STONER_WOHLFARTH
700 integrate_magnetodynamics();
705#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
706 if (thermostat->lb
and
718 cell_structure->for_each_local_particle(
719 [&kernel](
Particle &p) { kernel(p); });
721#ifdef ESPRESSO_BOND_CONSTRAINT
736 <<
"LB and EK are active but with different time steps.";
739 assert(lb.is_gpu() == ek.is_gpu());
740 assert(propagation.lb_skipped_md_steps ==
741 propagation.ek_skipped_md_steps);
743 propagation.lb_skipped_md_steps += 1;
744 propagation.ek_skipped_md_steps += 1;
746 propagation.lb_skipped_md_steps = 0;
747 propagation.ek_skipped_md_steps = 0;
748#ifdef ESPRESSO_CALIPER
752 lb.ghost_communication_vel();
753#ifdef ESPRESSO_CALIPER
758#ifdef ESPRESSO_CALIPER
764 propagation.lb_skipped_md_steps += 1;
766 propagation.lb_skipped_md_steps = 0;
767#ifdef ESPRESSO_CALIPER
771#ifdef ESPRESSO_CALIPER
777 propagation.ek_skipped_md_steps += 1;
779 propagation.ek_skipped_md_steps = 0;
780#ifdef ESPRESSO_CALIPER
784#ifdef ESPRESSO_CALIPER
791 thermostat->lb->rng_increment();
794#ifdef ESPRESSO_VIRTUAL_SITES_INERTIALESS_TRACERS
795 if (thermostat->lb
and
797#ifdef ESPRESSO_CALIPER
801 lb.ghost_communication_vel();
804#ifdef ESPRESSO_CALIPER
810#ifdef ESPRESSO_COLLISION_DETECTION
811 collision_detection->handle_collisions();
813 bond_breakage->process_queue(*
this);
831 lb.ghost_communication();
833 lees_edwards->update_box_params(*box_geo, sim_time);
834#ifdef ESPRESSO_CALIPER
838#ifdef ESPRESSO_VALGRIND
842#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
847#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
857 if (has_npt_enabled()) {
858 synchronize_npt_state();
868#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
869 if (boost::mpi::all_reduce(
::comm_cart,
not cell_structure->use_verlet_list,
870 std::logical_or<>())) {
871 cell_structure->use_verlet_list =
false;
885 if (
not cell_structure->is_verlet_skin_set()) {
887 cell_structure->set_verlet_skin_heuristic();
900 for (
int i = 0; i <
n_steps;) {
904 std::min((
n_steps - i), auto_update_accumulators->next_update());
928 propagation->recalc_forces =
true;
929 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(ParticleUnaryOp &&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.
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 method, Utils::Vector3d const &geo_left, Utils::Vector3d const &geo_right, Utils::Vector3d const &lattice_left, Utils::Vector3d const &lattice_right, double agrid)
void walberla_tau_sanity_checks(std::string method, double tau, double time_step)
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.