-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
157 lines (136 loc) · 4.6 KB
/
functions.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
from platform import node
def Generate_Model(W,H,t,ta,L,n,d,type):
import cadquery as cq
from cadquery import exporters
(L, H, W, t, ta, n, d) = (float(L), float(H), float(W), float(t), float(ta), int(n), float(d))
dist = L/n
ppts = [(-dist/2-i*dist,0) for i in range(n)]
pts = [
(W/2.0, H/2.0),
(W/2.0, (H/2.0 - t)),
(ta/2.0, (H/2.0 - t)),
(ta/2.0, (t - H/2.0)),
(W/2.0, (t - H/2.0)),
(W/2.0, H/-2.0),
(W/-2.0, H/-2.0),
(W/-2.0, (t - H/2.0)),
(ta/-2.0, (t - H/2.0)),
(ta/-2.0, (H/2.0 - t)),
(W/-2.0, (H/2.0 - t)),
(W/-2.0, H/2.0),
(W/2.0, H/2.0),]
if type == "Castellated Beam":
result = cq.Workplane("YZ").polyline(pts).close().extrude(L).faces(">Y[2]").workplane().pushPoints(ppts).polygon(6, d).cutThruAll()
elif type == "Cellular Beam":
result = cq.Workplane("YZ").polyline(pts).close().extrude(L).faces(">Y[2]").workplane().pushPoints(ppts).hole(d)
exporters.export(result, 'object.step', exporters.ExportTypes.STEP)
def Generate_geo_file(t,ta,type,n,Min_size,Max_size):
if type == "Castellated Beam":
s1 = 14+int(n)*6+1
s2 = 14+int(n)*6+3
elif type == "Cellular Beam":
s1 = 14+int(n)+1
s2 = 14+int(n)+3
code = """
SetFactory("OpenCASCADE");
Merge "object.step";
//+
Extrude {0, """+str(ta)+""", 0} {
Surface{13}; Layers {1}; Recombine;
}
//+
Extrude {0, 0, """+str(t)+"""} {
Surface{3}; Surface{"""+str(s2)+"""}; Surface{14}; Layers {1}; Recombine;
}
//+
Extrude {0, 0, """+"""-"""+str(t)+"""} {
Surface{8}; Surface{"""+str(s1)+"""}; Surface{12}; Layers {1}; Recombine;
}
//+
Recursive Delete {
Volume{1};
}
Coherence;
Mesh.MeshSizeMin = """+str(Min_size)+""";
Mesh.MeshSizeMax = """+str(Max_size)+""";
Mesh.Algorithm = 8;
Mesh.Algorithm3D = 4;
Mesh.RecombinationAlgorithm = 0;
Mesh.RecombineAll = 1;
Mesh.SubdivisionAlgorithm = 2;
Mesh 3;
Coherence Mesh;
"""
f = open('geometria.geo', 'w')
f.write(code)
f.close()
def Analysis_FEM(W,H,L,E,v,de,F,fix, FS):
W,H,L,Elas,poisson,de,F,FS= (float(W), float(H), float(L), float(E), float(v), float(de), float(F), float(FS))
import meshio
mesh = meshio.read("object.vtk")
nodos = mesh.points
connection = mesh.get_cells_type("hexahedron")
from scipy.sparse.linalg import spsolve
from numpy import array, zeros, round
from pmef.pro import AssembleMatrix, AssembleVector, ApplyBC
from pmef.pos import deform
import pyvista as pv
grav = array([0., 0., -1.])
class ProblemData:
SpaceDim = 3
pde = "Elasticity"
class ModelData:
E = Elas
v = poisson
density = de
selfweight = 0
gravity = grav
class ElementData:
dof = 3
nodes = 8
noInt = 8
type = "Brick8"
class Mesh:
NN = len(nodos)
NC = len(connection)
Nodos = nodos
Conex = connection
BC_data = []
Force = W*L*F
nodosz = nodos[round(nodos[:,2],4)==H/2.0,:]
f_node = Force/len(nodosz)
for i in range(Mesh.NN):
[x,y,z]=Mesh.Nodos[i]
if fix == "Start":
if round(x,4)==0:
BC_data.append([i, 1, 1, 0.])
BC_data.append([i, 1, 2, 0.])
BC_data.append([i, 1, 3, 0.])
if fix == "End - Start":
if round(x,4)==0:
BC_data.append([i, 1, 1, 0.])
BC_data.append([i, 1, 2, 0.])
BC_data.append([i, 1, 3, 0.])
if round(x,4)==L:
BC_data.append([i, 1, 1, 0.])
BC_data.append([i, 1, 2, 0.])
BC_data.append([i, 1, 3, 0.])
if round(z,4)==H/2:
BC_data.append([i, 0, 3, f_node])
BC_data = array(BC_data)
N = Mesh.NN*ElementData.dof
u = zeros(N,"float64")
K = AssembleMatrix(Mesh,ElementData, ProblemData, ModelData, "MatrizK")
f = AssembleVector(Mesh,ElementData, ProblemData, ModelData, "VectorF")
f = zeros(N, "float64")
[K, f] = ApplyBC(K, f, BC_data, Mesh, ElementData, ProblemData, ModelData)
u = spsolve(K.tocsr(), f)
defo = deform(Mesh.Nodos,u,FS)
cells = {"hexahedron": Mesh.Conex}
meshio.write_points_cells("result.vtk", defo, cells)
mesh = pv.read("result.vtk")
mesh["Ux"] = u[0::3]
mesh["Uy"] = u[1::3]
mesh["Uz"] = u[2::3]
mesh_vtp = mesh.extract_surface()
mesh_vtp.save("result.vtp")