39 template <
typename TDerived>
52 if (!useCorrectionTensor) {
57 if (!sumOnlyUndamaged) {
64 derived()->additionalCreate(results);
82 derived()->additionalInitialize(input, results);
86 if (
typeid(*
this) !=
typeid(other)) {
89 const TDerived* actOther = assert_cast<const TDerived*>(&other);
90 return (flags == actOther->flags) && derived()->additionalEquals(*actOther);
100 derived()->template eval<false>(i, j, C[i] * grad);
104 derived()->template eval<false>(i, j, grad);
115 derived()->template eval<true>(i, j, grad);
120 template <
typename TFunctor>
124 const TFunctor& functor) {
126 for (
Size k = 0; k < neighs.
size(); ++k) {
127 const Size j = neighs[k];
128 if (idxs[i] != idxs[j] || reduce[i] == 0._f || reduce[j] == 0._f) {
131 functor(i, j, grads[k]);
134 for (
Size k = 0; k < neighs.
size(); ++k) {
135 const Size j = neighs[k];
136 functor(i, j, grads[k]);
141 TDerived* derived() {
142 return static_cast<TDerived*
>(
this);
145 const TDerived* derived()
const {
146 return static_cast<const TDerived*
>(
this);
158 template <
typename TDerived>
166 bool sumOnlyUndamaged;
182 derived()->additionalCreate(results);
198 derived()->additionalInitialize(input, results);
202 if (
typeid(*
this) !=
typeid(other)) {
205 const TDerived* actOther = assert_cast<const TDerived*>(&other);
206 return (sumOnlyUndamaged == actOther->sumOnlyUndamaged) && derived()->additionalEquals(*actOther);
216 tieToTuple(f, de) = derived()->template eval<false>(i, j, grad);
229 tieToTuple(f, de) = derived()->template eval<true>(i, j, grad);
250 template <
typename TFunctor>
254 const TFunctor& functor) {
256 for (
Size k = 0; k < neighs.
size(); ++k) {
257 const Size j = neighs[k];
258 if (idxs[i] != idxs[j] || reduce[i] == 0._f || reduce[j] == 0._f) {
261 functor(k, i, j, grads[k]);
264 for (
Size k = 0; k < neighs.
size(); ++k) {
265 const Size j = neighs[k];
266 functor(k, i, j, grads[k]);
271 INLINE TDerived* derived() {
272 return static_cast<TDerived*
>(
this);
275 INLINE const TDerived* derived()
const {
276 return static_cast<const TDerived*
>(
this);
293 template <
typename T>
295 return m[j] / rho[i] * value;
312 template <
typename T>
314 return m[j] / rho[j] * value;
319 template <QuantityId Id,
typename Discr,
typename Traits>
340 discr.initialize(input);
348 template <
bool Symmetrize>
350 const typename Traits::Type dv = Traits::eval(v[j] - v[i], grad);
351 deriv[i] += discr.eval(i, j, dv);
353 deriv[j] += discr.eval(j, i, dv);
371 return cross(grad, v);
384 template <
typename Discr>
387 template <
typename Discr>
390 template <
typename Discr>
398 template <
template <
class>
class TVelocityDerivative>
402 switch (formulation) {
404 return makeAuto<TVelocityDerivative<CenterDensityDiscr>>(settings, flags);
406 return makeAuto<TVelocityDerivative<NeighbourDensityDiscr>>(settings, flags);
@ SHARED
Multiple derivatives may accumulate into the buffer.
@ UNIQUE
Only a single derivative accumulates to this buffer.
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
AutoPtr< IDerivative > makeDerivative(const RunSettings &settings, Flags< DerivativeFlag > flags=EMPTY_FLAGS)
Creates a given velocity derivative, using discretization given by selected SPH formulation.
@ SUM_ONLY_UNDAMAGED
Only undamaged particles (particles with damage > 0) from the same body (body with the same flag) wil...
@ CORRECTED
Use correction tensor on kernel gradient when evaluating the derivative.
Spatial derivatives to be computed by SPH discretization.
const EmptyFlags EMPTY_FLAGS
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.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
@ FLAG
ID of original body, used to implement discontinuities between bodies in SPH.
@ STRAIN_RATE_CORRECTION_TENSOR
Correction tensor used to improve conservation of total angular momentum.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ DENSITY
Density, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
@ STRESS_REDUCING
Total stress reduction factor due to damage and yielding. Is always scalar.
Holder of quantity values and their temporal derivatives.
@ SECOND
Quantity with 1st and 2nd derivative.
@ FIRST
Quantity with 1st derivative.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
INLINE SymmetricTensor symmetricOuter(const Vector &v1, const Vector &v2)
SYMMETRIZED outer product of two vectors.
INLINE Tuple< TArgs &... > tieToTuple(TArgs &... args)
Creates a tuple of l-value references. Use IGNORE placeholder to omit one or more parameters.
const struct Ignore IGNORE
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...
Helper template specifically used to implement forces.
virtual bool equals(const IDerivative &other) const override final
Returns true if this derivative is equal to the given derivative.
virtual void evalAcceleration(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads, ArrayView< Vector > dv) override
Computes the pair-wise accelerations of given particle and its neighbours.
virtual void initialize(const Storage &input, Accumulated &results) override final
Initialize derivative before iterating over neighbours.
virtual void evalNeighs(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
Compute derivatives of given particle.
virtual void evalSymmetric(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
Compute a part of derivatives from interaction of particle pairs.
virtual void create(Accumulated &results) override final
Emplace all needed buffers into shared storage.
AccelerationTemplate(const RunSettings &settings, const Flags< DerivativeFlag > flags=EMPTY_FLAGS)
Storage for accumulating derivatives.
Array< TValue > & getBuffer(const QuantityId id, const OrderEnum order)
Returns the buffer of given quantity and given order.
void insert(const QuantityId id, const OrderEnum order, const BufferSource source)
Creates a new storage with given ID.
INLINE TCounter size() const
Wrapper of pointer that deletes the resource from destructor.
Discretization using the density of the center particle.
INLINE T eval(const Size i, const Size j, const T &value)
void initialize(const Storage &input)
Helper template for derivatives that define both the symmetrized and asymmetric variant.
virtual void create(Accumulated &results) override final
Emplace all needed buffers into shared storage.
virtual bool equals(const IDerivative &other) const override final
Returns true if this derivative is equal to the given derivative.
virtual void evalNeighs(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
Compute derivatives of given particle.
DerivativeTemplate(const RunSettings &settings, const Flags< DerivativeFlag > flags=EMPTY_FLAGS)
virtual void evalSymmetric(const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
Compute a part of derivatives from interaction of particle pairs.
virtual void initialize(const Storage &input, Accumulated &results) override final
Initialize derivative before iterating over neighbours.
INLINE void unset(const TEnum flag)
Removed a single flag.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
Extension of derivative allowing to compute pair-wise acceleration for each neighbour.
Derivative accumulated by summing up neighbouring particles.
Extension of derivative, allowing a symmetrized evaluation.
Discretization using the densities of summed particles.
void initialize(const Storage &input)
INLINE T eval(const Size UNUSED(i), const Size j, const T &value)
TValue get(const TEnum idx, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0) const
Returns a value of given type from the settings.
Container storing all quantities used within the simulations.
Array< TValue > & getDt(const QuantityId key)
Retrieves a quantity derivative from the storage, given its key and value type.
auto getValues(const QuantityId first, const QuantityId second, const TArgs... others)
Retrieves an array of quantities from the key.
Symmetric tensor of 2nd order.
static INLINE SymmetricTensor null()
Returns a tensor with all zeros.
INLINE void additionalCreate(Accumulated &results)
INLINE void eval(const Size i, const Size j, const Vector &grad)
INLINE void additionalInitialize(const Storage &input, Accumulated &results)
INLINE bool additionalEquals(const VelocityTemplate &UNUSED(other)) const
@ STANDARD
P_i / rho_i^2 + P_j / rho_j^2.
@ BENZ_ASPHAUG
(P_i + P_j) / (rho_i rho_j)
@ SPH_STRAIN_RATE_CORRECTION_TENSOR
@ SPH_DISCRETIZATION
Specifies a discretization of SPH equations; see DiscretizationEnum.
static INLINE Float eval(const Vector &v, const Vector &grad)
static INLINE SymmetricTensor eval(const Vector &v, const Vector &grad)
static INLINE Vector eval(const Vector &v, const Vector &grad)