include/terraingen/distribution/tabulated.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief Size-frequency distributions given as tables, interpolated in log-log space. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/distribution/size_frequency.h" | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | /// A cumulative distribution given as a table of (D, N(>=D)) points, interpolated linearly | ||
| 15 | /// in log D and log N, so each interval is a power law. Extrapolation continues the end intervals' | ||
| 16 | /// slopes. | ||
| 17 | class TabulatedSfd final : public SizeFrequencyDistribution { | ||
| 18 | public: | ||
| 19 | /// The distribution through the table's points. | ||
| 20 | /// @param diameters At least two strictly increasing positive diameters, in `diameterUnit` m. | ||
| 21 | /// @param cumulative N(>=D) per `areaUnit` m^2 at each diameter; positive and not increasing. | ||
| 22 | /// @throws std::invalid_argument for too few or mismatched points, or values out of range. | ||
| 23 | TabulatedSfd(std::vector<double> diameters, std::vector<double> cumulative, | ||
| 24 | SfdKind kind = SfdKind::Density, double diameterUnit = 1.0, double areaUnit = 1.0); | ||
| 25 | |||
| 26 | /// The table's diameters in meters. | ||
| 27 | 1 | const std::vector<double>& Diameters() const { | |
| 28 | 1 | return m_diameters; | |
| 29 | } | ||
| 30 | |||
| 31 | /// The table's N(>=D) values per m^2 (or per m^2 per Gyr). | ||
| 32 | 1 | const std::vector<double>& CumulativeValues() const { | |
| 33 | 1 | return m_cumulative; | |
| 34 | } | ||
| 35 | |||
| 36 | protected: | ||
| 37 | double CumulativeAt(double diameter) const override; | ||
| 38 | double IncrementalAt(double diameter) const override; | ||
| 39 | /// The power-law inverse within the interval holding `target`, ignoring `minDiameter` and | ||
| 40 | /// `maxDiameter`; a flat interval, where N(>=D) never reaches `target`, gives its start | ||
| 41 | /// diameter. | ||
| 42 | double InvertCumulative(double target, double minDiameter, double maxDiameter) const override; | ||
| 43 | |||
| 44 | private: | ||
| 45 | std::size_t IntervalAt(double diameter) const; | ||
| 46 | |||
| 47 | std::vector<double> m_diameters; | ||
| 48 | std::vector<double> m_cumulative; | ||
| 49 | std::vector<double> m_slopes; | ||
| 50 | }; | ||
| 51 | |||
| 52 | } // namespace terraingen | ||
| 53 |