30#include "accumulators/AutoUpdateAccumulators.hpp"
36#include "collision_detection/CollisionDetection.hpp"
37#include "communication.hpp"
47#include "thermostat.hpp"
54#include <boost/mpi/collectives/all_reduce.hpp>
69 auto handle = std::make_shared<System>(Private());
75 box_geo = std::make_shared<BoxGeometry>();
76 local_geo = std::make_shared<LocalBox>();
77 cell_structure = std::make_shared<CellStructure>(*box_geo);
80 gpu = std::make_shared<GpuParticleData>();
82 propagation = std::make_shared<Propagation>();
83 bonded_ias = std::make_shared<BondedInteractionsMap>();
84 thermostat = std::make_shared<Thermostat::Thermostat>();
85 nonbonded_ias = std::make_shared<InteractionsNonBonded>();
86 comfixed = std::make_shared<ComFixed>();
87 galilei = std::make_shared<Galilei>();
88 oif_global = std::make_shared<OifGlobal>();
89 immersed_boundaries = std::make_shared<ImmersedBoundaries>();
90#ifdef ESPRESSO_COLLISION_DETECTION
92 std::make_shared<CollisionDetection::CollisionDetection>();
94 bond_breakage = std::make_shared<BondBreakage::BondBreakage>();
95 lees_edwards = std::make_shared<LeesEdwards::LeesEdwards>();
96 auto_update_accumulators =
97 std::make_shared<Accumulators::AutoUpdateAccumulators>();
98 constraints = std::make_shared<Constraints::Constraints>();
99 steepest_descent = std::make_shared<SteepestDescent>();
100#ifdef ESPRESSO_STOKESIAN_DYNAMICS
101 stokesian_dynamics = std::make_shared<StokesianDynamics>();
104 nptiso = std::make_shared<NptIsoParameters>();
105 npt_inst_pressure = std::make_shared<InstantaneousPressure>();
107 reinit_thermo =
true;
114void System::initialize() {
116 cell_structure->bind_system(
handle);
117 lees_edwards->bind_system(
handle);
118 bonded_ias->bind_system(
handle);
119 thermostat->bind_system(
handle);
120 nonbonded_ias->bind_system(
handle);
121 oif_global->bind_system(
handle);
122 immersed_boundaries->bind_system(
handle);
123#ifdef ESPRESSO_COLLISION_DETECTION
124 collision_detection->bind_system(
handle);
126 auto_update_accumulators->bind_system(
handle);
127 constraints->bind_system(
handle);
151 throw std::domain_error(
"time_step must be > 0.");
152 if (lb.is_solver_set()) {
153 lb.veto_time_step(value);
155 if (ek.is_solver_set()) {
156 ek.veto_time_step(value);
159 on_timestep_change();
163 if (lb.is_solver_set()) {
166 if (ek.is_solver_set()) {
173 propagation->recalc_forces =
true;
177 min_global_cut = value;
178 on_verlet_skin_change();
187 std::as_const(*cell_structure).decomposition());
188 cell_structure->set_regular_decomposition(
189 get_interaction_range(),
192 cell_structure->set_regular_decomposition(get_interaction_range(), {});
195 cell_structure->set_atom_decomposition();
200 std::as_const(*cell_structure).decomposition());
201 cell_structure->set_hybrid_decomposition(
208 set_cell_structure_topology(cell_structure->decomposition_type());
213 rebuild_cell_structure();
219#ifdef ESPRESSO_ELECTROSTATICS
220 coulomb.on_boxl_change();
222#ifdef ESPRESSO_DIPOLES
223 dipoles.on_boxl_change();
226 constraints->on_boxl_change();
231 auto const n_part = boost::mpi::all_reduce(
232 ::comm_cart, cell_structure->local_particles().size(), std::plus<>());
234 throw std::runtime_error(
235 "Cannot reset the box length when particles are present");
238 constraints->veto_boxl_change();
239 lb.veto_boxl_change();
240 ek.veto_boxl_change();
245 lb.on_node_grid_change();
246 ek.on_node_grid_change();
247#ifdef ESPRESSO_ELECTROSTATICS
248 coulomb.on_node_grid_change();
250#ifdef ESPRESSO_DIPOLES
251 dipoles.on_node_grid_change();
253 rebuild_cell_structure();
257#ifdef ESPRESSO_ELECTROSTATICS
258 coulomb.on_periodicity_change();
261#ifdef ESPRESSO_DIPOLES
262 dipoles.on_periodicity_change();
265#ifdef ESPRESSO_STOKESIAN_DYNAMICS
267 if (box_geo->periodic(0
u)
or box_geo->periodic(1u)
or box_geo->periodic(2u))
269 <<
"(False, False, False)\n";
272 on_verlet_skin_change();
277 lb.on_cell_structure_change();
278 ek.on_cell_structure_change();
279#ifdef ESPRESSO_ELECTROSTATICS
280 coulomb.on_cell_structure_change();
282#ifdef ESPRESSO_DIPOLES
283 dipoles.on_cell_structure_change();
290 rebuild_cell_structure();
291#ifdef ESPRESSO_ELECTROSTATICS
292 coulomb.on_coulomb_change();
294#ifdef ESPRESSO_DIPOLES
295 dipoles.on_dipoles_change();
297 on_short_range_ia_change();
301 lb.on_temperature_change();
302 ek.on_temperature_change();
306 lb.on_timestep_change();
307 ek.on_timestep_change();
308 on_thermostat_param_change();
312 rebuild_cell_structure();
313 propagation->recalc_forces =
true;
317 nonbonded_ias->recalc_maximal_cutoffs();
318 rebuild_cell_structure();
319 on_thermostat_param_change();
320 propagation->recalc_forces =
true;
324#ifdef ESPRESSO_ELECTROSTATICS
325 coulomb.on_coulomb_change();
327 on_short_range_ia_change();
331#ifdef ESPRESSO_DIPOLES
332 dipoles.on_dipoles_change();
334 on_short_range_ia_change();
340 propagation->recalc_forces =
true;
344 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
345 propagation->recalc_forces =
true;
346 propagation->recalc_used_propagations =
true;
355#ifdef ESPRESSO_ELECTROSTATICS
356 coulomb.on_particle_change();
358#ifdef ESPRESSO_DIPOLES
359 dipoles.on_particle_change();
361 propagation->recalc_forces =
true;
362 propagation->recalc_used_propagations =
true;
366 cell_structure->clear_local_properties();
370#ifdef ESPRESSO_ELECTROSTATICS
371 coulomb.on_particle_change();
376#ifdef ESPRESSO_VIRTUAL_SITES
377 if (propagation->recalc_used_propagations) {
378 update_used_propagations();
380#ifdef ESPRESSO_VIRTUAL_SITES_RELATIVE
381 if (propagation->used_propagations &
387#ifdef ESPRESSO_VIRTUAL_SITES_CENTER_OF_MASS
388 if (propagation->used_propagations &
393 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
396#ifdef ESPRESSO_ELECTROSTATICS
397 if (has_icc_enabled()) {
399 update_icc_particles();
406 immersed_boundaries->init_volume_conservation(*cell_structure);
412 cell_structure->update_ghosts_and_resort_particle(get_global_ghost_flags());
413 update_dependent_particles();
415#ifdef ESPRESSO_ELECTROSTATICS
416 coulomb.on_observable_calc();
419#ifdef ESPRESSO_DIPOLES
420 dipoles.on_observable_calc();
428#ifdef ESPRESSO_COLLISION_DETECTION
447 max_cut = std::max(max_cut, get_min_global_cut());
448 max_cut = std::max(max_cut, coulomb.cutoff());
449 max_cut = std::max(max_cut, dipoles.cutoff());
453 max_cut = std::max(max_cut, bonded_ias->maximal_cutoff());
455 max_cut = std::max(max_cut, nonbonded_ias->maximal_cutoff());
457#ifdef ESPRESSO_COLLISION_DETECTION
458 max_cut = std::max(max_cut, collision_detection->cutoff());
465#ifdef ESPRESSO_ELECTROSTATICS
466 coulomb.sanity_checks();
468#ifdef ESPRESSO_DIPOLES
469 dipoles.sanity_checks();
471 }
catch (std::runtime_error
const &
err) {
479 auto const max_cut = maximal_cutoff();
480 auto const verlet_skin = cell_structure->get_verlet_skin();
486 box_geo->set_length(
box_l);
492 integrator_sanity_checks();
493 long_range_interactions_sanity_checks();
500 npt_ensemble_init(propagation->recalc_forces);
506 thermostat->recalc_prefactors(time_step);
507 reinit_thermo =
false;
508 propagation->recalc_forces =
true;
512 cell_structure->clear_local_properties();
514#ifdef ESPRESSO_ADDITIONAL_CHECKS
518#ifdef ESPRESSO_ELECTROSTATICS
520 auto const &actor = coulomb.impl->solver;
526#ifdef ESPRESSO_DIPOLES
528 auto const &actor = dipoles.impl->solver;
536 on_observable_calc();
548 if (lb.is_solver_set())
559#ifdef ESPRESSO_COLLISION_DETECTION
560 if (
not collision_detection->is_off()) {
577 if (has_npt_enabled()) {
578 return &npt_inst_pressure->p_vir;
584#ifdef ESPRESSO_COLLISION_DETECTION
586 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
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.
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.
@ TRANS_VS_CENTER_OF_MASS
static std::shared_ptr< System > instance
bool is_same_system(System const *const system)
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.
void update_verlet_state(System::System const &system, double const collision_cut)
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.