relying on central functionality improves readability

This commit is contained in:
Martin Diehl 2019-12-08 11:25:33 +01:00
parent f19694f734
commit 75e93d9f0c
2 changed files with 45 additions and 65 deletions

View File

@ -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')

View File

@ -53,16 +53,6 @@ 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,
outname = os.path.splitext(name)[-2]+'_poked_{}.seeds'.format(options.N) if name else name,
buffered = False, labeled = False)
table.head_read()
info,extra_header = table.head_getGeom()
grid = info['grid']
size = info['size']
offset =(np.amin(options.box, axis=1)*geom.grid/geom.size).astype(int) offset =(np.amin(options.box, axis=1)*geom.grid/geom.size).astype(int)
box = np.amax(options.box, axis=1) \ box = np.amax(options.box, axis=1) \
- np.amin(options.box, axis=1) - np.amin(options.box, axis=1)
@ -79,38 +69,26 @@ for name in filenames:
n = 0 n = 0
for i in range(Nx): for i in range(Nx):
for j in range(Ny): for j in range(Ny):
g[0] = round((i+0.5)*box[0]*grid[0]/Nx-0.5)+offset[0] g[0] = round((i+0.5)*box[0]*geom.grid[0]/Nx-0.5)+offset[0]
g[1] = round((j+0.5)*box[1]*grid[1]/Ny-0.5)+offset[1] g[1] = round((j+0.5)*box[1]*geom.grid[1]/Ny-0.5)+offset[1]
for k in range(Nz): for k in range(Nz):
g[2] = k + offset[2] g[2] = k + offset[2]
g %= grid g %= geom.grid
seeds[n,0:3] = (g+0.5)/grid # normalize coordinates to box seeds[n,0:3] = (g+0.5)/geom.grid # normalize coordinates to box
seeds[n, 3] = geom.microstructure[g[0],g[1],g[2]] seeds[n, 3] = geom.microstructure[g[0],g[1],g[2]]
if options.x: g[0] += 1 if options.x: g[0] += 1
if options.y: g[1] += 1 if options.y: g[1] += 1
n += 1 n += 1
# ------------------------------------------ assemble header --------------------------------------- comments = geom.comments \
table.info_clear() + [scriptID + ' ' + ' '.join(sys.argv[1:]),
table.info_append(geom.comments+[
scriptID + ' ' + ' '.join(sys.argv[1:]),
"poking\ta {}\tb {}\tc {}".format(Nx,Ny,Nz), "poking\ta {}\tb {}\tc {}".format(Nx,Ny,Nz),
"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(info['homogenization']), "homogenization\t{}".format(geom.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