Пример #1
0
#nx, ny, nz = 544, 544, 544  # 5527 MB
#nx, ny, nz = 512, 512, 512  # 4608 MB
#nx, ny, nz = 480, 480, 480  # 3796 MB
#nx, ny, nz = 256, 256, 256  # 576 MB
nx, ny, nz = 240, 256, 256
#nx, ny, nz = 128, 128, 128  # 72 MB
tmax, tgap = 1000, 10 

# instances 
fields = Fields(0, nx, ny, nz, coeff_use='e', precision_float='single')
Core(fields)

print 'ns_pitch', fields.ns_pitch
print 'nbytes (MB)', nx*ny*nz * 9 * 4. / (1024**2)
        
'''
Pbc(fields, 'xyz')

tfunc = lambda tstep: np.sin(0.05 * tstep)
IncidentDirect(fields, 'ez', (20, 0, 0), (20, ny-1, nz-1), tfunc) 
#IncidentDirect(fields, 'ez', (0, 20, 0), (nx-1, 20, nz-1), tfunc) 
getf = GetFields(fields, 'ez', (0, 0, nz/2), (nx-1, ny-1, nz/2))

print fields.instance_list

# plot
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(12,8))
imag = plt.imshow(np.zeros((nx, ny), fields.dtype).T, interpolation='nearest', origin='lower', vmin=-1.1, vmax=1.1)
plt.colorbar()
Пример #2
0
if rank == 0: direction = '+'
elif rank == size - 1: direction = '-'
else: direction = '+-'

#exch = node.ExchangeMpiNonBlock(fields, direction)

#exch = node.ExchangeMpiBufferBlock(fields, direction)
#exch = node.ExchangeMpiBufferBlockSplit(fields, direction)
exch = node.ExchangeMpiBufferNonBlockSplitEnqueue(fields, direction, tmax)
if '+' in direction: cpu.Core(exch.cpuf_p)
if '-' in direction: cpu.Core(exch.cpuf_m)

is_master = True if rank == 0 else False

if is_plot:
    Pbc(fields, 'yz')
    getf = GetFields(fields, 'ez', (0, 0, 0.5), (-1, -1, 0.5))

    tfunc = lambda tstep: 40 * np.sin(0.05 * tstep)
    if rank < size - 1:
        IncidentDirect(fields, 'ez', (220, 0.5, 0), (220, 0.5, -1), tfunc)
    #if rank > 0:
    #    IncidentDirect(fields, 'ez', (20, 0.5, 0), (20, 0.5, -1), tfunc)

    if is_master:
        # plot
        import matplotlib.pyplot as plt
        plt.ion()
        fig = plt.figure(figsize=(12, 8))
        arr = np.zeros((size * nx, ny), fields.dtype)
        for i in range(1, size):
Пример #3
0
# plot
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rc('image', interpolation='nearest', origin='lower')
#plt.ion()
fig = plt.figure(figsize=(14, 8))

# gpu device
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
device = gpu_devices[0]

# z-axis
nx, ny, nz = 180, 160, 2
fields = Fields(context, device, nx, ny, nz)
Pbc(fields, 'xyz')
Core(fields)
IncidentDirect(fields, 'ey', (20, 0, 0), (20, ny - 1, nz - 1), tfunc)
IncidentDirect(fields, 'ex', (0, 20, 0), (nx - 1, 20, nz - 1), tfunc)

for tstep in xrange(1, tmax + 1):
    fields.update_e()
    fields.update_h()

ax1 = fig.add_subplot(2, 3, 1)
getf = GetFields(fields, 'ey', (0, 0, nz / 2), (nx - 1, ny - 1, nz / 2))
getf.get_event().wait()
ax1.imshow(getf.get_fields().T, vmin=-1.1, vmax=1.1)
ax1.set_title('%s, ey[20,:,:]' % repr(fields.ns))
ax1.set_xlabel('x')
ax1.set_ylabel('y')
Пример #4
0
mpl.rc('image', interpolation='nearest', origin='lower')
#plt.ion()
fig = plt.figure(figsize=(14,5))
ax1 = fig.add_subplot(1, 3, 1)
ax2 = fig.add_subplot(1, 3, 2)
ax3 = fig.add_subplot(1, 3, 3)

# gpu device
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
device = gpu_devices[0]

# xy-plane
nx, ny, nz = 180, 160, 2
fields = Fields(context, device, nx, ny, nz)
Pbc(fields, 'z')
Pml(fields, ('+-', '+-', ''), npml)
Core(fields)
IncidentDirect(fields, 'ez', (0.4, 0.3, 0), (0.4, 0.3, -1), tfunc) 
getf = GetFields(fields, 'ez', (0, 0, 0.5), (-1, -1, 0.5))

for tstep in xrange(1, tmax+1):
    fields.update_e()
    fields.update_h()

getf.get_event().wait()
ax1.imshow(getf.get_fields().T, vmin=-1.1, vmax=1.1)
ax1.set_title('xy-plane')
ax1.set_xlabel('x')
ax1.set_ylabel('y')
Пример #5
0
import pyopencl as cl
import sys

from kemp.fdtd3d.util import common_gpu
from kemp.fdtd3d.gpu import Fields, Core, Pbc, Pml, IncidentDirect, GetFields

nx, ny, nz = 2, 250, 300
tmax, tgap = 1000, 10
npml = 10

# instances
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
device = gpu_devices[0]
fields = Fields(context, device, nx, ny, nz)
Pbc(fields, 'x')
Pml(fields, ('', '+-', '+-'), npml)
Core(fields)

tfunc = lambda tstep: 50 * np.sin(0.05 * tstep)
IncidentDirect(fields, 'ex', (0, 0.4, 0.3), (-1, 0.4, 0.3), tfunc)
getf = GetFields(fields, 'ex', (0.5, 0, 0), (0.5, -1, -1))

print fields.instance_list

# plot
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(12, 8))
imag = plt.imshow(np.zeros((ny, nz), fields.dtype).T,
                  interpolation='nearest',
Пример #6
0
from kemp.fdtd3d.util import common_exchange


nx, ny, nz = 200, 300, 16
tmax, tgap = 200, 10

# instances
from kemp.fdtd3d.util import common_gpu
import pyopencl as cl
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
fields = Fields(context, gpu_devices[0], nx, ny, nz)
#fields = Fields(nx, ny, nz)

core = Core(fields)
pbc = Pbc(fields, 'x')
pbc = Pbc(fields, 'y')
pbc = Pbc(fields, 'z')
print fields.instance_list

tfunc = lambda tstep: np.sin(0.05 * tstep)
incident = DirectIncident(fields, 'ez', (20, 0, 0), (20, ny-1, nz-1), tfunc) 
incident = DirectIncident(fields, 'ey', (0, 20, 0), (nx-1, 20, nz-1), tfunc) 
#incident = DirectIncident(fields, 'ex', (0, 0, 20), (nx-1, ny-1, 20), tfunc) 
getf = GetFields(fields, 'ez', (0, 0, nz/2), (nx-1, ny-1, nz/2))

# for verify pbc
vpbc = common_exchange.VerifyPbc(fields, 'xyz')

# plot
import matplotlib.pyplot as plt
Пример #7
0
    def runTest(self):
        axis, nx, ny, nz, precision_float = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, '', precision_float)
        pbc = Pbc(fields, axis)

        # allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_eh_bufs(*ehs)

        # update
        fields.update_e()
        fields.update_h()

        # verify
        getf0, getf1 = {}, {}
        strfs_e = {
            'x': ['ey', 'ez'],
            'y': ['ex', 'ez'],
            'z': ['ex', 'ey']
        }[axis]
        strfs_h = {
            'x': ['hy', 'hz'],
            'y': ['hx', 'hz'],
            'z': ['hx', 'hy']
        }[axis]

        pt0 = (0, 0, 0)
        pt1 = { 'x': (0, ny-2, nz-2), \
                'y': (nx-2, 0, nz-2), \
                'z': (nx-2, ny-2, 0) }[axis]
        getf0['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (nx-1, 0, 0), \
                'y': (0, ny-1, 0), \
                'z': (0, 0, nz-1) }[axis]
        pt1 = { 'x': (nx-1, ny-2, nz-2), \
                'y': (nx-2, ny-1, nz-2), \
                'z': (nx-2, ny-2, nz-1) }[axis]
        getf1['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (0, 1, 1), \
                'y': (1, 0, 1), \
                'z': (1, 1, 0) }[axis]
        pt1 = { 'x': (0, ny-1, nz-1), \
                'y': (nx-1, 0, nz-1), \
                'z': (nx-1, ny-1, 0) }[axis]
        getf0['h'] = GetFields(fields, strfs_h, pt0, pt1)

        pt0 = { 'x': (nx-1, 1, 1), \
                'y': (1, ny-1, 1), \
                'z': (1, 1, nz-1) }[axis]
        pt1 = (nx - 1, ny - 1, nz - 1)
        getf1['h'] = GetFields(fields, strfs_h, pt0, pt1)

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            norm = np.linalg.norm( \
                    getf0[eh].get_fields() - getf1[eh].get_fields() )
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))