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
|
|
# -*- coding: utf-8 -*-
""" Created on Mon Dec 24 16:45:24 2018
@author: admin """ import os
while True:
ratio = input("enter aspect ratio (default: 0.5, warning possion ratio zero)...\n")
if not ratio:
ratio = 0.5
break
else:
try:
ratio = float(ratio)
if not (ratio <= 1.0 and ratio >= 0):
raise Exception
break
except:
print("input error, try again...")
print("Modeling...")
E = 35e3 # GPa
h = 5 # mm
miu = 0 # possion ratio
Bc = (E*h**3)/(12.0*(1.0-miu**2))
f_pressure = 1e-4 # N/mm^2
L = 1000
W = L*ratio
l = L if (Lelse W
element_num_X = 50
delta_X = L / element_num_X
element_num_Y = 50
delta_Y = W / element_num_Y
ele_area = L*W/(element_num_X*element_num_Y)
# collection of all generated nodes
nodes = [] for j in range(element_num_Y+1):
coor_y = j*delta_Y
for i in range(element_num_X+1):
coor_x = i*delta_X
nodes.append((coor_x,coor_y))
# collection of xy coordinates for drawing mesh
nodes_x = [n[0] for n in nodes]
nodes_y = [n[1] for n in nodes]
# collection of middle, sides, vertex nodes
# nodes_mid_index, one items
# nodes_vertex_indexs, four items
# nodes_left_indexs
# nodes_right_indexs
# nodes_bottom_indexs
# nodes_top_indexs nodes_mid_index = None
for n in nodes:
if n == (L/2,W/2):
nodes_mid_index = nodes.index(n)
break
nodes_vertex_indexs = [] for n in nodes:
if n == (0,0) or n == (L,0) or n == (L,W) or n == (0,W):
nodes_vertex_indexs.append(nodes.index(n))
def delete_vertex_nodes(nodes_list):
temp = set(nodes_list).difference(set(nodes_vertex_indexs))
temp_list = list(temp)
temp_list.sort()
return temp_list
nodes_left_indexs = [] for n in nodes:
if n[0] == 0:
nodes_left_indexs.append(nodes.index(n))
nodes_left_indexs = delete_vertex_nodes(nodes_left_indexs)
nodes_right_indexs = [] for n in nodes:
if n[0] == L:
nodes_right_indexs.append(nodes.index(n))
nodes_right_indexs = delete_vertex_nodes(nodes_right_indexs)
nodes_bottom_indexs = [] for n in nodes:
if n[1] == 0:
nodes_bottom_indexs.append(nodes.index(n))
nodes_bottom_indexs = delete_vertex_nodes(nodes_bottom_indexs)
nodes_top_indexs = [] for n in nodes:
if n[1] == W:
nodes_top_indexs.append(nodes.index(n))
nodes_top_indexs = delete_vertex_nodes(nodes_top_indexs)
# collection of element connectivity
elements = []
elements_has_mid_point = []
ele_index = 0 for j in range(element_num_Y):
for i in range(element_num_X):
index1 = ele_index + j
index2 = index1 + 1
index3 = index2 + element_num_X + 1
index4 = index3 - 1
elements.append((index1,index2,index3,index4))
ele_index += 1
if nodes_mid_index in (index1,index2,index3,index4):
elements_has_mid_point.append((index1,index2,index3,index4))
# now, lets turn to OpenSees
tcl_file = open('./output/co.tcl','wt')
tcl_file.write('wipe\n')
#tcl_file.write('puts "System"\n')
tcl_file.write('model basic -ndm 3 -ndf 6\n')
#tcl_file.write('puts "Nodes"\n')
for n in nodes:
tcl_file.write('node %d %f %f 0.0\n' % (nodes.index(n)+1,n[0],n[1]))
#tcl_file.write('puts "Constraints"\n')
for n_index in set.union(set(nodes_vertex_indexs),set(nodes_left_indexs),set(nodes_right_indexs),set(nodes_bottom_indexs),set(nodes_top_indexs)):
tcl_file.write('fix %d 1 1 1 1 1 1\n' % (n_index+1))
#tcl_file.write('puts "Material"\n')
tcl_file.write('nDMaterial ElasticIsotropic 1 %f %f\n' % (E,miu))
tcl_file.write('nDMaterial PlateFiber 601 1\n')
tcl_file.write('section PlateFiber 701 601 %f\n' % h)
#tcl_file.write('puts "Shell elements"\n')
for n_indexs in elements:
n_indexs1 = [n_indexs[i]+1 for i in range(len(n_indexs))]
tcl_file.write('element ShellMITC4 %d %d %d %d %d 701\n' % (elements.index(n_indexs)+1,*n_indexs1))
#tcl_file.write('puts "recorder"\n')
tcl_file.write('recorder Node -file ./output/node_mid.out -node %d -dof 3 disp\n' % nodes_mid_index)
elements_has_mid_point_indexs_inOpenSees = []
for ele in elements_has_mid_point:
elements_has_mid_point_indexs_inOpenSees.append(elements.index(ele)+1)
tcl_file.write('recorder Element -file ./output/Element.out -ele %d %d %d %d forces\n' % tuple(elements_has_mid_point_indexs_inOpenSees))
#tcl_file.write('puts "loading"\n')
tcl_file.write('pattern Plain 1 Linear {\n')
nodes_side_indexs = set.union(set(nodes_left_indexs),set(nodes_right_indexs),set(nodes_bottom_indexs),set(nodes_top_indexs))
nodes_inner_indexs = set(range(len(nodes))).difference(
set.union(set(nodes_vertex_indexs),nodes_side_indexs)
) for n_index in nodes_inner_indexs:
tcl_file.write('load %d 0.0 0.0 %f 0.0 0.0 0.0\n' % (n_index+1,f_pressure*ele_area))
for n_index in nodes_side_indexs:
tcl_file.write('load %d 0.0 0.0 %f 0.0 0.0 0.0\n' % (n_index+1,f_pressure*ele_area/2))
tcl_file.write('}\n')
tcl_file.write('puts "Analysing..."\n')
tcl_file.write("""constraints Plain numberer Plain
system BandGeneral
test EnergyIncr 1.0e-6 200
algorithm Newton
integrator LoadControl 1.0
analysis Static
analyze 1
puts "Analysis complete..." """)
tcl_file.close()
print("Modeling complete...")
if __name__ == '__main__':
print("="*80)
os.popen(".\\bin\\OpenSees.exe .\\output\\co.tcl",buffering=1).close()
print("="*80)
with open('./output/node_mid.out','tr') as file:
data = file.read()
deflection = float(data)
xishu = deflection*Bc/(f_pressure*l**4)
with open('./output/Element.out','tr') as file:
data = file.read()
forces = data.split()
b1 = [float(i) for i in forces[12:18]]
b2 = [float(i) for i in forces[42:48]]
b3 = [float(i) for i in forces[54:60]]
Mx, My = abs(b1[3] + b2[3]),abs(b1[4] + b3[4])
xishu_Mx = Mx/(f_pressure*l**2)/delta_X
xishu_My = My/(f_pressure*l**2)/delta_Y
print("f:%.6f Mx:%.6f My:%.6f" % (xishu,xishu_Mx,xishu_My))
os.system("pause")
|