Exemplo n.º 1
0
def create_particles(dim=2, n=10000, gamma=1.4):

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=2)

    c = 0.5
    for i in range(n):

        x = np.random.rand()
        y = np.random.rand()

        if (x-c)**2 + (y-c)**2 <= 0.25**2:
            particles["density"][i] = 1.0
            particles["pressure"][i] = 1.0
        else:
            particles["density"][i] = 0.125
            particles["pressure"][i] = 0.1

        particles["position-x"][i] = x
        particles["position-y"][i] = y
        particles["ids"][i] = i

    # zero out velocities and set particle type
    particles["velocity-x"][:] = 0.0
    particles["velocity-y"][:] = 0.0

    return particles
Exemplo n.º 2
0
def create_particles(gamma):

    Lx = 1.    # domain size in x
    nx = 101   # particles per dim
    n = nx*nx  # number of points

    # create particle container
    pc = phd.HydroParticleCreator(n)
    part = 0
    np.random.seed(0)
    for i in range(nx):
        for j in range(nx):
            pc['position-x'][part] = np.random.rand()
            pc['position-y'][part] = np.random.rand()
            pc['ids'][part] = part
            part += 1

    # set ambient values
    pc['density'][:]  = 1.0     # density
    pc['pressure'][:] = 1.0E-5*(gamma-1)  # total energy

    # put all enegery in center particle
    r = 0.1
    cells = ((pc['position-x']-.5)**2 + (pc['position-y']-.5)**2) <= r**2
    pc['pressure'][cells] = 1.0/(np.pi*r**2)*(gamma-1)

    # zero out the velocities and set particle type
    pc['velocity-x'][:] = 0.0
    pc['velocity-y'][:] = 0.0
    pc['tag'][:] = phd.ParticleTAGS.Real
    pc['type'][:] = phd.ParticleTAGS.Undefined

    return pc
Exemplo n.º 3
0
def create_particles(dim=2, nx=100, Lx=1.0, diaphragm=0.5, gamma=1.4):

    dx = Lx / nx  # spacing between particles
    n = nx * nx  # number of particles

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=2)
    part = 0
    for i in range(nx):
        for j in range(nx):
            particles["position-x"][part] = (i + 0.5) * dx
            particles["position-y"][part] = (j + 0.5) * dx
            particles["ids"][part] = part
            part += 1

    # set ambient values
    particles["density"][:] = 1.0
    particles["pressure"][:] = 1.0
    particles["velocity-x"][:] = 0.0
    particles["velocity-y"][:] = 0.0

    cells = particles["position-x"] > diaphragm
    particles["density"][cells] = 0.125
    particles["pressure"][cells] = 0.1

    return particles
Exemplo n.º 4
0
def create_particles(dim=2, nx=45, Lx=1.0, gamma=1.4):

    dx = Lx / nx  # spacing between particles
    n = nx * nx  # number of points

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=2)
    part = 0
    for i in range(nx):
        for j in range(nx):
            particles["position-x"][part] = (i + 0.5) * dx
            particles["position-y"][part] = (j + 0.5) * dx
            particles["ids"][part] = part
            part += 1

    # set ambient values
    particles["density"][:] = 1.0
    particles["pressure"][:] = 1.0E-6 * (gamma - 1)
    particles["velocity-x"][:] = 0.0
    particles["velocity-y"][:] = 0.0

    # put all enegery in center particle
    r = dx * .51
    cells = ((particles["position-x"]-.5)**2 +\
            (particles["position-y"]-.5)**2) <= r**2
    particles["pressure"][cells] = 1.0 / (dx * dx) * (gamma - 1)

    return particles
Exemplo n.º 5
0
def create_particles(gamma):

    Lx = 1.  # domain size in x
    nx = 101  # particles per dim
    n = nx * nx  # number of points

    dx = Lx / nx  # spacing between particles

    # create particle container
    pc = phd.HydroParticleCreator(n)
    part = 0
    for i in range(nx):
        for j in range(nx):
            pc['position-x'][part] = (i + 0.5) * dx
            pc['position-y'][part] = (j + 0.5) * dx
            pc['ids'][part] = part
            part += 1

    # set ambient values
    pc['density'][:] = 1.0  # density
    pc['pressure'][:] = 1.0E-5 * (gamma - 1)  # total energy

    # put all enegery in center particle
    r = dx * .51
    cells = ((pc['position-x'] - .5)**2 + (pc['position-y'] - .5)**2) <= r**2
    pc['pressure'][cells] = 1.0 / (dx * dx) * (gamma - 1)

    # zero out velocities and set particle type
    pc['velocity-x'][:] = 0.0
    pc['velocity-y'][:] = 0.0
    pc['tag'][:] = phd.ParticleTAGS.Real
    pc['type'][:] = phd.ParticleTAGS.Undefined

    return pc
Exemplo n.º 6
0
def create_particles(dim=2, gamma=1.4):

    nx = 50
    ny = 150
    Lx = 1.
    Ly = 3.

    if phd._in_parallel:
        # since we don't have rectangular
        # boundaries in parallel
        nx = 150
        ny = 150
        Lx = 3.
        Ly = 3.

    dx = Lx/nx
    dy = Ly/ny

    n = nx*ny

    # parameters of the problem
    center = 1.5

    p0 = 10.0
    grav = -1.0
    rho_1 = 1.0; rho_2 = 2.0
    amp = 1.0;   sigma = 0.1

    # create particle container
    particles = phd.HydroParticleCreator(n)
    part = 0
    for i in range(nx):
        for j in range(ny):

            x = (i+0.5)*dx
            y = (j+0.5)*dy

            if y < center:

                particles["density"][part] = rho_1
                particles["pressure"][part] = p0 + rho_1*grav*y

            else:

                particles["density"][part] = rho_2
                particles["pressure"][part] = p0 + rho_1*grav*center + rho_2*grav*(y-center)

            particles["position-x"][part] = x
            particles["position-y"][part] = y
            particles["velocity-y"][part] = amp*np.cos(2.*np.pi*x/1.)*np.exp(-(y-center)**2/sigma**2)
            particles["ids"][part] = part
            part += 1

    # zero out velocities and set particle type
    particles["velocity-x"][:] = 0.0

    return particles
def create_particles(dim, gamma):

    Lx = 1.  # domain size in x
    nx = 50  # particles per dim
    n = nx * nx  # number of points

    rho_1 = 1.0
    rho_2 = 2.0
    vel = 0.5
    amp = 0.05
    sigma = 0.05 / np.sqrt(2)

    dx = Lx / nx  # spacing between particles

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=2)
    part = 0
    for i in range(nx):
        for j in range(nx):

            x = (i + 0.5) * dx
            y = (j + 0.5) * dx

            pert = amp * np.sin(4. * np.pi * x)

            if 0.25 < y and y < 0.75:

                #particles["density"][part] = rho_1
                #particles["velocity-x"][part] = -(vel + pert)
                particles["density"][part] = rho_2
                particles["velocity-x"][part] = vel

            else:

                #particles["density"][part] = rho_2
                #particles["velocity-x"][part] = vel + pert
                particles["density"][part] = rho_1
                particles["velocity-x"][part] = -vel


            particles["velocity-y"][part] = 0.1*np.sin(4*np.pi*x)*(np.exp(-(y-0.25)**2/(2*sigma**2)) +\
                    np.exp(-(y-0.75)**2/(2*sigma**2)))
            particles["position-x"][part] = x
            particles["position-y"][part] = y
            particles["ids"][part] = part
            part += 1

    particles["pressure"][:] = 2.5
    #particles["velocity-y"][:] = 0.0

    return particles
Exemplo n.º 8
0
def create_particles(dim=2, nx=45, Lx=1., gamma=1.4):

    dx = Lx / nx  # spacing between particles
    n = nx * nx  # number of points

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=2)
    part = 0
    for i in range(nx):
        for j in range(nx):

            x = (i + 0.5) * dx - 0.5
            y = (j + 0.5) * dx - 0.5

            theta = np.arctan2(y, x)
            r = np.sqrt(x**2 + y**2)

            if 0 <= r < 0.2:
                vtheta = 5 * r
                press = 5 + 25. / 2 * r**2

            elif 0.2 <= r < 0.4:
                vtheta = 2 - 5 * r
                press = 9 + 25. / 2 * r**2 - 20. * r + 4 * np.log(r / 0.2)

            else:
                vtheta = 0.
                press = 3 + 4 * np.log(2)

            particles["position-x"][part] = x + 0.5
            particles["position-y"][part] = y + 0.5
            particles["velocity-x"][part] = -np.sin(theta) * vtheta
            particles["velocity-y"][part] = np.cos(theta) * vtheta
            particles["pressure"][part] = press
            particles["ids"][part] = part
            part += 1

    # set ambient values
    particles["density"][:] = 1.0

    return particles
Exemplo n.º 9
0
def create_particles(dim=2, n=10000, diaphragm=0.5, gamma=1.4):

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=2)
    np.random.seed(0)
    for i in range(n):
        particles["position-x"][i] = np.random.rand()
        particles["position-y"][i] = np.random.rand()
        particles["ids"][i] = i

    # set ambient values
    particles["density"][:] = 1.0
    particles["pressure"][:] = 1.0
    particles["velocity-x"][:] = 0.0
    particles["velocity-y"][:] = 0.0

    cells = particles["position-x"] > diaphragm
    particles["density"][cells] = 0.125
    particles["pressure"][cells] = 0.1

    return particles
Exemplo n.º 10
0
def create_particles(gamma, nx=10):

    Lx = 1.  # domain size in x
    dx = Lx / nx  # spacing between particles
    n = nx * nx  # number of points

    rho0 = 1.0
    vel0 = 0.0
    pre0 = 1.0

    A = 1.0e-6
    w = 2 * np.pi
    k = 2 * np.pi

    # create particle container
    particles = phd.HydroParticleCreator(n)

    particles["density"][:] = rho0
    particles["velocity-x"][:] = vel0
    particles["velocity-y"][:] = 0.0
    particles["pressure"][:] = pre0 / gamma

    part = 0
    for i in range(nx):
        for j in range(nx):
            x = (i + 0.5) * dx
            y = (j + 0.5) * dx

            particles["density"][part] += A * np.sin(k * x)
            particles["velocity-x"][part] += (w / k) * A / rho0 * np.sin(k * x)
            particles["pressure"][part] += (w / k)**2 * A * np.sin(k * x)

            particles["position-x"][part] = x
            particles["position-y"][part] = y
            particles["ids"][part] = part
            part += 1

    return particles
Exemplo n.º 11
0
def create_particles(dim=3, nx=45, Lx=1.0, gamma=1.4):

    dx = Lx / nx  # spacing between particles
    n = nx**3  # number of points

    # create particle container
    particles = phd.HydroParticleCreator(n, dim=3)
    part = 0
    np.random.seed(0)
    for i in range(nx):
        for j in range(nx):
            for k in range(nx):
                particles["position-x"][part] = (
                    i + 0.5) * dx + 1.0e-8 * dx * np.random.rand()
                particles["position-y"][part] = (
                    j + 0.5) * dx + 1.0e-8 * dx * np.random.rand()
                particles["position-z"][part] = (
                    k + 0.5) * dx + 1.0e-8 * dx * np.random.rand()
                particles["ids"][part] = part
                part += 1

    # set ambient values
    particles["density"][:] = 1.0  # density
    particles["pressure"][:] = 1.0E-6 * (gamma - 1)  # total energy
    particles["velocity-x"][:] = 0.0
    particles["velocity-y"][:] = 0.0
    particles["velocity-z"][:] = 0.0

    # put all enegery in center particle
    r = dx * .51
    cell = ((particles["position-x"]-.5)**2 +\
             (particles["position-y"]-.5)**2 +\
             (particles["position-z"]-.5)**2) <= r**2

    particles["pressure"][cell] = 1.0 / (dx * dx * dx) * (gamma - 1)

    return particles
Exemplo n.º 12
0
def create_particles(gamma):

    Lx = 1.  # domain size in x
    nx = 128  # particles per dim
    n = nx * nx  # number of points

    dx = Lx / nx  # spacing between particles

    # create particle container
    pc = phd.HydroParticleCreator(n)

    # set ambient values
    pc['density'][:] = 1.0  # density
    pc['pressure'][:] = 1.0  # total energy

    part = 0
    for i in range(nx):
        for j in range(nx):

            pc['position-x'][part] = (i + 0.5) * dx
            pc['position-y'][part] = (j + 0.5) * dx
            pc['ids'][part] = part

            if pc['position-x'][part] + pc['position-y'][part] < 0.5:
                pc['density'][part] = 0.125
                pc['pressure'][part] = 0.14

            part += 1

    # zero out velocities and set particle type
    pc['velocity-x'][:] = 0.0
    pc['velocity-y'][:] = 0.0
    pc['tag'][:] = phd.ParticleTAGS.Real
    pc['type'][:] = phd.ParticleTAGS.Undefined

    return pc
Exemplo n.º 13
0
        i += 1

    particles["mass"][:] = M / count
    particles["ids"][:] = np.arange(N)

    # center at (50, 50, 50)
    particles["position-x"][:] += 50.
    particles["position-y"][:] += 50.
    particles["position-z"][:] += 50.


if phd._rank == 0:

    num_part = 10000
    particles_root = phd.HydroParticleCreator(num_part, dim=3)

    make_plummer(particles_root, 1000., R=1., r_cut_off=10.)

    # how many particles_root to each process
    nsect, extra = divmod(num_part, phd._size)
    lengths = extra * [nsect + 1] + (phd._size - extra) * [nsect]
    send = np.array(lengths)

    # how many particles_root
    disp = np.zeros(phd._size, dtype=np.int32)
    for i in range(1, phd._size):
        disp[i] = send[i - 1] + disp[i - 1]

else:
Exemplo n.º 14
0
c = 0.25
e = c/a

G = 1.0
m1 = 1.0
m2 = 2.0
q = m1/m2 
m = m1 + m2
T = np.sqrt(4.*np.pi**2*a**3/(G*m))
dt = T/1000.

r0 = (1. - e)/(1. + q)*a
v0 = 1./(1. + q)*np.sqrt((1+e)/(1-e))*np.sqrt(G*m/a)

num_part = 2
particles = phd.HydroParticleCreator(num_part, dim=2)

particles["mass"][:] = np.array([m1, m2])
particles["position-x"][:] = np.array([r0, -q*r0])
particles["position-y"][:] = np.array([0., 0.])
particles["velocity-x"][:] = np.array([0., 0.])
particles["velocity-y"][:] = np.array([v0, -q*v0])

# computation related to boundaries
domain_manager = phd.DomainManager(
        xmin=[-1., -1.], xmax=[1., 1.],
        initial_radius=0.1) 

# setup gravity
gravity_tree = phd.GravityTree(barnes_angle=0.4,
        smoothing_length=0.0, calculate_potential=1)
Exemplo n.º 15
0
def create_particles(dim=3, gamma=1.4):

    L = 2.5  # domain size in x
    n = 33  # particles per dim
    dx = L / n
    num = n**3  # number of points

    M = 1.0
    R = 1.0
    G = 1.0
    u = 0.05 * G * M / R
    c = 1.25

    rho_fac = M / (2. * np.pi * R**2)
    pre_fac = 2. * rho_fac * u / 3.

    # create particle container
    particles = phd.HydroParticleCreator(num, dim=3)
    part = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):

                x = (i + 0.5) * dx
                y = (j + 0.5) * dx
                z = (k + 0.5) * dx

                r = np.sqrt((x - c)**2 + (y - c)**2 + (z - c)**2)

                if r <= R:

                    # stretch
                    rn = r**1.5 + 0.001
                    xn = x - c
                    yn = y - c
                    zn = z - c

                    theta = np.arctan2(np.sqrt(xn**2 + yn**2), zn)
                    phi = np.arctan2(yn, xn)

                    particles["position-x"][
                        part] = rn * np.sin(theta) * np.cos(phi) + c
                    particles["position-y"][
                        part] = rn * np.sin(theta) * np.sin(phi) + c
                    particles["position-z"][part] = rn * np.cos(theta) + c

                    particles["density"][part] = rho_fac / rn
                    particles["pressure"][part] = pre_fac / rn

                else:
                    particles["density"][part] = 1.e-5 * rho_fac / R
                    particles["pressure"][part] = 1.e-5 * pre_fac / R

                    particles["position-x"][part] = x
                    particles["position-y"][part] = y
                    particles["position-z"][part] = z

                particles["ids"][part] = part
                part += 1

    # zero out velocities and set particle type
    particles["velocity-x"][:] = 0.0
    particles["velocity-y"][:] = 0.0
    particles["velocity-z"][:] = 0.0

    return particles
Exemplo n.º 16
0
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

if rank == 0:

    gamma = 1.4

    Lx = 1.  # domain size in x
    nx = 51  # particles per dim
    n = nx * nx  # number of particles

    # create particle container
    #pc_root = phd.ParticleContainer(n)
    pc_root = phd.HydroParticleCreator(n, parallel=True)
    part = 0
    np.random.seed(0)
    for i in range(nx):
        for j in range(nx):
            pc_root['position-x'][part] = np.random.rand()
            pc_root['position-y'][part] = np.random.rand()
            pc_root['ids'][part] = part
            part += 1

    # set ambient values
    pc_root['density'][:] = 1.0  # density
    pc_root['pressure'][:] = 1.0E-5 * (gamma - 1)  # total energy

    # put all enegery in center particle
    r = 0.1
Exemplo n.º 17
0
    Ly = 3.
    ny = 144
    dy = Ly/ny

    n = nx*ny

    # parameters of the problem
    center = 1.5

    p0 = 10.0
    grav = -1.0
    rho_1 = 1.0; rho_2 = 2.0
    amp = 1.0;   sigma = 0.1

    # create particle container
    particles_root = phd.HydroParticleCreator(n)
    part = 0
    for i in range(nx):
        for j in range(ny):

            x = (i+0.5)*dx
            y = (j+0.5)*dy

            if y < center:

                particles_root["density"][part] = rho_1
                particles_root["pressure"][part] = p0 + rho_1*grav*y

            else:

                particles_root["density"][part] = rho_2