Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
pressure.cpp
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#include "config/config.hpp"
23
24#include "BoxGeometry.hpp"
25#include "Observable_stat.hpp"
26#include "Particle.hpp"
27#include "ParticleRange.hpp"
29#include "dpd.hpp"
33#include "pressure_inline.hpp"
34#include "short_range_loop.hpp"
35#include "system/System.hpp"
37
38#include <utils/Vector.hpp>
39#include <utils/flatten.hpp>
40
41#include <algorithm>
42#include <cstddef>
43#include <memory>
44#include <span>
45
46namespace System {
47std::shared_ptr<Observable_stat> System::calculate_pressure() {
48
49 auto obs_pressure_ptr = std::make_shared<Observable_stat>(
50 9ul, static_cast<std::size_t>(bonded_ias->get_next_key()),
51 nonbonded_ias->get_max_seen_particle_type());
52
53 if (long_range_interactions_sanity_checks()) {
54 return obs_pressure_ptr;
55 }
56
57 auto &obs_pressure = *obs_pressure_ptr;
58
59 on_observable_calc();
60
61 auto const volume = box_geo->volume();
62 auto const local_parts = cell_structure->local_particles();
63
64 for (auto const &p : local_parts) {
65 add_kinetic_virials(p, obs_pressure);
66 }
67
68 auto const coulomb_force_kernel = coulomb.pair_force_kernel();
69 auto const coulomb_pressure_kernel = coulomb.pair_pressure_kernel();
70
72 [this, coulomb_force_kernel_ptr = get_ptr(coulomb_force_kernel),
73 &obs_pressure](Particle const &p1, int bond_id,
74 std::span<Particle *> partners) {
75 auto const &iaparams = *bonded_ias->at(bond_id);
76 auto const result = calc_bonded_pressure_tensor(
77 iaparams, p1, partners, *box_geo, coulomb_force_kernel_ptr);
78 if (result) {
79 auto const &tensor = result.value();
80 /* pressure tensor part */
81 for (std::size_t k = 0u; k < 3u; k++)
82 for (std::size_t l = 0u; l < 3u; l++)
83 obs_pressure.bonded_contribution(bond_id)[k * 3u + l] +=
84 tensor(k, l);
85
86 return false;
87 }
88 return true;
89 },
90 [coulomb_force_kernel_ptr = get_ptr(coulomb_force_kernel),
91 coulomb_pressure_kernel_ptr = get_ptr(coulomb_pressure_kernel), this,
92 &obs_pressure](Particle const &p1, Particle const &p2,
93 Distance const &d) {
94 auto const &ia_params =
95 nonbonded_ias->get_ia_param(p1.type(), p2.type());
96 add_non_bonded_pair_virials(p1, p2, d.vec21, sqrt(d.dist2), ia_params,
97 *bonded_ias, coulomb_force_kernel_ptr,
98 coulomb_pressure_kernel_ptr, obs_pressure);
99 },
100 *cell_structure, maximal_cutoff(), bonded_ias->maximal_cutoff());
101
102#ifdef ELECTROSTATICS
103 /* calculate k-space part of electrostatic interaction. */
104 auto const coulomb_pressure = coulomb.calc_pressure_long_range(local_parts);
105 std::ranges::copy(coulomb_pressure, obs_pressure.coulomb.begin() + 9u);
106#endif
107#ifdef DIPOLES
108 /* calculate k-space part of magnetostatic interaction. */
110#endif
111
112#ifdef VIRTUAL_SITES_RELATIVE
113 if (!obs_pressure.virtual_sites.empty()) {
114 auto const vs_pressure = vs_relative_pressure_tensor(*cell_structure);
115 std::ranges::copy(Utils::flatten(vs_pressure),
116 obs_pressure.virtual_sites.begin());
117 }
118#endif
119
120#ifdef DPD
121 std::ranges::copy(dpd_pressure_local(), obs_pressure.dpd.begin());
122#endif
123
124 obs_pressure.rescale(volume);
125
126 obs_pressure.mpi_reduce();
127 return obs_pressure_ptr;
128}
129} // namespace System
Vector implementation and trait types for boost qvm interoperability.
Data structures for bonded interactions.
std::shared_ptr< Observable_stat > calculate_pressure()
Calculate the pressure from a virial expansion.
Definition pressure.cpp:47
This file contains the defaults for ESPResSo.
const T * get_ptr(std::optional< T > const &opt)
Utils::Vector9d dpd_pressure_local()
Local contribution to the pressure tensor.
Definition dpd.cpp:159
Routines to use DPD as thermostat or pair force .
Solver const & get_dipoles()
Definition dipoles.cpp:49
void flatten(Range const &v, OutputIterator out)
Flatten a range of ranges.
Definition flatten.hpp:64
Various procedures concerning interactions between particles.
void add_non_bonded_pair_virials(Particle const &p1, Particle const &p2, Utils::Vector3d const &d, double dist, IA_parameters const &ia_params, BondedInteractionsMap const &bonded_ias, 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.
std::optional< Utils::Matrix< double, 3, 3 > > calc_bonded_pressure_tensor(Bonded_IA_Parameters const &iaparams, Particle const &p1, std::span< Particle * > partners, BoxGeometry const &box_geo, Coulomb::ShortRangeForceKernel::kernel_type const *kernel)
void add_kinetic_virials(Particle const &p1, Observable_stat &obs_pressure)
Calculate kinetic pressure (aka energy) for one particle.
Utils::Matrix< double, 3, 3 > vs_relative_pressure_tensor(CellStructure const &cell_structure)
Definition relative.cpp:193
void short_range_loop(BondKernel bond_kernel, PairKernel pair_kernel, CellStructure &cell_structure, double pair_cutoff, double bond_cutoff, VerletCriterion const &verlet_criterion={})
void calc_pressure_long_range() const
Definition dipoles.cpp:193
Distance vector and length handed to pair kernels.
Struct holding all information for one particle.
Definition Particle.hpp:395
auto const & type() const
Definition Particle.hpp:418
DEVICE_QUALIFIER constexpr iterator begin() noexcept
Definition Array.hpp:140