SPH
TimeStepCriterion.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "common/ForwardDecl.h"
11 #include "quantities/QuantityIds.h"
12 
14 
15 class IScheduler;
16 
17 enum class CriterionId {
20  DERIVATIVE,
22  ACCELERATION,
23  DIVERGENCE,
24  MAX_CHANGE,
25 };
26 
27 std::ostream& operator<<(std::ostream& stream, const CriterionId id);
28 
29 struct TimeStep {
32 
35 };
36 
39 public:
47  virtual TimeStep compute(IScheduler& scheduler, Storage& storage, Float maxStep, Statistics& stats) = 0;
48 };
49 
80 private:
82  Float factor;
83 
86  Float power;
87 
88 public:
89  explicit DerivativeCriterion(const RunSettings& settings);
90 
91  virtual TimeStep compute(IScheduler& scheduler,
92  Storage& storage,
93  Float maxStep,
94  Statistics& stats) override;
95 
96 private:
97  template <template <typename> class Tls>
98  TimeStep computeImpl(IScheduler& scheduler, Storage& storage, Float maxStep, Statistics& stats);
99 };
100 
106 private:
107  Float factor;
108 
109 public:
110  explicit AccelerationCriterion(const RunSettings& settings);
111 
112  virtual TimeStep compute(IScheduler& scheduler,
113  Storage& storage,
114  Float maxStep,
115  Statistics& stats) override;
116 };
117 
122 private:
123  Float factor;
124 
125 public:
126  explicit DivergenceCriterion(const RunSettings& settings);
127 
128  virtual TimeStep compute(IScheduler& scheduler,
129  Storage& storage,
130  Float maxStep,
131  Statistics& stats) override;
132 };
133 
140 private:
141  Float courant;
142 
143 public:
144  explicit CourantCriterion(const RunSettings& settings);
145 
147  virtual TimeStep compute(IScheduler& scheduler,
148  Storage& storage,
149  Float maxStep,
150  Statistics& stats) override;
151 };
152 
153 
160 private:
162 
165  Float maxChange;
166  Float lastStep;
167 
168 public:
169  explicit MultiCriterion(const RunSettings& settings);
170 
171  MultiCriterion(Array<AutoPtr<ITimeStepCriterion>>&& criteria, const Float maxChange, const Float initial);
172 
173  virtual TimeStep compute(IScheduler& scheduler,
174  Storage& storage,
175  const Float maxStep,
176  Statistics& stats) override;
177 };
178 
Generic dynamically allocated resizable storage.
Simplified implementation of std::unique_ptr, using only default deleter.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
#define NAMESPACE_SPH_END
Definition: Object.h:12
Quantity identifiers.
std::ostream & operator<<(std::ostream &stream, const CriterionId id)
CriterionId
@ MAX_CHANGE
Timestep is limited by the maximum allowed change from previous timestep.
@ 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.
@ DERIVATIVE
Timestep based on value-to-derivative ratio.
Criterion setting time step based on computed acceleration of particles.
AccelerationCriterion(const RunSettings &settings)
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Computes the value of the time step.
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Time step based on CFL criterion.
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)
Criterion setting time step based on value-to-derivative ratio for time-dependent quantities.
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Computes the value of the time step.
DerivativeCriterion(const RunSettings &settings)
Criterion computing time step from velocity divergence.
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats) override
Computes the value of the time step.
DivergenceCriterion(const RunSettings &settings)
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Base class for timestep setters.
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, Float maxStep, Statistics &stats)=0
Computes the value of the time step.
Helper criterion, wrapping multiple criteria under ITimeStepCriterion interface.
virtual TimeStep compute(IScheduler &scheduler, Storage &storage, const Float maxStep, Statistics &stats) override
Computes the value of the time step.
MultiCriterion(const RunSettings &settings)
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
@ DIVERGENCE
Time step computed from velocity divergence.
@ ACCELERATION
Time step computed from ratio of acceleration and smoothing length.
Base class for all polymorphic objects.
Definition: Object.h:88
Float value
Value of the time step in code units (currently SI).
CriterionId id
Criterion applied to compute the time step;.