grainsB.append(gB) for rC, pC in zip(RsC, phiC): freq = SDC.frequency(pC, hC) * target_area freq = int(freq / (np.pi * rC**2.)) for f in range(freq): gC = pss.Grain(rC) grainsC.append(gC) for rD, pD in zip(RsD, phiD): freq = SDD.frequency(pD, hD) * target_area freq = int(freq / (np.pi * rD**2.)) for f in range(freq): gD = pss.Grain(rD) grainsD.append(gD) # library of grains has been generated, now place them into the mesh! groupA = pss.Ensemble(meshA, name='normaldistA_mu=3.6_sg=2.4') groupB = pss.Ensemble(meshB, name='normaldistB_mu=3.6_sg=4.8') groupC = pss.Ensemble(meshC, name='normaldistC_mu=3.6_sg=1.2') groupD = pss.Ensemble(meshD, name='normaldistD_mu=4.6_sg=2.4') # place them in, but don't worry if not possible to fit all. # allow for keyboard interrupt if there's a problem. try: i = 0 for gA in grainsA: gA.insertRandomly(meshA, m=1) groupA.add(gA, gA.x, gA.y) for gB in grainsB: gB.insertRandomly(meshB, m=1) groupB.add(gB, gB.x, gB.y) for gC in grainsC:
# matrix porosity = 0.5 #vf_G = 5.*vf_V # matrix porosity = 0.6 vf_G = 2. * vf_V / 3. + 1. / 6. # matrix porosity = 0.7 #vf_G = (2. + 3.*vf_V)/7. # matrix porosity = 0.8 #vf_G = (.25*vf_V+3./8.) print vf_V, vf_G first = True for v_void, v_grain in zip(vf_V, vf_G): if first: v_grain0 = v_grain v_void0 = v_void groupAG = pss.Ensemble( meshA, name='voidvariation_vfG-{:2.2f}_vfV-{:2.2f}_GRAINS_A'.format( v_grain0, v_void0)) groupBG = pss.Ensemble( meshB, name='voidvariation_vfG-{:2.2f}_vfV-{:2.2f}_GRAINS_B'.format( v_grain0, v_void0)) groupAV = pss.Ensemble( meshA, name='voidvariation_vfG-{:2.2f}_vfV-{:2.2f}_VOIDS_A'.format( v_grain0, v_void0)) groupBV = pss.Ensemble( meshB, name='voidvariation_vfG-{:2.2f}_vfV-{:2.2f}_VOIDS_B'.format( v_grain0, v_void0)) else: groupAG = pss.Ensemble(
target_area = float(meshA.x * meshA.y * vfrac) for r, p in zip(Rs, phi): # generate grain object with radius r g = pss.Grain(eqr=int(r)) # calculate the target number of grains from CDF (see above) prob = abs(CDF(p + h) - CDF(p - h)) g.targetFreq = int(round(prob * (target_area / float(g.area)))) grains.append(g) # library of grains has been generated, now place them into the mesh! # Just meshA for now # order grains from largest to smallest grains = [g for _, g in sorted(zip(phi, grains))] groupA = pss.Ensemble(meshA, name='shapevariationENS_A') groupB = pss.Ensemble(meshB, name='shapevariationENS_B') try: i = 0 for g in grains: for f in range(g.targetFreq): g.insertRandomly(meshA, m=1) groupA.add(g, g.x, g.y) g.insertRandomly(meshB, m=1) groupB.add(g, g.x, g.y) except KeyboardInterrupt: pass #print groupA.fabricTensor_discs() groupA.calcPSD()
test = diff/(np.pi*r**2.) if (1.-test)<=0.2: Rextra = r break ctr += 1 for r,freq in zip(RsA,freqs): if r == Rextra: freq+=1 for f in range(freq): g = pss.Grain(r) grainsA.append(g) grainsB.append(g) # library of grains has been generated, now place them into the mesh! groupA = pss.Ensemble(meshA,name='normaldistA') groupB = pss.Ensemble(meshB,name='normaldistB') # place them in, but don't worry if not possible to fit all. # allow for keyboard interrupt if there's a problem. try: i = 0 for gA in grainsA: gA.insertRandomly(meshA, m=1) groupA.add(gA,gA.x,gA.y) for gB in grainsB: gB.insertRandomly(meshB, m=1) groupB.add(gB,gB.x,gB.y) except KeyboardInterrupt: pass
freq2 = freq1 / (np.pi * r**2.) freq = int(freq2) diff += (freq2 - freq) * np.pi * r**2. freqs.append(freq) #print diff*np.pi*r**2. ctr = 0 for r in RsA: test = diff / (np.pi * r**2.) if (1. - test) <= 0.2: Rextra = r break ctr += 1 # library of grains has been generated, now place them into the mesh! groupA = pss.Ensemble(meshA, name='normaldistA') Rs = copy.deepcopy(RsA) Fr = copy.deepcopy(freqs) # place them in, but don't worry if not possible to fit all. # allow for keyboard interrupt if there's a problem. fig = plt.figure(figsize=(8, 4)) fig1 = plt.figure(figsize=(6, 4)) ax1a = fig1.add_subplot(131, aspect='equal') ax2a = fig1.add_subplot(132, aspect='equal') ax3a = fig1.add_subplot(133, aspect='equal') ax1a.axis('off') ax2a.axis('off') ax3a.axis('off') ax11 = fig.add_subplot(241) ax22 = fig.add_subplot(242)
meshA = pss.Mesh(X=500,Y=1200,cellsize=2.5e-6) meshB = pss.Mesh(X=500,Y=1200,cellsize=2.5e-6) # target volume (area) fraction vfrac = 0.5 # Store grain objects in list, 'grains' grainsA = [] grainsB = [] gLarge = pss.Grain(25.) gSmall = pss.Grain(5.) groupA = pss.Ensemble(meshA,name='bimodaldistA') groupB = pss.Ensemble(meshB,name='bimodaldistB') vfracA = 0. vfracB = 0. try: while vfracA < 0.3: gLarge.insertRandomly(meshA,m=1) groupA.add(gLarge,gLarge.x,gLarge.y) vfracA = meshA.vfrac() while vfracB < 0.3: gLarge.insertRandomly(meshB,m=1) groupB.add(gLarge,gLarge.x,gLarge.y) vfracB = meshB.vfrac() except KeyboardInterrupt:
target_area = float(meshA.x * meshA.y * vfrac) for r, p in zip(Rs, phi): # generate grain object with radius r g = pss.Grain(eqr=int(r)) # calculate the target number of grains from CDF (see above) prob = abs(CDF(p + h) - CDF(p - h)) g.targetFreq = int(round(prob * (target_area / float(g.area)))) grains.append(g) # library of grains has been generated, now place them into the mesh! # Just meshA for now # order grains from largest to smallest grains = [g for _, g in sorted(zip(phi, grains))] groupA = pss.Ensemble(meshA, name='mirror_test_ens') try: i = 0 for g in grains: for f in range(g.targetFreq): g.insertRandomly(meshA, m=1) groupA.add(g, g.x, g.y) except KeyboardInterrupt: pass groupA.optimise_materials(np.array([1, 2, 3, 4, 5, 6, 7, 8])) groupA.save() meshA.fillAll(-1)