8 template <
typename TValue>
11 if (!this->hasBuffer(
id, order)) {
16 auto recordIter = std::find_if(records.
begin(), records.
end(), [
id](QuantityRecord& r) {
19 if (recordIter == records.
end()) {
26 SPH_ASSERT(
false,
"Another derivatives accumulates to quantity marked as unique");
38 for (Element& e : buffers) {
39 forValue(e.buffer, [size](
auto& values) {
40 using T = typename std::decay_t<decltype(values)>::Type;
41 if (values.size() != size) {
46 SPH_ASSERT(std::count(values.begin(), values.end(), T(0._f)) == values.size());
52 template <
typename TValue>
54 for (Element& e : buffers) {
72 for (Element& e : buffers) {
73 forValue(e.buffer, [
this, &e, &others](
auto& buffer)
INL {
74 this->sumBuffer(buffer, e.id, others);
80 for (Element& e : buffers) {
81 forValue(e.buffer, [
this, &scheduler, &e, &others](
auto& buffer)
INL {
82 this->sumBuffer(scheduler, buffer, e.id, others);
87 for (Element& e : buffers) {
88 forValue(e.buffer, [&e, &storage](
auto& buffer) {
89 using T = typename std::decay_t<decltype(buffer)>::Type;
92 SPH_ASSERT(storage.has(e.id), getMetadata(e.id).quantityName);
93 SPH_ASSERT(Size(storage.getQuantity(e.id).getOrderEnum()) >= Size(e.order));
94 storage.getAll<T>(e.id)[Size(e.order)] = std::move(buffer);
101 return buffers.
size();
104 template <
typename Type>
108 auto iter = std::find_if(other->buffers.begin(), other->buffers.end(), [
id](
const Element& e) {
118 template <
typename Type>
121 const Type zero = Type(0._f);
122 for (
Size i = 0; i < buffer1.
size(); ++i) {
135 template <
typename Type>
136 void Accumulated::sumBuffer(
IScheduler& scheduler,
141 auto functor = [&iterators, &buffer1](
const Size i)
INL {
144 Type& x = *(iter + i);
145 if (x != Type(0._f)) {
156 for (
const Element& e : buffers) {
159 SPH_ASSERT(e.order == order,
"Cannot accumulate both values and derivatives of quantity");
Buffer storing quantity values accumulated by summing over particle pairs.
@ UNIQUE
Only a single derivative accumulates to this buffer.
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
#define NAMESPACE_SPH_END
QuantityId
Unique IDs of basic quantities of SPH particles.
Holder of quantity values and their temporal derivatives.
Interface for executing tasks (potentially) asynchronously.
INLINE void parallelFor(IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
Executes a functor concurrently from all available threads.
Container for storing particle quantities and materials.
decltype(auto) INLINE forValue(Variant< TArgs... > &variant, TFunctor &&functor)
Storage for accumulating derivatives.
void initialize(const Size size)
Initialize all storages.
void sum(ArrayView< Accumulated * > others)
Sums values of a list of storages.
Array< TValue > & getBuffer(const QuantityId id, const OrderEnum order)
Returns the buffer of given quantity and given order.
Size getBufferCnt() const
void store(Storage &storage)
Stores accumulated values to corresponding quantities.
void insert(const QuantityId id, const OrderEnum order, const BufferSource source)
Creates a new storage with given ID.
Object providing safe access to continuous memory of data.
INLINE Iterator< StorageType > end() noexcept
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
INLINE TCounter size() const noexcept
INLINE bool empty() const noexcept
INLINE Iterator< StorageType > begin() noexcept
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Simple (forward) iterator over continuous array of objects of type T.
Container storing all quantities used within the simulations.