Cell2Fire
A large-scale forest fire simulator.
Loading...
Searching...
No Matches
Cells.h
1#ifndef CELLS
2#define CELLS
3
4// include stuff
5#include "Ellipse.h"
6#include "ReadArgs.h"
7
8#include <math.h>
9#include <stdio.h>
10#include <string>
11#include <unordered_map>
12#include <unordered_set>
13#include <vector>
14
15using namespace std;
16
17std::vector<int> adjacentCells(int cell, int nrows, int ncols);
18/*
19 * Weather structure
20 */
21typedef struct
22{
23 float ws, waz, rh, tmp, apcp, ffmc, dmc, dc, isi, bui,
24 fwi; // David: some variables only used on C2FK and not on C2FSB and
25 // viceversa
26} weatherDF; // David: Moved here to simplify inclusion
27
28typedef struct
29{
30 char fueltype[4];
31 float ws, saz, cur, ps, cbh, ccf, cbd, elev, tmp, rh, lat, lon, ffmc, bui, gfl,
32 tree_height; // David: some variables only used on C2FK and not on C2FSB and
33 // viceversa
34 int waz, nftype, FMC, time, pattern, mon, jd, jd_min, pc, pdf;
35} inputs; // David: Moved here to simplify inclusion
36
37typedef struct
38{
39 char fueltype[4];
40 float p1, p2, p3; // hros coef
41 float q1, q2, q3; // flame length coef
42 float q, bui0, cfl; // fbp params
43 float cbh, fmc, fl, h;
44 int nftype;
46
47typedef struct
48{
49 float hffmc, sfc, csi, fl, fh, a, b, c, rss, angle, ros_active, cfb, se, rso, fmc, sfi, isi, be, sf, raz, wsv, ff,
50 crown_intensity, crown_flame_length, max_flame_length;
51 char covertype;
52 int crown, jd_min, jd;
53} main_outs;
54
55typedef struct
56{
57 float ros, dist, rost, cfb, fc, cfc, time, rss, isi;
58 char fd;
59 double fi;
61
62typedef struct
63{
64 float lb, area, perm, pgr, lbt;
65} snd_outs;
66
67class Cells
68{
69 // TODO: find where to put the enums
70 public:
71 // immutable
72 int id;
73 int fType;
74 int realId;
75 double _ctr2ctrdist;
76 double area;
77 double perimeter;
78
79 std::string fType2;
80 std::vector<int> coord; // maybe change this into a tuple or class CP: 2-tuple (int)
81 // std::unordered_map<std::string, int> adjacents; // CP: dictionary {string:
82 // [int array]}
83
84 string FTypeD[3];
85 string StatusD[5];
86
87 // mutable
88 int status;
89 int hPeriod;
90 int fireStarts;
91 int harvestStarts;
92 int fireStartsSeason;
93 int burntP;
94 int tYears;
95
96 std::unordered_map<int, std::vector<int>> gMsgList; // {40 -> [1, 2, 3] }
97 std::unordered_map<int, std::vector<int>> gMsgListSeason;
98 std::unordered_map<int, double> fireProgress; // CP: dictionary {int: double}
99 std::unordered_map<int, double> angleDict; // CP: dictionary {int: double}
100 std::unordered_map<int, double> ROSAngleDir; // CP: dictionary {int: double|None} Instead of None we
101 // can use a determined number like -9999 = None TODO:
102 // maybe int : double
103 std::unordered_map<int, double> distToCenter; // CP: dictionary {int: double}
104 std::unordered_map<int, int> angleToNb; // CP: dictionary {double: int}
105
106 // TODO: reference to shared object
107
108 // constructor and methods here
109 Cells(int _id,
110 double _area,
111 std::vector<int> _coord,
112 int _fType,
113 std::string _fType2,
114 double _perimeter,
115 int _status,
116 int _realId);
117
118 void initializeFireFields(std::vector<std::vector<int>>& coordCells,
119 std::unordered_set<int>& availSet,
120 int cols,
121 int rows); // TODO: need TYPE
122 void ros_distr_old(double thetafire, double forward, double flank, double back);
123 double rhoTheta(double theta, double a, double b);
124 void ros_distr(double thetafire, double forward, double flank, double back, double EFactor);
125 void ros_distr_V2(double thetafire, double a, double b, double c, double EFactor);
126
127 std::vector<int> manageFire(int period,
128 std::unordered_set<int>& AvailSet,
129 inputs df[],
130 fuel_coefs* coef,
131 std::vector<std::vector<int>>& coordCells,
132 std::unordered_map<int, Cells>& Cells_Obj,
133 arguments* args,
134 weatherDF* wdf_ptr,
135 std::vector<double>* FSCell,
136 std::vector<float>* crownMetrics,
137 bool& activeCrown,
138 double randomROS,
139 int perimeterCells,
140 std::vector<int>& crownState,
141 std::vector<float>& crownFraction,
142 std::vector<float>& surfFraction,
143 std::vector<float>& Intensities,
144 std::vector<float>& RateOfSpreads,
145 std::vector<float>& SurfaceFlameLengths,
146 std::vector<float>& CrownFlameLengths,
147 std::vector<float>& CrownIntensities,
148 std::vector<float>& MaxFlameLengths);
149
150 std::vector<int> manageFireBBO(int period,
151 std::unordered_set<int>& AvailSet,
152 inputs* df_ptr,
153 fuel_coefs* coef,
154 std::vector<std::vector<int>>& coordCells,
155 std::unordered_map<int, Cells>& Cells_Obj,
156 arguments* args,
157 weatherDF* wdf_ptr,
158 std::vector<double>* FSCell,
159 std::vector<float>* crownMetrics,
160 bool& activeCrown,
161 double randomROS,
162 int perimeterCells,
163 std::vector<float>& EllipseFactors,
164 std::vector<int>& crownState,
165 std::vector<float>& crownFraction,
166 std::vector<float>& surfFraction,
167 std::vector<float>& Intensities,
168 std::vector<float>& RateOfSpreads,
169 std::vector<float>& FlameLengths);
170
171 bool get_burned(int period,
172 int season,
173 int NMsg,
174 inputs df[],
175 fuel_coefs* coef,
176 arguments* args,
177 weatherDF* wdf_ptr,
178 bool& activeCrown,
179 int perimeterCells);
180
181 // void set_Adj(std::unordered_map<std::string, int> & adjacentCells);
182
183 void setStatus(int status_int);
184
185 std::string getStatus();
186
187 bool ignition(int period,
188 int year,
189 std::vector<int>& ignitionPoints,
190 inputs* df_ptr, // WORKING CHECK OK
191 fuel_coefs* coef,
192 arguments* args,
193 weatherDF* wdf_ptr,
194 bool& activeCrown,
195 int perimeterCells);
196
197 void harvested(int id, int period);
198
199 void print_info();
200
201 private:
202 double allocate(double offset, double base, double ros1, double ros2);
203 float slope_effect(float elev_i, float elev_j, int cellsize);
204};
205
206#endif
Definition Cells.h:68
bool get_burned(int period, int season, int NMsg, inputs df[], fuel_coefs *coef, arguments *args, weatherDF *wdf_ptr, bool &activeCrown, int perimeterCells)
Checks if a cell that has been reached by fire begins to burn.
Definition Cells.cpp:1145
void initializeFireFields(std::vector< std::vector< int > > &coordCells, std::unordered_set< int > &availSet, int cols, int rows)
Initializes fire-related fields for the cell during ignition.
Definition Cells.cpp:124
std::vector< int > manageFireBBO(int period, std::unordered_set< int > &AvailSet, inputs *df_ptr, fuel_coefs *coef, std::vector< std::vector< int > > &coordCells, std::unordered_map< int, Cells > &Cells_Obj, arguments *args, weatherDF *wdf_ptr, std::vector< double > *FSCell, std::vector< float > *crownMetrics, bool &activeCrown, double randomROS, int perimeterCells, std::vector< float > &EllipseFactors, std::vector< int > &crownState, std::vector< float > &crownFraction, std::vector< float > &surfFraction, std::vector< float > &Intensities, std::vector< float > &RateOfSpreads, std::vector< float > &FlameLengths)
Definition Cells.cpp:821
void setStatus(int status_int)
Sets a cell's fire status (0: Available, 1: Burning, 2: Burnt, 3: Harvested, 4: Non Fuel).
Definition Cells.cpp:1243
std::vector< int > manageFire(int period, std::unordered_set< int > &AvailSet, inputs df[], fuel_coefs *coef, std::vector< std::vector< int > > &coordCells, std::unordered_map< int, Cells > &Cells_Obj, arguments *args, weatherDF *wdf_ptr, std::vector< double > *FSCell, std::vector< float > *crownMetrics, bool &activeCrown, double randomROS, int perimeterCells, std::vector< int > &crownState, std::vector< float > &crownFraction, std::vector< float > &surfFraction, std::vector< float > &Intensities, std::vector< float > &RateOfSpreads, std::vector< float > &SurfaceFlameLengths, std::vector< float > &CrownFlameLengths, std::vector< float > &CrownIntensities, std::vector< float > &MaxFlameLengths)
Manage's the cell's response to being reached by fire.
Definition Cells.cpp:467
void ros_distr(double thetafire, double forward, double flank, double back, double EFactor)
Definition Cells.cpp:311
std::string getStatus()
Retrieve the cell's fire status.
Definition Cells.cpp:1254
void ros_distr_old(double thetafire, double forward, double flank, double back)
Definition Cells.cpp:240
void ros_distr_V2(double thetafire, double a, double b, double c, double EFactor)
Distributes the Rate of Spread (ROS) across the cell's neighbors based on fire direction and ellipse ...
Definition Cells.cpp:374
bool ignition(int period, int year, std::vector< int > &ignitionPoints, inputs *df_ptr, fuel_coefs *coef, arguments *args, weatherDF *wdf_ptr, bool &activeCrown, int perimeterCells)
Ignites a cell.
Definition Cells.cpp:1285
double rhoTheta(double theta, double a, double b)
Calculates the radial distance for a given angle in an ellipse defined by its semi-major and semi-min...
Definition Cells.cpp:287
Definition ReadArgs.h:16
Definition Cells.h:56
Definition Cells.h:38
Definition Cells.h:29
Definition Cells.h:48
Definition Cells.h:63
Definition Cells.h:22