ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
PartCfg.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
20#include "PartCfg.hpp"
21
22#include "BoxGeometry.hpp"
23#include "particle_node.hpp"
24#include "system/System.hpp"
25
26#include <algorithm>
27#include <cstddef>
28#include <span>
29
30void PartCfg::update() {
31 m_parts.clear();
32
33 auto const ids = get_particle_ids();
34 auto const chunk_size = fetch_cache_max_size();
35
36 for (std::size_t offset = 0; offset < ids.size();) {
37 auto const this_size = std::clamp(chunk_size, std::size_t{0},
38 std::size_t{ids.size() - offset});
39 auto const chunk_ids = std::span(ids.data() + offset, this_size);
40
41 prefetch_particle_data(chunk_ids);
42
43 for (auto id : chunk_ids) {
44 m_parts.push_back(get_particle_data(id));
45
46 auto &p = m_parts.back();
47 p.pos() += m_box_geo.image_shift(p.image_box());
48 p.image_box() = {};
49 }
50
51 offset += this_size;
52 }
53}
auto image_shift(Utils::Vector3i const &image_box) const
Calculate image box shift vector.
const Particle & get_particle_data(int p_id)
Get particle data.
std::vector< int > get_particle_ids()
Get all particle ids.
std::size_t fetch_cache_max_size()
Return the maximal number of particles that are kept in the fetch cache.
void prefetch_particle_data(std::span< const int > in_ids)
Fetch a range of particle into the fetch cache.
Particles creation and deletion.