forked from forefireAPI/firefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHalo.cpp
353 lines (292 loc) · 10.5 KB
/
Halo.cpp
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
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
*/
#include "Halo.h"
#include "FireDomain.h"
namespace libforefire {
// Static variables
const string Halo::FireNodesId = "FireNodesId";
const string Halo::FireNodesPosX = "FireNodesPosX";
const string Halo::FireNodesPosY = "FireNodesPosY";
const string Halo::FireNodesVelX = "FireNodesVelX";
const string Halo::FireNodesVelY = "FireNodesVelY";
const string Halo::FireNodesTime = "FireNodesTime";
bool Halo::outputs = false;
Halo::Halo() {
}
Halo::Halo(string hname, FireDomain* fd, list<FDCell*>& haloCells
, const size_t& istart, const size_t& jstart
, const size_t& iend, const size_t& jend
, const size_t& iinc, const size_t& jinc)
: name(hname) ,domain(fd), iComStart(istart), jComStart(jstart)
, iComEnd(iend), jComEnd(jend), iComIncrement(iinc), jComIncrement(jinc) {
cells = haloCells;
iCurrent = iComStart;
jCurrent = jComStart;
kCurrent = 0;
init = true;
isActive = true;
}
Halo::~Halo() {
// nothing to do
}
void Halo::writeHaloNodeList(const double& endChain, const double& endCom){
list<FireNodeData*> haloList;
double dpid, dnid;
/* clearing the preceding list and memory space */
while ( !nodeDataList.empty() ){
delete nodeDataList.back();
nodeDataList.pop_back();
}
/*-------------------------------*/
/* constructing the list of data */
/*-------------------------------*/
list<FDCell*>::iterator cell;
list<FireNode*>::iterator ifn;
for ( cell = cells.begin(); cell != cells.end(); ++cell ){
for ( ifn = (*cell)->fireNodes.begin(); ifn != (*cell)->fireNodes.end(); ++ifn ) {
(*ifn)->getPrev() == 0 ? dpid = 0. : dpid = (*ifn)->getPrev()->getIDtoDouble();
(*ifn)->getNext() == 0 ? dnid = 0. : dnid = (*ifn)->getNext()->getIDtoDouble();
haloList.push_back(new FireNodeData((*ifn)->getIDtoDouble()
, (*ifn)->getX(), (*ifn)->getY(), (*ifn)->getVx(), (*ifn)->getVy()
, (*ifn)->getTime(), dpid, dnid));
}
}
/* Arranging the list of data following the chains */
list<FireNodeData*> currentChain;
list<FireNodeData*>::iterator ifnd;
list<FireNodeData*>::iterator newifnd;
FireNodeData* tmpdata;
while ( !haloList.empty() ){
currentChain.clear();
/* choosing a seed for the chain */
FireNodeData* seed = haloList.front();
tmpdata = seed;
currentChain.push_front(tmpdata);
haloList.remove(tmpdata);
/* Populating the list with next
* nodes within incoming ones */
tmpdata = domain->idInList(seed->nid, haloList);
while ( tmpdata ){
currentChain.push_back(tmpdata);
haloList.remove(tmpdata);
tmpdata = domain->idInList(tmpdata->nid, haloList);
}
/* Populating the list with previous
* nodes within incoming ones */
tmpdata = domain->idInList(seed->pid, haloList);
while ( tmpdata ){
currentChain.push_front(tmpdata);
haloList.remove(tmpdata);
tmpdata = domain->idInList(tmpdata->pid, haloList);
}
/* Handling of the link nodes */
FireNode* firstOfChain = domain->getFireNodeByIDNeighborCells(
currentChain.front()->id, domain->getCell(currentChain.front()));
if ( firstOfChain != 0 ){
FireNode* prevOfChain = firstOfChain->getPrev();
currentChain.push_front(new FireNodeData(
prevOfChain->getIDtoDouble()
, prevOfChain->getX(), prevOfChain->getY()
, prevOfChain->getVx(), prevOfChain->getVy()
, prevOfChain->getTime()));
}
FireNode* lastOfChain = domain->getFireNodeByIDNeighborCells(
currentChain.back()->id, domain->getCell(currentChain.back()));
if ( lastOfChain != 0 ){
FireNode* nextOfChain = lastOfChain->getNext();
currentChain.push_back(new FireNodeData(
nextOfChain->getIDtoDouble()
, nextOfChain->getX(), nextOfChain->getY()
, nextOfChain->getVx(), nextOfChain->getVy()
, nextOfChain->getTime()));
}
/* pushing the current chain in the arranged halo list.
* If it is initialization, sending just the valid chains */
if ( isValid(currentChain) ){
for ( newifnd = currentChain.begin();
newifnd != currentChain.end(); ++newifnd ){
nodeDataList.push_back(*newifnd);
}
/* pushing the marker for the end of the chain */
nodeDataList.push_back(new FireNodeData(
0, 0, 0, 0, 0, endChain));
}
}
if ( init ) init = false;
/* Loading the communication matrices */
FFArray<double>* id;
domain->getDataLayer(FireNodesId)->getMatrix(&id, 0.);
FFArray<double>* posX;
domain->getDataLayer(FireNodesPosX)->getMatrix(&posX, 0.);
FFArray<double>* posY;
domain->getDataLayer(FireNodesPosY)->getMatrix(&posY, 0.);
FFArray<double>* velX;
domain->getDataLayer(FireNodesVelX)->getMatrix(&velX, 0.);
FFArray<double>* velY;
domain->getDataLayer(FireNodesVelY)->getMatrix(&velY, 0.);
FFArray<double>* time;
domain->getDataLayer(FireNodesTime)->getMatrix(&time, 0.);
list<FireNodeData*>::iterator haloNode;
size_t i, j, k;
initializePositionInMatrix();
getNewPositionInMatrix(i, j, k);
/* writing in the matrices, just before copy data to fortran and ATMO*/
for ( haloNode = nodeDataList.begin();
haloNode != nodeDataList.end(); ++haloNode ){
(*posX)(i,j,k) = (*haloNode)->posX;
(*posY)(i,j,k) = (*haloNode)->posY;
(*velX)(i,j,k) = (*haloNode)->velX;
(*velY)(i,j,k) = (*haloNode)->velY;
(*time)(i,j,k) = (*haloNode)->time;
(*id)(i,j,k) = (*haloNode)->id;
getNewPositionInMatrix(i, j, k);
}
(*time)(i,j,k) = endCom;
}
// reading from ATMO to create FNode info
void Halo::readHaloNodeList(const double& endCom, const double& noCom){
/* Loading the communication matrices */
FFArray<double>* id;
domain->getDataLayer(FireNodesId)->getMatrix(&id, 0.);
FFArray<double>* posX;
domain->getDataLayer(FireNodesPosX)->getMatrix(&posX, 0.);
FFArray<double>* posY;
domain->getDataLayer(FireNodesPosY)->getMatrix(&posY, 0.);
FFArray<double>* velX;
domain->getDataLayer(FireNodesVelX)->getMatrix(&velX, 0.);
FFArray<double>* velY;
domain->getDataLayer(FireNodesVelY)->getMatrix(&velY, 0.);
FFArray<double>* time;
domain->getDataLayer(FireNodesTime)->getMatrix(&time, 0.);
double tmpx, tmpy, tmpvx, tmpvy, t, sid;
size_t i, j, k;
FireNodeData* tmpData;
/* clearing the preceding list and memory space */
nodeDataList.clear();
initializePositionInMatrix();
getNewPositionInMatrix(i, j, k);
if ( (*time)(i,j,k) == noCom ) {
isActive = false;
if ( this == domain->southOuterHalo ) domain->southInnerHalo->isActive = false;
if ( this == domain->westOuterHalo ) domain->westInnerHalo->isActive = false;
if ( this == domain->northOuterHalo ) domain->northInnerHalo->isActive = false;
if ( this == domain->eastOuterHalo ) domain->eastInnerHalo->isActive = false;
return;
}
while ( (*time)(i,j,k) > endCom ) {
// getting the data
sid = (*id)(i,j,k);
tmpx = (*posX)(i,j,k);
tmpy = (*posY)(i,j,k);
tmpvx = (*velX)(i,j,k);
tmpvy = (*velY)(i,j,k);
t = (*time)(i,j,k);
tmpData = new FireNodeData(sid, tmpx, tmpy, tmpvx, tmpvy, t);
nodeDataList.push_back(tmpData);
getNewPositionInMatrix(i, j, k);
}
nodeDataList.push_back(new FireNodeData(0, 0, 0, 0, 0, endCom));
}
FireNode* Halo::getFireNodebyID(const double& sid){
long lsid = domain->getIDfromDouble(sid);
list<Halo*>::iterator halo;
list<FDCell*>::iterator cell;
FireNode* tmpfn = 0;
for ( cell = cells.begin(); cell != cells.end(); ++cell ){
tmpfn = (*cell)->getFirenodeByID(lsid);
if ( tmpfn ) return tmpfn;
}
return 0;
}
void Halo::initializePositionInMatrix(){
iCurrent = iComStart;
jCurrent = jComStart;
kCurrent = 0;
}
void Halo::getNewPositionInMatrix(size_t& i, size_t& j, size_t& k){
i = iCurrent;
j = jCurrent;
k = kCurrent;
/* incrementing for next call */
iCurrent += iComIncrement;
jCurrent += jComIncrement;
if ( iComIncrement == 1 and iCurrent > iComEnd ){
kCurrent++;
iCurrent = iComStart;
}
if ( jComIncrement == 1 and jCurrent > jComEnd ){
kCurrent++;
jCurrent = jComStart;
}
}
bool Halo::isValid(list<FireNodeData*>& chain){
/* asserting that the given chain is valid
* to be transmitted to other processors */
/* If it is initialization, everything is valid */
if ( init ) return true;
// Booleans to assert valid state
bool crossingInnerHalo = false;
// Iteration variables on the chain
list<FireNodeData*>::iterator cdata;
list<FireNodeData*>::iterator next = chain.begin();
++next;
list<FireNodeData*>::iterator last = chain.end();
--last;
string slink = "link";
const char* link = slink.c_str();
/* Scanning the chain for possible defects */
for ( cdata = chain.begin(); cdata != last; ++cdata ){
/* Checking that the chain crosses the inner halo */
if ( !crossingInnerHalo ){
if ( domain->getDomainID((*cdata)->id) == domain->getDomainID() )
crossingInnerHalo = true;
if ( domain->getDomainID((*next)->id) == domain->getDomainID() )
crossingInnerHalo = true;
FFPoint inter = domain->findIntersectionWithInnerFrontiers(*cdata, *next);
if ( inter.getX() != numeric_limits<double>::infinity() ) crossingInnerHalo = true;
}
/* Checking the distance between the markers */
if ( (*cdata)->distance(*next) > 4.*domain->getPerimeterResolution()
and (*cdata)->state != link and (*next)->state != link ){
if ( outputs ){
cout<<domain->getDomainID()
<<": Not taking into account the preceding chain as "<<(*cdata)->toString()
<<endl<<'\t'<<"and "<<(*next)->toString()<<" are too far away "
<<"("<< (*cdata)->distance(*next)<<" vs "
<<4.*domain->getPerimeterResolution()<<")"<<endl;
list<FireNodeData*>::iterator dat;
for ( dat = chain.begin(); dat != chain.end(); ++dat ){
cout<<domain->getDomainID()<<":"<<'\t'<<(*dat)->toString()<<endl;;
}
}
return false;
}
++next;
}
if ( !crossingInnerHalo ){
if ( outputs ){
cout<<domain->getDomainID()
<<": Not taking into account the preceding chain as "
<<"no intersection with the inner halo was found"<<endl;
}
return false;
}
/* If no defect is found, the chain is considered valid */
return true;
}
string Halo::getName(){
return name;
}
}