import os, numpy as np from pymicro.crystal.texture import PoleFigure from pymicro.crystal.microstructure import Microstructure if __name__ == '__main__': """ Example of a pole figure of a random microstructure with 200 grains. The poles are colored according using IPF coloring and resized proportionally to each grain volume. """ # create a microstructure with a random texture and 200 grains micro = Microstructure.random_texture(n=200) micro.autodelete = True # set random values for the grain volumes np.random.seed(22) for g in micro.grains: g['volume'] = 100 * np.random.random()**3 g.update() micro.grains.flush() # first pole figure pf = PoleFigure(microstructure=micro) pf.resize_markers = True pf.set_hkl_poles('001') pf.axis = 'Z' pf.set_map_field('ipf') pf.plot_pole_figures(plot_sst=True, display=False, save_as='png') del pf del micro
#!/usr/bin/env python import os, numpy as np from matplotlib import pyplot as plt from pymicro.crystal.microstructure import Microstructure, Orientation from pymicro.crystal.texture import PoleFigure N = 500 # number of grains micro = Microstructure.random_texture(N) # look at misorientation between pair of grains misorientations = [] for i in range(2, len(micro.grains)): o1 = micro.get_grain(i - 1).orientation o2 = micro.get_grain(i).orientation w = 180 / np.pi * o1.disorientation(o2)[0] misorientations.append(w) # plt misorientations histogram plt.hist(misorientations, bins=20, normed=True, cumulative=False) plt.title('misorientation distribution, random texture %d grains' % N) psis_dg = np.linspace(0, 63, 5 * 63 + 1) misorientations_MacKenzie = [] for psidg in psis_dg: psi = np.pi * psidg / 180 misorientations_MacKenzie.append(Orientation.misorientation_MacKenzie(psi)) plt.plot(psis_dg, misorientations_MacKenzie, 'k--', linewidth=2, label='MacKenzie (1958)') plt.ylim(0, 0.05) plt.legend(loc='upper left')