ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
bonded_interaction_data.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include "BoxGeometry.hpp"
25#include "rigid_bond.hpp"
26#include "system/System.hpp"
27#include "thermalized_bond.hpp"
28#include "thermostat.hpp"
29
30#include <boost/variant.hpp>
31
32#include <algorithm>
33#include <numeric>
34
35/** Visitor to get the bond cutoff from the bond parameter variant */
36class BondCutoff : public boost::static_visitor<double> {
37public:
38 template <typename T> double operator()(T const &bond) const {
39 return bond.cutoff();
40 }
41};
42
44 auto const max_cut_bonded = std::accumulate(
45 begin(), end(), BONDED_INACTIVE_CUTOFF, [](auto max_cut, auto const &kv) {
46 return std::max(max_cut,
47 boost::apply_visitor(BondCutoff(), *kv.second));
48 });
49
50 /* Check if there are dihedrals */
51 auto const any_dihedrals = std::any_of(begin(), end(), [](auto const &kv) {
52 return (boost::get<DihedralBond>(&(*kv.second)) ||
53 boost::get<TabulatedDihedralBond>(&(*kv.second)));
54 });
55
56 /* dihedrals: the central particle is indirectly connected to the fourth
57 * particle via the third particle, so we have to double the cutoff */
58 return (any_dihedrals) ? 2 * max_cut_bonded : max_cut_bonded;
59}
60
62 n_thermalized_bonds = 0;
63#ifdef BOND_CONSTRAINT
64 n_rigid_bonds = 0;
65#endif
66 for (auto &kv : *this) {
67 if (boost::get<ThermalizedBond>(&(*kv.second)) != nullptr) {
68 ++n_thermalized_bonds;
69 }
70#ifdef BOND_CONSTRAINT
71 if (boost::get<RigidBond>(&(*kv.second)) != nullptr) {
72 ++n_rigid_bonds;
73 }
74#endif
75 }
76 if (auto system = m_system.lock()) {
77 system->on_short_range_ia_change();
78 system->on_thermostat_param_change(); // thermalized bonds
79 }
80}
81
83 auto &system = get_system();
84 if (auto bond = boost::get<ThermalizedBond>(ptr.get())) {
85 bond->set_thermostat_view(system.thermostat);
86 }
87 if (auto bond = boost::get<IBMVolCons>(ptr.get())) {
88 system.immersed_boundaries->register_softID(*bond);
89 }
90 if (auto bond = boost::get<IBMTriel>(ptr.get())) {
91 bond->initialize(*system.box_geo, *system.cell_structure);
92 }
93 if (auto bond = boost::get<IBMTribend>(ptr.get())) {
94 bond->initialize(*system.box_geo, *system.cell_structure);
95 }
96}
97
99 if (auto bond = boost::get<ThermalizedBond>(ptr.get())) {
100 bond->unset_thermostat_view();
101 }
102 if (auto bond = boost::get<IBMVolCons>(ptr.get())) {
103 bond->unset_volumes_view();
104 }
105}
Data structures for bonded interactions.
static constexpr double BONDED_INACTIVE_CUTOFF
Visitor to get the bond cutoff from the bond parameter variant.
double operator()(T const &bond) const
virtual void activate_bond(mapped_type const &ptr)
virtual void deactivate_bond(mapped_type const &ptr)
double maximal_cutoff() const
Calculate the maximal cutoff of bonded interactions, required to determine the cell size for communic...
typename container_type::mapped_type mapped_type
Definition of the rigid bond data type for the Rattle algorithm.
Routines to thermalize the center of mass and distance of a particle pair.