-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelement.c
More file actions
1084 lines (1082 loc) · 36.5 KB
/
element.c
File metadata and controls
1084 lines (1082 loc) · 36.5 KB
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <omp.h>
#include "cvm.h"
#include "iscl/sorting/sorting.h"
int __mesh_element__setBoundaryConditionList(enum mesh_bc_enum side,
int *bc_list)
{
const char *fcnm = "__mesh_element__setBoundaryConditionList\0";
bc_list[0] =-12345;
bc_list[1] =-12345;
bc_list[2] =-12345;
if (side == SOUTH_BDRY)
{
bc_list[0] = SOUTH_BDRY;
bc_list[1] = SOUTH_FREE;
bc_list[2] = SOUTH_CE;
}
else if (side == EAST_BDRY)
{
bc_list[0] = EAST_BDRY;
bc_list[1] = EAST_FREE;
bc_list[2] = EAST_CE;
}
else if (side == NORTH_BDRY)
{
bc_list[0] = NORTH_BDRY;
bc_list[1] = NORTH_FREE;
bc_list[2] = NORTH_CE;
}
else if (side == WEST_BDRY)
{
bc_list[0] = WEST_BDRY;
bc_list[1] = WEST_FREE;
bc_list[2] = WEST_CE;
}
else if (side == BOTTOM_BDRY)
{
bc_list[0] = BOTTOM_BDRY;
bc_list[1] = BOTTOM_FREE;
bc_list[2] = BOTTOM_CE;
}
else if (side == TOP_BDRY)
{
bc_list[0] = TOP_BDRY;
bc_list[1] = TOP_FREE;
bc_list[2] = TOP_CE;
}
else
{
printf("%s: I do not know which side to get!\n", fcnm);
return -1;
}
return 0;
}
//============================================================================//
/*!
* @brief Gets the size of the IEN array describing the side'th mesh side
*
* @param[in] nelem number of elements in mesh
* @param[in] side desired side for which to extract length of IEN
* @param[in] element holds the boundary conditions for each element in mesh
* [nelem]
*
* @result length of IENbdry structure for this side
*
*/
int mesh_element__getBoundaryIENSize(int nelem,
enum mesh_bc_enum side,
struct mesh_element_struct *element)
{
const char *fcnm = "mesh_element__getBoundaryIENSize\0";
const int nbc = 3;
int bc_list[3], ibc, iface, ielem, ierr, len_IENside;
len_IENside = 0;
ierr = __mesh_element__setBoundaryConditionList(side, bc_list);
if (ierr != 0){
printf("%s: Error setting boundary list\n", fcnm);
return len_IENside;
}
// Loop on mesh
#pragma omp parallel for firstprivate(nbc, nelem), \
private(ielem, iface, ibc), shared(element), \
reduction(+:len_IENside)
for (ielem=0; ielem<nelem; ielem++){
for (iface=0; iface<element[ielem].nface; iface++){
if (element[ielem].bc[iface] == NO_BC){continue;}
for (ibc=0; ibc<nbc; ibc++){
if (bc_list[ibc] == element[ielem].bc[iface]){
len_IENside = len_IENside + element[ielem].ngnod_face;
break;
}
} // Loop on available boundary conditions
} // Loop on faces on element
} // Loop on elements
return len_IENside;
}
//============================================================================//
/*!
* @brief Gets the number of boundary elements on the side'th side
*
* @param[in] nelem number of elements in mesh
* @param[in] side desired side for which to extract number of elements
* @param[in] element holds the boundary conditions for each element in mesh
* [nelem]
*
* @result number of elements on the side'th side
*
*/
int mesh_element__getNumberOfBoundaryElements(int nelem,
enum mesh_bc_enum side,
struct mesh_element_struct *element)
{
const char *fcnm = "mesh_element__getNumberOfBoundaryElements\0";
const int nbc = 3;
int bc_list[3], ibc, iface, ielem, ierr, nelem_bdry;
nelem_bdry = 0;
ierr = __mesh_element__setBoundaryConditionList(side, bc_list);
if (ierr != 0){
printf("%s: Error setting boundary list\n", fcnm);
return nelem_bdry;
}
// Loop on mesh
#pragma omp parallel for firstprivate(nbc, nelem), \
private(ielem, iface, ibc), shared(element), \
reduction(+:nelem_bdry)
for (ielem=0; ielem<nelem; ielem++){
for (iface=0; iface<element[ielem].nface; iface++){
if (element[ielem].bc[iface] == NO_BC){continue;}
for (ibc=0; ibc<nbc; ibc++){
if (bc_list[ibc] == element[ielem].bc[iface]){
nelem_bdry = nelem_bdry + 1;
break;
}
} // Loop on available boundary conditions
} // Loop on faces on element
} // Loop on elements
return nelem_bdry;
}
//============================================================================//
int mesh_element__getIENBoundary(int nelem, bool lhomog,
enum mesh_bc_enum side,
struct mesh_element_struct *element,
int nelem_bdry, int *ien_bdry_ptr,
int *bdry2glob_elem,
int *ien_bdry)
{
const char *fcnm = "mesh_element__getIENBoundary\0";
const int nbc = 3;
int bc_list[3], ia, ibc, ielem, ielem_bdry, ierr,
iface, indx_bdry, indx_face, ngnod_face;
ierr = __mesh_element__setBoundaryConditionList(side, bc_list);
if (ierr != 0){
printf("%s: Error setting boundary list!\n", fcnm);
return -1;
}
ien_bdry_ptr[0] = 0;
if (lhomog){
// Set the boundary element ien pointer
ngnod_face = element[0].ngnod_face;
#pragma omp simd
for (ielem_bdry=1; ielem_bdry<nelem_bdry+1; ielem_bdry++)
{
ien_bdry_ptr[ielem_bdry] = ngnod_face*ielem_bdry;
}
// Extract the anchor nodes on the boundary
ielem_bdry = 0;
for (ielem=0; ielem<nelem; ielem++){
for (iface=0; iface<element[ielem].nface; iface++){
if (element[ielem].bc[iface] == NO_BC){continue;}
indx_face = iface*element[ielem].ngnod_face;
for (ibc=0; ibc<nbc; ibc++){
if (bc_list[ibc] == element[ielem].bc[iface]){
indx_bdry = ien_bdry_ptr[ielem_bdry];
for (ia=0; ia<element[ielem].ngnod_face; ia++){
ien_bdry[indx_bdry]
= element[ielem].ien_face[indx_face];
indx_face = indx_face + 1;
indx_bdry = indx_bdry + 1;
}
bdry2glob_elem[ielem_bdry] = ielem;
ielem_bdry = ielem_bdry + 1;
break;
} // End check on boundary condition match
} // Loop on available boundary conditions
} // Loop on faces on element
} // Loop on elements
}else{
printf("not done!\n");
return -1;
/*
ielem_bdry = 0;
for (ielem=0; ielem<nelem; ielem++){
if (element[ielem].bc[iface] == NO_BC){continue;}
for (iface=0; iface<element[ielem].nface; iface++){
for (ibc=0; ibc<nbc; ibc++){
if (bc_list[ibc] == element[ielem].bc[iface]){
bdry2glob_elem[ielem_bdry] = ielem;
ielem_bdry = ielem_bdry + 1;
break;
}
}
}
} // Loop on elements
*/
}
return 0;
}
//============================================================================//
int mesh_setBoundaryMesh(struct mesh_struct mesh,
enum mesh_bc_enum side,
struct mesh_struct *bdry)
{
const char *fcnm = "mesh_setBoundaryMesh\0";
memset(bdry, 0, sizeof(struct mesh_struct));
// Get the size of the boundary mesh
bdry->nelem = mesh_element__getNumberOfBoundaryElements(mesh.nelem,
side, mesh.element);
if (bdry->nelem < 1){
printf("%s: No elements on this side\n", fcnm);
return -1;
}
return 0;
}
//============================================================================//
/*!
* @brief Computes the length of the IEN array
*
* @param[in] nelem number of elements in mesh
* @param[in] lhomog If True then the mesh has only one element type
* If False then the mesh has mixed element types
*
* @result the length of the IEN array
*
*/
int mesh_element__getIENSize(int nelem, bool lhomog,
struct mesh_element_struct *element)
{
int ielem, len_ien;
if (nelem < 1){return 0;}
if (lhomog)
{
len_ien = nelem*element[0].ngnod;
}
else
{
len_ien = 0;
for (ielem=0; ielem<nelem; ielem++)
{
len_ien = len_ien + element[ielem].ngnod;
}
}
return len_ien;
}
//============================================================================//
/*!
* @brief Builds the element node to global node map
*
* @param[in] nelem number of elements in mesh
* @param[in] len_ien length of the ien array
* @param[in] lhomog If true then all elements in mesh are the same
* If false then multiple element types exist in mesh
* @param[in] element holds the IEN array for each element and
* number of anchor nodes per element [nelem]
*
* @param[out] ien maps from ia'th node on ielem'th element to
* global anchor node number [len_ien]
*
*/
int mesh_element__getIEN(int nelem, int len_ien, bool lhomog,
struct mesh_element_struct *element,
int *ien_ptr, int *ien)
{
const char *fcnm = "mesh_element__getIEN\0";
int ia, ielem, indx, ngnod;
indx = 0;
ien_ptr[0] = 0;
if (lhomog){
ngnod = element[0].ngnod;
#pragma omp simd
for (ielem=0; ielem<nelem+1; ielem++){
ien_ptr[ielem] = ngnod*ielem;
}
#pragma omp parallel for collapse(2) private(ia, ielem, indx), \
firstprivate(ngnod), shared(element, ien)
for (ielem=0; ielem<nelem; ielem++){
for (ia=0; ia<ngnod; ia++){
indx = ielem*ngnod + ia;
ien[indx] = element[ielem].ien[ia];
}
}
}else{
for (ielem=0; ielem<nelem; ielem++){
ngnod = element[ielem].ngnod;
for (ia=0; ia<ngnod; ia++){
ien[indx] = element[ielem].ien[ia];
indx = indx + 1;
}
ien_ptr[ielem+1] = indx;
}
}
if (ien_ptr[nelem] != len_ien){
printf("%s: ien_ptr %d and len_ien %d inconsistent\n",
fcnm, ien_ptr[nelem], len_ien);
return -1;
}
return 0;
}
//============================================================================//
/*!
* @brief Computes the number of anchor nodes in the mesh from the
* element struct
*
* @param[in] cnum If true then the element structure is C numbered
* If false the the element structure is Fortran numbered
* @param[in] nelem number of elements in mesh
* @param[in] element element structure [nelem]
*
* @result number of anchor nodes in mesh
*
* @author Ben Baker, ISTI
*
*/
int mesh_element__getNumberOfAnchorNodes(bool cnum, int nelem,
struct mesh_element_struct *element)
{
int ia, ielem, ngnod, nnpg;
nnpg = 0;
#pragma omp parallel for private(ia, ielem, ngnod), \
shared(element), reduction(max:nnpg)
for (ielem=0; ielem<nelem; ielem++)
{
ngnod = element[ielem].ngnod;
for (ia=0; ia<ngnod; ia++)
{
nnpg = (int) (fmax(nnpg, element[ielem].ien[ia]));
}
}
if (cnum){nnpg = nnpg + 1;}
return nnpg;
}
//============================================================================//
/*!
* @brief Returns the (x,y,z) anchor node locations from the element
* structure
*
* @param[in] nelem number of elements in mesh
* @param[in] nnpg number of anchor nodes in mesh
* @param[in] element element structure from which to extract (x,y,z)
* triples onto the mesh anchor node location
** arrays [nelem]
*
* @param[out] xlocs x anchor node locations [nnpg]
* @param[out] ylocs y anchor node locations [nnpg]
* @param[out] zlocs z anchor node locations [nnpg]
*
* @result 0 indicates success
*
* @author Ben Baker, ISTI
*
*/
int mesh_element__getAnchorNodeLocations(int nelem, int nnpg,
struct mesh_element_struct *element,
double *__restrict__ xlocs,
double *__restrict__ ylocs,
double *__restrict__ zlocs)
{
const char *fcnm = "mesh_element__getAnchorNodeLocations\0";
int ia, ielem, inpg, ngnod;
if (nnpg < 1){
printf("%s: Error no anchor nodes in mesh\n", fcnm);
return -1;
}
#pragma omp simd
for (inpg=0; inpg<nnpg; inpg++){
xlocs[inpg] = 0.0;
ylocs[inpg] = 0.0;
zlocs[inpg] = 0.0;
}
#pragma omp parallel for private(ia, ielem, inpg, ngnod), \
shared(element, xlocs, ylocs, zlocs)
for (ielem=0; ielem<nelem; ielem++){
ngnod = element[ielem].ngnod;
for (ia=0; ia<ngnod; ia++){
inpg = element[ielem].ien[ia];
xlocs[inpg] = element[ielem].x[ia];
ylocs[inpg] = element[ielem].y[ia];
zlocs[inpg] = element[ielem].z[ia];
} // Loop on anchor nodes
} // Loop on elements
return 0;
}
//============================================================================//
/*!
* @brief Extracts the desired boundary surface
*
* @param[in] nelem number of elements in mesh
* @param[in] bdry desired boundary
* @param[in] element holds the element faces' boundary conditions
* [nelem]
* @param[out] ien_bdry_ptr maps from ielem_bdry'th element to start
* index of ien_bdry [nelem_bdry+1]
*
* @param[out] ien_bdry holds the global anchor node number of the
* ia'th anchor node on the ielem_bdry'th
* boundary element
*
* @author Ben Baker, ISTI
*
*/
int mesh_element__getBoundarySurface(int nelem, enum mesh_bc_enum bdry,
struct mesh_element_struct *element,
int *ien_bdry_ptr,
int *ien_bdry)
{
int ia, ielem, ielem_bdry, iface, indx, jndx;
ielem_bdry = 0;
ien_bdry_ptr[0] = 0;
// Loop on elements
for (ielem=0; ielem<nelem; ielem++){
// Loop on element faces
for (iface=0; iface<element[ielem].nface; iface++){
// Element face matches the boundary condition
if (element[ielem].bc[iface] == bdry){
// Update pointer
ien_bdry_ptr[ielem_bdry+1] = ien_bdry_ptr[ielem_bdry]
+ element[ielem].ngnod_face;
indx = ien_bdry_ptr[ielem_bdry];
jndx = iface*element[ielem].ngnod_face;
ielem_bdry = ielem_bdry + 1;
// Copy the anchor nodes
for (ia=0; ia<element[ielem].ngnod_face; ia++){
ien_bdry[indx] = element[ielem].ien_face[jndx];
indx = indx + 1;
jndx = jndx + 1;
}
} // End check on boundary condition match
} // Loop on element faces
} // Loop on elements
return 0;
}
//============================================================================//
/*!
* @brief Computes the array sizes for describing the boundary element
* surfaces
*
* @param[in] nelem number of elements in mesh
* @param[in] bdry desired boundary
* @param[in] element holds the element faces' boundary conditions
* [nelem]
*
* @param[out] nelem_bdry number of elements on boundary
* @param[out] len_ien_bdry length of the ien_bdry array
*
* @result 0 indicates success
*
* @author Ben Baker, ISTI
*/
int mesh_element__getIENBoundarySize(int nelem, enum mesh_bc_enum bdry,
struct mesh_element_struct *element,
int *nelem_bdry, int *len_ien_bdry)
{
int ielem, iface;
*nelem_bdry = 0;
*len_ien_bdry = 0;
// Loop on elements
for (ielem=0; ielem<nelem; ielem++)
{
// Loop on element faces
for (iface=0; iface<element[ielem].nface; iface++)
{
// Element face matches the boundary condition
if (element[ielem].bc[iface] == bdry)
{
*nelem_bdry = *nelem_bdry + 1;
*len_ien_bdry = *len_ien_bdry + element[ielem].ngnod_face;
}
} // Loop on element faces
} // Loop on elements
return 0;
}
//============================================================================//
/*!
* @brief Generates a mapping from anchor nodes to elements to which they
* are connected
*
* @param[in] nelem number of elements in mesh
* @param[in] nnpg number of anchor nodes in mesh
* @param[in] element holds the number of anchor nodes and
* anchor node to global anchor node (ien)
* map on each element [nelem]
*
* @param[out] node2element_ptr maps from the inpg'th node to the
* start index of node2element [nnpg+1]
* @param[out] ierr 0 indicates success
*
* @result node2element[i1:i2] are the elements attached to the
* inpg'th node
*
* @author Ben Baker, ISTI
*
*/
int *mesh_element__getNode2ElementMap(int nelem, int nnpg,
struct mesh_element_struct *element,
int *node2element_ptr,
int *ierr)
{
const char *fcnm = "mesh_element__getNode2ElementMap\0";
int *iwork, *isort, *node2element,
i, i1, i2, ia, ielem, inpg, j, maxcons, nwork;
// Initialize
*ierr = 0;
iwork = NULL;
isort = NULL;
node2element = NULL;
if (nnpg < 1 || nelem < 1)
{
if (nelem < 1){printf("%s: Error no elements in mesh\n", fcnm);}
if (nnpg < 1){printf("%s: Error no anchor nodes in mesh\n", fcnm);}
*ierr = 1;
goto ERROR;
}
iwork = (int *)calloc((size_t) nnpg, sizeof(int));
// Compute the workspace size
maxcons = 0;
for (ielem=0; ielem<nelem; ielem++)
{
for (ia=0; ia<element[ielem].ngnod; ia++)
{
inpg = element[ielem].ien[ia];
iwork[inpg] = iwork[inpg] + 1;
maxcons = (int) (fmax(iwork[inpg], maxcons));
}
}
free(iwork);
iwork = NULL;
// Set the connectivity workspace
iwork = (int *)calloc((size_t) (nnpg*maxcons), sizeof(int));
for (i=0; i<nnpg*maxcons; i++)
{
iwork[i] =-1;
}
// Fill the workspace with the node to element connectivity
nwork = 0;
for (ielem=0; ielem<nelem; ielem++)
{
for (ia=0; ia<element[ielem].ngnod; ia++)
{
inpg = element[ielem].ien[ia];
i1 = maxcons*inpg;
i2 = maxcons*(inpg + 1);
for (i=i1; i<i2; i++)
{
if (iwork[i] == ielem){break;} // Already have it
// It's new so add it
if (iwork[i] ==-1)
{
iwork[i] = ielem;
nwork = nwork + 1;
break;
}
}
}
}
// Now tally up the connectivity and store it
isort = (int *)calloc((size_t) maxcons, sizeof(int));
node2element = (int *)calloc((size_t) nwork, sizeof(int));
node2element_ptr[0] = 0;
for (inpg=0; inpg<nnpg; inpg++)
{
i1 = maxcons*inpg;
i2 = maxcons*(inpg + 1);
j = 0;
for (i=i1; i<i2; i++)
{
if (iwork[i] ==-1){break;}
isort[j] = iwork[i];
j = j + 1;
}
if (j == 0)
{
printf("%s: This is an internal error; j can't be zero\n", fcnm);
}
// Sort it for my sanity
*ierr = __sorting_sort__int(j, isort, ASCENDING);
if (*ierr != 0)
{
printf("%s: Error sorting %d points\n", fcnm, j);
goto ERROR;
}
// Copy it
node2element_ptr[inpg+1] = node2element_ptr[inpg] + j;
i1 = node2element_ptr[inpg];
i2 = node2element_ptr[inpg+1];
j = 0;
for (i=i1; i<i2; i++)
{
node2element[i1+j] = isort[j];
j = j + 1;
}
}
ERROR:;
if (iwork != NULL){free(iwork);}
if (isort != NULL){free(isort);}
if (*ierr != 0)
{
free(node2element);
node2element = NULL;
}
return node2element;
}
//============================================================================//
/*!
* @brief Returns the material properties (vp, vs, dens, ...) at the
* anchor nodes from the element structure
*
* @param[in] nelem number of elements in mesh
* @param[in] nnpg number of anchor nodes in mesh
* @param[in] element element structure from which to extract material
* properties onto the mesh anchor nodes material
* arrays [nelem]
*
* @param[out] vp compressional velocity at anchor nodes [nnpg]
* @param[out] vs shear velocity at anchor nodes [nnpg]
* @param[out] dens density at anchor nodes [nnpg]
* @param[out] Qp P quality factor at anchor nodes [nnpg]
* @param[out] Qs S quality factor at anchor nodes [nnpg]
*
* @result 0 indicates success
*
* @author Ben Baker, ISTI
*
*/
int mesh_element__getAnchorNodeProperties(int nelem, int nnpg,
struct mesh_element_struct *element,
double *__restrict__ vp,
double *__restrict__ vs,
double *__restrict__ dens,
double *__restrict__ Qp,
double *__restrict__ Qs)
{
const char *fcnm = "mesh_element__getAnchorNodeProperties\0";
int ia, ielem, inpg, ngnod;
if (nnpg < 1)
{
printf("%s: Error no anchor nodes in mesh\n", fcnm);
return -1;
}
#pragma omp simd
for (inpg=0; inpg<nnpg; inpg++)
{
vp[inpg] = 0.0;
vs[inpg] = 0.0;
dens[inpg] = 0.0;
}
#pragma omp parallel for private(ia, ielem, inpg, ngnod), \
shared(element, vp, vs, dens)
for (ielem=0; ielem<nelem; ielem++)
{
ngnod = element[ielem].ngnod;
for (ia=0; ia<ngnod; ia++)
{
inpg = element[ielem].ien[ia];
vp[inpg] = element[ielem].vp[ia];
vs[inpg] = element[ielem].vs[ia];
dens[inpg] = element[ielem].dens[ia];
Qp[inpg] = element[ielem].Qp[ia];
Qs[inpg] = element[ielem].Qs[ia];
} // Loop on anchor nodes
} // Loop on elements
return 0;
}
//============================================================================//
/*!
* @brief Sets the element anchor node locations
*
* @param[in] nelem number of elements in mesh
* @param[in] nnpg number of anchor nodes in mesh
* @param[in] xlocs x anchor node locations [nnpg]
* @param[in] ylocs y anchor node locations [nnpg]
* @param[in] zlocs z anchor node locations [nnpg]
*
* @param[in,out] element on entry contains the element element structure
* with number of anchor nodes per element and
* array space pre-allocated for x, y, and z
* on exit the x, y, and z arrays for each element
*
* @result 0 indicates success
*
* @author Ben Baker, ISTI
*
*/
int mesh_element__setAnchorNodeLocations(int nelem, int nnpg,
double *__restrict__ xlocs,
double *__restrict__ ylocs,
double *__restrict__ zlocs,
struct mesh_element_struct *element)
{
const char *fcnm = "mesh_element__setAnchorNodeLocations\0";
int ia, ielem, inpg, ngnod;
if (nelem < 1)
{
printf("%s: There are no elements in the mesh\n", fcnm);
return -1;
}
if (nnpg < 1)
{
printf("%s: There are no anchor nodes in the mesh\n", fcnm);
return -1;
}
#pragma omp parallel for private(ia, ielem, inpg, ngnod), \
shared(element, xlocs, ylocs, zlocs)
for (ielem=0; ielem<nelem; ielem++)
{
ngnod = element[ielem].ngnod;
for (ia=0; ia<ngnod; ia++)
{
inpg = element[ielem].ien[ia];
element[ielem].x[ia] = xlocs[inpg];
element[ielem].y[ia] = ylocs[inpg];
element[ielem].z[ia] = zlocs[inpg];
} // Loop on anchor nodes
} // Loop on elements
return 0;
}
//============================================================================//
/*!
* @param[in] nelem number of elements in mesh
* @param[in] vp compressional velocity at anchor nodes [nnpg]
* @param[in] vs shear velocity at anchor nodes [nnpg]
* @param[in] dens density at anchor nodes [nnpg]
* @param[in] Qp P quality factor at anchor nodes [nnpg]
* @param[in] Qs S quality factor at anchor nodes [nnpg]
*
* @param[in,out] element on entry contains the element element structure
* with number of anchor nodes per element and
* array space pre-allocated for vp, vs, and dens
* on exit the vp, vs, dens, Qp, and Qs, arrays for
* each element
*
* @result 0 indicates success
*
* @author Ben Baker, ISTI
*
*/
int mesh_element__setAnchorNodeProperties(int nelem, int nnpg,
double *__restrict__ vp,
double *__restrict__ vs,
double *__restrict__ dens,
double *__restrict__ Qp,
double *__restrict__ Qs,
struct mesh_element_struct *element)
{
const char *fcnm = "mesh_element__setAnchorNodeProperties\0";
int ia, ielem, inpg, ngnod;
if (nelem < 1)
{
printf("%s: There are no elements in the mesh\n", fcnm);
return -1;
}
if (nnpg < 1)
{
printf("%s: There are no anchor nodes in the mesh\n", fcnm);
return -1;
}
#pragma omp parallel for private(ia, ielem, inpg, ngnod), \
shared(element, vp, vs, dens, Qp, Qs)
for (ielem=0; ielem<nelem; ielem++)
{
ngnod = element[ielem].ngnod;
for (ia=0; ia<ngnod; ia++)
{
inpg = element[ielem].ien[ia];
element[ielem].vp[ia] = vp[inpg];
element[ielem].vs[ia] = vs[inpg];
element[ielem].dens[ia] = dens[inpg];
element[ielem].Qp[ia] = Qp[inpg];
element[ielem].Qs[ia] = Qs[inpg];
} // Loop on anchor nodes
} // Loop on elements
return 0;
}
//============================================================================//
/*!
* @brief Releses the memory on the element structure
*
* @param[in] nelem number of elements in mesh (> 1)
*
* @param[in,out] element freed array of element structures [nelem]
*
* @author Ben Baker, ISTI
*
*/
void mesh_element_memory__free(int nelem,
struct mesh_element_struct *element)
{
int ielem;
if (element == NULL){return;}
for (ielem=0; ielem<nelem; ielem++)
{
if (element[ielem].vp != NULL){free(element[ielem].vp);}
if (element[ielem].vs != NULL){free(element[ielem].vs);}
if (element[ielem].dens != NULL){free(element[ielem].dens);}
if (element[ielem].Qp != NULL){free(element[ielem].Qp);}
if (element[ielem].Qs != NULL){free(element[ielem].Qs);}
if (element[ielem].x != NULL){free(element[ielem].x);}
if (element[ielem].y != NULL){free(element[ielem].y);}
if (element[ielem].z != NULL){free(element[ielem].z);}
if (element[ielem].ien_face != NULL){free(element[ielem].ien_face);}
if (element[ielem].ien != NULL){free(element[ielem].ien);}
if (element[ielem].bc != NULL){free(element[ielem].bc);}
if (element[ielem].neighbor != NULL){free(element[ielem].neighbor);}
memset(&element[ielem], 0, sizeof(struct mesh_element_struct));
}
return;
}
//============================================================================//
/*!
* @brief Frees the memory on the mesh structure
*
* @param[in,out] mesh on input contains the mesh structure
* on output all pointers on the mesh structure
* have been freed
*
* @author Ben Baker, ISTI
*
*/
void mesh_memory__free(struct mesh_struct *mesh)
{
if (mesh->element != NULL)
{
mesh_element_memory__free(mesh->nelem, mesh->element);
free(mesh->element);
mesh->element = NULL;
}
if (mesh->xlocs != NULL){free(mesh->xlocs);}
if (mesh->ylocs != NULL){free(mesh->ylocs);}
if (mesh->zlocs != NULL){free(mesh->zlocs);}
memset(mesh, 0, sizeof(struct mesh_struct));
return;
}
//============================================================================//
/*!
* @brief Determines if the mesh has mixed elements
*
* @param[in] nelem number of elements in mesh
* @param[in] element holds the element type of each element [nelem]
*
* @result If True then the mesh has multiple elemen types
* Otherwise the mesh is of uniform element type
*
* @author Ben Baker, ISTI
*
*/
bool mesh_element__ishomog(int nelem, struct mesh_element_struct *element)
{
enum mesh_element_type type0;
int ielem;
bool lhomog;
lhomog = true;
if (nelem < 1){return lhomog;}
type0 = element[0].type;
for (ielem=1; ielem<nelem; ielem++)
{
if (element[ielem].type != type0)
{
lhomog = false;
break;
}
}
return lhomog;
}
//============================================================================//
/*!
* @brief Returns the number of anchor nodes associated with the element type
*
* @param[in] type element type
* @param[in] lis3d if true then this is a 3D mesh.
* otherwise this is a 2D mesh
*
* @result number of anchor nodes on element
*
*/
int mesh_element_type2numAnchorNodes(enum mesh_element_type type, bool lis3d)
{
const char *fcnm = "mesh_element__type2numAnchorNodes\0";
int ngnod;
if (lis3d)
{
ngnod = 8; // hexes
if (type == TET4)
{
ngnod = 4;
}
else if (type == HEX27)
{
ngnod = 27;
}
else if (type == TET8)
{
ngnod = 11;
}
else
{
if (type != HEX8)
{
printf("%s: Defaulting to HEX8\n", fcnm);
}
}
}
else
{
printf("%s: Error 2d not yet done\n", fcnm);
return -1;
}
return ngnod;
}
//============================================================================//
/*!
* @brief Returns the number of faces for the element type
*
* @param[in] type element type
*
* @result number of faces on the element
*
*/
int mesh_element_type2numFaces(enum mesh_element_type type)
{
const char *fcnm = "mesh_element_type2numFaces\0";
int nface;
nface = 6; // hexes have 6 faces
if (type == TET4)
{
nface = 4;
}
else if (type == HEX27)
{
nface = 6;
}
else if (type == TET8)
{
nface = 4;
}
else
{
if (type != HEX8)
{
printf("%s: Defaulting to HEX8\n", fcnm);
}
}
return nface;
}
//============================================================================//
/*!
* @brief Returns the number of anchor nodes per element face for this
* element type
*
* @param[in] type element type
*
* @result number of anchor nodes per face
*
*/
int mesh_element_type2numAnchorNodesPerFace(enum mesh_element_type type)
{
const char *fcnm = "mesh_element_type2numAnchorNodesPerFace\0";
int ngnod_face;
ngnod_face = 4; // each face has 4 nodes
if (type == TET4)
{
ngnod_face = 3;
}
else if (type == HEX27)
{
ngnod_face = 9;
}
else if (type == TET8)
{
ngnod_face = 6;
}
else
{
if (type != HEX8)
{
printf("%s: Defaulting to HEX8\n", fcnm);
}
}
return ngnod_face;
}
//============================================================================//
/*!
* @brief Allocates integer pointers for each element in the mesh
*
* @param[in] type defines the element type (use HEX8)
* @param[in] nelem number of elements in mesh (length of element)
*