Skip to content

Commit 4d74fc8

Browse files
authored
Merge pull request #14 from bradenfrigoletto24/pytacsadapt
pytacsadapt
2 parents 2efc3a3 + ddd0b9a commit 4d74fc8

11 files changed

+2076
-194
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
"""
2+
A function to generate the plate geometry used for testing
3+
"""
4+
5+
# imports
6+
import numpy as np
7+
from egads4py import egads
8+
9+
10+
def makePlateGeom(width=1.0, height=1.0, npanels=1, makeIGES=False):
11+
"""
12+
Writes a plate.step/.iges geometry file for the planar plate model of the
13+
following form:
14+
__________ __________
15+
| | |
16+
| | | ^ y
17+
| | | |
18+
|__________|__________| ---> x
19+
20+
Parameters
21+
----------
22+
width : float
23+
the length of the plate geometry along the x-axis
24+
25+
height : float
26+
the length of the plate geometry along the y-axis
27+
28+
npanels : int
29+
the number of panels used define the plate geometry along the x-dimension
30+
31+
makeIGES : bool
32+
boolean flag on whether to return an IGES/STEP geometry
33+
"""
34+
# get the model size info
35+
nverts = 2 * (npanels + 1)
36+
nedges = (3 * npanels) + 1
37+
nfaces = npanels
38+
39+
# get the vertex coordinates
40+
nx = npanels + 1
41+
ny = 2
42+
x = np.linspace(0, width, nx)
43+
y = np.linspace(0, height, ny)
44+
X, Y = np.meshgrid(x, y)
45+
coords = np.zeros([nverts, 3])
46+
coords[:, 0] = X.ravel()
47+
coords[:, 1] = Y.ravel()
48+
# print(coords)
49+
50+
# make the quad node connectivity - used to make the edge and face connectivity
51+
quad_conn = []
52+
for iface in range(nfaces):
53+
i = iface % 4
54+
j = iface // 4
55+
quad_conn.append(
56+
[i + nx * j, (i + 1) + nx * j, (i + 1) + nx * (j + 1), i + nx * (j + 1)]
57+
)
58+
quad_conn = np.array(quad_conn)
59+
# print(quad_conn)
60+
61+
# make the edge connectivity
62+
edge_conn = []
63+
for iedge in range(nfaces * 4):
64+
ipanel = iedge // 4
65+
local_edge = iedge % 4
66+
if ipanel > 0 and local_edge == 3:
67+
continue
68+
v1 = quad_conn[ipanel, local_edge]
69+
if local_edge == 3:
70+
v2 = quad_conn[ipanel, 0]
71+
else:
72+
v2 = quad_conn[ipanel, local_edge + 1]
73+
edge_conn.append([v1, v2])
74+
edge_conn = np.array(edge_conn)
75+
# print(edge_conn)
76+
77+
# make the face connectivity
78+
face_conn = []
79+
for iface in range(nfaces):
80+
conn = []
81+
for iedge in range(4):
82+
v1 = quad_conn[iface, iedge]
83+
if iedge == 3:
84+
v2 = quad_conn[iface, 0]
85+
else:
86+
v2 = quad_conn[iface, iedge + 1]
87+
edge = np.array([v1, v2])
88+
edge_ind = np.where((edge_conn == edge).all(axis=1))[0]
89+
if edge_ind.size == 0:
90+
edge_ind = np.where((edge_conn == np.flip(edge)).all(axis=1))[0]
91+
conn.append(edge_ind[0])
92+
face_conn.append(conn)
93+
face_conn = np.array(face_conn)
94+
# print(face_conn)
95+
96+
# create egads
97+
ctx = egads.context()
98+
ctx.setOutLevel(0)
99+
100+
# create the node topology
101+
nodes = []
102+
for i in range(nverts):
103+
nodes.append(ctx.makeTopology(egads.NODE, rdata=coords[i]))
104+
105+
# create the line geometry
106+
lines = []
107+
for i in range(nedges):
108+
n1_ind = edge_conn[i, 0]
109+
n2_ind = edge_conn[i, 1]
110+
delta = coords[n2_ind] - coords[n1_ind]
111+
lines.append(
112+
ctx.makeGeometry(
113+
egads.CURVE, mtype=egads.LINE, rdata=[coords[n1_ind], delta]
114+
)
115+
)
116+
117+
# create the edge topology
118+
edges = []
119+
for i in range(nedges):
120+
n1_ind = edge_conn[i, 0]
121+
n2_ind = edge_conn[i, 1]
122+
delta = coords[n2_ind] - coords[n1_ind]
123+
dist = np.linalg.norm(delta, 2)
124+
edges.append(
125+
ctx.makeTopology(
126+
egads.EDGE,
127+
mtype=egads.TWONODE,
128+
geom=lines[i],
129+
children=[nodes[n1_ind], nodes[n2_ind]],
130+
rdata=[0, dist],
131+
)
132+
)
133+
134+
# create the edge loops
135+
edge_loops = []
136+
edge_loop_nums = []
137+
for i in range(nfaces):
138+
e1_ind = face_conn[i, 0]
139+
e2_ind = face_conn[i, 1]
140+
e3_ind = face_conn[i, 2]
141+
e4_ind = face_conn[i, 3]
142+
eloop, nloop_edges = ctx.makeLoop(
143+
[edges[e1_ind], edges[e2_ind], edges[e3_ind], edges[e4_ind]]
144+
)
145+
edge_loops.append(eloop)
146+
edge_loop_nums.append(nloop_edges)
147+
148+
# create the faces
149+
faces = []
150+
for i in range(nfaces):
151+
faces.append(ctx.makeFace(edge_loops[i], egads.SFORWARD))
152+
153+
# piece it all together and make the model
154+
shell = ctx.makeTopology(egads.SHELL, egads.OPEN, children=faces)
155+
body = ctx.makeTopology(egads.BODY, egads.SHEETBODY, children=[shell])
156+
model = ctx.makeTopology(egads.MODEL, children=[body])
157+
fname = "plate"
158+
if makeIGES:
159+
fname += ".iges"
160+
else:
161+
fname += ".step"
162+
model.saveModel(fname, overwrite=True)
163+
return
164+
165+
166+
makePlateGeom()

0 commit comments

Comments
 (0)