ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Observable_stat.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
20#pragma once
21
22#include <boost/range/algorithm/transform.hpp>
23#include <boost/range/numeric.hpp>
24
25#include <utils/Span.hpp>
26
27#include <algorithm>
28#include <cassert>
29#include <cstddef>
30#include <functional>
31#include <vector>
32
33/** Observable for the pressure and energy. */
35 /** Array for observables on each node. */
36 std::vector<double> m_data;
37 /** Number of doubles per data item */
38 std::size_t m_chunk_size;
39
40 /** Get contribution from a non-bonded interaction */
42 get_non_bonded_contribution(Utils::Span<double> base_pointer, int type1,
43 int type2) const;
44
45public:
46 Observable_stat(std::size_t chunk_size, std::size_t n_bonded, int max_type);
47
48 auto get_chunk_size() const { return m_chunk_size; }
49
50 /** Accumulate values.
51 * @param acc Initial value for the accumulator.
52 * @param column Which column to sum up (only relevant for multi-dimensional
53 * observables).
54 */
55 double accumulate(double acc = 0.0, std::size_t column = 0) const {
56 assert(column < m_chunk_size);
57 if (m_chunk_size == 1)
58 return boost::accumulate(m_data, acc);
59
60 for (auto it = m_data.begin() + static_cast<std::ptrdiff_t>(column);
61 it < m_data.end(); it += static_cast<std::ptrdiff_t>(m_chunk_size))
62 acc += *it;
63 return acc;
64 }
65
66 /** Rescale values */
67 void rescale(double volume) {
68 auto const fac = 1. / volume;
69 boost::transform(m_data, m_data.begin(), [fac](auto e) { return e * fac; });
70 }
71
72 /** Contribution from linear and angular kinetic energy (accumulated). */
74 /** Contribution(s) from bonded interactions. */
76 /** Contribution(s) from Coulomb interactions. */
78 /** Contribution(s) from dipolar interactions. */
80 /** Contribution from virtual sites (accumulated). */
82 /** Contribution from external fields (accumulated). */
84 /** Contribution(s) from non-bonded intramolecular interactions. */
86 /** Contribution(s) from non-bonded intermolecular interactions. */
88
89 /** Get contribution from a bonded interaction */
91 auto const offset = m_chunk_size * static_cast<std::size_t>(bond_id);
92 return {bonded.data() + offset, m_chunk_size};
93 }
94
95 void add_non_bonded_contribution(int type1, int type2, int molid1, int molid2,
97 assert(data.size() == m_chunk_size);
98 auto const span = (molid1 == molid2) ? non_bonded_intra : non_bonded_inter;
99 auto const dest = get_non_bonded_contribution(span, type1, type2);
100
101 boost::transform(dest, data, dest.begin(), std::plus<>{});
102 }
103
104 void add_non_bonded_contribution(int type1, int type2, int molid1, int molid2,
105 double data) {
106 add_non_bonded_contribution(type1, type2, molid1, molid2, {&data, 1});
107 }
108
109 /** Get contribution from a non-bonded intramolecular interaction */
111 int type2) const {
112 return get_non_bonded_contribution(non_bonded_intra, type1, type2);
113 }
114
115 /** Get contribution from a non-bonded intermolecular interaction */
117 int type2) const {
118 return get_non_bonded_contribution(non_bonded_inter, type1, type2);
119 }
120
121 /** MPI reduction. */
122 void mpi_reduce();
123};
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, double data)
auto get_chunk_size() const
void rescale(double volume)
Rescale values.
Utils::Span< double > dipolar
Contribution(s) from dipolar interactions.
Utils::Span< double > bonded_contribution(int bond_id) const
Get contribution from a bonded interaction.
Utils::Span< double > non_bonded_intra_contribution(int type1, int type2) const
Get contribution from a non-bonded intramolecular interaction.
double accumulate(double acc=0.0, std::size_t column=0) const
Accumulate values.
Utils::Span< double > virtual_sites
Contribution from virtual sites (accumulated).
void mpi_reduce()
MPI reduction.
Utils::Span< double > non_bonded_intra
Contribution(s) from non-bonded intramolecular interactions.
Utils::Span< double > external_fields
Contribution from external fields (accumulated).
Utils::Span< double > non_bonded_inter
Contribution(s) from non-bonded intermolecular interactions.
void add_non_bonded_contribution(int type1, int type2, int molid1, int molid2, Utils::Span< const double > data)
Utils::Span< double > non_bonded_inter_contribution(int type1, int type2) const
Get contribution from a non-bonded intermolecular interaction.
Utils::Span< double > bonded
Contribution(s) from bonded interactions.
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 pointer data() const
Definition Span.hpp:108
DEVICE_QUALIFIER constexpr size_type size() const
Definition Span.hpp:86
DEVICE_QUALIFIER constexpr iterator begin() const
Definition Span.hpp:89