-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoNodeSpring2D.py
232 lines (187 loc) · 6.38 KB
/
TwoNodeSpring2D.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
# -*- coding: utf-8 -*-
"""author: 周光武、簡子琦"""
from OneNodeSpring2D import OneNodeSpring2D
from Vector import Point, Vector
from numpy import matrix, zeros
from scipy.sparse import dok_matrix
class TwoNodeSpring2D(OneNodeSpring2D):
"""
Abstract object of two node spring element in X-Y plane.
Parameters
----------
id : {Element index, int}
node1 : {Starting Node, Node obj}
node2 : {Ending Node, Node obj}
material : {Spring material, Material obj}
mass : {Spring mass, float}
inertia : {Spring inertia, float}
Returns
-------
out : TwoNodeSpring obj
"""
def __init__(self, id, node1, node2, material, mass, inertia):
super().__init__(id, node1, material, mass, inertia)
self._node2 = node2
self._dofs = [node1.dof(0), node1.dof(1), node1.dof(5),
node2.dof(0), node2.dof(1), node2.dof(5)]
@property
def node2(self):
return self._node2
@property
def length_origin(self):
return self.get_length('pos_origin')
@property
def lumped_mass(self):
mass = dok_matrix((6, 1))
m = self.mass
i = self.inertia
mass[0, 0], mass[1, 0], mass[3, 0], mass[4, 0] = m, m, m, m
mass[2, 0], mass[5, 0] = i, i
return mass
def get_length(self, pos_type):
return self._get_axial_vector(pos_type).length
def get_local_stiffness(self):
return []
def get_global_stiffness(self):
K = self.get_local_stiffness()
self.transform_to_global(K, 'pos_origin')
return K
def get_internal_force(self, dof_type, pos_type):
dofs = dok_matrix((6, 1))
K = self.get_global_stiffness()
for i, dof in enumerate(self.dofs):
dofs[i, 0] = getattr(dof, dof_type)
force = K * dofs
return force
def orient_to_local(self, variable, pos_type):
axial_vector = self._get_axial_vector(pos_type)
x = axial_vector.x
y = axial_vector.y
l = axial_vector.length
c, s = x/l, y/l
v = [n for n in variable]
variable[0] = v[0]*c + v[1]*s
variable[1] = -v[0]*s + v[1]*c
variable[3] = v[3]*c + v[4]*s
variable[4] = -v[3]*s + v[4]*c
def orient_to_global(self, variable, pos_type):
axial_vector = self._get_axial_vector(pos_type)
x = axial_vector.x
y = axial_vector.y
l = axial_vector.length
c, s = x/l, y/l
v = [n for n in variable]
variable[0] = v[0]*c - v[1]*s
variable[1] = v[0]*s + v[1]*c
variable[3] = v[3]*c - v[4]*s
variable[4] = v[3]*s + v[4]*c
def transform_to_global(self, stiffness, pos_type):
axial_vector = self._get_axial_vector(pos_type)
x = axial_vector.x
y = axial_vector.y
l = axial_vector.length
c, s = x/l, y/l
k = stiffness
T = dok_matrix((6, 6))
T[0, 0], T[1, 1], T[3, 3], T[4, 4] = c, c, c, c
T[2, 2], T[5, 5] = 1, 1
T[0, 1], T[3, 4] = s, s
T[1, 0], T[4, 3] = -s, -s
K = T.T*k*T
for i in range(6):
for j in range(6):
stiffness[i, j] = K[i, j]
def _get_axial_vector(self, pos_type):
return Vector(getattr(self.node1, pos_type), getattr(self.node2, pos_type))
def __repr__(self):
return (f'\n{self.__class__.__name__} '
f'id = {self.id}; '
f'node1 = {self.node1.pos.value}; '
f'node2 = {self.node2.pos.value}; '
f'{self.material};')
class TwoNodeAxialSpring2D(TwoNodeSpring2D):
"""
Two node axial spring element object in X-Y plane.
Parameters
----------
id : {Element index, int}
node1 : {Starting Node, Node obj}
node2 : {Ending Node, Node obj}
material : {Spring material, Material obj}
mass : {Spring mass, float}
inertia : {Spring inertia, float}
Returns
-------
out : TwoNodeAxialSpring obj
"""
def get_local_stiffness(self):
k = dok_matrix((6, 6))
stiffness = self.stiffness
k[0, 0], k[3, 3] = stiffness, stiffness
k[0, 3], k[3, 0] = -stiffness, -stiffness
return k
class TwoNodeShearSpring2D(TwoNodeSpring2D):
"""
Two node shear spring element object in X-Y plane.
Parameters
----------
id : {Element index, int}
node1 : {Starting Node, Node obj}
node2 : {Ending Node, Node obj}
material : {Spring material, Material obj}
mass : {Spring mass, float}
inertia : {Spring inertia, float}
loc_ratio : {Shear location ratio, float}
Returns
-------
out : TwoNodeShearSpring obj
"""
def __init__(self, id, node1, node2, material, mass, inertia, loc_ratio = 0.0):
super().__init__(id, node1, node2, material, mass, inertia)
self._shear_location_ratio = loc_ratio
@property
def shear_location_ratio(self):
return self._shear_location_ratio
def get_local_stiffness(self):
stiffness = dok_matrix((6, 6))
k = self.stiffness
l0 = self.length_origin
ls = self.shear_location_ratio * l0
l0s = l0 - ls
A1 = k
A2 = l0s * k
A3 = ls * k
A4 = ls * l0s * k
A5 = l0s**2 * k
A6 = ls**2 * k
stiffness[1, 1], stiffness[4, 4] = A1, A1
stiffness[1, 4], stiffness[4, 1]= -A1, -A1
stiffness[1, 2], stiffness[2, 1] = A2, A2
stiffness[2, 4], stiffness[4, 2] = -A2, -A2
stiffness[1, 5], stiffness[5, 1] = A3, A3
stiffness[4, 5], stiffness[5, 4] = -A3, -A3
stiffness[2, 5], stiffness[5, 2] = A4, A4
stiffness[2, 2] = A5
stiffness[5, 5] = A6
return stiffness
class TwoNodeRotationSpring2D(TwoNodeSpring2D):
"""
Two node rotation spring element object in X-Y plane.
Parameters
----------
id : {Element index, int}
node1 : {Starting Node, Node obj}
node2 : {Ending Node, Node obj}
material : {Spring material, Material obj}
mass : {Spring mass, float}
inertia : {Spring inertia, float}
Returns
-------
out : TwoNodeRotationSpring obj
"""
def get_local_stiffness(self):
k = dok_matrix((6, 6))
stiffness = self.stiffness
k[2, 2], k[5, 5] = stiffness, stiffness
k[2, 5], k[5, 2] = -stiffness, -stiffness
return k