killed "margin" option, now same as all others: resolution and dimension in x and y.
can be non-square grid.
This commit is contained in:
parent
11f18073a8
commit
0d7f1e8623
|
@ -35,24 +35,22 @@ Its fiber orientation is oscillating by +/- amplitude within one period.
|
|||
""" + string.replace('$Id$','\n','\\n')
|
||||
)
|
||||
|
||||
parser.add_option('-r', '--resolution', dest='resolution', type='int', nargs=2, \
|
||||
help='resolution (a,b) of grid')
|
||||
parser.add_option('-d', '--dimension', dest='dimension', type='float', nargs=2, \
|
||||
help='physical dimension (x,y) of periodic patch')
|
||||
parser.add_option('-c', '--canal', dest='canal', type='float', \
|
||||
help='Haversian canal radius')
|
||||
parser.add_option('-o', '--osteon', dest='osteon', type='float', \
|
||||
help='Osteon radius (horizontal)')
|
||||
parser.add_option('-r', '--aspect', dest='aspect', type='float', \
|
||||
help='Osteon aspect ratio (vert/horiz)')
|
||||
help='osteon radius (horizontal)')
|
||||
parser.add_option('-l', '--lamella', dest='period', type='float', \
|
||||
help='lamella width')
|
||||
parser.add_option('-a', '--amplitude', dest='amplitude', type='float', \
|
||||
help='amplitude of twisted plywood wiggle in deg')
|
||||
parser.add_option( '--aspect', dest='aspect', type='float', \
|
||||
help='osteon aspect ratio (vert/horiz)')
|
||||
parser.add_option('-w', '--omega', dest='omega', type='float', \
|
||||
help='rotation angle (around normal) of osteon')
|
||||
parser.add_option('-s', '--size', dest='size', type='float', \
|
||||
help='box size (horizontal)')
|
||||
parser.add_option('-m', '--margin', dest='margin', type='float', \
|
||||
help='margin width')
|
||||
parser.add_option('-N', '--resolution', dest='resolution', type='int', \
|
||||
help='box size in pixels (horizontal)')
|
||||
parser.add_option('-a', '--amplitude', dest='amplitude', type='float', \
|
||||
help='Amplitude of twisted plywood wiggle in deg')
|
||||
parser.add_option('-p', '--period', dest='period', type='float', \
|
||||
help='lamella width')
|
||||
parser.add_option('--homogenization', dest='homogenization', type='int', \
|
||||
help='homogenization index to be used')
|
||||
parser.add_option('--crystallite', dest='crystallite', type='int', \
|
||||
|
@ -60,17 +58,16 @@ parser.add_option('--crystallite', dest='crystallite', type='int', \
|
|||
parser.add_option('--configuration', dest='config', action='store_true', \
|
||||
help='output material configuration')
|
||||
parser.add_option('-2', '--twodimensional', dest='twoD', action='store_true', \
|
||||
help='output geom file with two-dimensional data arrangement')
|
||||
help='use two-dimensional geom data arrangement')
|
||||
|
||||
parser.set_defaults(canal = 25e-6)
|
||||
parser.set_defaults(osteon = 75e-6)
|
||||
parser.set_defaults(osteon = 100e-6)
|
||||
parser.set_defaults(aspect = 1.0)
|
||||
parser.set_defaults(omega = 0.0)
|
||||
parser.set_defaults(period = 5e-6)
|
||||
parser.set_defaults(amplitude = 60)
|
||||
parser.set_defaults(size = 300e-6)
|
||||
parser.set_defaults(margin = 0.0)
|
||||
parser.set_defaults(resolution = 256)
|
||||
parser.set_defaults(dimension = numpy.array([300e-6,300e-6],'d'))
|
||||
parser.set_defaults(resolution = numpy.array([512,512],'i'))
|
||||
parser.set_defaults(homogenization = 1)
|
||||
parser.set_defaults(crystallite = 1)
|
||||
parser.set_defaults(config = False)
|
||||
|
@ -86,74 +83,56 @@ file = {'name':'STDIN',
|
|||
'croak':sys.stderr,
|
||||
}
|
||||
|
||||
if (options.resolution < 2):
|
||||
if numpy.any(options.resolution < 2):
|
||||
file['croak'].write('resolution too low...\n')
|
||||
sys.exit()
|
||||
|
||||
if (options.size < options.canal):
|
||||
file['croak'].write('canal larger than box...\n')
|
||||
sys.exit()
|
||||
|
||||
if (options.osteon < options.canal):
|
||||
file['croak'].write('canal larger than osteon...\n')
|
||||
sys.exit()
|
||||
|
||||
info = {'grains': 0,
|
||||
'resolution': numpy.zeros(3,'i'),
|
||||
'dimension': numpy.ones(3,'d'),
|
||||
'origin': numpy.ones(3,'d'),
|
||||
'homogenization': options.homogenization,
|
||||
}
|
||||
|
||||
if options.margin > 0.0:
|
||||
info['resolution'][0] = options.resolution
|
||||
info['resolution'][1] = round(options.resolution*(options.aspect * options.osteon + options.margin) / \
|
||||
(options.osteon + options.margin) )
|
||||
info['dimension'][0] = options.osteon + options.margin
|
||||
info['dimension'][1] = options.aspect * options.osteon + options.margin
|
||||
else:
|
||||
info['resolution'][0] = options.resolution
|
||||
info['resolution'][1] = options.resolution
|
||||
info['dimension'][0] = options.size
|
||||
info['dimension'][1] = options.size
|
||||
|
||||
options.canal *= info['resolution'][0]/info['dimension'][0] # rescale to pixel dimension
|
||||
options.osteon *= info['resolution'][0]/info['dimension'][0] # rescale to pixel dimension
|
||||
options.period *= info['resolution'][0]/info['dimension'][0] # rescale to pixel dimension
|
||||
options.omega *= math.pi/180.0 # rescale ro radians
|
||||
|
||||
rotation = numpy.array([[ math.cos(options.omega),math.sin(options.omega),],
|
||||
[-math.sin(options.omega),math.cos(options.omega),]],'d')
|
||||
|
||||
X0 = numpy.tile(range(info['resolution'][0]),(info['resolution'][0],1)) - info['resolution'][0]/2 + 0.5
|
||||
Y0 = numpy.tile(range(info['resolution'][1]),(info['resolution'][1],1)).transpose() - info['resolution'][1]/2 + 0.5
|
||||
box = numpy.dot(numpy.array([[options.canal,0.],[0.,options.aspect*options.canal]]).transpose(),rotation)
|
||||
sys.stderr.write("bounding box: %s\n"%(numpy.sqrt(numpy.sum(box*box,0))))
|
||||
|
||||
X = X0*rotation[0,0] + Y0*rotation[1,0] # rotate by omega
|
||||
Y = X0*rotation[0,1] + Y0*rotation[1,1] # rotate by omega
|
||||
info = {'grains': 0,
|
||||
'resolution': numpy.ones(3,'i'),
|
||||
'dimension': numpy.ones(3,'d'),
|
||||
'origin': numpy.zeros(3,'d'),
|
||||
'homogenization': options.homogenization,
|
||||
}
|
||||
|
||||
radius = numpy.sqrt(X*X/options.aspect/options.aspect + Y*Y)
|
||||
alpha = numpy.degrees(numpy.arctan2(X/options.aspect,Y))
|
||||
beta = options.amplitude*numpy.sin(math.pi*(radius-options.canal)/options.period)
|
||||
|
||||
info['resolution'][:2] = options.resolution
|
||||
info['dimension'][:2] = options.dimension
|
||||
info['dimension'][2] = min(info['dimension'][0]/info['resolution'][0],info['dimension'][1]/info['resolution'][1])
|
||||
info['origin'] = -info['dimension']/2.0
|
||||
|
||||
X0 = info['dimension'][0]/info['resolution'][0]*\
|
||||
(numpy.tile(numpy.arange(info['resolution'][0]),(info['resolution'][1],1)) - info['resolution'][0]/2 + 0.5)
|
||||
Y0 = info['dimension'][1]/info['resolution'][1]*\
|
||||
(numpy.tile(numpy.arange(info['resolution'][1]),(info['resolution'][0],1)).transpose() - info['resolution'][1]/2 + 0.5)
|
||||
|
||||
X = X0*rotation[0,0] + Y0*rotation[0,1] # rotate by omega
|
||||
Y = X0*rotation[1,0] + Y0*rotation[1,1] # rotate by omega
|
||||
|
||||
radius = numpy.sqrt(X*X + Y*Y/options.aspect/options.aspect)
|
||||
alpha = numpy.degrees(numpy.arctan2(Y/options.aspect,X))
|
||||
beta = options.amplitude*numpy.sin(2.0*math.pi*(radius-options.canal)/options.period)
|
||||
|
||||
microstructure = numpy.where(radius < float(options.canal),1,0) + numpy.where(radius > float(options.osteon),2,0)
|
||||
sys.stderr.write('micro %f\n'%(time.clock()))
|
||||
|
||||
info['grains'] = 3
|
||||
alphaOfGrain = numpy.zeros(info['resolution'][0]*info['resolution'][1],'d')
|
||||
betaOfGrain = numpy.zeros(info['resolution'][0]*info['resolution'][1],'d')
|
||||
for y in xrange(info['resolution'][1]):
|
||||
for x in xrange(info['resolution'][0]):
|
||||
if microstructure[x,y] == 0:
|
||||
microstructure[x,y] = info['grains']
|
||||
alphaOfGrain[info['grains']] = alpha[x,y]
|
||||
betaOfGrain[ info['grains']] = beta[x,y]
|
||||
if microstructure[y,x] == 0:
|
||||
microstructure[y,x] = info['grains']
|
||||
alphaOfGrain[info['grains']] = alpha[y,x]
|
||||
betaOfGrain[ info['grains']] = beta[y,x]
|
||||
info['grains'] += 1
|
||||
|
||||
|
||||
sys.stderr.write('micro assemble %f\n'%(time.clock()))
|
||||
|
||||
|
||||
# -------------------------------------- switch according to task ----------------------------------
|
||||
|
||||
formatwidth = 1+int(math.floor(math.log10(info['grains']-1)))
|
||||
|
@ -183,16 +162,16 @@ if options.config:
|
|||
else:
|
||||
|
||||
file['output'].write("4 header\n" + \
|
||||
"resolution\ta %i\tb %i\tc %i\n"%(info['resolution'][0],info['resolution'][1],1,) + \
|
||||
"dimension\tx %g\ty %g\tz %g\n"%(info['dimension'][0],info['dimension'][1],info['dimension'][0]/info['resolution'][0],) + \
|
||||
"origin\tx 0\ty 0\tz 0\n" + \
|
||||
"resolution\ta %i\tb %i\tc %i\n"%(info['resolution'][0],info['resolution'][1],info['resolution'][2]) + \
|
||||
"dimension\tx %g\ty %g\tz %g\n"%(info['dimension'][0],info['dimension'][1],info['dimension'][2]) + \
|
||||
"origin\tx %g\ty %g\tz %g\n"%(info['origin'][0],info['origin'][1],info['origin'][2]) + \
|
||||
"homogenization 1\n"
|
||||
)
|
||||
|
||||
for y in xrange(info['resolution'][1]):
|
||||
for x in xrange(info['resolution'][0]):
|
||||
file['output'].write(\
|
||||
str(microstructure[x,y]).rjust(formatwidth) + \
|
||||
str(microstructure[y,x]).rjust(formatwidth) + \
|
||||
{True:' ',False:'\n'}[options.twoD] )
|
||||
file['output'].write({True:'\n',False:''}[options.twoD])
|
||||
|
||||
|
|
Loading…
Reference in New Issue