SPH
Yorp.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "post/Analysis.h"
5 
7 
8 class YorpSpinup : public IEquationTerm {
9 private:
10  Float rate;
11 
12  Size stepCounter = 0;
13  static constexpr Size recomputationPeriod = 20;
14 
15  Array<Size> idxs;
16 
17 
18 public:
19  explicit YorpSpinup(const Float rate)
20  : rate(rate) {}
21 
22  virtual void setDerivatives(DerivativeHolder& UNUSED(derivatives),
23  const RunSettings& UNUSED(settings)) override {}
24 
25  virtual void initialize(IScheduler& UNUSED(scheduler), Storage& UNUSED(storage)) override {}
26 
27  virtual void finalize(IScheduler& UNUSED(scheduler), Storage& storage) override {
28  if (idxs.empty() || (stepCounter % recomputationPeriod == 0)) {
30  }
31  stepCounter++;
32 
33  ArrayView<Vector> r, v, dv;
34  tie(r, v, dv) = storage.getAll<Vector>(QuantityId::POSITION);
36  Vector omega = Post::getAngularFrequency(m, r, v, idxs);
37  if (getSqrLength(omega) < 1.e-6_f) {
38  omega = Vector(0._f, 0._f, 1._f);
39  }
40  const Vector dw = getNormalized(omega) * rate;
41 
42  for (Size i = 0; i < r.size(); ++i) {
43  dv[i] += cross(dw, r[i]);
44  }
45  }
46 
47  virtual void create(Storage& UNUSED(storage), IMaterial& UNUSED(material)) const override {}
48 };
49 
Various function for interpretation of the results of a simulation.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Right-hand side term of SPH equations.
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 UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ MASS
Paricles masses, always a scalar quantity.
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
INLINE Float getSqrLength(const Vector &v)
Definition: Vector.h:574
INLINE BasicVector< float > cross(const BasicVector< float > &v1, const BasicVector< float > &v2)
Cross product between two vectors.
Definition: Vector.h:559
BasicVector< Float > Vector
Definition: Vector.h:539
INLINE Vector getNormalized(const Vector &v)
Definition: Vector.h:590
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const
Definition: ArrayView.h:101
INLINE bool empty() const noexcept
Definition: Array.h:201
Container holding derivatives and the storage they accumulate to.
Definition: Derivative.h:173
Represents a term or terms appearing in evolutionary equations.
Definition: EquationTerm.h:22
Material settings and functions specific for one material.
Definition: IMaterial.h:110
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Container storing all quantities used within the simulations.
Definition: Storage.h:230
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 > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
Definition: Yorp.h:8
virtual void setDerivatives(DerivativeHolder &UNUSED(derivatives), const RunSettings &UNUSED(settings)) override
Definition: Yorp.h:22
virtual void finalize(IScheduler &UNUSED(scheduler), Storage &storage) override
Definition: Yorp.h:27
virtual void create(Storage &UNUSED(storage), IMaterial &UNUSED(material)) const override
Definition: Yorp.h:47
YorpSpinup(const Float rate)
Definition: Yorp.h:19
virtual void initialize(IScheduler &UNUSED(scheduler), Storage &UNUSED(storage)) override
Definition: Yorp.h:25
Array< Size > findLargestComponent(const Storage &storage, const Float particleRadius, const Flags< ComponentFlag > flags)
Returns the indices of particles belonging to the largest remnant.
Definition: Analysis.cpp:216
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.
Definition: Analysis.cpp:514
@ OVERLAP
Specifies that overlapping particles belong into the same component.