forked from nogenmyr/swiftSnap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
209 lines (179 loc) · 5.86 KB
/
utils.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
'''
'''
import mathutils
import itertools
def write(filename, obj, surffiles, refinestls,eMeshfiles, cast, snap, lays, locinmesh, implicit):
shmd = open(filename,'w')
shmd.write(foamHeader('dictionary','snappyHexMeshDict'))
shmd.write("castellatedMesh %s;\n"%str(cast).lower());
shmd.write("snap %s;\n"%str(snap).lower());
shmd.write("addLayers %s;\n"%str(lays).lower());
shmd.write("\ngeometry\n{\n")
for stl in surffiles:
shmd.write(" " + stl[0] + "\n {\n type triSurfaceMesh;\n name %s;\n }\n"%stl[0][0:-4])
for ref in refinestls:
shmd.write(" " + ref[0] + "\n {\n type triSurfaceMesh;\n name %s;\n }\n"%ref[0][0:-4])
shmd.write("};\n")
shmd.write("\ncastellatedMeshControls\n{\n")
shmd.write(" features\n (\n")
for em in eMeshfiles:
shmd.write(" {\n file \"" + em + "\";\n level %s;\n }\n"%em.strip('level.eMesh'))
shmd.write(" );\n")
shmd.write(" refinementSurfaces\n {\n")
for stl in surffiles:
pmin = stl[1]
pmax = stl[2]
ptype = stl[4]
shmd.write(" %s\n {\n"%stl[0][0:-4])
shmd.write(" level ({} {});\n".format(pmin,pmax))
shmd.write(" patchInfo\n")
shmd.write(" {\n")
shmd.write(" type %s;\n"%ptype)
shmd.write(" }\n")
shmd.write(" }\n")
shmd.write(" }\n")
shmd.write(" refinementRegions\n {\n")
for ref in refinestls:
dist = ref[2]
level = ref[1]
if ref[3]:
mode = 'inside'
else:
mode = 'outside'
shmd.write(" %s\n {\n"%ref[0][0:-4])
shmd.write(" mode %s;\n"%mode)
shmd.write(" levels (({} {}));\n".format(dist, level)) #snappy allows for more freedom here!
shmd.write(" }\n")
shmd.write(" }\n")
shmd.write(" locationInMesh ({} {} {});\n".format(*locinmesh))
shmd.write(defaultSettingsCastMesh().format(implicit[1]))
shmd.write("\naddLayersControls\n{\n layers\n {\n")
for stl in surffiles:
patchname = stl[0][0:-4]
patchlayers = stl[3]
shmd.write(" \"%s.*\"\n {\n "%patchname)
shmd.write("nSurfaceLayers %s;\n }\n"%patchlayers)
shmd.write(" }\n")
shmd.write(defaultSettingsLayers())
shmd.write(defaultSettings().format(str(implicit[0]).lower()))
shmd.write("// ************************************************************************* //")
shmd.close()
return 0
def unique(seq):
# order preserving
checked = []
for e in seq:
if e not in checked:
checked.append(e)
return checked
def makeBMD(path,verts, N):
filename = 'blockMeshDict'
f = open(path+'/' + filename, 'w')
f.write(foamHeader('dictionary','blockMeshDict'))
f.write('convertToMeters 1;\n\nvertices\n(\n')
for v in verts:
f.write(' ({} {} {})\n'.format(*v))
f.write(');\n\n')
f.write('blocks\n(\n')
f.write(' hex (4 5 6 7 0 1 2 3) ({} {} {}) simpleGrading (1 1 1)\n'.format(*N))
f.write(');\n\nedges\n(\n);\nboundary\n(\n);\nmergePatchPairs\n(\n);\n\n')
f.close()
return filename
def foamHeader(classtype, objecttype):
return """/*--------------------------------*- C++ -*----------------------------------*/
// File was generated by SwiftSnap, a Blender 3D addon.
FoamFile
{{
version 2.0;
format ascii;
class {};
object {};
}}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
""".format(classtype,objecttype)
def defaultSettings():
return """
snapControls
{{
nSmoothPatch 3;
tolerance 1.0;
nSolveIter 300;
nRelaxIter 5;
nFeatureSnapIter 10;
implicitFeatureSnap {};
explicitFeatureSnap true;
multiRegionFeatureSnap false;
}}
meshQualityControls
{{
maxNonOrtho 65;
maxBoundarySkewness 20;
maxInternalSkewness 4;
maxConcave 80;
minVol 1e-13;
minTetQuality 1e-30;
minArea -1;
minTwist 0.05;
minDeterminant 0.001;
minFaceWeight 0.05;
minVolRatio 0.01;
minTriangleTwist -1;
nSmoothScale 4;
errorReduction 0.75;
relaxed
{{
maxNonOrtho 75;
}}
}}
debug 0;
mergeTolerance 1E-6;
"""
def defaultSettingsCastMesh():
return """
maxLocalCells 100000;
maxGlobalCells 2000000;
minRefinementCells 0;
nCellsBetweenLevels 1;
resolveFeatureAngle {};
allowFreeStandingZoneFaces true;
}}
"""
def defaultSettingsLayers():
return """
relativeSizes true;
expansionRatio 1.25;
finalLayerThickness 0.3;
minThickness 0.25;
nGrow 0;
featureAngle 30;
slipFeatureAngle 30;
nRelaxIter 5;
nSmoothSurfaceNormals 1;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.3;
minMedianAxisAngle 90;
nBufferCellsNoExtrude 0;
nLayerIter 50;
nRelaxedIter 20;
nLayerIter 50;
}
"""