Example #1
0
    def verify(s, pt0, pt1):
        print('pt0 = %s, pt1 = %s' % (pt0, pt1))
        slidx = s.get_slidx(pt0, pt1)

        for strf in s.strf_list:
            # non-spatial
            fset = SetFields(s.fdtd, strf, pt0, pt1)
            value = np.random.rand()
            fset.set_fields(value)

            fget = GetFields(s.fdtd, strf, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields(strf)

            assert np.linalg.norm(value - copy) == 0

        if pt0 != pt1:
            for strf in s.strf_list:
                # spatial
                fset = SetFields(s.fdtd, strf, pt0, pt1, np.ndarray)
                values = np.random.rand(*fset.rplist['shape']).astype(
                    s.fdtd.dtype)
                fset.set_fields(values)

                fget = GetFields(s.fdtd, strf, pt0, pt1)
                fget.get_event().wait()
                copy = fget.get_fields(strf)

                assert np.linalg.norm(values - copy) == 0
	def verify(s, pt0, pt1):
		print('pt0 = %s, pt1 = %s' % (pt0, pt1))
		slidx = s.get_slidx(pt0, pt1)

		for strf in s.strf_list:
			# non-spatial
			fset = SetFields(s.fdtd, strf, pt0, pt1)
			value = np.random.rand()
			fset.set_fields(value)

			fget = GetFields(s.fdtd, strf, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields(strf)

			assert np.linalg.norm(value - copy) == 0

		if pt0 != pt1:
			for strf in s.strf_list:
				# spatial
				fset = SetFields(s.fdtd, strf, pt0, pt1, np.ndarray)
				values = np.random.rand(*fset.rplist['shape']).astype(s.fdtd.dtype)
				fset.set_fields(values)

				fget = GetFields(s.fdtd, strf, pt0, pt1)
				fget.get_event().wait()
				copy = fget.get_fields(strf)

				assert np.linalg.norm(values - copy) == 0
Example #3
0
    def test_boundary(s):
        print('\n-- test boundary (two fields) --')
        shape_dict = {
            'x': (s.ny * 2, s.nz),
            'y': (s.nx * 2, s.nz),
            'z': (s.nx * 2, s.ny)
        }

        print('E fields')
        str_fs_dict = {'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey']}
        pt0_dict = {
            'x': (s.nx - 1, 0, 0),
            'y': (0, s.ny - 1, 0),
            'z': (0, 0, s.nz - 1)
        }
        pt1 = (s.nx - 1, s.ny - 1, s.nz - 1)

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt0 = pt0_dict[axis]
            slidx = s.get_slidx(pt0, pt1)
            fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
            values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields()

            assert np.linalg.norm(values - copy) == 0

        print('H fields')
        str_fs_dict = {'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy']}
        pt0 = (0, 0, 0)
        pt1_dict = {
            'x': (0, s.ny - 1, s.nz - 1),
            'y': (s.nx - 1, 0, s.nz - 1),
            'z': (s.nx - 1, s.ny - 1, 0)
        }

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt1 = pt1_dict[axis]
            slidx = s.get_slidx(pt0, pt1)
            fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
            values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields()

            assert np.linalg.norm(values - copy) == 0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slidx = common.slices_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        fields = Fields(0, nx, ny, nz, '', 'single')
        getf = GetFields(fields, str_f, pt0, pt1) 
        
        # host allocations
        ehs = common_random.generate_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        fields.set_eh_bufs(*ehs)

        # verify
        getf.wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slidx]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))

        fields.context_pop()
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slidx = common.slices_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        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, '', 'single')
        getf = GetFields(fields, str_f, pt0, pt1) 
        
        # host allocations
        ehs = common_random.generate_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        fields.set_eh_bufs(*ehs)

        # verify
        getf.get_event().wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slidx]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slidx = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        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, '', 'single')
        getf = GetFields(fields, str_f, pt0, pt1) 
        
        # host allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        fields.set_eh_bufs(*ehs)

        # verify
        getf.get_event().wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slidx]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Example #7
0
    def test_boundary(s):
        print('\n-- test boundary (two fields) --')

        print('E fields')
        str_fs_dict = {'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey']}
        pt0 = (0, 0, 0)
        pt1_dict = {
            'x': (0, s.ny - 1, s.nz - 1),
            'y': (s.nx - 1, 0, s.nz - 1),
            'z': (s.nx - 1, s.ny - 1, 0)
        }

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt1 = pt1_dict[axis]
            slidx = s.get_slidx(pt0, pt1)
            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()

            for strf in str_fs:
                original = s.fhosts[strf][slidx]
                copy = fget.get_fields(strf)
                assert np.linalg.norm(original - copy) == 0

        print('H fields')
        str_fs_dict = {'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy']}
        pt0_dict = {
            'x': (s.nx - 1, 0, 0),
            'y': (0, s.ny - 1, 0),
            'z': (0, 0, s.nz - 1)
        }
        pt1 = (s.nx - 1, s.ny - 1, s.nz - 1)

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt0 = pt0_dict[axis]
            slidx = s.get_slidx(pt0, pt1)
            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()

            for strf in str_fs:
                original = s.fhosts[strf][slidx]
                copy = fget.get_fields(strf)
                assert np.linalg.norm(original - copy) == 0
	def test_boundary(s):
		print('\n-- test boundary (two fields) --')
		shape_dict = {'x':(s.ny*2, s.nz), 'y':(s.nx*2, s.nz), 'z':(s.nx*2, s.ny)}

		print('E fields')
		str_fs_dict = {'x':['ey','ez'], 'y':['ex','ez'], 'z':['ex','ey']}
		pt0_dict = {'x':(s.nx-1, 0, 0), 'y':(0, s.ny-1, 0), 'z':(0, 0, s.nz-1)}
		pt1 = (s.nx-1, s.ny-1, s.nz-1)

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt0 = pt0_dict[axis]
			slidx = s.get_slidx(pt0, pt1)
			fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
			values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields()

			assert np.linalg.norm(values - copy) == 0


		print('H fields')
		str_fs_dict = {'x':['hy','hz'], 'y':['hx','hz'], 'z':['hx','hy']}
		pt0 = (0, 0, 0)
		pt1_dict = {'x':(0, s.ny-1, s.nz-1), 'y':(s.nx-1, 0, s.nz-1), 'z':(s.nx-1, s.ny-1, 0)}

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt1 = pt1_dict[axis]
			slidx = s.get_slidx(pt0, pt1)
			fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
			values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields()

			assert np.linalg.norm(values - copy) == 0
Example #9
0
    def verify(s, pt0, pt1):
        print('pt0 = %s, pt1 = %s' % (pt0, pt1))
        slidx = s.get_slidx(pt0, pt1)

        for strf in s.strf_list:
            fget = GetFields(s.fdtd, strf, pt0, pt1)
            fget.get_event().wait()
            original = s.fhosts[strf][slidx]
            copy = fget.get_fields(strf)
            #print original, copy
            assert np.linalg.norm(original - copy) == 0
	def verify(s, pt0, pt1):
		print('pt0 = %s, pt1 = %s' % (pt0, pt1))
		slidx = s.get_slidx(pt0, pt1)

		for strf in s.strf_list:
			fget = GetFields(s.fdtd, strf, pt0, pt1)
			fget.get_event().wait()
			original = s.fhosts[strf][slidx]
			copy = fget.get_fields(strf)
			#print original, copy
			assert np.linalg.norm(original - copy) == 0
	def test_boundary(s):
		print('\n-- test boundary (two fields) --')

		print('E fields')
		str_fs_dict = {'x':['ey','ez'], 'y':['ex','ez'], 'z':['ex','ey']}
		pt0 = (0, 0, 0)
		pt1_dict = {'x':(0, s.ny-1, s.nz-1), 'y':(s.nx-1, 0, s.nz-1), 'z':(s.nx-1, s.ny-1, 0)}

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt1 = pt1_dict[axis]
			slidx = s.get_slidx(pt0, pt1)
			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()

			for strf in str_fs:
				original = s.fhosts[strf][slidx]
				copy = fget.get_fields(strf)
				assert np.linalg.norm(original - copy) == 0


		print('H fields')
		str_fs_dict = {'x':['hy','hz'], 'y':['hx','hz'], 'z':['hx','hy']}
		pt0_dict = {'x':(s.nx-1, 0, 0), 'y':(0, s.ny-1, 0), 'z':(0, 0, s.nz-1)}
		pt1 = (s.nx-1, s.ny-1, s.nz-1)

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt0 = pt0_dict[axis]
			slidx = s.get_slidx(pt0, pt1)
			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()

			for strf in str_fs:
				original = s.fhosts[strf][slidx]
				copy = fget.get_fields(strf)
				assert np.linalg.norm(original - copy) == 0
Example #12
0
# z-axis
nx, ny, nz = 180, 160, 2
fields = Fields(context, device, nx, ny, nz)
Core(fields)
Pbc(fields, 'xyz')
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')

ax2 = fig.add_subplot(2, 3, 4)
getf = GetFields(fields, 'ex', (0, 0, nz/2), (nx-1, ny-1, nz/2))
getf.get_event().wait()
ax2.imshow(getf.get_fields().T, vmin=-1.1, vmax=1.1)
ax2.set_title('%s, ex[:,20,:]' % repr(fields.ns))
ax2.set_xlabel('x')
ax2.set_ylabel('y')

# y-axis 
nx, ny, nz = 180, 2, 160
fields = Fields(context, device, nx, ny, nz)
gpu_id = 0

gpu_devices = common_gpu.get_gpu_devices()
context = cl.Context(gpu_devices)
device = gpu_devices[gpu_id]

fdtd = Fields(context, device, nx, ny, nz, coeff_use='')
src = DirectSrc(fdtd, 'ex', (1, ny / 5 * 4, nz / 5 * 3),
                (1, ny / 5 * 4, nz / 5 * 3), lambda tstep: np.sin(0.1 * tstep))
pbc = PbcInt(fdtd, 'x')
output = GetFields(fdtd, 'ex', (1, 0, 0), (1, ny - 1, nz - 1))

# Plot
import matplotlib.pyplot as plt
plt.ion()
imag = plt.imshow(output.get_fields().T,
                  cmap=plt.cm.hot,
                  origin='lower',
                  vmin=0,
                  vmax=0.05)
plt.colorbar()

# Main loop
from datetime import datetime
t0 = datetime.now()

for tstep in xrange(1, tmax + 1):
    fdtd.update_e()
    src.update(tstep)
    pbc.update_e()
Example #14
0
import pyopencl as cl
from kemp.fdtd3d import common_gpu
from kemp.fdtd3d.gpu import Fields, GetFields, Npml

nx, ny, nz = 100, 110, 128
gpu_id = 0

gpu_devices = common_gpu.get_gpu_devices()
context = cl.Context(gpu_devices)
device = gpu_devices[gpu_id]
fdtd = Fields(context, device, nx, ny, nz, coeff_use='')

fhosts = {}
pml = Npml(fdtd, -0.428571428571, 0.714285714286, 0.6, 0.2, 0.6, 0.2)

fhost = np.random.rand(nx, nz).astype(fdtd.dtype)
cl.enqueue_write_buffer(fdtd.queue, pml.pex, fhost)

pml.update_h()
fget = GetFields(fdtd, ['hz', 'hx'], (0, ny - 1, 0), (nx - 1, ny - 1, nz - 1))
fget.get_event().wait()
hz = fget.get_fields('hz')
hx = fget.get_fields('hx')

print fhost
print hz
print fhost.shape
print hz.shape

assert np.linalg.norm(fhost - hz) == 0
Example #15
0
    from datetime import datetime
    from time import time, sleep
    t0 = datetime.now()
    t00 = time()

# main loop
for tstep in xrange(1, tmax + 1):
    fields.update_e()
    exch.update_e()

    fields.update_h()
    exch.update_h()

    if tstep % 10 == 0 and is_plot:
        getf.get_event().wait()
        np.save('rank%d_%d' % (rank, tstep), getf.get_fields())

        if is_master:
            print(
                '[%s] %d/%d (%d %%)\r' %
                (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100)),
            sys.stdout.flush()

            for i in range(size):
                load_fail = True
                while load_fail:
                    try:
                        arr[i * nx:(i + 1) * nx, :] = np.load('rank%d_%d.npy' %
                                                              (i, tstep))
                        load_fail = False
                    except:
Example #16
0
tmax, tgap = 200, 10
gpu_id = 0

gpu_devices = common_gpu.get_gpu_devices()
context = cl.Context(gpu_devices)
device = gpu_devices[gpu_id]

fdtd = Fdtd(context, device, nx, ny, nz, coeff_use='')
src = DirectSrc(fdtd, 'ez', (nx/3*2, ny/2, 0), (nx/3*2, ny/2, nz-1), lambda tstep: np.sin(0.1 * tstep))
output = GetFields(fdtd, 'ez', (0, 0, nz/2), (nx-1, ny-1, nz/2))


# Plot
import matplotlib.pyplot as plt
plt.ion()
imag = plt.imshow(output.get_fields('ez').T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.05)
plt.colorbar()


# Main loop
from datetime import datetime
t0 = datetime.now()

for tstep in xrange(1, tmax+1):
	fdtd.update_h()
	fdtd.update_e()
	src.update(tstep)

	if tstep % tgap == 0:
		print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
		sys.stdout.flush()
Example #17
0
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()

# main loop
from datetime import datetime
t0 = datetime.now()

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

    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        getf.get_event().wait()
        imag.set_array( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()

plt.show()
print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100))
print('')
Example #18
0
import pyopencl as cl
from kemp.fdtd3d import common_gpu
from kemp.fdtd3d.gpu import Fields, GetFields, Npml

nx, ny, nz = 100, 110, 128
gpu_id = 0

gpu_devices = common_gpu.get_gpu_devices()
context = cl.Context(gpu_devices)
device = gpu_devices[gpu_id]
fdtd = Fields(context, device, nx, ny, nz, coeff_use='')

fhosts = {}
pml = Npml(fdtd, -0.428571428571, 0.714285714286, 0.6, 0.2, 0.6, 0.2)

fhost = np.random.rand(nx, nz).astype(fdtd.dtype)
cl.enqueue_write_buffer(fdtd.queue, pml.pex, fhost)

pml.update_h()
fget = GetFields(fdtd, ['hz','hx'], (0, ny-1, 0), (nx-1, ny-1, nz-1))
fget.get_event().wait()
hz = fget.get_fields('hz')
hx = fget.get_fields('hx')

print fhost
print hz
print fhost.shape
print hz.shape

assert np.linalg.norm(fhost - hz) == 0
Example #19
0
gpu_devices = common_gpu.get_gpu_devices()
context = cl.Context(gpu_devices)
device = gpu_devices[gpu_id]

fdtd = Fields(context, device, nx, ny, nz, coeff_use='')
src_e = DirectSrc(fdtd, 'ex', (1, ny/5*4, nz/5*1), (1, ny/5*4, nz/5*1), lambda tstep: np.sin(0.1 * tstep))
pbc = PbcInt(fdtd, 'x')
pml = Npml(fdtd, -0.428571428571, 0.714285714286, 0.6, 0.2, 0.6, 0.2)
output = GetFields(fdtd, 'ex', (1, 0, 0), (1, ny-1, nz-1))


# Plot
import matplotlib.pyplot as plt
plt.ion()
imag = plt.imshow(output.get_fields().T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.01)
plt.colorbar()


# Main loop
from datetime import datetime
t0 = datetime.now()

for tstep in xrange(1, tmax+1):
	fdtd.update_e()
	src_e.update(tstep)
	pml.update_e()
	pbc.update_e()

	fdtd.update_h()
	pml.update_h()
Example #20
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')

ax2 = fig.add_subplot(2, 3, 4)
getf = GetFields(fields, 'ex', (0, 0, nz / 2), (nx - 1, ny - 1, nz / 2))
getf.get_event().wait()
ax2.imshow(getf.get_fields().T, vmin=-1.1, vmax=1.1)
ax2.set_title('%s, ex[:,20,:]' % repr(fields.ns))
ax2.set_xlabel('x')
ax2.set_ylabel('y')

# y-axis
nx, ny, nz = 180, 2, 160
fields = Fields(context, device, nx, ny, nz)
Example #21
0
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()

# main loop
from datetime import datetime
t0 = datetime.now()

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

    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        getf.get_event().wait()
        imag.set_array( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()

plt.show()
print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100))
print('')
Example #22
0
    from datetime import datetime
    from time import time, sleep
    t0 = datetime.now()
    t00 = time()

# main loop
for tstep in xrange(1, tmax+1):
    fields.update_e()
    exch.update_e()

    fields.update_h()
    exch.update_h()

    if tstep % 10 == 0 and is_plot:
        getf.get_event().wait()
        np.save('rank%d_%d' % (rank, tstep), getf.get_fields())

        if is_master:
            print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
            sys.stdout.flush()

            for i in range(size):
                load_fail = True
                while load_fail:
                    try:
                        arr[i*nx:(i+1)*nx,:] = np.load('rank%d_%d.npy' % (i, tstep))
                        load_fail = False
                    except:
                        sleep(0.1)

            imag.set_array(arr.T)
Example #23
0
fig = plt.figure(figsize=(12,8))
#fig.add_subplot(1, 3, 1)
#imag = plt.imshow(np.zeros((nx, ny), fields.dtype).T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.05)
imag = plt.imshow(np.zeros((nx, ny), fields.dtype).T, interpolation='nearest', origin='lower', vmin=0, vmax=1.1)
plt.colorbar()

# main loop
from datetime import datetime
t0 = datetime.now()

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

    fields.update_h()
    vpbc.verify_h()

    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        getf.get_event().wait()
        imag.set_array( np.abs(getf.get_fields().T) )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()

plt.show()
#getf.wait()
#print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100))
print('')