Exemple #1
0
    def set_structure(self, fdtd, wait=True):
        self.set_fdtd(fdtd)
        prg       = fdtd._structure_prg
        height    = comp_to_real(fdtd.dtype)(self.height/fdtd.min_ds)
        com       = Fields(fdtd, (      3,  ), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.com      /fdtd.min_ds)
        base_poly = Fields(fdtd, (self.np, 3), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.base_poly/fdtd.min_ds)
        origin    = Fields(fdtd, (      3,  ), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.origin   /fdtd.min_ds)
        rot_mat   = Fields(fdtd, (      9,  ), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.rot_mat  )

        evts = []
        for i in xrange(3):
            material_params = Fields(fdtd, (len(self.material.params[i]),), dtype=comp_to_real(fdtd.dtype), mem_flag='r', \
                                     init_value=np.array(self.material.params[i], dtype=comp_to_real(fdtd.dtype)))
            args = [fdtd.engine.queue, (fdtd.engine.gs,), (fdtd.engine.ls,), \
                    base_poly.data, com.data, height, np.int32(self.np), np.int32(self.axis), \
                    self.grids_lists[i][0], self.grids_lists[i][1], self.grids_lists[i][2], \
                    np.int32(fdtd.nx), np.int32(fdtd.ny), np.int32(fdtd.nz), \
                    origin.data, rot_mat.data, \
                    material_params.data] + self.coefs_lists[i]
            if 'opencl' in fdtd.engine.name:
                evt  = prg.set_struc_plpy(*args)
            elif 'cuda' in fdtd.engine.name:
                func = fdtd.engine.get_function(prg, 'set_struc_plpy')
                fdtd.engine.prepare(func, args)
                evt  = fdtd.engine.enqueue_kernel(func, args, False)
            elif  'cpu' in fdtd.engine.name:
                func = fdtd.engine.set_kernel(prg.set_struc_plpy, args)
                evt  = func(*(args[3:]))
            evts.append(evt)
        if wait: wait_for_events(fdtd, evts)
        del com, base_poly, origin, rot_mat, material_params
        return evts
Exemple #2
0
 def set_structure(self, fdtd, wait=True):
     self.set_fdtd(fdtd)
     prg = fdtd._structure_prg
     points = Fields(fdtd, (4, ),
                     dtype=comp_to_real(fdtd.dtype),
                     mem_flag='r',
                     init_value=self.points / fdtd.min_ds)
     evts = []
     for i in xrange(3):
         material_params = Fields(fdtd, (len(self.material.params[i]),), dtype=comp_to_real(fdtd.dtype), mem_flag='r', \
                                  init_value=np.array(self.material.params[i], dtype=comp_to_real(fdtd.dtype)))
         args = [fdtd.engine.queue, (fdtd.engine.gs,), (fdtd.engine.ls,), \
                 points.data, \
                 self.grids_lists[i][0], self.grids_lists[i][1], \
                 np.int32(fdtd.nx), np.int32(fdtd.ny), \
                 material_params.data] + self.coefs_lists[i]
         if 'opencl' in fdtd.engine.name:
             evt = prg.set_struc_rect(*args)
         elif 'cuda' in fdtd.engine.name:
             func = fdtd.engine.get_function(prg, 'set_struc_rect')
             fdtd.engine.prepare(func, args)
             evt = fdtd.engine.enqueue_kernel(func, args, False)
         elif 'cpu' in fdtd.engine.name:
             func = fdtd.engine.set_kernel(prg.set_struc_rect, args)
             evt = func(*(args[3:]))
         evts.append(evt)
     if wait: wait_for_events(fdtd, evts)
     del points, material_params
     return evts
Exemple #3
0
    def set_structure(self, fdtd, wait=True):
        self.set_fdtd(fdtd)
        sin    = fdtd.dtype(self.sin)
        cos    = fdtd.dtype(self.cos)
        com    = Fields(fdtd, (2,), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.com   /fdtd.min_ds)
        radius = Fields(fdtd, (2,), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.radius/fdtd.min_ds)
        origin = Fields(fdtd, (2,), dtype=comp_to_real(fdtd.dtype), mem_flag='r', init_value=self.origin/fdtd.min_ds)

        evts = []
        for i in xrange(3):
            material_params = Fields(fdtd, (len(self.material.params[i]),), dtype=comp_to_real(fdtd.dtype), mem_flag='r', \
                                     init_value=np.array(self.material.params[i], dtype=comp_to_real(fdtd.dtype)))
            args = [fdtd.engine.queue, (fdtd.engine.gs,), (fdtd.engine.ls,), \
                    com.data, radius.data, \
                    self.grids_lists[i][0], self.grids_lists[i][1], \
                    np.int32(fdtd.nx), np.int32(fdtd.ny), \
                    origin.data, \
                    sin, cos, \
                    material_params.data] + self.coefs_lists[i]
            if 'opencl' in fdtd.engine.name:
                evt  = self.prg.set_struc_ellp2d(*args)
            elif 'cuda' in fdtd.engine.name:
                func = fdtd.engine.get_function(self.prg, 'set_struc_ellp2d')
                fdtd.engine.prepare(func, args)
                evt  = fdtd.engine.enqueue_kernel(func, args, False)
            elif  'cpu' in fdtd.engine.name:
                func = fdtd.engine.set_kernel(self.prg.set_struc_ellp2d, args)
                evt  = func(*(args[3:]))
            evts.append(evt)
        if wait: wait_for_events(fdtd, evts)
        del com, radius, origin, material_params
        return evts