15 stream <<
"CFL condition";
18 stream <<
"Acceleration";
21 stream <<
"Derivative";
24 stream <<
"Divergence";
27 stream <<
"Maximal value";
30 stream <<
"Default value";
33 stream <<
"Max. change limit";
132 if (power < -1.e3_f) {
134 return this->computeImpl<MinimalStepTls>(scheduler, storage, maxStep, stats);
137 return this->computeImpl<MeanStepTls>(scheduler, storage, maxStep, stats);
141 template <
template <
typename>
class Tls>
150 iterate<VisitorEnum::FIRST_ORDER>(storage, [&](
const QuantityId id,
auto& v,
auto& dv) {
152 using T =
typename std::decay_t<decltype(v)>::Type;
155 Tls<T> result(power);
158 auto functor = [&](
const Size i, Tls<T>& tls) {
159 const auto absdv =
abs(dv[i]);
160 const auto absv =
abs(v[i]);
168 for (
Size j = 0; j < vs.
size(); ++j) {
169 if (
abs(vs[j]) < 2._f * minValue) {
172 const Float value = factor * (vs[j] + minValue) / (dvs[j] +
EPS);
174 tls.add(value, v[i], dv[i], i);
180 for (Tls<T>& tl : tls) {
186 if (minStep && minStep.
value() < totalMinStep) {
187 totalMinStep = minStep.
value();
190 result.saveStats(stats);
204 if (totalMinStep > maxStep) {
205 totalMinStep = maxStep;
208 return { totalMinStep, minId };
230 auto functor = [&](
const Size i, Tl& tl) {
235 tl.minStep =
min(tl.minStep, step);
242 result.minStep =
min(result.minStep, tl.minStep);
245 if (result.minStep > maxStep) {
273 auto functor = [&](
const Size i, Tl& tl) {
276 const Float step = factor / dv;
278 tl.minStep =
min(tl.minStep, step);
285 result.minStep =
min(result.minStep, tl.minStep);
288 if (result.minStep > maxStep) {
321 auto functor = [&](
const Size i, Tl& tl) {
323 const Float value = courant * r[i][
H] / cs[i];
325 tl.minStep =
min(tl.minStep, value);
332 result.minStep =
min(result.minStep, tl.minStep);
335 if (result.minStep > maxStep) {
350 criteria.
push(makeAuto<CourantCriterion>(settings));
353 criteria.
push(makeAuto<DerivativeCriterion>(settings));
356 criteria.
push(makeAuto<AccelerationCriterion>(settings));
359 criteria.
push(makeAuto<DivergenceCriterion>(settings));
367 const Float maxChange,
369 : criteria(
std::move(criteria))
370 , maxChange(maxChange)
371 , lastStep(initial) {}
381 for (
auto& crit : criteria) {
382 const TimeStep step = crit->compute(scheduler, storage, maxStep, stats);
383 if (step.
value < minStep) {
384 minStep = step.
value;
390 if (maxChange <
INFTY) {
391 const Float maxStep = lastStep * (1._f + maxChange);
392 if (minStep > maxStep) {
401 return { minStep, minId };
INLINE bool isReal(const AntisymmetricTensor &t)
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
INLINE StaticArray< Float, 6 > getComponents(const T &value)
Returns the components of the object in array.
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.
Base class for all particle materials.
Functions for iterating over individual quantities in Storage.
Logging routines of the run.
#define VERBOSE_LOG
Helper macro, creating.
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
INLINE Float root< 4 >(const Float f)
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE auto abs(const T &f)
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
const NothingType NOTHING
Tool to measure time spent in functions and profile the code.
QuantityId
Unique IDs of basic quantities of SPH particles.
@ VELOCITY_DIVERGENCE
Velocity divergence.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ NEIGHBOUR_CNT
Number of neighbouring particles (in radius h * kernel.radius)
@ SOUND_SPEED
Sound speed, always a scalar quantity.
@ SECOND
Quantity with 1st and 2nd derivative.
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.
Statistics gathered and periodically displayed during the run.
@ LIMITING_PARTICLE_IDX
Index of particle that currently limits the timestep.
@ LIMITING_VALUE
Quantity value of particle that currently limits the timestep.
@ LIMITING_QUANTITY
Quantity that currently limits the timestep.
@ LIMITING_DERIVATIVE
Derivative value of particle that currently limits the timestep.
Template for thread-local storage.
NAMESPACE_SPH_BEGIN std::ostream & operator<<(std::ostream &stream, const CriterionId id)
Criteria for computing the time step.
@ MAX_CHANGE
Timestep is limited by the maximum allowed change from previous timestep.
@ DIVERGENCE
Timestep computed by velocity divergence.
@ INITIAL_VALUE
Timestep is not computed, using given initial value.
@ MAXIMAL_VALUE
Timestep given by selected maximal value.
@ CFL_CONDITION
Timestep computed using CFL condition.
@ ACCELERATION
Timestep constrained by acceleration condition.
@ DERIVATIVE
Timestep based on value-to-derivative ratio.
INLINE Float getSqrLength(const Vector &v)
AccelerationCriterion(const RunSettings &settings)
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Computes the value of the time step.
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
Generic dynamically allocated resizable storage.
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
INLINE bool empty() const noexcept
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Storage must contain at least positions of particles and sound speed, checked by assert.
CourantCriterion(const RunSettings &settings)
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Computes the value of the time step.
DerivativeCriterion(const RunSettings &settings)
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Computes the value of the time step.
DivergenceCriterion(const RunSettings &settings)
Convenient object for storing a single value of different types.
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.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, const Float maxStep, Statistics &stats) override
Computes the value of the time step.
MultiCriterion(const RunSettings &settings)
Generalized mean with negative (runtime) power.
INLINE void accumulate(const Float value)
INLINE Float compute() const
INLINE Type & value()
Returns the reference to the stored value.
INLINE Size count() const
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.
Array with fixed number of allocated elements.
INLINE TCounter size() const
Returns the current size of the array (number of constructed elements).
Object holding various statistics about current run.
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Container storing all quantities used within the simulations.
MaterialView getMaterialOfParticle(const Size particleIdx) const
Returns material view for material of given particle.
StaticArray< Array< TValue > &, 3 > getAll(const QuantityId key)
Retrieves quantity buffers from the storage, given its key and value type.
StorageSequence getQuantities()
Returns the sequence of quantities.
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.
Template for storing a copy of a value for every thread in given scheduler.
Generic storage and input/output routines of settings.
@ DIVERGENCE
Time step computed from velocity divergence.
@ DERIVATIVES
Time step computed by limiting value-to-derivative ratio of quantiites.
@ COURANT
Time step determined using CFL condition.
@ ACCELERATION
Time step computed from ratio of acceleration and smoothing length.
@ TIMESTEPPING_MEAN_POWER
@ TIMESTEPPING_INITIAL_TIMESTEP
@ TIMESTEPPING_DERIVATIVE_FACTOR
Multiplicative factor k for the derivative criterion; dt = k * v / dv.
@ TIMESTEPPING_MAX_INCREASE
@ TIMESTEPPING_COURANT_NUMBER
Courant number.
@ TIMESTEPPING_DIVERGENCE_FACTOR
Multiplicative factor for the divergence criterion.
Overload of std::swap for Sph::Array.
INLINE void add(const Float step, const T UNUSED(v), const T UNUSED(dv), const Float UNUSED(idx))
INLINE void add(const MeanStepTls &other)
MeanStepTls(const Float power)
INLINE Optional< Float > getStep() const
INLINE void saveStats(Statistics &UNUSED(stats)) const
Helper class storing a minimal value of time step and corresponding statistics.
INLINE void add(const Float step, const T v, const T dv, const Size idx)
Add a time step to the set, given also value, derivative and particle index.
INLINE Optional< Float > getStep() const
Return the computed time step.
MinimalStepTls(const Float UNUSED(power))
INLINE void add(const MinimalStepTls &other)
Add a time step computed by other TLS.
INLINE void saveStats(Statistics &stats) const
Save auxiliary statistics.
INLINE Size isDefined() const
Float value
Value of the time step in code units (currently SI).
CriterionId id
Criterion applied to compute the time step;.