src/config/craters.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "config/craters.h" | ||
| 4 | |||
| 5 | #include "layers/craters/shaping/resolved_state.h" | ||
| 6 | #include "terraingen/distribution/equilibrium.h" | ||
| 7 | #include "terraingen/distribution/ivanov.h" | ||
| 8 | #include "terraingen/distribution/log_polynomial.h" | ||
| 9 | #include "terraingen/distribution/minimum.h" | ||
| 10 | #include "terraingen/distribution/neukum.h" | ||
| 11 | #include "terraingen/distribution/power_law.h" | ||
| 12 | #include "terraingen/distribution/production_surface.h" | ||
| 13 | #include "terraingen/distribution/spliced.h" | ||
| 14 | #include "terraingen/distribution/tabulated.h" | ||
| 15 | #include "terraingen/distribution/viper.h" | ||
| 16 | #include "terraingen/io/feature_lists.h" | ||
| 17 | #include "terraingen/layers/craters/ages/age_model.h" | ||
| 18 | #include "terraingen/layers/craters/ages/freshness_ages.h" | ||
| 19 | #include "terraingen/layers/craters/ages/steady_state.h" | ||
| 20 | #include "terraingen/layers/craters/degradation/degradation_model.h" | ||
| 21 | #include "terraingen/layers/craters/degradation/diffusivities.h" | ||
| 22 | #include "terraingen/layers/craters/degradation/freshness_degradation.h" | ||
| 23 | #include "terraingen/layers/craters/profiles/complex.h" | ||
| 24 | #include "terraingen/layers/craters/profiles/martin_parkes_dunstan.h" | ||
| 25 | #include "util/overloaded.h" | ||
| 26 | #include "util/text.h" | ||
| 27 | |||
| 28 | #include <utility> | ||
| 29 | |||
| 30 | namespace terraingen { | ||
| 31 | |||
| 32 | namespace config { | ||
| 33 | |||
| 34 | namespace { | ||
| 35 | |||
| 36 | using SfdPtr = std::shared_ptr<const SizeFrequencyDistribution>; | ||
| 37 | |||
| 38 | 588 | Chronology BuildChronology(ChronologyModel chronology) { | |
| 39 | 588 | switch (chronology) { | |
| 40 | 11 | case ChronologyModel::Ivanov: | |
| 41 | 11 | return Chronology(IvanovMarsChronology); | |
| 42 | case ChronologyModel::Neukum: | ||
| 43 | break; | ||
| 44 | } | ||
| 45 | 577 | return Chronology(NeukumLunarChronology); | |
| 46 | } | ||
| 47 | |||
| 48 | 578 | SfdPtr BuildEquilibrium(EquilibriumModel equilibrium) { | |
| 49 | 578 | switch (equilibrium) { | |
| 50 | 103 | case EquilibriumModel::Hartmann: | |
| 51 | 206 | return std::make_shared<PowerLawSfd>(HartmannEquilibrium()); | |
| 52 | case EquilibriumModel::Trask: | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | 950 | return std::make_shared<PowerLawSfd>(TraskEquilibrium()); | |
| 56 | } | ||
| 57 | |||
| 58 | 320 | std::shared_ptr<const CraterAgeModel> BuildAges(const AgesSpec& spec) { | |
| 59 | 320 | using Result = std::shared_ptr<const CraterAgeModel>; | |
| 60 | 320 | return std::visit( | |
| 61 | 316 | Overloaded{ | |
| 62 | 5 | [](const FreshAgesSpec&) -> Result { return std::make_shared<FreshAges>(); }, | |
| 63 | 21 | [](const UniformAgesSpec& s) -> Result { | |
| 64 | 21 | return std::make_shared<UniformAges>(s.lifetimeGyr); | |
| 65 | }, | ||
| 66 | 290 | [](const SteadyStateAgesSpec& s) -> Result { | |
| 67 | 580 | return std::make_shared<SteadyStateAges>(BuildProduction(s.production), | |
| 68 | 290 | BuildEquilibrium(s.equilibrium), s.ageGyr, | |
| 69 | 868 | BuildChronology(s.chronology)); | |
| 70 | }, | ||
| 71 | 4 | [](const FreshnessAgesSpec& s) -> Result { | |
| 72 | 4 | return std::make_shared<FreshnessAges>(s.freshness, s.lifetimeGyr); | |
| 73 | }, | ||
| 74 | }, | ||
| 75 | 320 | spec); | |
| 76 | } | ||
| 77 | |||
| 78 | 2 | ComplexCraterShape BuildComplexShape(CraterMorphometryFit fit) { | |
| 79 | 2 | switch (fit) { | |
| 80 | 1 | case CraterMorphometryFit::Mars: | |
| 81 | 1 | return MarsComplexCraterShape(); | |
| 82 | case CraterMorphometryFit::Lunar: | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | 1 | return LunarComplexCraterShape(); | |
| 86 | } | ||
| 87 | |||
| 88 | /// The diffusion ages of `spec`; `matched` wears craters of steady-state `ages` to the visibility | ||
| 89 | /// cutoff at the end of their lifetimes, on `profile` from `fresh`. | ||
| 90 | 112 | DiffusionAgeModel BuildDiffusionAges(const DiffusionDegradationSpec& spec, | |
| 91 | const std::shared_ptr<const CraterAgeModel>& ages, | ||
| 92 | const std::shared_ptr<const DiffusedProfile>& profile, | ||
| 93 | const FreshMorphometry& fresh) { | ||
| 94 | 112 | switch (spec.diffusivity) { | |
| 95 | 106 | case DiffusivityModel::Matched: { | |
| 96 | 106 | auto steady = std::dynamic_pointer_cast<const SteadyStateAges>(ages); | |
| 97 | 106 | if (!steady) { | |
| 98 | 6 | return Fassett2022HartmannDiffusivity(); | |
| 99 | } | ||
| 100 | 300 | return EquilibriumDiffusionAges(profile, fresh, std::move(steady)); | |
| 101 | 106 | } | |
| 102 | ✗ | case DiffusivityModel::Fassett2022Hartmann: | |
| 103 | ✗ | return Fassett2022HartmannDiffusivity(); | |
| 104 | 1 | case DiffusivityModel::Fassett2022Trask: | |
| 105 | 1 | return Fassett2022TraskDiffusivity(); | |
| 106 | 1 | case DiffusivityModel::FassettThomson2014: | |
| 107 | 1 | return FassettThomson2014Diffusivity(); | |
| 108 | 1 | case DiffusivityModel::FassettThomson2014Calibration: | |
| 109 | 2 | return [](double, double ageGyr) { return FassettThomson2014DiffusionAge(ageGyr); }; | |
| 110 | 3 | case DiffusivityModel::PowerLaw: | |
| 111 | 3 | return spec.powerLaw; | |
| 112 | } | ||
| 113 | ✗ | return Fassett2022HartmannDiffusivity(); | |
| 114 | } | ||
| 115 | |||
| 116 | 316 | std::shared_ptr<const CraterProfile> BuildProfile(const ProfileSpec& spec, | |
| 117 | CraterMorphometryFit morphometry) { | ||
| 118 | 316 | using Result = std::shared_ptr<const CraterProfile>; | |
| 119 | 632 | const auto simple = [](const SimpleProfileSpec& simpleSpec) { | |
| 120 | 314 | return std::visit(Overloaded{ | |
| 121 | 16 | [](const FassettThomsonSpec& s) -> Result { | |
| 122 | 16 | return std::make_shared<FassettThomsonProfile>(s.rim); | |
| 123 | }, | ||
| 124 | 300 | [](const MartinParkesDunstanSpec&) -> Result { | |
| 125 | 300 | return std::make_shared<MartinParkesDunstanProfile>(); | |
| 126 | }, | ||
| 127 | }, | ||
| 128 | 316 | simpleSpec); | |
| 129 | }; | ||
| 130 | 316 | return std::visit(Overloaded{ | |
| 131 | 16 | [&](const FassettThomsonSpec& s) -> Result { return simple(s); }, | |
| 132 | 298 | [&](const MartinParkesDunstanSpec& s) -> Result { return simple(s); }, | |
| 133 | 2 | [&](const ComplexProfileSpec& s) -> Result { | |
| 134 | 2 | return std::make_shared<ComplexCraterProfile>( | |
| 135 | 2 | simple(s.simple), BuildComplexShape(morphometry)); | |
| 136 | }, | ||
| 137 | }, | ||
| 138 | 316 | spec); | |
| 139 | } | ||
| 140 | |||
| 141 | /// Sets `models.degradation` from `craters`; diffusion also wears `models.profile`. | ||
| 142 | 316 | void AddDegradation(const CraterLayerSpec& craters, CraterModels& models) { | |
| 143 | 316 | const FreshMorphometry fresh = BuildMorphometry(craters.morphometry); | |
| 144 | 630 | std::visit( | |
| 145 | 316 | Overloaded{ | |
| 146 | 188 | [&](const FreshnessDegradationSpec& s) { | |
| 147 | 375 | models.degradation = | |
| 148 | 188 | std::make_shared<FreshnessDegradation>(models.ages, fresh, s.cutoffDepthRatio); | |
| 149 | 187 | }, | |
| 150 | 15 | [&](const NoDegradationSpec& s) { | |
| 151 | 15 | models.degradation = std::make_shared<NoDegradation>(fresh, s.depthRatio); | |
| 152 | 15 | }, | |
| 153 | 113 | [&](const DiffusionDegradationSpec& s) { | |
| 154 | 113 | auto profile = std::make_shared<DiffusedProfile>(models.profile, s.reachRadii); | |
| 155 | 224 | const DiffusionAgeModel ages = BuildDiffusionAges(s, models.ages, profile, fresh); | |
| 156 | 112 | models.degradation = std::make_shared<DiffusionDegradation>(fresh, ages, profile); | |
| 157 | 112 | models.profile = std::move(profile); | |
| 158 | 112 | }, | |
| 159 | }, | ||
| 160 | 316 | craters.degradation); | |
| 161 | 314 | } | |
| 162 | |||
| 163 | /// The inherited craters a spec describes, their crater list read (`ReadCraterList`). | ||
| 164 | /// @throws ConfigError at `path`.path for an unreadable or malformed crater list. | ||
| 165 | 2 | InheritedCraters BuildInheritedCraters(const InheritedCratersSpec& spec, const std::string& path, | |
| 166 | const std::filesystem::path& directory) { | ||
| 167 | 2 | InheritedCraters inherited = spec.inherited; | |
| 168 | 4 | inherited.craters = AtFile(FieldPath(path, "path"), | |
| 169 | 4 | [&] { return ReadCraterList(Resolve(spec.path, directory)); }); | |
| 170 | 1 | return inherited; | |
| 171 | 1 | } | |
| 172 | |||
| 173 | /// A length as messages give it, such as 2.5. | ||
| 174 | 6 | std::string Meters(double value) { | |
| 175 | 6 | return FormatNumber(value, 6); | |
| 176 | } | ||
| 177 | |||
| 178 | /// @throws ConfigError at `path` when the density or the ages of a generating layer are not | ||
| 179 | /// defined at its smallest diameter, as steady-state ages are not below their production | ||
| 180 | /// function's range. | ||
| 181 | 247 | void CheckModelRange(const CraterLayerSpec& craters, const CraterModels& models, | |
| 182 | const std::string& path) { | ||
| 183 | 247 | try { | |
| 184 | 247 | models.density->Cumulative(craters.options.generation.minDiameter); | |
| 185 | 245 | models.ages->LifetimeGyr(craters.options.generation.minDiameter); | |
| 186 | 3 | } catch (const std::domain_error&) { | |
| 187 | 3 | const DiameterRange& density = models.density->ValidRange(); | |
| 188 | 6 | std::string message = "the density or ages are not defined at " + | |
| 189 | 6 | Meters(craters.options.generation.minDiameter) + " m"; | |
| 190 | 3 | const AgesSpec ages = LayerAges(craters); | |
| 191 | 3 | if (const auto* steady = std::get_if<SteadyStateAgesSpec>(&ages)) { | |
| 192 | 6 | message += "; steady-state ages need the production function's diameters, from " + | |
| 193 | 15 | Meters(BuildProduction(steady->production)->ValidRange().min) + " m"; | |
| 194 | ✗ | } else if (density.min > 0.0) { | |
| 195 | 3 | message += "; the density starts at " + Meters(density.min) + " m"; | |
| 196 | } | ||
| 197 | 6 | throw ConfigError(path, message); | |
| 198 | 6 | } | |
| 199 | 244 | } | |
| 200 | |||
| 201 | /// @throws ConfigError at "ages" when steady-state ages name another production function, | ||
| 202 | /// chronology, surface age or equilibrium than a density of a production surface capped by an | ||
| 203 | /// equilibrium, so the ages would not follow the craters drawn. | ||
| 204 | 287 | void CheckMatchingAges(const CraterLayerSpec& craters, const std::string& path) { | |
| 205 | 287 | const auto* steady = craters.ages ? std::get_if<SteadyStateAgesSpec>(&*craters.ages) : nullptr; | |
| 206 | 287 | const std::optional<SteadyStateAgesSpec> matching = MatchingAges(craters.density); | |
| 207 | 287 | if (!steady || !matching) { | |
| 208 | 39 | return; | |
| 209 | } | ||
| 210 | 248 | if (matching->production != steady->production || matching->chronology != steady->chronology || | |
| 211 | 496 | matching->ageGyr != steady->ageGyr || matching->equilibrium != steady->equilibrium) { | |
| 212 | 4 | throw ConfigError(FieldPath(path, "ages"), | |
| 213 | "steady-state ages must name the production function, chronology, " | ||
| 214 | "age_gyr and equilibrium of the density's production surface and " | ||
| 215 | 6 | "equilibrium, or be left out to follow them"); | |
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | /// @throws ConfigError at a manual crater with a rim height but no depth. | ||
| 220 | 289 | void CheckManualCraters(const std::vector<Crater>& manual, const std::string& path) { | |
| 221 | 330 | for (std::size_t n = 0; n < manual.size(); ++n) { | |
| 222 | 43 | if (!manual[n].depth && manual[n].rimHeight) { | |
| 223 | 4 | throw ConfigError(FieldPath(ItemPath(path, n), "rim_height_m"), "needs a depth"); | |
| 224 | } | ||
| 225 | } | ||
| 226 | 287 | } | |
| 227 | |||
| 228 | /// The library options a crater layer spec gives, its maps, completeness and inherited craters | ||
| 229 | /// read and checked. | ||
| 230 | 268 | CraterLayerOptions BuildCraterOptions(const CraterLayerSpec& craters, const std::string& path, | |
| 231 | const LayerInputs& inputs) { | ||
| 232 | 268 | CraterLayerOptions options = craters.options; | |
| 233 | 268 | options.secondaries = inputs.thrown; | |
| 234 | 309 | for (Crater crater : craters.manual) { | |
| 235 | 41 | crater.manual = true; | |
| 236 | 41 | options.generation.manual.Append(crater); | |
| 237 | } | ||
| 238 | 268 | if (craters.densityMap) { | |
| 239 | 2 | options.densityMap = | |
| 240 | 3 | BuildMap(*craters.densityMap, FieldPath(path, "density_map"), inputs.directory); | |
| 241 | } | ||
| 242 | 267 | if (craters.completeness) { | |
| 243 | 6 | options.generation.completeness = | |
| 244 | 6 | BuildField(*craters.completeness, FieldPath(path, "completeness"), inputs.directory); | |
| 245 | } | ||
| 246 | 267 | if (const auto& inherited = craters.replaceInheritedCraters) { | |
| 247 | 3 | options.inherited = BuildInheritedCraters( | |
| 248 | 5 | *inherited, FieldPath(path, "replace_inherited_craters"), inputs.directory); | |
| 249 | } | ||
| 250 | 266 | return options; | |
| 251 | 2 | } | |
| 252 | |||
| 253 | } // namespace | ||
| 254 | |||
| 255 | 591 | std::shared_ptr<const SizeFrequencyDistribution> BuildProduction(ProductionFunction production) { | |
| 256 | 591 | switch (production) { | |
| 257 | 14 | case ProductionFunction::Neukum: | |
| 258 | 28 | return std::make_shared<LogPolynomialSfd>(NeukumProductionFunction()); | |
| 259 | 9 | case ProductionFunction::Ivanov: | |
| 260 | 18 | return std::make_shared<LogPolynomialSfd>(IvanovMarsProductionFunction()); | |
| 261 | case ProductionFunction::ExtendedNeukum: | ||
| 262 | break; | ||
| 263 | } | ||
| 264 | 1136 | return std::make_shared<SplicedSfd>(ExtendedNeukumProductionFunction()); | |
| 265 | } | ||
| 266 | |||
| 267 | 915 | std::shared_ptr<const SizeFrequencyDistribution> BuildDensity(const DensitySpec& spec) { | |
| 268 | 915 | return std::visit( | |
| 269 | 910 | Overloaded{ | |
| 270 | 298 | [](const ProductionSurfaceSpec& s) -> SfdPtr { | |
| 271 | 298 | return std::make_shared<ProductionSurface>(BuildProduction(s.production), s.ageGyr, | |
| 272 | 892 | BuildChronology(s.chronology)); | |
| 273 | }, | ||
| 274 | 288 | [](const MinimumSpec& s) -> SfdPtr { | |
| 275 | 288 | std::vector<SfdPtr> distributions; | |
| 276 | 858 | for (const DensitySpec& distribution : s.distributions) { | |
| 277 | 1140 | distributions.push_back(BuildDensity(distribution)); | |
| 278 | } | ||
| 279 | 288 | return std::make_shared<MinimumSfd>(std::move(distributions)); | |
| 280 | 288 | }, | |
| 281 | 26 | [](const PowerLawSpec& s) -> SfdPtr { | |
| 282 | 26 | return std::make_shared<PowerLawSfd>(s.coefficient, s.exponent); | |
| 283 | }, | ||
| 284 | 2 | [](const PiecewisePowerLawSpec& s) -> SfdPtr { | |
| 285 | 2 | return std::make_shared<PiecewisePowerLawSfd>(s.segments, SfdKind::Density); | |
| 286 | }, | ||
| 287 | 3 | [](const TabulatedSpec& s) -> SfdPtr { | |
| 288 | 5 | return std::make_shared<TabulatedSfd>(s.diameters, s.cumulative, SfdKind::Density, | |
| 289 | 3 | s.diameterUnit, s.areaUnit); | |
| 290 | }, | ||
| 291 | 8 | [](const PiecewiseUniformSpec& s) -> SfdPtr { | |
| 292 | 8 | return std::make_shared<PiecewiseUniformSfd>(s.bands, SfdKind::Density, s.total); | |
| 293 | }, | ||
| 294 | 237 | [](const TraskSpec&) { return BuildEquilibrium(EquilibriumModel::Trask); }, | |
| 295 | 51 | [](const HartmannSpec&) { return BuildEquilibrium(EquilibriumModel::Hartmann); }, | |
| 296 | 1 | [](const MooreSpec& s) -> SfdPtr { | |
| 297 | 2 | return std::make_shared<PiecewisePowerLawSfd>(MooreDistribution(s.terrain)); | |
| 298 | }, | ||
| 299 | 1 | [](const ViperSpec&) -> SfdPtr { | |
| 300 | 2 | return std::make_shared<PiecewisePowerLawSfd>(ViperSpecification()); | |
| 301 | }, | ||
| 302 | }, | ||
| 303 | 915 | spec); | |
| 304 | } | ||
| 305 | |||
| 306 | 323 | FreshMorphometry BuildMorphometry(CraterMorphometryFit fit) { | |
| 307 | 323 | switch (fit) { | |
| 308 | 6 | case CraterMorphometryFit::Mars: | |
| 309 | 6 | return FreshMorphometry(MarsFreshCraterMorphometry); | |
| 310 | case CraterMorphometryFit::Lunar: | ||
| 311 | break; | ||
| 312 | } | ||
| 313 | 317 | return FreshMorphometry(LunarFreshCraterMorphometry); | |
| 314 | } | ||
| 315 | |||
| 316 | 334 | std::optional<SteadyStateAgesSpec> MatchingAges(const DensitySpec& density) { | |
| 317 | 334 | const auto* minimum = std::get_if<MinimumSpec>(&density); | |
| 318 | 334 | if (!minimum) { | |
| 319 | 18 | return std::nullopt; | |
| 320 | } | ||
| 321 | 316 | const ProductionSurfaceSpec* surface = nullptr; | |
| 322 | 316 | std::optional<EquilibriumModel> equilibrium; | |
| 323 | 944 | for (const DensitySpec& distribution : minimum->distributions) { | |
| 324 | 942 | if (const auto* s = std::get_if<ProductionSurfaceSpec>(&distribution)) { | |
| 325 | surface = s; | ||
| 326 | 314 | } else if (std::holds_alternative<TraskSpec>(distribution)) { | |
| 327 | 253 | equilibrium = EquilibriumModel::Trask; | |
| 328 | 61 | } else if (std::holds_alternative<HartmannSpec>(distribution)) { | |
| 329 | 61 | equilibrium = EquilibriumModel::Hartmann; | |
| 330 | } | ||
| 331 | } | ||
| 332 | 316 | if (!surface || !equilibrium) { | |
| 333 | 2 | return std::nullopt; | |
| 334 | } | ||
| 335 | 314 | return SteadyStateAgesSpec{surface->ageGyr, surface->production, *equilibrium, | |
| 336 | 314 | surface->chronology}; | |
| 337 | } | ||
| 338 | |||
| 339 | 326 | AgesSpec LayerAges(const CraterLayerSpec& craters) { | |
| 340 | 326 | if (craters.ages) { | |
| 341 | 279 | return *craters.ages; | |
| 342 | } | ||
| 343 | 82 | return MatchingAges(craters.density).value_or(SteadyStateAgesSpec{}); | |
| 344 | } | ||
| 345 | |||
| 346 | 289 | void CheckSpec(const CraterLayerSpec& spec, const std::string& path, LayerChecks& checks) { | |
| 347 | 291 | CheckManualCraters(spec.manual, FieldPath(path, "manual")); | |
| 348 | 574 | At(FieldPath(path, "spacing"), [&] { ValidateCraterSpacing(spec.options.generation.spacing); }); | |
| 349 | 574 | At(FieldPath(path, "apply"), [&] { ValidateCraterApplyOptions(spec.options.apply); }); | |
| 350 | 287 | const auto* diffusion = std::get_if<DiffusionDegradationSpec>(&spec.degradation); | |
| 351 | 287 | if (diffusion && diffusion->diffusivity == DiffusivityModel::PowerLaw) { | |
| 352 | 2 | At(FieldPath(path, "degradation"), | |
| 353 | 1 | [&] { ValidatePowerLawDiffusivity(diffusion->powerLaw); }); | |
| 354 | } | ||
| 355 | 287 | CheckMatchingAges(spec, path); | |
| 356 | 285 | checks.craters = true; | |
| 357 | 285 | if (spec.options.generateRandom && | |
| 358 | 271 | !(spec.options.generation.maxDiameter > spec.options.generation.minDiameter)) { | |
| 359 | 2 | throw ConfigError(FieldPath(path, "max_diameter_m"), "must exceed min_diameter_m"); | |
| 360 | } | ||
| 361 | 284 | } | |
| 362 | |||
| 363 | 8 | void CheckSpec(const SecondaryLayerSpec& spec, const std::string& path, LayerChecks& checks) { | |
| 364 | 8 | if (!checks.craters) { | |
| 365 | 2 | throw ConfigError(path, "secondaries need a crater layer before this one"); | |
| 366 | } | ||
| 367 | 14 | At(path, [&] { ValidateSecondaryCraterOptions(spec.secondaries); }); | |
| 368 | 7 | } | |
| 369 | |||
| 370 | 268 | LayerPtr BuildSpec(const CraterLayerSpec& spec, const std::string& path, | |
| 371 | const LayerInputs& inputs) { | ||
| 372 | 268 | CraterLayerOptions options = BuildCraterOptions(spec, path, inputs); | |
| 373 | 266 | CraterModels models = BuildCraterModels(spec, path); | |
| 374 | 261 | if (spec.options.generateRandom) { | |
| 375 | 494 | CheckModelRange(spec, models, FieldPath(path, "min_diameter_m")); | |
| 376 | } | ||
| 377 | 516 | return std::make_shared<CraterLayer>(std::move(models), std::move(options), inputs.base); | |
| 378 | 269 | } | |
| 379 | |||
| 380 | 7 | LayerPtr BuildSpec(const SecondaryLayerSpec& spec, const std::string& /*path*/, | |
| 381 | const LayerInputs& inputs) { | ||
| 382 | 7 | const std::shared_ptr<const CraterLayer>& primaries = inputs.craters.back(); | |
| 383 | 7 | const CraterShapeModels models{ | |
| 384 | 7 | primaries->Models().profile, | |
| 385 | 7 | std::make_shared<NoDegradation>(BuildMorphometry(spec.morphometry), spec.depthRatio)}; | |
| 386 | 7 | return std::make_shared<SecondaryCraterLayer>(primaries, models, spec.secondaries, | |
| 387 | 14 | CraterApplyOptions{}, inputs.base); | |
| 388 | 7 | } | |
| 389 | |||
| 390 | 258 | void CheckBuilt(const CraterLayerSpec& spec, const Layer& built, const std::string& path, | |
| 391 | LayerChecks& checks) { | ||
| 392 | 258 | const CraterModels& models = dynamic_cast<const CraterLayer&>(built).Models(); | |
| 393 | 258 | const std::string manualPath = FieldPath(path, "manual"); | |
| 394 | 297 | for (std::size_t n = 0; n < spec.manual.size(); ++n) { | |
| 395 | 41 | if (spec.manual[n].depth) { | |
| 396 | 16 | At(ItemPath(manualPath, n), | |
| 397 | 8 | [&] { ResolvedCraterState(models.Shape(), spec.manual[n]); }); | |
| 398 | } | ||
| 399 | } | ||
| 400 | 256 | if (!spec.options.generateRandom) { | |
| 401 | 14 | return; | |
| 402 | } | ||
| 403 | 244 | const std::string minPath = FieldPath(path, "min_diameter_m"); | |
| 404 | 242 | checks.expectedCraters.resize(checks.outputs.size(), 0.0); | |
| 405 | 596 | for (std::size_t i = 0; i < checks.outputs.size(); ++i) { | |
| 406 | 354 | if (!checks.outputs[i].grid) { | |
| 407 | 16 | continue; | |
| 408 | } | ||
| 409 | 338 | const double expected = At(minPath, [&] { | |
| 410 | 338 | return models.density->ExpectedCount(checks.outputs[i].area, | |
| 411 | 338 | spec.options.generation.minDiameter, | |
| 412 | 338 | spec.options.generation.maxDiameter); | |
| 413 | }); | ||
| 414 | 338 | CheckExpectedCount(expected, "craters", "raise min_diameter_m or set max_craters", minPath); | |
| 415 | 338 | checks.expectedCraters[i] += expected; | |
| 416 | } | ||
| 417 | 256 | } | |
| 418 | |||
| 419 | } // namespace config | ||
| 420 | |||
| 421 | 324 | CraterModels BuildCraterModels(const CraterLayerSpec& craters, const std::string& path) { | |
| 422 | 324 | using config::At; | |
| 423 | 324 | CraterModels models; | |
| 424 | 324 | models.density = | |
| 425 | 652 | At(FieldPath(path, "density"), [&] { return config::BuildDensity(craters.density); }); | |
| 426 | 320 | models.ages = | |
| 427 | 960 | At(FieldPath(path, "ages"), [&] { return config::BuildAges(config::LayerAges(craters)); }); | |
| 428 | 632 | models.profile = At(FieldPath(path, "profile"), | |
| 429 | 632 | [&] { return config::BuildProfile(craters.profile, craters.morphometry); }); | |
| 430 | 634 | At(FieldPath(path, "degradation"), [&] { config::AddDegradation(craters, models); }); | |
| 431 | 314 | return models; | |
| 432 | 10 | } | |
| 433 | |||
| 434 | } // namespace terraingen | ||
| 435 |