./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
18 / 18
100.0%
Branches:
12 / 13
92.3%
Functions:
5 / 5
100.0%

src/distribution/golombek_rapp.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/distribution/golombek_rapp.h"
4
5 #include "terraingen/util/bits.h"
6 #include "terraingen/util/special_functions.h"
7 #include "util/checks.h"
8
9 #include <cmath>
10 #include <stdexcept>
11
12 namespace terraingen {
13
14 91917 GolombekRappSfd::GolombekRappSfd(double coverage, double qa, double qb, DiameterRange range)
15 91917 : SizeFrequencyDistribution(SfdKind::Density, range), m_coverage(coverage) {
16
4/4
✓ Branch 0 taken 91916 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 91915 times.
91917 if (!(m_coverage > 0.0 && m_coverage < 1.0)) {
17
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Boulder coverage k must be between 0 and 1");
18 }
19
3/4
✓ Branch 0 taken 91914 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 91913 times.
✗ Branch 3 not taken.
183828 if (!(IsNonNegative(qa) && IsNonNegative(qb))) {
20
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Golombek-Rapp qa and qb must be finite and not negative");
21 }
22 91913 m_q = qa + qb / m_coverage;
23
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 91912 times.
91913 if (!(m_q > 0.0)) {
24
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Golombek-Rapp q must be positive");
25 }
26 91912 }
27
28 1042 double GolombekRappSfd::FractionalArea(double diameter) const {
29 1042 return m_coverage * std::exp(-m_q * diameter);
30 }
31
32 4058089 double GolombekRappSfd::CumulativeAt(double diameter) const {
33 4058089 return 4.0 * m_coverage * m_q / kPi * ExponentialIntegral(2, m_q * diameter) / diameter;
34 }
35
36 492307 double GolombekRappSfd::IncrementalAt(double diameter) const {
37 492307 return GolombekRappIncremental(diameter, m_coverage, m_q);
38 }
39
40 1039179 double GolombekRappIncremental(double diameter, double coverage, double q) {
41 1039179 return coverage * q * std::exp(-q * diameter) / (kPi * diameter * diameter / 4.0);
42 }
43
44 } // namespace terraingen
45