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
// *****************************************************************************
/*!
  \file      tests/unit/Mesh/TestAround.cpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2024 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     Unit tests for Mesh/Around
  \details   Unit tests for Mesh/Around.
*/
// *****************************************************************************

#include "NoWarning/tut.hpp"

#include "TUTConfig.hpp"
#include "Around.hpp"
#include "Reorder.hpp"
#include "DerivedData.hpp"

#ifndef DOXYGEN_GENERATING_OUTPUT

namespace tut {

//! All tests in group inherited from this base
struct Around_common {

  // Mesh connectivity for simple tetrahedron-only mesh
  std::vector< std::size_t > inpoel { 12, 14,  9, 11,<--- struct member 'Around_common::inpoel' is never used.
                                      10, 14, 13, 12,
                                      14, 13, 12,  9,
                                      10, 14, 12, 11,
                                      1,  14,  5, 11,
                                      7,   6, 10, 12,
                                      14,  8,  5, 10,
                                      8,   7, 10, 13,
                                      7,  13,  3, 12,
                                      1,   4, 14,  9,
                                      13,  4,  3,  9,
                                      3,   2, 12,  9,
                                      4,   8, 14, 13,
                                      6,   5, 10, 11,
                                      1,   2,  9, 11,
                                      2,   6, 12, 11,
                                      6,  10, 12, 11,
                                      2,  12,  9, 11,
                                      5,  14, 10, 11,
                                      14,  8, 10, 13,
                                      13,  3, 12,  9,
                                      7,  10, 13, 12,
                                      14,  4, 13,  9,
                                      14,  1,  9, 11 };

  // Mesh connectivity for simple triangle-only mesh
  std::vector< std::size_t > triinpoel { 1,  9,  2,<--- struct member 'Around_common::triinpoel' is never used.
                                         1,  4,  9,
                                         2,  9,  3,
                                         3,  9,  4,
                                         5,  6, 10,
                                         5, 10,  8,
                                         6,  7, 10,
                                         7,  8, 10,
                                         1,  2, 11,
                                         1, 11,  5,
                                         2,  6, 11,
                                         5, 11,  6,
                                         2,  3, 12,
                                         2, 12,  6,
                                         3,  7, 12,
                                         6, 12,  7,
                                         3,  4, 13,
                                         3, 13,  7,
                                         4,  8, 13,
                                         7, 13,  8,
                                         1, 14,  4,
                                         1,  5, 14,
                                         4, 14,  8,
                                         5,  8, 14 };
};

// Test group shortcuts
// The 2nd template argument is the max number of tests in this group. If
// omitted, the default is 50, specified in tut/tut.hpp.
using Around_group = test_group< Around_common, MAX_TESTS_IN_GROUP >;
using Around_object = Around_group::object;

//! Define test group
static Around_group Around( "Mesh/Around" );

//! Test definitions for group

//! Iterate via Around on elements surrounding points for tetrahedron-only mesh
template<> template<>
void Around_object::test< 1 >() {
  set_test_name( "Esup for tetrahedra" );

  // Shift node IDs to start from zero
  tk::shiftToZero( inpoel );

  // Generate elements surrounding points
  auto esup = tk::genEsup( inpoel, 4 );

  // Generate correct solution for elements surrounding points
  std::map< std::size_t, std::vector< std::size_t > > correct_esup {
    { { 0 }, { 4, 9, 14, 23 } },
    { { 1 }, { 11, 14, 15, 17 } },
    { { 2 }, { 8, 10, 11, 20 } },
    { { 3 }, { 9, 10, 12, 22 } },
    { { 4 }, { 4, 6, 13, 18 } },
    { { 5 }, { 5, 13, 15, 16 } },
    { { 6 }, { 5, 7, 8, 21 } },
    { { 7 }, { 6, 7, 12, 19 } },
    { { 8 }, { 0, 2, 9, 10, 11, 14, 17, 20, 22, 23 } },
    { { 9 }, { 1, 3, 5, 6, 7, 13, 16, 18, 19, 21 } },
    { { 10 }, { 0, 3, 4, 13, 14, 15, 16, 17, 18, 23 } },
    { { 11 }, { 0, 1, 2, 3, 5, 8, 11, 15, 16, 17, 20, 21 } },
    { { 12 }, { 1, 2, 7, 8, 10, 12, 19, 20, 21, 22 } },
    { { 13 }, { 0, 1, 2, 3, 4, 6, 9, 12, 18, 19, 22, 23 } }
  };

  // find out number of points from mesh connectivity
  auto minmax = std::minmax_element( begin(inpoel), end(inpoel) );
  Assert( *minmax.first == 0, "node ids should start from zero" );
  auto npoin = *minmax.second + 1;

  // this is more of a test on this test
  ensure_equals( "number of points in 'correct' esup incorrect",
                 npoin, correct_esup.size() );

  // test generated derived data structure, elements surrounding points
  for (std::size_t p=0; p<npoin; ++p) {
    // extract element ids from generated elements surrounding point p
    std::vector< std::size_t > points;

    const auto a = tk::Around(esup,p);
    // Iterate through all elements surrounding point p using copy/range-for
    // cppcheck-suppress useStlAlgorithm
    for (auto e : a) points.push_back(e);<--- Unmatched suppression: useStlAlgorithm
    // Iterate through all elements surrounding point p using vector::insert
    // using Around::begin/end
    decltype(points) points2;
    points2.insert( end(points2), a.begin(), a.end() );
    ensure( "Class Around using vector::insert and Around::begin/end incorrect",
            points2 == points );
    // Iterate through all elements surrounding point p using vector::insert
    // and std::begin/end
    decltype(points) points3;
    points3.insert( end(points3), std::begin(a), std::end(a) );
    ensure( "Class Around using vector::insert and std::begin/end incorrect",
            points3 == points );
    // Iterate through all elements surrounding point p using vector::insert
    // using Around::cbegin/cend
    decltype(points) points4;
    points4.insert( end(points4), a.cbegin(), a.cend() );
    ensure( "Class Around using vector::insert and Around::cbegin/cend "
            "incorrect", points4 == points );
    // Iterate through all elements surrounding point p using std::copy
    decltype(points) points5;
    std::copy( a.begin(), a.end(), std::back_inserter(points5) );
    ensure( "Class Around using std::copy and std::back_inserter incorrect",
            points5 == points );

    // find correct element ids surrounding point p
    auto it = correct_esup.find( p );
    // test if element ids exist surrounding point p
    ensure( "node id '" + std::to_string(p) + "' generated into esup but not "
            "in correct esup",
            it != correct_esup.end() );
    // test if element ids surrounding point p are correct
    if (it != correct_esup.end())
      ensure( "element ids surrounding point '" + std::to_string(p) +
              "' incorrect", points == it->second );
  }
}

//! Iterate via Around on elements surrounding points for triangle-only mesh
template<> template<>
void Around_object::test< 2 >() {
  set_test_name( "Esup for triangles" );

  // Shift node IDs to start from zero
  tk::shiftToZero( triinpoel );

  // Generate elements surrounding points
  auto esup = tk::genEsup( triinpoel, 3 );

  // Generate correct solution for elements surrounding points
  std::map< std::size_t, std::vector< std::size_t > > correct_esup {
    { { 0 }, { 0, 1, 8, 9, 20, 21 } },
    { { 1 }, { 0, 2, 8, 10, 12, 13 } },
    { { 2 }, { 2, 3, 12, 14, 16, 17 } },
    { { 3 }, { 1, 3, 16, 18, 20, 22 } },
    { { 4 }, { 4, 5, 9, 11, 21, 23 } },
    { { 5 }, { 4, 6, 10, 11, 13, 15 } },
    { { 6 }, { 6, 7, 14, 15, 17, 19 } },
    { { 7 }, { 5, 7, 18, 19, 22, 23 } },
    { { 8 }, { 0, 1, 2, 3 } },
    { { 9 }, { 4, 5, 6, 7 } },
    { { 10 }, { 8, 9, 10, 11 } },
    { { 11 }, { 12, 13, 14, 15 } },
    { { 12 }, { 16, 17, 18, 19 } },
    { { 13 }, { 20, 21, 22, 23 } }
  };

  // find out number of points from mesh connectivity
  auto minmax = std::minmax_element( begin(triinpoel), end(triinpoel) );
  Assert( *minmax.first == 0, "node ids should start from zero" );
  auto npoin = *minmax.second + 1;

  // this is more of a test on this test
  ensure_equals( "number of points in 'correct' esup incorrect",
                 npoin, correct_esup.size() );

  // test generated derived data structure, elements surrounding points
  for (std::size_t p=0; p<npoin; ++p) {
    // extract element ids from generated elements surrounding point p
    std::vector< std::size_t > points;
    // Iterate through all elements surrounding point p
    // cppcheck-suppress useStlAlgorithm
    for (auto e : tk::Around(esup,p)) points.push_back(e);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding point p
    auto it = correct_esup.find( p );
    // test if element ids exist surrounding point p
    ensure( "node id '" + std::to_string(p) + "' generated into esup but not "
            "in correct esup",
            it != correct_esup.end() );
    // test if element ids surrounding point p are correct
    if (it != correct_esup.end())
      ensure( "element ids surrounding point '" + std::to_string(p) +
              "' incorrect", points == it->second );
  }
}

//! Iterate via Around on points surrounding points for tetrahedron-only mesh
template<> template<>
void Around_object::test< 3 >() {
  set_test_name( "Psup for tetrahedra" );

  // Shift node IDs to start from zero
  tk::shiftToZero( inpoel );

  // Generate elements surrounding points
  auto psup = tk::genPsup( inpoel, 4, tk::genEsup(inpoel,4) );

  // Generate correct solution for points surrounding points
  std::map< std::size_t, std::vector< std::size_t > > correct_psup {
    { { 0 }, { 1, 3, 4, 8, 10, 13 } },
    { { 1 }, { 0, 2, 5, 8, 10, 11 } },
    { { 2 }, { 1, 3, 6, 8, 11, 12 } },
    { { 3 }, { 0, 2, 7, 8, 12, 13 } },
    { { 4 }, { 0, 5, 7, 9, 10, 13 } },
    { { 5 }, { 1, 4, 6, 9, 10, 11 } },
    { { 6 }, { 2, 5, 7, 9, 11, 12 } },
    { { 7 }, { 3, 4, 6, 9, 12, 13 } },
    { { 8 }, { 0, 1, 2, 3, 10, 11, 12, 13 } },
    { { 9 }, { 4, 5, 6, 7, 10, 11, 12, 13 } },
    { { 10 }, { 0, 1, 4, 5, 8, 9, 11, 13 } },
    { { 11 }, { 1, 2, 5, 6, 8, 9, 10, 12, 13 } },
    { { 12 }, { 2, 3, 6, 7, 8, 9, 11, 13 } },
    { { 13 }, { 0, 3, 4, 7, 8, 9, 10, 11, 12 } }
  };

  // find out number of points from mesh connectivity
  auto minmax = std::minmax_element( begin(inpoel), end(inpoel) );
  Assert( *minmax.first == 0, "node ids should start from zero" );
  auto npoin = *minmax.second + 1;

  // this is more of a test on this test
  ensure_equals( "number of points in psup incorrect",
                 npoin, correct_psup.size() );

  // test generated derived data structure, elements surrounding points
  for (std::size_t p=0; p<npoin; ++p) {
    // extract element ids from generated elements surrounding point p
    std::vector< std::size_t > points;
    // Iterate through all points surrounding point p
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(psup,p)) points.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding point p
    auto it = correct_psup.find( p );
    // test if element ids exist surrounding point p
    ensure( "node id '" + std::to_string(p) + "' generated into psup but not "
            "in correct psup",
            it != correct_psup.end() );
    // test if element ids surrounding point p are correct
    if (it != correct_psup.end())
      ensure( "point ids surrounding point '" + std::to_string(p) +
              "' incorrect", points == it->second );
  }
}

//! Iterate via Around on points surrounding points for triangle-only mesh
template<> template<>
void Around_object::test< 4 >() {
  set_test_name( "Psup for triangles" );

  // Shift node IDs to start from zero
  tk::shiftToZero( triinpoel );

  // Generate elements surrounding points
  auto psup = tk::genPsup( triinpoel, 3, tk::genEsup(triinpoel,3) );

  // Generate correct solution for points surrounding points
  std::map< std::size_t, std::vector< std::size_t > > correct_psup {
    { { 0 }, { 1, 3, 4, 8, 10, 13 } },
    { { 1 }, { 0, 2, 5, 8, 10, 11 } },
    { { 2 }, { 1, 3, 6, 8, 11, 12 } },
    { { 3 }, { 0, 2, 7, 8, 12, 13 } },
    { { 4 }, { 0, 5, 7, 9, 10, 13 } },
    { { 5 }, { 1, 4, 6, 9, 10, 11 } },
    { { 6 }, { 2, 5, 7, 9, 11, 12 } },
    { { 7 }, { 3, 4, 6, 9, 12, 13 } },
    { { 8 }, { 0, 1, 2, 3 } },
    { { 9 }, { 4, 5, 6, 7 } },
    { { 10 }, { 0, 1, 4, 5 } },
    { { 11 }, { 1, 2, 5, 6 } },
    { { 12 }, { 2, 3, 6, 7 } },
    { { 13 }, { 0, 3, 4, 7 } }
  };

  // find out number of points from mesh connectivity
  auto minmax = std::minmax_element( begin(triinpoel), end(triinpoel) );
  Assert( *minmax.first == 0, "node ids should start from zero" );
  auto npoin = *minmax.second + 1;

  // this is more of a test on this test
  ensure_equals( "number of points in psup incorrect",
                 npoin, correct_psup.size() );

  // test generated derived data structure, elements surrounding points
  for (std::size_t p=0; p<npoin; ++p) {
    // extract element ids from generated elements surrounding point p
    std::vector< std::size_t > points;
    // Iterate through all points surrounding point p
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(psup,p)) points.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding point p
    auto it = correct_psup.find( p );
    // test if element ids exist surrounding point p
    ensure( "node id '" + std::to_string(p) + "' generated into psup but not "
            "in correct psup",
            it != correct_psup.end() );
    // test if element ids surrounding point p are correct
    if (it != correct_psup.end())
      ensure( "point ids surrounding point '" + std::to_string(p) +
              "' incorrect", points == it->second );
  }
}

//! Iterate via Around on edges surrounding points for tetrahedron-only mesh
template<> template<>
void Around_object::test< 5 >() {
  set_test_name( "Edsup for tetrahedra" );

  // Shift node IDs to start from zero
  tk::shiftToZero( inpoel );

  // Generate edges surrounding points
  auto edsup = tk::genEdsup( inpoel, 4, tk::genEsup(inpoel,4) );

  // Generate correct solution for edges surrounding points
  std::map< std::size_t, std::vector< std::size_t > > correct_edsup {
    { {  0 }, { 1,   3,  4,  8, 10, 13 } },
    { {  1 }, { 2,   5,  8, 10, 11 } },
    { {  2 }, { 3,   6,  8, 11, 12 } },
    { {  3 }, { 7,   8, 12, 13 } },
    { {  4 }, { 5,   7,  9, 10, 13 } },
    { {  5 }, { 6,   9, 10, 11 } },
    { {  6 }, { 7,   9, 11, 12 } },
    { {  7 }, { 9,  12, 13 } },
    { {  8 }, { 10, 11, 12, 13 } },
    { {  9 }, { 10, 11, 12, 13 } },
    { { 10 }, { 11, 13 } },
    { { 11 }, { 12, 13 } },
    { { 12 }, { 13 } },
    // the last star of edsup is always empty, since only edges whose point ids
    // p < q are stored, however, the indices exist in edsup2 to allow client
    // code to be simpler and consistent with using the other derived
    // data structures
    { { 13 }, { } }
  };

  // find out number of points from mesh connectivity
  auto minmax = std::minmax_element( begin(inpoel), end(inpoel) );
  Assert( *minmax.first == 0, "node ids should start from zero" );
  auto npoin = *minmax.second + 1;

  // this is more of a test on this test
  ensure_equals( "number of points (star centers) in edsup incorrect",
                 npoin, correct_edsup.size() );

  // Test generated derived data structure, edges surrounding points
  for (std::size_t p=0; p<npoin; ++p) {
    // extract edge end-point ids from generated edges surrounding points
    std::vector< std::size_t > edge;
    // Iterate through all edges surrounding point p
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(edsup,p)) edge.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct star-center point id for list of star-end points
    auto it = correct_edsup.find( p );
    // test if star-end point ids exist emanating from star-center p
    ensure( "star-center point id '" + std::to_string(p) + "' generated into "
            "edsup but not in correct edsup",
            it != correct_edsup.end() );
    // test if star-end point ids starting from star-center point p are correct
    if (it != correct_edsup.end()) {
      ensure_equals( "number of star-end points starting from star-center " +
                     std::to_string(p) + " in generated edsup incorrect",
                     it->second.size(), edge.size() );
      ensure( "star-end point ids starting from star-center'" +
              std::to_string(p) + "' incorrect",
              edge == it->second );
    }
  }
}

//! Iterate via Around on edges surrounding points for triangle-only mesh
template<> template<>
void Around_object::test< 6 >() {
  set_test_name( "Edsup for triangles" );

  // Shift node IDs to start from zero
  tk::shiftToZero( triinpoel );

  // Generate edges surrounding points
  auto edsup = tk::genEdsup( triinpoel, 3, tk::genEsup(triinpoel,3) );

  // Generate correct solution for edges surrounding points
  std::map< std::size_t, std::vector< std::size_t > > correct_edsup {
    { { 0 }, { 1, 3, 4, 8, 10, 13 } },
    { { 1 }, { 2, 5, 8, 10, 11 } },
    { { 2 }, { 3, 6, 8, 11, 12 } },
    { { 3 }, { 7, 8, 12, 13 } },
    { { 4 }, { 5, 7, 9, 10, 13 } },
    { { 5 }, { 6, 9, 10, 11 } },
    { { 6 }, { 7, 9, 11, 12 } },
    { { 7 }, { 9, 12, 13 } },
    // the last star of edsup is always empty, and, depending on the mesh,
    // sometimes not only the last one but the last few, since only edges whose
    // point ids p < q are stored, however, the indices exist for all points in
    // edsup2 to allow client code to be simpler and consistent with using the
    // other derived data structures
    { { 8 }, { } },
    { { 9 }, { } },
    { { 10 }, { } },
    { { 11 }, { } },
    { { 12 }, { } },
    { { 13 }, { } }
  };

  // find out number of points from mesh connectivity
  auto minmax = std::minmax_element( begin(triinpoel), end(triinpoel) );
  Assert( *minmax.first == 0, "node ids should start from zero" );
  auto npoin = *minmax.second + 1;

  // this is more of a test on this test
  ensure_equals( "number of points (star centers) in edsup incorrect",
                 npoin, correct_edsup.size() );

  // Test generated derived data structure, edges surrounding points
  for (std::size_t p=0; p<npoin; ++p) {
    // extract edge end-point ids from generated edges surrounding points
    std::vector< std::size_t > edge;
    // Iterate through all edges surrounding point p
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(edsup,p)) edge.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct star-center point id for list of star-end points
    auto it = correct_edsup.find( p );
    // test if star-end point ids exist emanating from star-center p
    ensure( "star-center point id '" + std::to_string(p) + "' generated into "
            "edsup but not in correct edsup",
            it != correct_edsup.end() );
    // test if star-end point ids starting from star-center point p are correct
    if (it != correct_edsup.end()) {
      ensure_equals( "number of star-end points starting from star-center " +
                     std::to_string(p) + " in generated edsup incorrect",
                     it->second.size(), edge.size() );
      ensure( "star-end point ids starting from star-center'" +
              std::to_string(p) + "' incorrect",
              edge == it->second );
    }
  }
}


//! \brief Iterate via Around on elements surrounding points of elements for
//!    tetrahedron-only mesh
template<> template<>
void Around_object::test< 7 >() {
  set_test_name( "Esupel for tetrahedra" );

  // Shift node IDs to start from zero
  tk::shiftToZero( inpoel );

  // Generate elements surrounding points
  auto esupel = tk::genEsupel( inpoel, 4, tk::genEsup(inpoel,4) );

  // Generate correct solution for elements surrounding points of elements
  std::map< std::size_t, std::vector< std::size_t > > correct_esupel {
    { { 0 }, { 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
               20, 21, 22, 23 } },
    { { 1 }, { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19,
               20, 21, 22, 23 } },
    { { 2 }, { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19,
               20, 21, 22, 23 } },
    { { 3 }, { 0, 1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19,
               20, 21, 22, 23 } },
    { { 4 }, { 0, 1, 2, 3, 6, 9, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23 } },
    { { 5 }, { 0, 1, 2, 3, 6, 7, 8, 11, 13, 15, 16, 17, 18, 19, 20, 21 } },
    { { 6 }, { 0, 1, 2, 3, 4, 5, 7, 9, 12, 13, 16, 18, 19, 21, 22, 23 } },
    { { 7 }, { 1, 2, 3, 5, 6, 8, 10, 12, 13, 16, 18, 19, 20, 21, 22 } },
    { { 8 }, { 0, 1, 2, 3, 5, 7, 10, 11, 12, 15, 16, 17, 19, 20, 21, 22 } },
    { { 9 }, { 0, 1, 2, 3, 4, 6, 10, 11, 12, 14, 17, 18, 19, 20, 22, 23 } },
    { { 10 }, { 0, 1, 2, 7, 8, 9, 11, 12, 14, 17, 19, 20, 21, 22, 23 } },
    { { 11 }, { 0, 1, 2, 3, 5, 8, 9, 10, 14, 15, 16, 17, 20, 21, 22, 23 } },
    { { 12 }, { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 18, 19, 20, 21, 22, 23 } },
    { { 13 }, { 0, 1, 3, 4, 5, 6, 7, 14, 15, 16, 17, 18, 19, 21, 23 } },
    { { 14 }, { 0, 2, 3, 4, 9, 10, 11, 13, 15, 16, 17, 18, 20, 22, 23 } },
    { { 15 }, { 0, 1, 2, 3, 4, 5, 8, 11, 13, 14, 16, 17, 18, 20, 21, 23 } },
    { { 16 }, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 14, 15, 17, 18, 19, 20, 21,
                23 } },
    { { 17 }, { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 13, 14, 15, 16, 18, 20, 21, 22,
                23 } },
    { { 18 }, { 0, 1, 2, 3, 4, 5, 6, 7, 9, 12, 13, 14, 15, 16, 17, 19, 21, 22,
                23 } },
    { { 19 }, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 16, 18, 20, 21, 22,
                23 } },
    { { 20 }, { 0, 1, 2, 3, 5, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 19, 21, 22,
                23 } },
    { { 21 }, { 0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20,
                22 } },
    { { 22 }, { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 14, 17, 18, 19, 20, 21,
                23 } },
    { { 23 }, { 0, 1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                22 } }
  };

  // find out number of elements from mesh connectivity
  auto nelem = inpoel.size()/4;

  // this is more of a test on this test
  ensure_equals( "number of elements in esupel incorrect",
                 nelem, correct_esupel.size() );

  // test generated derived data structure, elements surrounding points of
  // elements
  for (std::size_t e=0; e<nelem; ++e) {
    // extract element ids from generated elements surrounding points of
    // elements
    std::vector< std::size_t > elements;
    // Iterate through all elements surrounding points of elements e
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(esupel,e)) elements.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding points of elements e
    auto it = correct_esupel.find( e );
    // test if element ids exist surrounding points of element e
    ensure( "elem id '" + std::to_string(e) + "' generated into esupel but not "
            "in correct esupel",
            it != correct_esupel.end() );
    // test if element ids surrounding points of element e are correct
    if (it != correct_esupel.end())
      ensure( "elem ids surrounding points of element '" + std::to_string(e) +
              "' incorrect", elements == it->second );
  }
}

//! \brief Iterate via Around on elements surrounding points of elements for
//!    triangle-only mesh
template<> template<>
void Around_object::test< 8 >() {
  set_test_name( "Esupel for triangles" );

  // Shift node IDs to start from zero
  tk::shiftToZero( triinpoel );

  // Generate elements surrounding points
  auto esupel = tk::genEsupel( triinpoel, 3, tk::genEsup(triinpoel,3) );

  // Generate correct solution for elements surrounding points of elements
  std::map< std::size_t, std::vector< std::size_t > > correct_esupel {
    { { 0 }, { 1, 2, 3, 8, 9, 10, 12, 13, 20, 21 } },
    { { 1 }, { 0, 2, 3, 8, 9, 16, 18, 20, 21, 22 } },
    { { 2 }, { 0, 1, 3, 8, 10, 12, 13, 14, 16, 17 } },
    { { 3 }, { 0, 1, 2, 12, 14, 16, 17, 18, 20, 22 } },
    { { 4 }, { 5, 6, 7, 9, 10, 11, 13, 15, 21, 23 } },
    { { 5 }, { 4, 6, 7, 9, 11, 18, 19, 21, 22, 23 } },
    { { 6 }, { 4, 5, 7, 10, 11, 13, 14, 15, 17, 19 } },
    { { 7 }, { 4, 5, 6, 14, 15, 17, 18, 19, 22, 23 } },
    { { 8 }, { 0, 1, 2, 9, 10, 11, 12, 13, 20, 21 } },
    { { 9 }, { 0, 1, 4, 5, 8, 10, 11, 20, 21, 23 } },
    { { 10 }, { 0, 2, 4, 6, 8, 9, 11, 12, 13, 15 } },
    { { 11 }, { 4, 5, 6, 8, 9, 10, 13, 15, 21, 23 } },
    { { 12 }, { 0, 2, 3, 8, 10, 13, 14, 15, 16, 17 } },
    { { 13 }, { 0, 2, 4, 6, 8, 10, 11, 12, 14, 15 } },
    { { 14 }, { 2, 3, 6, 7, 12, 13, 15, 16, 17, 19 } },
    { { 15 }, { 4, 6, 7, 10, 11, 12, 13, 14, 17, 19 } },
    { { 16 }, { 1, 2, 3, 12, 14, 17, 18, 19, 20, 22 } },
    { { 17 }, { 2, 3, 6, 7, 12, 14, 15, 16, 18, 19 } },
    { { 18 }, { 1, 3, 5, 7, 16, 17, 19, 20, 22, 23 } },
    { { 19 }, { 5, 6, 7, 14, 15, 16, 17, 18, 22, 23 } },
    { { 20 }, { 0, 1, 3, 8, 9, 16, 18, 21, 22, 23 } },
    { { 21 }, { 0, 1, 4, 5, 8, 9, 11, 20, 22, 23 } },
    { { 22 }, { 1, 3, 5, 7, 16, 18, 19, 20, 21, 23 } },
    { { 23 }, { 4, 5, 7, 9, 11, 18, 19, 20, 21, 22 } }
  };

  // find out number of elements from mesh connectivity
  auto nelem = triinpoel.size()/3;

  // this is more of a test on this test
  ensure_equals( "number of elements in esupel incorrect",
                 nelem, correct_esupel.size() );

  // test generated derived data structure, elements surrounding points of
  // elements
  for (std::size_t e=0; e<nelem; ++e) {
    // extract element ids from generated elements surrounding points of
    // elements
    std::vector< std::size_t > elements;
    // Iterate through all elements surrounding points of elements e
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(esupel,e)) elements.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding points of elements e
    auto it = correct_esupel.find( e );
    // test if element ids exist surrounding points of element e
    ensure( "elem id '" + std::to_string(e) + "' generated into esupel but not "
            "in correct esupel",
            it != correct_esupel.end() );
    // test if element ids surrounding points of element e are correct
    if (it != correct_esupel.end())
      ensure( "elem ids surrounding points of element '" + std::to_string(e) +
              "' incorrect", elements == it->second );
  }
}

//! \brief Iterate via Around on elements surrounding elements for
//!    tetrahedron-only mesh
template<> template<>
void Around_object::test< 9 >() {
  set_test_name( "Esuel for tetrahedra" );

  // Shift node IDs to start from zero
  tk::shiftToZero( inpoel );

  // Generate elements surrounding points
  auto esuel = tk::genEsuel( inpoel, 4, tk::genEsup(inpoel,4) );

  // Generate correct solution for elements surrounding elements
  std::map< std::size_t, std::vector< std::size_t > > correct_esuel {
    { { 0 }, { 2, 3, 17, 23 } },
    { { 1 }, { 2, 3, 19, 21 } },
    { { 2 }, { 0, 1, 20, 22 } },
    { { 3 }, { 0, 1, 16, 18 } },
    { { 4 }, { 18, 23 } },
    { { 5 }, { 16, 21 } },
    { { 6 }, { 18, 19 } },
    { { 7 }, { 19, 21 } },
    { { 8 }, { 20, 21 } },
    { { 9 }, { 22, 23 } },
    { { 10 }, { 20, 22 } },
    { { 11 }, { 17, 20 } },
    { { 12 }, { 19, 22 } },
    { { 13 }, { 16, 18 } },
    { { 14 }, { 17, 23 } },
    { { 15 }, { 16, 17 } },
    { { 16 }, { 3, 5, 13, 15 } },
    { { 17 }, { 0, 11, 14, 15 } },
    { { 18 }, { 3, 4, 6, 13 } },
    { { 19 }, { 1, 6, 7, 12 } },
    { { 20 }, { 2, 8, 10, 11 } },
    { { 21 }, { 1, 5, 7, 8 } },
    { { 22 }, { 2, 9, 10, 12 } },
    { { 23 }, { 0, 4, 9, 14 } }
  };

  // find out number of elements from mesh connectivity
  auto nelem = inpoel.size()/4;

  // this is more of a test on this test
  ensure_equals( "number of elements in esuel incorrect",
                 nelem, correct_esuel.size() );

  // test generated derived data structure, elements surrounding elements
  for (std::size_t e=0; e<nelem; ++e) {
    // extract element ids from generated elements surrounding elements
    std::vector< std::size_t > elements;
    // Iterate through all elements surrounding element e
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(esuel,e)) elements.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding elements e
    auto it = correct_esuel.find( e );
    // test if element ids exist surrounding element e
    ensure( "element id '" + std::to_string(e) + "' generated into esuel but not "
            "in correct esuel",
            it != correct_esuel.end() );
    // test if element ids surrounding element e are correct
    if (it != correct_esuel.end()) {
      ensure_equals( "number of elements surrounding element " +
                     std::to_string(e) + " in generated esuel incorrect",
                     it->second.size(), elements.size() );
      ensure( "element ids surrounding element '" + std::to_string(e) +
              "' incorrect", elements == it->second );
    }
  }
}

//! \brief Iterate via Around on elements surrounding elements for
//!    triangle-only mesh
template<> template<>
void Around_object::test< 10 >() {
  set_test_name( "Esuel for triangles" );

  // Shift node IDs to start from zero
  tk::shiftToZero( triinpoel );

  // Generate elements surrounding points
  auto esuel = tk::genEsuel( triinpoel, 3, tk::genEsup(triinpoel,3) );

  // Generate correct solution for elements surrounding points of elements
  std::map< std::size_t, std::vector< std::size_t > > correct_esuel {
    { { 0 }, { 1, 2, 8 } },
    { { 1 }, { 0, 3, 20 } },
    { { 2 }, { 0, 3, 12 } },
    { { 3 }, { 1, 2, 16 } },
    { { 4 }, { 5, 6, 11 } },
    { { 5 }, { 4, 7, 23 } },
    { { 6 }, { 4, 7, 15 } },
    { { 7 }, { 5, 6, 19 } },
    { { 8 }, { 0, 9, 10 } },
    { { 9 }, { 8, 11, 21 } },
    { { 10 }, { 8, 11, 13 } },
    { { 11 }, { 4, 9, 10 } },
    { { 12 }, { 2, 13, 14 } },
    { { 13 }, { 10, 12, 15 } },
    { { 14 }, { 12, 15, 17 } },
    { { 15 }, { 6, 13, 14 } },
    { { 16 }, { 3, 17, 18 } },
    { { 17 }, { 14, 16, 19 } },
    { { 18 }, { 16, 19, 22 } },
    { { 19 }, { 7, 17, 18 } },
    { { 20 }, { 1, 21, 22 } },
    { { 21 }, { 9, 20, 23 } },
    { { 22 }, { 18, 20, 23 } },
    { { 23 }, { 5, 21, 22 } }
  };

  // find out number of elements from mesh connectivity
  auto nelem = triinpoel.size()/3;

  // this is more of a test on this test
  ensure_equals( "number of elements in esuel incorrect",
                 nelem, correct_esuel.size() );

  // test generated derived data structure, elements surrounding elements
  for (std::size_t e=0; e<nelem; ++e) {
    // extract element ids from generated elements surrounding elements
    std::vector< std::size_t > elements;
    // Iterate through all elements surrounding element e
    // cppcheck-suppress useStlAlgorithm
    for (auto i : tk::Around(esuel,e)) elements.push_back(i);<--- Unmatched suppression: useStlAlgorithm
    // find correct element ids surrounding elements e
    auto it = correct_esuel.find( e );
    // test if element ids exist surrounding element e
    ensure( "element id '" + std::to_string(e) + "' generated into esuel but not "
            "in correct esuel",
            it != correct_esuel.end() );
    // test if element ids surrounding element e are correct
    if (it != correct_esuel.end()) {
      ensure_equals( "number of elements surrounding element " +
                     std::to_string(e) + " in generated esuel incorrect",
                     it->second.size(), elements.size() );
      ensure( "element ids surrounding element '" + std::to_string(e) +
              "' incorrect", elements == it->second );
    }
  }
}

} // tut::

#endif  // DOXYGEN_GENERATING_OUTPUT