-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
962 lines (793 loc) · 30.4 KB
/
main.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
#include <hpx/hpx.hpp>
#include <hpx/hpx_init.hpp>
#include <libgeodecomp.h>
#include <libgeodecomp/communication/typemaps.h>
#include <libgeodecomp/communication/mpilayer.h>
#include <libgeodecomp/parallelization/serialsimulator.h>
#include <libgeodecomp/parallelization/stripingsimulator.h>
#include <libgeodecomp/storage/multicontainercell.h>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <vector>
#include <string>
#include <iomanip>
#include <sstream>
#include <math.h>
#include <boost/assign/std/vector.hpp>
#include <libgeodecomp/config.h>
#include <libgeodecomp/geometry/stencils.h>
#include <libgeodecomp/io/bovwriter.h>
#include <libgeodecomp/io/ppmwriter.h>
#include <libgeodecomp/io/simplecellplotter.h>
#include <libgeodecomp/io/simpleinitializer.h>
#include <libgeodecomp/io/tracingwriter.h>
#include <libgeodecomp/loadbalancer/oozebalancer.h>
#include <libgeodecomp/loadbalancer/tracingbalancer.h>
#include <libgeodecomp/misc/apitraits.h>
#include <libgeodecomp/storage/image.h>
#include "hull.h"
using namespace boost::assign;
using namespace LibGeoDecomp;
FloatCoord<2> origin;
FloatCoord<2> quadrantDim;
struct neighbor
{
int neighborID;
std::vector<int> sendNodes;
std::vector<int> recvNodes;
};
struct neighborTable
{
std::vector<neighbor> myNeighbors;
};
struct ownerTableEntry
{
int globalID;
int localID;
int ownerID;
};
struct element
{
std::vector<int> nodeIDs;
};
struct SubNode
{
int globalID;
int localID;
int alive;
int lastAlive;
FloatCoord<3> location;
std::vector<int> neighboringNodes;
};
// Each instance represents one subdomain of an ADCIRC unstructured grid
class DomainCell
{
public:
class API:
public::APITraits::HasCustomRegularGrid,
public::APITraits::HasUnstructuredGrid,
public::APITraits::HasPointMesh
{
public:
inline FloatCoord<2> getRegularGridSpacing()
{
return quadrantDim;
}
inline FloatCoord<2> getRegularGridOrigin()
{
return origin;
}
};
DomainCell(const LibGeoDecomp::FloatCoord<2>& center = FloatCoord<2>(), int id = 0, int outputStep = 0) :
center(center), // Coordinates of the center of the domain
id(id), // Integer ID of the domain
outputStep(outputStep)
{}
template<typename NEIGHBORHOOD>
void update(const NEIGHBORHOOD& hood, int nanoStep);
std::vector<SubNode> getBoundaryNodes(const int domainID) const
{
std::vector<int> outgoingNodeIDs;
std::vector<SubNode> outgoingNodes;
DomainCell domainCell = *this;
for (int i=0; i<domainCell.myNeighborTable.myNeighbors.size(); i++)
{
if (domainCell.myNeighborTable.myNeighbors[i].neighborID == domainID)
{
for (int j=0; j<domainCell.myNeighborTable.myNeighbors[i].sendNodes.size(); j++)
{
outgoingNodeIDs.push_back(domainCell.myNeighborTable.myNeighbors[i].sendNodes[j]);
}
}
}
for (int i=0; i<outgoingNodeIDs.size(); i++)
{
outgoingNodes.push_back(domainCell.localNodes[outgoingNodeIDs[i]]);
}
return outgoingNodes;
}
void pushNeighborNode(const int neighborID)
{
if (std::count(neighboringNodes.begin(), neighboringNodes.end(), neighborID) == 0) {
neighboringNodes << neighborID;
}
}
void pushNeighborTable(const neighborTable myNeighborTable)
{
this->myNeighborTable = myNeighborTable;
}
void pushLocalNode(const SubNode resNodeID)
{
this->localNodes[resNodeID.localID]=resNodeID;
}
const LibGeoDecomp::FloatCoord<2>& getPoint() const
{
return center;
}
std::vector<LibGeoDecomp::FloatCoord<2> > getShape() const
{
std::vector<FloatCoord<2> > points;
std::vector<FloatCoord<2> > ret;
//Move localNode locations into a vector of FloatCoord<2>'s
for (std::map<int, SubNode>::const_iterator i=localNodes.begin(); i!=localNodes.end(); ++i)
{
FloatCoord<2> point;
point[0]=i->second.location[0];
point[1]=i->second.location[1];
// If statement makes only resident nodes count for the shape
if (i->second.globalID != -1) {
points.push_back(point);
}
}
ret = convexHull(&points);
return ret;
}
LibGeoDecomp::FloatCoord<2> center; // Coordinates of the center
// of the Domain
int id; // ID of the domain
int alive;
int outputStep;
std::vector<int> neighboringNodes; //IDs of neighboring nodes
neighborTable myNeighborTable;
std::map<int,SubNode> localNodes;
};
// ContainerCell translates between the unstructured grid and the
// regular grid currently required by LGD
typedef ContainerCell<DomainCell, 1000> ContainerCellType;
// type definition required for callback functions below
typedef LibGeoDecomp::TopologiesHelpers::Topology<2, false, false, false > TopologyType;
typedef LibGeoDecomp::Grid<ContainerCellType, TopologyType> GridType;
typedef LibGeoDecomp::CoordMap<ContainerCellType, GridType> BaseNeighborhood;
typedef LibGeoDecomp::NeighborhoodAdapter<BaseNeighborhood, 2> Neighborhood;
const Neighborhood *neighborhood;
DomainCell *domainCell;
template<typename NEIGHBORHOOD>
void DomainCell::update(const NEIGHBORHOOD& hood, int nanoStep)
{
domainCell = this;
neighborhood = &hood;
int domainID = domainCell->id;
int numNeighbors = myNeighborTable.myNeighbors.size();
std::cerr << "step = " << outputStep << std::endl;
if (outputStep == 0)
{
//Initial Output
std::ostringstream filename;
filename << "data/output" << domainID << "." << nanoStep << ".dat";
std::ofstream file(filename.str().c_str());
for (std::map<int, SubNode>::const_iterator i=localNodes.begin(); i!=localNodes.end(); ++i)
{
if (i->second.globalID != -1)
{
file << i->second.localID << " ";
file << i->second.location[0] << " ";
file << i->second.location[1] << " ";
file << i->second.alive << std::endl;
}
}
file.close();
}
//Debugging
/*
std::cerr << "I am domain number " << domainID << ", ";
//Loop over neighbors
std::cerr << "and I have " << numNeighbors << " neighbors.\n";
std::cerr << "They are:\n";
for (int i=0; i<numNeighbors; i++)
{
std::cerr << " ";
std::cerr << domainCell->myNeighborTable.myNeighbors[i].neighborID;
std::cerr << ", to whom I will send: ";
for (int j=0; j<domainCell->myNeighborTable.myNeighbors[i].sendNodes.size(); j++)
{
std::cerr << domainCell->myNeighborTable.myNeighbors[i].sendNodes[j] << " ";
}
std::cerr << ", and from whom I will receive: ";
for (int j=0; j<domainCell->myNeighborTable.myNeighbors[i].recvNodes.size(); j++)
{
std::cerr << domainCell->myNeighborTable.myNeighbors[i].recvNodes[j] << " ";
}
std::cerr << "\n";
}
std::cerr << "\n";
*/
for (std::map<int, SubNode>::iterator i=localNodes.begin(); i!=localNodes.end(); ++i)
{
i->second.lastAlive = i->second.alive;
}
//Exchange boundary values
//Loop over neighbors
for (int i=0; i<numNeighbors; i++)
{
std::vector<SubNode> incomingNodes;
int neighborID = myNeighborTable.myNeighbors[i].neighborID;
incomingNodes = neighborhood[0][neighborID].getBoundaryNodes(domainID);
// Verify we get the number of nodes we think we should be getting
if (incomingNodes.size() != myNeighborTable.myNeighbors[i].recvNodes.size())
{
throw std::runtime_error("boundary node number mismatch!");
}
// Verify each node has the same location
for (int j=0; j<incomingNodes.size(); j++)
{
int myLocalID = myNeighborTable.myNeighbors[i].recvNodes[j];
FloatCoord<3> localCoords = localNodes[myLocalID].location;
FloatCoord<3> remoteCoords = incomingNodes[j].location;
if (localCoords != remoteCoords)
{
throw std::runtime_error("boundary node location mismatch!");
}
localNodes[myLocalID].lastAlive = incomingNodes[j].alive;
}
}
// std::vector<FloatCoord<2> > points = getShape();
//TODO: Interact with a C-style kernel subroutine in another file
//Simple Kernel
//Loop over local points
for (std::map<int, SubNode>::iterator i=localNodes.begin(); i!=localNodes.end(); ++i)
{
int my_alive = i->second.lastAlive;
if (my_alive == 1)
{
//In this kernel, if the cell was alive previously, it
//will die the next timestep.
my_alive = 0;
} else {
//Count up neighbor alives
int sum = 0;
// std::cerr << "id = " << i->second.localID << ", neighbors =";
for (int j=0; j<i->second.neighboringNodes.size(); j++) {
sum += localNodes[i->second.neighboringNodes[j]].lastAlive;
// std::cerr << " " << i->second.neighboringNodes[j];
}
// std::cerr << ", sum = " << sum << std::endl;
if (sum > 0)
{
my_alive = 1;
}
}
i->second.alive = my_alive;
}
//Output
std::ostringstream filename;
filename << "data/output" << domainID << "." << outputStep+1 << ".dat";
std::ofstream file(filename.str().c_str());
for (std::map<int, SubNode>::const_iterator i=localNodes.begin(); i!=localNodes.end(); ++i)
{
if (i->second.globalID != -1)
{
file << i->second.localID << " ";
file << i->second.location[0] << " ";
file << i->second.location[1] << " ";
file << i->second.alive << std::endl;
}
}
file.close();
outputStep++;
}
class ADCIRCInitializer : public SimpleInitializer<ContainerCellType>
{
public:
//typedef typename ContainerCellType::Cargo Cargo;
typedef GridBase<ContainerCellType, 2> GridType;
using SimpleInitializer<ContainerCellType>::dimensions;
ADCIRCInitializer(const std::string& meshDir, const int steps) :
SimpleInitializer<ContainerCellType>(Coord<2>(), steps),
meshDir(meshDir)
{
determineGridDimensions();
}
virtual void grid(GridType *grid)
{
std::ifstream fort80File;
int numberOfDomains;
int numberOfElements;
int numberOfPoints;
//Neighbor table stuff
std::vector<neighborTable> myNeighborTables;
std::vector<ownerTableEntry> ownerTable;
//--------------------
openfort80File(fort80File);
readfort80(fort80File, &numberOfDomains, &numberOfElements, &numberOfPoints, &ownerTable);
std::vector<std::vector<int> > neighboringDomains;
std::vector<FloatCoord<2> > centers;
// clear grid:
CoordBox<2> box = grid->boundingBox();
for (CoordBox<2>::Iterator i = box.begin(); i != box.end(); ++i) {
grid->set(*i, ContainerCellType());
}
// piece together domain node cells:
for (int i=0; i< numberOfDomains; i++){
neighborTable myNeighborTable;
std::ifstream fort18File;
int numberOfNeighbors=0;
openfort18File(fort18File, i);
myNeighborTable = readfort18(fort18File);
numberOfNeighbors = myNeighborTable.myNeighbors.size();
myNeighborTables.push_back(myNeighborTable);
//Read fort.14 file for each domain
int numberOfPoints;
int numberOfElements;
std::ifstream fort14File;
openfort14File(fort14File, i);
readFort14Header(fort14File, &numberOfElements, &numberOfPoints);
std::vector<FloatCoord<3> > points;
std::vector<int> localIDs;
readFort14Points(fort14File, &points, &localIDs, numberOfPoints);
FloatCoord<2> center = determineCenter(&points);
center /= numberOfPoints;
centers.push_back(center);
// Load neighboringDomains with myNeighborTables
std::vector<int> neighbors;
for (int j=0; j<numberOfNeighbors; j++){
neighbors.push_back(myNeighborTable.myNeighbors[j].neighborID);
}
neighboringDomains.push_back(neighbors);
int nodeID = i;
DomainCell node(center, nodeID);
node.pushNeighborTable(myNeighborTable);
for (int j=0; j<numberOfNeighbors; j++)
{
node.pushNeighborNode(neighbors[j]);
}
// What does this loop do??
for (int j=0; j<ownerTable.size(); j++)
{
if (ownerTable[j].ownerID == nodeID)
{
SubNode thissubnode;
thissubnode.location = points[ownerTable[j].localID+1]; //FIXME
thissubnode.localID = ownerTable[j].localID;
thissubnode.globalID = ownerTable[j].globalID;
}
}
// Read elements
std::vector<element> myElements = readElements(fort14File, numberOfElements);
// Loop through all local nodes
for (int j=0; j<points.size(); j++)
{
SubNode thissubnode;
thissubnode.location = points[j];
thissubnode.localID = localIDs[j];
thissubnode.globalID = -1;
thissubnode.alive = 0;
// Initial Seed
if ( (nodeID == 0) && (thissubnode.localID == 5) )
{
thissubnode.alive = 1;
}
// Loop through all global nodes
for (int k=0; k<ownerTable.size(); k++)
{
// If the global node is owned by the current domain,
if (nodeID == ownerTable[k].ownerID)
{
//Then
if (localIDs[j] == ownerTable[k].localID)
{
thissubnode.globalID = ownerTable[k].globalID;
}
}
}
node.pushLocalNode(thissubnode);
}
//Assemble local linking information
//Loop over all Elements
for (int j=0; j<myElements.size(); j++)
{
//std::cerr << "elementid = " << j << std::endl;
//Loop over nodes associated with the element
for (int k=0; k<myElements[j].nodeIDs.size(); k++)
{
int outer_nodeID = node.localNodes[myElements[j].nodeIDs[k]].localID;
//std::cerr << "outer_nodeID = " << outer_nodeID << std::endl;
for (int l=0; l<myElements[k].nodeIDs.size(); l++)
{
int inner_nodeID = node.localNodes[myElements[j].nodeIDs[l]].localID;
//std::cerr << "inner_nodeID = " << inner_nodeID << std::endl;
bool notAlreadyThere = (std::count(
node.localNodes[inner_nodeID].neighboringNodes.begin(),
node.localNodes[inner_nodeID].neighboringNodes.end(),
outer_nodeID) == 0);
if ( (outer_nodeID != inner_nodeID) && notAlreadyThere)
{
node.localNodes[inner_nodeID].neighboringNodes.push_back(outer_nodeID);
//std::cerr << node.localNodes[inner_nodeID].neighboringNodes;
}
}
}
}
//Debug
//Loop over all points
/*
std::cerr << "domain = " << node.id << std::endl;
for (std::map<int, SubNode>::const_iterator i=node.localNodes.begin(); i!=node.localNodes.end(); ++i)
{
std::cerr << i->second.localID << " " << i->second.neighboringNodes << std::endl;
}
*/
FloatCoord<2> gridCoordFloat = (node.center - minCoord) / quadrantDim;
Coord<2> gridCoord(gridCoordFloat[0], gridCoordFloat[1]);
ContainerCellType container = grid->get(gridCoord);
container.insert(node.id, node);
grid->set(gridCoord, container);
}
}
private:
std::string meshDir;
double maxDiameter;
FloatCoord<2> minCoord;
FloatCoord<2> maxCoord;
void determineGridDimensions()
{
std::ifstream fort80File;
int numberOfDomains;
int numberOfElements;
int numberOfPoints;
std::vector<ownerTableEntry> ownerTable;
std::vector<neighborTable> myNeighborTables;
openfort80File(fort80File);
readfort80(fort80File, &numberOfDomains, &numberOfElements, &numberOfPoints, &ownerTable);
std::vector<FloatCoord<2> > centers;
for (int i=0; i< numberOfDomains; i++){
neighborTable myNeighborTable;
std::ifstream fort18File;
int numberOfNeighbors=0;
openfort18File(fort18File, i);
myNeighborTable = readfort18(fort18File);
numberOfNeighbors = myNeighborTable.myNeighbors.size();
myNeighborTables.push_back(myNeighborTable);
// need to push 'myNeighborTable' to the domain
//Read fort.14 file for each domain
int numberOfPoints;
int numberOfElements;
std::ifstream fort14File;
openfort14File(fort14File, i);
readFort14Header(fort14File, &numberOfElements, &numberOfPoints);
std::vector<FloatCoord<3> > points;
std::vector<int> localIDs;
readFort14Points(fort14File, &points, &localIDs, numberOfPoints);
FloatCoord<2> center = determineCenter(&points);
center /= numberOfPoints;
centers.push_back(center);
}
maxDiameter = determineMaximumDiameter(¢ers, myNeighborTables);
minCoord = FloatCoord<2>(
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
maxCoord = FloatCoord<2>(
-std::numeric_limits<double>::max(),
-std::numeric_limits<double>::max());
for (int i = 0; i < numberOfDomains; ++i) {
FloatCoord<2> p(centers[i][0], centers[i][1]);
minCoord = minCoord.min(p);
maxCoord = maxCoord.max(p);
}
origin = minCoord;
// add a safety factor for the cell spacing so we can be sure
// neighboring elements are never more than 1 cell apart in the grid:
quadrantDim = FloatCoord<2>(maxDiameter * 2.0, maxDiameter * 2.0);
FloatCoord<2> floatDimensions = (maxCoord - minCoord) / quadrantDim;
dimensions = Coord<2>(
ceil(floatDimensions[0]),
ceil(floatDimensions[1]));
std::cerr << "geometry summary:\n"
<< " minCoord: " << minCoord << "\n"
<< " maxCoord: " << maxCoord << "\n"
<< " maxDiameter: " << maxDiameter << "\n"
<< " dimensions: " << dimensions << "\n"
<< "\n";
}
FloatCoord<2> determineCenter(std::vector<FloatCoord<3> > *points)
{
FloatCoord<2> center;
for (int i=0; i < points->size(); i++){
FloatCoord<2> coord(points[0][i][0],points[0][i][1]);
center += coord;
}
return center;
}
double determineMaximumDiameter(
const std::vector<FloatCoord<2> >* points,
const std::vector<neighborTable> myNeighborTables)
{
double maxDiameter = 0;
int numPoints = points->size();
for (int point = 0; point < numPoints; ++point) {
int numNeighbors = myNeighborTables[point].myNeighbors.size();
for (int i=0; i<numNeighbors; i++){
int neighborID = myNeighborTables[point].myNeighbors[i].neighborID;
double dist = getDistance(points[0][point],points[0][neighborID]);
maxDiameter = std::max(maxDiameter,dist);
}
}
return maxDiameter;
}
double getDistance(FloatCoord<2> a, FloatCoord<2> b)
{
FloatCoord<2> c = a-b;
return sqrt(c[0]*c[0]+c[1]*c[1]);
}
void openfort80File(std::ifstream& meshFile)
{
std::string meshFileName = meshDir;
meshFileName.append("/fort.80");
meshFile.open(meshFileName.c_str());
if (!meshFile) {
throw std::runtime_error("could not open fort.80 file "+meshFileName);
}
}
void readfort80(std::ifstream& meshFile, int *numberOfDomains, int *numberOfElements, int *numberOfPoints, std::vector<ownerTableEntry> *ownerTable)
{
std::string buffer(1024, ' ');
//Discard first 3 lines:
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
meshFile >> *numberOfElements;
meshFile >> *numberOfPoints;
//Discard rest of line
std::getline(meshFile, buffer);
meshFile >> *numberOfDomains;
//Discard rest of the line:
std::getline(meshFile, buffer);
//Discard next 8 lines:
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
std::getline(meshFile, buffer);
for (int domain = 0; domain < *numberOfDomains; ++domain) {
int buf;
int numNodes;
meshFile >> buf;
if (buf != domain) {
throw std::runtime_error("buf does not match domain");
}
meshFile >> numNodes;
//Discard rest of the line
std::getline(meshFile, buffer);
for (int node = 0; node < numNodes; ++node) {
int nodeNum;
meshFile >> nodeNum;
}
// throw away the rest of the line
std::getline(meshFile, buffer);
}
// Throw away another line
std::getline(meshFile, buffer);
for (int node = 0; node < *numberOfPoints; node++) {
ownerTableEntry thisOwnerTableEntry;
int global_label;
int local_label;
int owner;
meshFile >> global_label;
meshFile >> owner;
meshFile >> local_label;
thisOwnerTableEntry.globalID=global_label;
thisOwnerTableEntry.ownerID=owner;
thisOwnerTableEntry.localID=local_label;
std::getline(meshFile, buffer);//discard rest of line
ownerTable->push_back(thisOwnerTableEntry);
}
}
void openfort18File(std::ifstream& meshFile, int domainID)
{
std::string meshFileName = meshDir;
meshFileName.append("/PE");
std::stringstream buf;
buf.width(4);
buf.fill('0');
buf << domainID;
meshFileName.append(buf.str());
meshFileName.append("/fort.18");
meshFile.open(meshFileName.c_str());
if (!meshFile) {
throw std::runtime_error("could not open fort.18 file"+meshFileName);
}
}
neighborTable readfort18(std::ifstream& meshFile)
{
neighborTable myNeighborTable;
int numNeighbors;
std::string buffer(1024, ' ');
while (buffer != "COMM")
{
meshFile >> buffer;
}
meshFile >> buffer; // PE
if (buffer != "PE"){
throw std::runtime_error("buffer does not match!");}
meshFile >> numNeighbors;
for (int i=0; i<numNeighbors; i++){
neighbor neighbor;
int numberOfRecvNodes;
meshFile >> buffer; //RECV
if (buffer != "RECV"){
throw std::runtime_error("buffer does not match!");}
meshFile >> buffer; //PE
if (buffer != "PE"){
throw std::runtime_error("buffer does not match!");}
meshFile >> neighbor.neighborID;
meshFile >> numberOfRecvNodes;
std::getline(meshFile, buffer);//discard rest of the line
//Assemble arrays of nodes to be received
for (int j=0; j<numberOfRecvNodes; j++){
int receiveNode;
meshFile >> receiveNode;
neighbor.recvNodes.push_back(receiveNode);
}
std::getline(meshFile, buffer);//discard rest of the line
myNeighborTable.myNeighbors.push_back(neighbor);
}
for (int i=0; i<numNeighbors; i++){
int neighbor;
int numberOfSendNodes;
meshFile >> buffer; //SEND
if (buffer != "SEND"){
throw std::runtime_error("buffer does not match!");}
meshFile >> buffer; //PE
if (buffer != "PE"){
throw std::runtime_error("buffer does not match!");}
meshFile >> neighbor;
meshFile >> numberOfSendNodes;
std::getline(meshFile, buffer);//discard rest of the line
//Assemble arrays of nodes to be sent
for (int j=0; j<numberOfSendNodes; j++){
int sendNode;
meshFile >> sendNode;
myNeighborTable.myNeighbors[i].sendNodes.push_back(sendNode);
}
std::getline(meshFile, buffer);//discard rest of the line
}
return myNeighborTable;
}
void openfort14File(std::ifstream& meshFile, int domainID)
{
std::string meshFileName = meshDir;
meshFileName.append("/PE");
std::stringstream buf;
buf.width(4);
buf.fill('0');
buf << domainID;
meshFileName.append(buf.str());
meshFileName.append("/fort.14");
meshFile.open(meshFileName.c_str());
if (!meshFile) {
throw std::runtime_error("could not open fort.14 file "+meshFileName);
}
}
void readFort14Header(std::ifstream& meshFile, int *numberOfElements, int *numberOfPoints)
{
std::string buffer(1024, ' ');
// discard first line, which only holds comments anyway
std::getline(meshFile, buffer);
meshFile >> *numberOfElements;
meshFile >> *numberOfPoints;
// discard remainder of line
std::getline(meshFile, buffer);
if (!meshFile.good()) {
throw std::logic_error("could not read header");
}
}
void readFort14Points(std::ifstream& meshFile, std::vector<FloatCoord<3> > *points, std::vector<int> *localIDs, const int numberOfPoints)
{
std::string buffer(1024, ' ');
for (int i = 0; i < numberOfPoints; ++i) {
FloatCoord<3> p;
int localID;
meshFile >> localID;
meshFile >> p[0];
meshFile >> p[1];
meshFile >> p[2];
std::getline(meshFile, buffer);
*points << p;
*localIDs << localID;
}
if (!meshFile.good()) {
throw std::runtime_error("could not read points");
}
}
std::vector<element> readElements(
std::ifstream& meshFile,
const int numberOfElements)
{
std::vector<element> ret;
if (!meshFile.good()) {
throw std::runtime_error("could not read elements");
}
std::string buffer(1024, ' ');
for (int elem = 0; elem < numberOfElements; ++elem) {
element myElement;
int buf;
int numNodes;
meshFile >> buf; // Element number
meshFile >> numNodes; // will always be 3
std::vector<int> nodeIDs;
for (int i = 0; i < numNodes; ++i) {
int node;
meshFile >> node;
nodeIDs.push_back(node);
}
std::getline(meshFile, buffer);
myElement.nodeIDs = nodeIDs;
ret.push_back(myElement);
}
return ret;
}
};
typedef
HpxSimulator::HpxSimulator<ContainerCellType, RecursiveBisectionPartition<2> >
SimulatorType;
LIBGEODECOMP_REGISTER_HPX_SIMULATOR_DECLARATION(
SimulatorType,
ConwayCellSimulator
)
LIBGEODECOMP_REGISTER_HPX_SIMULATOR(
SimulatorType,
ConwayCellSimulator
)
void runSimulation()
{
// TODO: figure out what the stuff below is
Coord<2> dim(3, 2);
std::size_t numCells = 100;
double minDistance = 100;
double quadrantSize = 400;
quadrantDim = FloatCoord<2>(quadrantSize, quadrantSize);
// Hardcoded link to the directory
std::string prunedDirname("/home/zbyerly/research/adcirclgd/meshes/shin32");
// Hardcoded number of simulation steps
int steps = 100;
// SerialSimulator<ContainerCellType> sim(
//sim(new ADCIRCInitializer(prunedDirname, steps));
/*
int ioPeriod = 1;
SiloWriter<ContainerCellType> *writer = new SiloWriter<ContainerCellType>("mesh", *ioPeriod);
writer->addSelectorForUnstructuredGrid(
&DomainCell::alive,
"DomainCell_alive");
sim.addWriter(writer);
*/
SimulatorType sim(
new ADCIRCInitializer(prunedDirname, steps),
1, //overcommitFactor
new TracingBalancer(new OozeBalancer()),
10, //balancingPeriod
1 // ghostZoneWidth
);
sim.run();
}
int hpx_main()
{
runSimulation();
return hpx::finalize();
}
int main(int argc, char *argv[])
{
return hpx::init(argc, argv);
}