FireSTARR
Loading...
Searching...
No Matches
FireSpread.h
1/* Copyright (c) Queen's Printer for Ontario, 2020. */
2/* Copyright (c) His Majesty the King in Right of Canada as represented by the Minister of Natural Resources, 2021-2025. */
3
4/* SPDX-License-Identifier: AGPL-3.0-or-later */
5
6#pragma once
7#include "Cell.h"
8#include "FWI.h"
9#include "Point.h"
10#include "Settings.h"
11#include "Util.h"
12#include "InnerPos.h"
13namespace fs::sim
14{
15
16static constexpr int MAX_SPREAD_ANGLE = 5.0;
17static constexpr MathSize INVALID_ROS = -1.0;
18static constexpr MathSize INVALID_INTENSITY = -1.0;
19
20class Scenario;
24int calculate_nd_ref_for_point(const int elevation, const topo::Point& point) noexcept;
25int calculate_nd_for_point(const Day day, const int elevation, const topo::Point& point);
30{
31public:
35 static const SlopeTableArray SlopeTable;
36 ~SpreadInfo() = default;
37 SpreadInfo(const Scenario& scenario,
38 DurationSize time,
39 const topo::SpreadKey& key,
40 int nd,
41 const wx::FwiWeather* weather);
50 SpreadInfo(const Scenario& scenario,
51 DurationSize time,
52 const topo::SpreadKey& key,
53 int nd,
55 const wx::FwiWeather* weather_daily);
56 CONSTEXPR SpreadInfo(SpreadInfo&& rhs) noexcept = default;
57 SpreadInfo(const SpreadInfo& rhs) noexcept = default;
58 CONSTEXPR SpreadInfo& operator=(SpreadInfo&& rhs) noexcept = default;
59 SpreadInfo& operator=(const SpreadInfo& rhs) noexcept = default;
60 // static MathSize calculateSpreadProbability(MathSize ros);
66 [[nodiscard]] static constexpr MathSize calculateRosFromThreshold(const ThresholdSize threshold)
67 {
68 // for some reason it returns -nan instead of nan if it's 1, so return this instead
69 if (1.0 == threshold)
70 {
71 return std::numeric_limits<ThresholdSize>::infinity();
72 }
73 if (0.0 == threshold)
74 {
75 return 0.0;
76 }
77 // NOTE: based off spread event probability from wotton
78 // should be the inverse of calculateSpreadProbability()
79 return 25.0 / 4.0 * log(-(exp(41.0 / 25.0) * threshold) / (threshold - 1));
80 }
85 [[nodiscard]] MathSize maxIntensity() const noexcept
86 {
87 return max_intensity_;
88 }
93 [[nodiscard]] const OffsetSet& offsets() const
94 {
95 return offsets_;
96 }
101 [[nodiscard]] constexpr bool isNotSpreading() const
102 {
103 return isInvalid();
104 }
109 [[nodiscard]] constexpr int nd() const
110 {
111 return nd_;
112 }
117 [[nodiscard]] constexpr const wx::FwiWeather* weather() const
118 {
119 return weather_;
120 }
125 [[nodiscard]] constexpr const wx::Wind& wind() const
126 {
127 return weather()->wind();
128 }
133 [[nodiscard]] constexpr const wx::Ffmc& ffmc() const
134 {
135 return weather()->ffmc();
136 }
141 [[nodiscard]] constexpr const wx::Bui& bui() const
142 {
143 return weather()->bui();
144 }
149 [[nodiscard]] constexpr const wx::Dmc& dmc() const
150 {
151 return weather()->dmc();
152 }
157 [[nodiscard]] constexpr const wx::Dc& dc() const
158 {
159 return weather()->dc();
160 }
165 [[nodiscard]] constexpr MathSize ffmcEffect() const
166 {
167 return weather()->ffmcEffect();
168 }
173 [[nodiscard]] constexpr DurationSize time() const
174 {
175 return time_;
176 }
181 [[nodiscard]] constexpr MathSize lengthToBreadth() const
182 {
183 return l_b_;
184 }
189 [[nodiscard]] constexpr SlopeSize percentSlope() const
190 {
191 return topo::Cell::slope(key_);
192 }
197 [[nodiscard]] constexpr AspectSize slopeAzimuth() const
198 {
199 return topo::Cell::aspect(key_);
200 }
205 [[nodiscard]] constexpr MathSize headRos() const
206 {
207 return head_ros_;
208 }
213 [[nodiscard]] constexpr fs::wx::Direction headDirection() const
214 {
215 return raz_;
216 }
221 [[nodiscard]] constexpr MathSize slopeFactor() const
222 {
223 // HACK: slope can be infinite, but anything > 60 is the same as 60
224 // we already capped the percent slope when making the Cells
225 return SlopeTable.at(percentSlope());
226 }
231 [[nodiscard]] constexpr MathSize foliarMoisture() const
232 {
233 const auto nd = abs(nd_);
234 // don't need to check `&& nd_ < 50` in second part because of reordering
235 return nd >= 50
236 ? 120.0
237 : nd >= 30
238 ? 32.9 + 3.17 * nd - 0.0288 * nd * nd
239 : 85.0 + 0.0189 * nd * nd;
240 }
245 [[nodiscard]] constexpr bool isInvalid() const
246 {
247 return -1 == head_ros_;
248 }
249 // required for making a map of SpreadInfo objects
250 SpreadInfo() noexcept
251 : offsets_({}),
252 max_intensity_(INVALID_INTENSITY),
253 key_(0),
254 weather_(nullptr),
255 time_(-1),
256 l_b_(-1),
257 head_ros_(INVALID_ROS),
258 cfb_(-1),
259 cfc_(-1),
260 tfc_(-1),
261 sfc_(-1),
262 is_crown_(false),
263 raz_(fs::wx::Direction::Invalid),
264 nd_(-1) {
265 };
266 SpreadInfo(
267 const int year,
268 const int month,
269 const int day,
270 const int hour,
271 const int minute,
272 const MathSize latitude,
273 const MathSize longitude,
274 const ElevationSize elevation,
275 const SlopeSize slope,
276 const AspectSize aspect,
277 const char* fuel_name,
278 const wx::FwiWeather* weather);
279 SpreadInfo(
280 const tm& start_date,
281 const MathSize latitude,
282 const MathSize longitude,
283 const ElevationSize elevation,
284 const SlopeSize slope,
285 const AspectSize aspect,
286 const char* fuel_name,
287 const wx::FwiWeather* weather);
288 MathSize crownFractionBurned() const
289 {
290 return cfb_;
291 }
292 MathSize crownFuelConsumption() const
293 {
294 return cfc_;
295 }
296 char fireDescription() const
297 {
298 return cfb_ >= 0.9 ? 'C' : (cfb_ < 0.1 ? 'S' : 'I');
299 }
300 MathSize surfaceFuelConsumption() const
301 {
302 return sfc_;
303 }
304 MathSize totalFuelConsumption() const
305 {
306 return tfc_;
307 }
308private:
312 SpreadInfo(DurationSize time,
313 MathSize min_ros,
314 MathSize cell_size,
315 const SlopeSize slope,
316 const AspectSize aspect,
317 const char* fuel_name,
318 int nd,
319 const wx::FwiWeather* weather);
320 SpreadInfo(DurationSize time,
321 MathSize min_ros,
322 MathSize cell_size,
323 const topo::SpreadKey& key,
324 int nd,
325 const wx::FwiWeather* weather);
326 SpreadInfo(DurationSize time,
327 MathSize min_ros,
328 MathSize cell_size,
329 const topo::SpreadKey& key,
330 int nd,
331 const wx::FwiWeather* weather,
332 const wx::FwiWeather* weather_daily);
337 static MathSize initial(SpreadInfo& spread,
338 const wx::FwiWeather& weather,
339 MathSize& ffmc_effect,
340 MathSize& wsv,
341 MathSize& rsoi,
342 const fuel::FuelType* const fuel,
343 bool has_no_slope,
344 MathSize heading_sin,
345 MathSize heading_cos,
346 MathSize bui_eff,
347 MathSize min_ros,
348 MathSize critical_surface_intensity);
352 OffsetSet offsets_{};
360 topo::SpreadKey key_;
368 DurationSize time_;
369 MathSize l_b_;
373 MathSize head_ros_;
374 MathSize cfb_;
375 MathSize cfc_;
376 MathSize tfc_;
377 MathSize sfc_;
378 bool is_crown_;
386 int nd_;
387};
388}
A single Scenario in an Iteration using a specific FireWeather stream.
Definition Scenario.h:31
Information regarding spread within a Cell for a specific Scenario and time.
Definition FireSpread.h:30
fs::wx::Direction raz_
Head fire spread direction.
Definition FireSpread.h:382
constexpr fs::wx::Direction headDirection() const
Head fire spread direction.
Definition FireSpread.h:213
static constexpr MathSize calculateRosFromThreshold(const ThresholdSize threshold)
Determine rate of spread from probability of spread threshold.
Definition FireSpread.h:66
constexpr const wx::Dmc & dmc() const
Duff Moisture Code used for spread.
Definition FireSpread.h:149
wx::FwiWeather const * weather_
FwiWeather determining spread.
Definition FireSpread.h:364
MathSize max_intensity_
Maximum intensity in any direction for spread (kW/m)
Definition FireSpread.h:356
static MathSize initial(SpreadInfo &spread, const wx::FwiWeather &weather, MathSize &ffmc_effect, MathSize &wsv, MathSize &rsoi, const fuel::FuelType *const fuel, bool has_no_slope, MathSize heading_sin, MathSize heading_cos, MathSize bui_eff, MathSize min_ros, MathSize critical_surface_intensity)
Definition FireSpread.cpp:80
constexpr const wx::Bui & bui() const
Build-up Index used for spread.
Definition FireSpread.h:141
int nd_
Difference between date and the date of minimum foliar moisture content (from ST-X-3)
Definition FireSpread.h:386
static const SlopeTableArray SlopeTable
Lookup table for Slope Factor calculated from Percent Slope.
Definition FireSpread.h:35
constexpr MathSize lengthToBreadth() const
Length to breadth ratio used for spread.
Definition FireSpread.h:181
constexpr const wx::Ffmc & ffmc() const
Fine Fuel Moisture Code used for spread.
Definition FireSpread.h:133
MathSize head_ros_
Head fire rate of spread (m/min)
Definition FireSpread.h:373
constexpr SlopeSize percentSlope() const
Slope used for spread (%)
Definition FireSpread.h:189
constexpr MathSize foliarMoisture() const
Calculate foliar moisture.
Definition FireSpread.h:231
MathSize maxIntensity() const noexcept
Maximum intensity in any direction for spread (kW/m)
Definition FireSpread.h:85
constexpr const wx::Wind & wind() const
Wind used for spread.
Definition FireSpread.h:125
DurationSize time_
Time that spread is occurring.
Definition FireSpread.h:368
constexpr int nd() const
Difference between date and the date of minimum foliar moisture content.
Definition FireSpread.h:109
constexpr bool isNotSpreading() const
Whether or not there is no spread.
Definition FireSpread.h:101
constexpr MathSize headRos() const
Head fire rate of spread (m/min)
Definition FireSpread.h:205
constexpr const wx::Dc & dc() const
Drought Code used for spread.
Definition FireSpread.h:157
constexpr DurationSize time() const
Time used for spread.
Definition FireSpread.h:173
constexpr MathSize slopeFactor() const
Slope factor calculated from percent slope.
Definition FireSpread.h:221
constexpr MathSize ffmcEffect() const
FFMC effect used for spread.
Definition FireSpread.h:165
constexpr AspectSize slopeAzimuth() const
Aspect used for spread (degrees)
Definition FireSpread.h:197
constexpr bool isInvalid() const
Whether or not there is no spread for given conditions.
Definition FireSpread.h:245
topo::SpreadKey key_
Attributes for Cell spread is occurring in.
Definition FireSpread.h:360
constexpr const wx::FwiWeather * weather() const
FwiWeather used for spread.
Definition FireSpread.h:117
OffsetSet offsets_
Offsets from origin point that represent spread under these conditions.
Definition FireSpread.h:352
const OffsetSet & offsets() const
Offsets from origin point that represent spread under these conditions.
Definition FireSpread.h:93
constexpr AspectSize aspect() const noexcept
Aspect (degrees)
Definition Cell.h:198
constexpr SlopeSize slope() const noexcept
Slope (degrees)
Definition Cell.h:214
Build-up Index value.
Definition FWI.h:130
Drought Code value.
Definition FWI.h:73
Direction with access to degrees or radians.
Definition Weather.h:64
Duff Moisture Code value.
Definition FWI.h:43
Fine Fuel Moisture Code value.
Definition FWI.h:15
A Weather value with calculated FWI indices.
Definition FWI.h:209
constexpr const Bui & bui() const
Build-up Index.
Definition FWI.h:374
constexpr MathSize ffmcEffect() const
Ffmc effect used for spread.
Definition FWI.h:422
constexpr const Dmc & dmc() const
Duff Moisture Code.
Definition FWI.h:350
constexpr const Ffmc & ffmc() const
Fine Fuel Moisture Code.
Definition FWI.h:342
constexpr const Dc & dc() const
Drought Code.
Definition FWI.h:358
constexpr const Wind & wind() const noexcept
Wind (km/h)
Definition Weather.h:368
Wind with a Speed and Direction.
Definition Weather.h:139
Definition log.py:1