./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
9 / 9
100.0%
Branches:
14 / 63
22.2%
Functions:
2 / 2, 1 excl
100.0%

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
12/61
✓ Branch 0 taken 3 times.
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 5 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 time.
✗ Branch 32 not taken.
✓ Branch 33 taken 1 time.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 time.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 time.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 1 time.
✗ Branch 46 not taken.
✓ Branch 47 taken 1 time.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
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
1/1
✓ Branch 1 taken 1 time.
2 return *m_production;
33 }
34
35 /// The surface age in Gyr.
36 2 double AgeGyr() const {
37
1/1
✓ Branch 1 taken 1 time.
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