import numpy as np import sys, os sys.path.append(os.path.expanduser('~')) from kemp.fdtd3d.cpu import QueueTask, Fields, Core, Pbc, IncidentDirect, GetFields nx, ny, nz = 160, 140, 32 tmax, tgap = 150, 10 # instances fields = Fields(QueueTask(), nx, ny, nz, 'e') Core(fields) Pbc(fields, 'xyz') """ tfunc = lambda tstep: np.sin(0.05 * tstep) IncidentDirect(fields, 'ez', (20, 0, 0), (20, -1, -1), tfunc) #IncidentDirect(fields, 'ez', (0, 20, 0), (-1, 20, -1), tfunc) getf = GetFields(fields, 'ez', (0, 0, 0.5), (-1, -1, 0.5)) 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()
coeff_use='e', precision_float='single', use_cpu_core=1) Core(fields) fields2 = Fields(QueueTask(), nx, ny, nz, coeff_use='e', precision_float='single', use_cpu_core=1) Core(fields2) #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()
# Created : 2012-02-13 # Modified: import numpy as np import sys from kemp.fdtd3d.cpu import QueueTask, Fields, Core, Pbc, Pml, IncidentDirect, GetFields nx, ny, nz = 2, 250, 300 tmax, tgap = 300, 10 npml = 10 # instances fields = Fields(QueueTask(), nx, ny, nz, use_cpu_core=1) 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 # main loop from datetime import datetime t0 = datetime.now() for tstep in xrange(1, tmax+1):
def runTest(self): axis, nx, ny, nz, mpi_type = self.args fields = Fields(nx, ny, nz, mpi_type=mpi_type) core = Core(fields) pbc = Pbc(fields, axis) # allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_ehs(*ehs) # update fields.update_e() fields.update_h() fields.enqueue_barrier() # 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']: g0 = getf0[eh].get_fields() g1 = getf1[eh].get_fields() norm = np.linalg.norm(g0 - g1) ''' print eh print g0 print g1 ''' self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))