SPH
CompressedStorage.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "quantities/Quantity.h"
4 #include "quantities/Storage.h"
5 
7 
10 
11 public:
12  CompressedVector() = default;
13 
15  data[X] = float(v[X]);
16  data[Y] = float(v[Y]);
17  data[Z] = float(v[Z]);
18  }
19 
20  explicit operator Vector() const {
21  return Vector(Float(data[X]), Float(data[Y]), Float(data[Z]));
22  }
23 };
24 
27 private:
28  Array<CompressedVector> positions;
29  Array<CompressedVector> velocities;
30  Array<float> radii;
31 
32 public:
33  CompressedStorage() = default;
34 
35  CompressedStorage(const Storage& storage) {
36  ArrayView<const Vector> r, v, dv;
37  tie(r, v, dv) = storage.getAll<Vector>(QuantityId::POSITION);
38 
39  positions.resize(r.size());
40  velocities.resize(r.size());
41  radii.resize(r.size());
42 
43  for (Size i = 0; i < r.size(); ++i) {
44  positions[i] = r[i];
45  velocities[i] = v[i];
46  radii[i] = float(r[i][H]);
47  }
48  }
49 
50  explicit operator Storage() const {
51  Storage storage;
52  Array<Vector> r(positions.size());
53  for (Size i = 0; i < r.size(); ++i) {
54  r[i] = Vector(positions[i]);
55  r[i][H] = Float(radii[i]);
56  }
57  storage.insert<Vector>(QuantityId::POSITION, OrderEnum::FIRST, std::move(r));
58 
59  Array<Vector> v(velocities.size());
60  for (Size i = 0; i < v.size(); ++i) {
61  v[i] = Vector(velocities[i]);
62  }
63  storage.getDt<Vector>(QuantityId::POSITION) = std::move(v);
64 
65  return storage;
66  }
67 };
68 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
Holder of quantity values and their temporal derivatives.
@ FIRST
Quantity with 1st derivative.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Definition: StaticArray.h:281
Container for storing particle quantities and materials.
BasicVector< Float > Vector
Definition: Vector.h:539
@ H
Definition: Vector.h:25
@ Y
Definition: Vector.h:23
@ X
Definition: Vector.h:22
@ Z
Definition: Vector.h:24
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const
Definition: ArrayView.h:101
void resize(const TCounter newSize)
Resizes the array to new size.
Definition: Array.h:215
INLINE TCounter size() const noexcept
Definition: Array.h:193
contains reduced information
CompressedStorage(const Storage &storage)
CompressedStorage()=default
CompressedVector(const Vector &v)
CompressedVector()=default
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Quantity & insert(const QuantityId key, const OrderEnum order, const TValue &defaultValue)
Creates a quantity in the storage, given its key, value type and order.
Definition: Storage.cpp:270
StaticArray< Array< TValue > &, 3 > getAll(const QuantityId key)
Retrieves quantity buffers from the storage, given its key and value type.
Definition: Storage.cpp:163
Array< TValue > & getDt(const QuantityId key)
Retrieves a quantity derivative from the storage, given its key and value type.
Definition: Storage.cpp:217
Object with deleted copy constructor and copy operator.
Definition: Object.h:54