def aggrAggregate(portNum, metaNum, pod_id, aggr_id, network, G, aggrGroupEdges): P = [0] * portNum for i in range(portNum): P[i] = aggr.Port(i) M = [0] * metaNum for i in range(metaNum): M[i] = aggr.MetaGroup(i) idmap = {} groups = network.pods[pod_id].aggrs[aggr_id].groups Gr = [0] * len(groups) i = 0 for g_id in groups: ports = set(G.groups[g_id].members[pod_id].keys()) Gr[i] = aggr.Group(i, g_id, ports, G.groups[g_id].rate, P) idmap[g_id] = i i += 1 G_unassigned = set(range(len(groups))) M_empty = set(range(portNum, metaNum - 1)) while len(G_unassigned) > 0: aggr.Aggregate(Gr[G_unassigned.pop()], M, Gr, P, M_empty, portNum) for g_id in groups: if g_id not in aggrGroupEdges.keys(): aggrGroupEdges[g_id] = {} aggrGroupEdges[g_id][pod_id] = M[Gr[idmap[g_id]].meta].ports switchAddr = 0 for i in range(metaNum): if len(M[i].ports) > 0: switchAddr += 1 return switchAddr
def edgeAggregate(portNum, metaNum, pod_id, edge_id, network, G): P = [0] * portNum for i in range(portNum): P[i] = aggr.Port(i) M = [0] * metaNum for i in range(metaNum): M[i] = aggr.MetaGroup(i) groups = network.pods[pod_id].edges[edge_id].groups Gr = [0] * len(groups) i = 0 for g_id in groups: ports = G.groups[g_id].members[pod_id][edge_id] Gr[i] = aggr.Group(i, g_id, ports, G.groups[g_id].rate, P) i += 1 G_unassigned = set(range(len(groups))) M_empty = set(range(portNum, metaNum - 1)) while len(G_unassigned) > 0: aggr.Aggregate(Gr[G_unassigned.pop()], M, Gr, P, M_empty, portNum) linkRate = [0] * 2 linkRate[0] = [] linkRate[1] = [] for i in range(portNum): linkRate[0].append(P[i].effective) linkRate[1].append(P[i].rate) switchAddr = [0] * 2 switchAddr[0] = len(groups) for i in range(metaNum): if len(M[i].ports) > 0: switchAddr[1] += 1 return [linkRate, switchAddr]
def generate_rosette(D, min_grid_res=40e-6): grid_res = min(D / 20, min_grid_res) rot = rotator.UniformRotator() cry = crystal.Rosette(D) gen = generator.MonodisperseGenerator(cry, rot, grid_res) agg = aggregate.Aggregate(gen) return (agg, grid_res)
def polydisp_dendrite(N=5, grid=None, align=True): #cry = crystal.Column(0.3e-3) agg = [] psd = stats.expon(scale=1.0e-3) rot = rotator.UniformRotator() for i in xrange(N): D = 1e3 while D > 0.3e-2 or D < 0.2e-3: D = psd.rvs() print "D: " + str(D) cry = crystal.Dendrite(D, alpha=0.705, beta=0.5, gamma=0.0001, num_iter=2500, hex_grid=grid) gen = generator.MonodisperseGenerator(cry, rot, 0.02e-3) agg.append(aggregate.Aggregate(gen, levels=5)) aggregate.t_i = 0 aggregate.t_o = 0 while len(agg) > 1: r = array([((a.extent[0][1] - a.extent[0][0]) + (a.extent[1][1] - a.extent[1][0])) / 4.0 for a in agg]) m_r = numpy.sqrt(array([a.X.shape[0] for a in agg]) / r) r_mat = (numpy.tile(r, (len(agg), 1)).T + r)**2 mr_mat = abs(numpy.tile(m_r, (len(agg), 1)).T - m_r) p_mat = r_mat * mr_mat p_max = p_mat.max() p_mat /= p_mat.max() collision = False while not collision: i = random.randint(len(agg)) j = random.randint(len(agg)) rnd = random.rand() if rnd < p_mat[i][j]: print i, j agg_top = agg[i] if (m_r[i] > m_r[j]) else agg[j] agg_btm = agg[i] if (m_r[i] <= m_r[j]) else agg[j] collision = agg_top.add_particle(particle=agg_btm.X, required=True) if collision: if align: agg_top.align() else: agg_top.rotate(rot) agg.pop(i if (m_r[i] <= m_r[j]) else j) print aggregate.t_i, aggregate.t_o if align: agg[0].align() agg[0].rotate(rotator.HorizontalRotator()) return agg[0]
def monodisp_demo(N=5): #cry = crystal.Plate(0.3e-3) #cry = crystal.Rosette(0.6e-3) cry = crystal.Spheroid(0.6e-3, 0.6) rot = rotator.UniformRotator() gen = generator.MonodisperseGenerator(cry, rot, 0.01e-3) agg = aggregate.Aggregate(gen) for i in xrange(N - 1): print i agg.add_particle(required=True, pen_depth=0.02e-3) agg.align() return agg
def ar(D): cry = crystal.Dendrite(D, hex_grid=grid) gen = generator.MonodisperseGenerator(cry, rot, grid_res) agg = aggregate.Aggregate(gen) m = agg.X.mean(0) X_c = agg.X - m cov = np.dot(X_c.T, X_c) (l, v) = np.linalg.eigh(cov) size = np.sqrt(l / X_c.shape[0] + (1. / (2 * np.sqrt(3)) * grid_res)**2) width = np.sqrt(0.5 * (size[1]**2 + size[2]**2)) height = size[0] print D, size, width, height return height / width
def gen(): if psd == "monodisperse": D = size elif psd == "exponential": psd_f = stats.expon(scale=size) D = max_size + 1 while (D < min_size) or (D > max_size): D = psd_f.rvs() cry = make_cry(D) gen = generator.MonodisperseGenerator(cry, rot, grid_res) if rimed: agg = aggregate.RimedAggregate(gen) else: agg = aggregate.Aggregate(gen) return agg
def monodisp_pseudo(N=5, grid=None, sig=1.0): cry = crystal.Dendrite(0.5e-3, alpha=0.705, beta=0.5, gamma=0.0001, num_iter=2500, hex_grid=grid) rot = rotator.UniformRotator() gen = generator.MonodisperseGenerator(cry, rot, 0.02e-3) """ p_agg = aggregate.PseudoAggregate(gen, sig=0.1e-2) rho_i = 916.7 #kg/m^3 N_dip = p_agg.grid().shape[0] m = 0.02e-3**3 * N_dip * N * rho_i sig = (m/20.3)**(1.0/2.35) print N_dip, sig """ p_agg = aggregate.PseudoAggregate(gen, sig=sig) aggs = [aggregate.Aggregate(gen, levels=5) for i in xrange(N - 1)] for agg in aggs: p_agg.add_particle(particle=agg.X, required=False) return p_agg
def monodisp_demo2(N=5): #cry = crystal.Column(0.3e-3) cry = crystal.Dendrite(0.3e-3, 0.705, 0.5, 0.0001, num_iter=2500) rot = rotator.UniformRotator() gen = generator.MonodisperseGenerator(cry, rot, 0.01e-3) agg = [aggregate.Aggregate(gen) for i in xrange(N)] aggregate.t_i = 0 aggregate.t_o = 0 while len(agg) > 1: r = array([((a.extent[0][1] - a.extent[0][0]) + (a.extent[1][1] - a.extent[1][0])) / 4.0 for a in agg]) m_r = numpy.sqrt(array([a.X.shape[0] for a in agg]) / r) r_mat = (numpy.tile(r, (len(agg), 1)).T + r)**2 mr_mat = abs(numpy.tile(m_r, (len(agg), 1)).T - m_r) p_mat = r_mat * mr_mat p_max = p_mat.max() p_mat /= p_mat.max() collision = False while not collision: i = random.randint(len(agg)) j = random.randint(len(agg)) rnd = random.rand() if rnd < p_mat[i][j]: print i, j agg_top = agg[i] if (m_r[i] > m_r[j]) else agg[j] agg_btm = agg[i] if (m_r[i] <= m_r[j]) else agg[j] collision = agg_top.add_particle(particle=agg_btm.X, required=True) agg_top.align() agg.pop(i if (m_r[i] <= m_r[j]) else j) print aggregate.t_i, aggregate.t_o return agg[0]