Skip to content

Commit bee9429

Browse files
committed
Add flame length summaries
1 parent af55d82 commit bee9429

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

Cell2Fire/Cell2Fire.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ std::unordered_map<int, std::vector<int>> HarvestedCells;
4949
std::vector<int> NFTypesCells;
5050
std::unordered_map<int, int> IgnitionHistory;
5151
std::unordered_map<int, std::string> WeatherHistory;
52-
std::unordered_map<int, std::vector<float>> Statistics;
52+
std::unordered_map<int, std::vector<float>> StatisticsPerCell;
5353
std::unordered_map<int, float> meanSurfaceFlameLength;
5454
std::unordered_map<int, float> meanCrownFlameLength;
5555
std::unordered_map<int, float> meanMaxFlameLength;
56+
std::unordered_map<int, std::vector<float>> StatisticsPerSim;
5657

5758
/******************************************************************************
5859
Utils
@@ -1824,37 +1825,55 @@ Cell2Fire::Results()
18241825
this->rows, this->cols, this->xllcorner, this->yllcorner, this->cellSide, this->maxFlameLengths);
18251826
}
18261827

1827-
// Flame Length Statistics
1828+
// Flame Length StatisticsPerCell
18281829
// This will be used to store accumulated flame lengths across simulations
18291830
if (this->args.Stats)
18301831
{
1831-
1832+
float totalCrown = 0;
1833+
float totalSurface = 0;
1834+
float maxPerSim = 0;
1835+
std::vector<float> simStats;
18321836
for (int cell : this->burntCells)
18331837
{
1834-
std::vector<float> flameLengthMeans;
1838+
std::vector<float> cellFlameLengthMeans;
18351839

18361840
float surfaceFlameLength = this->surfaceFlameLengths[cell] / args.TotalSims;
18371841
meanSurfaceFlameLength[cell] += surfaceFlameLength;
1838-
flameLengthMeans.push_back(meanSurfaceFlameLength[cell]);
1842+
cellFlameLengthMeans.push_back(meanSurfaceFlameLength[cell]);
1843+
totalSurface += this->surfaceFlameLengths[cell];
1844+
maxPerSim = max(maxPerSim, this->surfaceFlameLengths[cell]);
18391845

18401846
if ((this->args.AllowCROS) && (this->args.Simulator != "C"))
18411847
{
18421848
float crownFlameLength = this->crownFlameLengths[cell] / args.TotalSims;
18431849
float maxFlameLength = this->maxFlameLengths[cell] / args.TotalSims;
18441850
meanCrownFlameLength[cell] += crownFlameLength;
18451851
meanMaxFlameLength[cell] += maxFlameLength;
1846-
flameLengthMeans.push_back(meanCrownFlameLength[cell]);
1847-
flameLengthMeans.push_back(meanMaxFlameLength[cell]);
1852+
cellFlameLengthMeans.push_back(meanCrownFlameLength[cell]);
1853+
cellFlameLengthMeans.push_back(meanMaxFlameLength[cell]);
1854+
totalCrown += this->maxFlameLengths[cell];
1855+
maxPerSim = max(maxPerSim, this->crownFlameLengths[cell]);
18481856
}
1849-
1850-
Statistics[cell] = { flameLengthMeans };
1857+
StatisticsPerCell[cell] = { cellFlameLengthMeans };
1858+
}
1859+
simStats.push_back(totalSurface / BCells);
1860+
if ((this->args.AllowCROS) && (this->args.Simulator != "C"))
1861+
{
1862+
simStats.push_back(totalCrown / BCells);
18511863
}
1864+
simStats.push_back(maxPerSim);
1865+
1866+
StatisticsPerSim[this->sim] = { simStats };
1867+
std::ostringstream oss;
1868+
std::string Stats = this->statsFolder + "statisticsPerSim" + oss.str() + ".csv";
1869+
CSVWriter simStatsFile(Stats);
1870+
simStatsFile.printStats(StatisticsPerSim, "sim", (this->args.AllowCROS) && (this->args.Simulator != "C"));
18521871
if (currentSim == args.TotalSims)
18531872
{
18541873
std::ostringstream oss;
1855-
std::string Statsname = this->statsFolder + "statistics" + oss.str() + ".csv";
1874+
std::string Statsname = this->statsFolder + "statisticsPerCell" + oss.str() + ".csv";
18561875
CSVWriter statsFile(Statsname);
1857-
statsFile.printStats(Statistics);
1876+
statsFile.printStats(StatisticsPerCell, "cell", (this->args.AllowCROS) && (this->args.Simulator != "C"));
18581877
}
18591878
}
18601879

Cell2Fire/ReadArgs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ parseArgs(int argc, char* argv[], arguments* args_ptr)
209209
if (cmdOptionExists(argv, argv + argc, "--statistics"))
210210
{
211211
out_stats = true;
212-
printf("Statistics: %d \n", out_stats);
212+
printf("StatisticsPerCell: %d \n", out_stats);
213213
}
214214

215215
//--bbo
@@ -629,7 +629,7 @@ printArgs(arguments args)
629629
std::cout << "FinalGrid: " << args.FinalGrid << std::endl;
630630
std::cout << "PromTuned: " << args.PromTuned << std::endl;
631631
std::cout << "BBOTuning: " << args.BBOTuning << std::endl;
632-
std::cout << "Statistics: " << args.Stats << std::endl;
632+
std::cout << "StatisticsPerCell: " << args.Stats << std::endl;
633633
std::cout << "noOutput: " << args.NoOutput << std::endl;
634634
std::cout << "verbose: " << args.verbose << std::endl;
635635
std::cout << "seed: " << args.seed << std::endl;
@@ -661,7 +661,7 @@ printArgs(arguments args)
661661
std::cout << "FinalGrid: " << args.FinalGrid << std::endl;
662662
std::cout << "PromTuned: " << args.PromTuned << std::endl;
663663
std::cout << "BBOTuning: " << args.BBOTuning << std::endl;
664-
std::cout << "Statistics: " << args.Stats << std::endl;
664+
std::cout << "StatisticsPerCell: " << args.Stats << std::endl;
665665
std::cout << "noOutput: " << args.NoOutput << std::endl;
666666
std::cout << "verbose: " << args.verbose << std::endl;
667667
std::cout << "Ignition Points Log: " << args.IgnitionsLog << std::endl;

Cell2Fire/WriteCSV.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,21 @@ CSVWriter::printIgnitions(std::unordered_map<int, int> ignitionsHistory,
288288
}
289289

290290
void
291-
CSVWriter::printStats(std::unordered_map<int, std::vector<float>> statistics)
291+
CSVWriter::printStats(std::unordered_map<int, std::vector<float>> statistics, std::string type, bool hasCrown)
292292
{
293293
std::ofstream ofs(fileName, std::ofstream::out);
294294

295295
// Print column titles
296-
ofs << "cell,surfaceFlameLength,crownFlameLength,maxFlameLength\n";
296+
ofs << type << ",surfaceFlameLengthMean";
297+
if (hasCrown)
298+
{
299+
ofs << type << ",crownFlameLengthMean,maxFlameLength";
300+
}
301+
else if (type == "sim")
302+
{
303+
ofs << ",maxFlameLength";
304+
}
305+
ofs << std::endl;
297306

298307
// Iterate through the unordered_map using iterator
299308
for (auto it = statistics.begin(); it != statistics.end(); ++it)

Cell2Fire/WriteCSV.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CSVWriter
4545
void printWeather(std::vector<std::string> weatherHistory);
4646
void printIgnitions(std::unordered_map<int, int> ignitionsHistory,
4747
std::unordered_map<int, std::string> weatherHistory);
48-
void printStats(std::unordered_map<int, std::vector<float>> statistics);
48+
void printStats(std::unordered_map<int, std::vector<float>> statistics, std::string type, bool hasCrown);
4949
void printCSV_V2(int rows, int cols, std::vector<int> statusCells);
5050
// Function to create a directory
5151
void MakeDir(std::string pathPlot);

0 commit comments

Comments
 (0)