FireSTARR
Loading...
Searching...
No Matches
Settings.h
1/* SPDX-License-Identifier: AGPL-3.0-or-later */
2#ifndef FS_SETTINGS_H
3#define FS_SETTINGS_H
4#include "stdafx.h"
5#include "FuelLookup.h"
6namespace fs
7{
8namespace settings
9{
10class Settings;
11Settings& instance() noexcept;
13{
14public:
15 OutputDateOffsets(const string value) noexcept;
16 OutputDateOffsets() noexcept = default;
17 OutputDateOffsets(const OutputDateOffsets& rhs) = default;
18 OutputDateOffsets(OutputDateOffsets&& rhs) = default;
19 OutputDateOffsets& operator=(const OutputDateOffsets& rhs) = default;
20 OutputDateOffsets& operator=(OutputDateOffsets&& rhs) = default;
21 // Original text that was parsed
22 [[nodiscard]] string text() const noexcept { return text_; }
23 // Days to output probability contours for (1 is start date, 2 is day after, etc.)
24 [[nodiscard]] vector<int> offsets() const noexcept { return output_date_offsets_; }
25 // Whatever the maximum value in the date offsets is
26 [[nodiscard]] int max() const noexcept { return max_date_offset_; }
27
28private:
29 string text_{};
30 // Days to output probability contours for (1 is start date, 2 is day after, etc.)
31 vector<int> output_date_offsets_{};
32 // Whatever the maximum value in the date offsets is
33 int max_date_offset_{0};
34};
36{
37public:
38 StaticCuring() noexcept = default;
39 StaticCuring(const int value) noexcept
40 : value_{[&]() {
41 // HACK: enforce bounds
42 logging::check_fatal(
43 0 > value || 100 < value, "Grass curing (%) must be in range [0-100] but got {:d}", value
44 );
45 return value;
46 }()}
47 { }
48 int value() const noexcept { return value_.value(); };
49 bool has_value() const noexcept { return value_.has_value(); }
50 string as_string() const noexcept
51 {
52 string result = has_value() ? std::format("{:d}", value()) : "";
53 return result;
54 }
55
56private:
57 std::optional<int> value_{};
58};
59enum class Mode
60{
61 Simulation,
62 Test,
63 Surface
64};
69{
70public:
71 static void setRoot(const string dir_binary, const string dir_root) noexcept;
72 const string getRoot() const noexcept;
73 const string getBinaryDirectory() const noexcept;
74 Settings() = delete;
75 Settings(const string dir_binary, const string dir_root) noexcept;
76 string create(const pushd& dir) const;
77 // save to directory in same format parse expects
78 void saveTo(const string& output_directory) const noexcept;
79 bool found(const string& key) const noexcept
80 {
81 auto& s = settings_.second;
82 return s.find(key) != s.end();
83 }
84
85public:
86 // general settings
87 Mode mode{Mode::Simulation};
88 // directory to put simulation outputs in
89 string output_directory{};
90 // .csv with weather streams
91 LazyPath wx_file_name{};
92 // name to use for log file inside output_directory
93 string log_file_name{"firestarr.log"};
94 // full path for log file
95 string log_file{};
96 // HACK: should be output_directory, but if log_file_name starts with '/' it could be anything
97 string log_directory() const
98 {
99 static const auto d = [&] {
100 const auto last_index = log_file.find_last_of('/') + 1;
101 return log_file.substr(0, last_index);
102 }();
103 return d;
104 }
105 // perimeter to use for igntion (empty if none)
106 LazyPath perimeter{};
107 // Whether or not to save individual grids
108 bool save_individual{false};
109 // Whether or not to run things asynchronously where possible
110 bool run_async{true};
111 // Whether or not to run deterministically (100% chance of spread & survival)
112 bool deterministic{false};
113 // Whether or not this is running in test mode
114 constexpr bool is_test() const { return Mode::Test == mode; }
115 // Whether or not this is running in surface mode
116 constexpr bool is_surface() const { return Mode::Surface == mode; }
117 // Whether or not to save grids as .asc
118 bool save_as_ascii{false};
119 // Whether or not to save grids as .tif
120 bool save_as_tiff{true};
121 // Whether or not to save points used for spread
122 bool save_points{false};
123 // Whether or not to save intensity grids
124 bool save_intensity{true};
125 // Whether or not to save probability grids
126 bool save_probability{true};
127 // Whether or not to save occurrence grids
128 bool save_occurrence{false};
129 // Whether or not to save simulation area grids
130 bool save_simulation_area{false};
131 // Whether or not to force greenup for all fires
132 bool force_greenup{false};
133 // Whether or not to force no greenup for all fires
134 bool force_no_greenup{false};
135 // Whether or not to search for a start location if start point is non-fuel
136 bool no_search{false};
137 // Static curing value to force for all fires
138 StaticCuring static_curing{};
139 // Minimum rate of spread before fire is considered to be spreading (m/min)
140 MathSize minimum_ros{0.0};
141 // Maximum distance that the fire is allowed to spread in one step (# of cells)
142 MathSize maximum_spread_distance{0.0};
143 // Minimum Fine Fuel Moisture Code required for spread during the day
144 MathSize minimum_ffmc{0.0};
145 // Minimum Fine Fuel Moisture Code required for spread during the night
146 MathSize minimum_ffmc_at_night{0.0};
147 // Offset from UTC to use for entire simulation (hours)
148 std::optional<DurationSize> utc_offset{};
149 // Offset from sunrise at which the day is considered to start (hours)
150 DurationSize offset_sunrise{0.0};
151 // Offset from sunrise at which the day is considered to end (hours)
152 DurationSize offset_sunset{0.0};
153 // Default Percent Conifer to use for M1/M2 fuels where none is specified (%)
154 int default_percent_conifer{0};
155 // Default Percent Dead Fir to use for M3/M4 fuels where none is specified (%)
156 int default_percent_dead_fir{0};
157 // The maximum fire intensity for the 'low' range of intensity (kW/m)
158 int intensity_max_low{0};
159 // The maximum fire intensity for the 'moderate' range of intensity (kW/m)
160 int intensity_max_moderate{0};
161 // Confidence required before simulation stops (% / 100)
162 ThresholdSize confidence_level{0.0};
163 // Salt to use for random seeds
164 size_t salt{0};
165 // Maximum time simulation can run before it is ended and whatever results it has are used (s)
166 size_t maximum_time_seconds{0};
167 // Time between generating interim outputs (s)
168 size_t interim_output_interval_seconds{0};
169 // Minimum number of simulations that must run before stopping
170 size_t minimum_simulation_count{0};
171 // Minimum number of simulations with any spread that must run before stopping
172 size_t minimum_active_simulation_count{0};
173 // Maximum number of simulations before stopping and whatever results it has are used
174 size_t maximum_simulation_count{0};
175 // Weight to give to Scenario part of thresholds=
176 ThresholdSize threshold_scenario_weight{0.0};
177 // Weight to give to daily part of thresholds
178 ThresholdSize threshold_daily_weight{0.0};
179 // Weight to give to hourly part of thresholds
180 ThresholdSize threshold_hourly_weight{0.0};
181 // Root directory that raster inputs are stored in
182 LazyPath raster_root{};
183 // Name of file that defines fuel lookup table
184 LazyFuelLookup fuel_lookup{};
185 // Days to output probability contours for (1 is start date, 2 is day after, etc.)
186 OutputDateOffsets output_date_offsets{};
187 FwiWeather get_weather() const;
188 // FIX: need to get rain since noon yesterday to start of this hourly weather
189 Precipitation apcp_prev{Precipitation::Zero()};
190
191public:
192 // normal mode only variables
193 // initial fire size (ha)
194 std::optional<size_t> initial_size{};
195
196public:
197 // normal or test mode variables
198 std::optional<tm> start_date{};
199 std::optional<MathSize> latitude{};
200 std::optional<MathSize> longitude{};
201
202public:
203 // test mode only variables
204 // name of fuel to use for test
205 std::optional<string> fuel_name{};
206 // test every combination of settings for tests
207 std::optional<bool> test_all{};
208 // number of hours to run tests for
209 std::optional<MathSize> hours{};
210
211public:
212 // test/surface mode variables
213 std::optional<Ffmc> ffmc{};
214 std::optional<Dmc> dmc{};
215 std::optional<Dc> dc{};
216 std::optional<MathSize> wind_direction{};
217 std::optional<MathSize> wind_speed{};
218 std::optional<SlopeSize> slope{};
219 std::optional<AspectSize> aspect{};
220
221private:
222 string dir_binary_;
223 string dir_root_;
224 // unparsed and found settings
225 std::pair<string_map<string>, string_map<string>> settings_;
226};
227}
228}
229#endif
Definition FuelLookup.h:118
Definition Util.h:338
Definition Util.h:403
Definition Settings.h:13
Reads and provides access to settings for the simulation.
Definition Settings.h:69
Definition Settings.h:36
A Weather value with calculated FWI indices.
Definition FWI.h:142
Definition Weather.h:93