2018-11-17 13:16:58 +05:30
|
|
|
#!/usr/bin/env python3
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2019-12-08 15:30:38 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-08 22:51:16 +05:30
|
|
|
from io import StringIO
|
2019-12-08 15:30:38 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
2015-09-24 18:51:44 +05:30
|
|
|
import numpy as np
|
2019-12-08 15:30:38 +05:30
|
|
|
|
2015-06-05 17:11:44 +05:30
|
|
|
import damask
|
|
|
|
|
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
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2020-11-14 23:30:51 +05:30
|
|
|
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
2015-06-05 17:11:44 +05:30
|
|
|
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',
|
2020-03-20 10:54:41 +05:30
|
|
|
dest = 'x',
|
2015-08-08 00:33:26 +05:30
|
|
|
help = 'poke 45 deg along x')
|
|
|
|
parser.add_option('-y',
|
|
|
|
action = 'store_true',
|
|
|
|
dest = 'y',
|
|
|
|
help = 'poke 45 deg along y')
|
|
|
|
|
|
|
|
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,
|
|
|
|
)
|
2015-06-05 17:11:44 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2019-12-08 15:30:38 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-06-05 17:11:44 +05:30
|
|
|
|
2015-10-02 05:51:23 +05:30
|
|
|
options.box = np.array(options.box).reshape(3,2)
|
|
|
|
|
2015-06-05 17:11:44 +05:30
|
|
|
for name in filenames:
|
2019-12-08 15:55:33 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2020-09-15 10:28:06 +05:30
|
|
|
geom = damask.Geom.load_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2020-03-20 10:54:41 +05:30
|
|
|
|
2020-12-04 02:28:24 +05:30
|
|
|
offset =(np.amin(options.box, axis=1)*geom.cells/geom.size).astype(int)
|
2019-12-08 15:55:33 +05:30
|
|
|
box = np.amax(options.box, axis=1) \
|
|
|
|
- np.amin(options.box, axis=1)
|
2020-03-20 10:54:41 +05:30
|
|
|
|
2019-12-08 15:55:33 +05:30
|
|
|
Nx = int(options.N/np.sqrt(options.N*geom.size[1]*box[1]/geom.size[0]/box[0]))
|
|
|
|
Ny = int(options.N/np.sqrt(options.N*geom.size[0]*box[0]/geom.size[1]/box[1]))
|
2020-12-04 02:28:24 +05:30
|
|
|
Nz = int(box[2]*geom.cells[2])
|
2020-03-20 10:54:41 +05:30
|
|
|
|
2019-12-08 15:55:33 +05:30
|
|
|
damask.util.croak('poking {} x {} x {} in box {} {} {}...'.format(Nx,Ny,Nz,*box))
|
2020-03-20 10:54:41 +05:30
|
|
|
|
|
|
|
seeds = np.zeros((Nx*Ny*Nz,4))
|
|
|
|
g = np.zeros(3,dtype=np.int)
|
|
|
|
|
2019-12-08 15:55:33 +05:30
|
|
|
n = 0
|
|
|
|
for i in range(Nx):
|
|
|
|
for j in range(Ny):
|
2020-12-04 02:28:24 +05:30
|
|
|
g[0] = round((i+0.5)*box[0]*geom.cells[0]/Nx-0.5)+offset[0]
|
|
|
|
g[1] = round((j+0.5)*box[1]*geom.cells[1]/Ny-0.5)+offset[1]
|
2019-12-08 15:55:33 +05:30
|
|
|
for k in range(Nz):
|
|
|
|
g[2] = k + offset[2]
|
2020-12-04 02:28:24 +05:30
|
|
|
g %= geom.cells
|
|
|
|
seeds[n,0:3] = (g+0.5)/geom.cells # normalize coordinates to box
|
2020-09-24 02:57:15 +05:30
|
|
|
seeds[n, 3] = geom.material[g[0],g[1],g[2]]
|
2019-12-08 15:55:33 +05:30
|
|
|
if options.x: g[0] += 1
|
|
|
|
if options.y: g[1] += 1
|
|
|
|
n += 1
|
2020-03-20 10:54:41 +05:30
|
|
|
|
|
|
|
|
2019-12-08 15:55:33 +05:30
|
|
|
comments = geom.comments \
|
|
|
|
+ [scriptID + ' ' + ' '.join(sys.argv[1:]),
|
2020-03-20 10:54:41 +05:30
|
|
|
'poking\ta {}\tb {}\tc {}'.format(Nx,Ny,Nz),
|
2020-12-04 02:28:24 +05:30
|
|
|
'grid\ta {}\tb {}\tc {}'.format(*geom.cells),
|
2020-03-20 10:54:41 +05:30
|
|
|
'size\tx {}\ty {}\tz {}'.format(*geom.size),
|
|
|
|
'origin\tx {}\ty {}\tz {}'.format(*geom.origin),
|
2020-09-23 05:33:41 +05:30
|
|
|
]
|
2020-03-20 10:54:41 +05:30
|
|
|
|
2020-09-23 05:33:41 +05:30
|
|
|
table = damask.Table(seeds,{'pos':(3,),'material':(1,)},comments)
|
|
|
|
table.set('material',table.get('material').astype(np.int))\
|
2020-09-21 00:15:06 +05:30
|
|
|
.save(sys.stdout if name is None else \
|
2020-09-16 08:08:50 +05:30
|
|
|
os.path.splitext(name)[0]+f'_poked_{options.N}.seeds',legacy=True)
|