16 template <
typename TDerived>
24 for (
Size i = 0; i < r.size(); ++i) {
26 particlePoints.
push(p);
35 points = std::move(particlePoints);
38 points.resize(binCnt.value());
43 const Float lastX = particlePoints[particlePoints.
size() - 1].x;
45 const Size bin =
min(
Size(p.x * (binCnt.value() - 1) / lastX), binCnt.value() - 1);
50 for (
Size i = 0; i < points.size(); ++i) {
52 points[i].x /= weights[i];
53 points[i].y /= weights[i];
61 template <
typename TDerived>
67 template <
typename TDerived>
69 for (
Size i = 0; i < points.size(); ++i) {
71 dc.
drawLine(points[i], points[i - 1]);
88 if (t - lastTime < actPeriod) {
99 for (
Size i = 0; i < points.
size(); i += 2) {
102 points = std::move(newPoints);
108 bool needUpdateRange =
false;
109 while (!points.
empty() && this->isExpired(points.
front().
x, t)) {
111 needUpdateRange =
true;
115 if (needUpdateRange && params.
shrinkY) {
121 }
else if (!points.
empty()) {
132 if (points.
empty()) {
146 actPeriod = params.
period;
150 if (points.
empty()) {
161 bool TemporalPlot::isExpired(
const Float x,
const Float t)
const {
223 if (time - lastTime < period) {
230 for (
Size i = 0; i < v.
size(); ++i) {
231 angles[i] =
atan2(v[i][
Y], v[i][
X]);
264 if (points.
size() <= 1) {
267 for (
Size i = 0; i < points.
size() - 1; ++i) {
268 dc.
drawLine(points[i], points[i + 1]);
280 connect = connectivity;
287 name =
"Particle SFD";
296 if (time - lastTime < period) {
334 for (
Size i = 0; i < sfd.
size() - 1; ++i) {
336 path->addPoint(sfd[i]);
339 path->addPoint(sfd.
back());
350 const std::string& name)
380 if (!values.
empty()) {
382 for (
Size i = 0; i < values.
size() - 1; ++i) {
384 path->addPoint(values[i]);
387 path->addPoint(values.
back());
398 for (
auto&
plot : plots) {
399 plot->onTimeStep(storage, stats);
407 for (
auto&
plot : plots) {
415 plotAndIndex.value()->plot(dc);
426 auto getTicsInterval = [interval](
const Float step) {
432 step =
pow(10._f, order);
433 SPH_ASSERT(step >= std::numeric_limits<Float>::denorm_min());
434 if (getTicsInterval(step).size() < step * minCount) {
443 if (getTicsInterval(5 * step).size() >= 5 * step * minCount) {
445 }
else if (getTicsInterval(2 * step).size() >= 2 * step * minCount) {
448 const Interval ticsInterval = getTicsInterval(step);
451 for (
Float x = ticsInterval.
lower(); x <= ticsInterval.
upper() +
EPS * step; x += step) {
464 std::set<Float> tics;
466 for (
Float order = fromOrder; order <= toOrder; order++) {
467 const Float value =
pow(10._f, order);
473 if (tics.size() < minCount) {
475 for (
Float order = fromOrder; order <= toOrder; order++) {
476 const Float value =
pow(10._f, order);
477 if (interval.
contains(2._f * value)) {
478 tics.insert(2._f * value);
480 if (interval.
contains(5._f * value)) {
481 tics.insert(5._f * value);
488 SPH_ASSERT(tics.size() >= minCount && tics.size() < 20);
491 for (
Float t : tics) {
INLINE bool isReal(const AntisymmetricTensor &t)
#define SPH_ASSERT(x,...)
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.
IndexAdapter< TContainer > iterateWithIndex(TContainer &&container)
Logging routines of the run.
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.
INLINE auto floor(const T &f)
constexpr INLINE Float pow(const Float v)
Power for floats.
INLINE T log10(const T f)
INLINE T atan2(const T y, const T x)
INLINE auto ceil(const T &f)
constexpr Float PI
Mathematical constants.
#define NAMESPACE_SPH_END
Array< Float > getLinearTics(const Interval &interval, const Size minCount)
Returns the tics to be drawn on a linear axis of a plot.
Array< Float > getLogTics(const Interval &interval, const Size minCount)
Returns the tics to be drawn on a logarithmic axis of a plot.
Drawing quantity values as functions of time or spatial coordinates.
QuantityId
Unique IDs of basic quantities of SPH particles.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
Statistics gathered and periodically displayed during the run.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
Container for storing particle quantities and materials.
virtual void onTimeStep(const Storage &storage, const Statistics &stats) override
Updates the plot with new data.
AngularHistogramPlot(const Float period)
virtual void clear() override
Clears all cached data, prepares for next run.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
INLINE TCounter size() const
void reserve(const TCounter newMaxSize)
Allocates enough memory to store the given number of elements.
INLINE Iterator< StorageType > end() noexcept
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
StorageType & emplaceBack(TArgs &&... args)
Constructs a new element at the end of the array in place, using the provided arguments.
void fill(const T &t)
Sets all elements of the array to given value.
INLINE T & back() noexcept
void clear()
Removes all elements from the array, but does NOT release the memory.
INLINE TCounter size() const noexcept
INLINE T & front() noexcept
INLINE bool empty() const noexcept
INLINE Iterator< StorageType > begin() noexcept
Wrapper of pointer that deletes the resource from destructor.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
virtual void onTimeStep(const Storage &storage, const Statistics &stats) override
Updates the plot with new data.
virtual std::string getCaption() const override
Returns the caption of the plot.
DataPlot(const Array< Post::HistPoint > &points, const Flags< AxisScaleEnum > scale, const std::string &name)
virtual void clear() override
Clears all cached data, prepares for next run.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
Float period
Period of redrawing the histogram. Zero means the histogram is drawn every time step.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
virtual void clear() override
Clears all cached data, prepares for next run.
Optional< Interval > interval
Array< Post::HistPoint > points
Points representing the histogram.
virtual void onTimeStep(const Storage &storage, const Statistics &stats) override
Updates the plot with new data.
Abstraction of a drawing context.
virtual void drawLine(const PlotPoint &from, const PlotPoint &to)=0
Draws a line connecting two points.
virtual AutoPtr< IDrawPath > drawPath()=0
Draws a path connecting points.
virtual void setStyle(const Size index)=0
Changes the current drawing style.
virtual void drawPoint(const PlotPoint &point)=0
Adds a single point to the plot.
virtual Float evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
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.
INLINE Float size() const
Returns the size of the interval.
INLINE bool contains(const Float &value) const
Checks whether value is inside the interval.
INLINE bool empty() const
Returns true if the interval is empty (default constructed).
virtual void clear() override
Clears all cached data, prepares for next run.
virtual void onTimeStep(const Storage &storage, const Statistics &stats) override
Updates the plot with new data.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
INLINE Type & value()
Returns the reference to the stored value.
INLINE bool empty() const
Returns true if the queue contains no elements.
INLINE T & back()
Returns a reference to the last element in the queue.
INLINE Size size() const
Returns the number of elements in the queue.
void clear()
Removes all elements from the queue.
INLINE T & front()
Returns a reference to the first element in the queue.
T popFront()
Removes an element from the front of the queue.
void pushBack(const T &value)
Adds a new element to the back of the queue.
Plots a dependence of given quantity on the distance from the origin.
RadialDistributionPlot(const QuantityId id, const Optional< Size > binCnt=NOTHING)
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.
bool has(const TEnum idx) const
Checks if the given entry is stored in the settings.
virtual void clear() override
Clears all cached data, prepares for next run.
virtual std::string getCaption() const override
Returns the caption of the plot.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
virtual void onTimeStep(const Storage &storage, const Statistics &stats) override
Updates the plot with new data.
SfdPlot(const Flags< Post::ComponentFlag > connectivity, const Float period)
Plots SFD of components, given their connectivity.
Base class for plots showing a dependence of given quantity on a spatial coordinate.
virtual void clear() override
Clears all cached data, prepares for next run.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
virtual void onTimeStep(const Storage &storage, const Statistics &UNUSED(stats)) override
Object holding various statistics about current run.
TValue get(const StatisticsId idx) const
Returns value of a statistic.
Container storing all quantities used within the simulations.
Size getMaterialCnt() const
Return the number of materials in the storage.
Array< TValue > & getDt(const QuantityId key)
Retrieves a quantity derivative from the storage, given its key and value type.
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
virtual void plot(IDrawingContext &dc) const override
Draws the plot into the drawing context.
virtual void clear() override
Clears all cached data, prepares for next run.
virtual void onTimeStep(const Storage &storage, const Statistics &stats) override
Updates the plot with new data.
2D point and other primitives for 2D geometry
@ DENSITY
Density at zero pressure.
Array< HistPoint > getDifferentialHistogram(ArrayView< const Float > values, const HistogramParams ¶ms)
Computes the differential histogram from given values.
@ COMPONENTS
Equivalent radii of connected chunks of particles (SPH framework)
@ PARTICLES
Radii of individual particles, considering particles as spheres (N-body framework)
Array< HistPoint > getCumulativeHistogram(const Storage &storage, const ExtHistogramId id, const HistogramSource source, const HistogramParams ¶ms)
Computes cumulative (integral) histogram of particles in the storage.
Flags< Post::ComponentFlag > flags
Determines how the particles are clustered into the components.
Parameters of the histogram.
Float velocityCutoff
Cutoff value (upper bound) of particle velocity for inclusion in the histogram.
Float referenceDensity
Reference density, used when computing particle radii from their masses.
Interval range
Range of values from which the histogram is constructed.
struct Post::HistogramParams::ComponentParams components
Size binCnt
Number of histogram bins.
Float segment
Plotted time segment.
Interval fixedRangeX
Fixed x-range for the plot. If empty, a dynamic range is used.
Float minRangeY
Minimal size of the y-range.
Float period
Time that needs to pass before a new point is added.
bool shrinkY
When discarting points out of plotted range, shrink y-axis to fit currently visible points.