28#include "accumulators/AutoUpdateAccumulators.hpp"
34#include "collision_detection/CollisionDetection.hpp"
35#include "communication.hpp"
44#include "thermostat.hpp"
51#include <boost/mpi/collectives/all_reduce.hpp>
65 auto handle = std::make_shared<System>(Private());
71 box_geo = std::make_shared<BoxGeometry>();
72 local_geo = std::make_shared<LocalBox>();
73 cell_structure = std::make_shared<CellStructure>(*box_geo);
74#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
77 propagation = std::make_shared<Propagation>();
78 bonded_ias = std::make_shared<BondedInteractionsMap>();
79 thermostat = std::make_shared<Thermostat::Thermostat>();
80 nonbonded_ias = std::make_shared<InteractionsNonBonded>();
81 comfixed = std::make_shared<ComFixed>();
82 galilei = std::make_shared<Galilei>();
83 oif_global = std::make_shared<OifGlobal>();
84 immersed_boundaries = std::make_shared<ImmersedBoundaries>();
85#ifdef ESPRESSO_COLLISION_DETECTION
87 std::make_shared<CollisionDetection::CollisionDetection>();
89 bond_breakage = std::make_shared<BondBreakage::BondBreakage>();
90 lees_edwards = std::make_shared<LeesEdwards::LeesEdwards>();
91 auto_update_accumulators =
92 std::make_shared<Accumulators::AutoUpdateAccumulators>();
93 constraints = std::make_shared<Constraints::Constraints>();
94 steepest_descent = std::make_shared<SteepestDescent>();
95#ifdef ESPRESSO_STOKESIAN_DYNAMICS
96 stokesian_dynamics = std::make_shared<StokesianDynamics>();
99 nptiso = std::make_shared<NptIsoParameters>();
100 npt_inst_pressure = std::make_shared<InstantaneousPressure>();
102 reinit_thermo =
true;
109void System::initialize() {
110 auto handle = shared_from_this();
111 cell_structure->bind_system(handle);
112 lees_edwards->bind_system(handle);
113 bonded_ias->bind_system(handle);
114 thermostat->bind_system(handle);
115 nonbonded_ias->bind_system(handle);
116 oif_global->bind_system(handle);
117 immersed_boundaries->bind_system(handle);
118#ifdef ESPRESSO_COLLISION_DETECTION
119 collision_detection->bind_system(handle);
121 auto_update_accumulators->bind_system(handle);
122 constraints->bind_system(handle);
124 gpu.bind_system(handle);
127 lb.bind_system(handle);
128 ek.bind_system(handle);
141 throw std::domain_error(
"time_step must be > 0.");
142 if (lb.is_solver_set()) {
143 lb.veto_time_step(value);
145 if (ek.is_solver_set()) {
146 ek.veto_time_step(value);
149 on_timestep_change();
153 if (lb.is_solver_set()) {
156 if (ek.is_solver_set()) {
163 propagation->recalc_forces =
true;
167 min_global_cut = value;
168 on_verlet_skin_change();
175 auto &old_regular_decomposition =
177 std::as_const(*cell_structure).decomposition());
178 cell_structure->set_regular_decomposition(
179 get_interaction_range(),
180 old_regular_decomposition.fully_connected_boundary());
182 cell_structure->set_regular_decomposition(get_interaction_range(), {});
185 cell_structure->set_atom_decomposition();
190 std::as_const(*cell_structure).decomposition());
191 cell_structure->set_hybrid_decomposition(
192 old_hybrid_decomposition.get_cutoff_regular(),
193 old_hybrid_decomposition.get_n_square_types());
198 set_cell_structure_topology(cell_structure->decomposition_type());
203 rebuild_cell_structure();
206 if (not skip_method_adaption) {
209#ifdef ESPRESSO_ELECTROSTATICS
210 coulomb.on_boxl_change();
212#ifdef ESPRESSO_DIPOLES
213 dipoles.on_boxl_change();
216 constraints->on_boxl_change();
220 if (not skip_particle_checks) {
221 auto const n_part = boost::mpi::all_reduce(
222 ::comm_cart, cell_structure->local_particles().size(), std::plus<>());
224 throw std::runtime_error(
225 "Cannot reset the box length when particles are present");
228 constraints->veto_boxl_change();
229 lb.veto_boxl_change();
230 ek.veto_boxl_change();
235 lb.on_node_grid_change();
236 ek.on_node_grid_change();
237#ifdef ESPRESSO_ELECTROSTATICS
238 coulomb.on_node_grid_change();
240#ifdef ESPRESSO_DIPOLES
241 dipoles.on_node_grid_change();
243 rebuild_cell_structure();
247#ifdef ESPRESSO_ELECTROSTATICS
248 coulomb.on_periodicity_change();
251#ifdef ESPRESSO_DIPOLES
252 dipoles.on_periodicity_change();
255#ifdef ESPRESSO_STOKESIAN_DYNAMICS
257 if (box_geo->periodic(0u) or box_geo->periodic(1u) or box_geo->periodic(2u))
259 <<
"(False, False, False)\n";
262 on_verlet_skin_change();
267 lb.on_cell_structure_change();
268 ek.on_cell_structure_change();
269#ifdef ESPRESSO_ELECTROSTATICS
270 coulomb.on_cell_structure_change();
272#ifdef ESPRESSO_DIPOLES
273 dipoles.on_cell_structure_change();
280 rebuild_cell_structure();
281#ifdef ESPRESSO_ELECTROSTATICS
282 coulomb.on_coulomb_change();
284#ifdef ESPRESSO_DIPOLES
285 dipoles.on_dipoles_change();
287 on_short_range_ia_change();
291 lb.on_temperature_change();
292 ek.on_temperature_change();
296 lb.on_timestep_change();
297 ek.on_timestep_change();
298 on_thermostat_param_change();
302 rebuild_cell_structure();
303 propagation->recalc_forces =
true;
307 nonbonded_ias->recalc_maximal_cutoffs();
308 rebuild_cell_structure();
309 on_thermostat_param_change();
310 propagation->recalc_forces =
true;
314#ifdef ESPRESSO_ELECTROSTATICS
315 coulomb.on_coulomb_change();
317 on_short_range_ia_change();
321#ifdef ESPRESSO_DIPOLES
322 dipoles.on_dipoles_change();
324 on_short_range_ia_change();
330 propagation->recalc_forces =
true;
334 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
335 propagation->recalc_forces =
true;
344#ifdef ESPRESSO_ELECTROSTATICS
345 coulomb.on_particle_change();
347#ifdef ESPRESSO_DIPOLES
348 dipoles.on_particle_change();
350 propagation->recalc_forces =
true;
354#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
355 cell_structure->clear_local_properties();
360#ifdef ESPRESSO_ELECTROSTATICS
361 coulomb.on_particle_change();
366#ifdef ESPRESSO_VIRTUAL_SITES
367#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
370#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
373 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
376#ifdef ESPRESSO_ELECTROSTATICS
377 if (has_icc_enabled()) {
378#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
381 update_icc_particles();
388 immersed_boundaries->init_volume_conservation(*cell_structure);
394 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
395 update_dependent_particles();
397#ifdef ESPRESSO_ELECTROSTATICS
398 coulomb.on_observable_calc();
401#ifdef ESPRESSO_DIPOLES
402 dipoles.on_observable_calc();
406#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
411#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
413#ifdef ESPRESSO_COLLISION_DETECTION
414 auto const collision_detection_cutoff = collision_detection->cutoff();
420 cell_structure->get_verlet_skin(),
421 get_interaction_range(),
424 collision_detection_cutoff};
427 get_interaction_range(), propagation->integ_switch);
441 max_cut = std::max(max_cut, get_min_global_cut());
442 max_cut = std::max(max_cut, coulomb.cutoff());
443 max_cut = std::max(max_cut, dipoles.cutoff());
447 max_cut = std::max(max_cut, bonded_ias->maximal_cutoff());
449 max_cut = std::max(max_cut, nonbonded_ias->maximal_cutoff());
451#ifdef ESPRESSO_COLLISION_DETECTION
452 max_cut = std::max(max_cut, collision_detection->cutoff());
459#ifdef ESPRESSO_ELECTROSTATICS
460 coulomb.sanity_checks();
462#ifdef ESPRESSO_DIPOLES
463 dipoles.sanity_checks();
465 }
catch (std::runtime_error
const &err) {
473 auto const max_cut = maximal_cutoff();
474 auto const verlet_skin = cell_structure->get_verlet_skin();
480 box_geo->set_length(box_l);
486 integrator_sanity_checks();
487 long_range_interactions_sanity_checks();
494 npt_ensemble_init(propagation->recalc_forces);
500 thermostat->recalc_prefactors(time_step);
501 reinit_thermo =
false;
502 propagation->recalc_forces =
true;
506#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
507 cell_structure->clear_local_properties();
510#ifdef ESPRESSO_ADDITIONAL_CHECKS
514#ifdef ESPRESSO_ELECTROSTATICS
516 auto const &actor = coulomb.impl->solver;
522#ifdef ESPRESSO_DIPOLES
524 auto const &actor = dipoles.impl->solver;
532 on_observable_calc();
544 if (lb.is_solver_set())
555#ifdef ESPRESSO_COLLISION_DETECTION
556 if (not collision_detection->is_off()) {
573 if (has_npt_enabled()) {
574 return &npt_inst_pressure->p_vir;
580#ifdef ESPRESSO_COLLISION_DETECTION
582 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)
See for the Stokesian dynamics method used here.
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.