ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
VerletCriterion.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <config/config.hpp>
25
26#include "Particle.hpp"
28#include "system/System.hpp"
29
30#include <utils/index.hpp>
31#include <utils/math/sqr.hpp>
32
34 GetNonbondedCutoff(System::System const &system) : m_system{system} {}
35 auto operator()(int type_i, int type_j) const {
36 return m_system.nonbonded_ias->get_ia_param(type_i, type_j).max_cut;
37 }
38
39private:
40 System::System const &m_system;
41};
42
43/** Returns true if the particles are to be considered for short range
44 * interactions.
45 */
46template <typename CutoffGetter = GetNonbondedCutoff> class VerletCriterion {
47 const double m_skin;
48 const double m_eff_max_cut2;
49 const double m_eff_coulomb_cut2 = 0.;
50 const double m_eff_dipolar_cut2 = 0.;
51 const double m_collision_cut2 = 0.;
52 double eff_cutoff_sqr(double x) const {
53 if (x == inactive_cutoff)
54 return inactive_cutoff;
55 return Utils::sqr(x + m_skin);
56 }
57 CutoffGetter get_nonbonded_cutoff;
58
59public:
60 VerletCriterion(System::System const &system, double skin, double max_cut,
61 double coulomb_cut = 0., double dipolar_cut = 0.,
62 double collision_detection_cutoff = 0.)
63 : m_skin(skin), m_eff_max_cut2(eff_cutoff_sqr(max_cut)),
64 m_eff_coulomb_cut2(eff_cutoff_sqr(coulomb_cut)),
65 m_eff_dipolar_cut2(eff_cutoff_sqr(dipolar_cut)),
66 m_collision_cut2(eff_cutoff_sqr(collision_detection_cutoff)),
67 get_nonbonded_cutoff(system) {}
68
69 bool operator()(const Particle &p1, const Particle &p2, double dist2) const {
70 if (dist2 > m_eff_max_cut2)
71 return false;
72
73#ifdef ESPRESSO_ELECTROSTATICS
74 // Within real space cutoff of electrostatics and both are charged
75 if (dist2 <= m_eff_coulomb_cut2 and p1.q() != 0. and p2.q() != 0.)
76 return true;
77#endif
78
79#ifdef ESPRESSO_DIPOLES
80 // Within dipolar cutoff and both carry magnetic moments
81 if (dist2 <= m_eff_dipolar_cut2 and p1.dipm() != 0. and p2.dipm() != 0.)
82 return true;
83#endif
84
85#ifdef ESPRESSO_COLLISION_DETECTION
86 // Collision detection
87 if (dist2 <= m_collision_cut2)
88 return true;
89#endif
90
91 // Within short-range distance (including dpd and the like)
92 auto const ia_cut = get_nonbonded_cutoff(p1.type(), p2.type());
93 return (ia_cut != inactive_cutoff) &&
94 (dist2 <= Utils::sqr(ia_cut + m_skin));
95 }
96};
Main system class.
std::shared_ptr< InteractionsNonBonded > nonbonded_ias
Returns true if the particles are to be considered for short range interactions.
bool operator()(const Particle &p1, const Particle &p2, double dist2) const
VerletCriterion(System::System const &system, double skin, double max_cut, double coulomb_cut=0., double dipolar_cut=0., double collision_detection_cutoff=0.)
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
Definition config.hpp:53
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:28
Various procedures concerning interactions between particles.
auto operator()(int type_i, int type_j) const
GetNonbondedCutoff(System::System const &system)
Struct holding all information for one particle.
Definition Particle.hpp:435
auto const & q() const
Definition Particle.hpp:578
auto const & type() const
Definition Particle.hpp:458
auto const & dipm() const
Definition Particle.hpp:533