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 auto const n_non_bonded = get_non_bonded_offset(max_type, max_type) + 1ul;
50 constexpr std::size_t n_ext_fields = 1; // reduction over all fields
51 constexpr std::size_t n_kinetic = 1; // linear+angular kinetic contributions
52
53 auto const n_elements = n_kinetic + n_bonded + 2ul * n_non_bonded +
54 n_coulomb + n_dipolar + n_vs + n_ext_fields;
55 m_data = std::vector<double>(m_chunk_size * n_elements);
56
57 // spans for the different contributions
58 kinetic = std::span<double>(m_data.data(), m_chunk_size);
59 bonded = std::span<double>(kinetic.end(), n_bonded * m_chunk_size);
60 coulomb = std::span<double>(bonded.end(), n_coulomb * m_chunk_size);
61 dipolar = std::span<double>(coulomb.end(), n_dipolar * m_chunk_size);
62 virtual_sites = std::span<double>(dipolar.end(), n_vs * m_chunk_size);
64 std::span<double>(virtual_sites.end(), n_ext_fields * m_chunk_size);
66 std::span<double>(external_fields.end(), n_non_bonded * m_chunk_size);
68 std::span<double>(non_bonded_intra.end(), n_non_bonded * m_chunk_size);
69 assert(&*non_bonded_inter.end() == (m_data.data() + m_data.size()));
70}
71
72std::size_t Observable_stat::get_non_bonded_offset(int type1, int type2) const {
73 return static_cast<std::size_t>(
74 Utils::lower_triangular(std::max(type1, type2), std::min(type1, type2)));
75}
76
78 if (comm_cart.rank() == 0) {
79 std::vector<double> temp(m_data);
80 boost::mpi::reduce(comm_cart, temp, m_data, std::plus<>{}, 0);
81 } else {
82 boost::mpi::reduce(comm_cart, m_data, std::plus<>{}, 0);
83 }
84}
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 > virtual_sites
Contribution from virtual sites (accumulated).
std::span< double > kinetic
Contribution from linear and angular kinetic energy (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