ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/accumulators/ContactTimes.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2025 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 "AccumulatorBase.hpp"
23#include "observables/Observable.hpp"
24#include "system/System.hpp"
25
26#include <cstddef>
27#include <memory>
28#include <stdexcept>
29#include <string>
30#include <utility>
31#include <vector>
32
33namespace Accumulators {
34
35/**
36 * @brief Record the time distances are below a threshold.
37 *
38 * The contact time is defined as @f$ \tau = t_f - t_0 @f$ where
39 * @f$ t_f @f$ is the last measured time at which a pairwise distance was below
40 * the threshold and @f$ t_0 @f$ is the first measured time at which the same
41 * distance was below the threshold.
42 */
44public:
46 double contact_threshold,
47 std::shared_ptr<Observables::Observable> obs)
48 : AccumulatorBase(system, delta_N), m_obs(std::move(obs)),
49 m_contact_threshold(contact_threshold) {
50 if (contact_threshold < 0.) {
51 throw std::domain_error("Attribute 'contact_threshold' must be >= 0");
52 }
53 }
54
55 void update(boost::mpi::communicator const &comm) override;
56 std::string get_internal_state() const final;
57 void set_internal_state(std::string const &) final;
58
59 auto const &contact_times() const { return m_data; }
60 std::vector<std::size_t> shape() const override { return {m_data.size()}; }
61 void clear() { m_data.clear(); }
62 double get_contact_threshold() const { return m_contact_threshold; }
63
64private:
65 std::shared_ptr<Observables::Observable> m_obs;
66 std::vector<double> m_data;
67 double m_contact_threshold;
68 std::vector<bool> contacts;
69 std::vector<double> first_contact_times;
70};
71
72} // namespace Accumulators
Record the time distances are below a threshold.
std::string get_internal_state() const final
void update(boost::mpi::communicator const &comm) override
ContactTimes(::System::System const *system, int delta_N, double contact_threshold, std::shared_ptr< Observables::Observable > obs)
std::vector< std::size_t > shape() const override
void set_internal_state(std::string const &) final
Main system class.