-
Notifications
You must be signed in to change notification settings - Fork 10
/
model.c
1609 lines (1458 loc) · 62 KB
/
model.c
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
//********************************************************************************
//** **
//** Pertains to CU-BEN ver 4.0 **
//** **
//** CU-BENs: a ship hull modeling finite element library **
//** Copyright (c) 2019 C. J. Earls **
//** Developed by C. J. Earls, Cornell University **
//** All rights reserved. **
//** **
//** Contributors: **
//** Christopher Stull **
//** Heather Reed **
//** Justyna Kosianka **
//** Wensi Wu **
//** **
//** This program is free software: you can redistribute it and/or modify it **
//** under the terms of the GNU General Public License as published by the **
//** Free Software Foundation, either version 3 of the License, or (at your **
//** option) any later version. **
//** **
//** This program 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 General **
//** Public License for more details. **
//** **
//** You should have received a copy of the GNU General Public License along **
//** with this program. If not, see <https://www.gnu.org/licenses/>. **
//** **
//********************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "prototypes.h"
extern long NJ, NE_TR, NE_FR, NE_SH, NE_SBR, NE_FBR, NEQ, NBC, SNDOF, FNDOF, NTSTPS, ntstpsinpt;
extern double dt, ttot;
extern int ANAFLAG, ALGFLAG, OPTFLAG, SLVFLAG, FSIFLAG, FSIINCFLAG, brFSI_FLAG, shFSI_FLAG;
extern FILE *IFP[4], *OFP[8];
int struc (long *pjcode, long *pminc, int *pwrpres, long *pjnt)
{
long i, j, k, l, n, o, p, q, r, ptr; // Initialize function variables
long NE_BR = NE_SBR + NE_FBR;
int m, flag = 0, errchk;
int *jflag = alloc_int (NJ*4);
if (jflag == NULL) {
return 1;
}
long *jinc = alloc_long (NE_TR*2+NE_FR*2+NE_SH*3+NE_SBR*8+NE_FBR*8);
if (jinc == NULL) {
if (jflag != NULL) {
free (jflag);
jflag = NULL;
}
return 1;
}
long *jincloc = alloc_long (NJ*3+1);
if (jincloc == NULL) {
if (jflag != NULL) {
free (jflag);
jflag = NULL;
}
if (jinc != NULL) {
free (jinc);
jinc = NULL;
}
return 1;
}
long *xadj = alloc_long (NJ+1);
if (xadj == NULL) {
if (jflag != NULL) {
free (jflag);
jflag = NULL;
}
if (jinc != NULL) {
free (jinc);
jinc = NULL;
}
if (jincloc != NULL) {
free (jincloc);
jincloc = NULL;
}
return 1;
}
/* Joint-element connectivity flags tracks element-types connected to each joint - initialized to zero, which assumes "floating" joint */
/* Warping restraint flag tracks warping restraint at a joint (array 1) and number of frame elements connected to a joint (array 2) - initialized to zeros, which assumes member ends are fixed against warping */
for (i = 0; i < NJ*3; ++i) {
jflag[i] = *(pwrpres+i) = 0;
}
// Establish truss member incidences
for (i = 0; i < NE_TR; ++i) {
// Read in Ends 1 and 2 from input file
fscanf(IFP[0], "%ld,%ld\n", pminc+i*2, pminc+i*2+1);
jflag[(*(pminc+i*2)-1)*3]++; // Truss element is connected to Joint j
jflag[(*(pminc+i*2+1)-1)*3]++; // Truss element is connected to Joint k
}
// Establish frame member incidences
ptr = NE_TR * 2;
for (i = 0; i < NE_FR; ++i) {
// Read in Ends 1 and 2 from input file
fscanf(IFP[0], "%ld,%ld\n", pminc+ptr+i*2, pminc+ptr+i*2+1);
jflag[(*(pminc+ptr+i*2)-1)*3+1]++; // Frame element is connected to Joint j
jflag[(*(pminc+ptr+i*2+1)-1)*3+1]++; // Frame element is connected to Joint k
/* Increment warping restraint flags on joints to reflect number of frame members framing into joint */
(*(pwrpres+(*(pminc+ptr+i*2)-1)*3+1))++;
(*(pwrpres+(*(pminc+ptr+i*2+1)-1)*3+1))++;
}
// Establish shell member incidences
ptr += NE_FR * 2;
for (i = 0; i < NE_SH; ++i) {
// Read in Vertices 1, 2, and 3 from input file
fscanf(IFP[0], "%ld,%ld,%ld\n", pminc+ptr+i*3, pminc+ptr+i*3+1, pminc+ptr+i*3+2);
jflag[(*(pminc+ptr+i*3)-1)*3+2]++; // Shell element is connected to Joint j
jflag[(*(pminc+ptr+i*3+1)-1)*3+2]++; // Shell element is connected to Joint k
jflag[(*(pminc+ptr+i*3+2)-1)*3+2]++; // Shell element is connected to Joint l
}
// Establish brick member incidences
ptr += NE_SH * 3;
for (i = 0; i < NE_BR; ++i) {
// Read in nodes 1-8 from input file
fscanf(IFP[0], "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld\n", pminc+ptr+i*8, pminc+ptr+i*8+1, pminc+ptr+i*8+2, pminc+ptr+i*8+3, pminc+ptr+i*8+4, pminc+ptr+i*8+5, pminc+ptr+i*8+6, pminc+ptr+i*8+7);
jflag[(*(pminc+ptr+i*8)-1)*3+3]++; // Brick element is connected to Joint j
jflag[(*(pminc+ptr+i*8+1)-1)*3+3]++; // Brick element is connected to Joint k
jflag[(*(pminc+ptr+i*8+2)-1)*3+3]++; // Brick element is connected to Joint l
jflag[(*(pminc+ptr+i*8+3)-1)*3+3]++; // Brick element is connected to Joint j
jflag[(*(pminc+ptr+i*8+4)-1)*3+3]++; // Brick element is connected to Joint k
jflag[(*(pminc+ptr+i*8+5)-1)*3+3]++; // Brick element is connected to Joint l
jflag[(*(pminc+ptr+i*8+6)-1)*3+3]++; // Brick element is connected to Joint j
jflag[(*(pminc+ptr+i*8+7)-1)*3+3]++; // Brick element is connected to Joint k
}
// Build joint incidence and adjacency "locator arrays"
jincloc[0] = xadj[0] = 0;
for (i = 0; i < NJ; ++i) {
*(pjnt+i) = i;
jincloc[i*3+1] = jincloc[i*3] + jflag[i*3];
jincloc[i*3+2] = jincloc[i*3+1] + jflag[i*3+1];
jincloc[i*3+3] = jincloc[i*3+2] + jflag[i*3+2];
xadj[i+1] = xadj[i] + jflag[i*3] + jflag[i*3+1] + 2 * jflag[i*3+2];
jflag[i*3] = jflag[i*3+1] = jflag[i*3+2] = 0;
}
// Establish truss joint incidences
for (i = 0; i < NE_TR; ++i) {
j = *(pminc+i*2) - 1;
k = *(pminc+i*2+1) - 1;
jinc[jincloc[j*3]+jflag[j*3]] = i + 1;
jinc[jincloc[k*3]+jflag[k*3]] = i + 1;
jflag[j*3]++;
jflag[k*3]++;
}
// Establish frame joint incidences
ptr = NE_TR * 2;
for (i = 0; i < NE_FR; ++i) {
j = *(pminc+ptr+i*2) - 1;
k = *(pminc+ptr+i*2+1) - 1;
jinc[jincloc[j*3+1]+jflag[j*3+1]] = i + 1;
jinc[jincloc[k*3+1]+jflag[k*3+1]] = i + 1;
jflag[j*3+1]++;
jflag[k*3+1]++;
}
// Establish shell joint incidences
ptr += NE_FR * 2;
for (i = 0; i < NE_SH; ++i) {
j = *(pminc+ptr+i*3) - 1;
k = *(pminc+ptr+i*3+1) - 1;
l = *(pminc+ptr+i*3+2) - 1;
jinc[jincloc[j*3+2]+jflag[j*3+2]] = i + 1;
jinc[jincloc[k*3+2]+jflag[k*3+2]] = i + 1;
jinc[jincloc[l*3+2]+jflag[l*3+2]] = i + 1;
jflag[j*3+2]++;
jflag[k*3+2]++;
jflag[l*3+2]++;
}
// Establish brick joint incidences
ptr += NE_SH * 3;
for (i = 0; i < NE_BR; ++i) {
j = *(pminc+ptr+i*8+0) - 1;
k = *(pminc+ptr+i*8+1) - 1;
l = *(pminc+ptr+i*8+2) - 1;
n = *(pminc+ptr+i*8+3) - 1;
o = *(pminc+ptr+i*8+4) - 1;
p = *(pminc+ptr+i*8+5) - 1;
q = *(pminc+ptr+i*8+6) - 1;
r = *(pminc+ptr+i*8+7) - 1;
jinc[jincloc[j*3+2]+jflag[j*3+2]] = i + 1;
jinc[jincloc[k*3+2]+jflag[k*3+2]] = i + 1;
jinc[jincloc[l*3+2]+jflag[l*3+2]] = i + 1;
jinc[jincloc[n*3+2]+jflag[j*3+2]] = i + 1;
jinc[jincloc[o*3+2]+jflag[k*3+2]] = i + 1;
jinc[jincloc[p*3+2]+jflag[l*3+2]] = i + 1;
jinc[jincloc[q*3+2]+jflag[j*3+2]] = i + 1;
jinc[jincloc[r*3+2]+jflag[k*3+2]] = i + 1;
jflag[j*3+2]++;
jflag[k*3+2]++;
jflag[l*3+2]++;
jflag[n*3+2]++;
jflag[o*3+2]++;
jflag[p*3+2]++;
jflag[q*3+2]++;
jflag[r*3+2]++;
}
// Establish joint constraints; initialized to ones, which assumes free DOF */
for (i = 0; i < NJ*7; ++i) {
*(pjcode+i) = -1;
}
// Potentially all joints are constrained
for (i = 0; i < NJ*7; ++i) {
// Read in joint number and constraint direction from input file
fscanf(IFP[0], "%ld,%ld\n", &j, &k);
if (j != 0) {
switch (k) {
case 1:
fscanf(IFP[0], "\n");
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
case 2:
fscanf(IFP[0], "\n");
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
case 3:
fscanf(IFP[0], "\n");
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
case 4:
fscanf(IFP[0], "\n");
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
case 5:
fscanf(IFP[0], "\n");
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
case 6:
fscanf(IFP[0], "\n");
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
case 7:
fscanf(IFP[0], ",%d\n", pwrpres+(j-1)*3);
*(pjcode+(j-1)*7+(k-1)) = 0;
break;
default:
fprintf(OFP[0], "\n***ERROR*** Joint constraint input not");
fprintf(OFP[0], " recognized\n");
return 1;
break;
}
} else {
break;
}
}
/* Determine if joint DOF(s) is free due to no joint connection with truss (DOFs 1 thru 3), shell (DOFs 4 thru 6), or frame (DOF 7) elements */
for (i = 0; i < NJ; ++i) {
if (jflag[i*3+1] == 0) {
if (jflag[i*3+2] == 0) {
if (jflag[i*3] == 0) {
for (j = 0; j < 7; ++j) {
*(pjcode+i*7+j) = 0;
}
} else {
for (j = 3; j < 7; ++j) {
*(pjcode+i*7+j) = 0;
}
}
} else {
if (ANAFLAG != 4){
*(pjcode+i*7+6) = 0;
}
}
}
}
if (OPTFLAG == 2) {
// Pass control to graph function
errchk = graph (pjnt, xadj, pjcode, pwrpres, pminc, jinc, jincloc);
// Terminate program if errors encountered
if (errchk == 1) {
if (jflag != NULL) {
free (jflag);
jflag = NULL;
}
if (jinc != NULL) {
free (jinc);
jinc = NULL;
}
if (jincloc != NULL) {
free (jincloc);
jincloc = NULL;
}
if (xadj != NULL) {
free (xadj);
xadj = NULL;
}
return 1;
}
}
if (NE_TR > 0) {
// Print truss member incidences
fprintf(OFP[0], "\nTruss Member Incidences:\n\tMember\t\tEnd-1\t\tEnd-2\n");
for (i = 0; i < NE_TR; ++i) {
fprintf(OFP[0], "\t%ld\t\t%ld\t\t%ld\n", i + 1, *(pminc+i*2),
*(pminc+i*2+1));
}
if (OPTFLAG == 2) {
for (i = 0; i < NE_TR; ++i) {
fprintf(IFP[1], "%ld,%ld\n", *(pminc+i*2), *(pminc+i*2+1));
}
}
}
if (NE_FR > 0) {
// Print frame member incidences
fprintf(OFP[0], "\nFrame Member Incidences:\n\tMember\t\tEnd-1\t\tEnd-2\n");
ptr = NE_TR * 2;
for (i = 0; i < NE_FR; ++i) {
fprintf(OFP[0], "\t%ld\t\t%ld\t\t%ld\n", i + 1, *(pminc+ptr+i*2),
*(pminc+ptr+i*2+1));
}
if (OPTFLAG == 2) {
for (i = 0; i < NE_FR; ++i) {
fprintf(IFP[1], "%ld,%ld\n", *(pminc+ptr+i*2), *(pminc+ptr+i*2+1));
}
}
}
if (NE_SH > 0) {
// Print shell member incidences
fprintf(OFP[0], "\nShell Member Incidences:\n\tElement\t\tVertex-1\tVertex-2\t");
fprintf(OFP[0], "Vertex-3\n");
ptr = NE_TR * 2 + NE_FR * 2;
for (i = 0; i < NE_SH; ++i) {
fprintf(OFP[0], "\t%ld\t\t%ld\t\t%ld\t\t%ld\n", i + 1, *(pminc+ptr+i*3),
*(pminc+ptr+i*3+1), *(pminc+ptr+i*3+2));
}
if (OPTFLAG == 2) {
for (i = 0; i < NE_SH; ++i) {
fprintf(IFP[1], "%ld,%ld,%ld\n", *(pminc+ptr+i*3), *(pminc+ptr+i*3+1),
*(pminc+ptr+i*3+2));
}
}
}
if (NE_SBR > 0) {
// Print brick member incidences
fprintf(OFP[0], "\nSBrick Member Incidences:\n\tElement\t\tVertex-1\tVertex-2\tVertex-3\tVertex-4\tVertex-5\tVertex-6\tVertex-7\tVertex-8\n");
ptr = NE_TR * 2 + NE_FR * 2 + NE_SH * 3;
for (i = 0; i < NE_SBR; ++i) {
fprintf(OFP[0], "\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t\%ld\n", i + 1, *(pminc+ptr+i*8),
*(pminc+ptr+i*8+1), *(pminc+ptr+i*8+2), *(pminc+ptr+i*8+3), *(pminc+ptr+i*8+4), *(pminc+ptr+i*8+5), *(pminc+ptr+i*8+6), *(pminc+ptr+i*8+7));
}
}
if (NE_FBR > 0) {
// Print brick member incidences
fprintf(OFP[0], "\nFBrick Member Incidences:\n\tElement\t\tVertex-1\tVertex-2\tVertex-3\tVertex-4\tVertex-5\tVertex-6\tVertex-7\tVertex-8\n");
ptr = NE_TR * 2 + NE_FR * 2 + NE_SH * 3 + NE_SBR * 8;
for (i = 0; i < NE_FBR; ++i) {
fprintf(OFP[0], "\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t%ld\t\t\%ld\n", i + 1, *(pminc+ptr+i*8),
*(pminc+ptr+i*8+1), *(pminc+ptr+i*8+2), *(pminc+ptr+i*8+3), *(pminc+ptr+i*8+4), *(pminc+ptr+i*8+5), *(pminc+ptr+i*8+6), *(pminc+ptr+i*8+7));
}
}
// Print user-prescribed joint constraints
fprintf(OFP[0], "\nJoint Constraints:\n\tJoint\t\tDirection\tWarping (optional)\n");
// Potentially all joints are constrained
for (i = 0; i < NJ; ++i) {
for (j = 0; j < 6; ++j) {
if (*(pjcode+i*7+j) == 0) {
fprintf(OFP[0], "\t%ld\t\t%ld\n", i + 1, j + 1);
}
}
if (*(pjcode+i*7+6) == 0) {
fprintf(OFP[0], "\t%ld\t\t%ld\t\t%d\n", i + 1, j + 1, *(pwrpres+i*3));
}
}
if (OPTFLAG == 2) {
for (i = 0; i < NJ; ++i) {
for (j = 0; j < 6; ++j) {
if (*(pjcode+i*7+j) == 0) {
fprintf(IFP[1], "%ld,%ld\n", i + 1, j + 1);
}
}
if (*(pjcode+i*7+6) == 0) {
fprintf(IFP[1], "%ld,%ld,%d\n", i + 1, j + 1, *(pwrpres+i*3));
}
}
fprintf(IFP[1], "0,0\n");
}
if (jflag != NULL) {
free (jflag);
jflag = NULL;
}
if (jinc != NULL) {
free (jinc);
jinc = NULL;
}
if (jincloc != NULL) {
free (jincloc);
jincloc = NULL;
}
if (xadj != NULL) {
free (xadj);
xadj = NULL;
}
return 0;
}
void fsi (long *pmcode, long *pjcode, long *pminc, long *pelface, long *pfsiinc) {
// Initialize function variables
long i, j, k, l, m, n, NE_BR;
int nnpfsif; // Num nodes per FSI face; = 3 if solids are shells; = 4 if solid are bricks
int nnps; // Num nodes per solid
int nfps; // Num faces per solid
int nsolids;
if (shFSI_FLAG == 1) {
nnpfsif = 3;
nnps = 3;
nfps = 1;
nsolids = NE_SH;
}
if (brFSI_FLAG == 1) {
nnpfsif = 4;
nnps = 8;
nfps = 6;
nsolids = NE_SBR;
}
NE_BR = NE_FBR+nsolids;
long ptr = nsolids*nnps;
int face[4]; //global joints associated with an element's particular face
int lcjts[4], lcjtf[4]; //local fluid and solid joints for use in evaluating f-s faces
// Initialize elface and fsi incidence array
for (i = 0; i < nsolids; ++i) {
*(pelface+i) = 0;
for (j = 0; j < nfps; ++j) {
for (k = 0; k < nnpfsif; ++k) {
*(pfsiinc+i*nfps*nnpfsif+j*nnpfsif+k) = 0;
}
}
}
if (FSIINCFLAG == 0) { // read in fsi incidence array from input file
FILE *fsifile;
long j1, j2, j3;
// Read in solid shell coordinates
do {
fsifile = fopen("fsiinc.txt", "r"); // Open input file for reading
} while (fsifile == 0);
// Load dented shell coordinates
for (i = 0; i < nsolids; ++i) {
fscanf(fsifile, "%ld,%ld,%ld\n",&j1,&j2,&j3);
if (j1 != 0 || j2 != 0 || j3 != 0) { *(pelface+i) = 1;}
*(pfsiinc+i*3+0) = j1; *(pfsiinc+i*3+1) = j2; *(pfsiinc+i*3+2) = j3;
}
fclose(fsifile); // Close input file
}
else if (FSIINCFLAG == 1) { // auto find interface
/* *** READING IN FSIINC*** */
/* Determine which element faces are f-s faces by finding the faces that have a
fluid element and a solid element in common */
if (brFSI_FLAG == 1) {
// Loop through fluid elements
for (i = nsolids; i < NE_BR; ++i) {
l=0; // l = current solid element
m=0;
// Loop through solid elements until a matching face for each fluid element is found
while ((m < nnpfsif) && l < nsolids) {
m = 0; // m counts how many nodes on a potential matching face have ben found
for (j = 0; j < 8; ++j) { // Loop through nodes of fluid element i
for (k = 0; k < nnps; ++k) { // Loop through nodes of solid element l
// If the global joints of fluid and solid element are a match
if (*(pminc+ptr+(i-nsolids)*8+j) == *(pminc+l*nnps+k)) {
face[m] = *(pminc+l*nnps+k); // Assign global joint to local face array
++m;
/* If a full face has been found, increase the
number of fsi faces for current solid element */
if (m == nnpfsif) {
*(pelface+l) += 1;
}
}
}
}
++l; // Move on to next solid element if matching face not found
}
// If a full face has been found, assign the joints to the fsi incidence array
if (*(pelface+l-1) != 0 && m == nnpfsif){
for (n = 0; n < nnpfsif; ++n) {
// Store the global joint in the fsi incidence array
*(pfsiinc + (l-1)*nfps*nnpfsif + (*(pelface+l-1)-1)*nnpfsif + n) = face[n];
}
}
}
}
if (shFSI_FLAG == 1) {
// Loop through solid elements
for (l = 0; l < nsolids; ++l) {
i = nsolids; // i = current fluid element
m = 0;
// Loop through fluid elements until a matching face for each solid element is found
while ((m < nnpfsif) && i < NE_BR) {
m = 0; // m counts how many nodes on a potential matching face have ben found
for (k = 0; k < nnps; ++k) { // Loop through nodes of solid element l
for (j = 0; j < 8; ++j) { // Loop through nodes of fluid element i
// If the global joints of fluid and solid element are a match
if (*(pminc+ptr+(i-nsolids)*8+j) == *(pminc+l*nnps+k)) {
face[m] = *(pminc+l*nnps+k); // Assign global joint to local face array
++m;
/* If a full face has been found, increase the
number of fsi faces for current solid element */
if (m == nnpfsif) {
*(pelface+l) += 1;
}
}
}
}
++i; // Move on to next fluid element if matching face not found
}
// If a full face has been found, assign the joints to the fsi incidence array
if (*(pelface+l-1) != 0 && m == nnpfsif){
for (n = 0; n < nnpfsif; ++n) {
// Store the global joint in the fsi incidence array
*(pfsiinc + l*nfps*nnpfsif + (*(pelface+l-1)-1)*nnpfsif + n) = face[n];
}
}
}
}
}
}
void renumfsi (long *pminc, long *pmcode, long *pjcode, long *pelface, long *pfsiinc) {
// Initialize function variables
long i, j, k, l, m, n, o, NE_BR;
long jt, DOF;
int nnpfsif; // Num nodes per FSI face; = 3 if solids are shells; = 4 if solid are bricks
int nnps; // Num nodes per solid
int nfps; // Num faces per solid
int nsolids;
int ndofpe; // Number of dofs per solid
int ndofspn; // Number of dofs per node
if (shFSI_FLAG == 1) {
nnpfsif = 3;
nnps = 3;
nfps = 1;
nsolids = NE_SH;
ndofpe = 18;
ndofspn = 6;
}
if (brFSI_FLAG == 1) {
nnpfsif = 4;
nnps = 8;
nfps = 6;
nsolids = NE_SBR;
ndofpe = 24;
ndofspn = 3;
}
long jcode_temp[NJ][7];
NE_BR = NE_FBR+nsolids;
long NEQ_repl, NEQ_prev; //used for renumbering mcode
double fsitemp[nsolids*nfps*nnpfsif];
// Initialize fsitemp with fsi_inc values
for (i = 0; i < nsolids; ++i) {
for (j = 0; j < nfps; ++j) {
for (k = 0; k < nnpfsif; ++k) {
fsitemp[i*nnpfsif*nfps+j*nnpfsif+k] = *(pfsiinc+i*nnpfsif*nfps+j*nnpfsif+k);
}
}
}
for (i = 0; i < NJ; ++i) {
for (j = 0; j < 7; ++j) {
jcode_temp[i][j] = 0;
}
}
for (i = 0; i < NJ; ++i) {
fprintf(OFP[4],"%ld\t\t\t",i+1);
for (j = 0; j < 7; ++j) {
fprintf(OFP[4],"%ld\t",*(pjcode+i*7+j));
}
fprintf(OFP[4],"\n");
}
for (i = 0; i < NE_BR; ++i) {
fprintf(OFP[6],"%ld\t\t\t",i+1);
for (j = 0; j < 24; ++j) {
fprintf(OFP[6],"%ld\t",*(pmcode+i*24+j));
}
fprintf(OFP[6],"\n");
}
}
int graph (long *pjnt, long *pxadj, long *pjcode, int *pwrpres, long *pminc, long *pjinc,
long *pjincloc)
{
// Initialize function variables
long i, j, k, l, m, n, o, ptr, ptr2;
int errchk, flag = 0;
long *adjncy = alloc_long (*(pxadj+NJ));
if (adjncy == NULL) {
return 1;
}
// Generate DOF-weights and adjacency structure for each joint
ptr = NE_TR * 2;
ptr2 = NE_TR * 2 + NE_FR * 2;
for (i = 0; i < NJ; ++i) {
o = 0;
// Generate adjacency structure related to truss members
for (j = *(pjincloc+i*3); j < *(pjincloc+i*3+1); ++j) {
k = *(pjinc+j) - 1;
l = *(pminc+k*2) - 1;
m = *(pminc+k*2+1) - 1;
if (l == i) {
adjncy[*(pxadj+i)+o] = m;
o++;
} else {
adjncy[*(pxadj+i)+o] = l;
o++;
}
}
// Generate adjacency structure related to frame members
for (j = *(pjincloc+i*3+1); j < *(pjincloc+i*3+2); ++j) {
k = *(pjinc+j) - 1;
l = *(pminc+ptr+k*2) - 1;
m = *(pminc+ptr+k*2+1) - 1;
if (l == i) {
adjncy[*(pxadj+i)+o] = m;
o++;
} else {
adjncy[*(pxadj+i)+o] = l;
o++;
}
}
// Generate adjacency structure related to shell members
for (j = *(pjincloc+i*3+2); j < *(pjincloc+i*3+3); ++j) {
k = *(pjinc+j) - 1;
l = *(pminc+ptr2+k*3) - 1;
m = *(pminc+ptr2+k*3+1) - 1;
n = *(pminc+ptr2+k*3+2) - 1;
if (l == i) {
adjncy[*(pxadj+i)+o] = m;
adjncy[*(pxadj+i)+o+1] = n;
o += 2;
} else if (m == i) {
adjncy[*(pxadj+i)+o] = l;
adjncy[*(pxadj+i)+o+1] = n;
o += 2;
} else {
adjncy[*(pxadj+i)+o] = l;
adjncy[*(pxadj+i)+o+1] = m;
o += 2;
}
}
}
// Pass control to optnum function
errchk = optnum (pjnt, adjncy, pxadj, &flag);
// Terminate program if errors encountered
if (errchk == 1) {
if (adjncy != NULL) {
free (adjncy);
adjncy = NULL;
}
return 1;
}
if (flag == 1) {
fprintf(OFP[0], "\n***WARNING*** Original node-numbering scheme modified\n");
// Pass control to updatenum function
errchk = updatenum (pjcode, pminc, pwrpres, pjnt);
// Terminate program if errors encountered
if (errchk == 1) {
if (adjncy != NULL) {
free (adjncy);
adjncy = NULL;
}
return 1;
}
}
if (adjncy != NULL) {
free (adjncy);
adjncy = NULL;
}
return 0;
}
int optnum (long *pjnt, long *padjncy, long *pxadj, int *pflag)
{
// Initialize function variables
long ik, i, max, k, kmax, k4, jj, k5, band, nband, prof, nprof;
long *newjt = alloc_long (NJ);
if (newjt == NULL) {
return 1;
}
long *joint = alloc_long (NJ);
if (joint == NULL) {
if (newjt != NULL) {
free (newjt);
newjt = NULL;
}
return 1;
}
*pflag = 0; // Initialize flag for updating node numbering
// Attempt a node-numbering scheme setting each old node as the starting node
band = NJ*7;
prof = band * band;
for (ik = 0; ik < NJ; ++ik) {
// Initialize sub-routine variables for the ik'th starting node
for (i = 0; i < NJ; ++i) {
joint[i] = newjt[i] = -1;
}
max = 0;
nprof = 0;
i = 0;
newjt[0] = ik;
joint[ik] = 0;
k = kmax = 0;
do {
// Determine number of nodes connected to i'th new node
if (newjt[i] != -1) {
k4 = *(pxadj+newjt[i]+1) - *(pxadj+newjt[i]);
// Consecutively number nodes connected to i'th new node
for (jj = 0; jj < k4; ++jj) {
k5 = *(padjncy+*(pxadj+newjt[i])+jj);
if (joint[k5] == -1) {
k++;
kmax++;
newjt[k] = k5;
joint[k5] = k;
/* Calculate "bandwidth" and compare to existing; terminate attempt
if "bandwidth" is greater than or equal to existing */
nband = labs(i - k);
if (nband <= band) {
if (nband > max) {
max = nband;
}
} else {
break;
}
}
}
} else if (newjt[i] == -1 && k != 0) {
k++;
newjt[k] = newjt[k-1] - 1;
} else {
break;
}
nprof += max;
i++;
} while (k < NJ - 1);
/* If all joints were assigned new joint numbers, compute profile of proposed
joint-numbering scheme */
if (k == NJ - 1) {
nband = max;
/* If profile of proposed joint-numbering scheme is less than current
profile, store joint-numbering scheme */
if (nband < band) {
*pflag = 1;
band = nband;
prof = nprof;
for (i = 0; i < NJ; ++i) {
if (joint[i] != -1) {
*(pjnt+i) = joint[i];
} else {
kmax++;
*(pjnt+i) = kmax;
}
}
} else if (nband == band && nprof < prof) {
*pflag = 1;
band = nband;
prof = nprof;
for (i = 0; i < NJ; ++i) {
if (joint[i] != -1) {
*(pjnt+i) = joint[i];
} else {
kmax++;
*(pjnt+i) = kmax;
}
}
}
}
}
if (newjt != NULL) {
free (newjt);
newjt = NULL;
}
if (joint != NULL) {
free (joint);
joint = NULL;
}
return 0;
}
int updatenum (long *pjcode, long *pminc, int *pwrpres, long *pjnt)
{
// Define function variables
long i, j, ptr;
long *jcode = alloc_long (NJ*7);
if (jcode == NULL) {
return 1;
}
int *wrpres = alloc_int (NJ*3);
if (wrpres == NULL) {
if (jcode != NULL) {
free (jcode);
jcode = NULL;
}
return 1;
}
// Transfer variables with new node-numbering scheme to temporary variables
for (i = 0; i < NJ; ++i) {
// Transfer jcode
for (j = 0; j < 7; ++j) {
jcode[*(pjnt+i)*7+j] = *(pjcode+i*7+j);
}
// Transfer wrpres
for (j = 0; j < 3; ++j) {
wrpres[*(pjnt+i)*3+j] = *(pwrpres+i*3+j);
}
}
// Update variables with new node-numbering scheme
for (i = 0; i < NJ; ++i) {
// Update jcode
for (j = 0; j < 7; ++j) {
*(pjcode+i*7+j) = jcode[i*7+j];
}
// Update wrpres
for (j = 0; j < 3; ++j) {
*(wrpres+i*3+j) = wrpres[i*3+j];
}
}
// Update truss member incidences
for (i = 0; i < NE_TR; ++i) {
*(pminc+i*2) = *(pjnt+*(pminc+i*2)-1) + 1;
*(pminc+i*2+1) = *(pjnt+*(pminc+i*2+1)-1) + 1;
}
// Update frame member incidences
ptr = NE_TR * 2;
for (i = 0; i < NE_FR; ++i) {
*(pminc+ptr+i*2) = *(pjnt+*(pminc+ptr+i*2)-1) + 1;
*(pminc+ptr+i*2+1) = *(pjnt+*(pminc+ptr+i*2+1)-1) + 1;
}
// Update shell member incidences
ptr += NE_FR * 2;
for (i = 0; i < NE_SH; ++i) {
*(pminc+ptr+i*3) = *(pjnt+*(pminc+ptr+i*3)-1) + 1;
*(pminc+ptr+i*3+1) = *(pjnt+*(pminc+ptr+i*3+1)-1) + 1;
*(pminc+ptr+i*3+2) = *(pjnt+*(pminc+ptr+i*3+2)-1) + 1;
}
if (jcode != NULL) {
free (jcode);
jcode = NULL;
}
if (wrpres != NULL) {
free (wrpres);
wrpres = NULL;
}
return 0;
}
void codes (long *pmcode, long *pjcode, long *pminc, int *pwrpres)
{
long i, j, k, l, m, n, o, p, q, r, ptr, ptr2; // Initialize function variables
if (ANAFLAG != 4){
// Generate jcode
NEQ = 0;
for (i = 0; i < NJ; ++i) {
*(pwrpres+i*3+2) = *(pwrpres+i*3+1);
for (j = 0; j < 6; ++j) {
if (*(pjcode+i*7+j) != 0) {
NEQ++;
*(pjcode+i*7+j) = NEQ;
}
}
if (*(pjcode+i*7+6) != 0) {
NEQ++;
*(pjcode+i*7+6) = NEQ;
} else if (*(pjcode+i*7+6) == 0 && *(pwrpres+i*3) == 1) {
NEQ++;
*(pjcode+i*7+6) = NEQ;
NEQ += *(pwrpres+i*3+1) - 1;
}
}
}
/* Generate jcode for FSI; DOF 7 is pressure, not warping
Number DOFs s.t. displacement dofs are first, then pressure dofs*/
if (ANAFLAG == 4){
NEQ = 0;
for (i = 0; i < NJ; ++i) {
for (j = 0; j < 6; ++j) {
if (*(pjcode+i*7+j) != 0) {
NEQ++;
*(pjcode+i*7+j) = NEQ;
}
}
}
}
SNDOF = NEQ;
if (ANAFLAG == 4){
// Label pressure dofs
for (i = 0; i < NJ; ++i) {
if (*(pjcode+i*7+6) != 0) {
NEQ++;
*(pjcode+i*7+6) = NEQ;
}
}
}
// Fluid dofs are total - structural
FNDOF = NEQ-SNDOF;
// Generate mcode for truss elements from jcode using member incidence matrix
for (i = 0; i < NE_TR; ++i) {
j = *(pminc+i*2) - 1; // Establish End-1 joint number
k = *(pminc+i*2+1) - 1; // Establish End-2 joint number
// Increment of DOFs for each end
for (m = 0; m < 3; ++m) {
*(pmcode+i*6+m) = *(pjcode+j*7+m); // Assign mcode entry using jcode
*(pmcode+i*6+3+m) = *(pjcode+k*7+m); // As above, for DOFs 4 thru 6
}