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 <utils/Span.hpp>
27
28#include <algorithm>
29#include <cstddef>
30
31void PartCfg::update() {
32 m_parts.clear();
33
34 auto const ids = get_particle_ids();
35 auto const chunk_size = fetch_cache_max_size();
36
37 for (std::size_t offset = 0; offset < ids.size();) {
38 auto const this_size = std::clamp(chunk_size, std::size_t{0},
39 std::size_t{ids.size() - offset});
40 auto const chunk_ids =
41 Utils::make_const_span(ids.data() + offset, this_size);
42
43 prefetch_particle_data(chunk_ids);
44
45 for (auto id : chunk_ids) {
46 m_parts.push_back(get_particle_data(id));
47
48 auto &p = m_parts.back();
49 p.pos() += m_box_geo.image_shift(p.image_box());
50 p.image_box() = {};
51 }
52
53 offset += this_size;
54 }
55}
auto image_shift(Utils::Vector3i const &image_box) const
Calculate image box shift vector.
DEVICE_QUALIFIER constexpr Span< std::add_const_t< T > > make_const_span(T *p, std::size_t N)
Definition Span.hpp:122
void prefetch_particle_data(Utils::Span< const int > in_ids)
Fetch a range of particle into the fetch cache.
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.
Particles creation and deletion.