do not repeat code
This commit is contained in:
parent
fe463515d0
commit
cde6853a20
|
@ -39,61 +39,36 @@ for filename in options.filenames:
|
||||||
results = damask.DADF5(filename)
|
results = damask.DADF5(filename)
|
||||||
|
|
||||||
if not results.structured: continue
|
if not results.structured: continue
|
||||||
delta = results.size/results.grid*0.5
|
if results.version_major == 0 and results.version_minor >= 5:
|
||||||
x, y, z = np.meshgrid(np.linspace(delta[2],results.size[2]-delta[2],results.grid[2]),
|
coords = damask.grid_filters.cell_coord0(results.grid,results.size,results.origin)
|
||||||
np.linspace(delta[1],results.size[1]-delta[1],results.grid[1]),
|
else:
|
||||||
np.linspace(delta[0],results.size[0]-delta[0],results.grid[0]),
|
coords = damask.grid_filters.cell_coord0(results.grid,results.size)
|
||||||
indexing = 'ij')
|
|
||||||
|
|
||||||
coords = np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
|
|
||||||
|
|
||||||
N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
|
N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
|
||||||
N_digits = 5 # hack to keep test intact
|
N_digits = 5 # hack to keep test intact
|
||||||
for i,inc in enumerate(results.iter_visible('increments')):
|
for i,inc in enumerate(results.iter_visible('increments')):
|
||||||
print('Output step {}/{}'.format(i+1,len(results.increments)))
|
print('Output step {}/{}'.format(i+1,len(results.increments)))
|
||||||
|
|
||||||
header = '1 header\n'
|
table = damask.Table(np.ones(np.product(results.grid),dtype=int)*int(inc[3:]),{'inc':(1,)})
|
||||||
|
table.add('pos',coords.reshape((-1,3)))
|
||||||
data = np.array([int(inc[3:]) for j in range(np.product(results.grid))]).reshape([np.product(results.grid),1])
|
|
||||||
header+= 'inc'
|
|
||||||
|
|
||||||
coords = coords.reshape([np.product(results.grid),3])
|
|
||||||
data = np.concatenate((data,coords),1)
|
|
||||||
header+=' 1_pos 2_pos 3_pos'
|
|
||||||
|
|
||||||
results.set_visible('materialpoints',False)
|
results.set_visible('materialpoints',False)
|
||||||
results.set_visible('constituents', True)
|
results.set_visible('constituents', True)
|
||||||
for label in options.con:
|
for label in options.con:
|
||||||
x = results.get_dataset_location(label)
|
x = results.get_dataset_location(label)
|
||||||
if len(x) == 0:
|
if len(x) != 0:
|
||||||
continue
|
table.add(label,results.read_dataset(x,0,plain=True).reshape((results.grid.prod(),-1)))
|
||||||
array = results.read_dataset(x,0,plain=True)
|
|
||||||
d = np.product(np.shape(array)[1:])
|
|
||||||
data = np.concatenate((data,np.reshape(array,[np.product(results.grid),d])),1)
|
|
||||||
|
|
||||||
if d>1:
|
|
||||||
header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)])
|
|
||||||
else:
|
|
||||||
header+=' '+label
|
|
||||||
|
|
||||||
results.set_visible('constituents', False)
|
results.set_visible('constituents', False)
|
||||||
results.set_visible('materialpoints',True)
|
results.set_visible('materialpoints',True)
|
||||||
for label in options.mat:
|
for label in options.mat:
|
||||||
x = results.get_dataset_location(label)
|
x = results.get_dataset_location(label)
|
||||||
if len(x) == 0:
|
if len(x) != 0:
|
||||||
continue
|
table.add(label,results.read_dataset(x,0,plain=True).reshape((results.grid.prod(),-1)))
|
||||||
array = results.read_dataset(x,0,plain=True)
|
|
||||||
d = np.product(np.shape(array)[1:])
|
|
||||||
data = np.concatenate((data,np.reshape(array,[np.product(results.grid),d])),1)
|
|
||||||
|
|
||||||
if d>1:
|
|
||||||
header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)])
|
|
||||||
else:
|
|
||||||
header+=' '+label
|
|
||||||
|
|
||||||
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.mkdir(dirname,0o755)
|
os.mkdir(dirname,0o755)
|
||||||
file_out = '{}_inc{}.txt'.format(os.path.splitext(os.path.split(filename)[-1])[0],
|
file_out = '{}_inc{}.txt'.format(os.path.splitext(os.path.split(filename)[-1])[0],
|
||||||
inc[3:].zfill(N_digits))
|
inc[3:].zfill(N_digits))
|
||||||
np.savetxt(os.path.join(dirname,file_out),data,header=header,comments='')
|
table.to_ASCII(os.path.join(dirname,file_out))
|
||||||
|
|
Loading…
Reference in New Issue