-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-3d.sh
executable file
·466 lines (394 loc) · 13.4 KB
/
generate-3d.sh
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/bin/bash
####################################################################
## OVERVIEW ##
# Script will facilitate the generation of a digital
# microstructure. There are several core sections.
# 1) Setup the environment
# 2) Compile codes
# 3) Structure definition
# 4) Structure generation
# 5) Post processing
####################################################################
########################################################
## Setup environment ##
########################################################
dir=${PWD}
bin=$dir/bin
src=$dir/src
includes=$dir/includes
tmp_keyword='tmpoutput_'`date '+%s'` # Date in seconds
mkdir /tmp/$tmp_keyword
tmpdir=/tmp/$tmp_keyword
modelfile=$tmpdir/rve.txt
if [ ! -d $tmpdir ]; then
echo ERROR: tmp directory not created
exit
fi
time1=`date`
echo \# >> $modelfile
echo \# Generated: $time1 >> $modelfile
echo \# >> $modelfile
########################################################
## Install and compile ##
########################################################
echo Building CA executables
os=`uname -a | grep Darwin`
if [ "$os" > /dev/null ] ; then
echo MAC os found $os
make -f Makefile.Darwin
else
make -f Makefile.gfortran
fi
echo Building MC
make -f Makefile.MC MC
if [ -x MC2vti ] ; then
echo MC2vti up to date
else
echo Building MC2vti
g++ -o MC2vti MC2vti.cpp
fi
if [ -x 3d_enum ] ; then
echo 3d_enum up to date
elif [ -e 3d_enumerate ] ; then
echo Building 3d_enum
cd $dir/3d_enumerate
make
cp 3d_enum $dir/
else
echo No 3d_enum available
fi
cd $dir
if [ ! -f bimodal.pl -a bell_curve.pl -a recursiveSampler.pl ]; then
echo bimodal.pl or bell_curve.pl or recursiveSampler.pl does not exist in $dir
exit 1
fi
if [ ! -d $includes/voxelconvert ]; then
echo voxelconvert not installed in $includes
echo downloading voxelconvert
cd $includes
pwd
svn co https://latir.materials.cmu.edu/svn/voxelconvert voxelconvert
fi
cd $includes/voxelconvert
make
cd $dir
#######################################################################
## Structure Definition ##
#######################################################################
###########################################################
## Read and process commandline arguments ##
###########################################################
# check for proper commandline arguments
# if [[ $# -gt 1 ]] ; then
# echo or ./grow-3d.sh Inputfile number_of_iterations Periodic
# exit 1
# elif [[ $# -eq 3 ]]; then
# input_dir=`dirname $1`
# input_file=$1
# iterations=$2
# Periodic=$3
# fi
# echo
# echo INPUT_DIR " "$input_dir
# echo INPUT_FILE " "$input_file
# echo ITERATIONS " "$iterations
# echo PERIODIC " "$Periodic
###########################################################
## Interactive ##
###########################################################
echo
echo
echo "======Structure definition============================="
Eta=1
echo What is the scale of the model \(microns/voxel\)? [$Eta]
read eta
if [ "$eta" > /dev/null ] ; then
Eta=$eta
fi
## Define dimension of the RVE in voxels
Vx=100
Vy=100
Vz=100
echo What are the dimensions of the RVE \(voxels\)? [$Vx $Vy $Vz]
read vx vy vz
if [ "$vx" > /dev/null ] ; then
Vx=$vx
fi
if [ "$vy" > /dev/null ] ; then
Vy=$vy
fi
if [ "$vz" > /dev/null ] ; then
Vz=$vz
fi
## Comput the size of the RVE in microns
Rx=`echo $Vx $eta|awk '{print $1*$2}'`
Ry=`echo $Vy $eta|awk '{print $1*$2}'`
Rz=`echo $Vz $eta|awk '{print $1*$2}'`
## Compute the unit_RVE
Vmax=$Vx
if [ "$Vy" -gt "$Vmax" ]; then
Vmax=$Vy
fi
if [ "$Vz" -gt "$Vmax" ]; then
Vmax=$Vz
fi
Rmax=`echo $Vmax $eta|awk '{print $1*$2}'`
Ux=`echo $Vx $Vmax|awk '{print $1/$2}'`
Uy=`echo $Vy $Vmax|awk '{print $1/$2}'`
Uz=`echo $Vz $Vmax|awk '{print $1/$2}'`
echo "Unit"
echo $Ux $Uy $Uz
echo
## Define RVE boundary conditions
Periodic=true
echo Are the boundary conditions periodic? true=1 false=2 [1]
read periodic
if [ "$periodic" > /dev/null ] ; then
if [[ "$periodic" -eq 1 ]] ; then
Preiodic=true
elif [[ "$periodic" -ne 1 ]] ; then
Periodic=false
fi
fi
#######################################################################
## recursiveSampler.pl
#
# Description: resursiveSampler.pl is a code that implements a
# recusive strategy to pack ellipsoids in to the unit RVE. It executes
# a perl script to generate a discrete set of ellipsoids and place
# them in the unit RVE. The script defines the number and size
# distribution of grains in the RVE. It monitors if ellipsoids overlap
# and recursively divides the unit RVE into smaller and smaller
# sections to guide placement of ellipsoids into unfilled regions.
#
# What does Fraction Mean?
#
# (taken from recursiveSampler.pl) recursiveSampler.pl samples the
# computational space (either specified by -bbox, or the unit cube)
# randomly, and calls ellipsoidFunction at each of the sample points.
# it keeps track of the smallest dimension of the ellipsoid, and
# compares that with the dimension of it\'s bounding box. if the
# bounding box is greater than the -fraction parameter (0.333 by
# default) times the smallest dimension of the ellipsoid, then
# recursiveSampler resamples the box with recursively subdivided
# boxes.
#######################################################################
## Read ellipsoid overlap fraction
fraction=1.05
echo Please enter fraction of ellipsoid overlap. [$fraction]
read frac
if [ "$frac" > /dev/null ] ; then
fraction=$frac
fi
## Read ellipsoid distribution information and exectue recussiveSampler.pl
distfile="List"
ListFileName="ellipsoids.txt"
elscript="randomEntry.pl $ListFileName $Rx $Ry $Rz"
solution=1
echo Ellipsoid Distribution file? ellipsoidList=1 bell_curve=2 bimodal=3 [$solution]
read sol
if [ "$sol" > /dev/null ] ; then
solution=$sol
fi
if [ "$solution" -eq "3" ] ; then
distfile="bimodal.pl"
elscript="bimodal.pl"
cp $elscript $tmpdir
elif [ "$solution" -eq "2" ] ; then
distfile="bell_curve.pl"
elscript="bell_curve.pl"
cp $elscript $tmpdir
elif [ "$solution" -eq "1" ] ; then
distfile="List"
echo Enter the name of the ellipsoid list file. [$ListFileName]
read listFileName
if [ "$listFileName" > /dev/null ]; then
ListFileName=$listFileName
fi
elscript="randomEntry.pl $ListFileName $Rx $Ry $Rz"
cp $ListFileName $tmpdir
else
echo ERROR: invalid response
exit 1
fi
## Print the results of Structure Definition screen
echo
echo
echo "======Structure Summary============================="
echo Feature size: $a microns
echo Voxels for feature: $Va
echo RVE scale \(microns/voxel\): $eta
#echo RVE dimensions \(voxels\): $Vx $Vy $Vz
echo RVE dimensions \(microns\): $Rx $Ry $Rz
echo Unit RVE ratio: $Ux $Uy $Uz
echo Periodic $Periodic
echo Fraction: $fraction
echo Ellipsoids: $distfile
if [ "$solution" -eq "1" ] ; then
echo EllipsoidList: $ListFileName
fi
echo
## Print the results of Structure definition to model file
echo Scale\(microns/voxel\) $Eta >> $modelfile
echo Voxels $Vx $Vy $Vz >> $modelfile
echo Periodic $Periodic >> $modelfile
echo Fraction $fraction >> $modelfile
echo Ellipsoids $distfile >> $modelfile
if [ "$solution" -eq "1" ] ; then
echo EllipsoidList $ListFileName >> $modelfile
fi
#######################################################################
## Structure Generation ##
#######################################################################
echo
echo
echo "======Structure generation============================="
###########################################################
## Execute recursiveSampler.pl to pack RVE ##
###########################################################
echo =======executing recursiveSampler.pl with $distfile
if [ "$solution" -eq "3" ] ; then
perl recursiveSampler.pl -bbox 0 $Ux 0 $Uy 0 $Uz -fraction $fraction 'perl bimodal.pl' > $tmpdir/test.input
elif [ "$solution" -eq "2" ] ; then
perl recursiveSampler.pl -bbox 0 $Ux 0 $Uy 0 $Uz -fraction $fraction "perl bell_curve.pl $Rmax" > $tmpdir/test.input
elif [ "$solution" -eq "1" ] ; then
perl recursiveSampler.pl -bbox 0 $Rx 0 $Ry 0 $Rz -fraction $fraction -list $ListFileName > $tmpdir/test.input
fi
###########################################################
## Execute ellipticalFoam to choose a set of axtive ##
## ellipsoids in the RVE to fill space and minimize ##
## overlap. ##
###########################################################
echo =======executing ellipticalFoam
if [ -f cell.ctrl ] ; then rm cell.ctrl ; fi
cd $tmpdir
ulimit
$dir/ellipticalFoam test.input
rm paddedPoints pointKey metaData annealing.log
###########################################################
## Grow ellipsoids using Cellular Automaton ##
###########################################################
echo =======executing CA
if [ "$solution" -eq "3" ] ; then
$dir/myCA $Ux $Uy $Uz $Vx $Vy $Vz $Periodic
elif [ "$solution" -eq "2" ] ; then
$dir/myCA $Ux $Uy $Uz $Vx $Vy $Vz $Periodic
elif [ "$solution" -eq "1" ] ; then
$dir/myCA $Rx $Ry $Rz $Vx $Vy $Vz $Periodic
fi
#######################################################################
## Post processing ##
#######################################################################
echo
echo
echo "======Post processing============================="
###########################################################
## Renumber as unique grains and set grain size threshold
###########################################################
$dir/includes/voxelconvert/voxelconvert ellipsoid_BaseCA.ph ellipsoid_BaseCA.mc
Threshold=0
echo What is the threshold for grain size? \(voxels\) [$Threshold]
read threshold
if [ "$threshold" > /dev/null ] ; then
Threshold=$threshold
fi
$dir/includes/voxelconvert/ug3D ellipsoid_BaseCA.mc grains.mc $Threshold $Periodic
rm ellipsoid_BaseCA.mc
rm ellipsoid_BaseCA.ph
###########################################################
## Output XML format for texturelist ##
###########################################################
$dir/includes/voxelconvert/voxel2XML grains.mc
###########################################################
## Visualization ##
###########################################################
$dir/MC2vti grains.mc
###########################################################
## Stats ##
###########################################################
$dir/awk_stats.sh grains.xml
###########################################################
## Grow grains to provide realism to structure ##
###########################################################
iterations=0
echo
echo How many steps of MC grain growth? [$iterations]
read iters
if [ "$iters" > /dev/null ]; then
iterations=$iters
fi
if [[ $iterations -gt 0 ]]; then
echo Executing MC growth on structure
if [[ $iterations -lt 10 ]] ; then
grow_keyword='grw0'$iterations
elif [[ $iterations -ge 10 ]] ; then
grow_keyword='grw'$iterations
fi
count=1
LIMIT=25
keyword2=${grow_keyword}_v${count}
while [ $count -lt $LIMIT ]
do
if [ -d $tmpdir/${keyword2} ] ; then
keyword2=${grow_keyword}_v${count}
else
break
fi
let "count+=1"
done
grow_dir=${tmpdir}/${keyword2}
mkdir ${grow_dir}
if [ ! -d $grow_dir ]; then
echo ERROR: growth directory not created
exit
fi
$dir/MC grains.mc $grow_dir/grainsMC.mc $iterations $Periodic
cd $grow_dir
Threshold=0
echo What is the threshold for grain size? \(voxels\) [$Threshold]
read threshold
if [ "$threshold" > /dev/null ] ; then
Threshold=$threshold
fi
$dir/includes/voxelconvert/ug3D grainsMC.mc grains_$grow_keyword.mc $Threshold $Periodic
rm grainsMC.mc
###########################################################
## Output XML format for texturelist ##
###########################################################
$dir/includes/voxelconvert/voxel2XML grains_$grow_keyword.mc
###########################################################
## Visualization ##
###########################################################
$dir/MC2vti grains_$grow_keyword.mc
###########################################################
## Stats ##
###########################################################
$dir/awk_stats.sh grains_$grow_keyword.xml
fi
##############################################################
## Move data files to unique folder to prevent overwrite ##
##############################################################
#Safety check -- ensure directory with same filename does not exist
echo Moving data to OUTPUT_FILES directory
count=1
LIMIT=25
keyword='newoutput_'`date '+%m%d%y'`
keyword2=${keyword}_v${count}
while [ $count -lt $LIMIT ]
do
if [ -d $dir/OUTPUT_FILES/${keyword2} ] ; then
#echo satisfied for count=$count
keyword2=${keyword}_v${count}
else
break
fi
let "count+=1"
done
cd $dir
outputdir=OUTPUT_FILES/${keyword2}
mv $tmpdir $outputdir
echo Program Finished
echo Program started at $time1
echo Program ended at `date`
echo results are located in $dir/OUTPUT_FILES/${keyword2}
exit