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 | 91917 | if (!(m_coverage > 0.0 && m_coverage < 1.0)) { | |
| 17 | 2 | throw std::invalid_argument("Boulder coverage k must be between 0 and 1"); | |
| 18 | } | ||
| 19 | 183828 | if (!(IsNonNegative(qa) && IsNonNegative(qb))) { | |
| 20 | 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 | 91913 | if (!(m_q > 0.0)) { | |
| 24 | 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 |