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 | /* *****************************************************************
MESQUITE -- The Mesh Quality Improvement Toolkit
Copyright 2004 Lawrence Livermore National Laboratory. Under
the terms of Contract B545069 with the University of Wisconsin --
Madison, Lawrence Livermore National Laboratory retains certain
rights in this software.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
(lgpl.txt) along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[email protected]
***************************************************************** */
#include "MsqError.hpp"
#include "TopologyInfo.hpp"
#include <cstring>
#include <cassert>
namespace MBMesquite
{
TopologyInfo TopologyInfo::instance;
const char long_polygon_name[] = "Polygon";
const char long_triangle_name[] = "Triangle";
const char long_quadrilateral_name[] = "Quadrilateral";
const char long_polyhedron_name[] = "Polyhedron";
const char long_tetrahedron_name[] = "Tetrahedron";
const char long_hexahedron_name[] = "Hexahedron";
const char long_prism_name[] = "Prism";
const char long_pyramid_name[] = "Pyramd";
const char long_septahedron_name[] = "Septahedron";
const char short_polygon_name[] = "Polygon";
const char short_triangle_name[] = "Tri";
const char short_quadrilateral_name[] = "Quad";
const char short_polyhedron_name[] = "Polyhedron";
const char short_tetrahedron_name[] = "Tet";
const char short_hexahedron_name[] = "Hex";
const char short_prism_name[] = "Pri";
const char short_pyramid_name[] = "Pyr";
const char short_septahedron_name[] = "Sept";
TopologyInfo::TopologyInfo()<--- Member variable 'TopologyInfo::revVertAdjIdx' is not initialized in the constructor.
{
memset( dimMap, 0, sizeof( dimMap ) );
memset( adjMap, 0, sizeof( adjMap ) );
memset( edgeMap, 0, sizeof( edgeMap ) );
memset( faceMap, 0, sizeof( faceMap ) );
memset( vertAdjMap, 0, sizeof( vertAdjMap ) );
memset( shortNames, 0, sizeof( shortNames ) );
memset( longNames, 0, sizeof( longNames ) );
longNames[POLYGON] = long_polygon_name;
longNames[TRIANGLE] = long_triangle_name;
longNames[QUADRILATERAL] = long_quadrilateral_name;
longNames[POLYHEDRON] = long_polyhedron_name;
longNames[TETRAHEDRON] = long_tetrahedron_name;
longNames[HEXAHEDRON] = long_hexahedron_name;
longNames[PRISM] = long_prism_name;
longNames[PYRAMID] = long_pyramid_name;
longNames[SEPTAHEDRON] = long_septahedron_name;
shortNames[POLYGON] = short_polygon_name;
shortNames[TRIANGLE] = short_triangle_name;
shortNames[QUADRILATERAL] = short_quadrilateral_name;
shortNames[POLYHEDRON] = short_polyhedron_name;
shortNames[TETRAHEDRON] = short_tetrahedron_name;
shortNames[HEXAHEDRON] = short_hexahedron_name;
shortNames[PRISM] = short_prism_name;
shortNames[PYRAMID] = short_pyramid_name;
shortNames[SEPTAHEDRON] = short_septahedron_name;
dimMap[POLYGON] = 2;
dimMap[TRIANGLE] = 2;
dimMap[QUADRILATERAL] = 2;
dimMap[POLYHEDRON] = 3;
dimMap[TETRAHEDRON] = 3;
dimMap[HEXAHEDRON] = 3;
dimMap[PRISM] = 3;
dimMap[PYRAMID] = 3;
dimMap[SEPTAHEDRON] = 3;
adjMap[TRIANGLE][0] = 3;
adjMap[TRIANGLE][1] = 3;
adjMap[TRIANGLE][2] = 1;
adjMap[TRIANGLE][3] = 0;
adjMap[QUADRILATERAL][0] = 4;
adjMap[QUADRILATERAL][1] = 4;
adjMap[QUADRILATERAL][2] = 1;
adjMap[QUADRILATERAL][3] = 0;
adjMap[TETRAHEDRON][0] = 4;
adjMap[TETRAHEDRON][1] = 6;
adjMap[TETRAHEDRON][2] = 4;
adjMap[TETRAHEDRON][3] = 1;
adjMap[HEXAHEDRON][0] = 8;
adjMap[HEXAHEDRON][1] = 12;
adjMap[HEXAHEDRON][2] = 6;
adjMap[HEXAHEDRON][3] = 1;
adjMap[PRISM][0] = 6;
adjMap[PRISM][1] = 9;
adjMap[PRISM][2] = 5;
adjMap[PRISM][3] = 1;
adjMap[PYRAMID][0] = 5;
adjMap[PYRAMID][1] = 8;
adjMap[PYRAMID][2] = 5;
adjMap[PYRAMID][3] = 1;
adjMap[SEPTAHEDRON][0] = 7;
adjMap[SEPTAHEDRON][1] = 11;
adjMap[SEPTAHEDRON][2] = 6; /* See description in TSTT mesh interface doc */
adjMap[SEPTAHEDRON][3] = 1;
int side;
for( side = 0; side < 3; ++side )
{
edgeMap[TRIANGLE - FIRST_FACE][side][0] = side;
edgeMap[TRIANGLE - FIRST_FACE][side][1] = ( side + 1 ) % 3;
}
for( side = 0; side < 4; ++side )
{
edgeMap[QUADRILATERAL - FIRST_FACE][side][0] = side;
edgeMap[QUADRILATERAL - FIRST_FACE][side][1] = ( side + 1 ) % 4;
}
for( side = 0; side < 3; ++side )
{
edgeMap[TETRAHEDRON - FIRST_FACE][side][0] = side;
edgeMap[TETRAHEDRON - FIRST_FACE][side][1] = ( side + 1 ) % 3;
}
for( side = 3; side < 6; ++side )
{
edgeMap[TETRAHEDRON - FIRST_FACE][side][0] = side - 3;
edgeMap[TETRAHEDRON - FIRST_FACE][side][1] = 3;
}
for( side = 0; side < 4; ++side )
{
edgeMap[HEXAHEDRON - FIRST_FACE][side][0] = side;
edgeMap[HEXAHEDRON - FIRST_FACE][side][1] = ( side + 1 ) % 4;
}
for( side = 4; side < 8; ++side )
{
edgeMap[HEXAHEDRON - FIRST_FACE][side][0] = side - 4;
edgeMap[HEXAHEDRON - FIRST_FACE][side][1] = side;
}
for( side = 8; side < 12; ++side )
{
edgeMap[HEXAHEDRON - FIRST_FACE][side][0] = side - 4;
edgeMap[HEXAHEDRON - FIRST_FACE][side][1] = 4 + ( side + 1 ) % 4;
}
for( side = 0; side < 3; ++side )
{
edgeMap[PRISM - FIRST_FACE][side][0] = side;
edgeMap[PRISM - FIRST_FACE][side][1] = ( side + 1 ) % 3;
}
for( side = 3; side < 6; ++side )
{
edgeMap[PRISM - FIRST_FACE][side][0] = side - 3;
edgeMap[PRISM - FIRST_FACE][side][1] = side;
}
for( side = 6; side < 9; ++side )
{
edgeMap[PRISM - FIRST_FACE][side][0] = side - 3;
edgeMap[PRISM - FIRST_FACE][side][1] = 3 + ( side + 1 ) % 3;
}
for( side = 0; side < 4; ++side )
{
edgeMap[PYRAMID - FIRST_FACE][side][0] = side;
edgeMap[PYRAMID - FIRST_FACE][side][1] = ( side + 1 ) % 4;
}
for( side = 4; side < 8; ++side )
{
edgeMap[PYRAMID - FIRST_FACE][side][0] = side - 4;
edgeMap[PYRAMID - FIRST_FACE][side][1] = 4;
}
for( side = 0; side < 3; ++side )
{
faceMap[TETRAHEDRON - FIRST_VOL][side][0] = 3;
faceMap[TETRAHEDRON - FIRST_VOL][side][1] = side;
faceMap[TETRAHEDRON - FIRST_VOL][side][2] = ( side + 1 ) % 3;
faceMap[TETRAHEDRON - FIRST_VOL][side][3] = 3;
}
faceMap[TETRAHEDRON - FIRST_VOL][3][0] = 3;
faceMap[TETRAHEDRON - FIRST_VOL][3][1] = 2;
faceMap[TETRAHEDRON - FIRST_VOL][3][2] = 1;
faceMap[TETRAHEDRON - FIRST_VOL][3][3] = 0;
for( side = 0; side < 4; ++side )
{
faceMap[HEXAHEDRON - FIRST_VOL][side][0] = 4;
faceMap[HEXAHEDRON - FIRST_VOL][side][1] = side;
faceMap[HEXAHEDRON - FIRST_VOL][side][2] = ( side + 1 ) % 4;
faceMap[HEXAHEDRON - FIRST_VOL][side][3] = 4 + ( side + 1 ) % 4;
faceMap[HEXAHEDRON - FIRST_VOL][side][4] = side + 4;
}
faceMap[HEXAHEDRON - FIRST_VOL][4][0] = 4;
faceMap[HEXAHEDRON - FIRST_VOL][4][1] = 3;
faceMap[HEXAHEDRON - FIRST_VOL][4][2] = 2;
faceMap[HEXAHEDRON - FIRST_VOL][4][3] = 1;
faceMap[HEXAHEDRON - FIRST_VOL][4][4] = 0;
faceMap[HEXAHEDRON - FIRST_VOL][5][0] = 4;
faceMap[HEXAHEDRON - FIRST_VOL][5][1] = 4;
faceMap[HEXAHEDRON - FIRST_VOL][5][2] = 5;
faceMap[HEXAHEDRON - FIRST_VOL][5][3] = 6;
faceMap[HEXAHEDRON - FIRST_VOL][5][4] = 7;
for( side = 0; side < 4; ++side )
{
faceMap[PYRAMID - FIRST_VOL][side][0] = 3;
faceMap[PYRAMID - FIRST_VOL][side][1] = side;
faceMap[PYRAMID - FIRST_VOL][side][2] = ( side + 1 ) % 4;
faceMap[PYRAMID - FIRST_VOL][side][3] = 4;
}
faceMap[PYRAMID - FIRST_VOL][4][0] = 4;
faceMap[PYRAMID - FIRST_VOL][4][1] = 3;
faceMap[PYRAMID - FIRST_VOL][4][2] = 2;
faceMap[PYRAMID - FIRST_VOL][4][3] = 1;
faceMap[PYRAMID - FIRST_VOL][4][4] = 0;
for( side = 0; side < 3; ++side )
{
faceMap[PRISM - FIRST_VOL][side][0] = 4;
faceMap[PRISM - FIRST_VOL][side][1] = side;
faceMap[PRISM - FIRST_VOL][side][2] = ( side + 1 ) % 3;
faceMap[PRISM - FIRST_VOL][side][3] = 3 + ( side + 1 ) % 3;
faceMap[PRISM - FIRST_VOL][side][4] = side + 3;
}
faceMap[PRISM - FIRST_VOL][3][0] = 3;
faceMap[PRISM - FIRST_VOL][3][1] = 2;
faceMap[PRISM - FIRST_VOL][3][2] = 1;
faceMap[PRISM - FIRST_VOL][3][3] = 0;
faceMap[PRISM - FIRST_VOL][4][0] = 3;
faceMap[PRISM - FIRST_VOL][4][1] = 3;
faceMap[PRISM - FIRST_VOL][4][2] = 4;
faceMap[PRISM - FIRST_VOL][4][3] = 5;
int i;
for( i = 0; i < 3; ++i )
{
vertAdjMap[TRIANGLE - FIRST_FACE][i][0] = 2;
vertAdjMap[TRIANGLE - FIRST_FACE][i][1] = ( i + 1 ) % 3;
vertAdjMap[TRIANGLE - FIRST_FACE][i][2] = ( i + 2 ) % 3;
}
for( i = 0; i < 4; ++i )
{
vertAdjMap[QUADRILATERAL - FIRST_FACE][i][0] = 2;
vertAdjMap[QUADRILATERAL - FIRST_FACE][i][1] = ( i + 1 ) % 4;
vertAdjMap[QUADRILATERAL - FIRST_FACE][i][2] = ( i + 3 ) % 4;
}
unsigned tet_corner_data[] = { 1, 2, 3, 0, 3, 2, 3, 0, 1, 2, 1, 0 };
for( i = 0; i < 4; ++i )
{
vertAdjMap[TETRAHEDRON - FIRST_FACE][i][0] = 3;
for( unsigned j = 0; j < 3; ++j )
vertAdjMap[TETRAHEDRON - FIRST_FACE][i][j + 1] = tet_corner_data[3 * i + j];
}
for( i = 0; i < 4; ++i )
{
vertAdjMap[PYRAMID - FIRST_FACE][i][0] = 3;
vertAdjMap[PYRAMID - FIRST_FACE][i][1] = ( i + 1 ) % 4;
vertAdjMap[PYRAMID - FIRST_FACE][i][2] = ( i + 3 ) % 4;
vertAdjMap[PYRAMID - FIRST_FACE][i][3] = 4;
}
vertAdjMap[PYRAMID - FIRST_FACE][4][0] = 4;
for( i = 0; i < 4; i++ )
vertAdjMap[PYRAMID - FIRST_FACE][4][i + 1] = 3 - i;
for( i = 0; i < 4; ++i )
{
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][0] = 3;
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][1] = ( i + 1 ) % 4;
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][2] = ( i + 3 ) % 4;
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][3] = i + 4;
}
for( i = 4; i < 8; ++i )
{
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][0] = 3;
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][1] = ( i + 3 ) % 4 + 4;
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][2] = ( i + 1 ) % 4 + 4;
vertAdjMap[HEXAHEDRON - FIRST_FACE][i][3] = i - 4;
}
for( i = 0; i < 3; ++i )
{
vertAdjMap[PRISM - FIRST_FACE][i][0] = 3;
vertAdjMap[PRISM - FIRST_FACE][i][1] = ( i + 1 ) % 3;
vertAdjMap[PRISM - FIRST_FACE][i][2] = ( i + 2 ) % 3;
vertAdjMap[PRISM - FIRST_FACE][i][3] = i + 3;
}
for( i = 3; i < 6; ++i )
{
vertAdjMap[PRISM - FIRST_FACE][i][0] = 3;
vertAdjMap[PRISM - FIRST_FACE][i][1] = ( i + 2 ) % 3 + 3;
vertAdjMap[PRISM - FIRST_FACE][i][2] = ( i + 1 ) % 3 + 3;
vertAdjMap[PRISM - FIRST_FACE][i][3] = i - 3;
}
// Build reverse vertex-vertex adjacency index map
const EntityTopology types[] = { TRIANGLE, QUADRILATERAL, TETRAHEDRON, PYRAMID, PRISM, HEXAHEDRON };
const int num_types = sizeof( types ) / sizeof( types[0] );
for( i = 0; i < num_types; ++i )
{
const unsigned num_vert = corners( types[i] );
for( unsigned v = 0; v < num_vert; ++v )
{
unsigned num_v_adj;
const unsigned* v_adj = adjacent_vertices( types[i], v, num_v_adj );
unsigned* reverse = revVertAdjIdx[types[i] - FIRST_FACE][v];
reverse[0] = num_v_adj;
for( unsigned j = 0; j < num_v_adj; ++j )
{
unsigned num_j_adj, k;
const unsigned* j_adj = adjacent_vertices( types[i], v_adj[j], num_j_adj );
for( k = 0; k < num_j_adj && j_adj[k] != v; ++k )
;
assert( k < num_j_adj ); // If this fails, vertAdjMap is corrupt!
reverse[j + 1] = k;
}
}
}
}
void TopologyInfo::higher_order( EntityTopology topo,
unsigned num_nodes,
bool& midedge,
bool& midface,
bool& midvol,
MsqError& err )
{
int ho = higher_order( topo, num_nodes, err );
midedge = (bool)( ( ho & ( 1 << 1 ) ) >> 1 );
midface = (bool)( ( ho & ( 1 << 2 ) ) >> 2 );
midvol = (bool)( ( ho & ( 1 << 3 ) ) >> 3 );
}
int TopologyInfo::higher_order( EntityTopology topo, unsigned num_nodes, MsqError& err )
{
int result = 0;
if( topo == POLYGON ) // polygons currently do not have higher order elements
return 0;
if( topo >= MIXED || num_nodes < instance.adjMap[topo][0] )
{
MSQ_SETERR( err )( "Invalid element topology", MsqError::INVALID_ARG );
return 0;
}
unsigned dim = instance.dimMap[topo];
assert( num_nodes >= instance.adjMap[topo][0] );
unsigned nodes = num_nodes - instance.adjMap[topo][0];
unsigned edges = instance.adjMap[topo][1];
unsigned faces = instance.adjMap[topo][2];
if( edges && nodes >= edges )
{
nodes -= edges;
result |= 1 << 1;
}
if( faces && nodes >= faces )
{
nodes -= faces;
result |= 1 << 2;
}
if( 1 == nodes )
{
if( 2 == dim )
{
nodes -= 1;
result |= 1 << 2;
}
else if( 3 == dim )
{
nodes -= 1;
result |= 1 << 3;
}
}
if( nodes )
{
MSQ_SETERR( err )( "Invalid element topology", MsqError::INVALID_STATE );
}
return result;
}
int TopologyInfo::higher_order_from_side( EntityTopology topo,
unsigned num_nodes,
unsigned side_dimension,
unsigned side_number,
MsqError& err )
{
bool mids[4] = { true };
higher_order( topo, num_nodes, mids[1], mids[2], mids[3], err );
MSQ_ERRZERO( err );
if( side_dimension > dimension( topo ) || side_number > adjacent( topo, side_dimension ) )
{
MSQ_SETERR( err )( MsqError::INVALID_ARG, "Invalid side number: %u\n", side_number );
return 0;
}
if( !mids[side_dimension] ) return -1;
int result = side_number;
switch( side_dimension )
{
case 3:
if( mids[2] ) result += faces( topo );
case 2:
if( mids[1] ) result += edges( topo );
case 1:
result += corners( topo );
case 0:
break;
default:
MSQ_SETERR( err )( MsqError::INVALID_ARG, "Invalid dimension: %u\n", side_dimension );
return 0;
}
return result;
}
void TopologyInfo::side_from_higher_order( EntityTopology topo,
unsigned num_nodes,
unsigned node_number,
unsigned& side_dim_out,
unsigned& side_num_out,
MsqError& err )
{
bool midedge, midface, midvol;
higher_order( topo, num_nodes, midedge, midface, midvol, err );MSQ_ERRRTN( err );
side_num_out = node_number;
if( side_num_out < corners( topo ) )
{
side_dim_out = 0;
return;
}
side_num_out -= corners( topo );
if( midedge )
{
if( side_num_out < edges( topo ) )
{
side_dim_out = 1;
return;
}
side_num_out -= edges( topo );
}
if( midface )
{
if( side_num_out < faces( topo ) )
{
side_dim_out = 2;
return;
}
side_num_out -= faces( topo );
}
if( midvol && side_num_out == 0 )
{
side_dim_out = 3;
return;
}
MSQ_SETERR( err )( MsqError::INVALID_ARG, "Invalid node index\n" );
}
const unsigned* TopologyInfo::edge_vertices( EntityTopology topo, unsigned edge, MsqError& err )
{
if( topo < (EntityTopology)FIRST_FACE || topo > (EntityTopology)LAST_VOL || edge >= edges( topo ) )
{
MSQ_SETERR( err )( MsqError::INVALID_ARG );
topo = (EntityTopology)FIRST_FACE;
edge = 0;
}
return instance.edgeMap[topo - FIRST_FACE][edge];
}
const unsigned* TopologyInfo::edge_vertices( EntityTopology topo, unsigned edge )
{
if( topo < (EntityTopology)FIRST_FACE || topo > (EntityTopology)LAST_VOL || edge >= edges( topo ) )
{
return 0;
}
return instance.edgeMap[topo - FIRST_FACE][edge];
}
const unsigned* TopologyInfo::face_vertices( EntityTopology topo, unsigned face, unsigned& length, MsqError& err )
{
if( topo < (EntityTopology)FIRST_VOL || topo > (EntityTopology)LAST_VOL || face >= faces( topo ) )
{
MSQ_SETERR( err )( MsqError::INVALID_ARG );
topo = (EntityTopology)FIRST_VOL;
face = 0;
}
length = instance.faceMap[topo - FIRST_VOL][face][0];
return instance.faceMap[topo - FIRST_VOL][face] + 1;
}
const unsigned* TopologyInfo::face_vertices( EntityTopology topo, unsigned face, unsigned& length )
{
if( topo < (EntityTopology)FIRST_VOL || topo > (EntityTopology)LAST_VOL || face >= faces( topo ) )
{
return 0;
}
length = instance.faceMap[topo - FIRST_VOL][face][0];
return instance.faceMap[topo - FIRST_VOL][face] + 1;
}
const unsigned* TopologyInfo::side_vertices( EntityTopology topo,
unsigned dim,
unsigned side,
unsigned& count_out,
MsqError& err )
{
static const unsigned all[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
const unsigned* result;
if( dim != 0 && dim == dimension( topo ) )
{
count_out = corners( topo );
result = all;
}
else if( dim == 1 )
{
count_out = 2;
result = edge_vertices( topo, side, err );
}
else if( dim == 2 )
{
result = face_vertices( topo, side, count_out, err );
}
else
{
MSQ_SETERR( err )( MsqError::INVALID_ARG );
count_out = 0;
result = 0;
}
return result;
}
const unsigned* TopologyInfo::side_vertices( EntityTopology topo, unsigned dim, unsigned side, unsigned& count_out )
{
static const unsigned all[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
const unsigned* result;
if( dim != 0 && dim == dimension( topo ) )
{
count_out = corners( topo );
result = all;
}
else if( dim == 1 )
{
count_out = 2;
result = edge_vertices( topo, side );
}
else if( dim == 2 )
{
result = face_vertices( topo, side, count_out );
}
else
{
result = 0;
}
return result;
}
void TopologyInfo::side_number( EntityTopology topo,
unsigned num_nodes,
unsigned node_index,
unsigned& side_dim_out,
unsigned& side_num_out,
MsqError& err )
{
if( topo >= (EntityTopology)MIXED || num_nodes < instance.adjMap[topo][0] )
{
MSQ_SETERR( err )( "Invalid element topology", MsqError::INVALID_ARG );
return;
}
unsigned nodes = instance.adjMap[topo][0];
unsigned edges = instance.adjMap[topo][1];
unsigned faces = instance.adjMap[topo][2];
side_num_out = node_index;
if( side_num_out < nodes )
{
side_dim_out = 0;
return;
}
num_nodes -= nodes;
side_num_out -= nodes;
if( edges && num_nodes >= edges )
{
if( side_num_out < edges )
{
side_dim_out = 1;
return;
}
num_nodes -= edges;
side_num_out -= edges;
}
if( faces && num_nodes >= faces )
{
if( side_num_out < faces )
{
side_dim_out = 2;
return;
}
num_nodes -= faces;<--- Assignment of function parameter has no effect outside the function.<--- Variable 'num_nodes' is assigned a value that is never used.
side_num_out -= faces;
}
if( side_num_out == 0 )
{
side_dim_out = instance.dimMap[topo];
side_num_out = 0;
return;
}
MSQ_SETERR( err )( MsqError::INVALID_ARG );
}
const unsigned* TopologyInfo::adjacent_vertices( EntityTopology topo, unsigned index, unsigned& num_adj_out )
{
const unsigned count = corners( topo );
if( !count || index >= count )
{
num_adj_out = 0;
return 0;
}
const unsigned* vect = instance.vertAdjMap[topo - FIRST_FACE][index];
num_adj_out = vect[0];
return vect + 1;
}
const unsigned* TopologyInfo::reverse_vertex_adjacency_offsets( EntityTopology topo,
unsigned index,
unsigned& num_adj_out )
{
const unsigned count = corners( topo );
if( !count || index >= count )
{
num_adj_out = 0;
return 0;
}
const unsigned* vect = instance.revVertAdjIdx[topo - FIRST_FACE][index];
num_adj_out = vect[0];
return vect + 1;
}
bool TopologyInfo::compare_sides( const size_t* verts1,
EntityTopology type1,
unsigned side1,
const size_t* verts2,
EntityTopology type2,
unsigned side2,
unsigned side_dim,
MsqError& err )
{
const unsigned *conn1, *conn2;
unsigned len1, len2;
conn1 = side_vertices( type1, side_dim, side1, len1, err );
MSQ_ERRZERO( err );
conn2 = side_vertices( type2, side_dim, side2, len2, err );
MSQ_ERRZERO( err );
// obviously not the same if different number of vertices
// (triangular face cannot match quadrilateral face)
if( len1 != len2 ) return false;
// Find location (i) in vertices of side of second element
// that matches the first vertex in the side of the first
// element.
unsigned i, j;
for( i = 0; i < len2; ++i )
if( verts1[conn1[0]] == verts2[conn2[i]] ) break;
// If not found, then no match
if( i == len2 ) return false;
// Try comparing side connectivity in forward order
for( j = 1; j < len1; ++j )
if( verts1[conn1[j]] != verts2[conn2[( i + j ) % len2]] ) break;
// If they match, we're done
if( j == len1 ) return true;
// Try comparing in reverse order
for( j = 1; j < len1; ++j )
if( verts1[conn1[j]] != verts2[conn2[( i + len2 - j ) % len2]] ) return false;
// If here, matched in reverse order
return true;
}
unsigned TopologyInfo::find_edge( EntityTopology topo,
const unsigned* side_vertices,
bool& reversed_out,
MsqError& err )
{
if( dimension( topo ) <= 1 )
{
MSQ_SETERR( err )( MsqError::INVALID_ARG, "Invalid element dimension" );
return (unsigned)-1;
}
for( unsigned i = 0; i < edges( topo ); ++i )
{
const unsigned* edge = edge_vertices( topo, i, err );
MSQ_ERRZERO( err );
if( edge[0] == side_vertices[0] && edge[1] == side_vertices[1] )
{
reversed_out = false;
return i;
}
if( edge[0] == side_vertices[1] && edge[1] == side_vertices[0] )
{
reversed_out = true;
return i;
}
}
MSQ_SETERR( err )( MsqError::INVALID_ARG, "No such edge" );
return (unsigned)-1;
}
unsigned TopologyInfo::find_face( EntityTopology topo,
const unsigned* side_vertices,
unsigned num_vertices,
bool& reversed_out,
MsqError& err )
{
if( dimension( topo ) <= 2 )
{
MSQ_SETERR( err )( MsqError::INVALID_ARG, "Invalid element dimension" );
return (unsigned)-1;
}
for( unsigned i = 0; i < faces( topo ); ++i )
{
unsigned j, n, offset;
const unsigned* face = face_vertices( topo, i, n, err );
MSQ_ERRZERO( err );
if( n != num_vertices ) continue;
for( offset = 0; offset < num_vertices; ++offset )
if( face[offset] == side_vertices[0] ) break;
if( offset == num_vertices ) continue;
for( j = 1; j < num_vertices; ++j )
if( side_vertices[j] != face[( offset + j ) % num_vertices] ) break;
if( j == num_vertices )
{
reversed_out = false;
return i;
}
for( j = 1; j < num_vertices; ++j )
if( side_vertices[j] != face[( offset + num_vertices - j ) % num_vertices] ) break;
if( j == num_vertices )
{
reversed_out = true;
return i;
}
}
MSQ_SETERR( err )( MsqError::INVALID_ARG, "No such face" );
return (unsigned)-1;
}
void TopologyInfo::find_side( EntityTopology topo,
const unsigned* side_vertices,
unsigned num_vertices,
unsigned& dimension_out,
unsigned& number_out,
bool& reversed_out,
MsqError& err )
{
switch( num_vertices )
{
case 1:
dimension_out = 0;
number_out = *side_vertices;
reversed_out = false;
if( *side_vertices >= corners( topo ) ) MSQ_SETERR( err )
( MsqError::INVALID_ARG, "Invalid corner number: %u\n", *side_vertices );
break;
case 2:
dimension_out = 1;
number_out = find_edge( topo, side_vertices, reversed_out, err );MSQ_CHKERR( err );
break;
case 3:
case 4:
dimension_out = 2;
number_out = find_face( topo, side_vertices, num_vertices, reversed_out, err );MSQ_CHKERR( err );
break;
default:
MSQ_SETERR( err )
( MsqError::UNSUPPORTED_ELEMENT, "Invalid number of side vertices: %u\n", num_vertices );
break;
}
}
} // namespace MBMesquite
|