22 return vi /
sqr(rho[i]) + vj /
sqr(rho[j]);
37 return (vi + vj) / (rho[i] * rho[j]);
41 template <
typename Discr>
54 discr.initialize(input);
61 template <
bool Symmetric>
63 const Vector f = discr.eval(i, j, p[i], p[j]) * grad;
72 switch (formulation) {
96 du[i] -= p[i] / rho[i] * divv[i];
97 SPH_ASSERT(isReal(du[i]));
103 throw InvalidSetup(
"PressureForce needs to be used with EosMaterial or derived");
113 template <
typename Discr>
127 discr.initialize(input);
134 template <
bool Symmetrize>
136 const Vector f = discr.eval(i, j, s[i], s[j]) * grad;
152 derivatives.
require(makeDerivative<VelocityGradient>(
155 if (useCorrectionTensor) {
156 derivatives.
require(makeAuto<CorrectionTensor>(settings));
161 switch (formulation) {
194 du[i] += 1._f / rho[i] * ddot(s[i], gradv[i]);
197 TracelessTensor dev(gradv[i] - SymmetricTensor::identity() * gradv[i].trace() / 3._f);
198 ds[i] += 2._f * mu * dev;
199 SPH_ASSERT(isReal(du[i]) && isReal(ds[i]));
214 if (useCorrectionTensor) {
245 du[i] += 1._f / rho[i] *
ddot(s[i], gradv[i]);
248 ds[i] += 2._f * mu * dev;
267 w0 = kernel.valueImpl(0);
277 derivatives.
require(makeDerivative<VelocityGradient>(settings, flags));
279 throw InvalidSetup(
"This mode of the continuity equation requires stress tensor.");
281 derivatives.
require(makeDerivative<VelocityDivergence>(settings));
291 if (bulk[i] < rho[i]) {
292 const Float D = pow<3>(damage[i]);
293 p[i] = (1._f - D) * p[i];
307 drho[i] += -rho[i] * divv[i];
315 if (reduce[i] > 0._f) {
316 drho[i] += -rho[i] * gradv[i].trace();
318 drho[i] += -rho[i] * divv[i];
328 if (bulk[i] >= rho[i] && divv[i] < 0._f) {
329 drho[i] += -rho[i] * divv[i];
331 drho[i] += -reduce[i] * rho[i] * divv[i];
334 dbulk[i] += -bulk[i] * divv[i];
351 for (
Size i = 0; i < r.size(); ++i) {
352 rhoLimit =
min(rhoLimit, m[i] * w0 /
pow<3>(r[i][
H]));
370 : dimensions(dimensions) {
383 derivatives.
require(makeDerivative<VelocityDivergence>(settings));
391 for (
Size i = 0; i < r.
size(); ++i) {
405 if (r[i][H] > 2._f * minimal) {
406 v[i][H] = r[i][H] / dimensions * divv[i];
415 this->enforce(i, v, cs, neighCnt);
423 INLINE void AdaptiveSmoothingLength::enforce(
const Size i,
INLINE bool isReal(const AntisymmetricTensor &t)
INLINE Float ddot(const AntisymmetricTensor &t1, const AntisymmetricTensor &t2)
Double-dot product t1 : t2 = sum_ij t1_ij t2_ij.
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
INLINE AutoPtr< T > makeAuto(TArgs &&... args)
@ 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.
Right-hand side term of SPH equations.
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.
SPH-specific implementation of particle materials.
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 T sqr(const T &f) noexcept
Return a squared value.
constexpr INLINE Float pow< 3 >(const Float v)
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
@ BULK_DENSITY
Bulk density, may be lower than the material density.
@ VELOCITY_DIVERGENCE
Velocity divergence.
@ STRAIN_RATE_CORRECTION_TENSOR
Correction tensor used to improve conservation of total angular momentum.
@ DEVIATORIC_STRESS
Deviatoric stress tensor, always a traceless tensor.
@ PRESSURE
Pressure, affected by yielding and fragmentation model, always a scalar quantity.
@ VELOCITY_GRADIENT
Velocity gradient.
@ 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.
@ NEIGHBOUR_CNT
Number of neighbouring particles (in radius h * kernel.radius)
@ SOUND_SPEED
Sound speed, always a scalar quantity.
@ STRESS_REDUCING
Total stress reduction factor due to damage and yielding. Is always scalar.
@ FIRST
Quantity with 1st derivative.
@ ZERO
Quantity without derivatives, or "zero order" of quantity.
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.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Helper template specifically used to implement forces.
AccelerationTemplate(const RunSettings &settings, const Flags< DerivativeFlag > flags=EMPTY_FLAGS)
Storage for accumulating derivatives.
AdaptiveSmoothingLength(const RunSettings &settings, const Size dimensions=DIMENSIONS)
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
Float minimal
Minimal allowed value of the smoothing length.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
struct AdaptiveSmoothingLength::@17 enforcing
INLINE TCounter size() const
Discretization of pressure term in code SPH5.
INLINE T eval(const Size i, const Size j, const T &vi, const T &vj) const
void initialize(const Storage &input)
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
ContinuityEquation(const RunSettings &settings)
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
Container holding derivatives and the storage they accumulate to.
virtual void require(AutoPtr< IDerivative > &&derivative)
Adds derivative if not already present.
Material holding equation of state.
Wrapper of an integral value providing functions for reading and modifying individual bits.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
Material settings and functions specific for one material.
INLINE TValue getParam(const BodySettingsId paramIdx) const
Returns a parameter associated with given particle.
void setRange(const QuantityId id, const Interval &range, const Float minimal)
Sets the timestepping parameters of given quantity.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float upper() const
Returns upper bound of the interval.
static Interval unbounded()
Returns an unbounded (infinite) interval.
Thrown when components of the run are mutually incompatible.
Non-owning wrapper of a material and particles with this material.
INLINE IndexSequence sequence()
Returns iterable index sequence.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
INLINE Tuple< Vector, Float > eval(const Size i, const Size j, const Vector &grad)
INLINE void additionalCreate(Accumulated &UNUSED(results))
INLINE bool additionalEquals(const PressureGradient &UNUSED(other)) const
INLINE void additionalInitialize(const Storage &input, Accumulated &UNUSED(results))
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.
Flags< TValue > getFlags(const TEnum idx) const
Returns Flags from underlying value stored in settings.
virtual void setDerivatives(DerivativeHolder &derivatives, const RunSettings &settings) override
Sets derivatives required by this term.
virtual void initialize(IScheduler &scheduler, Storage &storage, const Float t) override
Initialize all the derivatives and/or quantity values before derivatives are computed.
virtual void create(Storage &storage, IMaterial &material) const override
Creates all quantities needed by the term using given material.
SolidStressForce(const RunSettings &settings)
virtual void finalize(IScheduler &scheduler, Storage &storage, const Float t) override
Computes all the derivatives and/or quantity values based on accumulated derivatives.
Discretization of pressure term in standard SPH formulation.
void initialize(const Storage &input)
INLINE T eval(const Size i, const Size j, const T &vi, const T &vj) const
Container storing all quantities used within the simulations.
Size getMaterialCnt() const
Return the number of materials in the storage.
Quantity & insert(const QuantityId key, const OrderEnum order, const TValue &defaultValue)
Creates a quantity in the storage, given its key, value type and order.
StaticArray< Array< TValue > &, 3 > getAll(const QuantityId key)
Retrieves quantity buffers from the storage, given its key and value type.
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.
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.
INLINE void additionalCreate(Accumulated &UNUSED(results))
INLINE Tuple< Vector, Float > eval(const Size i, const Size j, const Vector &grad)
StressDivergence(const RunSettings &settings)
INLINE void additionalInitialize(const Storage &input, Accumulated &UNUSED(results))
INLINE bool additionalEquals(const StressDivergence &UNUSED(other)) const
Symmetric tensor of 2nd order.
static INLINE SymmetricTensor identity()
Returns an identity tensor.
static INLINE SymmetricTensor null()
Returns a tensor with all zeros.
Symmetric traceless 2nd order tensor.
Heterogeneous container capable of storing a fixed number of values.
Creating code components based on values from settings.
@ NONE
Gass or material with no stress tensor.
@ STANDARD
P_i / rho_i^2 + P_j / rho_j^2.
@ BENZ_ASPHAUG
(P_i + P_j) / (rho_i rho_j)
@ DAMAGED_DECREASE_BULK_DENSITY
@ STANDARD
Normal continuity equation, using velocity divergence computed from all neighbors.
@ STRESS_TENSOR
Initial values of the deviatoric stress tensor.
@ ENERGY_MIN
Estimated minimal value of energy used to determine timestepping error.
@ DENSITY_RANGE
Allowed range of density. Densities of all particles all clamped to fit in the range.
@ ENERGY
Initial specific internal energy.
@ SHEAR_MODULUS
Shear modulus mu (a.k.a Lame's second parameter) of the material.
@ DENSITY
Density at zero pressure.
@ STRESS_TENSOR_MIN
Estimated minial value of stress tensor components used to determined timestepping error.
@ ENERGY_RANGE
Allowed range of specific internal energy.
@ RHEOLOGY_YIELDING
Model of stress reducing used within the rheological model.
@ SPH_STRAIN_RATE_CORRECTION_TENSOR
@ SPH_CONTINUITY_MODE
Specifies how the density is evolved, see ContinuityEnum.
@ SPH_NEIGHBOUR_ENFORCING
@ SPH_SOLVER_FORCES
List of forces to compute by the solver.
@ SPH_ADAPTIVE_SMOOTHING_LENGTH
Solution for evolutions of the smoothing length.
@ SPH_SMOOTHING_LENGTH_MIN
Minimal value of smoothing length.
@ SPH_DISCRETIZATION
Specifies a discretization of SPH equations; see DiscretizationEnum.