def tvbdRun(initialGrid, energyList, Eam, nIterations, gridLength, dimensions, alloyFraction, temp): alloyGrid, energyList = srf.runSim(initialGrid, energyList, temp, Eam, nIterations, gridLength, dimensions) randomMeasure2, actualList, binList = sref.getOrder( alloyGrid, alloyFraction, dimensions) return actualList, binList
def tvRun(initialGrid, eList, j, localEam, nIterationsPerSim, gridLength, dimensions, alloyFraction, runNum): gridNew, eList = srf.runSim(initialGrid, eList, j, localEam, nIterationsPerSim, gridLength, dimensions) currentOrderValue, actualList, binList = sref.getOrder( gridNew, alloyFraction, dimensions) return currentOrderValue
def cvRun(gridLength, alloyFraction, dimensions, eList, T, localEam, nIterationsPerSim): grid = srf.initializeGrid(gridLength, alloyFraction, dimensions) grid, eList = srf.runSim(grid, eList, T, localEam, nIterationsPerSim, gridLength, dimensions) currentOrderValue, actualList, binList = sref.getOrder( grid, alloyFraction, dimensions) return currentOrderValue
def standardRun(nIterations=3000000, gridLength=40, alloyFraction=50, Eam=0.1, T=300, dimensions=2, showMatrixImages=True): """Runs through simulation for one set of parameters""" alloyGrid = srf.initializeGrid(gridLength, alloyFraction, dimensions) # Sets up list list to take current system energy as simulation progresses energyList = [0] * (nIterations + 1) energyList[0] = sref.getTotalEnergy(alloyGrid, Eam, dimensions) if showMatrixImages and dimensions == 2: # Display initial matrix pyplot.figure(num="Initial config") img1 = pyplot.imshow(alloyGrid, interpolation='nearest') pyplot.colorbar(img1) orderMeasure1, actualList, binList = sref.getOrder(alloyGrid, alloyFraction, dimensions) print("Initial order is: {}".format(str(orderMeasure1))) alloyGrid, energyList = srf.runSim(alloyGrid, energyList, T, Eam, nIterations, gridLength, dimensions) if showMatrixImages and dimensions == 2: # Display matrix in prettier form, as a coloured graph pyplot.figure(num="Final config") img2 = pyplot.imshow(alloyGrid, interpolation='nearest') pyplot.colorbar(img2) pyplot.show() orderMeasure2, actualList, binList = sref.getOrder(alloyGrid, alloyFraction, dimensions) print("Final order is: {}".format(str(orderMeasure2)))
def getOrderTest(dimensions): gridLength = 20 comp = 40 ranGrid = srf.initializeGrid(gridLength, comp, dimensions) nForeignAtoms = int(comp * 0.01 * gridLength**dimensions) orderedGrid = np.zeros([gridLength] * dimensions) numAdded = 0 try: # try, except statement creates ordered grid (2 blocks) for i in range(gridLength): for j in range(gridLength): if dimensions == 2: orderedGrid[i, j] = 1 numAdded += 1 elif dimensions == 3: for k in range(gridLength): orderedGrid[i, j, k] = 1 numAdded += 1 assert (numAdded < nForeignAtoms) except (AssertionError ): # exception raised simply means we should stop adding # atoms, not that there is a problem pass if dimensions == 2: # shows ordered grid to show that we are testing an ordered grid pyplot.figure(num="orderedGrid") tempImg = pyplot.imshow(orderedGrid, interpolation='nearest') pyplot.colorbar(tempImg) pyplot.show() ranRan, actualList, binList = sref.getOrder(ranGrid, comp, dimensions) ranOrd, actualList, binList = sref.getOrder(orderedGrid, comp, dimensions) # ranRan should be much lower than ranOrd if ranRan < 0.2 * ranOrd: print( "CORRECT: random and ordered grids produces correct orderValues.") print("The order value for the random grid is: {}".format(str(ranRan))) print("The order value for the random grid is: {}".format(str(ranOrd)))
def createBarDistribution(gridLength=40, alloyFraction=50, nIterations=3000000, Eam=0.1, T=300, dimensions=2): alloyGrid = srf.initializeGrid(gridLength, alloyFraction, dimensions) # Sets up list to take current system energy as simulation progresses energyList = [0] * (nIterations + 1) energyList[0] = sref.getTotalEnergy(alloyGrid, Eam, dimensions) alloyGrid, energyList = srf.runSim(alloyGrid, energyList, T, Eam, nIterations, gridLength, dimensions) randomMeasure2, actualList, binList = sref.getOrder( alloyGrid, alloyFraction, dimensions) trace1 = plotly.graph_objs.Bar( x=[str(i) for i in range(dimensions * 2 + 1)], y=actualList, name='actualDistribution') trace2 = plotly.graph_objs.Bar( x=[str(i) for i in range(dimensions * 2 + 1)], y=binList, name='binomialDistribution') data = [trace1, trace2] layout = plotly.graph_objs.Layout( barmode='group', xaxis=dict(title='No. of unlike neighbours', titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')), yaxis=dict(title='Frequency', titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f'))) fig = plotly.graph_objs.Figure(data=data, layout=layout) plotly.offline.plot( fig, filename="""barDistribution [gL={}, n={}, comp={}, Eam={}, T={}, dimensions={}].html""".format(str(gridLength), str(nIterations), str(alloyFraction / 100.0), str(Eam), str(T), str(dimensions)).replace( '\n', '').replace('\t', ''))
def initializeGridTest(dimensions): """tests if intial grid is random and displays intial grid""" gridLength, alloyFraction = 20, 50 grid = srf.initializeGrid(gridLength, alloyFraction, dimensions) # checks order of inital grid result, actualList, binList = sref.getOrder(grid, alloyFraction, dimensions) if result > gridLength * 0.1: print("CORRECT: initializeGrid produces random grid") else: print( """ERROR: initializeGrid most likely does NOT produce a random grid. Run 1 more time to make sure.""") if dimensions == 2: # displays intial grid, if 2D pyplot.figure(num="Initial Grid Test") img = pyplot.imshow(grid, interpolation='nearest') pyplot.colorbar(img) pyplot.show()
def createTempVaryingBarDistribution(gridLength=40, alloyFraction=50, nIterations=3000000, Eam=0.1, tempList=[300, 1000, 3000, 5000], dimensions=2, multiProcess=True): initialGrid = srf.initializeGrid(gridLength, alloyFraction, dimensions) # Sets up list to take current system energy as simulation progresses energyList = [0] * (nIterations + 1) energyList[0] = sref.getTotalEnergy(initialGrid, Eam, dimensions) if multiProcess: p = Pool(processes=10) mainPartial = partial(tvbdRun, initialGrid, energyList, Eam, nIterations, gridLength, dimensions, alloyFraction) combined_lists = p.map(mainPartial, tempList) traceList = [i[0] for i in combined_lists] binList = combined_lists[-1][1] else: traceList = [0] * len(tempList) for i, j in enumerate(tempList): alloyGrid, energyList = srf.runSim(initialGrid, energyList, j, Eam, nIterations, gridLength, dimensions) randomMeasure2, actualList, binList = sref.getOrder( alloyGrid, alloyFraction, dimensions) traceList[i] = actualList xTraceList = str([str(i) for i in range(dimensions * 2 + 1)]) traceObjs = [] for i, j in enumerate(traceList): traceObjs.append( plotly.graph_objs.Bar(x=eval(xTraceList), y=j, name=str(tempList[i]) + " K")) traceObjs.append( plotly.graph_objs.Bar(x=xTraceList, y=binList, name='Binomial Distribution')) layout = plotly.graph_objs.Layout( barmode='group', xaxis=dict(title='No. of unlike neighbours', titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')), yaxis=dict(title='Frequency', titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f'))) fig = plotly.graph_objs.Figure(data=traceObjs, layout=layout) plotly.offline.plot( fig, filename="""tempVaryingBarDistribution [gL={}, n={}, comp={},Eam={}, dimensions={}].html""".format(str(gridLength), str(nIterations), str(alloyFraction / 100.0), str(Eam), str(dimensions)).replace('\n', '').replace('\t', ''))