ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
TimeSeries.cpp
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#include "TimeSeries.hpp"
20
21#include <boost/archive/binary_iarchive.hpp>
22#include <boost/archive/binary_oarchive.hpp>
23#include <boost/iostreams/device/array.hpp>
24#include <boost/iostreams/stream.hpp>
25#include <boost/serialization/vector.hpp>
26
27#include <sstream>
28#include <string>
29
30namespace Accumulators {
31void TimeSeries::update(boost::mpi::communicator const &comm) {
32 if (comm.rank() == 0) {
33 m_data.emplace_back(m_obs->operator()(comm));
34 } else {
35 m_obs->operator()(comm);
36 }
37}
38
39std::string TimeSeries::get_internal_state() const {
40 std::stringstream ss;
41 boost::archive::binary_oarchive oa(ss);
42
43 oa << m_data;
44
45 return ss.str();
46}
47
48void TimeSeries::set_internal_state(std::string const &state) {
49 namespace iostreams = boost::iostreams;
50 iostreams::array_source src(state.data(), state.size());
51 iostreams::stream<iostreams::array_source> ss(src);
52 boost::archive::binary_iarchive ia(ss);
53
54 ia >> m_data;
55 m_system = nullptr;
56}
57} // namespace Accumulators
void const * m_system
for bookkeeping purposes
void update(boost::mpi::communicator const &comm) override
void set_internal_state(std::string const &) final
std::string get_internal_state() const final