-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate_Grid.py
More file actions
308 lines (250 loc) · 9.1 KB
/
Generate_Grid.py
File metadata and controls
308 lines (250 loc) · 9.1 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
from pymint import MINTDevice, MINTLayerType
from parchmint.target import Target
from parchmint import Device
from pymint.constraints.arrayconstraint import ArrayConstraint
from pymint.constraints.orientationconstraint import OrientationConstraint, ComponentOrientation
import json
numFlowChannels = 0
numControlChannels = 0
numControlNets = 0
numValves = 0
sctList = []
flowChannels = []
controlChannels = []
controlNets = []
valves = []
#List of control ports that control the vertical and horizontal channels respectively
#that connect the square cell traps
verticalControlPorts = []
horizontalControlPorts = []
#Prompt user for grid size
gridSize = int(input("Please enter a grid size: "))
#Set component parameters
port_params = {
"portRadius": 1980
}
trap_params = {
"chamberWidth": 100,
"chamberLength": 100,
"channelWidth": 100
}
tree_in_params = {
"spacing": 1200,
"flowChannelWidth": 100,
"in": 1,
"out": gridSize
}
tree_out_params = {
"spacing": 1200,
"flowChannelWidth": 100,
"in": gridSize,
"out": 1
}
flow_channel_params = {
"channelWidth": 100
}
control_channel_params = {
"channelWidth": 100
}
valve_params = {
"width": 300,
"length": 100
}
# Create the MINTDevice instance with a name
device = MINTDevice(name="grid_" + str(gridSize) + "_device")
########################################################################################################################################################
# Create the flow layer
flow_layer = device.create_mint_layer(ID="flow", name_postfix="FLOW", group=None, layer_type=MINTLayerType.FLOW)
# Create the control layer
control_layer = device.create_mint_layer(ID="control", name_postfix="CONTROL", group=None, layer_type=MINTLayerType.CONTROL)
# Create the ports on the flow layer
port1 = device.create_mint_component(
name = "p1",
technology = "PORT",
params = port_params,
layer_ids = [flow_layer.ID]
)
port2 = device.create_mint_component(
name = "p2",
technology = "PORT",
params = port_params,
layer_ids = [flow_layer.ID]
)
# Create the square cell trap components and store them in an array
for i in range(1,gridSize**2+1):
sctList.append(device.create_mint_component(
name="ct"+str(i),
technology="SQUARE CELL TRAP",
params=trap_params,
layer_ids=[flow_layer.ID])
)
#Create the trees
tree1 = device.create_mint_component(
name="m1",
technology="TREE",
params=tree_in_params,
layer_ids=[flow_layer.ID]
)
tree2 = device.create_mint_component(
name="m2",
technology="TREE",
params=tree_out_params,
layer_ids=[flow_layer.ID]
)
#Connect tree1 to port1
numFlowChannels+=1
flowChannels.append(device.create_mint_connection(
name = "c"+str(numFlowChannels),
technology = "CHANNEL",
params = flow_channel_params,
source = Target(port1.ID, port=1),
sinks = [Target(tree1.ID,port=1)],
layer_id = flow_layer.ID
))
#Connect tree1 to first column of square cell traps
for row in range(1,gridSize+1):
numFlowChannels+=1
flowChannels.append(device.create_mint_connection(
name = "c"+str(numFlowChannels),
technology = "CHANNEL",
params = flow_channel_params,
source = Target(tree1.ID,port=1+row),
sinks = [Target(sctList[row-1].ID,port=4)],
layer_id = flow_layer.ID
))
#Connect adjacent cell traps within a column and connect adjacent columns
for col in range(1,gridSize+1):
#Connect cell traps within a column and place a valve on the channel
for row in range(1,gridSize):
numFlowChannels+=1
#Calculate the source and sink cell trap number
#To access the sct, it is the sctList[sctNum-1]
SourceSCTNum = (col-1)*gridSize+row
SinkSCTNum = (col-1)*gridSize+row+1
flowChannels.append(device.create_mint_connection(
name = "c"+str(numFlowChannels),
technology = "CHANNEL",
params = flow_channel_params,
source = Target(sctList[SourceSCTNum-1].ID,port="3"),
sinks = [Target(sctList[SinkSCTNum-1].ID,port="1")],
layer_id = flow_layer.ID
))
#Place valve on the channel we just made
numValves+=1
valves.append(device.create_valve(
name = "v" + str(numValves),
technology= "VALVE",
params = valve_params,
layer_ids = [control_layer.ID],
connection = flowChannels[numFlowChannels-1]
))
#Create control port
verticalControlPorts.append(device.create_mint_component(
name="vcp" + str(col),
technology="PORT",
params=port_params,
layer_ids=[control_layer.ID]
))
#Connect valves to control port
tempTargetList = []
for valve in valves[-(gridSize-1):]:
tempTargetList.append(Target(valve.ID,port=1))
numControlNets+=1
controlNets.append(device.create_mint_connection(
name = "n"+str(numControlNets),
technology = "CHANNEL",
params = control_channel_params,
source = Target(verticalControlPorts[-1].ID,port=1),
sinks = tempTargetList,
layer_id = control_layer.ID
))
#Connect current column to next column and place a valve on the connection
if(col!=gridSize):
for row in range(1,gridSize+1):
numFlowChannels+=1
SourceSCTNum = (col-1)*gridSize+row
SinkSCTNum = (col-1)*gridSize+row+gridSize
flowChannels.append(device.create_mint_connection(
name = "c"+str(numFlowChannels),
technology="CHANNEL",
params = flow_channel_params,
source = Target(sctList[SourceSCTNum-1].ID,port="2"),
sinks = [Target(sctList[SinkSCTNum-1].ID,port="4")],
layer_id = flow_layer.ID
))
#Place valve on the channel we just made
numValves+=1
valves.append(device.create_valve(
name = "v" + str(numValves),
technology= "VALVE",
params = valve_params,
layer_ids = [control_layer.ID],
connection = flowChannels[numFlowChannels-1]
))
#Put channels between the valves on horizontal channels
if(row!=1):
numControlChannels+=1
controlChannels.append(device.create_mint_connection(
name = "cc" + str(numControlChannels),
technology = "CHANNEL",
params = control_channel_params,
source = Target(valves[-2].ID,port=1),
sinks = [Target(valves[-1].ID,port=1)],
layer_id = control_layer.ID
))
#Create control port
horizontalControlPorts.append(device.create_mint_component(
name = "hcp" + str(col),
technology = "PORT",
params = port_params,
layer_ids = [control_layer.ID]
))
#Connect the control port to the valves on the "bottom" of grid
numControlChannels+=1
controlChannels.append(device.create_mint_connection(
name = "cc" + str(numControlChannels),
technology = "CHANNEL",
params = control_channel_params,
source = Target(valves[-1].ID,port=1),
sinks = [Target(horizontalControlPorts[-1].ID,port=1)],
layer_id = control_layer.ID
))
#Connect last row of square cell traps to tree2
for row in range(1,gridSize+1):
numFlowChannels+=1
flowChannels.append(device.create_mint_connection(
name = "c"+str(numFlowChannels),
technology = "CHANNEL",
params = flow_channel_params,
source = Target(sctList[(gridSize)*(gridSize-1)+row-1].ID,port="2"),
sinks = [Target(tree2.ID,port=str(row))],
layer_id = flow_layer.ID
))
#Connect tree2 to port2
numFlowChannels+=1
flowChannels.append(device.create_mint_connection(
name = "c"+str(numFlowChannels),
technology = "CHANNEL",
params = flow_channel_params,
source = Target(tree2.ID,port=gridSize+1),
sinks = [Target(port2.ID,port=1)],
layer_id = flow_layer.ID
))
#########################################################################################################################################################
#Constraints
cpb1 = ArrayConstraint(verticalControlPorts)
cpb2 = ArrayConstraint(horizontalControlPorts)
device.add_constraint(cpb1)
device.add_constraint(cpb2)
#Make the tree horizontal
oc = OrientationConstraint()
oc.add_component_orientation_pair(tree1,ComponentOrientation.HORIZONTAL)
oc.add_component_orientation_pair(tree2,ComponentOrientation.HORIZONTAL)
device.add_constraint(oc)
#########################################################################################################################################################
fileName = 'grid_' + str(gridSize) + '.mint'
with open(fileName, 'w') as file:
file.write(device.to_MINT())
with open('grid_' + str(gridSize) + ".json", 'w') as f:
json.dump(device.device.to_parchmint_v1_2(), f, indent=2)
print("Complete")