ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
pressure_inline.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
29
30#include "BoxGeometry.hpp"
31#include "Observable_stat.hpp"
32#include "Particle.hpp"
33#include "errorhandling.hpp"
34#include "exclusions.hpp"
35#include "forces_inline.hpp"
36
37#include <utils/Span.hpp>
38#include <utils/Vector.hpp>
40
41#include <boost/optional.hpp>
42#include <boost/variant.hpp>
43
44#include <string>
45#include <tuple>
46
47/** Calculate non-bonded energies between a pair of particles.
48 * @param p1 pointer to particle 1.
49 * @param p2 pointer to particle 2.
50 * @param d vector between p1 and p2.
51 * @param dist distance between p1 and p2.
52 * @param ia_params non-bonded interaction kernels.
53 * @param kernel_forces Coulomb force kernel.
54 * @param kernel_pressure Coulomb pressure kernel.
55 * @param[in,out] obs_pressure pressure observable.
56 */
58 Particle const &p1, Particle const &p2, Utils::Vector3d const &d,
59 double dist, IA_parameters const &ia_params,
62 Observable_stat &obs_pressure) {
63#ifdef EXCLUSIONS
64 if (do_nonbonded(p1, p2))
65#endif
66 {
67 auto const force = calc_central_radial_force(ia_params, d, dist).f +
68 calc_central_radial_charge_force(p1, p2, ia_params, d,
69 dist, kernel_forces)
70 .f +
71 calc_non_central_force(p1, p2, ia_params, d, dist).f;
72 auto const stress = Utils::tensor_product(d, force);
73 obs_pressure.add_non_bonded_contribution(p1.type(), p2.type(), p1.mol_id(),
74 p2.mol_id(), flatten(stress));
75 }
76
77#ifdef ELECTROSTATICS
78 if (!obs_pressure.coulomb.empty() and kernel_pressure != nullptr) {
79 /* real space Coulomb */
80 auto const p_coulomb = (*kernel_pressure)(p1.q() * p2.q(), d, dist);
81
82 for (int i = 0; i < 3; i++) {
83 for (int j = 0; j < 3; j++) {
84 obs_pressure.coulomb[i * 3 + j] += p_coulomb(i, j);
85 }
86 }
87 }
88#endif // ELECTROSTATICS
89
90#ifdef DIPOLES
91 /* real space magnetic dipole-dipole */
92 if (Dipoles::get_dipoles().impl->solver) {
93 fprintf(stderr, "calculating pressure for magnetostatics which doesn't "
94 "have it implemented\n");
95 }
96#endif // DIPOLES
97}
98
99inline boost::optional<Utils::Matrix<double, 3, 3>>
101 Bonded_IA_Parameters const &iaparams, Particle const &p1,
102 Particle const &p2, BoxGeometry const &box_geo,
104 auto const dx = box_geo.get_mi_vector(p1.pos(), p2.pos());
105 auto const result = calc_bond_pair_force(p1, p2, iaparams, dx, kernel);
106 if (result) {
107 auto const &force = result.get();
108
109 return Utils::tensor_product(force, dx);
110 }
111
112 return {};
113}
114
115inline boost::optional<Utils::Matrix<double, 3, 3>>
117 Particle const &p1, Particle const &p2,
118 Particle const &p3,
119 BoxGeometry const &box_geo) {
120 if ((boost::get<AngleHarmonicBond>(&iaparams) != nullptr) ||
121 (boost::get<AngleCosineBond>(&iaparams) != nullptr) ||
122#ifdef TABULATED
123 (boost::get<TabulatedAngleBond>(&iaparams) != nullptr) ||
124#endif
125 (boost::get<AngleCossquareBond>(&iaparams) != nullptr)) {
126 auto const dx21 = -box_geo.get_mi_vector(p1.pos(), p2.pos());
127 auto const dx31 = box_geo.get_mi_vector(p3.pos(), p1.pos());
128
129 auto const result =
130 calc_bonded_three_body_force(iaparams, box_geo, p1, p2, p3);
131 if (result) {
132 Utils::Vector3d force2, force3;
133 std::tie(std::ignore, force2, force3) = result.get();
134
135 return Utils::tensor_product(force2, dx21) +
136 Utils::tensor_product(force3, dx31);
137 }
138 } else {
139 runtimeWarningMsg() << "Unsupported bond type " +
140 std::to_string(iaparams.which()) +
141 " in pressure calculation.";
143 }
144
145 return {};
146}
147
148inline boost::optional<Utils::Matrix<double, 3, 3>> calc_bonded_pressure_tensor(
149 Bonded_IA_Parameters const &iaparams, Particle const &p1,
150 Utils::Span<Particle *> partners, BoxGeometry const &box_geo,
152 switch (number_of_partners(iaparams)) {
153 case 1:
154 return calc_bonded_virial_pressure_tensor(iaparams, p1, *partners[0],
155 box_geo, kernel);
156 case 2:
157 return calc_bonded_three_body_pressure_tensor(iaparams, p1, *partners[0],
158 *partners[1], box_geo);
159 default:
160 runtimeWarningMsg() << "Unsupported bond type " +
161 std::to_string(iaparams.which()) +
162 " in pressure calculation.";
164 }
165}
166
167/** Calculate kinetic pressure (aka energy) for one particle.
168 * @param[in] p1 particle for which to calculate pressure
169 * @param[out] obs_pressure pressure observable
170 */
171inline void add_kinetic_virials(Particle const &p1,
172 Observable_stat &obs_pressure) {
173 if (p1.is_virtual())
174 return;
175
176 /* kinetic pressure */
177 for (int k = 0; k < 3; k++)
178 for (int l = 0; l < 3; l++)
179 obs_pressure.kinetic[k * 3 + l] += p1.v()[k] * p1.v()[l] * p1.mass();
180}
Vector implementation and trait types for boost qvm interoperability.
__global__ float * force
Data structures for bonded interactions.
int number_of_partners(Bonded_IA_Parameters const &iaparams)
Return the number of bonded partners for the specified bond.
boost::variant< NoneBond, FeneBond, HarmonicBond, QuarticBond, BondedCoulomb, BondedCoulombSR, AngleHarmonicBond, AngleCosineBond, AngleCossquareBond, DihedralBond, TabulatedDistanceBond, TabulatedAngleBond, TabulatedDihedralBond, ThermalizedBond, RigidBond, IBMTriel, IBMVolCons, IBMTribend, OifGlobalForcesBond, OifLocalForcesBond, VirtualBond > Bonded_IA_Parameters
Variant in which to store the parameters of an individual bonded interaction.
Utils::Vector< T, 3 > get_mi_vector(const Utils::Vector< T, 3 > &a, const Utils::Vector< T, 3 > &b) const
Get the minimum-image vector between two coordinates.
Observable for the pressure and energy.
Utils::Span< double > kinetic
Contribution from linear and angular kinetic energy (accumulated).
void add_non_bonded_contribution(int type1, int type2, int molid1, int molid2, Utils::Span< const double > data)
Utils::Span< double > coulomb
Contribution(s) from Coulomb interactions.
A stripped-down version of std::span from C++17.
Definition Span.hpp:38
DEVICE_QUALIFIER constexpr bool empty() const
Definition Span.hpp:87
This file contains the defaults for ESPResSo.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeWarningMsg()
bool do_nonbonded(Particle const &p1, Particle const &p2)
Determine if the non-bonded interactions between p1 and p2 should be calculated.
Force calculation.
boost::optional< std::tuple< Utils::Vector3d, Utils::Vector3d, Utils::Vector3d > > calc_bonded_three_body_force(Bonded_IA_Parameters const &iaparams, BoxGeometry const &box_geo, Particle const &p1, Particle const &p2, Particle const &p3)
ParticleForce calc_central_radial_force(IA_parameters const &ia_params, Utils::Vector3d const &d, double const dist)
boost::optional< Utils::Vector3d > calc_bond_pair_force(Particle const &p1, Particle const &p2, Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &dx, Coulomb::ShortRangeForceKernel::kernel_type const *kernel)
Compute the bonded interaction force between particle pairs.
ParticleForce calc_central_radial_charge_force(Particle const &p1, Particle const &p2, IA_parameters const &ia_params, Utils::Vector3d const &d, double const dist, Coulomb::ShortRangeForceKernel::kernel_type const *coulomb_kernel)
ParticleForce calc_non_central_force(Particle const &p1, Particle const &p2, IA_parameters const &ia_params, Utils::Vector3d const &d, double const dist)
Solver const & get_dipoles()
Definition dipoles.cpp:51
Matrix< T, N, M > tensor_product(const Vector< T, N > &x, const Vector< T, M > &y)
Various procedures concerning interactions between particles.
void add_kinetic_virials(Particle const &p1, Observable_stat &obs_pressure)
Calculate kinetic pressure (aka energy) for one particle.
boost::optional< Utils::Matrix< double, 3, 3 > > calc_bonded_virial_pressure_tensor(Bonded_IA_Parameters const &iaparams, Particle const &p1, Particle const &p2, BoxGeometry const &box_geo, Coulomb::ShortRangeForceKernel::kernel_type const *kernel)
boost::optional< Utils::Matrix< double, 3, 3 > > calc_bonded_three_body_pressure_tensor(Bonded_IA_Parameters const &iaparams, Particle const &p1, Particle const &p2, Particle const &p3, BoxGeometry const &box_geo)
void add_non_bonded_pair_virials(Particle const &p1, Particle const &p2, Utils::Vector3d const &d, double dist, IA_parameters const &ia_params, Coulomb::ShortRangeForceKernel::kernel_type const *kernel_forces, Coulomb::ShortRangePressureKernel::kernel_type const *kernel_pressure, Observable_stat &obs_pressure)
Calculate non-bonded energies between a pair of particles.
boost::optional< Utils::Matrix< double, 3, 3 > > calc_bonded_pressure_tensor(Bonded_IA_Parameters const &iaparams, Particle const &p1, Utils::Span< Particle * > partners, BoxGeometry const &box_geo, Coulomb::ShortRangeForceKernel::kernel_type const *kernel)
Solver::ShortRangeForceKernel kernel_type
Solver::ShortRangePressureKernel kernel_type
Parameters for non-bonded interactions.
Utils::Vector3d f
force.
Definition Particle.hpp:314
Struct holding all information for one particle.
Definition Particle.hpp:393
auto is_virtual() const
Definition Particle.hpp:516
auto const & mass() const
Definition Particle.hpp:450
auto const & q() const
Definition Particle.hpp:506
auto const & v() const
Definition Particle.hpp:431
auto const & type() const
Definition Particle.hpp:416
auto const & mol_id() const
Definition Particle.hpp:414
auto const & pos() const
Definition Particle.hpp:429
Matrix representation with static size.
Definition matrix.hpp:65