distribution/golombek_rapp.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/distribution/golombek_rapp.h" | ||
| 2 | |||
| 3 | #include "terraingen/util/checks.h" | ||
| 4 | #include "terraingen/util/special_functions.h" | ||
| 5 | |||
| 6 | #include <cmath> | ||
| 7 | #include <numbers> | ||
| 8 | #include <stdexcept> | ||
| 9 | |||
| 10 | namespace terraingen { | ||
| 11 | |||
| 12 | 96475 | GolombekRappSfd::GolombekRappSfd(double coverage, double qa, double qb, DiameterRange range) | |
| 13 | 96475 | : SizeFrequencyDistribution(SfdKind::Density, range), coverage_(coverage) { | |
| 14 | 96475 | if (!(coverage_ > 0.0 && coverage_ < 1.0)) { | |
| 15 | 2 | throw std::invalid_argument("Boulder coverage k must be between 0 and 1"); | |
| 16 | } | ||
| 17 | 96473 | if (!(IsNonNegative(qa) && IsNonNegative(qb))) { | |
| 18 | 2 | throw std::invalid_argument("Golombek-Rapp qa and qb must be finite and not negative"); | |
| 19 | } | ||
| 20 | 96471 | q_ = qa + qb / coverage_; | |
| 21 | 96471 | if (!(q_ > 0.0)) { | |
| 22 | 1 | throw std::invalid_argument("Golombek-Rapp q must be positive"); | |
| 23 | } | ||
| 24 | 96475 | } | |
| 25 | |||
| 26 | 5649 | double GolombekRappSfd::FractionalArea(double diameter) const { | |
| 27 | 5649 | return coverage_ * std::exp(-q_ * diameter); | |
| 28 | } | ||
| 29 | |||
| 30 | 3915944 | double GolombekRappSfd::CumulativeAt(double diameter) const { | |
| 31 | 3915944 | return 4.0 * coverage_ * q_ / std::numbers::pi * ExponentialIntegral(2, q_ * diameter) / | |
| 32 | 3915944 | diameter; | |
| 33 | } | ||
| 34 | |||
| 35 | 5044257 | double GolombekRappSfd::IncrementalAt(double diameter) const { | |
| 36 | 5044257 | return coverage_ * q_ * std::exp(-q_ * diameter) / | |
| 37 | 5044257 | (std::numbers::pi * diameter * diameter / 4.0); | |
| 38 | } | ||
| 39 | |||
| 40 | } // namespace terraingen | ||
| 41 |