now using default 2D output for geometry

This commit is contained in:
Martin Diehl 2015-11-16 09:54:39 +00:00
parent 46e93190ad
commit 1336c8d0e6
1 changed files with 80 additions and 96 deletions

View File

@ -21,63 +21,57 @@ Its fiber orientation is oscillating by +/- amplitude within one period.
""", version = scriptID) """, version = scriptID)
parser.add_option('-g', '--grid', dest='grid', type='int', nargs=2, metavar = 'int int', \ parser.add_option('-g', '--grid', dest='grid', type='int', nargs=2, metavar = 'int int',
help='a,b grid of hexahedral box %default') help='a,b grid of hexahedral box [%default]')
parser.add_option('-s', '--size', dest='size', type='float', nargs=2, metavar = 'float float', \ parser.add_option('-s', '--size', dest='size', type='float', nargs=2, metavar = 'float float',
help='x,y size of hexahedral box %default') help='x,y size of hexahedral box [%default]')
parser.add_option('-c', '--canal', dest='canal', type='float', metavar = 'float', \ parser.add_option('-c', '--canal', dest='canal', type='float', metavar = 'float',
help='Haversian canal radius [%default]') help='Haversian canal radius [%default]')
parser.add_option('-o', '--osteon', dest='osteon', type='float', metavar = 'float', \ parser.add_option('-o', '--osteon', dest='osteon', type='float', metavar = 'float',
help='osteon radius (horizontal) [%default]') help='horizontal osteon radius [%default]')
parser.add_option('-l', '--lamella', dest='period', type='float', metavar = 'float', \ parser.add_option('-l', '--lamella', dest='period', type='float', metavar = 'float',
help='lamella width [%default]') help='lamella width [%default]')
parser.add_option('-a', '--amplitude', dest='amplitude', type='float', metavar = 'float', \ parser.add_option('-a', '--amplitude', dest='amplitude', type='float', metavar = 'float',
help='amplitude of twisted plywood wiggle in deg [%default]') help='amplitude of twisted plywood wiggle in deg [%default]')
parser.add_option( '--aspect', dest='aspect', type='float', metavar = 'float', \ parser.add_option( '--aspect', dest='aspect', type='float', metavar = 'float',
help='osteon aspect ratio (vert/horiz) [%default]') help='vertical/horizontal osteon aspect ratio [%default]')
parser.add_option('-w', '--omega', dest='omega', type='float', metavar = 'float', \ parser.add_option('-w', '--omega', dest='omega', type='float', metavar = 'float',
help='rotation angle (around normal) of osteon [%default]') help='rotation angle around normal of osteon [%default]')
parser.add_option('--homogenization', dest='homogenization', type='int', metavar = 'int', \ parser.add_option('--homogenization', dest='homogenization', type='int', metavar = 'int',
help='homogenization index to be used [%default]') help='homogenization index to be used [%default]')
parser.add_option('--crystallite', dest='crystallite', type='int', metavar = 'int', \ parser.add_option('--crystallite', dest='crystallite', type='int', metavar = 'int',
help='crystallite index to be used [%default]') help='crystallite index to be used [%default]')
parser.add_option('--configuration', dest='config', action='store_true', \
help='output material configuration [%default]')
parser.add_option('-2', '--twodimensional', dest='twoD', action='store_true', \
help='use two-dimensional geom data arrangement [%default]')
parser.set_defaults(canal = 25e-6) parser.set_defaults(canal = 25e-6,
parser.set_defaults(osteon = 100e-6) osteon = 100e-6,
parser.set_defaults(aspect = 1.0) aspect = 1.0,
parser.set_defaults(omega = 0.0) omega = 0.0,
parser.set_defaults(period = 5e-6) period = 5e-6,
parser.set_defaults(amplitude = 60) amplitude = 60,
parser.set_defaults(size = np.array([300e-6,300e-6],'d')) size = (300e-6,300e-6),
parser.set_defaults(grid = np.array([512,512],'i')) grid = (512,512),
parser.set_defaults(homogenization = 1) homogenization = 1,
parser.set_defaults(crystallite = 1) crystallite = 1)
parser.set_defaults(config = False)
parser.set_defaults(twoD = False)
(options,filename) = parser.parse_args() (options,filename) = parser.parse_args()
# ------------------------------------------ setup file handle -------------------------------------
if filename == []:
file = {'output':sys.stdout, 'croak':sys.stderr}
else:
file = {'output':open(filename[0],'w'), 'croak':sys.stderr}
if np.any(options.grid < 2): if np.any(options.grid < 2):
file['croak'].write('grid too small...\n') parser('invalid grid a b c.')
sys.exit()
if np.any(options.size <= 0.0): if np.any(options.size <= 0.0):
file['croak'].write('size too small...\n') parser('invalid size x y z.')
sys.exit()
# --- open input files ----------------------------------------------------------------------------
if filename == []: filename = [None]
table = damask.ASCIItable(outname = filename[0],
buffered = False)
damask.util.report(scriptName,filename[0])
options.omega *= math.pi/180.0 # rescale ro radians options.omega *= math.pi/180.0 # rescale ro radians
rotation = np.array([[ math.cos(options.omega),math.sin(options.omega),], rotation = np.array([[ math.cos(options.omega),math.sin(options.omega),],
[-math.sin(options.omega),math.cos(options.omega),]],'d') [-math.sin(options.omega),math.cos(options.omega),]],'d')
box = np.dot(np.array([[options.canal,0.],[0.,options.aspect*options.canal]]).transpose(),rotation) box = np.dot(np.array([[options.canal,0.],[0.,options.aspect*options.canal]]).transpose(),rotation)
@ -90,8 +84,8 @@ info = {
'homogenization': options.homogenization, 'homogenization': options.homogenization,
} }
info['grid'][:2] = options.grid info['grid'][:2] = np.array(options.grid,'i')
info['size'][:2] = options.size info['size'][:2] = np.array(options.size,'d')
info['size'][2] = min(info['size'][0]/info['grid'][0],info['size'][1]/info['grid'][1]) info['size'][2] = min(info['size'][0]/info['grid'][0],info['size'][1]/info['grid'][1])
info['origin'] = -info['size']/2.0 info['origin'] = -info['size']/2.0
@ -118,59 +112,49 @@ for y in xrange(info['grid'][1]):
alphaOfGrain[info['microstructures']] = alpha[y,x] alphaOfGrain[info['microstructures']] = alpha[y,x]
betaOfGrain[ info['microstructures']] = beta[y,x] betaOfGrain[ info['microstructures']] = beta[y,x]
info['microstructures'] += 1 info['microstructures'] += 1
#--- report --------------------------------------------------------------------------------------- #--- report ---------------------------------------------------------------------------------------
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n') damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) + \ 'size x y z: %s'%(' x '.join(map(str,info['size']))),
'size x y z: %s\n'%(' x '.join(map(str,info['size']))) + \ 'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))) + \ 'homogenization: %i'%info['homogenization'],
'microstructures: %i\n'%info['microstructures'] + \ 'microstructures: %i'%info['microstructures']])
'homogenization: %i\n'%info['homogenization'])
file['croak'].write("bounding box: %s\n"%(np.sqrt(np.sum(box*box,0))))
if np.any(info['grid'] < 1):
file['croak'].write('invalid grid a b c.\n')
sys.exit()
if np.any(info['size'] <= 0.0):
file['croak'].write('invalid size x y z.\n')
sys.exit()
# -------------------------------------- switch according to task ---------------------------------- # -------------------------------------- switch according to task ----------------------------------
formatwidth = 1+int(math.floor(math.log10(info['microstructures']-1))) formatwidth = 1+int(math.floor(math.log10(info['microstructures']-1)))
if options.config: header = [scriptID + ' ' + ' '.join(sys.argv[1:])]
file['output'].write('<microstructure>\n') header.append('<microstructure>')
file['output'].write('\n[canal]\n' + \ header.append('[canal]')
'crystallite %i\n'%options.crystallite + \ header.append('crystallite %i'%options.crystallite)
'(constituent)\tphase 1\ttexture 1\tfraction 1.0\n') header.append('(constituent)\tphase 1\ttexture 1\tfraction 1.0')
file['output'].write('\n[interstitial]\n' + \ header.append('[interstitial]')
'crystallite %i\n'%options.crystallite + \ header.append('crystallite %i'%options.crystallite)
'(constituent)\tphase 2\ttexture 2\tfraction 1.0\n') header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0')
for i in xrange(3,info['microstructures']): for i in xrange(3,info['microstructures']):
file['output'].write('\n[Grain%s]\n'%(str(i).zfill(formatwidth)) + \ header.append('[Grain%s]'%(str(i).zfill(formatwidth)))
'crystallite %i\n'%options.crystallite + \ header.append('crystallite %i'%options.crystallite)
'(constituent)\tphase 3\ttexture %s\tfraction 1.0\n'%(str(i).rjust(formatwidth))) header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth)))
file['output'].write('\n<texture>\n') header.append('<texture>')
file['output'].write('\n[canal]\n') header.append('[canal]')
file['output'].write('\n[interstitial]\n') header.append('[interstitial]')
for i in xrange(3,info['microstructures']): for i in xrange(3,info['microstructures']):
file['output'].write('\n[Grain%s]\n'%(str(i).zfill(formatwidth)) + \ header.append('[Grain%s]'%(str(i).zfill(formatwidth)))
'(gauss)\tphi1 %g\tPhi %g\tphi2 0\tscatter 0.0\tfraction 1.0\n'%(\ header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0\tscatter 0.0\tfraction 1.0'\
alphaOfGrain[i],\ %(alphaOfGrain[i],betaOfGrain[i]))
betaOfGrain[i])) header.append([
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']),
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']),
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']),
"homogenization\t{homog}".format(homog=info['homogenization']),
"microstructures\t{microstructures}".format(microstructures=info['microstructures'])])
else: table.info_append(header)
header = [scriptID + ' ' + ' '.join(sys.argv[1:])+'\n'] table.head_write()
header.append("grid\ta %i\tb %i\tc %i\n"%(info['grid'][0],info['grid'][1],info['grid'][2],))
header.append("size\tx %f\ty %f\tz %f\n"%(info['size'][0],info['size'][1],info['size'][2],)) # --- write microstructure information ------------------------------------------------------------
header.append("origin\tx %f\ty %f\tz %f\n"%(info['origin'][0],info['origin'][1],info['origin'][2],))
header.append("microstructures\t%i\n"%info['microstructures']) table.data = microstructure.reshape(info['grid'][1]*info['grid'][2],info['grid'][0])
header.append("homogenization\t%i\n"%info['homogenization']) table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
file['output'].write('%i\theader\n'%(len(header))+''.join(header))
#--- output finalization --------------------------------------------------------------------------
for y in xrange(info['grid'][1]): table.close()
for x in xrange(info['grid'][0]):
file['output'].write(\
str(microstructure[y,x]).rjust(formatwidth) + \
{True:' ',False:'\n'}[options.twoD] )
file['output'].write({True:'\n',False:''}[options.twoD])