using geom class
- dropped the use of the material class as it does not allow to have empty phase and crystallite. The material.config class needs a severe refurbishing (no crystallite, use orderedDict instead of hand written solution, drop of texture components). Probably best solution is to postpone this until we have a yaml/json reader for Fortran.
This commit is contained in:
parent
7d07a3752f
commit
8380071564
|
@ -1,11 +1,15 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os,sys,h5py
|
import os
|
||||||
import numpy as np
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import h5py
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import damask
|
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])
|
||||||
|
|
||||||
|
@ -14,40 +18,50 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
# MAIN
|
# MAIN
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [dream3dfile[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [DREAM.3Dfile(s)]', description = """
|
||||||
Convert DREAM3D file to geometry file. This can be done from cell data (direct pointwise takeover) or
|
Converts DREAM.3D file. Input can be cell data (direct pointwise takeover) or grain data (individual
|
||||||
from grain data (individual grains are segmented). Requires orientation data as quaternion.
|
grains are segmented). Requires orientation data as quaternion.
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-b','--basegroup',
|
parser.add_option('-b','--basegroup',
|
||||||
dest = 'basegroup', metavar = 'string',
|
dest = 'basegroup',
|
||||||
|
metavar = 'string',
|
||||||
help = 'name of the group in "DataContainers" containing the pointwise (and, if applicable grain average) data')
|
help = 'name of the group in "DataContainers" containing the pointwise (and, if applicable grain average) data')
|
||||||
parser.add_option('-p','--pointwise',
|
parser.add_option('-p','--pointwise',
|
||||||
dest = 'pointwise', metavar = 'string',
|
dest = 'pointwise',
|
||||||
|
metavar = 'string',
|
||||||
help = 'name of the group in "DataContainers/<basegroup>" containing pointwise data [%default]')
|
help = 'name of the group in "DataContainers/<basegroup>" containing pointwise data [%default]')
|
||||||
parser.add_option('-a','--average',
|
parser.add_option('-a','--average',
|
||||||
dest = 'average', metavar = 'string',
|
dest = 'average',
|
||||||
|
metavar = 'string',
|
||||||
help = 'name of the group in "DataContainers</basegroup>" containing grain average data. '\
|
help = 'name of the group in "DataContainers</basegroup>" containing grain average data. '\
|
||||||
+ 'Leave empty for pointwise data')
|
+ 'Leave empty for pointwise data')
|
||||||
parser.add_option('--phase',
|
parser.add_option('--phase',
|
||||||
dest = 'phase',
|
dest = 'phase',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string',
|
||||||
|
metavar = 'string',
|
||||||
help = 'name of the dataset containing pointwise/average phase IDs [%default]')
|
help = 'name of the dataset containing pointwise/average phase IDs [%default]')
|
||||||
parser.add_option('--microstructure',
|
parser.add_option('--microstructure',
|
||||||
dest = 'microstructure',
|
dest = 'microstructure',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string',
|
||||||
|
metavar = 'string',
|
||||||
help = 'name of the dataset connecting pointwise and average data [%default]')
|
help = 'name of the dataset connecting pointwise and average data [%default]')
|
||||||
parser.add_option('-q', '--quaternion',
|
parser.add_option('-q', '--quaternion',
|
||||||
dest = 'quaternion',
|
dest = 'quaternion',
|
||||||
type = 'string', metavar='string',
|
type = 'string',
|
||||||
|
metavar='string',
|
||||||
help = 'name of the dataset containing pointwise/average orientation as quaternion [%default]')
|
help = 'name of the dataset containing pointwise/average orientation as quaternion [%default]')
|
||||||
|
parser.add_option('--homogenization',
|
||||||
|
dest = 'homogenization',
|
||||||
|
type = 'int', metavar = 'int',
|
||||||
|
help = 'homogenization index to be used [%default]')
|
||||||
|
|
||||||
parser.set_defaults(pointwise = 'CellData',
|
parser.set_defaults(pointwise = 'CellData',
|
||||||
quaternion = 'Quats',
|
quaternion = 'Quats',
|
||||||
phase = 'Phases',
|
phase = 'Phases',
|
||||||
microstructure = 'FeatureIds',
|
microstructure = 'FeatureIds',
|
||||||
crystallite = 1,
|
homogenization = 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
@ -57,67 +71,59 @@ if options.basegroup is None:
|
||||||
|
|
||||||
rootDir ='DataContainers'
|
rootDir ='DataContainers'
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
if filenames == []: parser.error('no input file specified.')
|
if filenames == []: parser.error('no input file specified.')
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
|
||||||
table = damask.ASCIItable(outname = os.path.splitext(name)[0]+'.geom',
|
|
||||||
buffered = False, labeled=False,
|
|
||||||
)
|
|
||||||
except: continue
|
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
info = {}
|
|
||||||
ori = []
|
|
||||||
inFile = h5py.File(name, 'r')
|
inFile = h5py.File(name, 'r')
|
||||||
group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY')
|
group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY')
|
||||||
try:
|
try:
|
||||||
info['size'] = inFile[os.path.join(group_geom,'DIMENSIONS')][...] \
|
size = inFile[os.path.join(group_geom,'DIMENSIONS')][...] \
|
||||||
* inFile[os.path.join(group_geom,'SPACING')][...]
|
* inFile[os.path.join(group_geom,'SPACING')][...]
|
||||||
info['grid'] = inFile[os.path.join(group_geom,'DIMENSIONS')][...]
|
grid = inFile[os.path.join(group_geom,'DIMENSIONS')][...]
|
||||||
info['origin'] = inFile[os.path.join(group_geom,'ORIGIN')][...]
|
origin = inFile[os.path.join(group_geom,'ORIGIN')][...]
|
||||||
except:
|
except:
|
||||||
errors.append('Geometry data ({}) not found'.format(group_geom))
|
errors.append('Geometry data ({}) not found'.format(group_geom))
|
||||||
|
|
||||||
|
|
||||||
group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise)
|
group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise)
|
||||||
if options.average is None:
|
if options.average is None:
|
||||||
label = 'point'
|
label = 'Point'
|
||||||
N_microstructure = np.product(info['grid'])
|
|
||||||
|
|
||||||
dataset = os.path.join(group_pointwise,options.quaternion)
|
dataset = os.path.join(group_pointwise,options.quaternion)
|
||||||
try:
|
try:
|
||||||
quats = np.reshape(inFile[dataset][...],(N_microstructure,4))
|
quats = np.reshape(inFile[dataset][...],(np.product(grid),4))
|
||||||
texture = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats]
|
rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats]
|
||||||
except:
|
except:
|
||||||
errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset))
|
errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset))
|
||||||
|
|
||||||
dataset = os.path.join(group_pointwise,options.phase)
|
dataset = os.path.join(group_pointwise,options.phase)
|
||||||
try:
|
try:
|
||||||
phase = np.reshape(inFile[dataset][...],(N_microstructure))
|
phase = np.reshape(inFile[dataset][...],(np.product(grid)))
|
||||||
except:
|
except:
|
||||||
errors.append('Pointwise phase data ({}) not readable'.format(dataset))
|
errors.append('Pointwise phase data ({}) not readable'.format(dataset))
|
||||||
|
|
||||||
|
microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F')
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
label = 'grain'
|
label = 'Grain'
|
||||||
|
|
||||||
dataset = os.path.join(group_pointwise,options.microstructure)
|
dataset = os.path.join(group_pointwise,options.microstructure)
|
||||||
try:
|
try:
|
||||||
microstructure = np.reshape(inFile[dataset][...],(np.product(info['grid'])))
|
microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering
|
||||||
N_microstructure = np.max(microstructure)
|
|
||||||
except:
|
except:
|
||||||
errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset))
|
errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset))
|
||||||
|
|
||||||
group_average = os.path.join(rootDir,options.basegroup,options.average)
|
group_average = os.path.join(rootDir,options.basegroup,options.average)
|
||||||
|
|
||||||
dataset = os.path.join(group_average,options.quaternion)
|
dataset = os.path.join(group_average,options.quaternion)
|
||||||
try:
|
try:
|
||||||
texture = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
|
rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
|
||||||
except:
|
except:
|
||||||
errors.append('Average orientation data ({}) not readable'.format(dataset))
|
errors.append('Average orientation data ({}) not readable'.format(dataset))
|
||||||
|
|
||||||
|
@ -129,60 +135,25 @@ for name in filenames:
|
||||||
|
|
||||||
if errors != []:
|
if errors != []:
|
||||||
damask.util.croak(errors)
|
damask.util.croak(errors)
|
||||||
table.close(dismiss = True)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
config_header = ['<microstructure>']
|
||||||
|
for i in range(np.nanmax(microstructure)):
|
||||||
|
config_header += ['[{}{}]'.format(label,i+1),
|
||||||
|
'crystallite 1',
|
||||||
|
'(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1),
|
||||||
|
]
|
||||||
|
|
||||||
|
config_header += ['<texture>']
|
||||||
|
for i in range(np.nanmax(microstructure)):
|
||||||
|
config_header += ['[{}{}]'.format(label,i+1),
|
||||||
|
'(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*rot[i].asEulers(degrees = True)),
|
||||||
|
]
|
||||||
|
|
||||||
mat = damask.Material()
|
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
|
||||||
mat.verbose = False
|
+ config_header
|
||||||
|
geom = damask.Geom(microstructure,size,origin,
|
||||||
|
homogenization=options.homogenization,comments=header)
|
||||||
|
damask.util.croak(geom)
|
||||||
|
|
||||||
# dummy <homogenization>
|
geom.to_file(os.path.splitext(name)[0]+'.geom')
|
||||||
h = damask.config.material.Homogenization()
|
|
||||||
mat.add_section('Homogenization','none',h)
|
|
||||||
info['homogenization'] = 1
|
|
||||||
|
|
||||||
# <crystallite> placeholder (same for all microstructures at the moment)
|
|
||||||
c = damask.config.material.Crystallite()
|
|
||||||
mat.add_section('Crystallite','tbd',c)
|
|
||||||
|
|
||||||
# <phase> placeholders
|
|
||||||
for i in range(np.max(phase)):
|
|
||||||
p = damask.config.material.Phase()
|
|
||||||
mat.add_section('phase','phase{}-tbd'.format(i+1),p)
|
|
||||||
|
|
||||||
# <texture>
|
|
||||||
for i,o in enumerate(texture):
|
|
||||||
t = damask.config.material.Texture()
|
|
||||||
t.add_component('gauss',{'eulers':o.asEulers(degrees=True)})
|
|
||||||
mat.add_section(part='texture', section='{}{}'.format(label,i+1),initialData=t)
|
|
||||||
|
|
||||||
# <microstructure>
|
|
||||||
for i in range(N_microstructure):
|
|
||||||
m = damask.config.material.Microstructure()
|
|
||||||
mat.add_section('microstructure','{}{}'.format(label,i+1),m)
|
|
||||||
mat.add_microstructure('{}{}'.format(label,i+1),
|
|
||||||
{'phase': 'phase{}-tbd'.format(phase[i]),
|
|
||||||
'texture':'{}{}'.format(label,i+1),
|
|
||||||
'crystallite':'tbd',
|
|
||||||
'fraction':1
|
|
||||||
})
|
|
||||||
|
|
||||||
table.info_append([
|
|
||||||
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
|
||||||
"grid\ta {}\tb {}\tc {}".format(*info['grid']),
|
|
||||||
"size\tx {}\ty {}\tz {}".format(*info['size']),
|
|
||||||
"origin\tx {}\ty {}\tz {}".format(*info['origin']),
|
|
||||||
"homogenization\t{}".format(info['homogenization']),
|
|
||||||
str(mat).split('\n')
|
|
||||||
])
|
|
||||||
table.head_write()
|
|
||||||
|
|
||||||
if options.average is None:
|
|
||||||
table.data = [1, 'to', format(N_microstructure)]
|
|
||||||
table.data_write()
|
|
||||||
else:
|
|
||||||
table.data = microstructure.reshape(info['grid'][1]*info['grid'][2],info['grid'][0])
|
|
||||||
table.data_writeArray()
|
|
||||||
|
|
||||||
|
|
||||||
table.close()
|
|
||||||
|
|
Loading…
Reference in New Issue