10#include <initializer_list>
27template <
class SoAArraysType>
46 soaStorage.apply([=](
auto &list) { list.resize(length); });
54 template <std::
size_t attribute>
55 void push(
const double value) {
56 soaStorage.template get<attribute>().push_back(value);
66 template <
int attribute,
class ValueType>
67 void write(
size_t particleId,
const ValueType &value) {
68 soaStorage.template get<attribute>().at(particleId) = value;
76 if (other.
size() > 0) {
77 append_impl(other.soaStorage, std::make_index_sequence<std::tuple_size<SoAArraysType>::value>{});
86 if (other.
size() > 0) {
87 append_impl(other, std::make_index_sequence<std::tuple_size<SoAArraysType>::value>{});
96 template <
int... attributes>
98 if (other.
size() > 0) {
99 const auto newSize =
size() + other.
size();
100 append_impl(other.soaStorage, std::index_sequence<attributes...>{});
112 template <
int... attributes,
class ValueArrayType>
114 write_impl<attributes...>(particleId, values);
124 template <
int... attributes,
size_t N =
sizeof...(attributes)>
125 inline void writeMultiple(
size_t particleId,
const std::array<double, N> &values) {
126 write_impl<attributes...>(particleId, values);
137 template <
int... attributes>
138 std::array<double,
sizeof...(attributes)>
readMultiple(
size_t particleId)
const {
139 std::array<double,
sizeof...(attributes)> retArray;
140 if (particleId >=
size()) {
142 "SoA::read: requested particle id ({}) is bigger than number of particles ({})", particleId,
size());
145 read_impl<attributes...>(particleId, retArray);
155 template <std::
size_t attribute>
156 auto read(
size_t particleId)
const {
157 return soaStorage.template get<attribute>().at(particleId);
165 template <std::
size_t attribute>
167 return soaStorage.template get<attribute>().data();
178 size_t maxLength = 0;
187 soaStorage.apply([](
auto &list) { list.clear(); });
195 void swap(std::size_t a, std::size_t b) {
196 soaStorage.apply([=](
auto &list) { std::swap(list[a], list[b]); });
203 soaStorage.apply([](
auto &list) { list.pop_back(); });
225 template <
int attribute,
int... attributes,
class ValueArrayType>
226 void read_impl(
size_t particleId, ValueArrayType &values,
int _current = 0)
const {
227 values[_current] = soaStorage.template get<attribute>().at(particleId);
228 read_impl<attributes...>(particleId, values, _current + 1);
232 template <
class ValueArrayType>
233 void read_impl(
size_t particleId, ValueArrayType &values,
int _current = 0)
const {}
237 template <
int attribute,
int... attributes,
class ValueArrayType>
238 void write_impl(
size_t particleId,
const ValueArrayType &values,
int _current = 0) {
239 soaStorage.template get<attribute>().at(particleId) = values[_current];
240 write_impl<attributes...>(particleId, values, _current + 1);
244 template <
class ValueArrayType>
245 void write_impl(
size_t particleId,
const ValueArrayType &values,
int _current = 0) {}
248 template <std::
size_t attribute>
249 void appendSingleArray(
const utils::SoAStorage<SoAArraysType> &valArrays) {
250 auto ¤tVector = soaStorage.template get<attribute>();
251 auto &otherVector = valArrays.template get<attribute>();
252 currentVector.insert(currentVector.end(), otherVector.begin(), otherVector.end());
256 template <std::
size_t attribute>
257 void appendSingleArray(
const SoAView<SoAArraysType> &valArrays) {
258 auto ¤tVector = soaStorage.template get<attribute>();
259 auto otherVectorIterator = valArrays.template begin<attribute>();
260 currentVector.insert(currentVector.end(), otherVectorIterator, otherVectorIterator + valArrays.size());
264 template <std::size_t... Is>
265 void append_impl(
const utils::SoAStorage<SoAArraysType> &valArrays, std::index_sequence<Is...>) {
267 (appendSingleArray<Is>(valArrays), ...);
271 template <std::size_t... Is>
272 void append_impl(
const SoAView<SoAArraysType> &valArrays, std::index_sequence<Is...>) {
274 (appendSingleArray<Is>(valArrays), ...);
280 utils::SoAStorage<SoAArraysType> soaStorage;
Provides a struct to easily generate the desired SoAType.
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:23
size_t size() const
Returns the number of particles in the view.
Definition: SoAView.h:83
Structur of the array class.
Definition: SoA.h:28
void writeMultiple(size_t particleId, const ValueArrayType &values)
Writes or updates values of attributes for a specific particle.
Definition: SoA.h:113
void append(const SoAView< SoAArraysType > &other)
Appends the other SoA buffer to this.
Definition: SoA.h:85
void append(const SoA< SoAArraysType > &other)
Appends the specified attributes from the other SoA buffer to this.
Definition: SoA.h:97
void resizeArrays(size_t length)
Resizes all Vectors to the given length.
Definition: SoA.h:45
void pop_back()
Delete the last particle in the SoA.
Definition: SoA.h:202
void write(size_t particleId, const ValueType &value)
Writes / updates the value of an attribute for a specific particle.
Definition: SoA.h:67
void clear()
delete all particles in the soa
Definition: SoA.h:186
SoAView< SoAArraysType > constructView(size_t startIndex, size_t endIndex)
Constructs a view that starts at startIndex (inclusive) and ends at endIndex (exclusive).
Definition: SoA.h:221
SoA(const SoA &soa)=default
Copy constructor.
std::array< double, sizeof...(attributes)> readMultiple(size_t particleId) const
Reads from all given attribute arrays at position particleId.
Definition: SoA.h:138
void writeMultiple(size_t particleId, const std::array< double, N > &values)
Specialized version to pass arrays without specifying it directly.
Definition: SoA.h:125
SoAView< SoAArraysType > constructView()
Constructs a SoAView for the whole SoA and returns it.
Definition: SoA.h:210
void push(const double value)
Pushes a given value to the desired attribute array.
Definition: SoA.h:55
size_t size() const
Returns the number of particles.
Definition: SoA.h:177
SoA()=default
Default constructor.
void swap(std::size_t a, std::size_t b)
swap the position of two particles in the soa
Definition: SoA.h:195
auto begin()
Returns a pointer to the given attribute vector.
Definition: SoA.h:166
auto read(size_t particleId) const
Reads the value of a given attribute of a given particle.
Definition: SoA.h:156
void append(const SoA< SoAArraysType > &other)
Appends the other SoA buffer to this.
Definition: SoA.h:75
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
void for_each(T &&tuple, F &&f)
Applies a function f on every element of the tuple.
Definition: TupleUtils.h:22
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32