preparing transition to Geom and Table classes
This commit is contained in:
parent
871ff4c218
commit
0292e8fcc7
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os,math,sys
|
import os
|
||||||
import numpy as np
|
import sys
|
||||||
import damask
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
@ -35,109 +37,73 @@ parser.add_option('-y',
|
||||||
action = 'store_true',
|
action = 'store_true',
|
||||||
dest = 'y',
|
dest = 'y',
|
||||||
help = 'poke 45 deg along 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,
|
parser.set_defaults(x = False,
|
||||||
y = False,
|
y = False,
|
||||||
box = [0.0,1.0,0.0,1.0,0.0,1.0],
|
box = [0.0,1.0,0.0,1.0,0.0,1.0],
|
||||||
N = 16,
|
N = 16,
|
||||||
position = 'pos',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
options.box = np.array(options.box).reshape(3,2)
|
options.box = np.array(options.box).reshape(3,2)
|
||||||
|
|
||||||
# --- loop over output files -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
|
||||||
table = damask.ASCIItable(name = name,
|
table = damask.ASCIItable(name = name,
|
||||||
outname = os.path.splitext(name)[-2]+'_poked_{}.seeds'.format(options.N) if name else name,
|
outname = os.path.splitext(name)[-2]+'_poked_{}.seeds'.format(options.N) if name else name,
|
||||||
buffered = False, labeled = False)
|
buffered = False, labeled = False)
|
||||||
except: continue
|
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
info,extra_header = table.head_getGeom()
|
info,extra_header = table.head_getGeom()
|
||||||
|
|
||||||
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
grid = info['grid']
|
||||||
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
size = info['size']
|
||||||
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
|
||||||
'homogenization: %i'%info['homogenization'],
|
|
||||||
'microstructures: %i'%info['microstructures'],
|
|
||||||
])
|
|
||||||
|
|
||||||
errors = []
|
microstructure = table.microstructure_read(grid).reshape(grid) # read microstructure
|
||||||
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 != []:
|
|
||||||
damask.util.croak(errors)
|
|
||||||
table.close(dismiss = True)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# --- read data ------------------------------------------------------------------------------------
|
offset =(np.amin(options.box, axis=1)*grid/size).astype(int)
|
||||||
|
box = np.amax(options.box, axis=1) \
|
||||||
|
- np.amin(options.box, axis=1)
|
||||||
|
|
||||||
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure
|
Nx = int(options.N/np.sqrt(options.N*size[1]*box[1]/size[0]/box[0]))
|
||||||
|
Ny = int(options.N/np.sqrt(options.N*size[0]*box[0]/size[1]/box[1]))
|
||||||
# --- do work ------------------------------------------------------------------------------------
|
Nz = int(box[2]*grid[2])
|
||||||
|
|
||||||
newInfo = {
|
|
||||||
'microstructures': 0,
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
|
|
||||||
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])
|
|
||||||
|
|
||||||
damask.util.croak('poking {} x {} x {} in box {} {} {}...'.format(Nx,Ny,Nz,*box))
|
damask.util.croak('poking {} x {} x {} in box {} {} {}...'.format(Nx,Ny,Nz,*box))
|
||||||
|
|
||||||
seeds = np.zeros((Nx*Ny*Nz,4),'d')
|
seeds = np.zeros((Nx*Ny*Nz,4),'d')
|
||||||
grid = np.zeros(3,'i')
|
g = np.zeros(3,'i')
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
for i in range(Nx):
|
for i in range(Nx):
|
||||||
for j in range(Ny):
|
for j in range(Ny):
|
||||||
grid[0] = round((i+0.5)*box[0]*info['grid'][0]/Nx-0.5)+offset[0]
|
g[0] = round((i+0.5)*box[0]*grid[0]/Nx-0.5)+offset[0]
|
||||||
grid[1] = round((j+0.5)*box[1]*info['grid'][1]/Ny-0.5)+offset[1]
|
g[1] = round((j+0.5)*box[1]*grid[1]/Ny-0.5)+offset[1]
|
||||||
for k in range(Nz):
|
for k in range(Nz):
|
||||||
grid[2] = k + offset[2]
|
g[2] = k + offset[2]
|
||||||
grid %= info['grid']
|
g %= grid
|
||||||
seeds[n,0:3] = (0.5+grid)/info['grid'] # normalize coordinates to box
|
seeds[n,0:3] = (g+0.5)/grid # normalize coordinates to box
|
||||||
seeds[n, 3] = microstructure[grid[0],grid[1],grid[2]]
|
seeds[n, 3] = microstructure[g[2],g[1],g[0]]
|
||||||
if options.x: grid[0] += 1
|
if options.x: g[0] += 1
|
||||||
if options.y: grid[1] += 1
|
if options.y: g[1] += 1
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
newInfo['microstructures'] = len(np.unique(seeds[:,3]))
|
|
||||||
|
|
||||||
# --- report ---------------------------------------------------------------------------------------
|
|
||||||
if (newInfo['microstructures'] != info['microstructures']):
|
|
||||||
damask.util.croak('--> microstructures: %i'%newInfo['microstructures'])
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
# ------------------------------------------ assemble header ---------------------------------------
|
||||||
table.info_clear()
|
table.info_clear()
|
||||||
table.info_append(extra_header+[
|
table.info_append(extra_header+[
|
||||||
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
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(*info['grid']),
|
"grid\ta {}\tb {}\tc {}".format(*grid),
|
||||||
"size\tx {}\ty {}\tz {}".format(*info['size']),
|
"size\tx {}\ty {}\tz {}".format(*size),
|
||||||
"origin\tx {}\ty {}\tz {}".format(*info['origin']),
|
"origin\tx {}\ty {}\tz {}".format(*info['origin']),
|
||||||
"homogenization\t{}".format(info['homogenization']),
|
"homogenization\t{}".format(info['homogenization']),
|
||||||
"microstructures\t{}".format(newInfo['microstructures']),
|
|
||||||
])
|
])
|
||||||
table.labels_clear()
|
table.labels_clear()
|
||||||
table.labels_append(['{dim}_{label}'.format(dim = 1+i,label = options.position) for i in range(3)]+['microstructure'])
|
table.labels_append(['{dim}_{label}'.format(dim = 1+i,label = 'pos') for i in range(3)]+['microstructure'])
|
||||||
table.head_write()
|
table.head_write()
|
||||||
table.output_flush()
|
table.output_flush()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue