ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Observable_stat.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 "Observable_stat.hpp"
23
24#include "config/config.hpp"
25
26#include "communication.hpp"
27
28#include <utils/index.hpp>
29
30#include <boost/mpi/collectives/reduce.hpp>
31
32#include <cassert>
33#include <cstddef>
34#include <functional>
35#include <span>
36#include <vector>
37
38Observable_stat::Observable_stat(std::size_t chunk_size, std::size_t n_bonded,
39 int max_type)
40 : m_data{}, m_chunk_size{chunk_size} {
41 // number of chunks for different interaction types
42 constexpr std::size_t n_coulomb = 2;
43 constexpr std::size_t n_dipolar = 2;
44#ifdef VIRTUAL_SITES
45 constexpr std::size_t n_vs = 1;
46#else
47 constexpr std::size_t n_vs = 0;
48#endif
49#ifdef DPD
50 constexpr std::size_t n_dpd = 1;
51#else
52 constexpr std::size_t n_dpd = 0;
53#endif
54 auto const n_non_bonded = get_non_bonded_offset(max_type, max_type) + 1ul;
55 constexpr std::size_t n_ext_fields = 1; // reduction over all fields
56 constexpr std::size_t n_kinetic_lin = 1; // linear kinetic contribution
57 constexpr std::size_t n_kinetic_rot = 1; // angular kinetic contribution
58
59 auto const n_elements = n_kinetic_lin + n_kinetic_rot + n_bonded +
60 2ul * n_non_bonded + n_coulomb + n_dipolar + n_vs +
61 n_ext_fields + n_dpd;
62 m_data = std::vector<double>(m_chunk_size * n_elements);
63
64 // spans for the different contributions
65 kinetic_lin = std::span<double>(m_data.data(), m_chunk_size);
66 kinetic_rot = std::span<double>(kinetic_lin.end(), m_chunk_size);
67 bonded = std::span<double>(kinetic_rot.end(), n_bonded * m_chunk_size);
68 coulomb = std::span<double>(bonded.end(), n_coulomb * m_chunk_size);
69 dipolar = std::span<double>(coulomb.end(), n_dipolar * m_chunk_size);
70 virtual_sites = std::span<double>(dipolar.end(), n_vs * m_chunk_size);
71 dpd = std::span<double>(virtual_sites.end(), n_dpd * m_chunk_size);
72 external_fields = std::span<double>(dpd.end(), n_ext_fields * m_chunk_size);
74 std::span<double>(external_fields.end(), n_non_bonded * m_chunk_size);
76 std::span<double>(non_bonded_intra.end(), n_non_bonded * m_chunk_size);
77 assert(&*non_bonded_inter.end() == (m_data.data() + m_data.size()));
78}
79
80std::size_t Observable_stat::get_non_bonded_offset(int type1, int type2) const {
81 return static_cast<std::size_t>(
82 Utils::lower_triangular(std::max(type1, type2), std::min(type1, type2)));
83}
84
86 if (comm_cart.rank() == 0) {
87 std::vector<double> temp(m_data);
88 boost::mpi::reduce(comm_cart, temp, m_data, std::plus<>{}, 0);
89 } else {
90 boost::mpi::reduce(comm_cart, m_data, std::plus<>{}, 0);
91 }
92}
std::span< double > coulomb
Contribution(s) from Coulomb interactions.
std::span< double > non_bonded_inter
Contribution(s) from non-bonded intermolecular interactions.
std::span< double > dpd
Contribution from DPD.
std::span< double > kinetic_rot
Contribution from angular kinetic energy.
std::span< double > kinetic_lin
Contribution from linear kinetic energy.
std::span< double > virtual_sites
Contribution from virtual sites (accumulated).
Observable_stat(std::size_t chunk_size, std::size_t n_bonded, int max_type)
std::span< double > non_bonded_intra
Contribution(s) from non-bonded intramolecular interactions.
void mpi_reduce()
MPI reduction.
std::span< double > dipolar
Contribution(s) from dipolar interactions.
std::span< double > external_fields
Contribution from external fields (accumulated).
std::span< double > bonded
Contribution(s) from bonded interactions.
boost::mpi::communicator comm_cart
The communicator.
This file contains the defaults for ESPResSo.
T lower_triangular(T i, T j)
Linear index into a lower triangular matrix.
Definition index.hpp:71