-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandyFunctions
executable file
·313 lines (260 loc) · 10.4 KB
/
handyFunctions
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
#!/bin/bash
## ----- Print colors ----- ##
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m'
## ------------------------ ##
templateDicts="$handyDir/templateDicts"
templateBCs="$handyDir/templateBCs"
setNu () {
# Input options:
# $1 can be 'air', 'water', or a number that gets fed to foamDictionary
transp='constant/transportProperties'
printf "${CYAN}Setting $transp ${NC}\n"
if [ "$1" == "air" ]; then
foamDictionary -entry nu -set "[0 2 -1 0 0 0 0] 1.5e-5" $transp
elif [ "$1" == "water" ]; then
foamDictionary -entry nu -set "[0 2 -1 0 0 0 0] 1e-6" $transp
elif [ -z "$1" ]; then
foamDictionary -entry nu -set "[0 2 -1 0 0 0 0] $1" $transp
else
echo "Argument not provided"
fi
}
setThermo () {
# Input options:
# $1 Same as setNu, but no allowance for custom
# $2 for choosing the equation of state, 'bous' or 'ideal'
thermo='constant/thermophysicalProperties'
printf "${CYAN}Setting $thermo ${NC}\n"
if [ "$1" == "air" ]; then
foamDictionary -entry mixture.specie.molWeight -set 28.97 $thermo
foamDictionary -entry mixture.equationOfState.rho0 -set 1.225 $thermo
foamDictionary -entry mixture.equationOfState.beta -set 3e-3 $thermo
foamDictionary -entry mixture.thermodynamics.Cv -set 712 $thermo
foamDictionary -entry mixture.thermodynamics.Cp -set 1006 $thermo
foamDictionary -entry mixture.transport.mu -set 1.5e-5 $thermo
foamDictionary -entry mixture.transport.Pr -set 0.7 $thermo
elif [ "$1" == "water" ]; then
foamDictionary -entry mixture.specie.molWeight -set 18 $thermo
foamDictionary -entry mixture.equationOfState.rho0 -set 1000 $thermo
foamDictionary -entry mixture.equationOfState.beta -set 2.1e-4 $thermo
foamDictionary -entry mixture.thermodynamics.Cv -set 4160 $thermo
foamDictionary -entry mixture.thermodynamics.Cp -set 4184 $thermo
foamDictionary -entry mixture.transport.mu -set 1.05e-3 $thermo
foamDictionary -entry mixture.transport.Pr -set 6.9 $thermo
else
print "Argument 1 for setThermo invalid, please choose air or water"
fi
if [ "$2" == "bous" ]; then
foamDictionary -entry thermoType.equationOfState -set Boussinesq $thermo
elif [ "$2" == "ideal" ]; then
foamDictionary -entry thermoType.equationOfState -set perfectGas $thermo
else
# default to bous
foamDictionary -entry thermoType.equationOfState -set Boussinesq $thermo
fi
}
setSolver () {
# Input options
# $1 is the density option, 'incomp', 'buoy', 'comp'
# compressible and multiphase not currently implemented
# $2 is the timme option, 'steady', 'piso', 'pimple'
cont='system/controlDict'
printf "${CYAN}Setting solver in $cont ${NC}\n"
if [ "$1" == 'incomp' ] && [ "$2" == 'steady' ]; then
foamDictionary -entry application -set 'simpleFoam' $cont
elif [ "$1" == 'incomp' ] && ([ "$2" == 'piso' ] || [ "$2" == 'pimple' ]); then
foamDictionary -entry application -set "pimpleFoam" $cont
elif [ "$1" == 'buoy' ] && [ "$2" == 'steady' ]; then
foamDictionary -entry application -set "buoyantSimpleFoam" $cont
elif [ "$1" == 'buoy' ] && ([ "$2" == 'piso' ] || [ "$2" == 'pimple' ]); then
foamDictionary -entry application -set "buoyantPimpleFoam" $cont
else
print "Invalid arguments for setSolver"
fi
}
setTurbulence () {
# Input options
# $1 is the turbulence class, 'lam', 'rans', 'les', 'des'
# $2 is the turbulence model, e.g. 'kOmegaSST'
if [ -f constant/momentumTransport ]; then
turb='constant/momentumTransport'
else
turb='constant/turbulenceProperties'
fi
printf "${CYAN}Setting $turb ${NC}\n"
# Set the simulation type
if [ "$1" == "lam" ]; then
foamDictionary -entry simulationType -set laminar $turb
elif [ "$1" == "rans" ]; then
foamDictionary -entry simulationType -set RAS $turb
foamDictionary -entry RAS.RASModel -set $2 $turb
elif ([ "$1" == "les" ] || [ "$1" == "des" ]); then
foamDictionary -entry simulationType -set LES $turb
foamDictionary -entry LES.LESModel -set $2 $turb
fi
# Set the delta
if ([ "$1" == "les" ] || [ "$1" == "des" ]); then
if [[ "$2" == *"IDDES"* ]]; then
foamDictionary -entry LES.delta -set IDDESDelta $turb
else
foamDictionary -entry LES.delta -set cubeRootVol $turb
fi
fi
}
setSolutions () {
# Input options
# $1 can be 'piso' or 'pimple'
sol='system/fvSolution'
cont='system/controlDict'
printf "${CYAN}\nSetting $cont and $sol${NC}\n"
if [ "$1" == 'piso' ]; then
foamDictionary -entry PIMPLE.nCorrectors -set 2 $sol
foamDictionary -entry PIMPLE.nOuterCorrectors -set 1 $sol
foamDictionary -entry PIMPLE.nNonOrthogonalCorrectors -set 1 $sol
foamDictionary -entry maxCo -set 1 $cont
elif [ "$1" == 'pimple' ]; then
foamDictionary -entry PIMPLE.nCorrectors -set 1 $sol
foamDictionary -entry PIMPLE.nOuterCorrectors -set 3 $sol
foamDictionary -entry PIMPLE.nNonOrthogonalCorrectors -set 1 $sol
foamDictionary -entry maxCo -set 5 $cont
else
print "Argument 1 for setSolutions invalid, choose piso or pimple"
fi
}
setSchemes () {
# Input options
# $1 is the order of the schemes, 'first' or 'second'
# $2 is the time behavior, 'steady', 'piso' or 'pimple'
# $3 is the turbulence class, 'rans', 'les', or 'des'
schemes='system/fvSchemes'
printf "${CYAN}\nSetting $schemes ${NC}\n"
# Set the time scheme
if [ "$2" == "steady" ]; then
foamDictionary -entry ddtSchemes.default -set steadyState $schemes
elif [ "$1" == "first" ] && ([ "$2" == "piso" ] || [ "$2" == "pimple" ]); then
foamDictionary -entry ddtSchemes.default -set Euler $schemes
elif [ "$1" == "second" ] && ([ "$2" == "piso" ] || [ "$2" == "pimple" ]); then
foamDictionary -entry ddtSchemes.default -set backward $schemes
fi
# Use bounded schemes if steady state
bound=''
if [ "$2" == "steady" ]; then
bound='bounded'
fi
# Set the other schemes
# For now just div schemes, will look into optimal setting for the others later
if [ "$1" == "first" ]; then
foamDictionary -entry "divSchemes.div(phi,U)" -set "$bound Gauss upwind" $schemes
foamDictionary -entry "divSchemes.scalars" -set "$bound Gauss upwind" $schemes
elif [ "$3" == "rans" ]; then
foamDictionary -entry "divSchemes.div(phi,U)" -set "$bound Gauss linearUpwindV grad(U)" $schemes
foamDictionary -entry "divSchemes.scalars" -set "$bound Gauss linearUpwind default" $schemes
elif ([ "$3" == "les" ] || [ "$3" == "des" ]); then
foamDictionary -entry "divSchemes.div(phi,U)" -set "Gauss LUST grad(U)" $schemes
foamDictionary -entry "divSchemes.scalars" -set "Gauss linearUpwind default" $schemes
fi
sed -i 's/SCALARS/\$scalars/g' $schemes
}
setScalarTransport () {
if [ ! -d system ]; then
printf "system dir not found... \n"
exit 1
fi
if [ -f system/s ]; then
printf "system/s exists, overwrite? [y/n]\n"
read -n 1 option;
if [ ! "$option" == "y" ]; then exit 1; fi
fi
printf "${CYAN}\nSetting system/s ${NC}\n"
cp $templateDicts/s ./system/s;
# Option to set diffusivity
if [ ! -z "$1" ]; then
if [ "$1" == "air" ]; then
foamDictionary -entry D -set 1.5e-05 system/s;
elif [ "$1" == "water" ]; then
foamDictionary -entry D -set 1e-06 system/s;
else
foamDictionary -entry D -set "$1" system/s
fi
fi
}
setFvOptions () {
if [ ! -d constant ]; then
printf "constant dir not found... \n"
exit 1
fi
if [ -f constant/fvOptions ]; then
printf "fvOptions exists, overwrite? [y/n]\n"
read -n 1 option;
if [ ! "$option" == "y" ]; then exit 1; fi
fi
printf "${CYAN}\nSetting constant/fvOptions ${NC}\n"
cp $templateDicts/fvOptions constant/
}
setTopoSet () {
if [ ! -d system ]; then
printf "system dir not found... \n"
exit 1
fi
if [ -f system/topoSetDict ]; then
printf "topoSetDict exists, overwrite? [y/n]\n"
read -n 1 option;
if [ ! "$option" == "y" ]; then exit 1; fi
fi
printf "${CYAN}\nSetting system/topoSetDict ${NC}\n"
cp $templateDicts/topoSetDict system/
}
setBoundaryConditions () {
# Input options
# $1 is the turbulence model
# $2 is the density option, 'incomp', 'buoy', 'comp'
# compressible and multiphase not currently implemented
if [ ! -d 0.orig ]; then
printf "${CYAN}\nCreating 0.orig ${NC}\n"
mkdir 0.orig
fi
cp $templateBCs/U 0.orig/U
if [[ "$2" =~ "incomp" ]]; then
printf "${CYAN}\nSetting incompressible BCs ${NC}\n"
cp $templateBCs/p.incomp 0.orig/p
elif [[ "$2" =~ "buoy" ]]; then
printf "${CYAN}\nSetting buoyant BCs ${NC}\n"
cp $templateBCs/p.buoy 0.orig/p
cp $templateBCs/p_rgh 0.orig/p_rgh
cp $templateBCs/T 0.orig/T
cp $templateBCs/alphat 0.orig/alphat
elif [[ "$2" =~ "comp" ]]; then
printf "${CYAN}\nSetting compressible BCs ${NC}\n"
cp $templateBCs/p.comp 0.orig/p
cp $templateBCs/p_rgh 0.orig/p_rgh
cp $templateBCs/T 0.orig/T
cp $templateBCs/alphat 0.orig/alphat
fi
if [[ "$1" =~ "kOmega" ]]; then
printf "${CYAN}\nSetting kOmega BCs ${NC}\n"
cp $templateBCs/omega 0.orig/omega
cp $templateBCs/k 0.orig/k
cp $templateBCs/nut 0.orig/nut
elif [[ "$1" =~ "kEpsilon" ]]; then
printf "${CYAN}\nSetting kEpsilon BCs ${NC}\n"
cp $templateBCs/epsilon 0.orig/epsilon
cp $templateBCs/k 0.orig/k
cp $templateBCs/nut 0.orig/nut
fi
if [[ "$1" =~ "Spalart" ]]; then
printf "${CYAN}\nSetting SpalartAllmaras BCs ${NC}\n"
cp $templateBCs/nut 0.orig/nut
cp $templateBCs/nuTilda 0.orig/nuTilda
fi
if [[ "$1" =~ "kEqn" ]]; then
printf "${CYAN}\nSetting kEqn BCs ${NC}\n"
cp $templateBCs/k 0.orig/k
cp $templateBCs/nut 0.orig/nut
fi
if [[ "$1" =~ "Smagorinsky" ]]; then
printf "${CYAN}\nSetting Smagorinsky BCs ${NC}\n"
cp $templateBCs/nut 0.orig/nut
fi
}