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
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143 | /*
* =====================================================================================
*
* Filename: TempestOnlineMap.hpp
*
* Description: Interface to the TempestRemap library to compute the consistent,
* and accurate high-order conservative remapping weights for overlap
* grids on the sphere in climate simulations.
*
* Author: Vijay S. Mahadevan (vijaysm), [email protected]
*
* =====================================================================================
*/
#include "Announce.h"
#include "DataArray3D.h"
#include "FiniteElementTools.h"
#include "TriangularQuadrature.h"
#include "GaussQuadrature.h"
#include "GaussLobattoQuadrature.h"
#include "SparseMatrix.h"
#include "STLStringHelper.h"
#include "moab/Remapping/TempestOnlineMap.hpp"
#include "DebugOutput.hpp"
#include "moab/TupleList.hpp"
#include <fstream>
#include <cmath>
#include <cstdlib>
#ifdef MOAB_HAVE_NETCDFPAR
#include "netcdfcpp_par.hpp"
#else
#include "netcdfcpp.h"
#endif
///////////////////////////////////////////////////////////////////////////////
// #define VERBOSE
// #define VVERBOSE
// #define CHECK_INCREASING_DOF
void LinearRemapFVtoGLL( const Mesh& meshInput,
const Mesh& meshOutput,
const Mesh& meshOverlap,
const DataArray3D< int >& dataGLLNodes,
const DataArray3D< double >& dataGLLJacobian,
const DataArray1D< double >& dataGLLNodalArea,
int nOrder,
OfflineMap& mapRemap,
int nMonotoneType,
bool fContinuous,
bool fNoConservation );
void LinearRemapFVtoGLL_Volumetric( const Mesh& meshInput,
const Mesh& meshOutput,
const Mesh& meshOverlap,
const DataArray3D< int >& dataGLLNodes,
const DataArray3D< double >& dataGLLJacobian,
const DataArray1D< double >& dataGLLNodalArea,
int nOrder,
OfflineMap& mapRemap,
int nMonotoneType,
bool fContinuous,
bool fNoConservation );
///////////////////////////////////////////////////////////////////////////////
#define MPI_CHK_ERR( err ) \
if( err ) \
{ \
std::cout << "MPI Failure. ErrorCode (" << ( err ) << ") "; \
std::cout << "\nMPI Aborting... \n"; \
return moab::MB_FAILURE; \
}
moab::TempestOnlineMap::TempestOnlineMap( moab::TempestRemapper* remapper ) : OfflineMap(), m_remapper( remapper )
{
// Get the references for the MOAB core objects
m_interface = m_remapper->get_interface();
#ifdef MOAB_HAVE_MPI
m_pcomm = m_remapper->get_parallel_communicator();
#endif
// Update the references to the meshes
m_meshInput = remapper->GetMesh( moab::Remapper::SourceMesh );
m_meshInputCov = remapper->GetCoveringMesh();
m_meshOutput = remapper->GetMesh( moab::Remapper::TargetMesh );
m_meshOverlap = remapper->GetMesh( moab::Remapper::OverlapMesh );
is_parallel = false;
is_root = true;
rank = 0;
root_proc = rank;
size = 1;
#ifdef MOAB_HAVE_MPI
int flagInit;
MPI_Initialized( &flagInit );
if( flagInit )
{
is_parallel = true;
assert( m_pcomm != NULL );
rank = m_pcomm->rank();
size = m_pcomm->size();
is_root = ( rank == 0 );
}
#endif
// Compute and store the total number of source and target DoFs corresponding
// to number of rows and columns in the mapping.
// Initialize dimension information from file
this->setup_sizes_dimensions();
// Build a matrix of source and target discretization so that we know how to assign
// the global DoFs in parallel for the mapping weights
// For example, FV->FV: rows X cols = faces_source X faces_target
}
void moab::TempestOnlineMap::setup_sizes_dimensions()
{
if( m_meshInputCov )
{
std::vector< std::string > dimNames;
std::vector< int > dimSizes;
if( m_remapper->m_source_type == moab::TempestRemapper::RLL && m_remapper->m_source_metadata.size() )
{
dimNames.push_back( "lat" );
dimNames.push_back( "lon" );
dimSizes.resize( 2, 0 );
dimSizes[0] = m_remapper->m_source_metadata[1];
dimSizes[1] = m_remapper->m_source_metadata[2];
}
else
{
dimNames.push_back( "num_elem" );
dimSizes.push_back( m_meshInputCov->faces.size() );
}
this->InitializeSourceDimensions( dimNames, dimSizes );
}
if( m_meshOutput )
{
std::vector< std::string > dimNames;
std::vector< int > dimSizes;
if( m_remapper->m_target_type == moab::TempestRemapper::RLL && m_remapper->m_target_metadata.size() )
{
dimNames.push_back( "lat" );
dimNames.push_back( "lon" );
dimSizes.resize( 2, 0 );
dimSizes[0] = m_remapper->m_target_metadata[1];
dimSizes[1] = m_remapper->m_target_metadata[2];
}
else
{
dimNames.push_back( "num_elem" );
dimSizes.push_back( m_meshOutput->faces.size() );
}
this->InitializeTargetDimensions( dimNames, dimSizes );
}
}
///////////////////////////////////////////////////////////////////////////////
moab::TempestOnlineMap::~TempestOnlineMap()
{
m_interface = NULL;
#ifdef MOAB_HAVE_MPI
m_pcomm = NULL;
#endif
m_meshInput = NULL;
m_meshOutput = NULL;
m_meshOverlap = NULL;
}
///////////////////////////////////////////////////////////////////////////////
moab::ErrorCode moab::TempestOnlineMap::SetDOFmapTags( const std::string srcDofTagName,
const std::string tgtDofTagName )
{
moab::ErrorCode rval;
int tagSize = 0;
tagSize = ( m_eInputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Src * m_nDofsPEl_Src );
rval =
m_interface->tag_get_handle( srcDofTagName.c_str(), tagSize, MB_TYPE_INTEGER, this->m_dofTagSrc, MB_TAG_ANY );
if( rval == moab::MB_TAG_NOT_FOUND && m_eInputType != DiscretizationType_FV )
{
int ntot_elements = 0, nelements = m_remapper->m_source_entities.size();
#ifdef MOAB_HAVE_MPI
int ierr = MPI_Allreduce( &nelements, &ntot_elements, 1, MPI_INT, MPI_SUM, m_pcomm->comm() );
if( ierr != 0 ) MB_CHK_SET_ERR( MB_FAILURE, "MPI_Allreduce failed to get total source elements" );
#else
ntot_elements = nelements;
#endif
rval = m_remapper->GenerateCSMeshMetadata( ntot_elements, m_remapper->m_covering_source_entities,
&m_remapper->m_source_entities, srcDofTagName, m_nDofsPEl_Src );MB_CHK_ERR( rval );
rval = m_interface->tag_get_handle( srcDofTagName.c_str(), m_nDofsPEl_Src * m_nDofsPEl_Src, MB_TYPE_INTEGER,
this->m_dofTagSrc, MB_TAG_ANY );MB_CHK_ERR( rval );
}
else
MB_CHK_ERR( rval );
tagSize = ( m_eOutputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Dest * m_nDofsPEl_Dest );
rval =
m_interface->tag_get_handle( tgtDofTagName.c_str(), tagSize, MB_TYPE_INTEGER, this->m_dofTagDest, MB_TAG_ANY );
if( rval == moab::MB_TAG_NOT_FOUND && m_eOutputType != DiscretizationType_FV )
{
int ntot_elements = 0, nelements = m_remapper->m_target_entities.size();
#ifdef MOAB_HAVE_MPI
int ierr = MPI_Allreduce( &nelements, &ntot_elements, 1, MPI_INT, MPI_SUM, m_pcomm->comm() );
if( ierr != 0 ) MB_CHK_SET_ERR( MB_FAILURE, "MPI_Allreduce failed to get total source elements" );
#else
ntot_elements = nelements;
#endif
rval = m_remapper->GenerateCSMeshMetadata( ntot_elements, m_remapper->m_target_entities, NULL, tgtDofTagName,
m_nDofsPEl_Dest );MB_CHK_ERR( rval );
rval = m_interface->tag_get_handle( tgtDofTagName.c_str(), m_nDofsPEl_Dest * m_nDofsPEl_Dest, MB_TYPE_INTEGER,
this->m_dofTagDest, MB_TAG_ANY );MB_CHK_ERR( rval );
}
else
MB_CHK_ERR( rval );
return moab::MB_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
moab::ErrorCode moab::TempestOnlineMap::SetDOFmapAssociation( DiscretizationType srcType,
bool isSrcContinuous,
DataArray3D< int >* srcdataGLLNodes,
DataArray3D< int >* srcdataGLLNodesSrc,
DiscretizationType destType,
bool isTgtContinuous,
DataArray3D< int >* tgtdataGLLNodes )
{
moab::ErrorCode rval;
std::vector< bool > dgll_cgll_row_ldofmap, dgll_cgll_col_ldofmap, dgll_cgll_covcol_ldofmap;
std::vector< int > src_soln_gdofs, locsrc_soln_gdofs, tgt_soln_gdofs;
// We are assuming that these are element based tags that are sized: np * np
m_srcDiscType = srcType;
m_destDiscType = destType;
bool vprint = is_root && false;
#ifdef VVERBOSE
{
src_soln_gdofs.resize( m_remapper->m_covering_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src, -1 );
rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_covering_source_entities, &src_soln_gdofs[0] );MB_CHK_ERR( rval );
locsrc_soln_gdofs.resize( m_remapper->m_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src );
rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_source_entities, &locsrc_soln_gdofs[0] );MB_CHK_ERR( rval );
tgt_soln_gdofs.resize( m_remapper->m_target_entities.size() * m_nDofsPEl_Dest * m_nDofsPEl_Dest );
rval = m_interface->tag_get_data( m_dofTagDest, m_remapper->m_target_entities, &tgt_soln_gdofs[0] );MB_CHK_ERR( rval );
if( is_root )
{
{
std::ofstream output_file( "sourcecov-gids-0.txt" );
output_file << "I, GDOF\n";
for( unsigned i = 0; i < src_soln_gdofs.size(); ++i )
output_file << i << ", " << src_soln_gdofs[i] << "\n";
output_file << "ELEMID, IDOF, LDOF, GDOF, NDOF\n";
m_nTotDofs_SrcCov = 0;
if( isSrcContinuous )
dgll_cgll_covcol_ldofmap.resize(
m_remapper->m_covering_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src, false );
for( unsigned j = 0; j < m_remapper->m_covering_source_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
if( isSrcContinuous && !dgll_cgll_covcol_ldofmap[localDOF] )
{
m_nTotDofs_SrcCov++;
dgll_cgll_covcol_ldofmap[localDOF] = true;
}
output_file << m_remapper->lid_to_gid_covsrc[j] << ", " << offsetDOF << ", " << localDOF
<< ", " << src_soln_gdofs[offsetDOF] << ", " << m_nTotDofs_SrcCov << "\n";
}
}
}
output_file.flush(); // required here
output_file.close();
dgll_cgll_covcol_ldofmap.clear();
}
{
std::ofstream output_file( "source-gids-0.txt" );
output_file << "I, GDOF\n";
for( unsigned i = 0; i < locsrc_soln_gdofs.size(); ++i )
output_file << i << ", " << locsrc_soln_gdofs[i] << "\n";
output_file << "ELEMID, IDOF, LDOF, GDOF, NDOF\n";
m_nTotDofs_Src = 0;
if( isSrcContinuous )
dgll_cgll_col_ldofmap.resize(
m_remapper->m_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src, false );
for( unsigned j = 0; j < m_remapper->m_source_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodesSrc )[p][q][j] - 1;
const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
if( isSrcContinuous && !dgll_cgll_col_ldofmap[localDOF] )
{
m_nTotDofs_Src++;
dgll_cgll_col_ldofmap[localDOF] = true;
}
output_file << m_remapper->lid_to_gid_src[j] << ", " << offsetDOF << ", " << localDOF
<< ", " << locsrc_soln_gdofs[offsetDOF] << ", " << m_nTotDofs_Src << "\n";
}
}
}
output_file.flush(); // required here
output_file.close();
dgll_cgll_col_ldofmap.clear();
}
{
std::ofstream output_file( "target-gids-0.txt" );
output_file << "I, GDOF\n";
for( unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
output_file << i << ", " << tgt_soln_gdofs[i] << "\n";
output_file << "ELEMID, IDOF, GDOF, NDOF\n";
m_nTotDofs_Dest = 0;
for( unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
{
output_file << m_remapper->lid_to_gid_tgt[i] << ", " << i << ", " << tgt_soln_gdofs[i] << ", "
<< m_nTotDofs_Dest << "\n";
m_nTotDofs_Dest++;
}
output_file.flush(); // required here
output_file.close();
}
}
else
{
{
std::ofstream output_file( "sourcecov-gids-1.txt" );
output_file << "I, GDOF\n";
for( unsigned i = 0; i < src_soln_gdofs.size(); ++i )
output_file << i << ", " << src_soln_gdofs[i] << "\n";
output_file << "ELEMID, IDOF, LDOF, GDOF, NDOF\n";
m_nTotDofs_SrcCov = 0;
if( isSrcContinuous )
dgll_cgll_covcol_ldofmap.resize(
m_remapper->m_covering_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src, false );
for( unsigned j = 0; j < m_remapper->m_covering_source_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
if( isSrcContinuous && !dgll_cgll_covcol_ldofmap[localDOF] )
{
m_nTotDofs_SrcCov++;
dgll_cgll_covcol_ldofmap[localDOF] = true;
}
output_file << m_remapper->lid_to_gid_covsrc[j] << ", " << offsetDOF << ", " << localDOF
<< ", " << src_soln_gdofs[offsetDOF] << ", " << m_nTotDofs_SrcCov << "\n";
}
}
}
output_file.flush(); // required here
output_file.close();
dgll_cgll_covcol_ldofmap.clear();
}
{
std::ofstream output_file( "source-gids-1.txt" );
output_file << "I, GDOF\n";
for( unsigned i = 0; i < locsrc_soln_gdofs.size(); ++i )
output_file << i << ", " << locsrc_soln_gdofs[i] << "\n";
output_file << "ELEMID, IDOF, LDOF, GDOF, NDOF\n";
m_nTotDofs_Src = 0;
if( isSrcContinuous )
dgll_cgll_col_ldofmap.resize(
m_remapper->m_source_entities.size() * m_nDofsPEl_Src * m_nDofsPEl_Src, false );
for( unsigned j = 0; j < m_remapper->m_source_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodesSrc )[p][q][j] - 1;
const int offsetDOF = j * m_nDofsPEl_Src * m_nDofsPEl_Src + p * m_nDofsPEl_Src + q;
if( isSrcContinuous && !dgll_cgll_col_ldofmap[localDOF] )
{
m_nTotDofs_Src++;
dgll_cgll_col_ldofmap[localDOF] = true;
}
output_file << m_remapper->lid_to_gid_src[j] << ", " << offsetDOF << ", " << localDOF
<< ", " << locsrc_soln_gdofs[offsetDOF] << ", " << m_nTotDofs_Src << "\n";
}
}
}
output_file.flush(); // required here
output_file.close();
dgll_cgll_col_ldofmap.clear();
}
{
std::ofstream output_file( "target-gids-1.txt" );
output_file << "I, GDOF\n";
for( unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
output_file << i << ", " << tgt_soln_gdofs[i] << "\n";
output_file << "ELEMID, IDOF, GDOF, NDOF\n";
m_nTotDofs_Dest = 0;
for( unsigned i = 0; i < tgt_soln_gdofs.size(); ++i )
{
output_file << m_remapper->lid_to_gid_tgt[i] << ", " << i << ", " << tgt_soln_gdofs[i] << ", "
<< m_nTotDofs_Dest << "\n";
m_nTotDofs_Dest++;
}
output_file.flush(); // required here
output_file.close();
}
}
}
#endif
// Now compute the mapping and store it for the covering mesh
int srcTagSize = ( m_eInputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Src * m_nDofsPEl_Src );
if( m_remapper->point_cloud_source )
{
assert( m_nDofsPEl_Src == 1 );
col_gdofmap.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
col_dtoc_dofmap.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
src_soln_gdofs.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_covering_source_vertices, &src_soln_gdofs[0] );MB_CHK_ERR( rval );
srcTagSize = 1;
}
else
{
col_gdofmap.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, UINT_MAX );
col_dtoc_dofmap.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, UINT_MAX );
src_soln_gdofs.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, UINT_MAX );
rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_covering_source_entities, &src_soln_gdofs[0] );MB_CHK_ERR( rval );
}
// std::cout << "TOnlineMap: Process: " << rank << " and covering entities = [" <<
// col_dofmap.size() << ", " << src_soln_gdofs.size() << "]\n"; MPI_Barrier(MPI_COMM_WORLD);
#ifdef ALTERNATE_NUMBERING_IMPLEMENTATION
unsigned maxSrcIndx = 0;
// for ( unsigned j = 0; j < m_covering_source_entities.size(); j++ )
std::vector< int > locdofs( srcTagSize );
std::map< Node, moab::EntityHandle > mapLocalMBNodes;
double elcoords[3];
for( unsigned iel = 0; iel < m_remapper->m_covering_source_entities.size(); ++iel )
{
EntityHandle eh = m_remapper->m_covering_source_entities[iel];
rval = m_interface->get_coords( &eh, 1, elcoords );MB_CHK_ERR( rval );
Node elCentroid( elcoords[0], elcoords[1], elcoords[2] );
mapLocalMBNodes.insert( std::pair< Node, moab::EntityHandle >( elCentroid, eh ) );
}
const NodeVector& nodes = m_remapper->m_covering_source->nodes;
for( unsigned j = 0; j < m_remapper->m_covering_source->faces.size(); j++ )
{
const Face& face = m_remapper->m_covering_source->faces[j];
Node centroid;
centroid.x = centroid.y = centroid.z = 0.0;
for( unsigned l = 0; l < face.edges.size(); ++l )
{
centroid.x += nodes[face[l]].x;
centroid.y += nodes[face[l]].y;
centroid.z += nodes[face[l]].z;
}
const double factor = 1.0 / face.edges.size();
centroid.x *= factor;
centroid.y *= factor;
centroid.z *= factor;
EntityHandle current_eh;
if( mapLocalMBNodes.find( centroid ) != mapLocalMBNodes.end() )
{
current_eh = mapLocalMBNodes[centroid];
}
rval = m_interface->tag_get_data( m_dofTagSrc, ¤t_eh, 1, &locdofs[0] );MB_CHK_ERR( rval );
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
const int offsetDOF = p * m_nDofsPEl_Src + q;
maxSrcIndx = ( localDOF > maxSrcIndx ? localDOF : maxSrcIndx );
std::cout << "Col: " << current_eh << ", " << m_remapper->lid_to_gid_covsrc[j] << ", " << offsetDOF
<< ", " << localDOF << ", " << locdofs[offsetDOF] - 1 << ", " << maxSrcIndx << "\n";
}
}
}
#endif
m_nTotDofs_SrcCov = 0;
if( srcdataGLLNodes == NULL )
{ /* we only have a mapping for elements as DoFs */
for( unsigned i = 0; i < col_gdofmap.size(); ++i )
{
assert( src_soln_gdofs[i] > 0 );
col_gdofmap[i] = src_soln_gdofs[i] - 1;
col_dtoc_dofmap[i] = i;
if( vprint ) std::cout << "Col: " << i << ", " << col_gdofmap[i] << "\n";
m_nTotDofs_SrcCov++;
}
}
else
{
if( isSrcContinuous )
dgll_cgll_covcol_ldofmap.resize( m_remapper->m_covering_source_entities.size() * srcTagSize, false );
// Put these remap coefficients into the SparseMatrix map
for( unsigned j = 0; j < m_remapper->m_covering_source_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodes )[p][q][j] - 1;
const int offsetDOF = j * srcTagSize + p * m_nDofsPEl_Src + q;
if( isSrcContinuous && !dgll_cgll_covcol_ldofmap[localDOF] )
{
m_nTotDofs_SrcCov++;
dgll_cgll_covcol_ldofmap[localDOF] = true;
}
if( !isSrcContinuous ) m_nTotDofs_SrcCov++;
assert( src_soln_gdofs[offsetDOF] > 0 );
col_gdofmap[localDOF] = src_soln_gdofs[offsetDOF] - 1;
col_dtoc_dofmap[offsetDOF] = localDOF;
if( vprint )
std::cout << "Col: " << m_remapper->lid_to_gid_covsrc[j] << ", " << offsetDOF << ", "
<< localDOF << ", " << col_gdofmap[offsetDOF] << ", " << m_nTotDofs_SrcCov << "\n";
}
}
}
}
if( m_remapper->point_cloud_source )
{
assert( m_nDofsPEl_Src == 1 );
srccol_gdofmap.resize( m_remapper->m_source_vertices.size(), UINT_MAX );
srccol_dtoc_dofmap.resize( m_remapper->m_covering_source_vertices.size(), UINT_MAX );
locsrc_soln_gdofs.resize( m_remapper->m_source_vertices.size(), UINT_MAX );
rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_source_vertices, &locsrc_soln_gdofs[0] );MB_CHK_ERR( rval );
}
else
{
srccol_gdofmap.resize( m_remapper->m_source_entities.size() * srcTagSize, UINT_MAX );
srccol_dtoc_dofmap.resize( m_remapper->m_source_entities.size() * srcTagSize, UINT_MAX );
locsrc_soln_gdofs.resize( m_remapper->m_source_entities.size() * srcTagSize, UINT_MAX );
rval = m_interface->tag_get_data( m_dofTagSrc, m_remapper->m_source_entities, &locsrc_soln_gdofs[0] );MB_CHK_ERR( rval );
}
// Now compute the mapping and store it for the original source mesh
m_nTotDofs_Src = 0;
if( srcdataGLLNodesSrc == NULL )
{ /* we only have a mapping for elements as DoFs */
for( unsigned i = 0; i < srccol_gdofmap.size(); ++i )
{
assert( locsrc_soln_gdofs[i] > 0 );
srccol_gdofmap[i] = locsrc_soln_gdofs[i] - 1;
srccol_dtoc_dofmap[i] = i;
m_nTotDofs_Src++;
}
}
else
{
if( isSrcContinuous ) dgll_cgll_col_ldofmap.resize( m_remapper->m_source_entities.size() * srcTagSize, false );
// Put these remap coefficients into the SparseMatrix map
for( unsigned j = 0; j < m_remapper->m_source_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Src; p++ )
{
for( int q = 0; q < m_nDofsPEl_Src; q++ )
{
const int localDOF = ( *srcdataGLLNodesSrc )[p][q][j] - 1;
const int offsetDOF = j * srcTagSize + p * m_nDofsPEl_Src + q;
if( isSrcContinuous && !dgll_cgll_col_ldofmap[localDOF] )
{
m_nTotDofs_Src++;
dgll_cgll_col_ldofmap[localDOF] = true;
}
if( !isSrcContinuous ) m_nTotDofs_Src++;
assert( locsrc_soln_gdofs[offsetDOF] > 0 );
srccol_gdofmap[localDOF] = locsrc_soln_gdofs[offsetDOF] - 1;
srccol_dtoc_dofmap[offsetDOF] = localDOF;
}
}
}
}
int tgtTagSize = ( m_eOutputType == DiscretizationType_FV ? 1 : m_nDofsPEl_Dest * m_nDofsPEl_Dest );
if( m_remapper->point_cloud_target )
{
assert( m_nDofsPEl_Dest == 1 );
row_gdofmap.resize( m_remapper->m_target_vertices.size(), UINT_MAX );
row_dtoc_dofmap.resize( m_remapper->m_target_vertices.size(), UINT_MAX );
tgt_soln_gdofs.resize( m_remapper->m_target_vertices.size(), UINT_MAX );
rval = m_interface->tag_get_data( m_dofTagDest, m_remapper->m_target_vertices, &tgt_soln_gdofs[0] );MB_CHK_ERR( rval );
tgtTagSize = 1;
}
else
{
row_gdofmap.resize( m_remapper->m_target_entities.size() * tgtTagSize, UINT_MAX );
row_dtoc_dofmap.resize( m_remapper->m_target_entities.size() * tgtTagSize, UINT_MAX );
tgt_soln_gdofs.resize( m_remapper->m_target_entities.size() * tgtTagSize, UINT_MAX );
rval = m_interface->tag_get_data( m_dofTagDest, m_remapper->m_target_entities, &tgt_soln_gdofs[0] );MB_CHK_ERR( rval );
}
// Now compute the mapping and store it for the target mesh
// To access the GID for each row: row_gdofmap [ row_ldofmap [ 0 : local_ndofs ] ] = GDOF
m_nTotDofs_Dest = 0;
if( tgtdataGLLNodes == NULL )
{ /* we only have a mapping for elements as DoFs */
for( unsigned i = 0; i < row_gdofmap.size(); ++i )
{
assert( tgt_soln_gdofs[i] > 0 );
row_gdofmap[i] = tgt_soln_gdofs[i] - 1;
row_dtoc_dofmap[i] = i;
if( vprint ) std::cout << "Row: " << i << ", " << row_gdofmap[i] << "\n";
m_nTotDofs_Dest++;
}
}
else
{
if( isTgtContinuous ) dgll_cgll_row_ldofmap.resize( m_remapper->m_target_entities.size() * tgtTagSize, false );
// Put these remap coefficients into the SparseMatrix map
for( unsigned j = 0; j < m_remapper->m_target_entities.size(); j++ )
{
for( int p = 0; p < m_nDofsPEl_Dest; p++ )
{
for( int q = 0; q < m_nDofsPEl_Dest; q++ )
{
const int localDOF = ( *tgtdataGLLNodes )[p][q][j] - 1;
const int offsetDOF = j * tgtTagSize + p * m_nDofsPEl_Dest + q;
if( isTgtContinuous && !dgll_cgll_row_ldofmap[localDOF] )
{
m_nTotDofs_Dest++;
dgll_cgll_row_ldofmap[localDOF] = true;
}
if( !isTgtContinuous ) m_nTotDofs_Dest++;
assert( tgt_soln_gdofs[offsetDOF] > 0 );
row_gdofmap[localDOF] = tgt_soln_gdofs[offsetDOF] - 1;
row_dtoc_dofmap[offsetDOF] = localDOF;
if( vprint )
std::cout << "Row: " << m_remapper->lid_to_gid_tgt[j] << ", " << offsetDOF << ", " << localDOF
<< ", " << row_gdofmap[offsetDOF] << ", " << m_nTotDofs_Dest << "\n";
}
}
}
}
// Let us also allocate the local representation of the sparse matrix
#if defined( MOAB_HAVE_EIGEN3 ) && defined( VERBOSE )
if( vprint )
{
std::cout << "[" << rank << "]"
<< "DoFs: row = " << m_nTotDofs_Dest << ", " << row_gdofmap.size() << ", col = " << m_nTotDofs_Src
<< ", " << m_nTotDofs_SrcCov << ", " << col_gdofmap.size() << "\n";
// std::cout << "Max col_dofmap: " << maxcol << ", Min col_dofmap" << mincol << "\n";
}
#endif
// check monotonicity of row_gdofmap and col_gdofmap
#ifdef CHECK_INCREASING_DOF
for( size_t i = 0; i < row_gdofmap.size() - 1; i++ )
{
if( row_gdofmap[i] > row_gdofmap[i + 1] )
std::cout << " on rank " << rank << " in row_gdofmap[" << i << "]=" << row_gdofmap[i] << " > row_gdofmap["
<< i + 1 << "]=" << row_gdofmap[i + 1] << " \n";
}
for( size_t i = 0; i < col_gdofmap.size() - 1; i++ )
{
if( col_gdofmap[i] > col_gdofmap[i + 1] )
std::cout << " on rank " << rank << " in col_gdofmap[" << i << "]=" << col_gdofmap[i] << " > col_gdofmap["
<< i + 1 << "]=" << col_gdofmap[i + 1] << " \n";
}
#endif
return moab::MB_SUCCESS;
}
moab::ErrorCode moab::TempestOnlineMap::set_col_dc_dofs( std::vector< int >& values_entities )
{
// col_gdofmap has global dofs , that should be in the list of values, such that
// row_dtoc_dofmap[offsetDOF] = localDOF;
// // we need to find col_dtoc_dofmap such that: col_gdofmap[ col_dtoc_dofmap[i] ] == values_entities [i];
// we know that col_gdofmap[0..(nbcols-1)] = global_col_dofs -> in values_entities
// form first inverse
col_dtoc_dofmap.resize( values_entities.size() );
for( int j = 0; j < (int)values_entities.size(); j++ )
{
if( colMap.find( values_entities[j] - 1 ) != colMap.end() )
col_dtoc_dofmap[j] = colMap[values_entities[j] - 1];
else
{
col_dtoc_dofmap[j] = -1; // signal that this value should not be used in
// std::cout <<"values_entities[j] - 1: " << values_entities[j] - 1 <<" at index j = " << j << " not
// found in colMap \n";
}
}
return moab::MB_SUCCESS;
}
moab::ErrorCode moab::TempestOnlineMap::set_row_dc_dofs( std::vector< int >& values_entities )
{
// row_dtoc_dofmap = values_entities; // needs to point to local
// we need to find row_dtoc_dofmap such that: row_gdofmap[ row_dtoc_dofmap[i] ] == values_entities [i];
row_dtoc_dofmap.resize( values_entities.size() );
for( int j = 0; j < (int)values_entities.size(); j++ )
{
if( rowMap.find( values_entities[j] - 1 ) != rowMap.end() )
row_dtoc_dofmap[j] = rowMap[values_entities[j] - 1]; // values are 1 based, but rowMap, colMap are not
else
{
row_dtoc_dofmap[j] = -1; // not all values are used
// std::cout <<"values_entities[j] - 1: " << values_entities[j] - 1 <<" at index j = " << j << " not
// found in rowMap \n";
}
}
return moab::MB_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
moab::ErrorCode moab::TempestOnlineMap::GenerateRemappingWeights( std::string strInputType,
std::string strOutputType,
const GenerateOfflineMapAlgorithmOptions& mapOptions,
const std::string& srcDofTagName,
const std::string& tgtDofTagName )
{
NcError error( NcError::silent_nonfatal );
moab::DebugOutput dbgprint( std::cout, rank, 0 );
dbgprint.set_prefix( "[TempestOnlineMap]: " );
moab::ErrorCode rval;
const bool m_bPointCloudSource = ( m_remapper->point_cloud_source );
const bool m_bPointCloudTarget = ( m_remapper->point_cloud_target );
const bool m_bPointCloud = m_bPointCloudSource || m_bPointCloudTarget;
try
{
// Check command line parameters (data type arguments)
STLStringHelper::ToLower( strInputType );
STLStringHelper::ToLower( strOutputType );
DiscretizationType eInputType;
DiscretizationType eOutputType;
if( strInputType == "fv" )
{
eInputType = DiscretizationType_FV;
}
else if( strInputType == "cgll" )
{
eInputType = DiscretizationType_CGLL;
}
else if( strInputType == "dgll" )
{
eInputType = DiscretizationType_DGLL;
}
else if( strInputType == "pcloud" )
{
eInputType = DiscretizationType_PCLOUD;
}
else
{
_EXCEPTION1( "Invalid \"in_type\" value (%s), expected [fv|cgll|dgll]", strInputType.c_str() );
}
if( strOutputType == "fv" )
{
eOutputType = DiscretizationType_FV;
}
else if( strOutputType == "cgll" )
{
eOutputType = DiscretizationType_CGLL;
}
else if( strOutputType == "dgll" )
{
eOutputType = DiscretizationType_DGLL;
}
else if( strOutputType == "pcloud" )
{
eOutputType = DiscretizationType_PCLOUD;
}
else
{
_EXCEPTION1( "Invalid \"out_type\" value (%s), expected [fv|cgll|dgll]", strOutputType.c_str() );
}
// set all required input params
m_bConserved = !mapOptions.fNoConservation;
m_eInputType = eInputType;
m_eOutputType = eOutputType;
// Method flags
std::string strMapAlgorithm( "" );
int nMonotoneType = ( mapOptions.fMonotone ) ? ( 1 ) : ( 0 );
// Make an index of method arguments
std::set< std::string > setMethodStrings;
{
int iLast = 0;
for( size_t i = 0; i <= mapOptions.strMethod.length(); i++ )
{
if( ( i == mapOptions.strMethod.length() ) || ( mapOptions.strMethod[i] == ';' ) )
{
std::string strMethodString = mapOptions.strMethod.substr( iLast, i - iLast );
STLStringHelper::RemoveWhitespaceInPlace( strMethodString );
if( strMethodString.length() > 0 )
{
setMethodStrings.insert( strMethodString );
}
iLast = i + 1;
}
}
}
for( auto it : setMethodStrings )
{
// Piecewise constant monotonicity
if( it == "mono2" )
{
if( nMonotoneType != 0 )
{
_EXCEPTIONT( "Multiple monotonicity specifications found (--mono) or (--method \"mono#\")" );
}
if( ( m_eInputType == DiscretizationType_FV ) || ( m_eOutputType == DiscretizationType_FV ) )
{
_EXCEPTIONT( "--method \"mono2\" is only used when remapping to/from CGLL or DGLL grids" );
}
nMonotoneType = 2;
// Piecewise linear monotonicity
}
else if( it == "mono3" )
{
if( nMonotoneType != 0 )
{
_EXCEPTIONT( "Multiple monotonicity specifications found (--mono) or (--method \"mono#\")" );
}
if( ( m_eInputType == DiscretizationType_FV ) || ( m_eOutputType == DiscretizationType_FV ) )
{
_EXCEPTIONT( "--method \"mono3\" is only used when remapping to/from CGLL or DGLL grids" );
}
nMonotoneType = 3;
// Volumetric remapping from FV to GLL
}
else if( it == "volumetric" )
{
if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType == DiscretizationType_FV ) )
{
_EXCEPTIONT( "--method \"volumetric\" may only be used for FV->CGLL or FV->DGLL remapping" );
}
strMapAlgorithm = "volumetric";
// Inverse distance mapping
}
else if( it == "invdist" )
{
if( ( m_eInputType != DiscretizationType_FV ) || ( m_eOutputType != DiscretizationType_FV ) )
{
_EXCEPTIONT( "--method \"invdist\" may only be used for FV->FV remapping" );
}
strMapAlgorithm = "invdist";
}
else
{
_EXCEPTION1( "Invalid --method argument \"%s\"", it.c_str() );
}
}
m_nDofsPEl_Src =
( m_eInputType == DiscretizationType_FV || m_eInputType == DiscretizationType_PCLOUD ? 1
: mapOptions.nPin );
m_nDofsPEl_Dest =
( m_eOutputType == DiscretizationType_FV || m_eOutputType == DiscretizationType_PCLOUD ? 1
: mapOptions.nPout );
rval = SetDOFmapTags( srcDofTagName, tgtDofTagName );MB_CHK_ERR( rval );
double dTotalAreaInput = 0.0, dTotalAreaOutput = 0.0;
if( !m_bPointCloudSource )
{
// Calculate Input Mesh Face areas
if( is_root ) dbgprint.printf( 0, "Calculating input mesh Face areas\n" );
double dTotalAreaInput_loc = m_meshInput->CalculateFaceAreas( mapOptions.fSourceConcave );
dTotalAreaInput = dTotalAreaInput_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dTotalAreaInput_loc, &dTotalAreaInput, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root ) dbgprint.printf( 0, "Input Mesh Geometric Area: %1.15e\n", dTotalAreaInput );
// Input mesh areas
m_meshInputCov->CalculateFaceAreas( mapOptions.fSourceConcave );
}
if( !m_bPointCloudTarget )
{
// Calculate Output Mesh Face areas
if( is_root ) dbgprint.printf( 0, "Calculating output mesh Face areas\n" );
double dTotalAreaOutput_loc = m_meshOutput->CalculateFaceAreas( mapOptions.fTargetConcave );
dTotalAreaOutput = dTotalAreaOutput_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dTotalAreaOutput_loc, &dTotalAreaOutput, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root ) dbgprint.printf( 0, "Output Mesh Geometric Area: %1.15e\n", dTotalAreaOutput );
}
if( !m_bPointCloud )
{
// Verify that overlap mesh is in the correct order, only if size == 1
if( 1 == size )
{
int ixSourceFaceMax = ( -1 );
int ixTargetFaceMax = ( -1 );
if( m_meshOverlap->vecSourceFaceIx.size() != m_meshOverlap->vecTargetFaceIx.size() )
{
_EXCEPTIONT( "Invalid overlap mesh:\n"
" Possible mesh file corruption?" );
}
for( unsigned i = 0; i < m_meshOverlap->faces.size(); i++ )
{
if( m_meshOverlap->vecSourceFaceIx[i] + 1 > ixSourceFaceMax )
ixSourceFaceMax = m_meshOverlap->vecSourceFaceIx[i] + 1;
if( m_meshOverlap->vecTargetFaceIx[i] + 1 > ixTargetFaceMax )
ixTargetFaceMax = m_meshOverlap->vecTargetFaceIx[i] + 1;
}
// Check for forward correspondence in overlap mesh
if( m_meshInput->faces.size() - ixSourceFaceMax == 0 )
{
if( is_root ) dbgprint.printf( 0, "Overlap mesh forward correspondence found\n" );
}
else if( m_meshOutput->faces.size() - ixSourceFaceMax == 0 )
{ // Check for reverse correspondence in overlap mesh
if( is_root ) dbgprint.printf( 0, "Overlap mesh reverse correspondence found (reversing)\n" );
// Reorder overlap mesh
m_meshOverlap->ExchangeFirstAndSecondMesh();
}
// else
// { // No correspondence found
// _EXCEPTION4 ( "Invalid overlap mesh:\n"
// " No correspondence found with input and output meshes (%i,%i)
// vs (%i,%i)", m_meshInputCov->faces.size(),
// m_meshOutput->faces.size(), ixSourceFaceMax, ixTargetFaceMax );
// }
}
// Calculate Face areas
if( is_root ) dbgprint.printf( 0, "Calculating overlap mesh Face areas\n" );
double dTotalAreaOverlap_loc = m_meshOverlap->CalculateFaceAreas( false );
double dTotalAreaOverlap = dTotalAreaOverlap_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dTotalAreaOverlap_loc, &dTotalAreaOverlap, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root ) dbgprint.printf( 0, "Overlap Mesh Area: %1.15e\n", dTotalAreaOverlap );
// Correct areas to match the areas calculated in the overlap mesh
// if (fCorrectAreas)
{
if( is_root ) dbgprint.printf( 0, "Correcting source/target areas to overlap mesh areas\n" );
DataArray1D< double > dSourceArea( m_meshInputCov->faces.size() );
DataArray1D< double > dTargetArea( m_meshOutput->faces.size() );
assert( m_meshOverlap->vecSourceFaceIx.size() == m_meshOverlap->faces.size() );
assert( m_meshOverlap->vecTargetFaceIx.size() == m_meshOverlap->faces.size() );
assert( m_meshOverlap->vecFaceArea.GetRows() == m_meshOverlap->faces.size() );
assert( m_meshInputCov->vecFaceArea.GetRows() == m_meshInputCov->faces.size() );
assert( m_meshOutput->vecFaceArea.GetRows() == m_meshOutput->faces.size() );
for( size_t i = 0; i < m_meshOverlap->faces.size(); i++ )
{
if( m_meshOverlap->vecSourceFaceIx[i] < 0 || m_meshOverlap->vecTargetFaceIx[i] < 0 )
continue; // skip this cell since it is ghosted
// let us recompute the source/target areas based on overlap mesh areas
assert( static_cast< size_t >( m_meshOverlap->vecSourceFaceIx[i] ) < m_meshInputCov->faces.size() );
dSourceArea[m_meshOverlap->vecSourceFaceIx[i]] += m_meshOverlap->vecFaceArea[i];
assert( static_cast< size_t >( m_meshOverlap->vecTargetFaceIx[i] ) < m_meshOutput->faces.size() );
dTargetArea[m_meshOverlap->vecTargetFaceIx[i]] += m_meshOverlap->vecFaceArea[i];
}
for( size_t i = 0; i < m_meshInputCov->faces.size(); i++ )
{
if( fabs( dSourceArea[i] - m_meshInputCov->vecFaceArea[i] ) < 1.0e-10 )
{
m_meshInputCov->vecFaceArea[i] = dSourceArea[i];
}
}
for( size_t i = 0; i < m_meshOutput->faces.size(); i++ )
{
if( fabs( dTargetArea[i] - m_meshOutput->vecFaceArea[i] ) < 1.0e-10 )
{
m_meshOutput->vecFaceArea[i] = dTargetArea[i];
}
}
}
// Set source mesh areas in map
if( !m_bPointCloudSource && eInputType == DiscretizationType_FV )
{
this->SetSourceAreas( m_meshInputCov->vecFaceArea );
if( m_meshInputCov->vecMask.size() )
{
this->SetSourceMask( m_meshInputCov->vecMask );
}
}
// Set target mesh areas in map
if( !m_bPointCloudTarget && eOutputType == DiscretizationType_FV )
{
this->SetTargetAreas( m_meshOutput->vecFaceArea );
if( m_meshOutput->vecMask.size() )
{
this->SetTargetMask( m_meshOutput->vecMask );
}
}
/*
// Recalculate input mesh area from overlap mesh
if (fabs(dTotalAreaOverlap - dTotalAreaInput) > 1.0e-10) {
dbgprint.printf(0, "Overlap mesh only covers a sub-area of the sphere\n");
dbgprint.printf(0, "Recalculating source mesh areas\n");
dTotalAreaInput = m_meshInput->CalculateFaceAreasFromOverlap(m_meshOverlap);
dbgprint.printf(0, "New Input Mesh Geometric Area: %1.15e\n", dTotalAreaInput);
}
*/
}
// Finite volume input / Finite volume output
if( ( eInputType == DiscretizationType_FV ) && ( eOutputType == DiscretizationType_FV ) )
{
// Generate reverse node array and edge map
if( m_meshInputCov->revnodearray.size() == 0 ) m_meshInputCov->ConstructReverseNodeArray();
if( m_meshInputCov->edgemap.size() == 0 ) m_meshInputCov->ConstructEdgeMap( false );
// Initialize coordinates for map
this->InitializeSourceCoordinatesFromMeshFV( *m_meshInputCov );
this->InitializeTargetCoordinatesFromMeshFV( *m_meshOutput );
// Finite volume input / Finite element output
rval = this->SetDOFmapAssociation( eInputType, false, NULL, NULL, eOutputType, false, NULL );MB_CHK_ERR( rval );
// Construct remap
if( is_root ) dbgprint.printf( 0, "Calculating remap weights\n" );
LinearRemapFVtoFV_Tempest_MOAB( mapOptions.nPin );
}
else if( eInputType == DiscretizationType_FV )
{
DataArray3D< double > dataGLLJacobian;
if( is_root ) dbgprint.printf( 0, "Generating output mesh meta data\n" );
double dNumericalArea_loc = GenerateMetaData( *m_meshOutput, mapOptions.nPout, mapOptions.fNoBubble,
dataGLLNodesDest, dataGLLJacobian );
double dNumericalArea = dNumericalArea_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dNumericalArea_loc, &dNumericalArea, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root ) dbgprint.printf( 0, "Output Mesh Numerical Area: %1.15e\n", dNumericalArea );
// Initialize coordinates for map
this->InitializeSourceCoordinatesFromMeshFV( *m_meshInputCov );
this->InitializeTargetCoordinatesFromMeshFE( *m_meshOutput, mapOptions.nPout, dataGLLNodesDest );
// Generate the continuous Jacobian
bool fContinuous = ( eOutputType == DiscretizationType_CGLL );
if( eOutputType == DiscretizationType_CGLL )
{
GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobian, this->GetTargetAreas() );
}
else
{
GenerateDiscontinuousJacobian( dataGLLJacobian, this->GetTargetAreas() );
}
// Generate reverse node array and edge map
if( m_meshInputCov->revnodearray.size() == 0 ) m_meshInputCov->ConstructReverseNodeArray();
if( m_meshInputCov->edgemap.size() == 0 ) m_meshInputCov->ConstructEdgeMap( false );
// Finite volume input / Finite element output
rval = this->SetDOFmapAssociation( eInputType, false, NULL, NULL, eOutputType,
( eOutputType == DiscretizationType_CGLL ), &dataGLLNodesDest );MB_CHK_ERR( rval );
// Generate remap weights
if( strMapAlgorithm == "volumetric" )
{
if( is_root ) dbgprint.printf( 0, "Calculating remapping weights for FV->GLL (volumetric)\n" );
LinearRemapFVtoGLL_Volumetric( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, dataGLLNodesDest,
dataGLLJacobian, this->GetTargetAreas(), mapOptions.nPin, *this,
nMonotoneType, fContinuous, mapOptions.fNoConservation );
}
else
{
if( is_root ) dbgprint.printf( 0, "Calculating remapping weights for FV->GLL\n" );
LinearRemapFVtoGLL( *m_meshInputCov, *m_meshOutput, *m_meshOverlap, dataGLLNodesDest, dataGLLJacobian,
this->GetTargetAreas(), mapOptions.nPin, *this, nMonotoneType, fContinuous,
mapOptions.fNoConservation );
}
}
else if( ( eInputType == DiscretizationType_PCLOUD ) || ( eOutputType == DiscretizationType_PCLOUD ) )
{
DataArray3D< double > dataGLLJacobian;
if( !m_bPointCloudSource )
{
// Generate reverse node array and edge map
if( m_meshInputCov->revnodearray.size() == 0 ) m_meshInputCov->ConstructReverseNodeArray();
if( m_meshInputCov->edgemap.size() == 0 ) m_meshInputCov->ConstructEdgeMap( false );
// Initialize coordinates for map
if( eInputType == DiscretizationType_FV )
{
this->InitializeSourceCoordinatesFromMeshFV( *m_meshInputCov );
}
else
{
if( is_root ) dbgprint.printf( 0, "Generating input mesh meta data\n" );
DataArray3D< double > dataGLLJacobianSrc;
GenerateMetaData( *m_meshInputCov, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrcCov,
dataGLLJacobian );
GenerateMetaData( *m_meshInput, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrc,
dataGLLJacobianSrc );
}
}
// else { /* Source is a point cloud dataset */ }
if( !m_bPointCloudTarget )
{
// Generate reverse node array and edge map
if( m_meshOutput->revnodearray.size() == 0 ) m_meshOutput->ConstructReverseNodeArray();
if( m_meshOutput->edgemap.size() == 0 ) m_meshOutput->ConstructEdgeMap( false );
// Initialize coordinates for map
if( eOutputType == DiscretizationType_FV )
{
this->InitializeSourceCoordinatesFromMeshFV( *m_meshOutput );
}
else
{
if( is_root ) dbgprint.printf( 0, "Generating output mesh meta data\n" );
GenerateMetaData( *m_meshOutput, mapOptions.nPout, mapOptions.fNoBubble, dataGLLNodesDest,
dataGLLJacobian );
}
}
// else { /* Target is a point cloud dataset */ }
// Finite volume input / Finite element output
rval = this->SetDOFmapAssociation(
eInputType, ( eInputType == DiscretizationType_CGLL ),
( m_bPointCloudSource || eInputType == DiscretizationType_FV ? NULL : &dataGLLNodesSrcCov ),
( m_bPointCloudSource || eInputType == DiscretizationType_FV ? NULL : &dataGLLNodesSrc ), eOutputType,
( eOutputType == DiscretizationType_CGLL ), ( m_bPointCloudTarget ? NULL : &dataGLLNodesDest ) );MB_CHK_ERR( rval );
// Construct remap
if( is_root ) dbgprint.printf( 0, "Calculating remap weights with Nearest-Neighbor method\n" );
rval = LinearRemapNN_MOAB( true /*use_GID_matching*/, false /*strict_check*/ );MB_CHK_ERR( rval );
}
else if( ( eInputType != DiscretizationType_FV ) && ( eOutputType == DiscretizationType_FV ) )
{
DataArray3D< double > dataGLLJacobianSrc, dataGLLJacobian;
if( is_root ) dbgprint.printf( 0, "Generating input mesh meta data\n" );
// double dNumericalAreaCov_loc =
GenerateMetaData( *m_meshInputCov, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrcCov,
dataGLLJacobian );
double dNumericalArea_loc = GenerateMetaData( *m_meshInput, mapOptions.nPin, mapOptions.fNoBubble,
dataGLLNodesSrc, dataGLLJacobianSrc );
// if ( is_root ) dbgprint.printf ( 0, "Input Mesh: Coverage Area: %1.15e, Output Area:
// %1.15e\n", dNumericalAreaCov_loc, dTotalAreaOutput_loc );
// assert(dNumericalAreaCov_loc >= dTotalAreaOutput_loc);
double dNumericalArea = dNumericalArea_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dNumericalArea_loc, &dNumericalArea, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root )
{
dbgprint.printf( 0, "Input Mesh Numerical Area: %1.15e\n", dNumericalArea );
if( fabs( dNumericalArea - dTotalAreaInput ) > 1.0e-12 )
{
dbgprint.printf( 0, "WARNING: Significant mismatch between input mesh "
"numerical area and geometric area\n" );
}
}
if( dataGLLNodesSrcCov.GetSubColumns() != m_meshInputCov->faces.size() )
{
_EXCEPTIONT( "Number of element does not match between metadata and "
"input mesh" );
}
// Initialize coordinates for map
this->InitializeSourceCoordinatesFromMeshFE( *m_meshInputCov, mapOptions.nPin, dataGLLNodesSrcCov );
this->InitializeTargetCoordinatesFromMeshFV( *m_meshOutput );
// Generate the continuous Jacobian for input mesh
bool fContinuousIn = ( eInputType == DiscretizationType_CGLL );
if( eInputType == DiscretizationType_CGLL )
{
GenerateUniqueJacobian( dataGLLNodesSrcCov, dataGLLJacobian, this->GetSourceAreas() );
}
else
{
GenerateDiscontinuousJacobian( dataGLLJacobian, this->GetSourceAreas() );
}
// Finite element input / Finite volume output
rval = this->SetDOFmapAssociation( eInputType, ( eInputType == DiscretizationType_CGLL ),
&dataGLLNodesSrcCov, &dataGLLNodesSrc, eOutputType, false, NULL );MB_CHK_ERR( rval );
// Generate remap
if( is_root ) dbgprint.printf( 0, "Calculating remap weights\n" );
if( strMapAlgorithm == "volumetric" )
{
_EXCEPTIONT( "Unimplemented: Volumetric currently unavailable for"
"GLL input mesh" );
}
LinearRemapSE4_Tempest_MOAB( dataGLLNodesSrcCov, dataGLLJacobian, nMonotoneType, fContinuousIn,
mapOptions.fNoConservation );
}
else if( ( eInputType != DiscretizationType_FV ) && ( eOutputType != DiscretizationType_FV ) )
{
DataArray3D< double > dataGLLJacobianIn, dataGLLJacobianSrc;
DataArray3D< double > dataGLLJacobianOut;
// Input metadata
if( is_root ) dbgprint.printf( 0, "Generating input mesh meta data\n" );
GenerateMetaData( *m_meshInputCov, mapOptions.nPin, mapOptions.fNoBubble, dataGLLNodesSrcCov,
dataGLLJacobianIn );
double dNumericalAreaSrc_loc = GenerateMetaData( *m_meshInput, mapOptions.nPin, mapOptions.fNoBubble,
dataGLLNodesSrc, dataGLLJacobianSrc );
double dNumericalAreaIn = dNumericalAreaSrc_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dNumericalAreaSrc_loc, &dNumericalAreaIn, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root )<--- First condition
{
dbgprint.printf( 0, "Input Mesh Numerical Area: %1.15e\n", dNumericalAreaIn );
if( fabs( dNumericalAreaIn - dTotalAreaInput ) > 1.0e-12 )
{
dbgprint.printf( 0, "WARNING: Significant mismatch between input mesh "
"numerical area and geometric area\n" );
}
}
// Output metadata
if( is_root ) dbgprint.printf( 0, "Generating output mesh meta data\n" );<--- Second condition
double dNumericalAreaOut_loc = GenerateMetaData( *m_meshOutput, mapOptions.nPout, mapOptions.fNoBubble,
dataGLLNodesDest, dataGLLJacobianOut );
double dNumericalAreaOut = dNumericalAreaOut_loc;
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
MPI_Reduce( &dNumericalAreaOut_loc, &dNumericalAreaOut, 1, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
#endif
if( is_root )
{
dbgprint.printf( 0, "Output Mesh Numerical Area: %1.15e\n", dNumericalAreaOut );
if( fabs( dNumericalAreaOut - dTotalAreaOutput ) > 1.0e-12 )
{
if( is_root )
dbgprint.printf( 0, "WARNING: Significant mismatch between output mesh "
"numerical area and geometric area\n" );
}
}
// Initialize coordinates for map
this->InitializeSourceCoordinatesFromMeshFE( *m_meshInputCov, mapOptions.nPin, dataGLLNodesSrcCov );
this->InitializeTargetCoordinatesFromMeshFE( *m_meshOutput, mapOptions.nPout, dataGLLNodesDest );
// Generate the continuous Jacobian for input mesh
bool fContinuousIn = ( eInputType == DiscretizationType_CGLL );
if( eInputType == DiscretizationType_CGLL )
{
GenerateUniqueJacobian( dataGLLNodesSrcCov, dataGLLJacobianIn, this->GetSourceAreas() );
}
else
{
GenerateDiscontinuousJacobian( dataGLLJacobianIn, this->GetSourceAreas() );
}
// Generate the continuous Jacobian for output mesh
bool fContinuousOut = ( eOutputType == DiscretizationType_CGLL );
if( eOutputType == DiscretizationType_CGLL )
{
GenerateUniqueJacobian( dataGLLNodesDest, dataGLLJacobianOut, this->GetTargetAreas() );
}
else
{
GenerateDiscontinuousJacobian( dataGLLJacobianOut, this->GetTargetAreas() );
}
// Input Finite Element to Output Finite Element
rval = this->SetDOFmapAssociation( eInputType, ( eInputType == DiscretizationType_CGLL ),
&dataGLLNodesSrcCov, &dataGLLNodesSrc, eOutputType,
( eOutputType == DiscretizationType_CGLL ), &dataGLLNodesDest );MB_CHK_ERR( rval );
// Generate remap
if( is_root ) dbgprint.printf( 0, "Calculating remap weights\n" );
LinearRemapGLLtoGLL2_MOAB( dataGLLNodesSrcCov, dataGLLJacobianIn, dataGLLNodesDest, dataGLLJacobianOut,
this->GetTargetAreas(), mapOptions.nPin, mapOptions.nPout, nMonotoneType,
fContinuousIn, fContinuousOut, mapOptions.fNoConservation );
}
else
{
_EXCEPTIONT( "Not implemented" );
}
#ifdef MOAB_HAVE_EIGEN3
copy_tempest_sparsemat_to_eigen3();
#endif
#ifdef MOAB_HAVE_MPI
{
// Remove ghosted entities from overlap set
moab::Range ghostedEnts;
rval = m_remapper->GetOverlapAugmentedEntities( ghostedEnts );MB_CHK_ERR( rval );
moab::EntityHandle m_meshOverlapSet = m_remapper->GetMeshSet( moab::Remapper::OverlapMesh );
rval = m_interface->remove_entities( m_meshOverlapSet, ghostedEnts );MB_CHK_SET_ERR( rval, "Deleting ghosted entities failed" );
}
#endif
// Verify consistency, conservation and monotonicity, globally
if( !mapOptions.fNoCheck )
{
if( is_root ) dbgprint.printf( 0, "Verifying map" );
this->IsConsistent( 1.0e-8 );
if( !mapOptions.fNoConservation ) this->IsConservative( 1.0e-8 );
if( nMonotoneType != 0 )
{
this->IsMonotone( 1.0e-12 );
}
}
}
catch( Exception& e )
{
dbgprint.printf( 0, "%s", e.ToString().c_str() );
return ( moab::MB_FAILURE );
}
catch( ... )
{
return ( moab::MB_FAILURE );
}
return moab::MB_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
int moab::TempestOnlineMap::IsConsistent( double dTolerance )
{
#ifndef MOAB_HAVE_MPI
return OfflineMap::IsConsistent( dTolerance );
#else
// Get map entries
DataArray1D< int > dataRows;
DataArray1D< int > dataCols;
DataArray1D< double > dataEntries;
// Calculate row sums
DataArray1D< double > dRowSums;
m_mapRemap.GetEntries( dataRows, dataCols, dataEntries );
dRowSums.Allocate( m_mapRemap.GetRows() );
for( unsigned i = 0; i < dataRows.GetRows(); i++ )
{
dRowSums[dataRows[i]] += dataEntries[i];
}
// Verify all row sums are equal to 1
int fConsistent = 0;
for( unsigned i = 0; i < dRowSums.GetRows(); i++ )
{
if( fabs( dRowSums[i] - 1.0 ) > dTolerance )
{
fConsistent++;
int rowGID = row_gdofmap[i];
Announce( "TempestOnlineMap is not consistent in row %i (%1.15e)", rowGID, dRowSums[i] );
}
}
int ierr;
int fConsistentGlobal = 0;
ierr = MPI_Allreduce( &fConsistent, &fConsistentGlobal, 1, MPI_INT, MPI_SUM, m_pcomm->comm() );
if( ierr != MPI_SUCCESS ) return -1;
return fConsistentGlobal;
#endif
}
///////////////////////////////////////////////////////////////////////////////
int moab::TempestOnlineMap::IsConservative( double dTolerance )
{
#ifndef MOAB_HAVE_MPI
return OfflineMap::IsConservative( dTolerance );
#else
// return OfflineMap::IsConservative(dTolerance);
int ierr;
// Get map entries
DataArray1D< int > dataRows;
DataArray1D< int > dataCols;
DataArray1D< double > dataEntries;
const DataArray1D< double >& dTargetAreas = this->GetTargetAreas();
const DataArray1D< double >& dSourceAreas = this->GetSourceAreas();
// Calculate column sums
std::vector< int > dColumnsUnique;
std::vector< double > dColumnSums;
int nColumns = m_mapRemap.GetColumns();
m_mapRemap.GetEntries( dataRows, dataCols, dataEntries );
dColumnSums.resize( m_nTotDofs_SrcCov, 0.0 );
dColumnsUnique.resize( m_nTotDofs_SrcCov, -1 );
for( unsigned i = 0; i < dataEntries.GetRows(); i++ )
{
dColumnSums[dataCols[i]] += dataEntries[i] * dTargetAreas[dataRows[i]] / dSourceAreas[dataCols[i]];
assert( dataCols[i] < m_nTotDofs_SrcCov );
// GID for column DoFs: col_gdofmap[ col_ldofmap [ dataCols[i] ] ]
int colGID = this->GetColGlobalDoF( dataCols[i] ); // col_gdofmap[ col_ldofmap [ dataCols[i] ] ];
// int colGID = col_gdofmap[ col_ldofmap [ dataCols[i] ] ];
dColumnsUnique[dataCols[i]] = colGID;
// std::cout << "Column dataCols[i]=" << dataCols[i] << " with GID = " << colGID <<
// std::endl;
}
int rootProc = 0;
std::vector< int > nElementsInProc;
const int nDATA = 3;
if( !rank ) nElementsInProc.resize( size * nDATA );
int senddata[nDATA] = { nColumns, m_nTotDofs_SrcCov, m_nTotDofs_Src };
ierr = MPI_Gather( senddata, nDATA, MPI_INT, nElementsInProc.data(), nDATA, MPI_INT, rootProc, m_pcomm->comm() );
if( ierr != MPI_SUCCESS ) return -1;
int nTotVals = 0, nTotColumns = 0, nTotColumnsUnq = 0;<--- The scope of the variable 'nTotVals' can be reduced. [+]The scope of the variable 'nTotVals' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
std::vector< int > dColumnIndices;
std::vector< double > dColumnSourceAreas;<--- Unused variable: dColumnSourceAreas
std::vector< double > dColumnSumsTotal;
std::vector< int > displs, rcount;
if( rank == rootProc )
{
displs.resize( size + 1, 0 );
rcount.resize( size, 0 );
int gsum = 0;
for( int ir = 0; ir < size; ++ir )
{
nTotVals += nElementsInProc[ir * nDATA];
nTotColumns += nElementsInProc[ir * nDATA + 1];
nTotColumnsUnq += nElementsInProc[ir * nDATA + 2];
displs[ir] = gsum;
rcount[ir] = nElementsInProc[ir * nDATA + 1];
gsum += rcount[ir];
// printf("%d: nTotColumns: %d, Displs: %d, rcount: %d, gsum = %d\n", ir, nTotColumns,
// displs[ir], rcount[ir], gsum);
}
dColumnIndices.resize( nTotColumns, -1 );
dColumnSumsTotal.resize( nTotColumns, 0.0 );
// dColumnSourceAreas.resize ( nTotColumns, 0.0 );
}
// Gather all ColumnSums to root process and accumulate
// We expect that the sums of all columns equate to 1.0 within user specified tolerance
// Need to do a gatherv here since different processes have different number of elements
// MPI_Reduce(&dColumnSums[0], &dColumnSumsTotal[0], m_mapRemap.GetColumns(), MPI_DOUBLE,
// MPI_SUM, 0, m_pcomm->comm());
ierr = MPI_Gatherv( &dColumnsUnique[0], m_nTotDofs_SrcCov, MPI_INT, &dColumnIndices[0], rcount.data(),
displs.data(), MPI_INT, rootProc, m_pcomm->comm() );
if( ierr != MPI_SUCCESS ) return -1;
ierr = MPI_Gatherv( &dColumnSums[0], m_nTotDofs_SrcCov, MPI_DOUBLE, &dColumnSumsTotal[0], rcount.data(),
displs.data(), MPI_DOUBLE, rootProc, m_pcomm->comm() );
if( ierr != MPI_SUCCESS ) return -1;
// ierr = MPI_Gatherv ( &dSourceAreas[0], m_nTotDofs_SrcCov, MPI_DOUBLE, &dColumnSourceAreas[0],
// rcount.data(), displs.data(), MPI_DOUBLE, rootProc, m_pcomm->comm() ); if ( ierr !=
// MPI_SUCCESS ) return -1;
// Clean out unwanted arrays now
dColumnSums.clear();
dColumnsUnique.clear();
// Verify all column sums equal the input Jacobian
int fConservative = 0;
if( rank == rootProc )
{
displs[size] = ( nTotColumns );
// std::vector<double> dColumnSumsOnRoot(nTotColumnsUnq, 0.0);
std::map< int, double > dColumnSumsOnRoot;
// std::map<int, double> dColumnSourceAreasOnRoot;
for( int ir = 0; ir < size; ir++ )
{
for( int ips = displs[ir]; ips < displs[ir + 1]; ips++ )
{
if( dColumnIndices[ips] < 0 ) continue;
// printf("%d, %d: dColumnIndices[ips]: %d\n", ir, ips, dColumnIndices[ips]);
assert( dColumnIndices[ips] < nTotColumnsUnq );
dColumnSumsOnRoot[dColumnIndices[ips]] += dColumnSumsTotal[ips]; // / dColumnSourceAreas[ips];
// dColumnSourceAreasOnRoot[ dColumnIndices[ips] ] = dColumnSourceAreas[ips];
// dColumnSourceAreas[ dColumnIndices[ips] ]
}
}
for( std::map< int, double >::iterator it = dColumnSumsOnRoot.begin(); it != dColumnSumsOnRoot.end(); ++it )
{
// if ( fabs ( it->second - dColumnSourceAreasOnRoot[it->first] ) > dTolerance )
if( fabs( it->second - 1.0 ) > dTolerance )
{
fConservative++;
Announce( "TempestOnlineMap is not conservative in column "
// "%i (%1.15e)", it->first, it->second );
"%i (%1.15e)",
it->first, it->second /* / dColumnSourceAreasOnRoot[it->first] */ );
}
}
}
// TODO: Just do a broadcast from root instead of a reduction
ierr = MPI_Bcast( &fConservative, 1, MPI_INT, rootProc, m_pcomm->comm() );
if( ierr != MPI_SUCCESS ) return -1;
return fConservative;
#endif
}
///////////////////////////////////////////////////////////////////////////////
int moab::TempestOnlineMap::IsMonotone( double dTolerance )
{
#ifndef MOAB_HAVE_MPI
return OfflineMap::IsMonotone( dTolerance );
#else
// Get map entries
DataArray1D< int > dataRows;
DataArray1D< int > dataCols;
DataArray1D< double > dataEntries;
m_mapRemap.GetEntries( dataRows, dataCols, dataEntries );
// Verify all entries are in the range [0,1]
int fMonotone = 0;
for( unsigned i = 0; i < dataRows.GetRows(); i++ )
{
if( ( dataEntries[i] < -dTolerance ) || ( dataEntries[i] > 1.0 + dTolerance ) )
{
fMonotone++;
Announce( "TempestOnlineMap is not monotone in entry (%i): %1.15e", i, dataEntries[i] );
}
}
int ierr;
int fMonotoneGlobal = 0;
ierr = MPI_Allreduce( &fMonotone, &fMonotoneGlobal, 1, MPI_INT, MPI_SUM, m_pcomm->comm() );
if( ierr != MPI_SUCCESS ) return -1;
return fMonotoneGlobal;
#endif
}
///////////////////////////////////////////////////////////////////////////////
moab::ErrorCode moab::TempestOnlineMap::ApplyWeights( moab::Tag srcSolutionTag,
moab::Tag tgtSolutionTag,
bool transpose )
{
moab::ErrorCode rval;
std::vector< double > solSTagVals;
std::vector< double > solTTagVals;
moab::Range sents, tents;
if( m_remapper->point_cloud_source || m_remapper->point_cloud_target )
{
if( m_remapper->point_cloud_source )
{
moab::Range& covSrcEnts = m_remapper->GetMeshVertices( moab::Remapper::CoveringMesh );
solSTagVals.resize( covSrcEnts.size(), -1.0 );
sents = covSrcEnts;
}
else
{
moab::Range& covSrcEnts = m_remapper->GetMeshEntities( moab::Remapper::CoveringMesh );
solSTagVals.resize( covSrcEnts.size() * this->GetSourceNDofsPerElement() * this->GetSourceNDofsPerElement(),
-1.0 );
sents = covSrcEnts;
}
if( m_remapper->point_cloud_target )
{
moab::Range& tgtEnts = m_remapper->GetMeshVertices( moab::Remapper::TargetMesh );
solTTagVals.resize( tgtEnts.size(), -1.0 );
tents = tgtEnts;
}
else
{
moab::Range& tgtEnts = m_remapper->GetMeshEntities( moab::Remapper::TargetMesh );
solTTagVals.resize(
tgtEnts.size() * this->GetDestinationNDofsPerElement() * this->GetDestinationNDofsPerElement(), -1.0 );
tents = tgtEnts;
}
}
else
{
moab::Range& covSrcEnts = m_remapper->GetMeshEntities( moab::Remapper::CoveringMesh );
moab::Range& tgtEnts = m_remapper->GetMeshEntities( moab::Remapper::TargetMesh );
solSTagVals.resize( covSrcEnts.size() * this->GetSourceNDofsPerElement() * this->GetSourceNDofsPerElement(),
-1.0 );
solTTagVals.resize(
tgtEnts.size() * this->GetDestinationNDofsPerElement() * this->GetDestinationNDofsPerElement(), -1.0 );
sents = covSrcEnts;
tents = tgtEnts;
}
// The tag data is np*np*n_el_src
rval = m_interface->tag_get_data( srcSolutionTag, sents, &solSTagVals[0] );MB_CHK_SET_ERR( rval, "Getting local tag data failed" );
// Compute the application of weights on the suorce solution data and store it in the
// destination solution vector data Optionally, can also perform the transpose application of
// the weight matrix. Set the 3rd argument to true if this is needed
rval = this->ApplyWeights( solSTagVals, solTTagVals, transpose );MB_CHK_SET_ERR( rval, "Applying remap operator onto source vector data failed" );
// The tag data is np*np*n_el_dest
rval = m_interface->tag_set_data( tgtSolutionTag, tents, &solTTagVals[0] );MB_CHK_SET_ERR( rval, "Setting local tag data failed" );
return moab::MB_SUCCESS;
}
moab::ErrorCode moab::TempestOnlineMap::DefineAnalyticalSolution( moab::Tag& solnTag,
const std::string& solnName,
moab::Remapper::IntersectionContext ctx,
sample_function testFunction,
moab::Tag* clonedSolnTag,
std::string cloneSolnName )
{
moab::ErrorCode rval;
const bool outputEnabled = ( is_root );
int discOrder;
DiscretizationType discMethod;
moab::EntityHandle meshset;
moab::Range entities;
Mesh* trmesh;
switch( ctx )
{
case Remapper::SourceMesh:
meshset = m_remapper->m_covering_source_set;<--- Variable 'meshset' is assigned a value that is never used.
trmesh = m_remapper->m_covering_source;
entities = ( m_remapper->point_cloud_source ? m_remapper->m_covering_source_vertices
: m_remapper->m_covering_source_entities );
discOrder = m_nDofsPEl_Src;
discMethod = m_eInputType;
break;
case Remapper::TargetMesh:
meshset = m_remapper->m_target_set;<--- Variable 'meshset' is assigned a value that is never used.
trmesh = m_remapper->m_target;
entities =
( m_remapper->point_cloud_target ? m_remapper->m_target_vertices : m_remapper->m_target_entities );
discOrder = m_nDofsPEl_Dest;
discMethod = m_eOutputType;
break;
default:
if( outputEnabled )
std::cout << "Invalid context specified for defining an analytical solution tag" << std::endl;
return moab::MB_FAILURE;
}
// Let us create teh solution tag with appropriate information for name, discretization order
// (DoF space)
rval = m_interface->tag_get_handle( solnName.c_str(), discOrder * discOrder, MB_TYPE_DOUBLE, solnTag,
MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_ERR( rval );
if( clonedSolnTag != NULL )
{
if( cloneSolnName.size() == 0 )
{
cloneSolnName = solnName + std::string( "Cloned" );
}
rval = m_interface->tag_get_handle( cloneSolnName.c_str(), discOrder * discOrder, MB_TYPE_DOUBLE,
*clonedSolnTag, MB_TAG_DENSE | MB_TAG_CREAT );MB_CHK_ERR( rval );
}
// Triangular quadrature rule
const int TriQuadratureOrder = 10;
if( outputEnabled ) std::cout << "Using triangular quadrature of order " << TriQuadratureOrder << std::endl;
TriangularQuadratureRule triquadrule( TriQuadratureOrder );
const int TriQuadraturePoints = triquadrule.GetPoints();
const DataArray2D< double >& TriQuadratureG = triquadrule.GetG();
const DataArray1D< double >& TriQuadratureW = triquadrule.GetW();
// Output data
DataArray1D< double > dVar;
DataArray1D< double > dVarMB; // re-arranged local MOAB vector
// Nodal geometric area
DataArray1D< double > dNodeArea;
// Calculate element areas
// trmesh->CalculateFaceAreas(fContainsConcaveFaces);
if( discMethod == DiscretizationType_CGLL || discMethod == DiscretizationType_DGLL )
{
/* Get the spectral points and sample the functionals accordingly */
const bool fGLL = true;
const bool fGLLIntegrate = false;
// Generate grid metadata
DataArray3D< int > dataGLLNodes;
DataArray3D< double > dataGLLJacobian;
GenerateMetaData( *trmesh, discOrder, false, dataGLLNodes, dataGLLJacobian );
// Number of elements
int nElements = trmesh->faces.size();
// Verify all elements are quadrilaterals
for( int k = 0; k < nElements; k++ )
{
const Face& face = trmesh->faces[k];
if( face.edges.size() != 4 )
{
_EXCEPTIONT( "Non-quadrilateral face detected; "
"incompatible with --gll" );
}
}
// Number of unique nodes
int iMaxNode = 0;
for( int i = 0; i < discOrder; i++ )
{
for( int j = 0; j < discOrder; j++ )
{
for( int k = 0; k < nElements; k++ )
{
if( dataGLLNodes[i][j][k] > iMaxNode )
{
iMaxNode = dataGLLNodes[i][j][k];
}
}
}
}
// Get Gauss-Lobatto quadrature nodes
DataArray1D< double > dG;
DataArray1D< double > dW;
GaussLobattoQuadrature::GetPoints( discOrder, 0.0, 1.0, dG, dW );
// Get Gauss quadrature nodes
const int nGaussP = 10;
DataArray1D< double > dGaussG;
DataArray1D< double > dGaussW;
GaussQuadrature::GetPoints( nGaussP, 0.0, 1.0, dGaussG, dGaussW );
// Allocate data
dVar.Allocate( iMaxNode );
dVarMB.Allocate( discOrder * discOrder * nElements );
dNodeArea.Allocate( iMaxNode );
// Sample data
for( int k = 0; k < nElements; k++ )
{
const Face& face = trmesh->faces[k];
// Sample data at GLL nodes
if( fGLL )
{
for( int i = 0; i < discOrder; i++ )
{
for( int j = 0; j < discOrder; j++ )
{
// Apply local map
Node node;
Node dDx1G;
Node dDx2G;
ApplyLocalMap( face, trmesh->nodes, dG[i], dG[j], node, dDx1G, dDx2G );
// Sample data at this point
double dNodeLon = atan2( node.y, node.x );
if( dNodeLon < 0.0 )
{
dNodeLon += 2.0 * M_PI;
}
double dNodeLat = asin( node.z );
double dSample = ( *testFunction )( dNodeLon, dNodeLat );
dVar[dataGLLNodes[j][i][k] - 1] = dSample;
}
}
// High-order Gaussian integration over basis function
}
else
{
DataArray2D< double > dCoeff( discOrder, discOrder );
for( int p = 0; p < nGaussP; p++ )
{
for( int q = 0; q < nGaussP; q++ )
{
// Apply local map
Node node;
Node dDx1G;
Node dDx2G;
ApplyLocalMap( face, trmesh->nodes, dGaussG[p], dGaussG[q], node, dDx1G, dDx2G );
// Cross product gives local Jacobian
Node nodeCross = CrossProduct( dDx1G, dDx2G );
double dJacobian =
sqrt( nodeCross.x * nodeCross.x + nodeCross.y * nodeCross.y + nodeCross.z * nodeCross.z );
// Find components of quadrature point in basis
// of the first Face
SampleGLLFiniteElement( 0, discOrder, dGaussG[p], dGaussG[q], dCoeff );
// Sample data at this point
double dNodeLon = atan2( node.y, node.x );
if( dNodeLon < 0.0 )
{
dNodeLon += 2.0 * M_PI;
}
double dNodeLat = asin( node.z );
double dSample = ( *testFunction )( dNodeLon, dNodeLat );
// Integrate
for( int i = 0; i < discOrder; i++ )
{
for( int j = 0; j < discOrder; j++ )
{
double dNodalArea = dCoeff[i][j] * dGaussW[p] * dGaussW[q] * dJacobian;
dVar[dataGLLNodes[i][j][k] - 1] += dSample * dNodalArea;
dNodeArea[dataGLLNodes[i][j][k] - 1] += dNodalArea;
}
}
}
}
}
}
// Divide by area
if( fGLLIntegrate )
{
for( size_t i = 0; i < dVar.GetRows(); i++ )
{
dVar[i] /= dNodeArea[i];
}
}
// Let us rearrange the data based on DoF ID specification
if( ctx == Remapper::SourceMesh )
{
for( unsigned j = 0; j < entities.size(); j++ )
for( int p = 0; p < discOrder; p++ )
for( int q = 0; q < discOrder; q++ )
{
const int offsetDOF = j * discOrder * discOrder + p * discOrder + q;
dVarMB[offsetDOF] = dVar[col_dtoc_dofmap[offsetDOF]];
}
}
else
{
for( unsigned j = 0; j < entities.size(); j++ )
for( int p = 0; p < discOrder; p++ )
for( int q = 0; q < discOrder; q++ )
{
const int offsetDOF = j * discOrder * discOrder + p * discOrder + q;
dVarMB[offsetDOF] = dVar[row_dtoc_dofmap[offsetDOF]];
}
}
// Set the tag data
rval = m_interface->tag_set_data( solnTag, entities, &dVarMB[0] );MB_CHK_ERR( rval );
}
else
{
// assert( discOrder == 1 );
if( discMethod == DiscretizationType_FV )
{
/* Compute an element-wise integral to store the sampled solution based on Quadrature
* rules */
// Resize the array
dVar.Allocate( trmesh->faces.size() );
std::vector< Node >& nodes = trmesh->nodes;
// Loop through all Faces
for( size_t i = 0; i < trmesh->faces.size(); i++ )
{
const Face& face = trmesh->faces[i];
// Loop through all sub-triangles
for( size_t j = 0; j < face.edges.size() - 2; j++ )
{
const Node& node0 = nodes[face[0]];
const Node& node1 = nodes[face[j + 1]];
const Node& node2 = nodes[face[j + 2]];
// Triangle area
Face faceTri( 3 );
faceTri.SetNode( 0, face[0] );
faceTri.SetNode( 1, face[j + 1] );
faceTri.SetNode( 2, face[j + 2] );
double dTriangleArea = CalculateFaceArea( faceTri, nodes );
// Calculate the element average
double dTotalSample = 0.0;
// Loop through all quadrature points
for( int k = 0; k < TriQuadraturePoints; k++ )
{
Node node( TriQuadratureG[k][0] * node0.x + TriQuadratureG[k][1] * node1.x +
TriQuadratureG[k][2] * node2.x,
TriQuadratureG[k][0] * node0.y + TriQuadratureG[k][1] * node1.y +
TriQuadratureG[k][2] * node2.y,
TriQuadratureG[k][0] * node0.z + TriQuadratureG[k][1] * node1.z +
TriQuadratureG[k][2] * node2.z );
double dMagnitude = node.Magnitude();
node.x /= dMagnitude;
node.y /= dMagnitude;
node.z /= dMagnitude;
double dLon = atan2( node.y, node.x );
if( dLon < 0.0 )
{
dLon += 2.0 * M_PI;
}
double dLat = asin( node.z );
double dSample = ( *testFunction )( dLon, dLat );
dTotalSample += dSample * TriQuadratureW[k] * dTriangleArea;
}
dVar[i] += dTotalSample / trmesh->vecFaceArea[i];
}
}
rval = m_interface->tag_set_data( solnTag, entities, &dVar[0] );MB_CHK_ERR( rval );
}
else /* discMethod == DiscretizationType_PCLOUD */
{
/* Get the coordinates of the vertices and sample the functionals accordingly */
std::vector< Node >& nodes = trmesh->nodes;
// Resize the array
dVar.Allocate( nodes.size() );
for( size_t j = 0; j < nodes.size(); j++ )
{
Node& node = nodes[j];
double dMagnitude = node.Magnitude();
node.x /= dMagnitude;
node.y /= dMagnitude;
node.z /= dMagnitude;
double dLon = atan2( node.y, node.x );
if( dLon < 0.0 )
{
dLon += 2.0 * M_PI;
}
double dLat = asin( node.z );
double dSample = ( *testFunction )( dLon, dLat );
dVar[j] = dSample;
}
rval = m_interface->tag_set_data( solnTag, entities, &dVar[0] );MB_CHK_ERR( rval );
}
}
return moab::MB_SUCCESS;
}
moab::ErrorCode moab::TempestOnlineMap::ComputeMetrics( moab::Remapper::IntersectionContext ctx,
moab::Tag& exactTag,
moab::Tag& approxTag,
std::map< std::string, double >& metrics,
bool verbose )
{
moab::ErrorCode rval;
const bool outputEnabled = ( is_root );
int discOrder;
DiscretizationType discMethod;
moab::EntityHandle meshset;
moab::Range entities;
Mesh* trmesh;
switch( ctx )
{
case Remapper::SourceMesh:
meshset = m_remapper->m_covering_source_set;<--- Variable 'meshset' is assigned a value that is never used.
trmesh = m_remapper->m_covering_source;<--- Variable 'trmesh' is assigned a value that is never used.
entities = ( m_remapper->point_cloud_source ? m_remapper->m_covering_source_vertices
: m_remapper->m_covering_source_entities );
discOrder = m_nDofsPEl_Src;
discMethod = m_eInputType;<--- Variable 'discMethod' is assigned a value that is never used.
break;
case Remapper::TargetMesh:
meshset = m_remapper->m_target_set;<--- Variable 'meshset' is assigned a value that is never used.
trmesh = m_remapper->m_target;<--- Variable 'trmesh' is assigned a value that is never used.
entities =
( m_remapper->point_cloud_target ? m_remapper->m_target_vertices : m_remapper->m_target_entities );
discOrder = m_nDofsPEl_Dest;
discMethod = m_eOutputType;<--- Variable 'discMethod' is assigned a value that is never used.
break;
default:
if( outputEnabled )
std::cout << "Invalid context specified for defining an analytical solution tag" << std::endl;
return moab::MB_FAILURE;
}
// Let us create teh solution tag with appropriate information for name, discretization order
// (DoF space)
std::string exactTagName, projTagName;
const int ntotsize = entities.size() * discOrder * discOrder;
int ntotsize_glob = 0;
std::vector< double > exactSolution( ntotsize, 0.0 ), projSolution( ntotsize, 0.0 );
rval = m_interface->tag_get_name( exactTag, exactTagName );MB_CHK_ERR( rval );
rval = m_interface->tag_get_data( exactTag, entities, &exactSolution[0] );MB_CHK_ERR( rval );
rval = m_interface->tag_get_name( approxTag, projTagName );MB_CHK_ERR( rval );
rval = m_interface->tag_get_data( approxTag, entities, &projSolution[0] );MB_CHK_ERR( rval );
std::vector< double > errnorms( 3, 0.0 ), globerrnorms( 3, 0.0 ); // L1Err, L2Err, LinfErr
for( int i = 0; i < ntotsize; ++i )
{
const double error = fabs( exactSolution[i] - projSolution[i] );
errnorms[0] += error;
errnorms[1] += error * error;
errnorms[2] = ( error > errnorms[2] ? error : errnorms[2] );
}
#ifdef MOAB_HAVE_MPI
if( m_pcomm )
{
MPI_Reduce( &ntotsize, &ntotsize_glob, 1, MPI_INT, MPI_SUM, 0, m_pcomm->comm() );
MPI_Reduce( &errnorms[0], &globerrnorms[0], 2, MPI_DOUBLE, MPI_SUM, 0, m_pcomm->comm() );
MPI_Reduce( &errnorms[2], &globerrnorms[2], 1, MPI_DOUBLE, MPI_MAX, 0, m_pcomm->comm() );
}
#else
ntotsize_glob = ntotsize;
globerrnorms = errnorms;
#endif
globerrnorms[0] = ( globerrnorms[0] / ntotsize_glob );
globerrnorms[1] = std::sqrt( globerrnorms[1] / ntotsize_glob );
metrics.clear();
metrics["L1Error"] = globerrnorms[0];
metrics["L2Error"] = globerrnorms[1];
metrics["LinfError"] = globerrnorms[2];
if( verbose && is_root )
{
std::cout << "Error metrics when comparing " << projTagName << " against " << exactTagName << std::endl;
std::cout << "\t L_1 error = " << globerrnorms[0] << std::endl;
std::cout << "\t L_2 error = " << globerrnorms[1] << std::endl;
std::cout << "\t L_inf error = " << globerrnorms[2] << std::endl;
}
return moab::MB_SUCCESS;
}
|