# create 10 different particles
N = 10
# Generate N phi values and equiv radii (in cells)
phi = np.linspace(minphi, maxphi, N)

Rs = ((DD_(phi) * .5 * 1.e-3) / meshA.cellsize)

# interval over which to calculate number from pdf
# No. = |CDF(x+h) - CDF(x-h)| * no. of areas
h = abs(phi[1] - phi[0]) * .5

# target area that ALL particles should take up at end
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))]

vf_V = np.array([0., 0.125, 0.25])
vf_V = vf_V[::-1]
# matrix porosity = 0.5
#vf_G = 5.*vf_V
Beispiel #2
0
# create 10 different particles
N = 10
# Generate N phi values and equiv radii (in cells)
phi = np.linspace(minphi, maxphi, N)

Rs = ((DD_(phi) * .5 * 1.e-3) / meshA.cellsize)

# interval over which to calculate number from pdf
# No. = |CDF(x+h) - CDF(x-h)| * no. of areas
h = abs(phi[1] - phi[0]) * .5

# target area that ALL particles should take up at end
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
print SDA.details()
print SDB.details()
print SDC.details()
print SDD.details()

# target area that ALL particles should take up at end
target_area = float(meshA.Ncells * vfrac)

# Generate 4 libraries, one for each domain
# of grains, and record the expected frequency
# of each.
for rA, pA in zip(RsA, phiA):
    freq = SDA.frequency(pA, hA) * target_area
    freq = int(freq / (np.pi * rA**2.))
    for f in range(freq):
        gA = pss.Grain(rA)
        grainsA.append(gA)
for rB, pB in zip(RsB, phiB):
    freq = SDB.frequency(pB, hB) * target_area
    freq = int(freq / (np.pi * rB**2.))
    for f in range(freq):
        gB = pss.Grain(rB)
        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
    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

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)
Beispiel #5
0
r *= np.pi

off = .5

R = [[-1.,-1.],
     [-1.,1.],
     [1.,-1.],
     [1.,-1.]]

R[2][1] += off

#grain = pss.Grain(shape='file',File='grain_arearatio-0.725.txt',eqr=20.,rot=r)
#grain1 = pss.Grain(shape='polygon',poly_params=R,eqr=20.,rot=r)
#grain2 = pss.Grain(shape='polygon',poly_params=R,eqr=20.,rot=r*3)

grain = pss.Grain(shape='circle',eqr=20)

grain.place(x,yA,1,mesh1)
grain.place(x,yB,2,mesh1)

fill = mesh1.calcVol([1,2])
vfrac = fill/float(mesh1.Ncells)

print "Total volume fraction of particles is: {:3.3f} %".format(vfrac*100.)


mesh1.fillAll(3)
mesh1.plateVel(0.,1.25e-3,1500.,axis=1)
mesh1.plateVel(1.25e-3,2.5e-3,-1500.,axis=1)
mesh1.fillPlate(-1,2.49e-3,2.5e-3)
mesh1.fillPlate(-1,0.,0.01e-3)
    ax.set_ylim(0, 1)

ax1 = fig.add_subplot(245, aspect='equal')
ax2 = fig.add_subplot(246, aspect='equal')
ax3 = fig.add_subplot(247, aspect='equal')
ax4 = fig.add_subplot(248, aspect='equal')
group = []
for ax in [ax1, ax2, ax3, ax4]:
    ctr = 0
    m = 0
    for r, freq in zip(Rs, Fr):
        if r == Rextra: freq += 1
        m += 1
        for f in range(freq):
            if ax == ax1:
                g = pss.Grain(r)
                g.insertRandomly(meshA, m=m)
                group.append(g)
            else:
                g = group[ctr]
                g.place(g.x, g.y, m, meshA)
                ctr += 1
    if ax != ax1: meshA.fillAll(m + 1)
    for KK, col in zip(range(meshA.NoMats), cols):
        matter = np.copy(meshA.materials[KK, :, :]) * col
        if KK != 2:
            ax1a.contour(meshA.xi,
                         meshA.yi,
                         matter,
                         1,
                         colors='k',

# Test area A (square lattice) ymin = 2.e-3 ymax = 2.5e-3
XcoordsA = np.linspace(0.,1.e-3,5)
YcoordsA = np.linspace(2.e-3,3.e-3,5)

# Test area B (hexagonal lattice) ymin = .5e-3 ymax = 1.e-3
XcoordsB = np.linspace(0.,1.e-3,5)
YcoordsB = np.linspace(0.e-3,1.e-3,5)

c = 0
rot = 0
for yA,yB in zip(YcoordsA,YcoordsB):
    phi = rot*np.pi/180.
    print phi
    grain = pss.Grain(shape='polygon',eqr=10.,poly_params=poly_params,rot=phi)
    rot += 30.
    if c == 0:
        c = 1
    else:
        c = 0
    for xA,xB in zip(XcoordsA,XcoordsB):
        if c == 0:
            xB += .125e-3
        elif c == 1:
            pass
        #xB -= .125e-3
        grain.place(xA,yA,1,mesh1)
        grain.place(xB,yB,2,mesh1)

fill = mesh1.calcVol([1,2])
import numpy as np

mesh1 = pss.Mesh(X=100, Y=500, cellsize=.5e-5)

x = .25e-3
yA = 1.875e-3
yB = 0.625e-3

theta = 45.

r = np.pi * theta / 180.

R = [[-1., -1.], [-1., 1.], [1., 1.], [1., -1.]]

#grain = pss.Grain(shape='file',File='grain_arearatio-0.725.txt',eqr=20.,rot=r)
grain1 = pss.Grain(shape='polygon', poly_params=R, eqr=20., rot=r)
grain2 = pss.Grain(shape='polygon', poly_params=R, eqr=20., rot=r)

grain1.place(x, yA, 1, mesh1)
grain2.place(x, yB, 2, mesh1)

fill = mesh1.calcVol([1, 2])
vfrac = fill / float(mesh1.Ncells)

print "Total volume fraction of particles is: {:3.3f} %".format(vfrac * 100.)

mesh1.fillAll(3)
mesh1.plateVel(0., 1.25e-3, 1500., axis=1)
mesh1.plateVel(1.25e-3, 2.5e-3, -1500., axis=1)
mesh1.fillPlate(-1, 2.49e-3, 2.5e-3)
mesh1.fillPlate(-1, 0., 0.01e-3)
Beispiel #9
0
import pySALESetup as pss
import numpy as np

mesh1 = pss.Mesh(X=200, Y=600, cellsize=.5e-5)

grain1 = pss.Grain(eqr=10.)
grain2 = pss.Grain(eqr=10.)

# Test area A (square lattice) ymin = 2.e-3 ymax = 2.5e-3
XcoordsA = np.linspace(0., 1.e-3, 5)
YcoordsA = np.linspace(2.e-3, 3.e-3, 5)

# Test area B (hexagonal lattice) ymin = .5e-3 ymax = 1.e-3
XcoordsB = np.linspace(0., 1.e-3, 5)
YcoordsB = np.linspace(0.e-3, 1.e-3, 5)

c = 0
for yA, yB in zip(YcoordsA, YcoordsB):
    if c == 0:
        c = 1
    else:
        c = 0
    for xA, xB in zip(XcoordsA, XcoordsB):
        grain1.place(xA, yA, 1, mesh1)
        grain2.place(xB, yB, 2, mesh1)

fill = mesh1.calcVol([1, 2])
vfrac = fill / float(mesh1.Ncells)

print "Total volume fraction of particles is: {:3.3f} %".format(vfrac * 100.)
import pySALESetup as pss
import matplotlib.pyplot as plt
from math import ceil


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)
Beispiel #11
0
import pySALESetup as pss
import numpy as np

mesh1 = pss.Mesh(X=500,Y=1500)
grain1 = pss.Grain(eqr=50.)
grain2 = pss.Grain(eqr=50.)



# Test area A (square lattice) ymin = 2.e-3 ymax = 2.5e-3
XcoordsA = np.linspace(0.,1.e-3,5)
YcoordsA = np.linspace(2.e-3,2.5e-3,3)

# Test area B (hexagonal lattice) ymin = .5e-3 ymax = 1.e-3
XcoordsB = np.linspace(0.,1.e-3,5)
YcoordsB = np.linspace(.5e-3,1.e-3,3)

c = 0
for yA,yB in zip(YcoordsA,YcoordsB):
    if c == 0:
        c = 1
    else:
        c = 0
    for xA,xB in zip(XcoordsA,XcoordsB):
        if c == 0:
            xB += .125e-3
        elif c == 1:
            pass
        #xB -= .125e-3
        grain1.place(xA,yA,1,mesh1)
        grain2.place(xB,yB,2,mesh1)
Beispiel #12
0
import pySALESetup as pss
import numpy as np
import glob
import random


def DD_(x):
    return 2.**(-x)


allfiles = glob.glob('../grain_library/grain_area*.txt')
# create 5 different particles
N = 4
# Generate N phi values and equiv radii (in cells)
minphi = -np.log2(2 * 4 * 2.5e-3)
maxphi = -np.log2(2 * 200 * 2.5e-3)
phi = np.linspace(minphi, maxphi, N)

Rs = ((DD_(phi) * .5 * 1.e-3) / 2.5e-6)
ctr = 0
for r, p in zip(Rs, phi):
    # generate grain object with radius r
    fff = random.choice(allfiles)
    g = pss.Grain(eqr=int(r), shape='file', File=fff)
    g.view(save=True, fname='grain_{}.png'.format(ctr), show=False)
    ctr += 1