-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkw.py
2025 lines (1384 loc) · 45.9 KB
/
kw.py
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
# -*- coding: utf-8 -*-
"""
Created on
@author: OWP
"""
#%%
import numpy as np
import putools
import warnings
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
return '%s:%s: %s: %s\n' % (filename, lineno, category.__name__, message)
warnings.formatwarning = warning_on_one_line
#%%
def assembly(fid,assembly_name):
'''
*ASSEMBLY
Arguments
------------
fid: file identifier
assembly_name: string with name
Returns
------------
None
'''
fid.write('*ASSEMBLY, NAME=' + assembly_name.upper() + '\n')
fid.write('**' + '\n')
#%%
def assemblyend(fid):
'''
*END ASSEMBLY
Arguments
------------
fid: file identifier
Returns
------------
None
'''
fid.write('*END ASSEMBLY' + '\n')
fid.write('**' + '\n')
#%%
def beamaddedinertia(fid,linear_mass,x1,x2,alpha,I_11,I_22,I_12):
'''
*BEAM ADDED INERTIA
Arguments
------------
fid: file identifier
linear_mass: mass [kg/m]
x1: 1-dir offset [m]
x2: 2-dir offset [m]
alpha: rotation offset [deg]
I_11: inertia [kg*m^2]
I_22: inertia [kg*m^2]
I_12: inertia [kg*m^2]
Returns
------------
None
'''
fid.write('*BEAM ADDED INERTIA' + '\n')
values_list=[linear_mass,x1,x2,alpha,I_11,I_22,I_12]
str_values=putools.num.num2stre(values_list,digits=3,delimeter=', ')
fid.write(str_values + '\n')
#fid.write('**' + '\n')
#%%
def beammember(fid,coord1,coord2,nset,elset,node_num_base,el_num_base,n_el=10,max_length=1.0):
'''
Beam member between two points
Arguments
------------
fid: file identifier
coord1: coordinates of start node
coord2: coordinates of end node
nset: string with node set name
elset: string with element set name
node_num_base: base node number for member
el_num_base: base element number for member
n_el: number of elements in member
max_length: max element length (overrides n_el)
Returns
------------
None
'''
coord1=coord1.flatten()
coord2=coord2.flatten()
# Vector along member
t_vec=putools.num.ensurenp(coord2)-putools.num.ensurenp(coord1)
L0=np.linalg.norm(t_vec)
# Determine number of elements
if (n_el is None):
n_el=np.ceil(L0/max_length)
elif max_length is not None:
# If n_el is specified then use it as a miniumum, else use only length
if n_el is not None:
n_el=np.max([n_el,np.ceil(L0/max_length)])
elif n_el is None:
n_el=np.ceil(L0/max_length)
n_node=n_el-1
x=np.linspace(coord1[0],coord2[0],n_node)
y=np.linspace(coord1[1],coord2[1],n_node)
z=np.linspace(coord1[2],coord2[2],n_node)
node_num=np.arange(1,n_node+1)+node_num_base
el_num=np.arange(1,n_el+1)+el_num_base
node_matrix=np.column_stack((node_num,x,y,z))
el_matrix=np.column_stack((el_num,node_num[0:-1],node_num[1:]))
node(fid,node_matrix,nset)
element(fid,el_matrix,'B31',elset)
return node_matrix, el_matrix
#%%
def beamsection(fid,elset,material,sectiontype,sectionproperties,direction):
'''
*BEAM SECTION
Arguments
------------
fid: file identifier
elset: string with element set
material: string with material name
sectiontype: e.g. 'RECTANGULAR' or 'PIPE'
sectionproperties: array with numbers required for the section type above
direction: array with n1-direction, e.g. [0,1,0]
Returns
------------
None
'''
if isinstance(elset,str):
elset=[elset]
sectionproperties=putools.num.ensurenp(sectionproperties)
direction=putools.num.ensurenp(direction)
for elset_sub in elset:
fid.write('*BEAM SECTION, ELSET=' + elset_sub.upper() + ', MATERIAL=' + material.upper() + ', SECTION=' + sectiontype.upper() + '\n')
putools.txt.writematrix(fid,sectionproperties,5,', ','f')
putools.txt.writematrix(fid,direction,3,', ','f')
fid.write('**' + '\n')
#%%
def beamgeneralsection(fid,elset,density,sectionproperties,direction,materialproperties):
'''
*BEAM GENERAL SECTION
Arguments
------------
fid: file identifier
elset: string with element set name
density: in [kg/m^3]
sectionproperties: [A,I11,I12,I22,It] array with cross section properties
direction: array with n1-direction, e.g. [0,1,0]
materialproperties: [E,G] array with elastic and shear modulus
Returns
------------
None
'''
fid.write('*BEAM GENERAL SECTION, ELSET=' + elset.upper() + ', SECTION=GENERAL, DENSITY=' + putools.num.num2strf(density,3) + '\n')
putools.txt.writematrix(fid,sectionproperties,5,', ','e')
putools.txt.writematrix(fid,direction,3,', ','f')
putools.txt.writematrix(fid,materialproperties,5,', ','e')
fid.write('**' + '\n')
#%%
def boundary(fid,op,nodename,BCmat,partname):
'''
*BOUNDARY
Arguments
------------
fid: file identifier
op: 'MOD' for modified BCs or 'NEW' for new BCs (erase all old)
nodename: string with node set name or array with node numbers
BCmat: array to specificy, e.g. [1,4,0] to set DOF 1,2,3,4 to zero
partname: string with part name
Returns
------------
None
'''
checkarg(op,['MOD','NEW'])
partname_str=''
if len(partname)>0:
partname_str=partname.upper() + '.'
fid.write('*BOUNDARY, OP=' + op.upper() + '\n')
if isinstance(nodename,str):
nodename=[nodename]
if putools.num.isnumeric(nodename):
nodename=putools.num.ensurenp(nodename)
for k in nodename:
fid.write(partname_str + str(nodename[k]) + ',' + str(BCmat[0]) + ',' + str(BCmat[1]) + ',' + str(BCmat[2]) + '\n')
elif isinstance(nodename,list):
for node in nodename:
fid.write(partname_str + str(node) + ',' + str(BCmat[0]) + ',' + str(BCmat[1]) + ',' + str(BCmat[2]) + '\n')
fid.write('**' + '\n')
fid.write('**' + '\n')
#%%
def checkarg(a_str,arg_allowed):
'''
Check allowable arguments
Arguments
------------
a_str: string with argument to check
arg_allowed: string or list with arguments that are allowed
Returns
------------
None
'''
if isinstance(arg_allowed,str):
arg_allowed=[arg_allowed]
correct_arg=False
for arg in arg_allowed:
if a_str.upper()==arg.upper():
correct_arg=True
if correct_arg==False:
exc_str='Argument ' + a_str + ' not allowed, argument must be '
for arg in arg_allowed:
exc_str=exc_str + arg.upper() + ' or '
exc_str=exc_str[:-4]
raise Exception(exc_str)
#%%
def cload(fid,op,nset,dof,magnitude_force,partname=''):
'''
*CLOAD
Arguments
------------
fid: file identifier
op: 'MOD' for modified CLOADS or 'NEW' for new CLOADS (erase all old)
nset: string with node set name or array with node numbers
dof: DOF number between 1 and 6
magnitude_force: signed force magnitude
Returns
------------
None
'''
checkarg(op,['MOD','NEW','DELETE'])
partname_str=''
if len(partname)>0:
partname_str=partname.upper() + '.'
if op.casefold()=='DELETE':
fid.write('*CLOAD, OP=NEW' + '\n')
fid.write('**' + '\n')
return
fid.write('*CLOAD, OP=' + op.upper() + '\n')
magnitude_force=putools.num.ensurenp(magnitude_force)
if isinstance(nset,str):
nset=[nset]
magnitude_force=np.atleast_1d(magnitude_force)
if np.shape(magnitude_force)==(1,):
magnitude_force=magnitude_force*np.ones(len(nset))
if putools.num.isnumeric(nset):
for k in np.arange(len(nset)):
fid.write( partname_str + str(nset[k]) + ', ' + str(int(dof)) + ', ' + putools.num.num2stre(magnitude_force[k],3) + '\n')
elif isinstance(nset,list):
for k in np.arange(len(nset)):
fid.write( partname_str + nset[k] + ', ' + str(int(dof)) + ', ' + putools.num.num2stre(magnitude_force[k],3) + '\n')
fid.write('**' + '\n')
#fid.write('**' + '\n')
#%%
def comment(fid,comment_str,logic_main=False):
'''
Add comment to input file
Arguments
------------
fid: file identifier
comment_str: string or list with comments
logic_main: many or few stars
Returns
------------
None
'''
if logic_main==True:
separatator='***********************************************************'
else:
separatator='**********'
if isinstance(comment_str,str):
comment_str=[comment_str]
fid.write(separatator + '\n')
for comment_sub in comment_str:
fid.write('** ' + comment_sub + '\n')
fid.write(separatator + '\n')
#%%
def dload(fid,op,elset,type_id,magnitude):
'''
*DLOAD
Arguments
------------
fid: file identifier
op: 'MOD' for modified DLOADS or 'NEW' for new DLOADS (erase all old)
elset: name of element set
type_id: load type, e.g. PZ for line load in z-direction
magnitude: signed load magnitude
Returns
------------
None
'''
checkarg(op,['MOD','NEW','DELETE'])
if op.upper()=='DELETE':
fid.write('*DLOAD, OP=NEW' + '\n')
fid.write('**' + '\n')
fid.write('**' + '\n')
return
if isinstance(magnitude,str):
magnitude_str=magnitude
elif putools.num.isnumeric(magnitude):
magnitude_str=putools.num.num2stre(magnitude)
fid.write('*DLOAD, OP=' + op.upper() + '\n')
fid.write( elset + ', ' + type_id + ', ' + magnitude_str + '\n')
fid.write('**' + '\n')
#fid.write('**' + '\n')
#%%
def element(fid,element_nodenumber,element_type,elsetname,star=True):
'''
*ELEMENT
Arguments
------------
fid: file identifier
element_nodenumber: array with rows [el_num,node_num1,node_num2]
element_type: element type, e.g. B31
elsetname: string with name
Returns
------------
None
'''
element_nodenumber=putools.num.ensurenp(element_nodenumber)
element_nodenumber=np.atleast_2d(element_nodenumber)
id_neg=element_nodenumber<=0
n_neg=np.sum(np.sum(id_neg))
if n_neg>0:
print('***** For ELSET ' + elsetname)
raise Exception('***** Negative element or node number' )
if element_type=='B31' or element_type=='B33':
if np.shape(element_nodenumber)[1]!=3:
print('***** For ELSET ' + elsetname)
raise Exception('***** B31 or B33 must have 2 nodes')
if element_type=='B32':
if np.shape(element_nodenumber)[1]!=4:
print('***** For ELSET ' + elsetname)
raise Exception('***** B32 must have 3 nodes')
fid.write('*ELEMENT, TYPE=' + element_type.upper() + ', ELSET=' + elsetname.upper() + '\n')
putools.txt.writematrix(fid,element_nodenumber,'',', ','int')
if star==True:
fid.write('**' + '\n')
fid.write('**' + '\n')
#%%
def fieldoutput(fid,id_type,variables,set_id='',options=''):
'''
*FIELD OUTPUT
Arguments
------------
fid: file identifier
id_type: 'NODE' or 'ELEMENT'
variables: response quantity, e.g. U or SF
set_id: name of nodeset or elset
Returns
------------
None
'''
comma=', '
if len(options)<=1:
comma=''
options=''
fid.write('*OUTPUT, FIELD' + comma + options.upper() + '\n')
if id_type.upper()=='NODE':
if not set_id:
fid.write('*NODE OUTPUT \n')
else:
fid.write('*NODE OUTPUT, NSET=' + set_id.upper() + '\n')
elif id_type.upper()=='ELEMENT':
if not set_id:
fid.write('*ELEMENT OUTPUT \n')
else:
fid.write('*ELEMENT OUTPUT, ELSET=' + set_id.upper() + '\n')
if isinstance(variables,str):
variables=[variables]
for variables_sub in variables:
fid.write(variables_sub + '\n')
fid.write('**' + '\n')
#%%
def elset(fid,elsetname,elements,option=''):
'''
*ELSET
Arguments
------------
fid: file identifier
elsetname: string with name
elements: element numbers or list of strings to include in elset
Returns
------------
None
'''
fid.write('*ELSET, ELSET=' + elsetname.upper() + '\n')
if isinstance(elements,str):
elements=[elements]
if putools.num.isnumeric(elements):
elements=np.atleast_1d(putools.num.ensurenp(elements))
bins=putools.num.rangebin(len(elements),16)
for bins_sub in bins:
putools.txt.writematrix(fid,elements[bins_sub],'',',','int')
else:
for elements_sub in elements:
fid.write(elements_sub.upper() + '\n')
fid.write('**' + '\n')
fid.write('**' + '\n')
#%%
def frequency(fid,n_modes,normalization='DISPLACEMENT'):
'''
*FREQUENCY
Arguments
------------
fid: file identifier
n_modes: number of modes
normalization: 'DISPLACEMENT' or 'MASS'
Returns
------------
None
'''
if normalization.upper()=='MASS':
norm='MASS'
comma=''
options=''
else:
norm='DISPLACEMENT'
comma=', '
options='SIM=NO'
fid.write('*FREQUENCY, NORMALIZATION=' + norm + comma + options + '\n')
fid.write(str(n_modes) + '\n')
fid.write('**' + '\n')
fid.write('**' + '\n')
#%%
def getcoord(nodes,node_matrix):
nodes=putools.num.ensure_1d_list(nodes)
coord=np.zeros((len(nodes),3))
for k in np.arange(len(nodes)):
idx=np.where(node_matrix[:,0]==int(nodes[k]))[0][0]
coord[k,:]=node_matrix[idx,1:]
return coord
#%%
def gravload(fid,op,elset,magnitude=9.81,direction='z',partname=''):
'''
Gravity load through *DLOAD
Arguments
------------
fid: file identifier
op: 'MOD' or 'NEW'
elset: element set
magnitude: gravitational constant
direction: 'x','y', or 'z'
partname: name of part
Returns
------------
None
'''
partname_str=''
if len(partname)>0:
partname_str=partname.upper() + '.'
checkarg(op,['MOD','NEW'])
checkarg(direction,['x','y','z'])
fid.write('*DLOAD, OP=' + op.upper() + '\n')
if isinstance(elset,str):
elset=[elset]
if magnitude<0:
print('***** Gravity magnitude should generally be positive: magnitude 9.81 and direction [0 0 -1]')
if direction=='x':
direction_str=' -1 , 0, 0'
elif direction=='y':
direction_str=' 0 , -1, 0'
elif direction=='z':
direction_str=' 0 , 0, -1'
for elset_sub in elset:
fid.write(partname_str + elset_sub.upper() + ', GRAV, ' + putools.num.num2strf(magnitude,5) + ',' + direction_str + '\n')
fid.write('**' + '\n')
#%%
def historyoutput(fid,options=''):
'''
*OUTPUT, HISTORY
Arguments
------------
fid: file identifier
options:
Returns
------------
None
'''
comma=', '
if len(options)<=1:
comma=''
options=''
fid.write('*OUTPUT, HISTORY' + comma + options.upper() + '\n')
#%%
def historyoutputelement(fid,variables,elset,options=''):
'''
*ELEMENT OUTPUT
Arguments
------------
fid: file identifier
variables: response quantity, e.g. SF
elset: string with element name
Returns
------------
None
'''
fid.write('*ELEMENT OUTPUT, ELSET=' + elset + '\n')
if isinstance(variables,str):
variables=[variables]
for variables_sub in variables:
fid.write(variables_sub + '\n')
fid.write('**' + '\n')
#%%
def historyoutputnode(fid,variables,nset,options=''):
'''
*NODE OUTPUT
Arguments
------------
fid: file identifier
variables: response quantity, e.g. 'U'
nset: string with node name
Returns
------------
None
'''
fid.write('*NODE OUTPUT, NSET=' + nset + '\n')
if isinstance(variables,str):
variables=[variables]
for variables_sub in variables:
fid.write(variables_sub + '\n')
fid.write('**' + '\n')
#%%
def include(fid,filename):
'''
*INCLUDE
Arguments
------------
fid: file identifier
filename: string with name of inp file
Returns
------------
None
'''
fid.write('**' + '\n')
fid.write('*INCLUDE, INPUT=' + filename + '\n')
fid.write('**' + '\n')
#%%
def instance(fid,instancename,partname):
'''
*INSTANCE
Arguments
------------
fid: file identifier
instancename: string with instance
partname: string with part
Returns
------------
None
'''
fid.write('*INSTANCE, NAME=' + instancename.upper() + ', PART=' + partname.upper() + '\n')
fid.write('**' + '\n')
#%%
def instanceend(fid):
'''
*END INSTANCE
Arguments
------------
fid: file identifier
Returns
------------
None
'''
fid.write('*END INSTANCE' + '\n')
fid.write('**' + '\n')
#%%
def line(fid,line):
'''
Write line(s) of code in input file
Arguments
------------
fid: file identifier
line: string or list with lines to write to file
Returns
------------
None
'''
if isinstance(line,str):
line=[line]
for line_sub in line:
fid.write(line_sub + '\n')
#%%
def material(fid,materialname,E,v,density,alpha=None):
'''
*MATERIAL
Arguments
------------
fid: file identifier
materialname: string with name
E: elastic modulus in [Pa]
v: Poisson ratio
density: in [kg/m^3]
Returns
------------
None
'''
fid.write('*MATERIAL, NAME=' + materialname.upper() + '\n')
fid.write('*ELASTIC' + '\n')
putools.txt.writematrix(fid,[E,v],3,', ',['e' , 'f'])
fid.write('*DENSITY' + '\n')
putools.txt.writematrix(fid,[density],3,', ',['e'])
if alpha is not None:
fid.write('*EXPANSION' + '\n')
putools.txt.writematrix(fid,[alpha],3,', ',['e'])
fid.write('**' + '\n')
fid.write('**' + '\n')
#%%
def memberjointc(fid,node1,node2,coord1,coord2,node_num_base,el_num_base,element_type,setname,n1,kj1,kj2,offset1=0,offset2=0,n_el=10,max_length=None):
'''
Beam member with user-defined stiffness at member joints
N1 J1 MemberEl1 MemberEl2 MemberEl3 MemberEl4 MemberEl5 J2 N2
O~~~~~~O------------o-------------o------------o------------o------------O~~~~~~O
Arguments
------------
fid: file identifier
node1: (super)node number at joint 1
node2: (super)node number at joint 2
coord1: coordinates of node 1
coord2: coordinates of node 2
node_num_base: base node number for member
el_num_base: base element number for member
element_type: element type, e.g. B31
setname: name for member
n1: array with n1-direction, e.g. [0,1,0]
kj1: [kx,ky,kz,krx,kry,krz] array with 6 spring stiffnesses in [N/m] and [Nm/rad] for joint 1
kj2: [kx,ky,kz,krx,kry,krz] array with 6 spring stiffnesses in [N/m] and [Nm/rad] for joint 2
offset1: eccentricity offset of member end 1 in [m]
offset2: eccentricity offset of member end 2 in [m]
n_el: number of elements in member
max_length: max element length (overrides n_el)
Returns
------------
None
'''
setname=setname.upper()
comment(fid,'Member ' + setname)
if el_num_base is None:
el_num_base=node_num_base
# Joint stiffness
kj1=putools.num.ensurenp(kj1)
kj2=putools.num.ensurenp(kj2)
# Only allow 2-node elements
checkarg(element_type,['B31','B33'])
if any(kj1<0):
raise Exception('***** kj1 is negative for set ' + setname)
if any(kj2<0):
raise Exception('***** kj2 is negative for set ' + setname)
if offset1<0:
raise Exception('***** offset1 is negative for set ' + setname)
if offset2<0:
raise Exception('***** offset2 is negative for set ' + setname)
if all(kj1==0):
warnings.warn('***** kj1 is all zero for set ' + setname, stacklevel=2)
if all(kj2==0):
warnings.warn('***** kj2 is all zero for set ' + setname, stacklevel=2)
# if any(kj1>1e36) and not all(kj1>1e36):
# raise Exception('***** kj1 is too large for set ' + setname)
# if any(kj2>1e36) and not all(kj2>1e36):
# raise Exception('***** kj2 is too large for set ' + setname)
# Vector for n1-direction (lateral)
n1=putools.num.ensurenp(n1)
n1=n1/np.linalg.norm(n1)
coord1=coord1.flatten()
coord2=coord2.flatten()
# Vector along member
t_vec=putools.num.ensurenp(coord2)-putools.num.ensurenp(coord1)
L0=np.linalg.norm(t_vec)
t_vec=t_vec/L0
n1_tmp=n1
n2=np.cross(t_vec,n1_tmp)
n1=np.cross(n2,t_vec)
if all(np.abs(t_vec)<1e-12):
raise Exception('***** t_vec is zero for set ' + setname)
if all(np.abs(n1)<1e-12):
raise Exception('***** n1 is zero for set ' + setname)
if all(np.abs(n2)<1e-12):
raise Exception('***** n2 is zero for set ' + setname)
if L0==0:
raise Exception('***** L0 is zero for set ' + setname)
# If kj stiffnesses are all inf, the member is continuous and therefore
# instead directly linked to the supernode, the offset is thus ignored
# In the future, this should be replaced by an input argument instead
inf_threshold=1e36
if all(kj1>inf_threshold):
J1_cont=True
offset1=0
else:
J1_cont=False
if all(kj2>inf_threshold):
J2_cont=True
offset2=0
else:
J2_cont=False
# Shorten member by offset
if offset1>0:
coord1=coord1+t_vec*offset1
if offset2>0:
coord2=coord2-t_vec*offset2
# Determine number of elements
if (n_el is None):