ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ParticleTraits.hpp
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#ifndef OBSERVABLES_PARTICLE_TRAITS
20#define OBSERVABLES_PARTICLE_TRAITS
21
22#include "BoxGeometry.hpp"
23#include "Particle.hpp"
24#include "config/config.hpp"
25#include "rotation.hpp"
26#include "system/System.hpp"
27
29/**
30 * Template specialization for `Particle`. The traits mechanism is used to get
31 * indirect access to particle properties. This helps making the implementation
32 * of observables independent of the particle type.
33 */
34template <> struct traits<Particle> {
35 auto id(Particle const &p) const { return p.id(); }
36 auto position(Particle const &p) const {
37 auto const &box_geo = *System::get_system().box_geo;
38 return box_geo.unfolded_position(p.pos(), p.image_box());
39 }
40 auto position_folded(Particle const &p) const { return p.pos(); }
41 auto velocity(Particle const &p) const { return p.v(); }
42 auto force(Particle const &p) const { return p.force(); }
43 auto mass(Particle const &p) const {
44#ifdef VIRTUAL_SITES
45 // we exclude virtual particles since their mass does not have a meaning
46 if (p.is_virtual())
47 return decltype(p.mass()){};
48#endif
49 return p.mass();
50 }
51 auto charge(Particle const &p) const { return p.q(); }
52 auto dipole_moment(Particle const &p) const {
53#ifdef DIPOLES
54 return p.calc_dip();
55#else
56 return Utils::Vector3d{};
57#endif
58 }
59 auto dipole_field(Particle const &p) const {
60#ifdef DIPOLE_FIELD_TRACKING
61 return p.dip_fld();
62#else
63 return Utils::Vector3d{};
64#endif
65 }
66 auto velocity_body(Particle const &p) const {
67#ifdef ROTATION
68 return convert_vector_space_to_body(p, p.v());
69#else
70 return Utils::Vector3d{};
71#endif
72 }
73 auto angular_velocity(Particle const &p) const {
74#ifdef ROTATION
76#else
77 return Utils::Vector3d{};
78#endif
79 }
80 auto angular_velocity_body(Particle const &p) const {
81#ifdef ROTATION
82 return p.omega();
83#else
84 return Utils::Vector3d{};
85#endif
86 }
87 auto director(Particle const &p) const {
88#ifdef ROTATION
89 return p.calc_director();
90#else
91 return Utils::Vector3d{{0., 0., 1.}};
92#endif
93 }
94};
95
96} // namespace ParticleObservables
97
98#endif
std::shared_ptr< BoxGeometry > box_geo
This file contains the defaults for ESPResSo.
System & get_system()
This file contains all subroutines required to process rotational motion.
Utils::Vector3d convert_vector_body_to_space(const Particle &p, const Utils::Vector3d &vec)
Definition rotation.hpp:57
Utils::Vector3d convert_vector_space_to_body(const Particle &p, const Utils::Vector3d &v)
Definition rotation.hpp:61
auto velocity_body(Particle const &p) const
auto position(Particle const &p) const
auto dipole_field(Particle const &p) const
auto director(Particle const &p) const
auto mass(Particle const &p) const
auto angular_velocity_body(Particle const &p) const
auto position_folded(Particle const &p) const
auto id(Particle const &p) const
auto charge(Particle const &p) const
auto force(Particle const &p) const
auto angular_velocity(Particle const &p) const
auto velocity(Particle const &p) const
auto dipole_moment(Particle const &p) const
Struct holding all information for one particle.
Definition Particle.hpp:395
auto const & dip_fld() const
Definition Particle.hpp:498
auto is_virtual() const
Definition Particle.hpp:518
auto const & mass() const
Definition Particle.hpp:452
auto const & q() const
Definition Particle.hpp:508
auto calc_dip() const
Definition Particle.hpp:495
auto const & v() const
Definition Particle.hpp:433
auto const & omega() const
Definition Particle.hpp:481
auto const & image_box() const
Definition Particle.hpp:444
auto const & pos() const
Definition Particle.hpp:431
auto const & force() const
Definition Particle.hpp:435
auto const & id() const
Definition Particle.hpp:414
auto calc_director() const
Definition Particle.hpp:487