relying on central functionality improves readability
This commit is contained in:
parent
f19694f734
commit
75e93d9f0c
|
@ -58,11 +58,13 @@ for name in filenames:
|
||||||
microstructure),
|
microstructure),
|
||||||
axis=1)[mask]
|
axis=1)[mask]
|
||||||
|
|
||||||
comments = [scriptID + ' ' + ' '.join(sys.argv[1:]),
|
comments = geom.comments \
|
||||||
|
+ [scriptID + ' ' + ' '.join(sys.argv[1:]),
|
||||||
"grid\ta {}\tb {}\tc {}".format(*geom.grid),
|
"grid\ta {}\tb {}\tc {}".format(*geom.grid),
|
||||||
"size\tx {}\ty {}\tz {}".format(*geom.size),
|
"size\tx {}\ty {}\tz {}".format(*geom.size),
|
||||||
"origin\tx {}\ty {}\tz {}".format(*geom.origin),
|
"origin\tx {}\ty {}\tz {}".format(*geom.origin),
|
||||||
"homogenization\t{}".format(geom.homogenization)]
|
"homogenization\t{}".format(geom.homogenization)]
|
||||||
|
|
||||||
table = damask.Table(seeds,{'pos':(3,),'microstructure':(1,)},comments)
|
table = damask.Table(seeds,{'pos':(3,),'microstructure':(1,)},comments)
|
||||||
table.to_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.seeds')
|
table.to_ASCII(sys.stdout if name is None else \
|
||||||
|
os.path.splitext(name)[0]+'.seeds')
|
||||||
|
|
|
@ -50,67 +50,45 @@ if filenames == []: filenames = [None]
|
||||||
options.box = np.array(options.box).reshape(3,2)
|
options.box = np.array(options.box).reshape(3,2)
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
|
|
||||||
table = damask.ASCIItable(name = name,
|
offset =(np.amin(options.box, axis=1)*geom.grid/geom.size).astype(int)
|
||||||
outname = os.path.splitext(name)[-2]+'_poked_{}.seeds'.format(options.N) if name else name,
|
box = np.amax(options.box, axis=1) \
|
||||||
buffered = False, labeled = False)
|
- np.amin(options.box, axis=1)
|
||||||
|
|
||||||
table.head_read()
|
Nx = int(options.N/np.sqrt(options.N*geom.size[1]*box[1]/geom.size[0]/box[0]))
|
||||||
info,extra_header = table.head_getGeom()
|
Ny = int(options.N/np.sqrt(options.N*geom.size[0]*box[0]/geom.size[1]/box[1]))
|
||||||
|
Nz = int(box[2]*geom.grid[2])
|
||||||
|
|
||||||
grid = info['grid']
|
damask.util.croak('poking {} x {} x {} in box {} {} {}...'.format(Nx,Ny,Nz,*box))
|
||||||
size = info['size']
|
|
||||||
|
|
||||||
offset =(np.amin(options.box, axis=1)*geom.grid/geom.size).astype(int)
|
seeds = np.zeros((Nx*Ny*Nz,4),'d')
|
||||||
box = np.amax(options.box, axis=1) \
|
g = np.zeros(3,'i')
|
||||||
- np.amin(options.box, axis=1)
|
|
||||||
|
|
||||||
Nx = int(options.N/np.sqrt(options.N*geom.size[1]*box[1]/geom.size[0]/box[0]))
|
n = 0
|
||||||
Ny = int(options.N/np.sqrt(options.N*geom.size[0]*box[0]/geom.size[1]/box[1]))
|
for i in range(Nx):
|
||||||
Nz = int(box[2]*geom.grid[2])
|
for j in range(Ny):
|
||||||
|
g[0] = round((i+0.5)*box[0]*geom.grid[0]/Nx-0.5)+offset[0]
|
||||||
damask.util.croak('poking {} x {} x {} in box {} {} {}...'.format(Nx,Ny,Nz,*box))
|
g[1] = round((j+0.5)*box[1]*geom.grid[1]/Ny-0.5)+offset[1]
|
||||||
|
for k in range(Nz):
|
||||||
seeds = np.zeros((Nx*Ny*Nz,4),'d')
|
g[2] = k + offset[2]
|
||||||
g = np.zeros(3,'i')
|
g %= geom.grid
|
||||||
|
seeds[n,0:3] = (g+0.5)/geom.grid # normalize coordinates to box
|
||||||
n = 0
|
seeds[n, 3] = geom.microstructure[g[0],g[1],g[2]]
|
||||||
for i in range(Nx):
|
if options.x: g[0] += 1
|
||||||
for j in range(Ny):
|
if options.y: g[1] += 1
|
||||||
g[0] = round((i+0.5)*box[0]*grid[0]/Nx-0.5)+offset[0]
|
n += 1
|
||||||
g[1] = round((j+0.5)*box[1]*grid[1]/Ny-0.5)+offset[1]
|
|
||||||
for k in range(Nz):
|
|
||||||
g[2] = k + offset[2]
|
|
||||||
g %= grid
|
|
||||||
seeds[n,0:3] = (g+0.5)/grid # normalize coordinates to box
|
|
||||||
seeds[n, 3] = geom.microstructure[g[0],g[1],g[2]]
|
|
||||||
if options.x: g[0] += 1
|
|
||||||
if options.y: g[1] += 1
|
|
||||||
n += 1
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
comments = geom.comments \
|
||||||
table.info_clear()
|
+ [scriptID + ' ' + ' '.join(sys.argv[1:]),
|
||||||
table.info_append(geom.comments+[
|
"poking\ta {}\tb {}\tc {}".format(Nx,Ny,Nz),
|
||||||
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
"grid\ta {}\tb {}\tc {}".format(*geom.grid),
|
||||||
"poking\ta {}\tb {}\tc {}".format(Nx,Ny,Nz),
|
"size\tx {}\ty {}\tz {}".format(*geom.size),
|
||||||
"grid\ta {}\tb {}\tc {}".format(*geom.grid),
|
"origin\tx {}\ty {}\tz {}".format(*geom.origin),
|
||||||
"size\tx {}\ty {}\tz {}".format(*geom.size),
|
"homogenization\t{}".format(geom.homogenization)]
|
||||||
"origin\tx {}\ty {}\tz {}".format(*geom.origin),
|
|
||||||
"homogenization\t{}".format(info['homogenization']),
|
|
||||||
])
|
|
||||||
table.labels_clear()
|
|
||||||
table.labels_append(['{dim}_{label}'.format(dim = 1+i,label = 'pos') for i in range(3)]+['microstructure'])
|
|
||||||
table.head_write()
|
|
||||||
table.output_flush()
|
|
||||||
|
|
||||||
# --- write seeds information ------------------------------------------------------------
|
table = damask.Table(seeds,{'pos':(3,),'microstructure':(1,)},comments)
|
||||||
|
table.to_ASCII(sys.stdout if name is None else \
|
||||||
table.data = seeds
|
os.path.splitext(name)[0]+'_poked_{}.seeds'.format(options.N))
|
||||||
table.data_writeArray()
|
|
||||||
|
|
||||||
# --- output finalization --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
table.close() # close ASCII table
|
|
||||||
|
|
Loading…
Reference in New Issue