2013-02-25 22:42:13 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
import os,sys,string,re,math
|
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
|
|
|
|
|
|
|
scriptID = string.replace('$Id$','\n','\\n')
|
|
|
|
scriptName = scriptID.split()[1][:-3]
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
2013-05-14 23:21:53 +05:30
|
|
|
# MAIN
|
2014-10-09 22:33:06 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options]', description = """
|
2013-02-25 22:42:13 +05:30
|
|
|
Generate a geometry file of an osteon enclosing the Harvesian canal and separated by interstitial tissue.
|
|
|
|
The osteon phase is lamellar with a twisted plywood structure.
|
2013-02-27 16:26:30 +05:30
|
|
|
Its fiber orientation is oscillating by +/- amplitude within one period.
|
2014-10-09 22:33:06 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-g', '--grid', dest='grid', type='int', nargs=2, metavar = 'int int', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='a,b grid of hexahedral box %default')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-s', '--size', dest='size', type='float', nargs=2, metavar = 'float float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='x,y size of hexahedral box %default')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-c', '--canal', dest='canal', type='float', metavar = 'float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='Haversian canal radius [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-o', '--osteon', dest='osteon', type='float', metavar = 'float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='osteon radius (horizontal) [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-l', '--lamella', dest='period', type='float', metavar = 'float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='lamella width [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-a', '--amplitude', dest='amplitude', type='float', metavar = 'float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='amplitude of twisted plywood wiggle in deg [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option( '--aspect', dest='aspect', type='float', metavar = 'float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='osteon aspect ratio (vert/horiz) [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('-w', '--omega', dest='omega', type='float', metavar = 'float', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='rotation angle (around normal) of osteon [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('--homogenization', dest='homogenization', type='int', metavar = 'int', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='homogenization index to be used [%default]')
|
2014-01-20 20:11:56 +05:30
|
|
|
parser.add_option('--crystallite', dest='crystallite', type='int', metavar = 'int', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='crystallite index to be used [%default]')
|
2013-02-25 22:42:13 +05:30
|
|
|
parser.add_option('--configuration', dest='config', action='store_true', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='output material configuration [%default]')
|
2013-02-25 22:42:13 +05:30
|
|
|
parser.add_option('-2', '--twodimensional', dest='twoD', action='store_true', \
|
2013-04-12 18:18:39 +05:30
|
|
|
help='use two-dimensional geom data arrangement [%default]')
|
2013-02-25 22:42:13 +05:30
|
|
|
|
|
|
|
parser.set_defaults(canal = 25e-6)
|
2013-02-28 00:13:53 +05:30
|
|
|
parser.set_defaults(osteon = 100e-6)
|
2013-02-25 22:42:13 +05:30
|
|
|
parser.set_defaults(aspect = 1.0)
|
2013-02-27 16:26:30 +05:30
|
|
|
parser.set_defaults(omega = 0.0)
|
2013-02-25 22:42:13 +05:30
|
|
|
parser.set_defaults(period = 5e-6)
|
|
|
|
parser.set_defaults(amplitude = 60)
|
2014-10-09 22:33:06 +05:30
|
|
|
parser.set_defaults(size = np.array([300e-6,300e-6],'d'))
|
|
|
|
parser.set_defaults(grid = np.array([512,512],'i'))
|
2013-02-25 22:42:13 +05:30
|
|
|
parser.set_defaults(homogenization = 1)
|
|
|
|
parser.set_defaults(crystallite = 1)
|
|
|
|
parser.set_defaults(config = False)
|
|
|
|
parser.set_defaults(twoD = False)
|
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
(options,filename) = parser.parse_args()
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
# ------------------------------------------ setup file handle -------------------------------------
|
|
|
|
if filename == []:
|
|
|
|
file = {'output':sys.stdout, 'croak':sys.stderr}
|
|
|
|
else:
|
|
|
|
file = {'output':open(filename[0],'w'), 'croak':sys.stderr}
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
if np.any(options.grid < 2):
|
2013-05-15 02:39:37 +05:30
|
|
|
file['croak'].write('grid too small...\n')
|
|
|
|
sys.exit()
|
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
if np.any(options.size <= 0.0):
|
2013-05-15 02:39:37 +05:30
|
|
|
file['croak'].write('size too small...\n')
|
2013-02-25 22:42:13 +05:30
|
|
|
sys.exit()
|
|
|
|
|
2013-05-14 23:21:53 +05:30
|
|
|
options.omega *= math.pi/180.0 # rescale ro radians
|
2014-10-09 22:33:06 +05:30
|
|
|
rotation = np.array([[ math.cos(options.omega),math.sin(options.omega),],
|
2013-02-28 00:13:53 +05:30
|
|
|
[-math.sin(options.omega),math.cos(options.omega),]],'d')
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
box = np.dot(np.array([[options.canal,0.],[0.,options.aspect*options.canal]]).transpose(),rotation)
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2013-04-12 18:18:39 +05:30
|
|
|
|
|
|
|
info = {
|
2014-10-09 22:33:06 +05:30
|
|
|
'grid': np.ones(3,'i'),
|
|
|
|
'size': np.ones(3,'d'),
|
|
|
|
'origin': np.zeros(3,'d'),
|
2013-05-14 23:21:53 +05:30
|
|
|
'microstructures': 3,
|
2013-04-12 18:18:39 +05:30
|
|
|
'homogenization': options.homogenization,
|
2013-02-25 22:42:13 +05:30
|
|
|
}
|
|
|
|
|
2013-04-12 18:18:39 +05:30
|
|
|
info['grid'][:2] = options.grid
|
|
|
|
info['size'][:2] = options.size
|
|
|
|
info['size'][2] = min(info['size'][0]/info['grid'][0],info['size'][1]/info['grid'][1])
|
|
|
|
info['origin'] = -info['size']/2.0
|
2013-02-27 16:26:30 +05:30
|
|
|
|
2013-04-12 18:18:39 +05:30
|
|
|
X0 = info['size'][0]/info['grid'][0]*\
|
2014-10-09 22:33:06 +05:30
|
|
|
(np.tile(np.arange(info['grid'][0]),(info['grid'][1],1)) - info['grid'][0]/2 + 0.5)
|
2013-04-12 18:18:39 +05:30
|
|
|
Y0 = info['size'][1]/info['grid'][1]*\
|
2014-10-09 22:33:06 +05:30
|
|
|
(np.tile(np.arange(info['grid'][1]),(info['grid'][0],1)).transpose() - info['grid'][1]/2 + 0.5)
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2013-05-14 23:21:53 +05:30
|
|
|
X = X0*rotation[0,0] + Y0*rotation[0,1] # rotate by omega
|
|
|
|
Y = X0*rotation[1,0] + Y0*rotation[1,1] # rotate by omega
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
radius = np.sqrt(X*X + Y*Y/options.aspect/options.aspect)
|
|
|
|
alpha = np.degrees(np.arctan2(Y/options.aspect,X))
|
|
|
|
beta = options.amplitude*np.sin(2.0*math.pi*(radius-options.canal)/options.period)
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
microstructure = np.where(radius < float(options.canal),1,0) + np.where(radius > float(options.osteon),2,0)
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
alphaOfGrain = np.zeros(info['grid'][0]*info['grid'][1],'d')
|
|
|
|
betaOfGrain = np.zeros(info['grid'][0]*info['grid'][1],'d')
|
2013-04-12 18:18:39 +05:30
|
|
|
for y in xrange(info['grid'][1]):
|
|
|
|
for x in xrange(info['grid'][0]):
|
2013-02-28 00:13:53 +05:30
|
|
|
if microstructure[y,x] == 0:
|
2013-04-12 18:18:39 +05:30
|
|
|
microstructure[y,x] = info['microstructures']
|
|
|
|
alphaOfGrain[info['microstructures']] = alpha[y,x]
|
|
|
|
betaOfGrain[ info['microstructures']] = beta[y,x]
|
|
|
|
info['microstructures'] += 1
|
2013-07-18 18:58:54 +05:30
|
|
|
#--- report ---------------------------------------------------------------------------------------
|
|
|
|
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
|
2013-04-12 18:18:39 +05:30
|
|
|
file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) + \
|
|
|
|
'size x y z: %s\n'%(' x '.join(map(str,info['size']))) + \
|
|
|
|
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))) + \
|
|
|
|
'microstructures: %i\n'%info['microstructures'] + \
|
|
|
|
'homogenization: %i\n'%info['homogenization'])
|
2014-10-09 22:33:06 +05:30
|
|
|
file['croak'].write("bounding box: %s\n"%(np.sqrt(np.sum(box*box,0))))
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
if np.any(info['grid'] < 1):
|
2013-05-15 21:32:38 +05:30
|
|
|
file['croak'].write('invalid grid a b c.\n')
|
2013-05-15 02:39:37 +05:30
|
|
|
sys.exit()
|
2014-10-09 22:33:06 +05:30
|
|
|
if np.any(info['size'] <= 0.0):
|
2013-05-15 21:32:38 +05:30
|
|
|
file['croak'].write('invalid size x y z.\n')
|
2013-05-15 02:39:37 +05:30
|
|
|
sys.exit()
|
|
|
|
|
2013-02-25 22:42:13 +05:30
|
|
|
# -------------------------------------- switch according to task ----------------------------------
|
2013-04-12 18:18:39 +05:30
|
|
|
formatwidth = 1+int(math.floor(math.log10(info['microstructures']-1)))
|
2013-02-25 22:42:13 +05:30
|
|
|
if options.config:
|
|
|
|
file['output'].write('<microstructure>\n')
|
|
|
|
file['output'].write('\n[canal]\n' + \
|
|
|
|
'crystallite %i\n'%options.crystallite + \
|
|
|
|
'(constituent)\tphase 1\ttexture 1\tfraction 1.0\n')
|
|
|
|
file['output'].write('\n[interstitial]\n' + \
|
|
|
|
'crystallite %i\n'%options.crystallite + \
|
|
|
|
'(constituent)\tphase 2\ttexture 2\tfraction 1.0\n')
|
2013-04-18 19:23:13 +05:30
|
|
|
for i in xrange(3,info['microstructures']):
|
2013-02-27 16:26:30 +05:30
|
|
|
file['output'].write('\n[Grain%s]\n'%(str(i).zfill(formatwidth)) + \
|
2013-02-25 22:42:13 +05:30
|
|
|
'crystallite %i\n'%options.crystallite + \
|
2013-02-27 16:26:30 +05:30
|
|
|
'(constituent)\tphase 3\ttexture %s\tfraction 1.0\n'%(str(i).rjust(formatwidth)))
|
2013-02-25 22:42:13 +05:30
|
|
|
|
|
|
|
file['output'].write('\n<texture>\n')
|
|
|
|
file['output'].write('\n[canal]\n')
|
|
|
|
file['output'].write('\n[interstitial]\n')
|
2013-04-18 19:23:13 +05:30
|
|
|
for i in xrange(3,info['microstructures']):
|
2013-02-27 16:26:30 +05:30
|
|
|
file['output'].write('\n[Grain%s]\n'%(str(i).zfill(formatwidth)) + \
|
2013-02-25 22:42:13 +05:30
|
|
|
'(gauss)\tphi1 %g\tPhi %g\tphi2 0\tscatter 0.0\tfraction 1.0\n'%(\
|
|
|
|
alphaOfGrain[i],\
|
|
|
|
betaOfGrain[i]))
|
|
|
|
|
|
|
|
else:
|
2014-01-20 20:11:56 +05:30
|
|
|
header = [scriptID + ' ' + ' '.join(sys.argv[1:])+'\n']
|
2013-05-14 23:21:53 +05:30
|
|
|
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],))
|
|
|
|
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'])
|
|
|
|
header.append("homogenization\t%i\n"%info['homogenization'])
|
|
|
|
file['output'].write('%i\theader\n'%(len(header))+''.join(header))
|
2013-02-25 22:42:13 +05:30
|
|
|
|
2013-04-12 18:18:39 +05:30
|
|
|
for y in xrange(info['grid'][1]):
|
|
|
|
for x in xrange(info['grid'][0]):
|
2013-02-25 22:42:13 +05:30
|
|
|
file['output'].write(\
|
2013-02-28 00:13:53 +05:30
|
|
|
str(microstructure[y,x]).rjust(formatwidth) + \
|
2013-02-25 22:42:13 +05:30
|
|
|
{True:' ',False:'\n'}[options.twoD] )
|
|
|
|
file['output'].write({True:'\n',False:''}[options.twoD])
|
2014-10-09 22:33:06 +05:30
|
|
|
|