fixed wrong variable name when using pre-existing microstructures from table.

added switch to skip effort for tolerance == 0.
This commit is contained in:
Philip Eisenlohr 2015-12-09 14:13:19 +00:00
parent 87daed84e6
commit 6de6b8b87f
1 changed files with 29 additions and 28 deletions

View File

@ -191,15 +191,13 @@ for name in filenames:
colOri = table.label_index(label)+(3-coordDim) # column(s) of orientation data (following 3 or 2 coordinates that were expanded to 3!) colOri = table.label_index(label)+(3-coordDim) # column(s) of orientation data (following 3 or 2 coordinates that were expanded to 3!)
if inputtype == 'microstructure': if inputtype == 'microstructure':
microstructure = table.data[:,colOri]
nGrains = len(np.unique(microstructure)) grain = table.data[:,colOri]
nGrains = len(np.unique(grain))
else: else:
# --- start background messaging if options.verbose: bg = damask.util.backgroundMessage(); bg.start() # start background messaging
if options.verbose:
bg = damask.util.backgroundMessage()
bg.start()
colPhase = -1 # column of phase data comes last colPhase = -1 # column of phase data comes last
if options.verbose: bg.set_message('sorting positions...') if options.verbose: bg.set_message('sorting positions...')
@ -250,28 +248,29 @@ for name in filenames:
cos_disorientations = -np.ones(1,dtype='f') # largest possible disorientation cos_disorientations = -np.ones(1,dtype='f') # largest possible disorientation
closest_grain = -1 # invalid neighbor closest_grain = -1 # invalid neighbor
neighbors = np.array(KDTree.query_ball_point([x,y,z], 3)) # point indices within radius if options.tolerance > 0.0: # only try to compress orientations if asked to
neighbors = neighbors[(neighbors < myPos) & \ neighbors = np.array(KDTree.query_ball_point([x,y,z], 3)) # point indices within radius
(table.data[index[neighbors],colPhase] == myPhase)] # filter neighbors: skip myself, anyone further ahead (cannot yet have a grain ID), and other phases neighbors = neighbors[(neighbors < myPos) & \
grains = np.unique(grain[neighbors]) # unique grain IDs among valid neighbors (table.data[index[neighbors],colPhase] == myPhase)] # filter neighbors: skip myself, anyone further ahead (cannot yet have a grain ID), and other phases
grains = np.unique(grain[neighbors]) # unique grain IDs among valid neighbors
if len(grains) > 0: # check immediate neighborhood first if len(grains) > 0: # check immediate neighborhood first
cos_disorientations = np.array([o.disorientation(orientations[grainID],
SST = False)[0].quaternion.w \
for grainID in grains]) # store disorientation per grainID
closest_grain = np.argmax(cos_disorientations) # find grain among grains that has closest orientation to myself
match = 'local'
if cos_disorientations[closest_grain] < threshold: # orientation not close enough?
grains = existingGrains[np.atleast_1d( ( np.array(phases) == myPhase ) & \
( np.in1d(existingGrains,grains,invert=True) ) )] # check every other already identified grain (of my phase)
if len(grains) > 0:
cos_disorientations = np.array([o.disorientation(orientations[grainID], cos_disorientations = np.array([o.disorientation(orientations[grainID],
SST = False)[0].quaternion.w \ SST = False)[0].quaternion.w \
for grainID in grains]) # store disorientation per grainID for grainID in grains]) # store disorientation per grainID
closest_grain = np.argmax(cos_disorientations) # find grain among grains that has closest orientation to myself closest_grain = np.argmax(cos_disorientations) # find grain among grains that has closest orientation to myself
match = 'global' match = 'local'
if cos_disorientations[closest_grain] < threshold: # orientation not close enough?
grains = existingGrains[np.atleast_1d( ( np.array(phases) == myPhase ) & \
( np.in1d(existingGrains,grains,invert=True) ) )] # check every other already identified grain (of my phase)
if len(grains) > 0:
cos_disorientations = np.array([o.disorientation(orientations[grainID],
SST = False)[0].quaternion.w \
for grainID in grains]) # store disorientation per grainID
closest_grain = np.argmax(cos_disorientations) # find grain among grains that has closest orientation to myself
match = 'global'
if cos_disorientations[closest_grain] >= threshold: # orientation now close enough? if cos_disorientations[closest_grain] >= threshold: # orientation now close enough?
grainID = grains[closest_grain] grainID = grains[closest_grain]
@ -281,12 +280,12 @@ for name in filenames:
multiplicity[grainID] += 1 multiplicity[grainID] += 1
statistics[match] += 1 statistics[match] += 1
else: else:
grain[myPos] = nGrains # ... and assign to me grain[myPos] = nGrains # assign new grain to me ...
nGrains += 1 # ... and update counter
orientations.append(o) # store new orientation for future comparison orientations.append(o) # store new orientation for future comparison
multiplicity.append(1) # having single occurrence so far multiplicity.append(1) # having single occurrence so far
phases.append(myPhase) # store phase info for future reporting phases.append(myPhase) # store phase info for future reporting
nGrains += 1 # update counter ... existingGrains = np.arange(nGrains) # update list of existing grains
existingGrains = np.arange(nGrains)
myPos += 1 myPos += 1
@ -296,6 +295,8 @@ for name in filenames:
damask.util.croak("{} seconds total.\n{} local and {} global matches.".\ damask.util.croak("{} seconds total.\n{} local and {} global matches.".\
format(time.clock()-tick,statistics['local'],statistics['global'])) format(time.clock()-tick,statistics['local'],statistics['global']))
grain += 1 # offset from starting index 0 to 1
# --- generate header ---------------------------------------------------------------------------- # --- generate header ----------------------------------------------------------------------------
info = { info = {
@ -343,7 +344,7 @@ for name in filenames:
# --- write microstructure information ------------------------------------------------------------ # --- write microstructure information ------------------------------------------------------------
table.data = grain.reshape(info['grid'][1]*info['grid'][2],info['grid'][0]) + 1 # offset from starting index 0 to 1 table.data = grain.reshape(info['grid'][1]*info['grid'][2],info['grid'][0])
table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ') table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
#--- output finalization -------------------------------------------------------------------------- #--- output finalization --------------------------------------------------------------------------