forked from forefireAPI/firefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BurningMapLayer.h
177 lines (145 loc) · 5.37 KB
/
BurningMapLayer.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
/*
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 BURNINGMAPLAYER_H_
#define BURNINGMAPLAYER_H_
#include "DataLayer.h"
#include "FireDomain.h"
namespace libforefire {
/*! \class BurningMapLayer
* \brief Template data layer object specific to burning maps
*
* BurningMapLayer gives access to the burning map.
* Whenever getMatrix() is called the array is re-computed.
*/
template<typename T> class BurningMapLayer : public DataLayer<T> {
size_t nx; /*!< size of the array in the X direction */
size_t ny; /*!< size of the array in the Y direction */
size_t size; /*!< size of the array */
FireDomain* domain; /*!< domain related to the map of arrival times */
FFArray<T>* arrivalTimes; /*!< pointer to the array of arrival times */
double latestCall; /*!< time of the latest call to getMatrix() */
SimulationParameters* params;
/*! \brief interpolation method: lowest order */
T getNearestData(FFPoint);
public:
/*! \brief Default constructor */
BurningMapLayer() : DataLayer<T>() {};
/*! \brief Constructor with all necessary information */
BurningMapLayer(string name, FireDomain* fd
, const size_t& nnx, const size_t& nny)
: DataLayer<T>(name), nx(nnx), ny(nny), domain(fd) {
size = nx*ny;
arrivalTimes = new FFArray<T>("BMap", 0., nx, ny);
latestCall = -1.;
params = SimulationParameters::GetInstance();
};
/*! \brief Destructor */
virtual ~BurningMapLayer(){
delete arrivalTimes;
}
/*! \brief obtains the value at a given position in the array */
T getVal(size_t = 0, size_t = 0);
/*! \brief computes the value at a given firenode */
T getValueAt(FireNode*);
/*! \brief computes the value at a given location and time */
T getValueAt(FFPoint, const double&);
/*! \brief directly stores the desired values in a given array */
size_t getValuesAt(FireNode*, PropagationModel*, size_t);
/*! \brief directly stores the desired values in a given array */
size_t getValuesAt(FFPoint, const double&, FluxModel*, size_t);
/*! \brief getter to the pointer on the FFArray */
void getMatrix(FFArray<T>**, const double&);
/*! \brief stores data from a fortran array into the FFArray */
void setMatrix(string&, double*, const size_t&, size_t&, const double&);
/*! \brief print the related FFArray */
string print2D(size_t, size_t);
string print();
void dumpAsBinary(string, const double&
, FFPoint&, FFPoint&, size_t&, size_t&);
};
template<typename T>
T BurningMapLayer<T>::getVal(size_t i, size_t j){
return (*arrivalTimes)(i, j);
}
template<typename T>
T BurningMapLayer<T>::getValueAt(FireNode* fn){
return getNearestData(fn->getLoc());
}
template<typename T>
T BurningMapLayer<T>::getValueAt(FFPoint loc, const double& time){
return getNearestData(loc);
}
template<typename T>
size_t BurningMapLayer<T>::getValuesAt(FireNode* fn
, PropagationModel* model, size_t curItem){
return 0;
}
template<typename T>
size_t BurningMapLayer<T>::getValuesAt(FFPoint loc, const double& t
, FluxModel* model, size_t curItem){
return 0;
}
template<typename T>
T BurningMapLayer<T>::getNearestData(FFPoint loc){
cout<<"BurningMapLayer<T>::getNearestData() "
<<"shouldn't have been called"<<endl;
return 0.;
}
template<typename T>
void BurningMapLayer<T>::getMatrix(
FFArray<T>** matrix, const double& t){
if ( t != latestCall ){
for ( size_t i=0; i < nx; i++ ){
for ( size_t j=0; j < ny; j++ ){
(*arrivalTimes)(i,j) = domain->getArrivalTime(i, j);
}
}
latestCall = t;
}
// Affecting the computed matrix to the desired array
*matrix = arrivalTimes;
}
template<typename T>
void BurningMapLayer<T>::setMatrix(string& mname, double* inMatrix
, const size_t& sizein, size_t& sizeout, const double& time){
if ( arrivalTimes->getSize() == sizein ){
arrivalTimes->copyDataFromFortran(inMatrix);
} else {
cout<<"Error while trying to retrieve data for data layer "
<<this->getKey()<<", matrix size not matching";
}
}
template<typename T>
string BurningMapLayer<T>::print(){
return print2D(0,0);
}
template<typename T>
string BurningMapLayer<T>::print2D(size_t i, size_t j){
return arrivalTimes->print2D(i,j);
}
template<typename T>
void BurningMapLayer<T>::dumpAsBinary(string filename, const double& time
, FFPoint& SWC, FFPoint& NEC, size_t& nnx, size_t& nny){
/* writing the matrix in a binary file */
ostringstream outputfile;
outputfile<<filename<<"."<<this->getKey();
ofstream FileOut(outputfile.str().c_str(), ios_base::binary);
FileOut.write(reinterpret_cast<const char*>(&nx), sizeof(size_t));
FileOut.write(reinterpret_cast<const char*>(&ny), sizeof(size_t));
FileOut.write(reinterpret_cast<const char*>(arrivalTimes->getData()), arrivalTimes->getSize()*sizeof(T));
FileOut.close();
}
} /* namespace libforefire */
#endif /* BURNINGMAPLAYER_H_ */