./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
262 / 266
98.5%
Branches:
197 / 246
80.1%
Functions:
44 / 44
100.0%

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
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 577 times.
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
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 475 times.
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
4/7
✓ Branch 1 taken 290 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 289 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 289 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
580 return std::make_shared<SteadyStateAges>(BuildProduction(s.production),
68 290 BuildEquilibrium(s.equilibrium), s.ageGyr,
69
2/3
✓ Branch 1 taken 290 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 289 times.
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/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
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
5/7
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
112 switch (spec.diffusivity) {
95 106 case DiffusivityModel::Matched: {
96 106 auto steady = std::dynamic_pointer_cast<const SteadyStateAges>(ages);
97
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 100 times.
106 if (!steady) {
98
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 return Fassett2022HartmannDiffusivity();
99 }
100
3/8
✓ Branch 1 taken 100 times.
✓ Branch 4 taken 100 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 100 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 return std::make_shared<ComplexCraterProfile>(
135
2/3
✓ Branch 3 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
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
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 187 times.
188 std::make_shared<FreshnessDegradation>(models.ages, fresh, s.cutoffDepthRatio);
149 187 },
150 15 [&](const NoDegradationSpec& s) {
151
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
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
2/5
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 112 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
224 const DiffusionAgeModel ages = BuildDiffusionAges(s, models.ages, profile, fresh);
156
2/3
✓ Branch 1 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
112 models.degradation = std::make_shared<DiffusionDegradation>(fresh, ages, profile);
157 112 models.profile = std::move(profile);
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 },
159 },
160
1/1
✓ Branch 1 taken 314 times.
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
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1 time.
4 inherited.craters = AtFile(FieldPath(path, "path"),
169
1/1
✓ Branch 3 taken 1 time.
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
1/1
✓ Branch 1 taken 245 times.
247 models.density->Cumulative(craters.options.generation.minDiameter);
185
1/1
✓ Branch 1 taken 244 times.
245 models.ages->LifetimeGyr(craters.options.generation.minDiameter);
186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } catch (const std::domain_error&) {
187
1/1
✓ Branch 1 taken 3 times.
3 const DiameterRange& density = models.density->ValidRange();
188
1/1
✓ Branch 1 taken 3 times.
6 std::string message = "the density or ages are not defined at " +
189
1/1
✓ Branch 1 taken 3 times.
6 Meters(craters.options.generation.minDiameter) + " m";
190
1/1
✓ Branch 1 taken 3 times.
3 const AgesSpec ages = LayerAges(craters);
191
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (const auto* steady = std::get_if<SteadyStateAgesSpec>(&ages)) {
192
1/1
✓ Branch 1 taken 3 times.
6 message += "; steady-state ages need the production function's diameters, from " +
193
4/5
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
15 Meters(BuildProduction(steady->production)->ValidRange().min) + " m";
194
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ } else if (density.min > 0.0) {
195
0/3
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
3 message += "; the density starts at " + Meters(density.min) + " m";
196 }
197
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
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
4/4
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 250 times.
✓ Branch 3 taken 10 times.
287 const auto* steady = craters.ages ? std::get_if<SteadyStateAgesSpec>(&*craters.ages) : nullptr;
206 287 const std::optional<SteadyStateAgesSpec> matching = MatchingAges(craters.density);
207
4/4
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 248 times.
✓ Branch 3 taken 2 times.
287 if (!steady || !matching) {
208 39 return;
209 }
210
2/4
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 248 times.
✗ Branch 3 not taken.
248 if (matching->production != steady->production || matching->chronology != steady->chronology ||
211
5/6
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 247 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 246 times.
✓ Branch 5 taken 1 time.
496 matching->ageGyr != steady->ageGyr || matching->equilibrium != steady->equilibrium) {
212
1/1
✓ Branch 1 taken 2 times.
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
2/2
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
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
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 287 times.
330 for (std::size_t n = 0; n < manual.size(); ++n) {
222
4/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 33 times.
43 if (!manual[n].depth && manual[n].rimHeight) {
223
4/4
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
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
1/1
✓ Branch 1 taken 268 times.
268 options.secondaries = inputs.thrown;
234
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 268 times.
309 for (Crater crater : craters.manual) {
235 41 crater.manual = true;
236
1/1
✓ Branch 1 taken 41 times.
41 options.generation.manual.Append(crater);
237 }
238
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 266 times.
268 if (craters.densityMap) {
239 2 options.densityMap =
240
3/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
3 BuildMap(*craters.densityMap, FieldPath(path, "density_map"), inputs.directory);
241 }
242
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 261 times.
267 if (craters.completeness) {
243 6 options.generation.completeness =
244
3/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
6 BuildField(*craters.completeness, FieldPath(path, "completeness"), inputs.directory);
245 }
246
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 265 times.
267 if (const auto& inherited = craters.replaceInheritedCraters) {
247
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1 time.
3 options.inherited = BuildInheritedCraters(
248
1/1
✓ Branch 1 taken 2 times.
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
3/3
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 568 times.
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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
298 return std::make_shared<ProductionSurface>(BuildProduction(s.production), s.ageGyr,
272
2/3
✓ Branch 1 taken 298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 297 times.
892 BuildChronology(s.chronology));
273 },
274 288 [](const MinimumSpec& s) -> SfdPtr {
275 288 std::vector<SfdPtr> distributions;
276
2/2
✓ Branch 0 taken 570 times.
✓ Branch 1 taken 288 times.
858 for (const DensitySpec& distribution : s.distributions) {
277
2/3
✓ Branch 1 taken 570 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 570 times.
1140 distributions.push_back(BuildDensity(distribution));
278 }
279
1/1
✓ Branch 1 taken 285 times.
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
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 317 times.
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
2/2
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 18 times.
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
2/2
✓ Branch 0 taken 628 times.
✓ Branch 1 taken 316 times.
944 for (const DensitySpec& distribution : minimum->distributions) {
324
1/2
✓ Branch 0 taken 628 times.
✗ Branch 1 not taken.
942 if (const auto* s = std::get_if<ProductionSurfaceSpec>(&distribution)) {
325 surface = s;
326
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 61 times.
314 } else if (std::holds_alternative<TraskSpec>(distribution)) {
327 253 equilibrium = EquilibriumModel::Trask;
328
1/2
✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
61 } else if (std::holds_alternative<HartmannSpec>(distribution)) {
329 61 equilibrium = EquilibriumModel::Hartmann;
330 }
331 }
332
3/4
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 314 times.
✗ Branch 3 not taken.
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
2/2
✓ Branch 0 taken 279 times.
✓ Branch 1 taken 47 times.
326 if (craters.ages) {
341 279 return *craters.ages;
342 }
343
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 12 times.
82 return MatchingAges(craters.density).value_or(SteadyStateAgesSpec{});
344 }
345
346 289 void CheckSpec(const CraterLayerSpec& spec, const std::string& path, LayerChecks& checks) {
347
1/1
✓ Branch 2 taken 287 times.
291 CheckManualCraters(spec.manual, FieldPath(path, "manual"));
348
2/2
✓ Branch 2 taken 287 times.
✓ Branch 6 taken 287 times.
574 At(FieldPath(path, "spacing"), [&] { ValidateCraterSpacing(spec.options.generation.spacing); });
349
2/2
✓ Branch 2 taken 287 times.
✓ Branch 6 taken 287 times.
574 At(FieldPath(path, "apply"), [&] { ValidateCraterApplyOptions(spec.options.apply); });
350
1/2
✓ Branch 0 taken 287 times.
✗ Branch 1 not taken.
287 const auto* diffusion = std::get_if<DiffusionDegradationSpec>(&spec.degradation);
351
4/4
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 204 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 82 times.
287 if (diffusion && diffusion->diffusivity == DiffusivityModel::PowerLaw) {
352
1/1
✓ Branch 2 taken 1 time.
2 At(FieldPath(path, "degradation"),
353
1/1
✓ Branch 1 taken 1 time.
1 [&] { ValidatePowerLawDiffusivity(diffusion->powerLaw); });
354 }
355 287 CheckMatchingAges(spec, path);
356 285 checks.craters = true;
357
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 14 times.
285 if (spec.options.generateRandom &&
358
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 270 times.
271 !(spec.options.generation.maxDiameter > spec.options.generation.minDiameter)) {
359
3/3
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
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
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 7 times.
8 if (!checks.craters) {
365
3/3
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 8 taken 1 time.
2 throw ConfigError(path, "secondaries need a crater layer before this one");
366 }
367
1/1
✓ Branch 2 taken 7 times.
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
1/1
✓ Branch 1 taken 261 times.
266 CraterModels models = BuildCraterModels(spec, path);
374
2/2
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 14 times.
261 if (spec.options.generateRandom) {
375
2/2
✓ Branch 1 taken 247 times.
✓ Branch 4 taken 244 times.
494 CheckModelRange(spec, models, FieldPath(path, "min_diameter_m"));
376 }
377
1/1
✓ Branch 1 taken 258 times.
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
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 const std::shared_ptr<const CraterLayer>& primaries = inputs.craters.back();
383
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 const CraterShapeModels models{
384
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 primaries->Models().profile,
385
1/3
✓ Branch 1 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 std::make_shared<NoDegradation>(BuildMorphometry(spec.morphometry), spec.depthRatio)};
386 7 return std::make_shared<SecondaryCraterLayer>(primaries, models, spec.secondaries,
387
1/1
✓ Branch 1 taken 7 times.
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
1/2
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
258 const CraterModels& models = dynamic_cast<const CraterLayer&>(built).Models();
393 258 const std::string manualPath = FieldPath(path, "manual");
394
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 256 times.
297 for (std::size_t n = 0; n < spec.manual.size(); ++n) {
395
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 33 times.
41 if (spec.manual[n].depth) {
396
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 6 times.
16 At(ItemPath(manualPath, n),
397
1/1
✓ Branch 2 taken 6 times.
8 [&] { ResolvedCraterState(models.Shape(), spec.manual[n]); });
398 }
399 }
400
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 242 times.
256 if (!spec.options.generateRandom) {
401 14 return;
402 }
403
1/1
✓ Branch 1 taken 242 times.
244 const std::string minPath = FieldPath(path, "min_diameter_m");
404
1/1
✓ Branch 1 taken 242 times.
242 checks.expectedCraters.resize(checks.outputs.size(), 0.0);
405
2/2
✓ Branch 0 taken 354 times.
✓ Branch 1 taken 242 times.
596 for (std::size_t i = 0; i < checks.outputs.size(); ++i) {
406
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 338 times.
354 if (!checks.outputs[i].grid) {
407 16 continue;
408 }
409
1/1
✓ Branch 1 taken 338 times.
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
1/1
✓ Branch 1 taken 338 times.
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
4/5
✓ Branch 1 taken 324 times.
✓ Branch 4 taken 320 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 320 times.
✓ Branch 11 taken 320 times.
652 At(FieldPath(path, "density"), [&] { return config::BuildDensity(craters.density); });
426 320 models.ages =
427
4/5
✓ Branch 1 taken 320 times.
✓ Branch 4 taken 316 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 316 times.
✓ Branch 12 taken 316 times.
960 At(FieldPath(path, "ages"), [&] { return config::BuildAges(config::LayerAges(craters)); });
428
2/2
✓ Branch 1 taken 316 times.
✓ Branch 4 taken 316 times.
632 models.profile = At(FieldPath(path, "profile"),
429
2/3
✗ Branch 1 not taken.
✓ Branch 2 taken 316 times.
✓ Branch 4 taken 316 times.
632 [&] { return config::BuildProfile(craters.profile, craters.morphometry); });
430
3/3
✓ Branch 1 taken 316 times.
✓ Branch 4 taken 314 times.
✓ Branch 7 taken 314 times.
634 At(FieldPath(path, "degradation"), [&] { config::AddDegradation(craters, models); });
431 314 return models;
432 10 }
433
434 } // namespace terraingen
435