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