2016-05-11 14:31:39 +05:30
|
|
|
#!/usr/bin/env python2
|
2015-06-05 17:11:44 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2015-09-24 18:51:44 +05:30
|
|
|
import os,math,sys
|
|
|
|
import numpy as np
|
2015-06-05 17:11:44 +05:30
|
|
|
import damask
|
2015-09-24 18:51:44 +05:30
|
|
|
from optparse import OptionParser
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2015-06-05 17:11:44 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
|
|
|
Create seeds file by poking at 45 degree through given geom file.
|
|
|
|
Mimics APS Beamline 34-ID-E DAXM poking.
|
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-N', '--points',
|
|
|
|
dest = 'N',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'number of poking locations [%default]')
|
2015-10-02 05:51:23 +05:30
|
|
|
parser.add_option('-b', '--box',
|
|
|
|
dest = 'box',
|
|
|
|
type = 'float', nargs = 6, metavar = ' '.join(['float']*6),
|
|
|
|
help = 'bounding box as fraction in x, y, and z directions')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-x',
|
|
|
|
action = 'store_true',
|
|
|
|
dest = 'x',
|
|
|
|
help = 'poke 45 deg along x')
|
|
|
|
parser.add_option('-y',
|
|
|
|
action = 'store_true',
|
|
|
|
dest = 'y',
|
|
|
|
help = 'poke 45 deg along y')
|
|
|
|
parser.add_option('-p','--position',
|
|
|
|
dest = 'position',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'column label for coordinates [%default]')
|
|
|
|
|
|
|
|
parser.set_defaults(x = False,
|
|
|
|
y = False,
|
2015-10-02 05:51:23 +05:30
|
|
|
box = [0.0,1.0,0.0,1.0,0.0,1.0],
|
2015-08-08 00:33:26 +05:30
|
|
|
N = 16,
|
|
|
|
position = 'pos',
|
|
|
|
)
|
2015-06-05 17:11:44 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2015-10-02 05:51:23 +05:30
|
|
|
options.box = np.array(options.box).reshape(3,2)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over output files -------------------------------------------------------------------------
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-06-05 17:11:44 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-08-21 01:12:05 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
2015-09-24 18:51:44 +05:30
|
|
|
outname = os.path.splitext(name)[-2]+'_poked_{}.seeds'.format(options.N) if name else name,
|
2015-08-21 01:12:05 +05:30
|
|
|
buffered = False, labeled = False)
|
|
|
|
except: continue
|
2015-09-24 18:51:44 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- interpret header ----------------------------------------------------------------------------
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_read()
|
|
|
|
info,extra_header = table.head_getGeom()
|
|
|
|
|
2015-09-24 18:51:44 +05:30
|
|
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
2015-09-30 04:05:57 +05:30
|
|
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
|
|
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
|
|
|
'homogenization: %i'%info['homogenization'],
|
|
|
|
'microstructures: %i'%info['microstructures'],
|
|
|
|
])
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
errors = []
|
|
|
|
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
|
|
|
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
|
|
|
|
if errors != []:
|
2015-09-24 18:51:44 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- read data ------------------------------------------------------------------------------------
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure
|
|
|
|
|
|
|
|
# --- do work ------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
newInfo = {
|
|
|
|
'microstructures': 0,
|
|
|
|
}
|
2015-10-02 05:51:23 +05:30
|
|
|
offset = (np.amin(options.box, axis=1)*info['grid']/info['size']).astype(int)
|
|
|
|
box = np.amax(options.box, axis=1) - np.amin(options.box, axis=1)
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-10-02 05:51:23 +05:30
|
|
|
Nx = int(options.N/math.sqrt(options.N*info['size'][1]*box[1]/info['size'][0]/box[0]))
|
|
|
|
Ny = int(options.N/math.sqrt(options.N*info['size'][0]*box[0]/info['size'][1]/box[1]))
|
|
|
|
Nz = int(box[2]*info['grid'][2])
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-10-02 05:51:23 +05:30
|
|
|
damask.util.croak('poking {} x {} x {} in box {} {} {}...'.format(Nx,Ny,Nz,*box))
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-06-05 17:11:44 +05:30
|
|
|
seeds = np.zeros((Nx*Ny*Nz,4),'d')
|
|
|
|
grid = np.zeros(3,'i')
|
|
|
|
|
|
|
|
n = 0
|
|
|
|
for i in xrange(Nx):
|
|
|
|
for j in xrange(Ny):
|
2015-10-02 05:51:23 +05:30
|
|
|
grid[0] = round((i+0.5)*box[0]*info['grid'][0]/Nx-0.5)+offset[0]
|
|
|
|
grid[1] = round((j+0.5)*box[1]*info['grid'][1]/Ny-0.5)+offset[1]
|
|
|
|
damask.util.croak('x,y coord on surface: {},{}...'.format(*grid[:2]))
|
2015-06-05 17:11:44 +05:30
|
|
|
for k in xrange(Nz):
|
2015-10-02 05:51:23 +05:30
|
|
|
grid[2] = k + offset[2]
|
2015-06-05 17:11:44 +05:30
|
|
|
grid %= info['grid']
|
2015-09-30 04:05:57 +05:30
|
|
|
seeds[n,0:3] = (0.5+grid)/info['grid'] # normalize coordinates to box
|
2015-06-05 17:11:44 +05:30
|
|
|
seeds[n, 3] = microstructure[grid[0],grid[1],grid[2]]
|
|
|
|
if options.x: grid[0] += 1
|
|
|
|
if options.y: grid[1] += 1
|
|
|
|
n += 1
|
|
|
|
|
|
|
|
newInfo['microstructures'] = len(np.unique(seeds[:,3]))
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- report ---------------------------------------------------------------------------------------
|
2016-03-03 19:14:51 +05:30
|
|
|
if (newInfo['microstructures'] != info['microstructures']):
|
2016-03-03 19:28:04 +05:30
|
|
|
damask.util.croak('--> microstructures: %i'%newInfo['microstructures'])
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
|
|
|
table.info_clear()
|
|
|
|
table.info_append(extra_header+[
|
|
|
|
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
2015-08-21 01:12:05 +05:30
|
|
|
"poking\ta {}\tb {}\tc {}".format(Nx,Ny,Nz),
|
2015-10-02 05:51:23 +05:30
|
|
|
"grid\ta {}\tb {}\tc {}".format(*info['grid']),
|
|
|
|
"size\tx {}\ty {}\tz {}".format(*info['size']),
|
|
|
|
"origin\tx {}\ty {}\tz {}".format(*info['origin']),
|
2015-08-21 01:12:05 +05:30
|
|
|
"homogenization\t{}".format(info['homogenization']),
|
|
|
|
"microstructures\t{}".format(newInfo['microstructures']),
|
2015-06-05 17:11:44 +05:30
|
|
|
])
|
2015-08-08 00:33:26 +05:30
|
|
|
table.labels_clear()
|
|
|
|
table.labels_append(['{dim}_{label}'.format(dim = 1+i,label = options.position) for i in range(3)]+['microstructure'])
|
|
|
|
table.head_write()
|
|
|
|
table.output_flush()
|
|
|
|
|
|
|
|
# --- write seeds information ------------------------------------------------------------
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-09-24 18:51:44 +05:30
|
|
|
table.data = seeds
|
|
|
|
table.data_writeArray()
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# --- output finalization --------------------------------------------------------------------------
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close() # close ASCII table
|