Skip to content

Commit

Permalink
fuel table as direct ascii and removed some prints
Browse files Browse the repository at this point in the history
  • Loading branch information
forefire committed Jun 21, 2024
1 parent 6a2d927 commit 0e9d607
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 194 deletions.
9 changes: 5 additions & 4 deletions src/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ int Command::loadData(const string& arg, size_t& numTabs){
cout << "LoadData Warning : expecting 1 or 2 arguments" << endl;
return error;
}
cout<<" Loading data "<<args.size()<<endl;

SimulationParameters *simParam = SimulationParameters::GetInstance();
string path = simParam->GetPath(args[0]);

Expand Down Expand Up @@ -986,12 +986,12 @@ int Command::loadData(const string& arg, size_t& numTabs){

#else
simParam->setParameter("NetCDFfile", args[0]);
cout<<" Loading data "<<args[0]<<endl;

try
{
NcFile dataFile(path.c_str(), NcFile::read);
if (!dataFile.isNull()) {
cout<<" NC0 data "<<endl;
NcVar domVar = dataFile.getVar("domain");
if (!domVar.isNull()) {
map<string,NcVarAtt> attributeList = domVar.getAtts();
Expand Down Expand Up @@ -1038,11 +1038,12 @@ int Command::loadData(const string& arg, size_t& numTabs){
int year, yday;
if (simParam->ISODateDecomposition(args[1], secs, year, yday))
{
cout<<"loading at time "<<args[1]<<endl;

simParam->setInt("refYear", year);
simParam->setInt("refDay", yday);
simParam->setInt("refTime", secs);
simParam->setParameter("ISOdate", args[1]);

}

string com = "FireDomain[sw=("+simParam->getParameter("SWx")+".,"+simParam->getParameter("SWy")+".,"+simParam->getParameter("SWz")+".);ne=(";
Expand Down
47 changes: 45 additions & 2 deletions src/DataBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ void DataBroker::commonInitialization() {
<< params->getParameter("ForeFireDataDirectory") << '/'
<< params->getParameter("fuelsTableFile");
*/
infile << params->GetPath(params->getParameter("fuelsTableFile"));
readTableFromAsciiFile(infile.str(), fuelPropertiesTable);
std::string paramTable = params->getParameter("fuelsTable");
if (paramTable != "1234567890") {
readTableFromString(paramTable, fuelPropertiesTable);
} else {
std::ostringstream infile;
infile << params->GetPath(params->getParameter("fuelsTableFile"));
readTableFromAsciiFile(infile.str(), fuelPropertiesTable);
}

}

void DataBroker::updateFuelValues(PropagationModel* model, string key, double value){
Expand Down Expand Up @@ -529,6 +536,42 @@ bool DataBroker::isRelevantData(FFPoint& SW, FFPoint& ext) {
return true;
}

void DataBroker::readTableFromString(const std::string& data,
std::vector<std::map<std::string, double>>& table) {
std::istringstream dataStream(data);
std::string line;
const std::string delimiter = ";";
std::vector<std::string> paramNames;

// Get the first line to extract parameter names
if (!std::getline(dataStream, line)) {
throw std::runtime_error("ERROR: could not read the header line from data.");
}
tokenize(line, paramNames, delimiter);

// Process the rest of the data
std::vector<std::string> vals;
double dval;
while (std::getline(dataStream, line)) {
vals.clear();
tokenize(line, vals, delimiter);
if (vals.size() != paramNames.size()) {
throw std::runtime_error("ERROR: Number of values does not match number of parameters for fuel " + vals[0]);
}

std::map<std::string, double> currentMap;
for (size_t pos = 0; pos < vals.size(); ++pos) {
std::istringstream iss(vals[pos]);
if (!(iss >> dval)) {
throw std::runtime_error("ERROR: could not cast " + vals[pos] +
" into a suitable value for parameter " + paramNames[pos] +
" of fuel " + vals[0]);
}
currentMap[paramNames[pos]] = dval;
}
table.push_back(std::move(currentMap));
}
}

void DataBroker::readTableFromAsciiFile(string filename,
vector<map<string, double> >& table) {
Expand Down
3 changes: 3 additions & 0 deletions src/DataBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ class DataBroker {

/*! \brief reading a table from an ascii file */
void readTableFromAsciiFile(string, vector<map<string, double> >&);
/*! \brief reading a table from an sttring variable */

void readTableFromString(const std::string&, vector<map<string, double> >&);

/*! \brief splitting a string according to a delimiter */
void tokenize(const string&, vector<string>&, const string&);
Expand Down
2 changes: 1 addition & 1 deletion src/FireDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ void FireDomain::loadWindDataInBinary(double refTime){
<<params->getParameter("NetCDFfile");
*/
infile << params->GetPath(params->getParameter("NetCDFfile"));
cout<<"reading in FireDom Constructor Common I"<<params->getParameter("NetCDFfile")<<endl;

dataBroker->initializePropagativeLayer(infile.str());

/* initializations for the flux models */
Expand Down
4 changes: 2 additions & 2 deletions src/NCXYZTDataLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ template<typename T> class XYZTDataLayer : public DataLayer<T> {
interp = InterpolationBilinearDir;
}

if( interp == InterpolationBilinear){
/* if( interp == InterpolationBilinear){
cout<<"layer "<<name<<" is mode InterpolationBilinear"<<endl;
}
if( interp == InterpolationBilinearT){
Expand All @@ -198,7 +198,7 @@ template<typename T> class XYZTDataLayer : public DataLayer<T> {
}
if( interp == InterpolationBilinearDir){
cout<<"layer "<<name<<" is mode InterpolationBilinear Scalar Dir (8 directions)"<<endl;
}
}*/

}
/*! \brief destructor */
Expand Down
Binary file removed tools/3nestFFCASE/.DS_Store
Binary file not shown.
114 changes: 3 additions & 111 deletions tools/barbaggio.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"YOR2TO3": 60
},
"ignitions": [
{"when": "2024-01-03T10:36:00", "latitude": 42.689245, "longitude": 9.3864812}
{"when": "2024-01-03T11:40:00", "latitude": 42.689245, "longitude": 9.3864812}
],
"case_path": "%s/"%orig,
"template_path": "/Users/filippi_j/soft/firefront/tools/3nestFFCASE/",
Expand Down Expand Up @@ -90,7 +90,7 @@
gen_AF_case = False
gen_2D_VTK_OUT = False
gen_3D_VTK_OUT = False
gen_KML_OUT = True
gen_KML_OUT = False
gen_TESTFUEL_case = False

OUTKMLDOMAINFILE = CAST["case_path"]+CAST["OUTKMLDOMAINFILE"]
Expand Down Expand Up @@ -244,7 +244,7 @@

if gen_KML_OUT:
from preprocessing.ffToGeoJson import genKMLFiles
genKMLFiles(PGDFILES[-1], BMAPFILE, FFINPUTPATTERN, BMAPKMLOUT,frontsKMLOUT, everyNFronts=6, change_color_every=1,btslice=(40,-1))
genKMLFiles(PGDFILES[-1], BMAPFILE, FFINPUTPATTERN, BMAPKMLOUT,frontsKMLOUT, everyNFronts=20, change_color_every=10000000000)

from preprocessing.ffToGeoJson import plotRos
#plotRos(PGDFILES[-1], BMAPFILE,max_speed_filter=1000.0)
Expand All @@ -260,114 +260,6 @@
from datetime import datetime



# define when to start
# define the domain
#

cost = [0.0,
0.0,
0.0,
210.17010116577148,
211.17010116577148,
215.17010116577148,
221.42010116577148,
229.67010116577148,
432.80348205566406,
1968.0598907470703,
2022.0598907470703,
2299.4276733398438,
2949.2632446289062,
4105.273971557617,
15482.962337493896,
20914.563625335693,
20958.063625335693,
22070.49808883667,
22102.74808883667,
22152.99808883667,
27016.63991165161,
31189.866333007812,
31412.628520965576,
33319.78584098816,
37538.17907142639,
42307.246057510376,
45969.47225379944,
47950.97472572327,
63450.30722236633,
98820.76568984985,
118991.89973831177,
165543.5011806488,
207644.5391407013,
258222.29362487793,
316281.03370666504,
359526.27380371094,
426399.09272644046,
471431.36740753177,
568360.2472064209,
627504.1055247497,
645412.9739634704,
659830.8771464538,
755253.0878855896,
804791.1836268615,
825648.5333583069,
865845.019369812,
888656.672583313,
955530.7864253235,
1026989.1899516296,
1120100.1706092071,
1237810.4050776672,
1356820.6299311828,
1514884.2269732666,
1594973.6059386444,
1651007.5541236114,
1683435.6126587105,
1731498.5213243675,
1739892.421066494,
1770438.2120802116,
1782285.448363514,
1818582.7460586738,
1861542.8454639625,
1894287.3541576576,
1905846.0894405555,
1929709.776379795,
1939955.0624038887,
1969903.5098488044,
1995118.1327755165,
2026537.5029518318,
2054908.0466148567,
2056578.453730793,
2093923.470576496,
2110355.661647053,
2131127.224284382,
2141263.9343216135,
2160388.001452656,
2167340.813575001,
2171339.1651680185,
2185996.7539436533,
2190421.6003219797,
2195660.7494308664,
2198974.6313583567,
2202753.9343979075,
2206021.3943664744,
2210215.363146992,
2221235.047381611,
2227777.806933613,
2235665.1993667795,
2237372.2564346506,
2247969.6464073374,
2249192.6416084482,
2250594.816216679,
2250638.816216679,
2265639.499686451,
2282383.091773243,
2282427.591773243,
2284826.036002369,
2286531.68581316,
2286576.93581316,
2290015.165564747,
2300200.7319557383,
2304126.8798134043]

def plotArea(larea,cf):
areas = [area / 10000 for area, _ in larea] # Convert from m² to hectares
dates = [date for _, date in larea]
Expand Down
Loading

0 comments on commit 0e9d607

Please sign in to comment.