28#include "accumulators/AutoUpdateAccumulators.hpp"
34#include "collision_detection/CollisionDetection.hpp"
35#include "communication.hpp"
42#include "thermostat.hpp"
49#include <boost/mpi/collectives/all_reduce.hpp>
63 auto handle = std::make_shared<System>(Private());
69 box_geo = std::make_shared<BoxGeometry>();
70 local_geo = std::make_shared<LocalBox>();
71 cell_structure = std::make_shared<CellStructure>(*box_geo);
72#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
75 propagation = std::make_shared<Propagation>();
76 bonded_ias = std::make_shared<BondedInteractionsMap>();
77 thermostat = std::make_shared<Thermostat::Thermostat>();
78 nonbonded_ias = std::make_shared<InteractionsNonBonded>();
79 comfixed = std::make_shared<ComFixed>();
80 galilei = std::make_shared<Galilei>();
81 oif_global = std::make_shared<OifGlobal>();
82 immersed_boundaries = std::make_shared<ImmersedBoundaries>();
83#ifdef ESPRESSO_COLLISION_DETECTION
85 std::make_shared<CollisionDetection::CollisionDetection>();
87 bond_breakage = std::make_shared<BondBreakage::BondBreakage>();
88 lees_edwards = std::make_shared<LeesEdwards::LeesEdwards>();
89 auto_update_accumulators =
90 std::make_shared<Accumulators::AutoUpdateAccumulators>();
91 constraints = std::make_shared<Constraints::Constraints>();
93 nptiso = std::make_shared<NptIsoParameters>();
94 npt_inst_pressure = std::make_shared<InstantaneousPressure>();
103void System::initialize() {
104 auto handle = shared_from_this();
105 cell_structure->bind_system(handle);
106 lees_edwards->bind_system(handle);
107 immersed_boundaries->bind_system(handle);
108 bonded_ias->bind_system(handle);
109 thermostat->bind_system(handle);
110 nonbonded_ias->bind_system(handle);
111 oif_global->bind_system(handle);
112 immersed_boundaries->bind_system(handle);
113#ifdef ESPRESSO_COLLISION_DETECTION
114 collision_detection->bind_system(handle);
116 auto_update_accumulators->bind_system(handle);
117 constraints->bind_system(handle);
119 gpu.bind_system(handle);
122 lb.bind_system(handle);
123 ek.bind_system(handle);
136 throw std::domain_error(
"time_step must be > 0.");
137 if (lb.is_solver_set()) {
138 lb.veto_time_step(value);
140 if (ek.is_solver_set()) {
141 ek.veto_time_step(value);
144 on_timestep_change();
148 if (lb.is_solver_set()) {
151 if (ek.is_solver_set()) {
158 propagation->recalc_forces =
true;
162 min_global_cut = value;
163 on_verlet_skin_change();
170 auto &old_regular_decomposition =
172 std::as_const(*cell_structure).decomposition());
173 cell_structure->set_regular_decomposition(
174 get_interaction_range(),
175 old_regular_decomposition.fully_connected_boundary());
177 cell_structure->set_regular_decomposition(get_interaction_range(), {});
180 cell_structure->set_atom_decomposition();
185 std::as_const(*cell_structure).decomposition());
186 cell_structure->set_hybrid_decomposition(
187 old_hybrid_decomposition.get_cutoff_regular(),
188 old_hybrid_decomposition.get_n_square_types());
193 set_cell_structure_topology(cell_structure->decomposition_type());
198 rebuild_cell_structure();
201 if (not skip_method_adaption) {
204#ifdef ESPRESSO_ELECTROSTATICS
205 coulomb.on_boxl_change();
207#ifdef ESPRESSO_DIPOLES
208 dipoles.on_boxl_change();
211 constraints->on_boxl_change();
215 if (not skip_particle_checks) {
216 auto const n_part = boost::mpi::all_reduce(
217 ::comm_cart, cell_structure->local_particles().size(), std::plus<>());
219 throw std::runtime_error(
220 "Cannot reset the box length when particles are present");
223 constraints->veto_boxl_change();
224 lb.veto_boxl_change();
225 ek.veto_boxl_change();
230 lb.on_node_grid_change();
231 ek.on_node_grid_change();
232#ifdef ESPRESSO_ELECTROSTATICS
233 coulomb.on_node_grid_change();
235#ifdef ESPRESSO_DIPOLES
236 dipoles.on_node_grid_change();
238 rebuild_cell_structure();
242#ifdef ESPRESSO_ELECTROSTATICS
243 coulomb.on_periodicity_change();
246#ifdef ESPRESSO_DIPOLES
247 dipoles.on_periodicity_change();
250#ifdef ESPRESSO_STOKESIAN_DYNAMICS
252 if (box_geo->periodic(0u) or box_geo->periodic(1u) or box_geo->periodic(2u))
254 <<
"(False, False, False)\n";
257 on_verlet_skin_change();
262 lb.on_cell_structure_change();
263 ek.on_cell_structure_change();
264#ifdef ESPRESSO_ELECTROSTATICS
265 coulomb.on_cell_structure_change();
267#ifdef ESPRESSO_DIPOLES
268 dipoles.on_cell_structure_change();
275 rebuild_cell_structure();
276#ifdef ESPRESSO_ELECTROSTATICS
277 coulomb.on_coulomb_change();
279#ifdef ESPRESSO_DIPOLES
280 dipoles.on_dipoles_change();
282 on_short_range_ia_change();
286 lb.on_temperature_change();
287 ek.on_temperature_change();
291 lb.on_timestep_change();
292 ek.on_timestep_change();
293 on_thermostat_param_change();
297 rebuild_cell_structure();
298 propagation->recalc_forces =
true;
302 nonbonded_ias->recalc_maximal_cutoffs();
303 rebuild_cell_structure();
304 on_thermostat_param_change();
305 propagation->recalc_forces =
true;
309#ifdef ESPRESSO_ELECTROSTATICS
310 coulomb.on_coulomb_change();
312 on_short_range_ia_change();
316#ifdef ESPRESSO_DIPOLES
317 dipoles.on_dipoles_change();
319 on_short_range_ia_change();
325 propagation->recalc_forces =
true;
329 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
330 propagation->recalc_forces =
true;
339#ifdef ESPRESSO_ELECTROSTATICS
340 coulomb.on_particle_change();
342#ifdef ESPRESSO_DIPOLES
343 dipoles.on_particle_change();
345 propagation->recalc_forces =
true;
349#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
350 cell_structure->clear_local_properties();
355#ifdef ESPRESSO_ELECTROSTATICS
356 coulomb.on_particle_change();
361#ifdef ESPRESSO_VIRTUAL_SITES
362#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
365#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
368 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
371#ifdef ESPRESSO_ELECTROSTATICS
372 if (has_icc_enabled()) {
373#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
376 update_icc_particles();
383 immersed_boundaries->init_volume_conservation(*cell_structure);
389 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
390 update_dependent_particles();
392#ifdef ESPRESSO_ELECTROSTATICS
393 coulomb.on_observable_calc();
396#ifdef ESPRESSO_DIPOLES
397 dipoles.on_observable_calc();
401#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
406#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
408#ifdef ESPRESSO_COLLISION_DETECTION
409 auto const collision_detection_cutoff = collision_detection->cutoff();
415 cell_structure->get_verlet_skin(),
416 get_interaction_range(),
419 collision_detection_cutoff};
422 get_interaction_range(), propagation->integ_switch);
436 max_cut = std::max(max_cut, get_min_global_cut());
437 max_cut = std::max(max_cut, coulomb.cutoff());
438 max_cut = std::max(max_cut, dipoles.cutoff());
442 max_cut = std::max(max_cut, bonded_ias->maximal_cutoff());
444 max_cut = std::max(max_cut, nonbonded_ias->maximal_cutoff());
446#ifdef ESPRESSO_COLLISION_DETECTION
447 max_cut = std::max(max_cut, collision_detection->cutoff());
454#ifdef ESPRESSO_ELECTROSTATICS
455 coulomb.sanity_checks();
457#ifdef ESPRESSO_DIPOLES
458 dipoles.sanity_checks();
460 }
catch (std::runtime_error
const &err) {
468 auto const max_cut = maximal_cutoff();
469 auto const verlet_skin = cell_structure->get_verlet_skin();
475 box_geo->set_length(box_l);
481 integrator_sanity_checks();
482 long_range_interactions_sanity_checks();
489 npt_ensemble_init(propagation->recalc_forces);
495 thermostat->recalc_prefactors(time_step);
496 reinit_thermo =
false;
497 propagation->recalc_forces =
true;
501#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
502 cell_structure->clear_local_properties();
505#ifdef ESPRESSO_ADDITIONAL_CHECKS
509#ifdef ESPRESSO_ELECTROSTATICS
511 auto const &actor = coulomb.impl->solver;
517#ifdef ESPRESSO_DIPOLES
519 auto const &actor = dipoles.impl->solver;
527 on_observable_calc();
539 if (lb.is_solver_set())
550#ifdef ESPRESSO_COLLISION_DETECTION
551 if (not collision_detection->is_off()) {
568 if (has_npt_enabled()) {
569 return &npt_inst_pressure->p_vir;
575#ifdef ESPRESSO_COLLISION_DETECTION
577 return not collision_detection->is_off();
CellStructureType
Cell structure topology.
@ NSQUARE
Atom decomposition (N-square).
@ HYBRID
Hybrid decomposition.
@ REGULAR
Regular decomposition.
@ INTEG_METHOD_NPT_ISO_AND
@ INTEG_METHOD_NPT_ISO_MTK
Vector implementation and trait types for boost qvm interoperability.
Data structures for bonded interactions.
Hybrid decomposition cell system.
static LocalBox make_regular_decomposition(Utils::Vector3d const &box_l, Utils::Vector3i const &node_index, Utils::Vector3i const &node_grid)
void on_periodicity_change()
double get_interaction_range() const
Get the interaction range.
double maximal_cutoff() const
Calculate the maximal cutoff of all interactions.
void on_constraint_change()
Called every time a constraint is changed.
void on_cell_structure_change()
unsigned get_global_ghost_flags() const
Returns the ghost flags required for running pair kernels for the global state, e....
void on_boxl_change(bool skip_method_adaption=false)
Called when the box length has changed.
void set_box_l(Utils::Vector3d const &box_l)
Change the box dimensions.
void on_temperature_change()
void on_thermostat_param_change()
void on_lees_edwards_change()
void on_integration_start()
void set_force_cap(double value)
Set force_cap.
void on_non_bonded_ia_change()
void on_verlet_skin_change()
void update_dependent_particles()
Update particles with properties depending on other particles, namely virtual sites and ICC charges.
void on_lb_boundary_conditions_change()
Called when the LB boundary conditions change (geometry, slip velocity, or both).
void veto_boxl_change(bool skip_particle_checks=false) const
void set_time_step(double value)
Set time_step.
void on_particle_change()
Called every time a particle property changes.
bool long_range_interactions_sanity_checks() const
Check electrostatic and magnetostatic methods are properly initialized.
void on_node_grid_change()
void on_particle_charge_change()
Called every time a particle charge changes.
void on_particle_local_change()
Called every time a particle local property changes.
void on_observable_calc()
called before calculating observables, i.e.
void on_timestep_change()
void check_kT(double value) const
Veto temperature change.
static std::shared_ptr< System > create()
Utils::Vector3d * get_npt_virial() const
void set_min_global_cut(double value)
Set min_global_cut.
bool has_npt_enabled() const
void set_cell_structure_topology(CellStructureType topology)
Change cell structure topology.
void on_short_range_ia_change()
void rebuild_cell_structure()
Rebuild cell lists.
bool has_collision_detection_enabled() const
Returns true if the particles are to be considered for short range interactions.
void vs_com_update_particles(CellStructure &cell_structure, BoxGeometry const &box_geo)
std::shared_ptr< KokkosHandle > kokkos_handle
Communicator communicator
boost::mpi::communicator comm_cart
The communicator.
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
ICC is a method that allows to take into account the influence of arbitrarily shaped dielectric inter...
@ DATA_PART_MOMENTUM
Particle::m.
@ DATA_PART_PROPERTIES
Particle::p.
@ DATA_PART_BONDS
Particle::bonds.
@ DATA_PART_POSITION
Particle::r.
static std::shared_ptr< System > instance
void set_system(std::shared_ptr< System > new_instance)
bool all_compare(boost::mpi::communicator const &comm, T const &value)
Compare values on all nodes.
Exports for the NpT code.
void invalidate_fetch_cache()
Invalidate the fetch cache for get_particle_data.
void clear_particle_node()
Invalidate particle_node.
Particles creation and deletion.
void vs_relative_update_particles(CellStructure &cell_structure, BoxGeometry const &box_geo)
ESPRESSO_ATTR_ALWAYS_INLINE void update_cabana_state(CellStructure &cell_structure, auto const &verlet_criterion, double const pair_cutoff, auto const integ_switch)
Utils::Vector3i calc_node_index() const
Calculate the node index in the Cartesian topology.
Utils::Vector3i node_grid
Regular decomposition cell system.
Routines to thermalize the center of mass and distance of a particle pair.