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-2022 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 template <typename Distance>
70 bool operator()(const Particle &p1, const Particle &p2,
71 Distance const &dist) const {
72 auto const &dist2 = dist.dist2;
73 if (dist2 > m_eff_max_cut2)
74 return false;
75
76#ifdef ESPRESSO_ELECTROSTATICS
77 // Within real space cutoff of electrostatics and both are charged
78 if (dist2 <= m_eff_coulomb_cut2 and p1.q() != 0. and p2.q() != 0.)
79 return true;
80#endif
81
82#ifdef ESPRESSO_DIPOLES
83 // Within dipolar cutoff and both carry magnetic moments
84 if (dist2 <= m_eff_dipolar_cut2 and p1.dipm() != 0. and p2.dipm() != 0.)
85 return true;
86#endif
87
88#ifdef ESPRESSO_COLLISION_DETECTION
89 // Collision detection
90 if (dist2 <= m_collision_cut2)
91 return true;
92#endif
93
94 // Within short-range distance (including dpd and the like)
95 auto const ia_cut = get_nonbonded_cutoff(p1.type(), p2.type());
96 return (ia_cut != inactive_cutoff) &&
97 (dist2 <= Utils::sqr(ia_cut + m_skin));
98 }
99};
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, Distance const &dist) 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:44
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:28
Various procedures concerning interactions between particles.
Distance vector and length handed to pair kernels.
auto operator()(int type_i, int type_j) const
GetNonbondedCutoff(System::System const &system)
Struct holding all information for one particle.
Definition Particle.hpp:450
auto const & q() const
Definition Particle.hpp:593
auto const & type() const
Definition Particle.hpp:473
auto const & dipm() const
Definition Particle.hpp:548