forked from forefireAPI/firefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataBroker.h
310 lines (243 loc) · 13.3 KB
/
DataBroker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
Copyright (C) 2012 ForeFire Team, SPE, UniversitŽ de Corse.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
*/
#ifndef DATABROKER_H_
#define DATABROKER_H_
#include "DataLayer.h"
#include "GradientDataLayer.h"
#include "NCXYZTDataLayer.h"
#include "FuelDataLayer.h"
#include "ArrayDataLayer.h"
#include "BurningRatioLayer.h"
#include "TwoTimeArrayLayer.h"
#include "PropagativeLayer.h"
#include "FluxLayer.h"
#include "FFArrays.h"
#include "AtmosphericData.h"
#include "ParallelData.h"
#include "SimulationParameters.h"
using namespace std;
namespace libforefire {
class FireDomain;
class FluxModel;
template<typename T> class MultiplicativeLayer;
/*! \class DataBroker
* \brief Data Broker for a fire simulation
*
* DataBroker implements a data management tool tailored for FireDomain.
* Several layers of available data are stored and methods to communicate
* the desired values to the FireDomain are defined. The FireDomain has
* first registered the properties needed by the propagation model and
* DataBroker is responsible for accessing these values at given location
* and time. DataBroker also manages the storing of atmospheric properties
* (for coupled fire/atmopshere simulations) and parallel-related arrays
* (for parallel simulations).
*/
class DataBroker {
// Information concerning the fire model
FireDomain* domain; /*!< pointers to the domain */
static SimulationParameters* params;
// Information concerning the atmospheric model
FFPoint atmoSWCorner, atmoNECorner; /*!< spatial limit of the domain */
size_t atmosphericNx, atmosphericNy; /*!< size of the atmospheric matrices */
AtmosphericData* atmosphericData; /*!< pointer to the atmospheric-related data */
// Information concerning the embedded parallelism
ParallelData* parallelData; /*!< pointer to the parallel-related data */
// map of the data layers
map<string, DataLayer<double>* > layersMap; /*!< map of the different scalar layers stored in the data broker */
map<string, DataLayer<double>* >::iterator ilayer; /*!< iterator of the list of layers */
map<string, FluxLayer<double>* > fluxLayersMap; /*!< map of the different flux layers stored in the data broker */
map<string, FluxLayer<double>* >::iterator flayer; /*!< iterator of the list of layers */
// List of the data layers
list<DataLayer<double>* > layers; /*!< list of the different layers stored in the data broker */
list<FluxLayer<double>* > fluxLayers; /*!< list of the different flux layers stored in the data broker */
// Pre-defined layers
static DataLayer<double>* fuelLayer; /*!< predefined layer for fuel parameters */
static DataLayer<double>* dummyLayer; /*!< predefined layer for a dummy variable (optimization) */
static DataLayer<double>* altitudeLayer; /*!< predefined layer for the altitude (optimization) */
static DataLayer<double>* slopeLayer; /*!< predefined layer for the slope (optimization) */
static DataLayer<double>* moistureLayer; /*!< predefined layer for moisture (optimization) */
static DataLayer<double>* temperatureLayer; /*!< predefined layer for temperature (optimization) */
static DataLayer<double>* windULayer; /*!< predefined layer for longitudinal wind (optimization) */
static DataLayer<double>* windVLayer; /*!< predefined layer for lateral wind (optimization) */
vector<map<string, double> > fuelPropertiesTable; /*!< values of the properties of the fuels */
void extractFuelProperties(vector<map<string, double> >, ForeFireModel*);
/* Handling of the propagation data brokers */
typedef int (*propPropGetter)(FireNode*, PropagationModel*, int);
typedef map<string, propPropGetter> propGetterMap;
static propGetterMap makePGmap(){
// Construction of the map from strings to desired property computation
propGetterMap pgM;
pgM["fieldSpeed"] = &getDummy;
pgM["altitude"] = &getAltitude;
pgM["slope"] = &getSlope;
pgM["windU"] = &getWindU;
pgM["windV"] = &getWindV;
pgM["normalWind"] = &getNormalWind;
pgM["fuel"] = &getFuelProperties;
pgM["moisture"] = &getMoisture;
pgM["temperature"] = &getTemperature;
pgM["frontDepth"] = &getFrontDepth;
pgM["frontCurvature"] = &getFrontCurvature;
pgM["frontFastestInSection"] = &getFrontFastestInSection;
return pgM;
}
static const propGetterMap propPropertiesGetters; /*!< map to predefined functors to compute properties */
vector<vector<propPropGetter> > propDataGetters; /*!< vector of functors to compute properties for propagation models (optimization) */
vector<size_t> numPropDataGetters; /*!< vector of the number of functors for propagation models (optimization) */
/* Handling of the propagation data brokers */
typedef int (*fluxPropGetter)(FFPoint, const double&, FluxModel*, int);
typedef map<string, fluxPropGetter> fluxGetterMap;
static fluxGetterMap makeFGmap(){
// Construction of the map from strings to desired property computation
fluxGetterMap pgM;
pgM["fuel"] = &getFuelProperties;
pgM["moisture"] = &getMoisture;
pgM["altitude"] = &getAltitude;
pgM["windU"] = &getWindU;
pgM["windV"] = &getWindV;
return pgM;
}
static const fluxGetterMap fluxPropertiesGetters; /*!< map to predefined functors to compute properties */
vector<vector<fluxPropGetter> > fluxDataGetters; /*!< vector of functors to compute properties for flux models (optimization) */
vector<size_t> numFluxDataGetters; /*!< vector of the number of functors for flux models (optimization) */
/* list of all the properties needed by the models in use */
vector<string> neededProperties;
void dropProperty(string);
/*! \brief getting the desired property for given firenode */
double getProperty(FireNode*, string);
/*! \brief getting the desired property for given location */
double getProperty(FFPoint, string);
/* Pre-defined function for propagation models */
/*! \brief predefined function for getting the value of a dummy variable for given firenode */
static int getDummy(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the fuel parameters at firenode location */
static int getFuelProperties(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the moisture at firenode location */
static int getMoisture(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the temperature at firenode location */
static int getTemperature(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the altitude for given firenode */
static int getAltitude(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the slope for given firenode */
static int getSlope(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the longitudinal wind for given firenode */
static int getWindU(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the transverse wind for given firenode */
static int getWindV(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the normal wind for given firenode */
static int getNormalWind(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the front depth */
static int getFrontDepth(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the front curvature */
static int getFrontCurvature(FireNode*, PropagationModel*, int);
/*! \brief predefined function for getting the front fastest speed nearby in the section */
static int getFrontFastestInSection(FireNode*, PropagationModel*, int);
/* Pre-defined function for flux models */
/*! \brief predefined function for getting the fuel parameters at given location and time */
static int getFuelProperties(FFPoint, const double&, FluxModel*, int);
/*! \brief predefined function for getting the moisture at given location and time */
static int getMoisture(FFPoint, const double&, FluxModel*, int);
/*! \brief predefined function for getting the altitude for given location and time */
static int getAltitude(FFPoint, const double&, FluxModel*, int);
/*! \brief predefined function for getting the longitudinal wind for given location and time */
static int getWindU(FFPoint, const double&, FluxModel*, int);
/*! \brief predefined function for getting the transverse wind for given location and time */
static int getWindV(FFPoint, const double&, FluxModel*, int);
/*! \brief common initialization (for all constructors) */
void commonInitialization();
/*! \brief retrieving the south-west point in an NcFile */
FFPoint getNetCDFSWCorner(NcVar*);
/*! \brief retrieving the time origin in an NcFile */
double getNetCDFTimeOrigin(NcVar*);
/*! \brief retrieving the south-west point in an NcFile */
FFPoint getNetCDFSpatialSpan(NcVar*);
/*! \brief retrieving the time origin in an NcFile */
double getNetCDFTimeSpan(NcVar*);
/*! \brief loading a NCXYZTDataLayer from an NcFile */
XYZTDataLayer<double>* constructXYZTLayerFromFile(NcFile*, string,int);
/*! \brief loading a FuelDataLayer from an NcFile */
FuelDataLayer<double>* constructFuelLayerFromFile(NcFile*);
/*! \brief loading a PropagativeLayer from an NcFile */
PropagativeLayer<double>* constructPropagativeLayerFromFile(NcFile*, string);
/*! \brief loading a FluxLayer from an NcFile */
FluxLayer<double>* constructFluxLayerFromFile(NcFile*, string);
/*! \brief testing inclusion of a variable domain inside the fire domain */
bool isRelevantData(FFPoint&, FFPoint&);
double getNetCDFFileVersion(NcVar* var);
/*! \transpose data from fortran netcdf*/
double* readAndTransposeFortranProjectedField(NcVar* , const size_t& ,const size_t& , const size_t& ,const size_t& ,bool , int );
int* readAndTransposeIntFortranProjectedField(NcVar* , const size_t& ,const size_t& , const size_t& ,const size_t&, bool , int );
public:
// Pre-defined layers
static FluxLayer<double>* heatFluxLayer; /*!< predefined layer for heat flux */
static XYZTDataLayer<double>* PwindULayer; /*!< predefined layer for longitudinal wind (optimization) */
static XYZTDataLayer<double>* PwindVLayer; /*!< predefined layer for lateral wind (optimization) */
/*! \brief default constructor */
DataBroker(FireDomain* = 0);
/*! \brief destructor */
virtual ~DataBroker();
/*! \brief registering a propagation model */
void registerPropagationModel(PropagationModel*);
void updateFuelValues(PropagationModel*, string key, double value );
/*! \brief registering a flux model */
void registerFluxModel(FluxModel*);
/*! \brief registering a layer in the data broker */
void registerLayer(string, DataLayer<double>*);
/*! \brief registering a flux layer in the data broker */
void registerFluxLayer(string, FluxLayer<double>*);
/*! \brief loadFromNCFile function for NetCDF files */
void loadFromNCFile(string);
/*! \brief reading a table from an ascii file */
void readTableFromAsciiFile(string, vector<map<string, double> >&);
/*! \brief splitting a string according to a delimiter */
void tokenize(const string&, vector<string>&, const string&);
/*! \brief initializing the atmospheric layers */
void setAtmosphericDomain(const FFPoint&, const FFPoint&
, const size_t&, const size_t&);
void initializeAtmosphericLayers(const double&, const size_t&, const size_t&);
/*! \brief initializing the propagative layer */
void initializePropagativeLayer(string);
/*! \brief initializing the flux layers */
void initializeFluxLayers(string);
/*! \brief initializing the parallel properties */
void initializeParallelProperties(const size_t&, const size_t&
, const size_t&, const double&);
/*! \brief insuring the presence of all needed layers */
void insureLayersExistence();
/*! \brief initialize flux layers */
void initFluxLayers(const double&);
/*! \brief default constant layer constructor */
void addConstantLayer(string, const double&);
/*! \brief typical double layer constructor */
void addLayer(string name, double &x0 , double &y0, double& t0, double& width , double& height, double& timespan, size_t& nnx, size_t& nny, size_t& nnz, double* values);
/*! \brief accessor to the desired data layer */
DataLayer<double>* getLayer(const string&);
/*! \brief accessor to the desired flux layer */
FluxLayer<double>* getFluxLayer(const string&);
/*! \brief recomputes flux actives surfaces for each model */
void computeActiveSurfacesFlux(const double&);
/*! \brief accessor to the desired set of properties for propagation models */
void getPropagationData(PropagationModel*, FireNode*);
bool* optimizedPropDataBroker;
/*! \brief accessor to the desired set of properties for flux models */
void getFluxData(FluxModel*, FFPoint&, const double&);
bool* optimizedFluxDataBroker;
/*! \brief accessor to the data contained in the desired layer */
void getMatrix(string, const FFPoint&, const FFPoint&
, const double&, FFArray<double>**);
string printLayers();
};
}
#endif /* DATABROKER_H_ */