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>>
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);
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) {
64 }
65 return pressure;
66}
67
68inline std::optional<Utils::Matrix<double, 3, 3>>
71 Particle const &p2, BoxGeometry const &box_geo,
74 box_geo, kernel,
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
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) {
102 std::tie(std::ignore, force2, force3) = result.value();
105 }
106 } else {
107 runtimeWarningMsg() << "Unsupported bond type " +
108 std::to_string(iaparams.index()) +
109 " in pressure calculation.";
111 }
112 return {};
113}
114
115inline std::optional<Utils::Matrix<double, 3, 3>>
117 Utils::Vector3d const &pos1,
118 Utils::Vector3d const &pos2,
119 Utils::Vector3d const &pos3,
120 Utils::Vector3d const &pos4,
121 BoxGeometry const &box_geo) {
122 if (std::holds_alternative<DihedralBond>(iaparams)
124 or std::holds_alternative<TabulatedDihedralBond>(iaparams)
125#endif
126 ) {
127 auto const v12 = box_geo.get_mi_vector(pos1, pos2);
128 auto const v23 = box_geo.get_mi_vector(pos3, pos1);
129 auto const v34 = box_geo.get_mi_vector(pos4, pos3);
130
131 auto const result = calc_bonded_dihedral_force(iaparams, v12, v23, v34);
132
133 if (result) {
135 std::tie(std::ignore, force2, force3, force4) = result.value();
136
140 }
141 } else {
142 runtimeWarningMsg() << "Unsupported bond type " +
143 std::to_string(iaparams.index()) +
144 " in pressure calculation.";
146 }
147
148 return {};
149}
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.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
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, Utils::Vector3d > > calc_bonded_dihedral_force(Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &v12, Utils::Vector3d const &v23, Utils::Vector3d const &v34)
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_four_body_pressure_tensor(Bonded_IA_Parameters const &iaparams, Utils::Vector3d const &pos1, Utils::Vector3d const &pos2, Utils::Vector3d const &pos3, Utils::Vector3d const &pos4, BoxGeometry const &box_geo)
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
Matrix representation with static size.
Definition matrix.hpp:65