removed Geom.homogenization from shell scripts

This commit is contained in:
Philip Eisenlohr 2020-09-22 20:03:41 -04:00
parent 683161d479
commit 997f7dfa05
10 changed files with 69 additions and 93 deletions

@ -1 +1 @@
Subproject commit fa2885da8604c3ac46f64670393f04678dd1f45b Subproject commit 86f77da4aec6cb52bbcc2724f00a6cf6a7dc6e91

View File

@ -52,16 +52,11 @@ parser.add_option('-q', '--quaternion',
type = 'string', type = 'string',
metavar='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',
homogenization = 1,
) )
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()
@ -150,8 +145,7 @@ for name in filenames:
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
+ config_header + config_header
geom = damask.Geom(microstructure,size,origin, geom = damask.Geom(microstructure,size,origin,comments=header)
homogenization=options.homogenization,comments=header)
damask.util.croak(geom) damask.util.croak(geom)
geom.save_ASCII(os.path.splitext(name)[0]+'.geom',compress=False) geom.save_ASCII(os.path.splitext(name)[0]+'.geom',compress=False)

View File

@ -52,10 +52,6 @@ parser.add_option('-p', '--periods',
dest = 'periods', dest = 'periods',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
help = 'number of repetitions of unit cell [%default]') help = 'number of repetitions of unit cell [%default]')
parser.add_option('--homogenization',
dest = 'homogenization',
type = 'int', metavar = 'int',
help = 'homogenization index to be used [%default]')
parser.add_option('--m', parser.add_option('--m',
dest = 'microstructure', dest = 'microstructure',
type = 'int', nargs = 2, metavar = 'int int', type = 'int', nargs = 2, metavar = 'int int',
@ -66,7 +62,6 @@ parser.set_defaults(type = minimal_surfaces[0],
periods = 1, periods = 1,
grid = (16,16,16), grid = (16,16,16),
size = (1.0,1.0,1.0), size = (1.0,1.0,1.0),
homogenization = 1,
microstructure = (1,2), microstructure = (1,2),
) )
@ -85,7 +80,6 @@ microstructure = np.where(options.threshold < surface[options.type](x,y,z),
options.microstructure[1],options.microstructure[0]) options.microstructure[1],options.microstructure[0])
geom=damask.Geom(microstructure,options.size, geom=damask.Geom(microstructure,options.size,
homogenization=options.homogenization,
comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) comments=[scriptID + ' ' + ' '.join(sys.argv[1:])])
damask.util.croak(geom) damask.util.croak(geom)

View File

@ -57,10 +57,6 @@ parser.add_option('-w', '--omega',
dest='omega', dest='omega',
type='float', metavar = 'float', type='float', metavar = 'float',
help='rotation angle around normal of osteon [%default]') help='rotation angle around normal of osteon [%default]')
parser.add_option( '--homogenization',
dest='homogenization',
type='int', metavar = 'int',
help='homogenization index to be used [%default]')
parser.set_defaults(canal = 25e-6, parser.set_defaults(canal = 25e-6,
osteon = 100e-6, osteon = 100e-6,
@ -70,7 +66,7 @@ parser.set_defaults(canal = 25e-6,
amplitude = 60, amplitude = 60,
size = (300e-6,300e-6), size = (300e-6,300e-6),
grid = (512,512), grid = (512,512),
homogenization = 1) )
(options,filename) = parser.parse_args() (options,filename) = parser.parse_args()
@ -139,7 +135,7 @@ header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
+ config_header + config_header
geom = damask.Geom(microstructure.reshape(grid), geom = damask.Geom(microstructure.reshape(grid),
size,-size/2, size,-size/2,
homogenization=options.homogenization,comments=header) comments=header)
damask.util.croak(geom) damask.util.croak(geom)
geom.save_ASCII(sys.stdout if name is None else name,compress=False) geom.save_ASCII(sys.stdout if name is None else name,compress=False)

View File

@ -44,14 +44,9 @@ parser.add_option('--axes',
dest = 'axes', dest = 'axes',
type = 'string', nargs = 3, metavar = ' '.join(['string']*3), type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
help = 'orientation coordinate frame in terms of position coordinate frame [+x +y +z]') help = 'orientation coordinate frame in terms of position coordinate frame [+x +y +z]')
parser.add_option('--homogenization',
dest = 'homogenization',
type = 'int', metavar = 'int',
help = 'homogenization index to be used [%default]')
parser.set_defaults(homogenization = 1, parser.set_defaults(pos = 'pos',
pos = 'pos',
) )
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
@ -102,7 +97,7 @@ for name in filenames:
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
+ config_header + config_header
geom = damask.Geom(microstructure,size,origin, geom = damask.Geom(microstructure,size,origin,
homogenization=options.homogenization,comments=header) comments=header)
damask.util.croak(geom) damask.util.croak(geom)
geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False) geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False)

View File

@ -142,10 +142,6 @@ group.add_option('--without-config',
dest = 'config', dest = 'config',
action = 'store_false', action = 'store_false',
help = 'omit material configuration header') help = 'omit material configuration header')
group.add_option('--homogenization',
dest = 'homogenization',
type = 'int', metavar = 'int',
help = 'homogenization index to be used [%default]')
group.add_option('--phase', group.add_option('--phase',
dest = 'phase', dest = 'phase',
type = 'int', metavar = 'int', type = 'int', metavar = 'int',
@ -157,7 +153,6 @@ parser.set_defaults(pos = 'pos',
weight = 'weight', weight = 'weight',
microstructure = 'microstructure', microstructure = 'microstructure',
eulers = 'euler', eulers = 'euler',
homogenization = 1,
phase = 1, phase = 1,
cpus = 2, cpus = 2,
laguerre = False, laguerre = False,
@ -225,7 +220,7 @@ for name in filenames:
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
+ config_header + config_header
geom = damask.Geom(indices.reshape(grid),size,origin, geom = damask.Geom(indices.reshape(grid),size,origin,
homogenization=options.homogenization,comments=header) comments=header)
damask.util.croak(geom) damask.util.croak(geom)
geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False) geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False)

View File

@ -41,7 +41,7 @@ parser.add_option('-N', '--iterations',
help = 'curvature flow iterations [%default]') help = 'curvature flow iterations [%default]')
parser.add_option('-i', '--immutable', parser.add_option('-i', '--immutable',
action = 'extend', dest = 'immutable', metavar = '<int LIST>', action = 'extend', dest = 'immutable', metavar = '<int LIST>',
help = 'list of immutable microstructure indices') help = 'list of immutable material indices')
parser.add_option('--ndimage', parser.add_option('--ndimage',
dest = 'ndimage', action='store_true', dest = 'ndimage', action='store_true',
help = 'use ndimage.gaussian_filter in lieu of explicit FFT') help = 'use ndimage.gaussian_filter in lieu of explicit FFT')
@ -66,13 +66,13 @@ for name in filenames:
grid_original = geom.grid grid_original = geom.grid
damask.util.croak(geom) damask.util.croak(geom)
microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 materials = np.tile(geom.materials,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1
grid = np.array(microstructure.shape) grid = np.array(materials.shape)
# --- initialize support data --------------------------------------------------------------------- # --- initialize support data ---------------------------------------------------------------------
# store a copy the initial microstructure to find locations of immutable indices # store a copy of the initial material indices to find locations of immutable indices
microstructure_original = np.copy(microstructure) materials_original = np.copy(materials)
if not options.ndimage: if not options.ndimage:
X,Y,Z = np.mgrid[0:grid[0],0:grid[1],0:grid[2]] X,Y,Z = np.mgrid[0:grid[0],0:grid[1],0:grid[2]]
@ -88,14 +88,14 @@ for name in filenames:
for smoothIter in range(options.N): for smoothIter in range(options.N):
interfaceEnergy = np.zeros(microstructure.shape,dtype=np.float32) interfaceEnergy = np.zeros(materials.shape,dtype=np.float32)
for i in (-1,0,1): for i in (-1,0,1):
for j in (-1,0,1): for j in (-1,0,1):
for k in (-1,0,1): for k in (-1,0,1):
# assign interfacial energy to all voxels that have a differing neighbor (in Moore neighborhood) # assign interfacial energy to all voxels that have a differing neighbor (in Moore neighborhood)
interfaceEnergy = np.maximum(interfaceEnergy, interfaceEnergy = np.maximum(interfaceEnergy,
getInterfaceEnergy(microstructure,np.roll(np.roll(np.roll( getInterfaceEnergy(materials,np.roll(np.roll(np.roll(
microstructure,i,axis=0), j,axis=1), k,axis=2))) materials,i,axis=0), j,axis=1), k,axis=2)))
# periodically extend interfacial energy array by half a grid size in positive and negative directions # periodically extend interfacial energy array by half a grid size in positive and negative directions
periodic_interfaceEnergy = np.tile(interfaceEnergy,(3,3,3))[grid[0]//2:-grid[0]//2, periodic_interfaceEnergy = np.tile(interfaceEnergy,(3,3,3))[grid[0]//2:-grid[0]//2,
@ -143,33 +143,35 @@ for name in filenames:
return_distances = False, return_distances = False,
return_indices = True) # want index of closest bulk grain return_indices = True) # want index of closest bulk grain
periodic_microstructure = np.tile(microstructure,(3,3,3))[grid[0]//2:-grid[0]//2, periodic_materials = np.tile(materials,(3,3,3))[grid[0]//2:-grid[0]//2,
grid[1]//2:-grid[1]//2, grid[1]//2:-grid[1]//2,
grid[2]//2:-grid[2]//2] # periodically extend the microstructure grid[2]//2:-grid[2]//2] # periodically extend the geometry
microstructure = periodic_microstructure[index[0], materials = periodic_materials[index[0],
index[1], index[1],
index[2]].reshape(2*grid)[grid[0]//2:-grid[0]//2, index[2]].reshape(2*grid)[grid[0]//2:-grid[0]//2,
grid[1]//2:-grid[1]//2, grid[1]//2:-grid[1]//2,
grid[2]//2:-grid[2]//2] # extent grains into interface region grid[2]//2:-grid[2]//2] # extent grains into interface region
# replace immutable microstructures with closest mutable ones # replace immutable materials with closest mutable ones
index = ndimage.morphology.distance_transform_edt(np.in1d(microstructure,options.immutable).reshape(grid), index = ndimage.morphology.distance_transform_edt(np.in1d(materials,options.immutable).reshape(grid),
return_distances = False, return_distances = False,
return_indices = True) return_indices = True)
microstructure = microstructure[index[0], materials = materials[index[0],
index[1], index[1],
index[2]] index[2]]
immutable = np.zeros(microstructure.shape, dtype=np.bool) immutable = np.zeros(materials.shape, dtype=np.bool)
# find locations where immutable microstructures have been in original structure # find locations where immutable materials have been in original structure
for micro in options.immutable: for micro in options.immutable:
immutable += microstructure_original == micro immutable += materials_original == micro
# undo any changes involving immutable microstructures # undo any changes involving immutable materials
microstructure = np.where(immutable, microstructure_original,microstructure) materials = np.where(immutable, materials_original,materials)
geom = geom.duplicate(microstructure[0:grid_original[0],0:grid_original[1],0:grid_original[2]]) damask.Geom(materials = materials[0:grid_original[0],0:grid_original[1],0:grid_original[2]],
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) size = geom.size,
origin = geom.origin,
geom.save_ASCII(sys.stdout if name is None else name,compress=False) comments = geom.comments + [scriptID + ' ' + ' '.join(sys.argv[1:])],
)\
.save_ASCII(sys.stdout if name is None else name,compress=False)

View File

@ -30,7 +30,7 @@ class myThread (threading.Thread):
def run(self): def run(self):
global bestSeedsUpdate global bestSeedsUpdate
global bestSeedsVFile global bestSeedsVFile
global nMicrostructures global nMaterials
global delta global delta
global points global points
global target global target
@ -70,7 +70,7 @@ class myThread (threading.Thread):
selectedMs = [] selectedMs = []
direction = [] direction = []
for i in range(NmoveGrains): for i in range(NmoveGrains):
selectedMs.append(random.randrange(1,nMicrostructures)) selectedMs.append(random.randrange(1,nMaterials))
direction.append((np.random.random()-0.5)*delta) direction.append((np.random.random()-0.5)*delta)
@ -101,11 +101,11 @@ class myThread (threading.Thread):
#--- evaluate current seeds file ------------------------------------------------------------------ #--- evaluate current seeds file ------------------------------------------------------------------
perturbedGeom = damask.Geom.load_ASCII(perturbedGeomVFile) perturbedGeom = damask.Geom.load_ASCII(perturbedGeomVFile)
myNmicrostructures = len(np.unique(perturbedGeom.microstructure)) myNmaterials = len(np.unique(perturbedGeom.materials))
currentData=np.bincount(perturbedGeom.microstructure.ravel())[1:]/points currentData=np.bincount(perturbedGeom.materials.ravel())[1:]/points
currentError=[] currentError=[]
currentHist=[] currentHist=[]
for i in range(nMicrostructures): # calculate the deviation in all bins per histogram for i in range(nMaterials): # calculate the deviation in all bins per histogram
currentHist.append(np.histogram(currentData,bins=target[i]['bins'])[0]) currentHist.append(np.histogram(currentData,bins=target[i]['bins'])[0])
currentError.append(np.sqrt(np.square(np.array(target[i]['histogram']-currentHist[i])).sum())) currentError.append(np.sqrt(np.square(np.array(target[i]['histogram']-currentHist[i])).sum()))
@ -117,12 +117,12 @@ class myThread (threading.Thread):
bestMatch = match bestMatch = match
#--- count bin classes with no mismatch ---------------------------------------------------------------------- #--- count bin classes with no mismatch ----------------------------------------------------------------------
myMatch=0 myMatch=0
for i in range(nMicrostructures): for i in range(nMaterials):
if currentError[i] > 0.0: break if currentError[i] > 0.0: break
myMatch = i+1 myMatch = i+1
if myNmicrostructures == nMicrostructures: if myNmaterials == nMaterials:
for i in range(min(nMicrostructures,myMatch+options.bins)): for i in range(min(nMaterials,myMatch+options.bins)):
if currentError[i] > target[i]['error']: # worse fitting, next try if currentError[i] > target[i]['error']: # worse fitting, next try
randReset = True randReset = True
break break
@ -141,25 +141,25 @@ class myThread (threading.Thread):
for line in perturbedSeedsVFile: for line in perturbedSeedsVFile:
currentSeedsFile.write(line) currentSeedsFile.write(line)
bestSeedsVFile.write(line) bestSeedsVFile.write(line)
for j in range(nMicrostructures): # save new errors for all bins for j in range(nMaterials): # save new errors for all bins
target[j]['error'] = currentError[j] target[j]['error'] = currentError[j]
if myMatch > match: # one or more new bins have no deviation if myMatch > match: # one or more new bins have no deviation
damask.util.croak( 'Stage {:d} cleared'.format(myMatch)) damask.util.croak( 'Stage {:d} cleared'.format(myMatch))
match=myMatch match=myMatch
sys.stdout.flush() sys.stdout.flush()
break break
if i == min(nMicrostructures,myMatch+options.bins)-1: # same quality as before: take it to keep on moving if i == min(nMaterials,myMatch+options.bins)-1: # same quality as before: take it to keep on moving
bestSeedsUpdate = time.time() bestSeedsUpdate = time.time()
perturbedSeedsVFile.seek(0) perturbedSeedsVFile.seek(0)
bestSeedsVFile.close() bestSeedsVFile.close()
bestSeedsVFile = StringIO() bestSeedsVFile = StringIO()
bestSeedsVFile.writelines(perturbedSeedsVFile.readlines()) bestSeedsVFile.writelines(perturbedSeedsVFile.readlines())
for j in range(nMicrostructures): for j in range(nMaterials):
target[j]['error'] = currentError[j] target[j]['error'] = currentError[j]
randReset = True randReset = True
else: #--- not all grains are tessellated else: #--- not all grains are tessellated
damask.util.croak('Thread {:d}: Microstructure mismatch ({:d} microstructures mapped)'\ damask.util.croak('Thread {:d}: Material mismatch ({:d} material indices mapped)'\
.format(self.threadID,myNmicrostructures)) .format(self.threadID,myNmaterials))
randReset = True randReset = True
@ -217,10 +217,10 @@ points = np.array(options.grid).prod().astype('float')
# ----------- calculate target distribution and bin edges # ----------- calculate target distribution and bin edges
targetGeom = damask.Geom.load_ASCII(os.path.splitext(os.path.basename(options.target))[0]+'.geom') targetGeom = damask.Geom.load_ASCII(os.path.splitext(os.path.basename(options.target))[0]+'.geom')
nMicrostructures = len(np.unique(targetGeom.microstructure)) nMaterials = len(np.unique(targetGeom.materials))
targetVolFrac = np.bincount(targetGeom.microstructure.flatten())/targetGeom.grid.prod().astype(np.float) targetVolFrac = np.bincount(targetGeom.materials.flatten())/targetGeom.grid.prod().astype(np.float)
target = [] target = []
for i in range(1,nMicrostructures+1): for i in range(1,nMaterials+1):
targetHist,targetBins = np.histogram(targetVolFrac,bins=i) #bin boundaries targetHist,targetBins = np.histogram(targetVolFrac,bins=i) #bin boundaries
target.append({'histogram':targetHist,'bins':targetBins}) target.append({'histogram':targetHist,'bins':targetBins})
@ -233,7 +233,7 @@ else:
bestSeedsVFile.write(damask.util.execute('seeds_fromRandom'+\ bestSeedsVFile.write(damask.util.execute('seeds_fromRandom'+\
' -g '+' '.join(list(map(str, options.grid)))+\ ' -g '+' '.join(list(map(str, options.grid)))+\
' -r {:d}'.format(options.randomSeed)+\ ' -r {:d}'.format(options.randomSeed)+\
' -N '+str(nMicrostructures))[0]) ' -N '+str(nMaterials))[0])
bestSeedsUpdate = time.time() bestSeedsUpdate = time.time()
# ----------- tessellate initial seed file to get and evaluate geom file # ----------- tessellate initial seed file to get and evaluate geom file
@ -244,11 +244,11 @@ initialGeomVFile.write(damask.util.execute('geom_fromVoronoiTessellation '+
initialGeomVFile.seek(0) initialGeomVFile.seek(0)
initialGeom = damask.Geom.load_ASCII(initialGeomVFile) initialGeom = damask.Geom.load_ASCII(initialGeomVFile)
if len(np.unique(targetGeom.microstructure)) != nMicrostructures: if len(np.unique(targetGeom.materials)) != nMaterials:
damask.util.croak('error. Microstructure count mismatch') damask.util.croak('error. Material count mismatch')
initialData = np.bincount(initialGeom.microstructure.flatten())/points initialData = np.bincount(initialGeom.materials.flatten())/points
for i in range(nMicrostructures): for i in range(nMaterials):
initialHist = np.histogram(initialData,bins=target[i]['bins'])[0] initialHist = np.histogram(initialData,bins=target[i]['bins'])[0]
target[i]['error']=np.sqrt(np.square(np.array(target[i]['histogram']-initialHist)).sum()) target[i]['error']=np.sqrt(np.square(np.array(target[i]['histogram']-initialHist)).sum())
@ -257,13 +257,13 @@ if target[0]['error'] > 0.0:
target[0]['error'] *=((target[0]['bins'][0]-np.min(initialData))**2.0+ target[0]['error'] *=((target[0]['bins'][0]-np.min(initialData))**2.0+
(target[0]['bins'][1]-np.max(initialData))**2.0)**0.5 (target[0]['bins'][1]-np.max(initialData))**2.0)**0.5
match=0 match=0
for i in range(nMicrostructures): for i in range(nMaterials):
if target[i]['error'] > 0.0: break if target[i]['error'] > 0.0: break
match = i+1 match = i+1
if options.maxseeds < 1: if options.maxseeds < 1:
maxSeeds = len(np.unique(initialGeom.microstructure)) maxSeeds = len(np.unique(initialGeom.materials))
else: else:
maxSeeds = options.maxseeds maxSeeds = options.maxseeds

View File

@ -61,7 +61,7 @@ for name in filenames:
'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)] ]
damask.Table(seeds[mask],{'pos':(3,)},comments)\ damask.Table(seeds[mask],{'pos':(3,)},comments)\
.add('material',materials[mask].astype(int))\ .add('material',materials[mask].astype(int))\

View File

@ -76,7 +76,7 @@ for name in filenames:
g[2] = k + offset[2] g[2] = k + offset[2]
g %= geom.grid g %= geom.grid
seeds[n,0:3] = (g+0.5)/geom.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.materials[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
@ -88,9 +88,9 @@ for name in filenames:
'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)] ]
table = damask.Table(seeds,{'pos':(3,),'microstructure':(1,)},comments) table = damask.Table(seeds,{'pos':(3,),'material':(1,)},comments)
table.set('microstructure',table.get('microstructure').astype(np.int))\ table.set('material',table.get('material').astype(np.int))\
.save(sys.stdout if name is None else \ .save(sys.stdout if name is None else \
os.path.splitext(name)[0]+f'_poked_{options.N}.seeds',legacy=True) os.path.splitext(name)[0]+f'_poked_{options.N}.seeds',legacy=True)