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-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
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/Vector.hpp>
39
40#include <cstdio>
41#include <optional>
42#include <span>
43#include <string>
44#include <tuple>
45#include <variant>
46
47// Overload for Cabana kernels: takes positions and charge product directly
48inline std::optional<Utils::Matrix<double, 3, 3>>
50 Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &pos1,
51 Utils::Vector3d const &pos2, BoxGeometry const &box_geo,
52 Coulomb::ShortRangeForceKernel::kernel_type const *kernel, double q1q2) {
53 auto const dx = box_geo.get_mi_vector(pos1, pos2);
54 auto const pair_force = calc_bond_pair_force(iaparams, dx,
55#ifdef ESPRESSO_ELECTROSTATICS
56 q1q2, kernel
57#else
58 0.0, nullptr
59#endif
60 );
61 std::optional<Utils::Matrix<double, 3, 3>> pressure{std::nullopt};
62 if (pair_force) {
63 pressure = Utils::tensor_product(*pair_force, dx);
64 }
65 return pressure;
66}
67
68inline std::optional<Utils::Matrix<double, 3, 3>>
70 Bonded_IA_Parameters const &iaparams, Particle const &p1,
71 Particle const &p2, BoxGeometry const &box_geo,
73 return calc_bonded_virial_pressure_tensor(iaparams, p1.pos(), p2.pos(),
74 box_geo, kernel,
75#ifdef ESPRESSO_ELECTROSTATICS
76 p1.q() * p2.q()
77#else
78 0.0
79#endif
80 );
81}
82
83// Overload for Cabana kernels: takes positions directly
84inline std::optional<Utils::Matrix<double, 3, 3>>
86 Utils::Vector3d const &pos1,
87 Utils::Vector3d const &pos2,
88 Utils::Vector3d const &pos3,
89 BoxGeometry const &box_geo) {
90 if (std::holds_alternative<AngleHarmonicBond>(iaparams) or
91 std::holds_alternative<AngleCosineBond>(iaparams) or
92#ifdef ESPRESSO_TABULATED
93 std::holds_alternative<TabulatedAngleBond>(iaparams) or
94#endif
95 std::holds_alternative<AngleCossquareBond>(iaparams)) {
96 auto const dx21 = -box_geo.get_mi_vector(pos1, pos2);
97 auto const dx31 = box_geo.get_mi_vector(pos3, pos1);
98
99 auto const result = calc_bonded_three_body_force(iaparams, dx21, dx31);
100 if (result) {
101 Utils::Vector3d force2, force3;
102 std::tie(std::ignore, force2, force3) = result.value();
103 return Utils::tensor_product(force2, dx21) +
104 Utils::tensor_product(force3, dx31);
105 }
106 } else {
107 runtimeWarningMsg() << "Unsupported bond type " +
108 std::to_string(iaparams.index()) +
109 " in pressure calculation.";
111 }
112 return {};
113}
Vector implementation and trait types for boost qvm interoperability.
Data structures for bonded interactions.
std::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.
ESPRESSO_ATTR_ALWAYS_INLINE Utils::Vector3< T > get_mi_vector(Utils::Vector3< T > const &a, Utils::Vector3< T > const &b) const
Get the minimum-image vector between two coordinates.
static auto pair_force(Utils::Vector3d const &d, Utils::Vector3d const &m1, Utils::Vector3d const &m2)
Pair force of two interacting dipoles.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeWarningMsg()
Force calculation.
ESPRESSO_ATTR_ALWAYS_INLINE std::optional< Utils::Vector3d > calc_bond_pair_force(Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &dx, double const q1q2, Coulomb::ShortRangeForceKernel::kernel_type const *kernel)
Compute the bonded interaction force between particle pairs.
ESPRESSO_ATTR_ALWAYS_INLINE std::optional< std::tuple< Utils::Vector3d, Utils::Vector3d, Utils::Vector3d > > calc_bonded_three_body_force(Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &vec1, Utils::Vector3d const &vec2)
Matrix< T, N, M > tensor_product(const Vector< T, N > &x, const Vector< T, M > &y)
Various procedures concerning interactions between particles.
std::optional< Utils::Matrix< double, 3, 3 > > calc_bonded_three_body_pressure_tensor(Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &pos1, Utils::Vector3d const &pos2, Utils::Vector3d const &pos3, BoxGeometry const &box_geo)
std::optional< Utils::Matrix< double, 3, 3 > > calc_bonded_virial_pressure_tensor(Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &pos1, Utils::Vector3d const &pos2, BoxGeometry const &box_geo, Coulomb::ShortRangeForceKernel::kernel_type const *kernel, double q1q2)
Solver::ShortRangeForceKernel kernel_type
Struct holding all information for one particle.
Definition Particle.hpp:435
auto const & q() const
Definition Particle.hpp:578
auto const & pos() const
Definition Particle.hpp:471
Matrix representation with static size.
Definition matrix.hpp:65