Skip to content

Commit 669af30

Browse files
committed
feat: add --active-front for simultaneous multi-cell ignition (active fire front)
Reads cells from ActiveFront.csv and ignites them all at t=0; the engine grows an elliptical front from each and they coalesce. Touches ReadArgs (flag parsing), Cell2Fire.h (ActiveFrontCells member), and Cell2Fire.cpp (read file + ignite all seeds in RunIgnition).
1 parent 567c70b commit 669af30

4 files changed

Lines changed: 75 additions & 1 deletion

File tree

Cell2Fire/Cell2Fire.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,29 @@ Cell2Fire::Cell2Fire(arguments _args) : CSVForest(_args.InFolder + "fuels", " ")
511511
}
512512
}
513513

514+
/* Active front: read a set of cells to ignite simultaneously (ActiveFront.csv) */
515+
if (this->args.ActiveFront)
516+
{
517+
std::string sepAF = ",";
518+
std::string activeFile = args.InFolder + "ActiveFront.csv";
519+
CSVReader CSVActive(activeFile, sepAF);
520+
std::vector<std::vector<std::string>> ActiveDF = CSVActive.getData(activeFile);
521+
this->ActiveFrontCells.clear();
522+
for (size_t rr = 1; rr < ActiveDF.size(); ++rr) // skip header row
523+
{
524+
if (ActiveDF[rr].size() >= 2 && !ActiveDF[rr][1].empty())
525+
this->ActiveFrontCells.push_back(std::stoi(ActiveDF[rr][1]));
526+
}
527+
if (!this->ActiveFrontCells.empty())
528+
{
529+
this->args.TotalYears = 1; // the front is a single scenario
530+
this->IgnitionPoints = std::vector<int>(1, this->ActiveFrontCells[0]);
531+
this->IgnitionSets = std::vector<std::vector<int>>(1);
532+
std::cout << "Active front: " << this->ActiveFrontCells.size()
533+
<< " seed cells will ignite simultaneously" << std::endl;
534+
}
535+
}
536+
514537
/* BBO Tuning factors (only the ones present in the instances*/
515538
if (this->args.BBOTuning)
516539
{
@@ -1051,6 +1074,46 @@ Cell2Fire::RunIgnition(boost::random::mt19937 generator, int ep)
10511074
}
10521075
}
10531076

1077+
// --- Active front: ignite all remaining seed cells simultaneously ---
1078+
if (this->args.ActiveFront)
1079+
{
1080+
bool anyAF = false;
1081+
for (size_t k = 0; k < this->ActiveFrontCells.size(); ++k)
1082+
{
1083+
int fc = this->ActiveFrontCells[k];
1084+
if (fc < 1 || fc > this->nCells)
1085+
continue;
1086+
if (this->burntCells.find(fc) != this->burntCells.end()) // already lit (e.g. first cell)
1087+
{
1088+
anyAF = true;
1089+
continue;
1090+
}
1091+
if (this->statusCells[fc - 1] >= 3) // non-burnable / harvested / firebreak
1092+
continue;
1093+
if (this->Cells_Obj.find(fc) == this->Cells_Obj.end())
1094+
InitCell(fc);
1095+
std::unordered_map<int, Cells>::iterator itf = this->Cells_Obj.find(fc);
1096+
if (itf->second.getStatus() != "Available" || itf->second.fType == 0)
1097+
continue;
1098+
std::vector<int> ipf = { fc };
1099+
if (itf->second.ignition(this->fire_period[this->year - 1],
1100+
this->year, ipf, &df[fc - 1],
1101+
this->coef_ptr, this->args_ptr,
1102+
&(this->wdf[this->weatherPeriod]),
1103+
this->activeCrown, this->perimeterCells))
1104+
{
1105+
this->statusCells[fc - 1] = 1;
1106+
this->nIgnitions++;
1107+
this->burningCells.insert(fc);
1108+
this->burntCells.insert(fc);
1109+
this->availCells.erase(fc);
1110+
anyAF = true;
1111+
}
1112+
}
1113+
if (anyAF)
1114+
this->noIgnition = false;
1115+
}
1116+
10541117
// Plotter placeholder
10551118
if (this->args.OutputGrids)
10561119
{

Cell2Fire/Cell2Fire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Cell2Fire
103103
std::vector<string> fTypeCells2; // (long int&, const char [9]);
104104
std::vector<std::vector<std::string>> WeatherData;
105105
std::vector<int> IgnitionPoints;
106+
std::vector<int> ActiveFrontCells; // seed cells of an active front
106107
vector<int> burnedOutList;
107108
std::vector<double> FSCell;
108109
std::vector<float> crownMetrics;

Cell2Fire/ReadArgs.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ parseArgs(int argc, char* argv[], arguments* args_ptr)
110110
bool verbose_input = false;
111111
bool iplog_input = false;
112112
bool input_ignitions = false;
113+
bool active_front = false;
113114
bool out_grids = false;
114115
bool out_fl = false;
115116
bool out_intensity = false;
@@ -201,6 +202,14 @@ parseArgs(int argc, char* argv[], arguments* args_ptr)
201202
printf("Ignitions: %s \n", btoa(input_ignitions));
202203
}
203204

205+
//--active-front (ignite a set of cells simultaneously, read from ActiveFront.csv)
206+
if (cmdOptionExists(argv, argv + argc, "--active-front"))
207+
{
208+
active_front = true;
209+
input_ignitions = true; // active front uses the ignition-from-file path
210+
printf("Active front: %s \n", btoa(active_front));
211+
}
212+
204213
//--grids
205214
if (cmdOptionExists(argv, argv + argc, "--grids"))
206215
{
@@ -607,6 +616,7 @@ parseArgs(int argc, char* argv[], arguments* args_ptr)
607616
args_ptr->verbose = verbose_input;
608617
args_ptr->IgnitionsLog = iplog_input;
609618
args_ptr->Ignitions = input_ignitions;
619+
args_ptr->ActiveFront = active_front;
610620
args_ptr->OutputGrids = out_grids;
611621
args_ptr->FinalGrid = out_finalgrid;
612622
args_ptr->PromTuned = prom_tuned;

Cell2Fire/ReadArgs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typedef struct
1616
{
1717
std::string InFolder, OutFolder, WeatherOpt, HarvestPlan, Simulator, WeatherWeightsFile;
1818
bool OutMessages, OutFl, OutIntensity, OutRos, OutCrown, OutCrownConsumption, OutSurfConsumption, Trajectories,
19-
NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS, UseWeatherWeights;
19+
NoOutput, verbose, IgnitionsLog, Ignitions, OutputGrids, FinalGrid, PromTuned, Stats, BBOTuning, AllowCROS, UseWeatherWeights, ActiveFront;
2020
float ROSCV, ROSThreshold, CROSThreshold, HFIThreshold, HFactor, FFactor, BFactor, EFactor, FirePeriodLen;
2121
float CBDFactor, CCFFactor, ROS10Factor, CROSActThreshold;
2222
int MinutesPerWP, MaxFirePeriods, TotalYears, TotalSims, NWeatherFiles, IgnitionRadius, seed, nthreads, FMC,

0 commit comments

Comments
 (0)