forked from EllieSchnee126/NDLArFieldCageSimulations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoBox.py
129 lines (102 loc) · 5.84 KB
/
geoBox.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
from netgen.occ import *
from ngsolve import *
# All lengths are in units of millimeters!!!!
def buildGeometry(stripWidth, stripSpacing, numberOfStrips):
# Parameters for geometry
stripDistance = stripWidth + stripSpacing
stripThickness = 0.1
boardThickness = 6.35
boxLength = 1000
boxHeight = 3000
boxWidth = stripDistance * numberOfStrips + stripSpacing
LArExtension = 100
# Constructing the geometry
# LAr Volume
shapeLAr = Box(Pnt(-LArExtension, -(boxWidth + (boardThickness/2) + stripThickness + boardThickness) - LArExtension, -LArExtension),
Pnt(boxLength + LArExtension, boxWidth + (boardThickness/2) + stripThickness + boardThickness + LArExtension, boxHeight + LArExtension))
# FR4 board for field cage
outerInsul = Box(Pnt(0, -(boxWidth + (boardThickness/2) + stripThickness + boardThickness), 0), Pnt(boxLength, boxWidth + (boardThickness/2) + stripThickness + boardThickness, boxHeight))
innerInsul = Box(Pnt(boardThickness, -(boxWidth + (boardThickness/2) + stripThickness), boardThickness), Pnt(boxLength - boardThickness, (boxWidth + (boardThickness/2) + stripThickness), boxHeight - boardThickness))
shapeInsul = outerInsul
shapeInsul -= innerInsul
# Cathode in the middle of the field cage
shapePlateMid1 = Box(Pnt(boardThickness, (boardThickness/2), boardThickness), Pnt(boxLength - boardThickness, (boardThickness/2) + stripThickness, boxHeight - boardThickness))
shapePlateMid2 = Box(Pnt(boardThickness, -(boardThickness/2), boardThickness), Pnt(boxLength - boardThickness, -(boardThickness/2) - stripThickness, boxHeight - boardThickness))
# Anodes on either end
shapePlate1 = Box(Pnt(boardThickness, boxWidth + (boardThickness/2), boardThickness), Pnt(boxLength - boardThickness, boxWidth + (boardThickness/2) + stripThickness, boxHeight - boardThickness))
shapePlate2 = Box(Pnt(boardThickness, -boxWidth - (boardThickness/2), boardThickness), Pnt(boxLength - boardThickness, -boxWidth - (boardThickness/2) - stripThickness, boxHeight - boardThickness))
shapeInsul -= shapePlateMid1
shapeInsul -= shapePlateMid2
shapeInsul -= shapePlate1
shapeInsul -= shapePlate2
# Strips for one side
strips1 = []
for x in range(numberOfStrips):
outerStripTemp = Box(Pnt(boardThickness, (boardThickness/2) + stripSpacing + x*stripDistance, boardThickness), Pnt(boxLength - boardThickness, (boardThickness/2) + stripSpacing + stripWidth + x*stripDistance, boxHeight - boardThickness))
innerStripTemp = Box(Pnt(boardThickness + stripThickness, (boardThickness/2) + stripSpacing + x*stripDistance, boardThickness + stripThickness),
Pnt(boxLength - boardThickness - stripThickness, (boardThickness/2) + stripSpacing + stripWidth + x*stripDistance,
boxHeight - boardThickness - stripThickness))
outerStripTemp -= innerStripTemp
strips1.append(outerStripTemp)
# Strips for other side
strips2 = []
for x in range(numberOfStrips):
outerStripTemp = Box(Pnt(boardThickness, -((boardThickness/2) + stripSpacing + x*stripDistance), boardThickness), Pnt(boxLength - boardThickness, -((boardThickness/2) + stripSpacing + stripWidth + x*stripDistance), boxHeight - boardThickness))
innerStripTemp = Box(Pnt(boardThickness + stripThickness, -((boardThickness/2) + stripSpacing + x*stripDistance), boardThickness + stripThickness),
Pnt(boxLength - boardThickness - stripThickness, -((boardThickness/2) + stripSpacing + stripWidth + x*stripDistance),
boxHeight - boardThickness - stripThickness))
outerStripTemp -= innerStripTemp
strips2.append(outerStripTemp)
# Cutting out of the LAr Volume
shapeLAr -= shapeInsul
shapeLAr -= shapePlateMid1
shapeLAr -= shapePlateMid2
shapeLAr -= shapePlate1
shapeLAr -= shapePlate2
for strip in strips1:
shapeLAr -= strip
for strip in strips2:
shapeLAr -= strip
# Input for Glue
shape = []
shape.append(shapeLAr)
shape.append(shapeInsul)
shape.append(shapePlate1)
shape.append(shapePlate2)
shape.append(shapePlateMid1)
shape.append(shapePlateMid2)
for strip in strips1:
shape.append(strip)
for strip in strips2:
shape.append(strip)
return shape
def mesh(shape, folderName, meshFineness):
# Meshing
geo = OCCGeometry(Glue(shape))
mesh = Mesh(geo.GenerateMesh(maxh=meshFineness))
mesh.ngmesh.Export(folderName, "Elmer Format")
# Make solver file (I think this is only necessary when running the elmer GUI)
solver = open("./" + folderName + "/ELMERSOLVER_STARTINFO", 'w')
solver.write("case.sif\n1\n")
solver.close()
def main(args):
# Builds the geometry and then meshes it
Shape = buildGeometry(int(args.StripWidth), int(args.StripSpacing), int(args.StripNumber))
mesh(Shape, args.outFolderName, int(args.MeshFineness)) # I had issues when trying to use too coarse of a mesh
# (30 mm), however, even a 10mm mesh took close to 2 hours to run on our cluster
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description = 'Create ND LAr geometry and export mesh')
parser.add_argument('-o', '--outFolderName',
default = 'LArBox',
help = 'output folder name (default: LArBox)')
parser.add_argument('StripWidth',
help = 'Set the width of each strip')
parser.add_argument('StripSpacing',
help = 'Set the spacing between each strip')
parser.add_argument('StripNumber',
help = 'Set the number of strips (on one side of the box)')
parser.add_argument('MeshFineness',
help='Set the fineness of the mesh')
args = parser.parse_args()
main(args)