-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathquad_mesh.cpp
6274 lines (5768 loc) · 131 KB
/
quad_mesh.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
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
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <cmath>
# include <ctime>
using namespace std;
# include "quad_mesh.hpp"
//****************************************************************************80
int *adj_set_q4_mesh ( int node_num, int element_num,
int element_node[], int element_neighbor[], int adj_num, int adj_row[] )
//****************************************************************************80
//
// Purpose:
//
// ADJ_SET_Q4_MESH sets adjacencies in a triangulation.
//
// Discussion:
//
// This routine is called to set the adjacencies, after the
// appropriate amount of memory has been set aside for storage.
//
// The mesh is assumed to involve 4-node quadrilaterals.
//
// Two nodes are "adjacent" if they are both nodes in some element.
// Also, a node is considered to be adjacent to itself.
//
// This routine can be used to create the compressed column storage
// for a linear element finite element discretization of
// Poisson's equation in two dimensions.
//
// Diagram:
//
// side 3
// 4-------3
// s | | s
// i | | i
// d | | d
// e | | e
// | |
// 4 | | 2
// | |
// 1-------2
//
// side 1
//
// The local node numbering
//
//
// 20-21-22-23-24
// | | | | |
// | | | | |
// 15-16-17-18-19
// | | | | |
// | | | | |
// 10-11-12-13-14
// | | | | |
// | | | | |
// 5--6--7--8--9
// | | | | |
// | | | | |
// 0--1--2--3--4
//
// A sample grid.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 28 September 2009
//
// Author:
//
// John Burkardt
//
// Parameters
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int ELEMENT_NUM, the number of elements.
//
// Input, int ELEMENT_NODE[4*ELEMENT_NUM], lists the nodes that
// make up each element in counterclockwise order.
//
// Input, int ELEMENT_NEIGHBOR[4*ELEMENT_NUM], for each side of
// an element, lists the neighboring element, or -1 if there is
// no neighbor.
//
// Input, int ADJ_NUM, the number of adjacencies.
//
// Input, int ADJ_ROW[NODE_NUM+1]. Information about column J is stored
// in entries ADJ_ROW(J) through ADJ_ROW(J+1)-1 of ADJ.
//
// Output, int ADJ_SET_Q4_MESH[ADJ_NUM], the adjacency information.
//
{
int *adj;
int *adj_copy;
int k;
int k1;
int k2;
int n1;
int n2;
int n3;
int n4;
int node;
int element;
int element2;
int element_order = 4;
adj = new int[adj_num];
for ( k = 0; k < adj_num; k++ )
{
adj[k] = -1;
}
adj_copy = new int[node_num];
for ( node = 0; node < node_num; node++ )
{
adj_copy[node] = adj_row[node];
}
//
// Set every node to be adjacent to itself.
//
for ( node = 0; node < node_num; node++ )
{
adj[adj_copy[node]] = node;
adj_copy[node] = adj_copy[node] + 1;
}
//
// Examine each element.
//
for ( element = 0; element < element_num; element++ )
{
n1 = element_node[0+element*element_order];
n2 = element_node[1+element*element_order];
n3 = element_node[2+element*element_order];
n4 = element_node[3+element*element_order];
//
// Add edges (1,3) and (2,4). There is no need to check for redundancy,
// since this is the only case when these nodes can share an element.
//
adj[adj_copy[n1]] = n3;
adj_copy[n1] = adj_copy[n1] + 1;
adj[adj_copy[n3]] = n1;
adj_copy[n3] = adj_copy[n3] + 1;
adj[adj_copy[n2]] = n4;
adj_copy[n2] = adj_copy[n2] + 1;
adj[adj_copy[n4]] = n2;
adj_copy[n4] = adj_copy[n4] + 1;
//
// Add edge (1,2) if this is the first occurrence,
// that is, if the edge (1,2) is on a boundary (ELEMENT2 <= 0)
// or if this element is the first of the pair in which the edge
// occurs (ELEMENT < ELEMENT2).
//
element2 = element_neighbor[0+element*4];
if ( element2 < 0 || element < element2 )
{
adj[adj_copy[n1]] = n2;
adj_copy[n1] = adj_copy[n1] + 1;
adj[adj_copy[n2]] = n1;
adj_copy[n2] = adj_copy[n2] + 1;
}
//
// Add edge (2,3).
//
element2 = element_neighbor[1+element*4];
if ( element2 < 0 || element < element2 )
{
adj[adj_copy[n2]] = n3;
adj_copy[n2] = adj_copy[n2] + 1;
adj[adj_copy[n3]] = n2;
adj_copy[n3] = adj_copy[n3] + 1;
}
//
// Add edge (3,4).
//
element2 = element_neighbor[2+element*4];
if ( element2 < 0 || element < element2 )
{
adj[adj_copy[n4]] = n3;
adj_copy[n4] = adj_copy[n4] + 1;
adj[adj_copy[n3]] = n4;
adj_copy[n3] = adj_copy[n3] + 1;
}
//
// Add edge (4,1).
//
element2 = element_neighbor[3+element*4];
if ( element2 < 0 || element < element2 )
{
adj[adj_copy[n1]] = n4;
adj_copy[n1] = adj_copy[n1] + 1;
adj[adj_copy[n4]] = n1;
adj_copy[n4] = adj_copy[n4] + 1;
}
}
//
// Ascending sort the entries for each node.
//
for ( node = 0; node < node_num; node++ )
{
k1 = adj_row[node];
k2 = adj_row[node+1]-1;
i4vec_sort_heap_a ( k2+1-k1, adj+k1 );
}
delete [] adj_copy;
return adj;
}
//****************************************************************************80
int adj_size_q4_mesh ( int node_num, int element_num, int element_node[],
int element_neighbor[], int adj_row[] )
//****************************************************************************80
//
// Purpose:
//
// ADJ_SIZE_Q4_MESH counts adjacencies in a Q4 mesh.
//
// Discussion:
//
// This routine is called to count the adjacencies, so that the
// appropriate amount of memory can be set aside for storage when
// the adjacency structure is created.
//
// The mesh is assumed to involve 4-node quadrilaterals.
//
// Two nodes are "adjacent" if they are both nodes in some quadrilateral.
// Also, a node is considered to be adjacent to itself.
//
// Diagram:
//
// side 3
// 4-------3
// s | | s
// i | | i
// d | | d
// e | | e
// | |
// 4 | | 2
// | |
// 1-------2
//
// side 1
//
// The local node numbering
//
//
// 20-21-22-23-24
// | | | | |
// | | | | |
// 15-16-17-18-19
// | | | | |
// | | | | |
// 10-11-12-13-14
// | | | | |
// | | | | |
// 5--6--7--8--9
// | | | | |
// | | | | |
// 0--1--2--3--4
//
// A sample grid.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 29 September 2009
//
// Author:
//
// John Burkardt
//
// Parameters
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int ELEMENT_NUM, the number of elements.
//
// Input, int ELEMENT_NODE[4*ELEMENT_NUM], lists the nodes that
// make up each element, in counterclockwise order.
//
// Input, int ELEMENT_NEIGHBOR[4*ELEMENT_NUM], for each side of
// a element, lists the neighboring elment, or -1 if there is
// no neighbor.
//
// Output, int ADJ_ROW[NODE_NUM+1], Information about column J is stored
// in entries ADJ_ROW[J] through ADJ_ROW[J+1]-1 of ADJ.
//
// Output, int ADJ_SIZE_Q4_MESH, the number of adjacencies.
//
{
int adj_num;
int element;
int element_order = 4;
int element2;
int i;
int n1;
int n2;
int n3;
int n4;
int node;
adj_num = 0;
//
// Set every node to be adjacent to itself.
//
for ( node = 0; node < node_num; node++ )
{
adj_row[node] = 1;
}
//
// Examine each element.
//
for ( element = 0; element < element_num; element++ )
{
n1 = element_node[0+element*element_order];
n2 = element_node[1+element*element_order];
n3 = element_node[2+element*element_order];
n4 = element_node[3+element*element_order];
//
// Add edge (1,3).
//
adj_row[n1] = adj_row[n1] + 1;
adj_row[n3] = adj_row[n3] + 1;
//
// Add edge (2,4).
//
adj_row[n2] = adj_row[n2] + 1;
adj_row[n4] = adj_row[n4] + 1;
//
// Add edge (1,2) if this is the first occurrence,
// that is, if the edge (1,2) is on a boundary (ELEMENT2 <= 0)
// or if this element is the first of the pair in which the edge
// occurs (ELEMENT < ELEMENT2).
//
element2 = element_neighbor[0+element*4];
if ( element2 < 0 || element < element2 )
{
adj_row[n1] = adj_row[n1] + 1;
adj_row[n2] = adj_row[n2] + 1;
}
//
// Add edge (2,3).
//
element2 = element_neighbor[1+element*4];
if ( element2 < 0 || element < element2 )
{
adj_row[n2] = adj_row[n2] + 1;
adj_row[n3] = adj_row[n3] + 1;
}
//
// Add edge (3,4).
//
element2 = element_neighbor[2+element*4];
if ( element2 < 0 || element < element2 )
{
adj_row[n3] = adj_row[n3] + 1;
adj_row[n4] = adj_row[n4] + 1;
}
//
// Add edge (4,1).
//
element2 = element_neighbor[3+element*4];
if ( element2 < 0 || element < element2 )
{
adj_row[n4] = adj_row[n4] + 1;
adj_row[n1] = adj_row[n1] + 1;
}
}
//
// We used ADJ_ROW to count the number of entries in each column.
// Convert it to pointers into the ADJ array.
//
for ( node = node_num; 1 <= node; node-- )
{
adj_row[node] = adj_row[node-1];
}
adj_row[0] = 0;
for ( i = 1; i <= node_num; i++ )
{
adj_row[i] = adj_row[i] + adj_row[i-1];
}
//
// Finally, record the total number of adjacencies.
//
adj_num = adj_row[node_num];
return adj_num;
}
//****************************************************************************80
void area_q4_mesh ( int node_num, int element_num, double node_xy[],
int element_node[], double element_area[], double *mesh_area )
//****************************************************************************80
//
// Purpose:
//
// AREA_Q4_MESH computes areas of elements in a Q4 mesh.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 24 February 2009
//
// Author:
//
// John Burkardt
//
// Parameters
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int ELEMENT_NUM, the number of elements.
//
// Input, double NODE_XY[2*NODE_NUM], the node coordinates.
//
// Input, int ELEMENT_NODE[4*ELEMENT_NUM], lists the
// nodes that make up each element, in counterclockwise order.
//
// Output, double ELEMENT_AREA[ELEMENT_NUM], the element areas.
//
// Output, double *MESH_AREA, the mesh area.
//
{
int dim;
int element;
int node;
double q4[2*4];
for ( element = 0; element < element_num; element++ )
{
for ( node = 0; node < 4; node++ )
{
for ( dim = 0; dim < 2; dim++ )
{
q4[dim+2*node] = node_xy[dim+2*element_node[node+4*element]];
}
}
element_area[element] = area_quad ( q4 );
}
*mesh_area = r8vec_sum ( element_num, element_area );
return;
}
//****************************************************************************80
double area_quad ( double quad_xy[2*4] )
//****************************************************************************80
//
// Purpose:
//
// AREA_QUAD returns the area of a quadrilateral.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 23 February 2009
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double QUAD_XY[2*4], the coordinates of the nodes.
//
// Output, double AREA_QUAD, the area.
//
{
double area;
double area1;
double area2;
double t1[2*3];
double t2[2*3];
t1[0+0*2] = quad_xy[0+0*2];
t1[1+0*2] = quad_xy[1+0*2];
t1[0+1*2] = quad_xy[0+1*2];
t1[1+1*2] = quad_xy[1+1*2];
t1[0+2*2] = quad_xy[0+2*2];
t1[1+2*2] = quad_xy[1+2*2];
area1 = triangle_area ( t1 );
t2[0+0*2] = quad_xy[0+2*2];
t2[1+0*2] = quad_xy[1+2*2];
t2[0+1*2] = quad_xy[0+3*2];
t2[1+1*2] = quad_xy[1+3*2];
t2[0+2*2] = quad_xy[0+0*2];
t2[1+2*2] = quad_xy[1+0*2];
area2 = triangle_area ( t2 );
if ( area1 < 0.0 || area2 < 0.0 )
{
t1[0+0*2] = quad_xy[0+1*2];
t1[1+0*2] = quad_xy[1+1*2];
t1[0+1*2] = quad_xy[0+2*2];
t1[1+1*2] = quad_xy[1+2*2];
t1[0+2*2] = quad_xy[0+3*2];
t1[1+2*2] = quad_xy[1+3*2];
area1 = triangle_area ( t1 );
t2[0+0*2] = quad_xy[0+3*2];
t2[1+0*2] = quad_xy[1+3*2];
t2[0+1*2] = quad_xy[0+0*2];
t2[1+1*2] = quad_xy[1+0*2];
t2[0+2*2] = quad_xy[0+1*2];
t2[1+2*2] = quad_xy[1+1*2];
area2 = triangle_area ( t2 );
if ( area1 < 0.0 || area2 < 0.0 )
{
cerr << "\n";
cerr << "AREA_QUAD - Fatal error!\n";
cerr << " The quadrilateral nodes seem to be listed in\n";
cerr << " the wrong order, or the quadrilateral is\n";
cerr << " degenerate.\n";
exit ( 1 );
}
}
area = area1 + area2;
return area;
}
//****************************************************************************80
void bandwidth ( int element_order, int element_num, int element_node[],
int *ml, int *mu, int *m )
//****************************************************************************80
//
// Purpose:
//
// BANDWIDTH determines the bandwidth associated with the finite element mesh.
//
// Discussion:
//
// The quantity computed here is the "geometric" bandwidth determined
// by the finite element mesh alone.
//
// If a single finite element variable is associated with each node
// of the mesh, and if the nodes and variables are numbered in the
// same way, then the geometric bandwidth is the same as the bandwidth
// of a typical finite element matrix.
//
// The bandwidth M is defined in terms of the lower and upper bandwidths:
//
// M = ML + 1 + MU
//
// where
//
// ML = maximum distance from any diagonal entry to a nonzero
// entry in the same row, but earlier column,
//
// MU = maximum distance from any diagonal entry to a nonzero
// entry in the same row, but later column.
//
// Because the finite element node adjacency relationship is symmetric,
// we are guaranteed that ML = MU.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 23 September 2006
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int ELEMENT_ORDER, the order of the elements.
//
// Input, int ELEMENT_NUM, the number of elements.
//
// Input, int ELEMENT_NODE[ELEMENT_ORDER*ELEMENT_NUM];
// ELEMENT_NODE(I,J) is the global index of local node I in element J.
//
// Output, int *ML, *MU, the lower and upper bandwidths of the matrix.
//
// Output, int *M, the bandwidth of the matrix.
//
{
int element;
int global_i;
int global_j;
int local_i;
int local_j;
*ml = 0;
*mu = 0;
for ( element = 0; element < element_num; element++ )
{
for ( local_i = 0; local_i < element_order; local_i++ )
{
global_i = element_node[local_i+element*element_order];
for ( local_j = 0; local_j < element_order; local_j++ )
{
global_j = element_node[local_j+element*element_order];
*mu = i4_max ( *mu, global_j - global_i );
*ml = i4_max ( *ml, global_i - global_j );
}
}
}
*m = *ml + 1 + *mu;
return;
}
//****************************************************************************80
int boundary_edge_count_q4_mesh ( int element_num, int element_node[] )
//****************************************************************************80
//
// Purpose:
//
// BOUNDARY_EDGE_COUNT_Q4_MESH counts the boundary edges.
//
// Discussion:
//
// This routine is given a Q4 mesh, an abstract list of sets of 4 nodes.
// It is assumed that the nodes in each Q4 are listed
// in a counterclockwise order, although the routine should work
// if the nodes are consistently listed in a clockwise order as well.
//
// It is assumed that each edge of the mesh is either
// * an INTERIOR edge, which is listed twice, once with positive
// orientation and once with negative orientation, or;
// * a BOUNDARY edge, which will occur only once.
//
// This routine should work even if the region has holes.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 27 February 2009
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int ELEMENT_NUM, the number of elements.
//
// Input, int ELEMENT_NODE[4*ELEMENT_NUM], the nodes
// that make up the elements. These should be listed in counterclockwise
// order.
//
// Output, int BOUNDARY_EDGE_COUNT_Q4_MESH, the number of boundary
// edges.
//
{
int boundary_edge_num;
int e1;
int e2;
int *edge;
int element;
int interior_edge_num;
int j;
int m;
int n;
int unique_num;
m = 2;
n = 4 * element_num;
//
// Set up the edge array.
//
edge = new int[2*4*element_num];
for ( element = 0; element < element_num; element++ )
{
edge[0+element*2+element_num*2*0] = element_node[0+element*4];
edge[1+element*2+element_num*2*0] = element_node[1+element*4];
edge[0+element*2+element_num*2*1] = element_node[1+element*4];
edge[1+element*2+element_num*2*1] = element_node[2+element*4];
edge[0+element*2+element_num*2*2] = element_node[2+element*4];
edge[1+element*2+element_num*2*2] = element_node[3+element*4];
edge[0+element*2+element_num*2*3] = element_node[3+element*4];
edge[1+element*2+element_num*2*3] = element_node[0+element*4];
}
//
// In each column, force the smaller entry to appear first.
//
for ( j = 0; j < n; j++ )
{
e1 = i4_min ( edge[0+2*j], edge[1+2*j] );
e2 = i4_max ( edge[0+2*j], edge[1+2*j] );
edge[0+2*j] = e1;
edge[1+2*j] = e2;
}
//
// Ascending sort the column array.
//
i4col_sort_a ( m, n, edge );
//
// Get the number of unique columns in EDGE.
//
unique_num = i4col_sorted_unique_count ( m, n, edge );
interior_edge_num = 4 * element_num - unique_num;
boundary_edge_num = 4 * element_num - 2 * interior_edge_num;
delete [] edge;
return boundary_edge_num;
}
//****************************************************************************80
int boundary_edge_count_euler_q4_mesh ( int node_num, int element_num,
int hole_num )
//****************************************************************************80
//
// Purpose:
//
// BOUNDARY_EDGE_COUNT_EULER_Q4_MESH counts boundary edges.
//
// Discussion:
//
// We assume we are given information about a quadrilateral mesh
// of a set of nodes in the plane.
//
// Given the number of nodes, elements and holes, we are going to apply
// Euler's formula to determine the number of edges that lie on the
// boundary of the set of nodes.
//
// The number of faces, including the infinite face and internal holes,
// is ELEMENT_NUM + HOLE_NUM + 1.
//
// Let BOUNDARY_NUM denote the number of edges on the boundary.
// Each of the ELEMENT_NUM quadrilaterals uses four edges. Every edge
// occurs in two different elements, so the number of edges must be
// ( 4 * ELEMENT_NUM + BOUNDARY_NUM ) / 2.
//
// The number of nodes used in the mesh is NODE_NUM.
//
// Euler's formula asserts that, for a simple connected figure in the
// plane with no edge crossings, NODE_NUM nodes, EDGE_NUM edges and
// FACE_NUM faces:
//
// NODE_NUM - EDGE_NUM + FACE_NUM = 2
//
// In our context, this becomes
//
// NODE_NUM - ( 4 * ELEMENT_NUM + BOUNDARY_NUM ) / 2
// + ELEMENT_NUM + HOLE_NUM + 1 = 2
//
// or
//
// BOUNDARY_NUM = 2 * NODE_NUM + 2 * HOLE_NUM - 2 * ELEMENT_NUM - 2
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 17 February 2009
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Marc de Berg, Marc Krevald, Mark Overmars, Otfried Schwarzkopf,
// Computational Geometry, Section 9.1,
// Springer, 2000.
//
// Parameters:
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int ELEMENT_NUM, the number of elements.
//
// Input, int HOLE_NUM, the number of internal holes.
//
// Output, int BOUNDARY_EDGE_COUNT_EULER_Q4_MESH, the number of edges that
// lie on the boundary of the mesh.
//
{
int boundary_num;
boundary_num = 2 * node_num + 2 * hole_num - 2 * element_num - 2;
return boundary_num;
}
//****************************************************************************80
char ch_cap ( char ch )
//****************************************************************************80
//
// Purpose:
//
// CH_CAP capitalizes a single character.
//
// Discussion:
//
// This routine should be equivalent to the library "toupper" function.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 July 1998
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char CH, the character to capitalize.
//
// Output, char CH_CAP, the capitalized character.
//
{
if ( 97 <= ch && ch <= 122 )
{
ch = ch - 32;
}
return ch;
}
//****************************************************************************80
bool ch_eqi ( char ch1, char ch2 )
//****************************************************************************80
//
// Purpose:
//
// CH_EQI is true if two characters are equal, disregarding case.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 June 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char CH1, CH2, the characters to compare.
//
// Output, bool CH_EQI, is true if the two characters are equal,
// disregarding case.
//
{
if ( 97 <= ch1 && ch1 <= 122 )
{
ch1 = ch1 - 32;
}
if ( 97 <= ch2 && ch2 <= 122 )
{
ch2 = ch2 - 32;
}
return ( ch1 == ch2 );
}
//****************************************************************************80
int ch_to_digit ( char ch )
//****************************************************************************80
//
// Purpose:
//
// CH_TO_DIGIT returns the integer value of a base 10 digit.
//
// Example:
//
// CH DIGIT
// --- -----
// '0' 0
// '1' 1
// ... ...
// '9' 9
// ' ' 0
// 'X' -1
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 June 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char CH, the decimal digit, '0' through '9' or blank are legal.
//
// Output, int CH_TO_DIGIT, the corresponding integer value. If the character was
// 'illegal', then DIGIT is -1.
//
{
int digit;
if ( '0' <= ch && ch <= '9' )
{
digit = ch - '0';
}
else if ( ch == ' ' )
{
digit = 0;
}
else
{
digit = -1;
}
return digit;
}
//****************************************************************************80
void example1_q4_mesh ( int node_num, int element_num, double node_xy[],
int element_node[], int element_neighbor[] )
//****************************************************************************80
//
// Purpose:
//
// EXAMPLE1_Q4_MESH sets up example #1 Q4 mesh.
//
// Discussion:
//
// The appropriate values of NODE_NUM and ELEMENT_NUM can be found by
// calling EXAMPLE1_Q4_MESH_SIZE first.
//
// 24---25---26---27---28
// | 14 | 15 | 16 | 17 |
// 18---19---20---21---22---23
// | 10 | -2 | 11 | 12 | 13 |
// 12---13---14---15---16---17
// | 5 | 6 | 7 | 8 | 9 |