12 ref =
Vector(0._f, 1._f, 0._f);
14 ref =
Vector(0._f, 0._f, 1._f);
17 dir2 =
cross(axis, dir1);
23 const Vector projected = values[idx] -
dot(values[idx], axis) * axis;
24 const Float x =
dot(projected, dir1);
25 const Float y =
dot(projected - x * dir1, dir2);
32 : palette(
std::move(palette)) {
34 kernel = Factory::getKernel<3>(settings);
44 float SummedDensityColorizer::sum(
const Size idx)
const {
47 for (
const auto& n : neighs) {
48 rho += m[n.index] * kernel.
value(r[idx] - r[n.index], r[idx][
H]);
63 for (
Size i = 0; i < data.
size(); ++i) {
67 const Size size = to - from;
94 Float sig1, sig2, sig3;
96 const Float sigMax =
max(sig1, sig2, sig3);
97 const Float young_red =
max((1._f -
pow<3>(damage[i])) * young, 1.e-20_f);
98 const Float strain = sigMax / young_red;
99 ratio[i] = float(strain / eps_min[i]);
105 palette =
Palette({ { u_0,
Rgba(0.5f, 0.5f, 0.5) },
106 { u_glow,
Rgba(0.5f, 0.5f, 0.5f) },
107 { u_red,
Rgba(0.8f, 0.f, 0.f) },
108 { u_yellow,
Rgba(1.f, 1.f, 0.6f) } },
114 : detection(detection) {
144 if (isBoundary(idx)) {
151 bool BoundaryColorizer::isBoundary(
const Size idx)
const {
155 return neighbours.values[idx] < neighbours.threshold;
158 return getLength(normals.values[idx]) > normals.threshold;
166 static uint64_t getHash(
const uint64_t value,
const Size seed) {
168 constexpr
int A = 54059;
169 constexpr
int B = 76963;
170 constexpr
int FIRST = 37;
172 uint64_t hash =
FIRST + seed;
174 std::memcpy(&data[0], &value, data.size());
175 for (uint i = 0; i <
sizeof(uint64_t); ++i) {
176 hash = (hash * A) ^ (data[i] * B);
181 static Rgba getRandomizedColor(
const Size idx,
const Size seed = 0) {
182 const uint64_t hash = getHash(idx, seed);
183 const uint8_t r = (hash & 0x00000000FFFF);
184 const uint8_t g = (hash & 0x0000FFFF0000) >> 16;
185 const uint8_t b = (hash & 0xFFFF00000000) >> 32;
186 return Rgba(r / 255.f, g / 255.f, b / 255.f);
189 template <
typename TDerived>
191 const Optional<Size> id =
static_cast<const TDerived*
>(
this)->evalId(idx);
195 const Rgba color = getRandomizedColor(
id.value(), seed);
199 template <
typename TDerived>
202 const Optional<Size> id =
static_cast<const TDerived*
>(
this)->evalId(idx);
223 if (!persistentIdxs.
empty() && idx < persistentIdxs.
size()) {
234 , connectivity(connectivity)
235 , highlightIdx(highlightIdx) {}
238 if (newHighlightIdx) {
239 highlightIdx =
min(newHighlightIdx.
value(), components.
size() - 1);
247 if (highlightIdx.
value() == components[idx]) {
248 return Rgba(1.f, 0.65f, 0.f);
263 for (
Size i = 0; i < r.size(); ++i) {
264 if (components[i] ==
id.value()) {
268 if (indices.
size() > 1) {
281 if (current == cached.r) {
290 cached.r = current.
clone();
297 return "Bound component ID";
299 return "Component ID (flag)";
301 return "Component ID";
311 for (
Size matId = 0; matId < matCnt; ++matId) {
INLINE bool almostEqual(const AffineMatrix &m1, const AffineMatrix &m2, const Float eps=EPS)
ArrayRef< T > makeArrayRef(Array< T > &data, const RefEnum type)
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Object converting quantity values of particles into colors.
bool hasVelocity(const Storage &storage)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T max(const T &f1, const T &f2)
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
constexpr INLINE Float pow< 3 >(const Float v)
INLINE T log10(const T f)
INLINE T atan2(const T y, const T x)
constexpr Float PI
Mathematical constants.
#define NAMESPACE_SPH_END
const NothingType NOTHING
@ LOGARITHMIC
Control points are interpolated on logarithmic scale. All points must be positive!
@ FLAG
ID of original body, used to implement discontinuities between bodies in SPH.
@ DEVIATORIC_STRESS
Deviatoric stress tensor, always a traceless tensor.
@ PRESSURE
Pressure, affected by yielding and fragmentation model, always a scalar quantity.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ SURFACE_NORMAL
Vector approximating surface normal.
@ MASS
Paricles masses, always a scalar quantity.
@ NEIGHBOUR_CNT
Number of neighbouring particles (in radius h * kernel.radius)
@ MATERIAL_ID
Index of material of the particle. Can be generally different than the flag value.
@ EPS_MIN
Activation strait rate.
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
INLINE StaticArray< Float, 3 > findEigenvalues(const SymmetricTensor &t)
Returns three eigenvalue of symmetric matrix.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
INLINE BasicVector< float > cross(const BasicVector< float > &v1, const BasicVector< float > &v2)
Cross product between two vectors.
BasicVector< Float > Vector
INLINE float dot(const BasicVector< float > &v1, const BasicVector< float > &v2)
Make sure the vector is trivially constructible and destructible, needed for fast initialization of a...
INLINE Vector getNormalized(const Vector &v)
INLINE bool empty() const
INLINE ArrayView subset(const TCounter start, const TCounter length) const
Returns a subset of the arrayview.
void resize(const TCounter newSize)
Resizes the array to new size.
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
INLINE TCounter size() const noexcept
Array clone() const
Performs a deep copy of all elements of the array.
virtual bool isInitialized() const override
Checks if the colorizer has been initialized.
virtual Rgba evalColor(const Size idx) const override
Returns the color of idx-th particle.
virtual bool hasData(const Storage &storage) const override
Checks if the storage constains all data necessary to initialize the colorizer.
BoundaryColorizer(const Detection detection, const Float threshold=15._f)
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
virtual std::string name() const override
Returns the name of the colorizer.
void setHighlightIdx(const Optional< Size > newHighlightIdx)
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
ComponentIdColorizer(const GuiSettings &gui, const Flags< Post::ComponentFlag > connectivity, const Optional< Size > highlightIdx=NOTHING)
INLINE Optional< Size > evalId(const Size idx) const
virtual bool hasData(const Storage &storage) const override
Checks if the storage constains all data necessary to initialize the colorizer.
virtual Rgba evalColor(const Size idx) const override
Returns the color of idx-th particle.
virtual Optional< Particle > getParticle(const Size idx) const override
Returns the original value of the displayed quantity.
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
virtual bool hasData(const Storage &storage) const override
Checks if the storage constains all data necessary to initialize the colorizer.
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
virtual bool isInitialized() const override
Checks if the colorizer has been initialized.
DirectionColorizer(const Vector &axis, const Palette &palette)
virtual Optional< float > evalScalar(const Size idx) const override
static std::string toString(const TEnum value)
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
void build(IScheduler &scheduler, ArrayView< const Vector > points)
Constructs the struct with an array of vectors.
virtual Size findAll(const Size index, const Float radius, Array< NeighbourRecord > &neighbours) const =0
Finds all neighbours within given radius from the point given by index.
Material settings and functions specific for one material.
INLINE TValue getParam(const BodySettingsId paramIdx) const
Returns a parameter associated with given particle.
virtual Optional< Particle > getParticle(const Size idx) const override
Returns the original value of the displayed quantity.
virtual Rgba evalColor(const Size idx) const override
Returns the color of idx-th particle.
INLINE Optional< Size > evalId(const Size idx) const
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
INLINE IndexIterator begin() const
INLINE IndexIterator end() const
INLINE Float value(const Vector &r, const Float h) const noexcept
INLINE Float radius() const noexcept
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
virtual Optional< Particle > getParticle(const Size idx) const override
Returns the original value of the displayed quantity.
Non-owning wrapper of a material and particles with this material.
INLINE IndexSequence sequence()
Returns iterable index sequence.
INLINE Type & value()
Returns the reference to the stored value.
Represents a color palette, used for mapping arbitrary number to a color.
virtual Optional< Particle > getParticle(const Size idx) const override
Returns the original value of the displayed quantity.
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
Object holding information about single particle.
Particle & addParameter(const BodySettingsId id, const Dynamic &value)
Adds another material parameter or updates the one stored previously.
Particle & addValue(const QuantityId id, const Dynamic &value)
Adds another quantity value or updates the value of quantity previously stored.
static Rgba gray(const float value=0.5f)
Array with fixed number of allocated elements.
Container storing all quantities used within the simulations.
Size getMaterialCnt() const
Return the number of materials in the storage.
Array< TValue > & getDt(const QuantityId key)
Retrieves a quantity derivative from the storage, given its key and value type.
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
bool has(const QuantityId key) const
Checks if the storage contains quantity with given key.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
virtual void initialize(const Storage &storage, const RefEnum ref) override
Initialize the colorizer before by getting necessary quantities from storage.
SummedDensityColorizer(const RunSettings &settings, Palette palette)
Symmetric tensor of 2nd order.
static INLINE SymmetricTensor identity()
Returns an identity tensor.
Symmetric traceless 2nd order tensor.
@ YOUNG_MODULUS
Young modulus of the material.
@ EOS
Equation of state for this material, see EosEnum for options.
@ RHEOLOGY_YIELDING
Model of stress reducing used within the rheological model.
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
Vector getAngularFrequency(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Vector > v, const Vector &r0, const Vector &v0, ArrayView< const Size > idxs=nullptr)
Computes the immediate vector of angular frequency of a rigid body.
@ SEPARATE_BY_FLAG
Specifies that particles with different flag belong to different component, even if they overlap.
Size findComponents(const Storage &storage, const Float particleRadius, const Flags< ComponentFlag > flags, Array< Size > &indices)
Finds and marks connected components (a.k.a. separated bodies) in the array of vertices.
Vector getCenterOfMass(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Size > idxs=nullptr)
Computes the center of mass.
Overload of std::swap for Sph::Array.