Exemplo n.º 1
0
def bh_interact(c1, c2, theta):
    if c1.get_num_particles() == 0 or c2.get_num_particles() == 0:
        return
    elif c1.get_num_particles() > 1:
        c1_children = c1.get_sub_cells()
        for i in c1_children:
            bh_interact(i, c2, theta)
    elif c2.get_num_particles() == 1:
        p1 = c1.particles[iter(c1.indices).next()]
        p2 = c1.particles[iter(c2.indices).next()]
        p1.f = p1.f.add(common.compute_force(p1.pos, p2.pos, p1.m, p2.m))
        return
    else:
        approximate(c2)
        p = c1.particles[iter(c1.indices).next()]
        d = math.sqrt(p.pos.distance_r2(c2.center))
        s = c2.region.r[0][1] - c2.region.r[0][0]
        if s / d < theta:
            # sufficiently far away
            p.f = p.f.add(common.compute_force(p.pos, c2.center, p.m, c2.m))
            pass
        else:
            # recursively visit sub regions
            for i in c2.get_sub_cells():
                bh_interact(c1, i, theta)
            pass
    return
Exemplo n.º 2
0
def bh_interact2(c1, c2, theta):
    if c2.get_num_particles() == 0:
        return
    elif c2.get_num_particles() == 1:
        p1 = c1.particles[iter(c1.indices).next()]
        p2 = c1.particles[iter(c2.indices).next()]
        p1.f = p1.f.add(common.compute_force(p1.pos, p2.pos, p1.m, p2.m))
        return
    else:
        # assume this has been called already
        #approximate(c2)
        p = c1.particles[iter(c1.indices).next()]
        d = math.sqrt(p.pos.distance_r2(c2.center))
        s = c2.region.r[0][1] - c2.region.r[0][0]
        if s / d < theta:
            # sufficiently far away
            p.f = p.f.add(common.compute_force(p.pos, c2.center, p.m, c2.m))
            skip_children()
    return
Exemplo n.º 3
0
def bh_interact2(c1, c2, theta):
    if c2.get_num_particles() == 0:
        return
    elif c2.get_num_particles() == 1:
        p1 = c1.particles[iter(c1.indices).next()]
        p2 = c1.particles[iter(c2.indices).next()]
        p1.f = p1.f.add(common.compute_force(p1.pos, p2.pos, p1.m, p2.m))
        return
    else:
        # assume this has been called already
        # approximate(c2)
        p = c1.particles[iter(c1.indices).next()]
        d = math.sqrt(p.pos.distance_r2(c2.center))
        s = c2.region.r[0][1] - c2.region.r[0][0]
        if s / d < theta:
            # sufficiently far away
            p.f = p.f.add(common.compute_force(p.pos, c2.center, p.m, c2.m))
            skip_children()
    return