FireSTARR
Loading...
Searching...
No Matches
Duff.h
1/* SPDX-License-Identifier: AGPL-3.0-or-later */
2#ifndef FS_DUFF_H
3#define FS_DUFF_H
4#include "stdafx.h"
5#include "Log.h"
6#include "unstable.h"
7namespace fs::duff
8{
39struct Duff
40{
44 MathSize ash{};
48 MathSize rho{};
52 MathSize b0{};
56 MathSize b1{};
60 MathSize b2{};
64 MathSize b3{};
70 [[nodiscard]] ThresholdSize probabilityOfSurvival(const MathSize mc_pct) const noexcept
71 {
75 const auto ConstantPart = b0 + b2 * ash + b3 * rho;
76 const auto d = 1 + exp(-(b1 * mc_pct + ConstantPart));
77 if (0 == d)
78 {
79 return 1.0;
80 }
81 return 1.0 / d;
82 }
88 [[nodiscard]] constexpr bool operator==(const Duff& rhs) const
89 {
90 // HACK: only equivalent if identical
91 return this == &rhs;
92 }
98 [[nodiscard]] constexpr bool operator!=(const Duff& rhs) const { return !operator==(rhs); }
99};
100// /**
101// * \brief Feather moss (upper) [Frandsen table 2/3]
102// */
103// static constexpr Duff FeatherMossUpper{17.2, 46.4, 13.9873, -0.3296, 0.4904, 0.0568};
104// /**
105// * \brief Feather moss (lower) [Frandsen table 2/3]
106// */
107// static constexpr Duff FeatherMossLower{19.1, 38.9, 13.2628, -0.1167, 0.3308, -0.2604};
111static constexpr Duff SphagnumUpper{12.4, 21.8, -8.8306, -0.0608, 0.8095, 0.2735};
112// /**
113// * \brief Sphagnum (lower) [Frandsen table 2/3]
114// */
115// static constexpr Duff SphagnumLower{56.7, 119.0, 327.3347, -3.7655, -8.7849, 2.6684};
119static constexpr Duff FeatherMoss{18.1, 42.7, 9.0970, -0.1040, 0.1165, -0.0646};
123static constexpr Duff Reindeer{26.1, 56.3, 8.0359, -0.0393, -0.0591, -0.0340};
124// /**
125// * \brief Sedge meadow (upper) [Frandsen table 2/3]
126// */
127// static constexpr Duff SedgeMeadowUpper{23.3, 69.4, 39.8477, -0.1800, -0.3727, -0.1874};
128// /**
129// * \brief Sedge meadow (lower) [Frandsen table 2/3]
130// */
131// static constexpr Duff SedgeMeadowLower{44.9, 91.5, 29.0818, -0.2059, -0.2319, -0.0420};
135static constexpr Duff WhiteSpruce{35.9, 122.0, 332.5604, -1.2220, -2.1024, -1.2619};
139static constexpr Duff Peat{9.4, 222.0, -19.8198, -0.1169, 1.0414, 0.0782};
143static constexpr Duff PeatMuck{34.9, 203.0, 37.2276, -0.1876, -0.2833, -0.0951};
144// /**
145// * \brief Sedge meadow (Seney) [Frandsen table 2/3]
146// */
147// static constexpr Duff SedgeMeadowSeney{35.4, 183.0, 71.813, -0.1413, -0.1253, 0.0390};
151static constexpr Duff PineSeney{36.5, 190.0, 45.1778, -0.3227, -0.3644, -0.0362};
155static constexpr Duff SprucePine{30.7, 116.0, 58.6921, -0.2737, -0.5413, -0.1246};
156// /**
157// * \brief Grass/sedge marsh [Frandsen table 2/3]
158// */
159// static constexpr Duff GrassSedgeMarsh{35.2, 120.0, 236.2934, -0.8423, -2.5097, -0.4902};
160// /**
161// * \brief Southern pine duff [Frandsen table 2/3]
162// */
163// static constexpr Duff SouthernPine{68.0, 112.0, 58.6921, -0.2737, -0.5413, -0.1246};
164// /**
165// * \brief Hardwood swamp (upper) [Frandsen table 2/3]
166// */
167// static constexpr Duff HardwoodSwamp{18.2, 138.0, 33.6907, -0.2946, -0.3002, -0.4040};
168// coefficients aren't defined in the table these came from
169// static const Duff Pocosin;
170// static const Duff SwampForest;
171// static const Duff Flatwoods;
172}
173namespace fs::testing
174{
175template <class TypeA, class TypeB>
176int compare_duff(
177 const string name,
178 const TypeA& a,
179 const TypeB& b,
180 const logging::level log_level = logging::level::info
181)
182{
183 static constexpr int RESOLUTION = 10000;
184 static constexpr MathSize RANGE = 250.0;
185 // check %, so 1 decimal is fine
186 static constexpr auto EPSILON = static_cast<MathSize>(1e-1);
187 std::ignore = logging::output(log_level, "Checking {:s}", name);
188 logging::check_equal_verbose(logging::level::debug, a.ash, b.ash, "ash");
189 logging::check_equal_verbose(logging::level::debug, a.rho, b.rho, "rho");
190 logging::check_equal_verbose(logging::level::debug, a.b0, b.b0, "b0");
191 logging::check_equal_verbose(logging::level::debug, a.b1, b.b1, "b1");
192 logging::check_equal_verbose(logging::level::debug, a.b2, b.b2, "b2");
193 logging::check_equal_verbose(logging::level::debug, a.b3, b.b3, "b3");
194 for (auto i = 0; i < RESOLUTION; ++i)
195 {
196 const MathSize mc = RANGE * i / RESOLUTION;
197 const auto msg = std::format("probability of survival (mc = {})", mc);
198 logging::check_tolerance(
199 EPSILON, a.probabilityOfSurvival(mc), b.probabilityOfSurvival(mc), msg.c_str()
200 );
201 }
202 return 0;
203}
204// FIX: this was used to compare to the old template version, but now just
205// compares each Duff to itself
206int test_duff(const int argc, const char* const argv[]);
207}
208#endif
A specific type of Duff layer, and the associated smouldering coefficients.
Definition Duff.h:40
constexpr bool operator!=(const Duff &rhs) const
Inequality operator.
Definition Duff.h:98
MathSize rho
Organic bulk density (kg/m^3)
Definition Duff.h:48
MathSize ash
Inorganic content, percentage oven dry weight.
Definition Duff.h:44
ThresholdSize probabilityOfSurvival(const MathSize mc_pct) const noexcept
Probability of survival (% / 100) [eq Ig-1].
Definition Duff.h:70
MathSize b2
B_2 [table 2].
Definition Duff.h:60
MathSize b3
B_3 [table 2].
Definition Duff.h:64
MathSize b1
B_1 [table 2].
Definition Duff.h:56
constexpr bool operator==(const Duff &rhs) const
Equality operator.
Definition Duff.h:88
MathSize b0
B_0 [table 2].
Definition Duff.h:52