-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotter3D.py
187 lines (128 loc) · 7.53 KB
/
plotter3D.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
from matplotlib.colors import Normalize
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
class Posprocess():
"""
Classe destinada ao pos processamento dos dados de treliça tridimensional
- plotar os graficos
"""
def __init__(self, model):
self.nodes = model.nodes
self.elementos = model.elementos
self.contorno = model.contorno
self.A = model.A
self.forcas = model.forcas
# material
self.modYoung = model.E
def plotDeslocamento3D(self, des):
fig = plt.figure('Plote das forma deformada')
#ax = fig.add_subplot(111, projection='3d')
ax = plt.axes(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
scale = 1./np.max(np.abs(des))
ax.set_title(f'Deslocamento da estrutura')
for pontos in self.contorno:
#print(self.nodes[pontos[0]][1], self.nodes[pontos[0]][2], self.nodes[pontos[0]][3])
ax.scatter3D(self.nodes[pontos[0]][1], self.nodes[pontos[0]][2], self.nodes[pontos[0]][3], marker = '*', color = 'black')
for elem in self.elementos:
#ax.scatter3D( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]], [self.nodes[elem[1]][2],self.nodes[elem[2]][2]], [self.nodes[elem[1]][3],self.nodes[elem[2]][3]])
# ([Xelem1,Xelem2], [Yelem1,Yelem2], [Zelem1,Zelem2])
ax.plot3D( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]],
[self.nodes[elem[1]][2], self.nodes[elem[2]][2]],
[self.nodes[elem[1]][3],self.nodes[elem[2]][3]], '--k' )
#ax.text(x = self.nodes[elem[1]][1] , y = self.nodes[elem[1]][2] , z = self.nodes[elem[1]][3] , s = str(self.nodes[elem[1]][0]) )
#ax.text(x = self.nodes[elem[2]][1] , y = self.nodes[elem[2]][2] , z = self.nodes[elem[2]][3] , s = str(self.nodes[elem[2]][0]) )
#delocamento
ax.plot3D( [ self.nodes[elem[1]][1] + scale*des[3*elem[1]], self.nodes[elem[2]][1] + scale*des[3*elem[2]]],
[ self.nodes[elem[1]][2] + scale*des[ 3*elem[1] + 1 ] , self.nodes[elem[2]][2] + scale*des[ 3*elem[2] + 1 ]],
[ self.nodes[elem[1]][3] + scale*des[ 3*elem[1] + 2 ], self.nodes[elem[2]][3] + scale*des[ 3*elem[2]+ 2 ]], '--r' )
#plt.axis('equal')
plt.show()
def plotDeslocamento2D(self, des):
fig = plt.figure('Plote das forma deformada')
#ax = fig.add_subplot(111, projection='3d')
ax = plt.axes()
ax.set_xlabel('x')
ax.set_ylabel('y')
scale = 1./np.max(np.abs(des))
ax.set_title(f'Deslocamento da estrutura')
for pontos in self.contorno:
#plot cc
ax.scatter(self.nodes[pontos[0]][1], self.nodes[pontos[0]][2], marker = '*', color = 'black')
for elem in self.elementos:
ax.plot( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]],
[self.nodes[elem[1]][2], self.nodes[elem[2]][2]], '--k' )
#delocamento
ax.plot( [ self.nodes[elem[1]][1] + scale*des[3*elem[1]], self.nodes[elem[2]][1] + scale*des[3*elem[2]]],
[ self.nodes[elem[1]][2] + scale*des[ 3*elem[1] + 1 ] , self.nodes[elem[2]][2]+ scale*des[ 3*elem[2] + 1 ]], '--r' )
#plt.axis('equal')
plt.show()
def plotModoVibra3D(self, phi, mode):
fig = plt.figure('Plote dos modos de vibrar da estrutura')
#ax = fig.add_subplot(111, projection='3d')
ax = plt.axes(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title(f'{mode + 1} ° modo de vibrar da estrutura')
scale = 3./np.max(np.abs(phi))
for elem in self.elementos:
#ax.scatter3D( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]], [self.nodes[elem[1]][2],self.nodes[elem[2]][3]], [self.nodes[elem[1]][3],self.nodes[elem[2]][3]], s = 100)
# ([Xelem1,Xelem2], [Yelem1,Yelem2], [Zelem1,Zelem2])
ax.plot3D( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]],
[self.nodes[elem[1]][2], self.nodes[elem[2]][2]],
[self.nodes[elem[1]][3],self.nodes[elem[2]][3]], color="green", linewidth=2.0, linestyle="-" )
# modo de vibrar
ax.plot3D( [ self.nodes[elem[1]][1] + scale*phi[mode][3*elem[1]], self.nodes[elem[2]][1] + scale*phi[mode][3*elem[2]] ],
[ self.nodes[elem[1]][2] + scale*phi[mode][ 3*elem[1] + 1 ] , self.nodes[elem[2]][2] + scale*phi[mode][ 3*elem[2] + 1 ]],
[ self.nodes[elem[1]][3] + scale*phi[mode][ 3*elem[1] + 2 ], self.nodes[elem[2]][3] + scale*phi[mode][ 3*elem[2]+ 2 ]], '--r' )
#plt.axis('equal')
plt.show()
def plotModoVibra2D(self, phi, mode):
fig = plt.figure('Plote dos modos de vibrar da estrutura')
#ax = fig.add_subplot(111, projection='3d')
ax = plt.axes()
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title(f'{mode + 1} ° modo de vibrar da estrutura')
scale = 3./np.max(np.abs(phi))
for elem in self.elementos:
#ax.scatter3D( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]], [self.nodes[elem[1]][2],self.nodes[elem[2]][3]], [self.nodes[elem[1]][3],self.nodes[elem[2]][3]], s = 100)
# ([Xelem1,Xelem2], [Yelem1,Yelem2], [Zelem1,Zelem2])
ax.plot( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]],
[self.nodes[elem[1]][2], self.nodes[elem[2]][2]], color="green", linewidth=2.0, linestyle="-" )
# modo de vibrar
ax.plot3D( [ self.nodes[elem[1]][1] + scale*phi[mode][3*elem[1]], self.nodes[elem[2]][1] + scale*phi[mode][3*elem[2]] ],
[ self.nodes[elem[1]][2] + scale*phi[mode][ 3*elem[1] + 1 ] , self.nodes[ele[2]][2] + scale*phi[mode][ 3*elem[2] + 1 ]], '--r' )
#plt.axis('equal')
plt.show()
def plotStress3D(self, stress, var=''):
fig = plt.figure('Plote das tensões')
#ax = fig.add_subplot(111)
ax = plt.axes(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title(f'Tensão na estrutura')
for pontos in self.contorno:
ax.scatter3D(self.nodes[pontos[0]][1], self.nodes[pontos[0]][2], self.nodes[pontos[0]][3], marker = '*', color = 'black')
norm = plt.Normalize(np.min(stress), np.max(stress))
cmap = plt.get_cmap('gist_rainbow')
c = cmap(norm(stress))
# plotando as linhas
for index,elem in enumerate(self.elementos):
ax.plot3D( [self.nodes[elem[1]][1], self.nodes[elem[2]][1]], [self.nodes[elem[1]][2],self.nodes[elem[2]][2]], [self.nodes[elem[1]][3],self.nodes[elem[2]][3]], linewidth=(self.A[index]/max(self.A))*5, markersize=5, c=c[index])
# ([Xelem1,Xelem2], [Yelem1,Yelem2], [Zelem1,Zelem2])
ax.text(x = self.nodes[elem[1]][1] , y = self.nodes[elem[1]][2] , z = self.nodes[elem[1]][3] , s = str(self.nodes[elem[1]][0]) )
#ax.text(x = self.nodes[elem[2]][1] , y = self.nodes[elem[2]][2] , z = self.nodes[elem[2]][3] , s = str(self.nodes[elem[2]][0]) )
cbar = plt.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax)
cbar.set_label('Stress '+var)
#plt.show()
def plotStress2D():
pass
if __name__ == '__main__':
pass