Cell2Fire
A large-scale forest fire simulator.
Loading...
Searching...
No Matches
Cell2Fire.h
1#ifndef CELL2FIRE
2#define CELL2FIRE
3
4// Headers
5#include "Cells.h"
6#include "DataGenerator.h"
7#include "FuelModelKitral.h"
8#include "FuelModelSpain.h"
9#include "Lightning.h"
10#include "ReadArgs.h"
11#include "ReadCSV.h"
12#include "Spotting.h"
13#include "WriteCSV.h"
14
15// Include libraries
16#include <algorithm>
17#include <cmath>
18#include <iostream>
19#include <math.h>
20#include <memory>
21#include <random>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <string>
26#include <unordered_map>
27#include <unordered_set>
28#include <vector>
29
30using namespace std;
31
33{
34 // DFs
35 private:
36 CSVReader CSVWeather;
37 CSVReader CSVForest;
38
39 public:
40 // Main inputs
41 arguments args;
42 arguments* args_ptr;
43 fuel_coefs* coef_ptr;
44 fuel_coefs coefs[18];
45
46 // Integers
47 int sim;
48 int rows;
49 int cols;
50 int widthSims;
51 int weatherPeriod = 0;
52 int year = 1;
53 int gridNumber = 0;
54 int weatherperiod = 0;
55 int counter_wt = 0;
56 long int nCells;
57 int nIgnitions = 0;
58 double xllcorner;
59 double yllcorner;
60 // Booleans
61 bool noIgnition = true; // None = -1
62 bool activeCrown = false;
63 bool messagesSent = false;
64 bool repeatFire = false;
65 bool done = false;
66 bool noMessages = false;
67
68 // Doubles
69 double cellSide;
70 double areaCells;
71 double perimeterCells;
72 double ROSRV;
73
74 // Strings
75 string gridFolder;
76 string messagesFolder;
77 string rosFolder;
78 string crownFolder;
79 string surfaceIntensityFolder;
80 string crownIntensityFolder;
81 string sfbFolder;
82 string cfbFolder;
83 string surfaceFlameLengthFolder;
84 string maxFlameLengthFolder;
85 string crownFlameLengthFolder;
86 string historyFolder;
87 string ignitionsFolder;
88
89 // Vectors
90 std::vector<int> fire_period;
91 std::vector<std::vector<int>> coordCells;
92 std::vector<std::unordered_map<std::string, int>> adjCells;
93 std::vector<std::vector<std::string>> DF;
94 std::vector<std::vector<std::string>> WDist;
95 std::vector<std::string> WeatherHistory;
96 std::vector<float> ignProb; // (long int&, int);
97 std::vector<int> statusCells; //(long int, int);
98 std::vector<int> fTypeCells; // (long int&, int);
99 std::vector<string> fTypeCells2; // (long int&, const char [9]);
100 std::vector<std::vector<std::string>> WeatherDF;
101 std::vector<int> IgnitionPoints;
102 vector<int> burnedOutList;
103 std::vector<double> FSCell;
104 std::vector<float> crownMetrics;
105 std::vector<int> crownState;
106 std::vector<float> surfaceIntensities;
107 std::vector<float> crownIntensities;
108 std::vector<float> crownFraction;
109 std::vector<float> surfFraction;
110 std::vector<float> RateOfSpreads;
111 std::vector<float> surfaceFlameLengths;
112 std::vector<float> crownFlameLengths;
113 std::vector<float> maxFlameLengths;
114 std::vector<std::vector<int>> IgnitionSets;
115 // std::vector<int> IgnitionHistory;
116
117 // Sets
118 std::unordered_set<int> availCells;
119 std::unordered_set<int> nonBurnableCells;
120 std::unordered_set<int> burningCells;
121 std::unordered_set<int> burntCells;
122 std::unordered_set<int> harvestCells;
123
124 // Cells Dictionary
125 std::unordered_map<int, Cells> Cells_Obj;
126
127 // Constructor
128 Cell2Fire(arguments args);
129
130 // Methods
131 void InitCell(int id);
132 void reset(int rnumber, double rnumber2, int simExt);
133 bool RunIgnition(std::default_random_engine generator, int ep);
134 std::unordered_map<int, std::vector<int>> SendMessages();
135 void GetMessages(std::unordered_map<int, std::vector<int>> sendMessageList);
136 void Results();
137 void outputGrid();
138 void updateWeather();
139 void Step(std::default_random_engine generator, int ep);
140 void InitHarvested();
141
142 // Utils
143 std::vector<float> getROSMatrix();
144 std::vector<float> getFireProgressMatrix();
145};
146
147#endif
Definition ReadCSV.h:34
Definition Cell2Fire.h:33
void Step(std::default_random_engine generator, int ep)
Executes a single simulation step in the forest fire model.
Definition Cell2Fire.cpp:2278
void Results()
Generates and outputs simulation results, including fire behavior metrics, final grid status,...
Definition Cell2Fire.cpp:1835
std::unordered_map< int, std::vector< int > > SendMessages()
Message-sending phase of the fire spread model, where burning cells propagate fire messages to neighb...
Definition Cell2Fire.cpp:1336
std::vector< float > getROSMatrix()
Retrieves the Rate of Spread (ROS) matrix for all cells.
Definition Cell2Fire.cpp:2440
void GetMessages(std::unordered_map< int, std::vector< int > > sendMessageList)
Processes incoming fire messages to determine the ignition and progression of fire in cells.
Definition Cell2Fire.cpp:1553
std::vector< float > getFireProgressMatrix()
Retrieves the Fire Progress matrix for all cells.
Definition Cell2Fire.cpp:2453
void reset(int rnumber, double rnumber2, int simExt)
Resets the simulation environment for a new run.
Definition Cell2Fire.cpp:628
void InitCell(int id)
Initializes a cell within the simulation and adds it to the cell collection.
Definition Cell2Fire.cpp:583
bool RunIgnition(std::default_random_engine generator, int ep)
Simulates the ignition phase of the fire spread model for a single simulation year.
Definition Cell2Fire.cpp:1018
void updateWeather()
Updates the weather conditions during the simulation based on specified criteria.
Definition Cell2Fire.cpp:2219
void outputGrid()
Outputs the current state of the forest grid to a CSV file.
Definition Cell2Fire.cpp:2160
Definition ReadArgs.h:16
Definition Cells.h:38