コード例 #1
0
def create_particles(gamma):

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

    dx = Lx / nx  # spacing between particles

    # create particle container
    pc = phd.ParticleContainer(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.0  # total energy

    cells = pc['position-x'] > .5
    pc['density'][cells] = 0.125
    pc['pressure'][cells] = 0.1

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

    return pc
コード例 #2
0
def create_particles(gamma):

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

    rho_1 = 1.0
    rho_2 = 2.0
    vel = 0.5
    amp = 0.05

    dx = Lx / nx  # spacing between particles

    # create particle container
    pc = phd.ParticleContainer(n)
    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:

                pc['density'][part] = rho_1
                pc['velocity-x'][part] = -(vel + pert)

            else:

                pc['density'][part] = rho_2
                pc['velocity-x'][part] = vel + pert

            pc['position-x'][part] = x
            pc['position-y'][part] = y
            pc['velocity-y'][part] = pert
            pc['ids'][part] = part
            part += 1

    pc['pressure'][:] = 2.5
    pc['velocity-y'][:] = 0.0
    pc['tag'][:] = phd.ParticleTAGS.Real
    pc['type'][:] = phd.ParticleTAGS.Undefined

    return pc
コード例 #3
0
def create_particles(gamma):

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

    # create particle container
    pc = phd.ParticleContainer(n, dim=3)

    part = 0
    np.random.seed(0)
    for i in range(nx):
        for j in range(nx):
            for k in range(nx):
                pc['position-x'][part] = np.random.rand()
                pc['position-y'][part] = np.random.rand()
                pc['position-z'][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\
            + (pc['position-z']-.5)**2 ) <= r**2
    pc['pressure'][cells] = 1.0 / (4.0 * np.pi * r**3 / 3.) * (gamma - 1)

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

    return pc
コード例 #4
0
if rank == 0:

    gamma = 1.4

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

    rho_1 = 1.0; rho_2 = 2.0
    vel = 0.5; amp = 0.05

    dx = Lx/nx # spacing between particles

    # create particle container
    pc_root = phd.ParticleContainer(n)
    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:

                pc_root['density'][part] = rho_1
                pc_root['velocity-x'][part] = -(vel + pert)

            else:
コード例 #5
0
import phd
import h5py
import numpy as np
import matplotlib.pyplot as plt

file_names = []
file_ ='../multi_core/uniform/sedov_3d_uniform_output/sedov_3d_uniform_0113/data0113_cpu'

num_proc = 4
for i in range(num_proc):
    file_names.append(file_ + `i`.zfill(4) + '.hdf5')

# stitch back solution from all processors
particles = phd.ParticleContainer(dim=3)
for data_file in file_names:

    f = h5py.File(data_file, 'r')
    size = f['/density'].size
    pc = phd.ParticleContainer(size, dim=3)

    pc['position-x'][:] = f['/position-x'][:]
    pc['position-y'][:] = f['/position-y'][:]
    pc['position-z'][:] = f['/position-z'][:]
    pc['density'][:] = f['/density'][:]
    pc['velocity-x'][:] = f['/velocity-x'][:]
    pc['velocity-y'][:] = f['/velocity-y'][:]
    pc['velocity-z'][:] = f['/velocity-z'][:]
    pc['pressure'][:] = f['/pressure'][:]
    pc['tag'][:] = f['/tag'][:]
    pc['type'][:] = f['/type'][:]
    pc['volume'][:] = f['/volume'][:]
コード例 #6
0
import phd
import h5py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mat_colors
from matplotlib.collections import PatchCollection

fields = [
    'position-x', 'position-y', 'velocity-x', 'velocity-y', 'density',
    'pressure', 'volume', 'tag', 'type', 'ids', 'process'
]

file_name = '../multi_core/cartesian/sod_2d_cartesian_output/' +\
        'sod_2d_cartesian_0072/data0072_cpu'
sod_mc = phd.ParticleContainer()

# stitch back multi-core solution
num_proc = 5
for i in range(num_proc):

    data_file = file_name + ` i `.zfill(4) + '.hdf5'
    f = h5py.File(data_file, "r")
    size = f['/density'].size

    pc = phd.ParticleContainer(size)
    for field in fields:
        pc[field][:] = f['/' + field][:]

    sod_mc.append_container(pc)
    del pc
コード例 #7
0
import phd
import h5py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mat_colors
from matplotlib.collections import PatchCollection

fields = [
    'position-x', 'position-y', 'position-z', 'velocity-x', 'velocity-y',
    'velocity-z', 'density', 'pressure', 'volume', 'tag', 'type', 'ids',
    'process'
]

file_name = '../multi_core/uniform/sedov_2d_uniform_output/' +\
        'sedov_2d_uniform_0113/data0113_cpu'
sedov_mc = phd.ParticleContainer(dim=3)

# stitch back multi-core solution
num_procs = 4
for i in range(num_procs):

    data_file = file_name + ` i `.zfill(4) + '.hdf5'
    f = h5py.File(data_file, "r")
    size = f['/density'].size

    pc = phd.ParticleContainer(size, dim=3)
    for field in fields:
        pc[field][:] = f['/' + field][:]

    pc.remove_tagged_particles(phd.ParticleTAGS.Ghost)
    sedov_mc.append_container(pc)
コード例 #8
0
#$ mpirun -n 4 python sedov_2d_cartesian.py

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 = 50  # particles per dim
    n = nx * nx * nx  # number of particles

    # create particle container
    pc_root = phd.ParticleContainer(n, dim=3)

    part = 0
    np.random.seed(0)
    for i in range(nx):
        for j in range(nx):
            for k in range(nx):
                pc_root['position-x'][part] = np.random.rand()
                pc_root['position-y'][part] = np.random.rand()
                pc_root['position-z'][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
コード例 #9
0
import phd
import h5py
import numpy as np
import matplotlib.pyplot as plt

file_names = []
#file_ = '../multi_core/cartesian/sedov_2d_cartesian_output/sedov_2d_cartesian_0139/data0139_cpu'
file_ = '../multi_core/uniform/sedov_2d_uniform_output/sedov_2d_uniform_0105/data0105_cpu'

num_procs = 5
for i in range(num_procs):
    file_names.append(file_ + ` i `.zfill(4) + '.hdf5')

# stitch back solution from all processors
particles = phd.ParticleContainer()
for data_file in file_names:

    f = h5py.File(data_file, 'r')
    size = f['/density'].size
    pc = phd.ParticleContainer(size)

    pc['position-x'][:] = f['/position-x'][:]
    pc['position-y'][:] = f['/position-y'][:]
    pc['density'][:] = f['/density'][:]
    pc['velocity-x'][:] = f['/velocity-x'][:]
    pc['velocity-y'][:] = f['/velocity-y'][:]
    pc['pressure'][:] = f['/pressure'][:]
    pc['tag'][:] = f['/tag'][:]
    pc['type'][:] = f['/type'][:]
    pc['volume'][:] = f['/volume'][:]