FireSTARR
Loading...
Searching...
No Matches
FWI.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 <string>
8#include "Weather.h"
9namespace fs::wx
10{
14class Ffmc : public Index<Ffmc>
15{
16public:
18 using Index::Index;
20
28 Ffmc(const Temperature& temperature,
29 const RelativeHumidity& rh,
30 const Speed& ws,
31 const Precipitation& prec,
32 const Ffmc& ffmc_previous) noexcept;
36 static const Ffmc Zero;
37 static const Ffmc Invalid;
38};
42class Dmc : public Index<Dmc>
43{
44public:
46 using Index::Index;
48
57 Dmc(const Temperature& temperature,
58 const RelativeHumidity& rh,
59 const Precipitation& prec,
60 const Dmc& dmc_previous,
61 int month,
62 MathSize latitude) noexcept;
66 static const Dmc Zero;
67 static const Dmc Invalid;
68};
72class Dc : public Index<Dc>
73{
74public:
76 using Index::Index;
78
86 Dc(const Temperature& temperature,
87 const Precipitation& prec,
88 const Dc& dc_previous,
89 int month,
90 MathSize latitude) noexcept;
94 static const Dc Zero;
95 static const Dc Invalid;
96};
100class Isi : public Index<Isi>
101{
102public:
109 Isi(MathSize value, const Speed& ws, const Ffmc& ffmc) noexcept;
115 Isi(const Speed& ws, const Ffmc& ffmc) noexcept;
119 static const Isi Zero;
120 static const Isi Invalid;
121private:
123 using Index::Index;
125};
129class Bui : public Index<Bui>
130{
131public:
138 Bui(MathSize value, const Dmc& dmc, const Dc& dc) noexcept;
144 Bui(const Dmc& dmc, const Dc& dc) noexcept;
148 static const Bui Zero;
149 static const Bui Invalid;
150private:
152 using Index::Index;
154};
158class Fwi : public Index<Fwi>
159{
160public:
167 Fwi(MathSize value, const Isi& isi, const Bui& bui) noexcept;
173 Fwi(const Isi& isi, const Bui& bui) noexcept;
177 static const Fwi Zero;
178 static const Fwi Invalid;
179private:
181 using Index::Index;
183};
187class Dsr : public Index<Dsr>
188{
189public:
191 using Index::Index;
193
197 explicit Dsr(const Fwi& fwi) noexcept;
201 static const Dsr Zero;
202 static const Dsr Invalids;
203};
208 : public Weather
209{
210public:
214 static const FwiWeather Zero;
215 static const FwiWeather Invalid;
219 FwiWeather() noexcept;
225 FwiWeather(istringstream* iss,
226 string* str);
237 FwiWeather(const FwiWeather& yesterday,
238 const int month,
239 const MathSize latitude,
240 const Temperature& temp,
241 const RelativeHumidity& rh,
242 const Wind& wind,
243 const Precipitation& prec);
258 const RelativeHumidity& rh,
259 const Wind& wind,
260 const Precipitation& prec,
261 const Ffmc& ffmc,
262 const Dmc& dmc,
263 const Dc& dc,
264 const Isi& isi,
265 const Bui& bui,
266 const Fwi& fwi) noexcept;
280 const RelativeHumidity& rh,
281 const Wind& wind,
282 const Precipitation& prec,
283 const Ffmc& ffmc,
284 const Dmc& dmc,
285 const Dc& dc,
286 const Isi& isi,
287 const Bui& bui) noexcept;
299 const RelativeHumidity& rh,
300 const Wind& wind,
301 const Precipitation& prec,
302 const Ffmc& ffmc,
303 const Dmc& dmc,
304 const Dc& dc) noexcept;
311 FwiWeather(const FwiWeather& wx, const Speed& ws, const Ffmc& ffmc) noexcept;
315 ~FwiWeather() override = default;
320 constexpr FwiWeather(FwiWeather&& rhs) noexcept = default;
325 constexpr FwiWeather(const FwiWeather& rhs) noexcept = default;
331 FwiWeather& operator=(FwiWeather&& rhs) noexcept = default;
337 FwiWeather& operator=(const FwiWeather& rhs) = default;
342 [[nodiscard]] constexpr const Ffmc& ffmc() const
343 {
344 return ffmc_;
345 }
350 [[nodiscard]] constexpr const Dmc& dmc() const
351 {
352 return dmc_;
353 }
358 [[nodiscard]] constexpr const Dc& dc() const
359 {
360 return dc_;
361 }
366 [[nodiscard]] constexpr const Isi& isi() const
367 {
368 return isi_;
369 }
374 [[nodiscard]] constexpr const Bui& bui() const
375 {
376 return bui_;
377 }
382 [[nodiscard]] constexpr const Fwi& fwi() const
383 {
384 return fwi_;
385 }
390 [[nodiscard]] constexpr MathSize mcFfmcPct() const
391 {
392 return mc_ffmc_pct_;
393 }
398 [[nodiscard]] constexpr MathSize mcDmcPct() const
399 {
400 return mc_dmc_pct_;
401 }
406 [[nodiscard]] constexpr MathSize mcFfmc() const
407 {
408 return mcFfmcPct() / 100.0;
409 }
414 [[nodiscard]] constexpr MathSize mcDmc() const
415 {
416 return mcDmcPct() / 100.0;
417 }
422 [[nodiscard]] constexpr MathSize ffmcEffect() const
423 {
424 return ffmc_effect_;
425 }
426private:
434 FwiWeather(const FwiWeather& wx,
435 const Wind& wind,
436 const Ffmc& ffmc,
437 const Isi& isi) noexcept;
444 FwiWeather(const FwiWeather& wx, const Wind& wind, const Ffmc& ffmc) noexcept;
472 MathSize mc_ffmc_pct_;
476 MathSize mc_dmc_pct_;
480 MathSize ffmc_effect_;
481};
482[[nodiscard]] constexpr bool operator<(const FwiWeather& lhs, const FwiWeather& rhs)
483{
484 if (lhs.temp() == rhs.temp())
485 {
486 if (lhs.rh() == rhs.rh())
487 {
488 if (lhs.wind() == rhs.wind())
489 {
490 if (lhs.prec() == rhs.prec())
491 {
492 if (lhs.ffmc() == rhs.ffmc())
493 {
494 if (lhs.dmc() == rhs.dmc())
495 {
496 if (lhs.dc() == rhs.dc())
497 {
498 assert(lhs.isi() == rhs.isi());
499 assert(lhs.bui() == rhs.bui());
500 assert(lhs.fwi() == rhs.fwi());
501 }
502 return lhs.dc() < rhs.dc();
503 }
504 return lhs.dmc() < rhs.dmc();
505 }
506 return lhs.ffmc() < rhs.ffmc();
507 }
508 return lhs.prec() < rhs.prec();
509 }
510 return lhs.wind() < rhs.wind();
511 }
512 return lhs.rh() < rhs.rh();
513 }
514 return lhs.temp() < rhs.temp();
515}
516[[nodiscard]] constexpr bool operator!=(const FwiWeather& lhs, const FwiWeather& rhs)
517{
518 return lhs.temp() != rhs.temp()
519 || lhs.rh() != rhs.rh()
520 || lhs.wind() != rhs.wind()
521 || lhs.prec() != rhs.prec()
522 || lhs.ffmc() != rhs.ffmc()
523 || lhs.dmc() != rhs.dmc()
524 || lhs.dc() != rhs.dc()
525 || lhs.isi() != rhs.isi()
526 || lhs.bui() != rhs.bui()
527 || lhs.fwi() != rhs.fwi();
528}
529[[nodiscard]] constexpr bool operator==(const FwiWeather& lhs, const FwiWeather& rhs)
530{
531 return !(lhs != rhs);
532}
533constexpr auto FFMC_MOISTURE_CONSTANT = 147.27723;
534constexpr MathSize ffmc_to_moisture(const MathSize ffmc) noexcept
535{
536 return FFMC_MOISTURE_CONSTANT * (101.0 - ffmc) / (59.5 + ffmc);
537}
538constexpr MathSize ffmc_to_moisture(const Ffmc& ffmc) noexcept
539{
540 return ffmc_to_moisture(ffmc.asValue());
541}
542constexpr MathSize moisture_to_ffmc(const MathSize m) noexcept
543{
544 return (59.5 * (250.0 - m) / (FFMC_MOISTURE_CONSTANT + m));
545}
546constexpr Ffmc ffmc_from_moisture(const MathSize m) noexcept
547{
548 return Ffmc(moisture_to_ffmc(m));
549}
550}
A wrapper around a MathSize to ensure correct types are used.
Definition Index.h:15
constexpr Index() noexcept
Construct with a value of 0.
Definition Index.h:28
Build-up Index value.
Definition FWI.h:130
static const Bui Zero
Build-up Index of 0.
Definition FWI.h:148
Bui(MathSize value, const Dmc &dmc, const Dc &dc) noexcept
Calculate Build-up Index and verify previous value is within tolerance of calculated value.
Definition FWI.cpp:498
Drought Code value.
Definition FWI.h:73
Dc(const Temperature &temperature, const Precipitation &prec, const Dc &dc_previous, int month, MathSize latitude) noexcept
Calculate Drought Code.
Definition FWI.cpp:403
static const Dc Zero
Drought Code of 0.
Definition FWI.h:94
Duff Moisture Code value.
Definition FWI.h:43
Dmc(const Temperature &temperature, const RelativeHumidity &rh, const Precipitation &prec, const Dmc &dmc_previous, int month, MathSize latitude) noexcept
Duff Moisture Code.
Definition FWI.cpp:354
static const Dmc Zero
Duff Moisture Code of 0.
Definition FWI.h:66
Danger Severity Rating value.
Definition FWI.h:188
static const Dsr Zero
Danger Severity Rating of 0.
Definition FWI.h:201
Dsr(const Fwi &fwi) noexcept
Calculate Danger Severity Rating.
Definition FWI.cpp:615
Fine Fuel Moisture Code value.
Definition FWI.h:15
static const Ffmc Zero
Fine Fuel Moisture Code of 0.
Definition FWI.h:36
Ffmc(const Temperature &temperature, const RelativeHumidity &rh, const Speed &ws, const Precipitation &prec, const Ffmc &ffmc_previous) noexcept
Calculate Fine Fuel Moisture Code.
Definition FWI.cpp:297
A Weather value with calculated FWI indices.
Definition FWI.h:209
constexpr const Bui & bui() const
Build-up Index.
Definition FWI.h:374
FwiWeather() noexcept
Construct with 0 for all values.
Definition FWI.cpp:737
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
Fwi fwi_
Fire Weather Index.
Definition FWI.h:468
constexpr const Isi & isi() const
Initial Spread Index.
Definition FWI.h:366
constexpr const Ffmc & ffmc() const
Fine Fuel Moisture Code.
Definition FWI.h:342
Ffmc ffmc_
Fine Fuel Moisture Code.
Definition FWI.h:448
Isi isi_
Initial Spread Index.
Definition FWI.h:460
MathSize mc_ffmc_pct_
Moisture content (ratio) based on Ffmc.
Definition FWI.h:472
constexpr const Fwi & fwi() const
Fire Weather Index.
Definition FWI.h:382
constexpr MathSize mcFfmcPct() const
Moisture content (%) based on Ffmc.
Definition FWI.h:390
static const FwiWeather Zero
FwiWeather with 0 for all Indices.
Definition FWI.h:214
Bui bui_
Build-up Index.
Definition FWI.h:464
MathSize ffmc_effect_
Ffmc effect used for spread.
Definition FWI.h:480
constexpr MathSize mcFfmc() const
Moisture content (ratio) based on Ffmc.
Definition FWI.h:406
Dc dc_
Drought Code.
Definition FWI.h:456
Dmc dmc_
Duff Moisture Code.
Definition FWI.h:452
constexpr MathSize mcDmcPct() const
Moisture content (%) based on Dmc.
Definition FWI.h:398
MathSize mc_dmc_pct_
Moisture content (ratio) based on Dmc.
Definition FWI.h:476
constexpr MathSize mcDmc() const
Moisture content (ratio) based on Dmc.
Definition FWI.h:414
constexpr const Dc & dc() const
Drought Code.
Definition FWI.h:358
Fire Weather Index value.
Definition FWI.h:159
Fwi(MathSize value, const Isi &isi, const Bui &bui) noexcept
Calculate Fire Weather Index and verify previous value is within tolerance of calculated value.
Definition FWI.cpp:563
static const Fwi Zero
Fire Weather Index of 0.
Definition FWI.h:177
Initial Spread Index value.
Definition FWI.h:101
static const Isi Zero
Initial Spread Index of 0.
Definition FWI.h:119
Isi(MathSize value, const Speed &ws, const Ffmc &ffmc) noexcept
Calculate Initial Spread Index and verify previous value is within tolerance of calculated value.
Definition FWI.cpp:437
Precipitation (1hr accumulation) (mm)
Definition Weather.h:287
Relative humidity as a percentage.
Definition Weather.h:34
Speed in kilometers per hour.
Definition Weather.h:49
Temperature in degrees Celsius.
Definition Weather.h:19
Collection of weather indices used for calculating FwiWeather.
Definition Weather.h:302
constexpr const Temperature & temp() const noexcept
Temperature (Celsius)
Definition Weather.h:352
constexpr const Wind & wind() const noexcept
Wind (km/h)
Definition Weather.h:368
constexpr const RelativeHumidity & rh() const noexcept
Relative Humidity (%)
Definition Weather.h:360
constexpr const Precipitation & prec() const noexcept
Precipitation (1hr accumulation) (mm)
Definition Weather.h:376
Wind with a Speed and Direction.
Definition Weather.h:139