ensure to bring all seeds within target range

This commit is contained in:
Martin Diehl 2015-04-10 20:47:20 +00:00
parent d7b36c2c30
commit d008b566b4
1 changed files with 23 additions and 15 deletions

View File

@ -10,6 +10,7 @@ import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = os.path.splitext(scriptID.split()[1])[0] scriptName = os.path.splitext(scriptID.split()[1])[0]
mismatch = None mismatch = None
currentSeedsName = None currentSeedsName = None
@ -90,11 +91,11 @@ class myThread (threading.Thread):
perturbedSeedsTable.head_write() perturbedSeedsTable.head_write()
outputAlive=True outputAlive=True
ms = 1 ms = 1
while outputAlive and perturbedSeedsTable.data_read(): # perturbe selecte microstructure while outputAlive and perturbedSeedsTable.data_read(): # perturbe selected microstructure
if ms == selectedMs: if ms == selectedMs:
direction+=direction direction+=direction
newCoords=np.array(tuple(map(float,perturbedSeedsTable.data[0:3]))+direction) newCoords=np.array(tuple(map(float,perturbedSeedsTable.data[0:3]))+direction)
newCoords=np.where(newCoords>=1.0,newCoords-1.0,newCoords) newCoords=np.where(newCoords>=1.0,newCoords-1.0,newCoords) # ensure that the seeds remain in the box (move one side out, other side in)
newCoords=np.where(newCoords <0.0,newCoords+1.0,newCoords) newCoords=np.where(newCoords <0.0,newCoords+1.0,newCoords)
perturbedSeedsTable.data[0:3]=[format(f, '8.6f') for f in newCoords] perturbedSeedsTable.data[0:3]=[format(f, '8.6f') for f in newCoords]
ms+=1 ms+=1
@ -117,10 +118,13 @@ class myThread (threading.Thread):
currentData=np.bincount(perturbedGeomTable.data.astype(int).ravel())[1:]/points currentData=np.bincount(perturbedGeomTable.data.astype(int).ravel())[1:]/points
currentError=[] currentError=[]
currentHist=[] currentHist=[]
for i in xrange(nMicrostructures): for i in xrange(nMicrostructures): # 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()))
if currentError[0]>0.0: # as long as not all grains are within the range of the target, use the deviation to left and right as error
currentError[0] =((target[0]['bins'][0]-np.min(currentData))**2.0+
(target[0]['bins'][1]-np.max(currentData))**2.0)**0.5
s.acquire() # do the evaluation serially s.acquire() # do the evaluation serially
bestMatch = match bestMatch = match
#--- count bin classes with no mismatch ---------------------------------------------------------------------- #--- count bin classes with no mismatch ----------------------------------------------------------------------
@ -150,12 +154,12 @@ class myThread (threading.Thread):
bestSeedsVFile.write(line) bestSeedsVFile.write(line)
for j in xrange(nMicrostructures): # save new errors for all bins for j in xrange(nMicrostructures): # save new errors for all bins
target[j]['error'] = currentError[j] target[j]['error'] = currentError[j]
if myMatch > match: # one or more bins have no deviation if myMatch > match: # one or more new bins have no deviation
print 'Stage %i cleared'%(myMatch) print 'Stage %i cleared'%(myMatch)
match=myMatch match=myMatch
sys.stdout.flush() sys.stdout.flush()
break break
if i == min(nMicrostructures,myMatch+options.bins)-1: if i == min(nMicrostructures,myMatch+options.bins)-1: # same quality as before (for the considered bins): take it to keep on moving
bestSeedsUpdate = time.time() bestSeedsUpdate = time.time()
perturbedSeedsVFile.reset() perturbedSeedsVFile.reset()
bestSeedsVFile.close() bestSeedsVFile.close()
@ -265,6 +269,10 @@ for i in xrange(nMicrostructures):
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())
# as long as not all grain sizes are within the range, the error is the deviation to left and right
if target[0]['error'] > 0.0:
target[0]['error'] =((target[0]['bins'][0]-np.min(initialData))**2.0+
(target[0]['bins'][1]-np.max(initialData))**2.0)**0.5
match=0 match=0
for i in xrange(nMicrostructures): for i in xrange(nMicrostructures):
if target[i]['error'] > 0.0: break if target[i]['error'] > 0.0: break
@ -273,7 +281,7 @@ for i in xrange(nMicrostructures):
if options.maxseeds < 1: maxSeeds = initialMicrostructures if options.maxseeds < 1: maxSeeds = initialMicrostructures
print 'Stage %i cleared'%match if match >0: print 'Stage %i cleared'%match
sys.stdout.flush() sys.stdout.flush()
initialGeomVFile.close() initialGeomVFile.close()