-
Notifications
You must be signed in to change notification settings - Fork 92
/
section.py
5185 lines (4165 loc) · 194 KB
/
section.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
from typing import List, Union, Optional, Tuple
import copy
from dataclasses import dataclass, asdict
import warnings
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import matplotlib.cm as cm
import matplotlib.patches as mpatches
from matplotlib.colors import ListedColormap, CenteredNorm
from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
from rich.console import Console
from rich.text import Text
from rich.live import Live
from rich.table import Table
from rich.panel import Panel
from rich.progress import Progress
import numpy as np
from scipy.sparse import csc_matrix, coo_matrix, linalg
from scipy.optimize import brentq
import sectionproperties.pre.pre as pre
import sectionproperties.pre.geometry as section_geometry
import sectionproperties.analysis.fea as fea
import sectionproperties.analysis.solver as solver
import sectionproperties.post.post as post
from shapely.geometry import Polygon
from shapely.strtree import STRtree
from shapely.geometry import Point
class Section:
"""Class for structural cross-sections.
Stores the finite element geometry, mesh and material information and provides methods to
compute the cross-section properties. The element type used in this program is the six-noded
quadratic triangular element.
The constructor extracts information from the provided mesh object and creates and stores the
corresponding Tri6 finite element objects.
:param geometry: Cross-section geometry object used to generate the mesh
:type geometry: :class:`~sectionproperties.pre.geometry.Geometry`
:param bool time_info: If set to True, a detailed description of the computation and the time
cost is printed to the terminal for every computation performed.
The following example creates a :class:`~sectionproperties.analysis.section.Section`
object of a 100D x 50W rectangle using a mesh size of 5::
import sectionproperties.pre.library.primitive_sections as primitive_sections
from sectionproperties.analysis.section import Section
geometry = primitive_sections.rectangular_section(d=100, b=50)
geometry.create_mesh(mesh_sizes=[5])
section = Section(geometry)
:cvar elements: List of finite element objects describing the cross-section mesh
:vartype elements: list[:class:`~sectionproperties.analysis.fea.Tri6`]
:cvar int num_nodes: Number of nodes in the finite element mesh
:cvar geometry: Cross-section geometry object used to generate the mesh
:vartype geometry: :class:`~sectionproperties.pre.geometry.Geometry`
:cvar mesh: Mesh dict returned by triangle
:vartype mesh: dict(mesh)
:cvar mesh_nodes: Array of node coordinates from the mesh
:vartype mesh_nodes: :class:`numpy.ndarray`
:cvar mesh_elements: Array of connectivities from the mesh
:vartype mesh_elements: :class:`numpy.ndarray`
:cvar mesh_attributes: Array of attributes from the mesh
:vartype mesh_attributes: :class:`numpy.ndarray`
:cvar materials: List of materials
:type materials: list[:class:`~sectionproperties.pre.pre.Material`]
:cvar material_groups: List of objects containing the elements in each defined material
:type material_groups: list[:class:`~sectionproperties.pre.pre.MaterialGroup`]
:cvar section_props: Class to store calculated section properties
:vartype section_props: :class:`~sectionproperties.analysis.section.SectionProperties`
:raises AssertionError: If the number of materials does not equal the number of regions
:raises ValueError: If geometry does not contain a mesh
"""
def __init__(
self,
geometry: Union[section_geometry.Geometry, section_geometry.CompoundGeometry],
time_info: bool = False,
):
"""Inits the Section class."""
if not hasattr(geometry, "mesh") or not geometry.mesh:
raise ValueError(
"Selected Geometry or CompoundGeometry "
"object does not contain a mesh.\n"
"Try running {geometry}.create_mesh() before adding to "
"a Section object for analysis."
)
self.geometry = geometry
self.time_info = time_info
self.mesh = geometry.mesh
self.materials = []
mesh = self.mesh
if isinstance(self.geometry, section_geometry.CompoundGeometry):
self.materials = [geom.material for geom in self.geometry.geoms]
else:
self.materials = [self.geometry.material]
# extract mesh data
nodes = np.array(mesh["vertices"], dtype=np.dtype(float))
elements = np.array(mesh["triangles"], dtype=np.dtype(int))
attributes = np.array(mesh["triangle_attributes"].T[0], dtype=np.dtype(int))
# swap mid-node order to retain node ordering consistency
elements[:, [3, 4, 5]] = elements[:, [5, 3, 4]]
# save total number of nodes in mesh
self.num_nodes = len(nodes)
# initialise material_sections variable
self.material_groups = []
# if materials are specified, check that the right number of material properties are
# specified and then populate material_groups list
if self.materials:
msg = "Number of materials ({0}), ".format(len(self.materials))
msg += "should match the number of regions ({0}).".format(
max(attributes) + 1
)
assert len(self.materials) == max(attributes) + 1, msg
# add a MaterialGroup object to the material_groups list for each uniquely
# encountered material
for (i, material) in enumerate(self.materials):
# add the first material to the list
if i == 0:
self.material_groups.append(MaterialGroup(material, self.num_nodes))
else:
# if the material hasn't been encountered
if material not in self.materials[:i]:
self.material_groups.append(
MaterialGroup(material, self.num_nodes)
)
self.elements = [] # initialise list holding all element objects
# build the mesh one element at a time
for (i, node_ids) in enumerate(elements):
x1 = nodes[node_ids[0]][0]
y1 = nodes[node_ids[0]][1]
x2 = nodes[node_ids[1]][0]
y2 = nodes[node_ids[1]][1]
x3 = nodes[node_ids[2]][0]
y3 = nodes[node_ids[2]][1]
x4 = nodes[node_ids[3]][0]
y4 = nodes[node_ids[3]][1]
x5 = nodes[node_ids[4]][0]
y5 = nodes[node_ids[4]][1]
x6 = nodes[node_ids[5]][0]
y6 = nodes[node_ids[5]][1]
# create a list containing the vertex and mid-node coordinates
coords = np.array([[x1, x2, x3, x4, x5, x6], [y1, y2, y3, y4, y5, y6]])
# if materials are specified, get the material
if self.materials:
# get attribute index of current element
att_el = attributes[i]
# fetch the material
material = self.materials[att_el]
# if there are no materials specified, use a default material
else: # Should not happen but included as failsafe
material = pre.DEFAULT_MATERIAL
# add tri6 elements to the mesh
new_element = fea.Tri6(i, coords, node_ids, material)
self.elements.append(new_element)
# add element to relevant MaterialGroup
for group in self.material_groups:
if material is group.material:
group.add_element(new_element)
break
# save mesh input
self.mesh = mesh
self.mesh_nodes = nodes
self.mesh_elements = elements
self.mesh_attributes = attributes
# create the search tree
p_mesh = [
Polygon(self.geometry.mesh["vertices"][tri][0:3])
for tri in self.geometry.mesh["triangles"]
]
self.poly_mesh_idx = dict((id(poly), i) for i, poly in enumerate(p_mesh))
self.mesh_search_tree = STRtree(p_mesh)
# initialise class storing section properties
self.section_props = SectionProperties()
def calculate_geometric_properties(self):
"""Calculates the geometric properties of the cross-section and stores them in the
:class:`~sectionproperties.analysis.section.SectionProperties` object contained in
the ``section_props`` class variable.
The following geometric section properties are calculated:
* Cross-sectional area
* Cross-sectional perimeter
* Cross-sectional mass
* Area weighted material properties, composite only :math:`E_{eff}`, :math:`G_{eff}`, :math:`{nu}_{eff}`
* Modulus weighted area (axial rigidity)
* First moments of area
* Second moments of area about the global axis
* Second moments of area about the centroidal axis
* Elastic centroid
* Centroidal section moduli
* Radii of gyration
* Principal axis properties
If materials are specified for the cross-section, the moments of area and section moduli
are elastic modulus weighted.
The following example demonstrates the use of this method::
section = Section(geometry)
section.calculate_geometric_properties()
"""
def calculate_geom(progress=None):
# initialise properties
self.section_props.area = 0
self.section_props.perimeter = 0
self.section_props.mass = 0
self.section_props.ea = 0
self.section_props.ga = 0
self.section_props.qx = 0
self.section_props.qy = 0
self.section_props.ixx_g = 0
self.section_props.iyy_g = 0
self.section_props.ixy_g = 0
# calculate perimeter
self.section_props.perimeter = self.geometry.calculate_perimeter()
if progress is not None:
task = progress.add_task(
description="[red]Calculating geometric properties",
total=len(self.elements),
)
# calculate global geometric properties
for el in self.elements:
(
area,
qx,
qy,
ixx_g,
iyy_g,
ixy_g,
e,
g,
rho,
) = el.geometric_properties()
self.section_props.area += area
self.section_props.mass += area * rho
self.section_props.ea += area * e
self.section_props.ga += area * g
self.section_props.qx += qx * e
self.section_props.qy += qy * e
self.section_props.ixx_g += ixx_g * e
self.section_props.iyy_g += iyy_g * e
self.section_props.ixy_g += ixy_g * e
if progress is not None:
progress.update(task, advance=1)
self.section_props.nu_eff = (
self.section_props.ea / (2 * self.section_props.ga) - 1
)
self.section_props.e_eff = self.section_props.ea / self.section_props.area
self.section_props.g_eff = self.section_props.ga / self.section_props.area
self.section_props.calculate_elastic_centroid()
self.section_props.calculate_centroidal_properties(self.mesh)
if progress is not None:
progress.update(
task,
description="[bold green]:white_check_mark: Geometric analysis complete",
)
# conduct geometric analysis
if self.time_info:
progress = solver.create_progress()
progress_table = Table.grid()
panel = Panel.fit(
progress,
title="[bold]Geometric Analysis",
border_style="red",
padding=(1, 1),
)
progress_table.add_row(panel)
with Live(progress_table, refresh_per_second=10) as live:
calculate_geom(progress=progress)
panel.border_style = "green"
live.refresh()
print()
else:
calculate_geom()
def calculate_warping_properties(self, solver_type="direct"):
"""Calculates all the warping properties of the cross-section and stores them in the
:class:`~sectionproperties.analysis.section.SectionProperties` object contained in
the ``section_props`` class variable.
:param string solver_type: Solver used for solving systems of linear equations, either
using the *'direct'* method or *'cgs'* iterative method
The following warping section properties are calculated:
* Torsion constant
* Shear centre
* Shear area
* Warping constant
* Monosymmetry constant
If materials are specified, the values calculated for the torsion constant, warping
constant and shear area are elastic modulus weighted.
Note that the geometric properties must be calculated prior to the calculation of the
warping properties::
section = Section(geometry)
section.calculate_geometric_properties()
section.calculate_warping_properties()
:raises RuntimeError: If the geometric properties have not been
calculated prior to calling this method
"""
# check that a geometric analysis has been performed
if None in [
self.section_props.area,
self.section_props.ixx_c,
self.section_props.cx,
]:
err = "Calculate geometric properties before performing a warping analysis."
raise RuntimeError(err)
# check if any geometry are disjoint
if isinstance(self.geometry, section_geometry.CompoundGeometry):
polygons = [sec_geom.geom for sec_geom in self.geometry.geoms]
disjoint_regions = section_geometry.check_geometry_disjoint(polygons)
if disjoint_regions:
warnings.warn(
"\nThe section geometry contains disjoint regions which is invalid for warping analysis.\n"
"Please revise your geometry to ensure there is connectivity between all regions.\n"
"Please see https://sectionproperties.readthedocs.io/en/latest/rst/analysis.html#warping-analysis for more "
"information."
)
# create a new Section with the origin shifted to the centroid for calculation of the
# warping properties such that the Lagrangian multiplier approach can be utilised
warping_section = Section(self.geometry)
# shift the coordinates of each element N.B. the mesh class attribute remains unshifted!
for el in warping_section.elements:
el.coords[0, :] -= self.section_props.cx
el.coords[1, :] -= self.section_props.cy
# entire warping analysis is contained in following definition
def warping_analysis(progress=None):
# assemble stiffness matrix and load vector for warping function
if progress:
task = progress.add_task(
description="[red]Assembling {0}x{0} stiffness matrix".format(
self.num_nodes
),
total=len(warping_section.elements),
)
(k_lg, f_torsion) = warping_section.assemble_torsion(
progress=progress, task=task
)
progress.update(
task,
description="[green]:white_check_mark: {0}x{0} stiffness matrix assembled".format(
self.num_nodes
),
)
progress.update(0, advance=1)
else:
(k_lg, f_torsion) = warping_section.assemble_torsion()
# ILU decomposition of stiffness matrices
def ilu_decomp(progress=None, task=None):
# ILU decomposition on regular stiffness matrix
k_precond = linalg.LinearOperator(
(self.num_nodes, self.num_nodes), linalg.spilu(k).solve
)
if progress is not None:
progress.update(task, advance=1)
# ILU decomposition on Lagrangian stiffness matrix
k_lg_precond = linalg.LinearOperator(
(self.num_nodes + 1, self.num_nodes + 1), linalg.spilu(k_lg).solve
)
if progress is not None:
progress.update(task, advance=1)
return (k_precond, k_lg_precond)
# if the cgs method is used, perform ILU decomposition
if solver_type == "cgs":
if progress:
task = progress.add_task(
description="[red]Performing ILU decomposition",
total=2,
)
(k_precond, k_lg_precond) = ilu_decomp(progress=progress, task=task)
progress.update(
task,
description="[green]:white_check_mark: ILU decomposition complete",
)
else:
(k_precond, k_lg_precond) = ilu_decomp()
# solve for warping function
def solve_warping():
if solver_type == "cgs":
omega = solver.solve_cgs_lagrange(k_lg, f_torsion, m=k_lg_precond)
elif solver_type == "direct":
omega = solver.solve_direct_lagrange(k_lg, f_torsion)
return omega
if progress:
task = progress.add_task(
description="[red]Solving warping function ({0})".format(
solver_type
),
total=1,
)
omega = solve_warping()
progress.update(task, advance=1)
progress.update(
task,
description="[green]:white_check_mark: Warping function solved ({0})".format(
solver_type
),
)
progress.update(0, advance=1)
else:
omega = solve_warping()
# save the warping function
self.section_props.omega = omega
# determine the torsion constant
self.section_props.j = (
self.section_props.ixx_c
+ self.section_props.iyy_c
- omega.dot(k_lg[:-1, :-1].dot(np.transpose(omega)))
)
# assemble shear function load vectors
def assemble_shear_load(progress=None, task=None):
f_psi = np.zeros(self.num_nodes)
f_phi = np.zeros(self.num_nodes)
for el in warping_section.elements:
(f_psi_el, f_phi_el) = el.shear_load_vectors(
self.section_props.ixx_c,
self.section_props.iyy_c,
self.section_props.ixy_c,
self.section_props.nu_eff,
)
f_psi[el.node_ids] += f_psi_el
f_phi[el.node_ids] += f_phi_el
if progress is not None:
progress.update(task, advance=1)
return (f_psi, f_phi)
if progress:
task = progress.add_task(
description="[red]Assembling shear function vectors",
total=len(warping_section.elements),
)
(f_psi, f_phi) = assemble_shear_load(progress=progress, task=task)
progress.update(
task,
description="[green]:white_check_mark: Shear function vectors assembled",
)
progress.update(0, advance=1)
else:
(f_psi, f_phi) = assemble_shear_load()
# solve for shear functions psi and phi
def solve_shear_functions(progress=None, task=None):
if solver_type == "cgs":
psi_shear = solver.solve_cgs_lagrange(k_lg, f_psi, m=k_lg_precond)
if progress is not None:
progress.update(task, advance=1)
phi_shear = solver.solve_cgs_lagrange(k_lg, f_phi, m=k_lg_precond)
if progress is not None:
progress.update(task, advance=1)
elif solver_type == "direct":
psi_shear = solver.solve_direct_lagrange(k_lg, f_psi)
if progress is not None:
progress.update(task, advance=1)
phi_shear = solver.solve_direct_lagrange(k_lg, f_phi)
if progress is not None:
progress.update(task, advance=1)
return (psi_shear, phi_shear)
if progress:
task = progress.add_task(
description="[red]Solving shear functions ({0})".format(
solver_type
),
total=2,
)
(psi_shear, phi_shear) = solve_shear_functions(
progress=progress, task=task
)
progress.update(
task,
description="[green]:white_check_mark: Shear functions solved ({0})".format(
solver_type
),
)
progress.update(0, advance=1)
else:
(psi_shear, phi_shear) = solve_shear_functions()
# save the shear functions
self.section_props.psi_shear = psi_shear
self.section_props.phi_shear = phi_shear
# assemble shear centre and warping moment integrals
def assemble_sc_warping_integrals(progress=None, task=None):
sc_xint = 0
sc_yint = 0
q_omega = 0
i_omega = 0
i_xomega = 0
i_yomega = 0
for el in warping_section.elements:
(
sc_xint_el,
sc_yint_el,
q_omega_el,
i_omega_el,
i_xomega_el,
i_yomega_el,
) = el.shear_warping_integrals(
self.section_props.ixx_c,
self.section_props.iyy_c,
self.section_props.ixy_c,
omega[el.node_ids],
)
sc_xint += sc_xint_el
sc_yint += sc_yint_el
q_omega += q_omega_el
i_omega += i_omega_el
i_xomega += i_xomega_el
i_yomega += i_yomega_el
if progress is not None:
progress.update(task, advance=1)
return (sc_xint, sc_yint, q_omega, i_omega, i_xomega, i_yomega)
if progress:
task = progress.add_task(
description="[red]Assembling shear and warping integrals",
total=len(warping_section.elements),
)
(
sc_xint,
sc_yint,
q_omega,
i_omega,
i_xomega,
i_yomega,
) = assemble_sc_warping_integrals(progress=progress, task=task)
progress.update(
task,
description="[green]:white_check_mark: Shear and warping integrals assembled",
)
progress.update(0, advance=1)
else:
(
sc_xint,
sc_yint,
q_omega,
i_omega,
i_xomega,
i_yomega,
) = assemble_sc_warping_integrals()
# calculate shear centres (elasticity approach)
Delta_s = (
2
* (1 + self.section_props.nu_eff)
* (
self.section_props.ixx_c * self.section_props.iyy_c
- self.section_props.ixy_c**2
)
)
x_se = (1 / Delta_s) * (
(self.section_props.nu_eff / 2 * sc_xint) - f_torsion.dot(phi_shear)
)
y_se = (1 / Delta_s) * (
(self.section_props.nu_eff / 2 * sc_yint) + f_torsion.dot(psi_shear)
)
(x11_se, y22_se) = fea.principal_coordinate(
self.section_props.phi, x_se, y_se
)
# calculate shear centres (Trefftz's approach)
x_st = (
self.section_props.ixy_c * i_xomega
- self.section_props.iyy_c * i_yomega
) / (
self.section_props.ixx_c * self.section_props.iyy_c
- self.section_props.ixy_c**2
)
y_st = (
self.section_props.ixx_c * i_xomega
- self.section_props.ixy_c * i_yomega
) / (
self.section_props.ixx_c * self.section_props.iyy_c
- self.section_props.ixy_c**2
)
# save shear centres
self.section_props.Delta_s = Delta_s
self.section_props.x_se = x_se
self.section_props.y_se = y_se
self.section_props.x11_se = x11_se
self.section_props.y22_se = y22_se
self.section_props.x_st = x_st
self.section_props.y_st = y_st
# calculate warping constant
self.section_props.gamma = (
i_omega
- q_omega**2 / self.section_props.ea
- y_se * i_xomega
+ x_se * i_yomega
)
def assemble_shear_deformation(progress=None, task=None):
# assemble shear deformation coefficients
kappa_x = 0
kappa_y = 0
kappa_xy = 0
for el in warping_section.elements:
(kappa_x_el, kappa_y_el, kappa_xy_el) = el.shear_coefficients(
self.section_props.ixx_c,
self.section_props.iyy_c,
self.section_props.ixy_c,
psi_shear[el.node_ids],
phi_shear[el.node_ids],
self.section_props.nu_eff,
)
kappa_x += kappa_x_el
kappa_y += kappa_y_el
kappa_xy += kappa_xy_el
if progress is not None:
progress.update(task, advance=1)
return (kappa_x, kappa_y, kappa_xy)
if progress:
task = progress.add_task(
description="[red]Assembling shear deformation coefficients",
total=len(warping_section.elements),
)
(kappa_x, kappa_y, kappa_xy) = assemble_shear_deformation(
progress=progress, task=task
)
progress.update(
task,
description="[green]:white_check_mark: Shear deformation coefficients assembled",
)
progress.update(0, advance=1)
else:
(kappa_x, kappa_y, kappa_xy) = assemble_shear_deformation()
# calculate shear areas wrt global axis
self.section_props.A_sx = Delta_s**2 / kappa_x
self.section_props.A_sy = Delta_s**2 / kappa_y
self.section_props.A_sxy = Delta_s**2 / kappa_xy
# calculate shear areas wrt principal bending axis:
alpha_xx = kappa_x * self.section_props.area / Delta_s**2
alpha_yy = kappa_y * self.section_props.area / Delta_s**2
alpha_xy = kappa_xy * self.section_props.area / Delta_s**2
# rotate the tensor by the principal axis angle
phi_rad = self.section_props.phi * np.pi / 180
R = np.array(
[
[np.cos(phi_rad), np.sin(phi_rad)],
[-np.sin(phi_rad), np.cos(phi_rad)],
]
)
rotatedAlpha = R.dot(
np.array([[alpha_xx, alpha_xy], [alpha_xy, alpha_yy]])
).dot(np.transpose(R))
# recalculate the shear area based on the rotated alpha value
self.section_props.A_s11 = self.section_props.area / rotatedAlpha[0, 0]
self.section_props.A_s22 = self.section_props.area / rotatedAlpha[1, 1]
# calculate the monosymmetry consants
def calculate_monosymmetry_integrals(progress=None, task=None):
int_x = 0
int_y = 0
int_11 = 0
int_22 = 0
for el in warping_section.elements:
(
int_x_el,
int_y_el,
int_11_el,
int_22_el,
) = el.monosymmetry_integrals(self.section_props.phi)
int_x += int_x_el
int_y += int_y_el
int_11 += int_11_el
int_22 += int_22_el
if progress is not None:
progress.update(task, advance=1)
return (int_x, int_y, int_11, int_22)
if progress:
task = progress.add_task(
description="[red]Assembling monosymmetry integrals",
total=len(self.elements),
)
(int_x, int_y, int_11, int_22) = calculate_monosymmetry_integrals(
progress=progress, task=task
)
progress.update(
task,
description="[green]:white_check_mark: Monosymmetry integrals assembled",
)
progress.update(0, advance=1)
else:
(int_x, int_y, int_11, int_22) = calculate_monosymmetry_integrals()
# calculate the monosymmetry constants
self.section_props.beta_x_plus = (
-int_x / self.section_props.ixx_c + 2 * self.section_props.y_se
)
self.section_props.beta_x_minus = (
int_x / self.section_props.ixx_c - 2 * self.section_props.y_se
)
self.section_props.beta_y_plus = (
-int_y / self.section_props.iyy_c + 2 * self.section_props.x_se
)
self.section_props.beta_y_minus = (
int_y / self.section_props.iyy_c - 2 * self.section_props.x_se
)
self.section_props.beta_11_plus = (
-int_11 / self.section_props.i11_c + 2 * self.section_props.y22_se
)
self.section_props.beta_11_minus = (
int_11 / self.section_props.i11_c - 2 * self.section_props.y22_se
)
self.section_props.beta_22_plus = (
-int_22 / self.section_props.i22_c + 2 * self.section_props.x11_se
)
self.section_props.beta_22_minus = (
int_22 / self.section_props.i22_c - 2 * self.section_props.x11_se
)
# conduct warping analysis
if self.time_info:
# create warping progress
progress = solver.create_progress()
total_task = progress.add_task(
description="[bold red]Conducting warping analysis...", total=7
)
progress_table = Table.grid()
panel = Panel.fit(
progress,
title="[bold]Warping Analysis",
border_style="red",
padding=(1, 1),
)
progress_table.add_row(panel)
with Live(progress_table, refresh_per_second=10) as live:
warping_analysis(progress)
progress.update(
total_task,
description="[bold green]:white_check_mark: Warping analysis completed",
)
panel.border_style = "green"
live.refresh()
print()
else:
warping_analysis()
def calculate_frame_properties(self, solver_type="direct"):
"""Calculates and returns the properties required for a frame analysis. The properties are
also stored in the :class:`~sectionproperties.analysis.section.SectionProperties`
object contained in the ``section_props`` class variable.
:param string solver_type: Solver used for solving systems of linear equations, either
using the *'direct'* method or *'cgs'* iterative method
:return: Cross-section properties to be used for a frame analysis *(area, ixx, iyy, ixy, j,
phi)*
:rtype: tuple(float, float, float, float, float, float)
The following section properties are calculated:
* Cross-sectional area *(area)*
* Second moments of area about the centroidal axis *(ixx, iyy, ixy)*
* Torsion constant *(j)*
* Principal axis angle *(phi)*
If materials are specified for the cross-section, the area, second moments of area and
torsion constant are elastic modulus weighted.
The following example demonstrates the use of this method::
section = Section(geometry)
(area, ixx, iyy, ixy, j, phi) = section.calculate_frame_properties()
"""
# initialise geometric properties
self.section_props.area = 0
self.section_props.ea = 0
self.section_props.qx = 0
self.section_props.qy = 0
self.section_props.ixx_g = 0
self.section_props.iyy_g = 0
self.section_props.ixy_g = 0
self.section_props.ixx_c = 0
self.section_props.iyy_c = 0
self.section_props.ixy_c = 0
self.section_props.j = 0
self.section_props.phi = 0
# calculate global geometric properties
for el in self.elements:
(area, qx, qy, ixx_g, iyy_g, ixy_g, e, _, _) = el.geometric_properties()
self.section_props.area += area
self.section_props.ea += area * e
self.section_props.qx += qx * e
self.section_props.qy += qy * e
self.section_props.ixx_g += ixx_g * e
self.section_props.iyy_g += iyy_g * e
self.section_props.ixy_g += ixy_g * e
# calculate elastic centroid location
self.section_props.calculate_elastic_centroid()
# calculate second moments of area about the centroidal xy axis
self.section_props.ixx_c = (
self.section_props.ixx_g
- self.section_props.qx**2 / self.section_props.ea
)
self.section_props.iyy_c = (
self.section_props.iyy_g
- self.section_props.qy**2 / self.section_props.ea
)
self.section_props.ixy_c = (
self.section_props.ixy_g
- self.section_props.qx * self.section_props.qy / self.section_props.ea
)
# calculate the principal axis angle
Delta = (
((self.section_props.ixx_c - self.section_props.iyy_c) / 2) ** 2
+ self.section_props.ixy_c**2
) ** 0.5
i11_c = (self.section_props.ixx_c + self.section_props.iyy_c) / 2 + Delta
# calculate initial principal axis angle
if abs(self.section_props.ixx_c - i11_c) < 1e-12 * i11_c:
self.section_props.phi = 0
else:
self.section_props.phi = (
np.arctan2(self.section_props.ixx_c - i11_c, self.section_props.ixy_c)
* 180
/ np.pi
)
# create a new Section with the origin shifted to the centroid for calculation of
# the warping properties
warping_section = Section(self.geometry)
# shift the coordinates of each element N.B. the mesh class attribute remains unshifted
for el in warping_section.elements:
el.coords[0, :] -= self.section_props.cx
el.coords[1, :] -= self.section_props.cy
(k_lg, f) = warping_section.assemble_torsion()
# if the cgs method is used, perform ILU decomposition
if solver_type == "cgs":
k_lg_precond = linalg.LinearOperator(
(self.num_nodes + 1, self.num_nodes + 1), linalg.spilu(k_lg).solve
)
# solve for warping function
if solver_type == "cgs":
omega = solver.solve_cgs_lagrange(k_lg, f, m=k_lg_precond)
elif solver_type == "direct":
omega = solver.solve_direct_lagrange(k_lg, f)
# calculate the torsion constant
self.section_props.j = (
self.section_props.ixx_c
+ self.section_props.iyy_c
- omega.dot(k_lg[:-1, :-1].dot(np.transpose(omega)))
)
return (
self.section_props.ea,
self.section_props.ixx_c,
self.section_props.iyy_c,
self.section_props.ixy_c,
self.section_props.j,
self.section_props.phi,
)
def calculate_plastic_properties(self, verbose=False):
"""Calculates the plastic properties of the cross-section and stores them in the
:class:`~sectionproperties.analysis.section.SectionProperties` object contained in
the ``section_props`` class variable.
:param bool verbose: If set to True, the number of iterations required for each plastic
axis is printed to the terminal.
The following warping section properties are calculated:
* Plastic centroid for bending about the centroidal and principal axes
* Plastic section moduli for bending about the centroidal and principal axes
* Shape factors for bending about the centroidal and principal axes
If materials are specified for the cross-section, the plastic section moduli are displayed
as plastic moments (i.e :math:`M_p = f_y S`) and the shape factors are not calculated.
Note that the geometric properties must be calculated before the plastic properties are
calculated::
section = Section(geometry)
section.calculate_geometric_properties()
section.calculate_plastic_properties()
:raises RuntimeError: If the geometric properties have not been calculated prior to calling
this method
"""