include/terraingen/distribution/production_surface.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief The crater density of a surface of a given age: a production function times a chronology. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/distribution/size_frequency.h" | ||
| 8 | |||
| 9 | #include <functional> | ||
| 10 | #include <memory> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | /// N(>=1 km) per m^2 on a surface `ageGyr` old, such as `NeukumLunarChronology`. | ||
| 15 | using Chronology = std::function<double(double ageGyr)>; | ||
| 16 | |||
| 17 | /// The cumulative crater density on a surface of a given age: a production function scaled | ||
| 18 | /// so that N(>=1 km) follows a chronology, N(D, T) = Phi(D) * N1(T) / Phi(1 km). | ||
| 19 | /// | ||
| 20 | /// This is the population with no erosion; small craters exceed equilibrium on old surfaces. | ||
| 21 | 468 | class ProductionSurface final : public SizeFrequencyDistribution { | |
| 22 | public: | ||
| 23 | /// The surface `ageGyr` Gyr old, with the valid range and extrapolation of `production`. | ||
| 24 | /// @param production A `ProductionRate` distribution defined at 1 km. | ||
| 25 | /// @throws std::invalid_argument for a null or wrong-kind `production` or empty `chronology`. | ||
| 26 | /// @throws std::domain_error if the age is out of range or `production` is not defined at 1 km. | ||
| 27 | ProductionSurface(std::shared_ptr<const SizeFrequencyDistribution> production, double ageGyr, | ||
| 28 | const Chronology& chronology); | ||
| 29 | |||
| 30 | /// The `ProductionRate` distribution the surface scales. | ||
| 31 | 2 | const SizeFrequencyDistribution& Production() const { | |
| 32 | 2 | return *m_production; | |
| 33 | } | ||
| 34 | |||
| 35 | /// The surface age in Gyr. | ||
| 36 | 2 | double AgeGyr() const { | |
| 37 | 2 | return m_ageGyr; | |
| 38 | } | ||
| 39 | |||
| 40 | protected: | ||
| 41 | double CumulativeAt(double diameter) const override; | ||
| 42 | double IncrementalAt(double diameter) const override; | ||
| 43 | double InvertCumulative(double target, double minDiameter, double maxDiameter) const override; | ||
| 44 | |||
| 45 | private: | ||
| 46 | std::shared_ptr<const SizeFrequencyDistribution> m_production; | ||
| 47 | double m_ageGyr; | ||
| 48 | double m_scale; | ||
| 49 | }; | ||
| 50 | |||
| 51 | namespace detail { | ||
| 52 | |||
| 53 | /// A chronology N1(T) = `burst` (e^(`decay` T) - 1) + `linear` T per km^2, the form of Neukum's | ||
| 54 | /// (lunar) and Ivanov's (Martian): craters at least 1 km across on a surface T Gyr old. | ||
| 55 | struct ExponentialChronology { | ||
| 56 | double burst = 0.0; ///< Coefficient of the exponential term, per km^2. | ||
| 57 | double decay = 0.0; ///< Rate of the exponential term, per Gyr. | ||
| 58 | double linear = 0.0; ///< Present-day flux, per km^2 per Gyr. | ||
| 59 | double maxAgeGyr = 0.0; ///< Oldest age accepted, in Gyr. | ||
| 60 | const char* ageError = ""; ///< Message for an age outside [0, `maxAgeGyr`]. | ||
| 61 | |||
| 62 | /// N1 per m^2 at `ageGyr` Gyr. | ||
| 63 | /// @throws std::domain_error with `ageError` unless 0 <= `ageGyr` <= `maxAgeGyr`. | ||
| 64 | double Count(double ageGyr) const; | ||
| 65 | |||
| 66 | /// dN1/dT per m^2 per Gyr at `ageGyr` Gyr before present. | ||
| 67 | /// @throws std::domain_error as `Count`. | ||
| 68 | double Rate(double ageGyr) const; | ||
| 69 | }; | ||
| 70 | |||
| 71 | } // namespace detail | ||
| 72 | |||
| 73 | } // namespace terraingen | ||
| 74 |