ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
aosoa_pack.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 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 <config/config.hpp>
23
24#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
25
27
28#include <Kokkos_Core.hpp>
29
30#include <cstdint>
31
45
55
56 AoSoA_pack() = default;
57
59
60 void resize(std::size_t num_particles) {
61 if (position.extent(0) == 0) {
62 // First allocation
64#ifdef ESPRESSO_ELECTROSTATICS
66#endif
67 id = IdViewType("id", num_particles);
70#ifdef ESPRESSO_DPD
72#endif
73#if defined(ESPRESSO_GAY_BERNE) or defined(ESPRESSO_DIPOLES)
75#endif
76#ifdef ESPRESSO_DIPOLES
78#endif
79 } else {
80 // Reallocation
81 Kokkos::realloc(position, num_particles);
82#ifdef ESPRESSO_ELECTROSTATICS
83 Kokkos::realloc(charge, num_particles);
84#endif
85 Kokkos::realloc(id, num_particles);
86 Kokkos::realloc(type, num_particles);
87 Kokkos::realloc(flags, num_particles);
88#ifdef ESPRESSO_DPD
89 Kokkos::realloc(velocity, num_particles);
90#endif
91#if defined(ESPRESSO_GAY_BERNE) or defined(ESPRESSO_DIPOLES)
92 Kokkos::realloc(director, num_particles);
93#endif
94#ifdef ESPRESSO_DIPOLES
95 Kokkos::realloc(dipm, num_particles);
96#endif
97 }
98 }
99
100 template <typename array_layout>
102 Kokkos::View<double *[3], array_layout, Kokkos::HostSpace> const &view,
103 std::size_t i) const {
104 return {view(i, 0), view(i, 1), view(i, 2)};
105 }
106
107 template <typename array_layout>
109 Kokkos::View<double *[3], array_layout, Kokkos::HostSpace> &view,
110 std::size_t i, Utils::Vector3d const &value) {
111 view(i, 0) = value[0];
112 view(i, 1) = value[1];
113 view(i, 2) = value[2];
114 }
115
116 void set_has_exclusion(std::size_t i, bool value) {
117 flags(i) = value ? uint8_t{1} : uint8_t{0};
118 }
119
120 bool has_exclusion(std::size_t i) const { return flags(i) == uint8_t{1}; }
121};
122
123#endif // ESPRESSO_SHARED_MEMORY_PARALLELISM
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
IdToIndexViewType id_to_index
Utils::Vector3d get_vector_at(Kokkos::View< double *[3], array_layout, Kokkos::HostSpace > const &view, std::size_t i) const
Kokkos::View< double *, Kokkos::HostSpace > ChargeViewType
bool has_exclusion(std::size_t i) const
Kokkos::View< uint8_t *, Kokkos::HostSpace > FlagsViewType
Kokkos::View< double *, Kokkos::HostSpace > DipmViewType
void set_vector_at(Kokkos::View< double *[3], array_layout, Kokkos::HostSpace > &view, std::size_t i, Utils::Vector3d const &value)
Kokkos::View< double *[3], Kokkos::LayoutRight, Kokkos::HostSpace > DirectorViewType
PositionViewType position
AoSoA_pack(std::size_t num_particles)
Kokkos::View< int *, Kokkos::HostSpace > TypeViewType
Kokkos::View< double *[3], Kokkos::LayoutRight, Kokkos::HostSpace > PositionViewType
void set_has_exclusion(std::size_t i, bool value)
DirectorViewType director
Kokkos::View< int *, Kokkos::HostSpace > IdViewType
VelocityViewType velocity
void resize(std::size_t num_particles)