ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/observables/RDF.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-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 "Observable.hpp"
23
24#include "PidObservable.hpp"
25
26#include <cstddef>
27#include <stdexcept>
28#include <utility>
29#include <vector>
30
31namespace Observables {
32
33/** Radial distribution function.
34 */
35class RDF : public Observable {
36 /** Identifiers of the reference particles */
37 std::vector<int> m_ids1;
38 /** Identifiers of the distant particles */
39 std::vector<int> m_ids2;
40
41 std::vector<double>
42 evaluate(boost::mpi::communicator const &comm,
43 ParticleReferenceRange const &local_particles_1,
44 ParticleReferenceRange const &local_particles_2,
46
47public:
48 // Range of the profile.
49 double min_r, max_r;
50 // Number of bins
51 std::size_t n_r_bins;
52
53 std::vector<std::size_t> shape() const override { return {n_r_bins}; }
54
55 RDF(std::vector<int> ids1, std::vector<int> ids2, int n_r_bins, double min_r,
56 double max_r)
57 : m_ids1(std::move(ids1)), m_ids2(std::move(ids2)), min_r(min_r),
58 max_r(max_r) {
59 if (max_r <= min_r)
60 throw std::runtime_error("max_r has to be > min_r");
61 if (n_r_bins <= 0)
62 throw std::domain_error("n_r_bins has to be >= 1");
63 this->n_r_bins = static_cast<std::size_t>(n_r_bins);
64 }
65 std::vector<double>
66 operator()(boost::mpi::communicator const &comm) const final;
67
68 std::vector<int> &ids1() { return m_ids1; }
69 std::vector<int> &ids2() { return m_ids2; }
70 std::vector<int> const &ids1() const { return m_ids1; }
71 std::vector<int> const &ids2() const { return m_ids2; }
72};
73
74} // Namespace Observables
Base class for observables.
Radial distribution function.
RDF(std::vector< int > ids1, std::vector< int > ids2, int n_r_bins, double min_r, double max_r)
std::vector< int > & ids2()
std::vector< int > const & ids1() const
std::vector< int > const & ids2() const
std::vector< std::size_t > shape() const override
std::vector< int > & ids1()
std::vector< double > operator()(boost::mpi::communicator const &comm) const final
Definition RDF.cpp:39
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange