moderized
needs some polishing with respect to array orders
This commit is contained in:
parent
6836a2eae8
commit
78f30684f8
|
@ -1,46 +1,66 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os,sys,math
|
import os
|
||||||
import numpy as np
|
import sys
|
||||||
|
from io import StringIO
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# MAIN
|
# MAIN
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [option(s)] [geomfile]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile]', description = """
|
||||||
Generate a geometry file of an osteon enclosing the Harvesian canal and separated by interstitial tissue.
|
Generate description of an osteon enclosing the Harvesian canal and separated by interstitial tissue.
|
||||||
The osteon phase is lamellar with a twisted plywood structure.
|
The osteon phase is lamellar with a twisted plywood structure.
|
||||||
Its fiber orientation is oscillating by +/- amplitude within one period.
|
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='horizontal osteon radius [%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='vertical/horizontal osteon aspect ratio [%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',
|
|
||||||
help='crystallite index to be used [%default]')
|
|
||||||
|
|
||||||
parser.set_defaults(canal = 25e-6,
|
parser.set_defaults(canal = 25e-6,
|
||||||
osteon = 100e-6,
|
osteon = 100e-6,
|
||||||
|
@ -50,107 +70,83 @@ parser.set_defaults(canal = 25e-6,
|
||||||
amplitude = 60,
|
amplitude = 60,
|
||||||
size = (300e-6,300e-6),
|
size = (300e-6,300e-6),
|
||||||
grid = (512,512),
|
grid = (512,512),
|
||||||
homogenization = 1,
|
homogenization = 1)
|
||||||
crystallite = 1)
|
|
||||||
|
|
||||||
(options,filename) = parser.parse_args()
|
(options,filename) = parser.parse_args()
|
||||||
|
|
||||||
if np.any(np.array(options.grid) < 2):
|
|
||||||
parser('invalid grid a b c.')
|
|
||||||
if np.any(np.array(options.size) <= 0.0):
|
|
||||||
parser('invalid size x y z.')
|
|
||||||
|
|
||||||
# --- open input files ----------------------------------------------------------------------------
|
name = None if filename == [] else filename[0]
|
||||||
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
if filename == []: filename = [None]
|
options.omega *= np.pi/180.0 # rescale ro radians
|
||||||
|
rotation = np.array([[ np.cos(options.omega),np.sin(options.omega),],
|
||||||
table = damask.ASCIItable(outname = filename[0],
|
[-np.sin(options.omega),np.cos(options.omega),]],'d')
|
||||||
buffered = False, labeled=False)
|
|
||||||
|
|
||||||
damask.util.report(scriptName,filename[0])
|
|
||||||
|
|
||||||
options.omega *= math.pi/180.0 # rescale ro radians
|
|
||||||
rotation = np.array([[ math.cos(options.omega),math.sin(options.omega),],
|
|
||||||
[-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)
|
||||||
|
|
||||||
|
grid = np.array(options.grid,'i')
|
||||||
|
size = np.array(options.size,'d')
|
||||||
|
|
||||||
info = {
|
X0 = size[0]/grid[0]*\
|
||||||
'grid': np.ones(3,'i'),
|
(np.tile(np.arange(grid[0]),(grid[1],1)) - grid[0]/2 + 0.5)
|
||||||
'size': np.ones(3,'d'),
|
Y0 = size[1]/grid[1]*\
|
||||||
'origin': np.zeros(3,'d'),
|
(np.tile(np.arange(grid[1]),(grid[0],1)).transpose() - grid[1]/2 + 0.5)
|
||||||
'microstructures': 3,
|
|
||||||
'homogenization': options.homogenization,
|
|
||||||
}
|
|
||||||
|
|
||||||
info['grid'][:2] = np.array(options.grid,'i')
|
|
||||||
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['origin'] = -info['size']/2.0
|
|
||||||
|
|
||||||
X0 = info['size'][0]/info['grid'][0]*\
|
|
||||||
(np.tile(np.arange(info['grid'][0]),(info['grid'][1],1)) - info['grid'][0]/2 + 0.5)
|
|
||||||
Y0 = info['size'][1]/info['grid'][1]*\
|
|
||||||
(np.tile(np.arange(info['grid'][1]),(info['grid'][0],1)).transpose() - info['grid'][1]/2 + 0.5)
|
|
||||||
|
|
||||||
X = X0*rotation[0,0] + Y0*rotation[0,1] # rotate by omega
|
X = X0*rotation[0,0] + Y0*rotation[0,1] # rotate by omega
|
||||||
Y = X0*rotation[1,0] + Y0*rotation[1,1] # rotate by omega
|
Y = X0*rotation[1,0] + Y0*rotation[1,1] # rotate by omega
|
||||||
|
|
||||||
radius = np.sqrt(X*X + Y*Y/options.aspect/options.aspect)
|
radius = np.sqrt(X*X + Y*Y/options.aspect/options.aspect)
|
||||||
alpha = np.degrees(np.arctan2(Y/options.aspect,X))
|
alpha = np.degrees(np.arctan2(Y/options.aspect,X))
|
||||||
beta = options.amplitude*np.sin(2.0*math.pi*(radius-options.canal)/options.period)
|
beta = options.amplitude*np.sin(2.0*np.pi*(radius-options.canal)/options.period)
|
||||||
|
|
||||||
microstructure = np.where(radius < float(options.canal),1,0) + np.where(radius > float(options.osteon),2,0)
|
microstructure = np.where(radius < float(options.canal), 1,0)\
|
||||||
|
+ np.where(radius > float(options.osteon),2,0)
|
||||||
|
|
||||||
alphaOfGrain = np.zeros(info['grid'][0]*info['grid'][1],'d')
|
# extend to 3D
|
||||||
betaOfGrain = np.zeros(info['grid'][0]*info['grid'][1],'d')
|
size = np.append(size,np.min(size/grid))
|
||||||
for y in range(info['grid'][1]):
|
grid = np.append(grid,1)
|
||||||
for x in range(info['grid'][0]):
|
microstructure = microstructure.reshape(microstructure.shape+(1,))
|
||||||
if microstructure[y,x] == 0:
|
|
||||||
microstructure[y,x] = info['microstructures']
|
|
||||||
alphaOfGrain[info['microstructures']] = alpha[y,x]
|
|
||||||
betaOfGrain[ info['microstructures']] = beta[y,x]
|
|
||||||
info['microstructures'] += 1
|
|
||||||
|
|
||||||
#--- report ---------------------------------------------------------------------------------------
|
alphaOfGrain = np.zeros(grid[0]*grid[1],'d')
|
||||||
damask.util.report_geom(info,['grid','size','origin','homogenization','microstructures'])
|
betaOfGrain = np.zeros(grid[0]*grid[1],'d')
|
||||||
|
|
||||||
formatwidth = 1+int(math.floor(math.log10(info['microstructures']-1)))
|
i = 3
|
||||||
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]
|
for x in range(grid[0]):
|
||||||
header.append('<microstructure>')
|
for y in range(grid[1]):
|
||||||
header.append('[canal]')
|
if microstructure[y,x] == 0: #ToDo: Wrong order (y and x are flipped)
|
||||||
header.append('crystallite %i'%options.crystallite)
|
microstructure[y,x] = i #ToDo: Wrong order (y and x are flipped)
|
||||||
header.append('(constituent)\tphase 1\ttexture 1\tfraction 1.0')
|
alphaOfGrain[i] = alpha[y,x]
|
||||||
header.append('[interstitial]')
|
betaOfGrain[ i] = beta[y,x]
|
||||||
header.append('crystallite %i'%options.crystallite)
|
i+=1
|
||||||
header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0')
|
|
||||||
for i in range(3,info['microstructures']):
|
|
||||||
header.append('[Grain%s]'%(str(i).zfill(formatwidth)))
|
|
||||||
header.append('crystallite %i'%options.crystallite)
|
|
||||||
header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth)))
|
|
||||||
|
|
||||||
header.append('<texture>')
|
formatwidth = 1+int(np.floor(np.log10(np.nanmax(microstructure)-1)))
|
||||||
header.append('[canal]')
|
config_header = []
|
||||||
header.append('[interstitial]')
|
config_header.append('<microstructure>')
|
||||||
for i in range(3,info['microstructures']):
|
config_header.append('[canal]')
|
||||||
header.append('[Grain%s]'%(str(i).zfill(formatwidth)))
|
config_header.append('crystallite 1')
|
||||||
header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0\tscatter 0.0\tfraction 1.0'\
|
config_header.append('(constituent)\tphase 1\ttexture 1\tfraction 1.0')
|
||||||
%(alphaOfGrain[i],betaOfGrain[i]))
|
config_header.append('[interstitial]')
|
||||||
header.append([
|
config_header.append('crystallite 1')
|
||||||
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']),
|
config_header.append('(constituent)\tphase 2\ttexture 2\tfraction 1.0')
|
||||||
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']),
|
for i in range(3,np.max(microstructure)):
|
||||||
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']),
|
config_header.append('[Grain%s]'%(str(i).zfill(formatwidth)))
|
||||||
"homogenization\t{homog}".format(homog=info['homogenization']),
|
config_header.append('crystallite 1')
|
||||||
"microstructures\t{microstructures}".format(microstructures=info['microstructures'])])
|
config_header.append('(constituent)\tphase 3\ttexture %s\tfraction 1.0'%(str(i).rjust(formatwidth)))
|
||||||
|
|
||||||
|
config_header.append('<texture>')
|
||||||
|
config_header.append('[canal]')
|
||||||
|
config_header.append('[interstitial]')
|
||||||
|
for i in range(3,np.max(microstructure)):
|
||||||
|
config_header.append('[Grain%s]'%(str(i).zfill(formatwidth)))
|
||||||
|
config_header.append('(gauss)\tphi1 %g\tPhi %g\tphi2 0'%(alphaOfGrain[i],betaOfGrain[i]))
|
||||||
|
|
||||||
|
header = [scriptID + ' ' + ' '.join(sys.argv[1:])] + config_header
|
||||||
|
geom = damask.Geom(microstructure.reshape(grid),
|
||||||
|
size,-size/2,
|
||||||
|
homogenization=options.homogenization,comments=header)
|
||||||
|
damask.util.croak(geom)
|
||||||
|
|
||||||
table.info_append(header)
|
if name is None:
|
||||||
table.head_write()
|
sys.stdout.write(str(geom.show()))
|
||||||
|
else:
|
||||||
# --- write microstructure information ------------------------------------------------------------
|
geom.to_file(name)
|
||||||
|
|
||||||
table.data = microstructure.reshape(info['grid'][1]*info['grid'][2],info['grid'][0])
|
|
||||||
table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
|
|
||||||
|
|
||||||
#--- output finalization --------------------------------------------------------------------------
|
|
||||||
table.close()
|
|
||||||
|
|
Loading…
Reference in New Issue