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 // don't need to check `&& nd_ < 50` in second part because of reordering
234 return nd_ >= 50
235 ? 120.0
236 : nd_ >= 30
237 ? 32.9 + 3.17 * nd_ - 0.0288 * nd_ * nd_
238 : 85.0 + 0.0189 * nd_ * nd_;
239 }
244 [[nodiscard]] constexpr bool isInvalid() const
245 {
246 return -1 == head_ros_;
247 }
248 // required for making a map of SpreadInfo objects
249 SpreadInfo() noexcept
250 : offsets_({}),
251 max_intensity_(INVALID_INTENSITY),
252 key_(0),
253 weather_(nullptr),
254 time_(-1),
255 l_b_(-1),
256 head_ros_(INVALID_ROS),
257 cfb_(-1),
258 cfc_(-1),
259 tfc_(-1),
260 sfc_(-1),
261 is_crown_(false),
262 raz_(fs::wx::Direction::Invalid),
263 nd_(-1) {
264 };
265 SpreadInfo(
266 const int year,
267 const int month,
268 const int day,
269 const int hour,
270 const int minute,
271 const MathSize latitude,
272 const MathSize longitude,
273 const ElevationSize elevation,
274 const SlopeSize slope,
275 const AspectSize aspect,
276 const char* fuel_name,
277 const wx::FwiWeather* weather);
278 SpreadInfo(
279 const tm& start_date,
280 const MathSize latitude,
281 const MathSize longitude,
282 const ElevationSize elevation,
283 const SlopeSize slope,
284 const AspectSize aspect,
285 const char* fuel_name,
286 const wx::FwiWeather* weather);
287 MathSize crownFractionBurned() const
288 {
289 return cfb_;
290 }
291 MathSize crownFuelConsumption() const
292 {
293 return cfc_;
294 }
295 char fireDescription() const
296 {
297 return cfb_ >= 0.9 ? 'C' : (cfb_ < 0.1 ? 'S' : 'I');
298 }
299 MathSize surfaceFuelConsumption() const
300 {
301 return sfc_;
302 }
303 MathSize totalFuelConsumption() const
304 {
305 return tfc_;
306 }
307private:
311 SpreadInfo(DurationSize time,
312 MathSize min_ros,
313 MathSize cell_size,
314 const SlopeSize slope,
315 const AspectSize aspect,
316 const char* fuel_name,
317 int nd,
318 const wx::FwiWeather* weather);
319 SpreadInfo(DurationSize time,
320 MathSize min_ros,
321 MathSize cell_size,
322 const topo::SpreadKey& key,
323 int nd,
324 const wx::FwiWeather* weather);
325 SpreadInfo(DurationSize time,
326 MathSize min_ros,
327 MathSize cell_size,
328 const topo::SpreadKey& key,
329 int nd,
330 const wx::FwiWeather* weather,
331 const wx::FwiWeather* weather_daily);
336 static MathSize initial(SpreadInfo& spread,
337 const wx::FwiWeather& weather,
338 MathSize& ffmc_effect,
339 MathSize& wsv,
340 MathSize& rsoi,
341 const fuel::FuelType* const fuel,
342 bool has_no_slope,
343 MathSize heading_sin,
344 MathSize heading_cos,
345 MathSize bui_eff,
346 MathSize min_ros,
347 MathSize critical_surface_intensity);
351 OffsetSet offsets_{};
359 topo::SpreadKey key_;
367 DurationSize time_;
368 MathSize l_b_;
372 MathSize head_ros_;
373 MathSize cfb_;
374 MathSize cfc_;
375 MathSize tfc_;
376 MathSize sfc_;
377 bool is_crown_;
385 int nd_;
386};
387}
A single Scenario in an Iteration using a specific FireWeather stream.
Definition Scenario.h:38
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:381
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:363
MathSize max_intensity_
Maximum intensity in any direction for spread (kW/m)
Definition FireSpread.h:355
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:385
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:372
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:367
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:244
topo::SpreadKey key_
Attributes for Cell spread is occurring in.
Definition FireSpread.h:359
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:351
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