예제 #1
0
    def _package_surface_data_cl(self, context, queue, geometry, wavelengths,
                                 wavelength_step):
        surface_data = {}
        device = context.devices[0]
        nsurfaces = len(geometry.unique_surfaces)
        nwavelengths = len(wavelengths)

        detect = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        absorb = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        reemit = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        reflect_diffuse = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        reflect_specular = np.zeros((nsurfaces, nwavelengths),
                                    dtype=np.float32)
        eta = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        k = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        reemission_cdf = np.zeros((nsurfaces, nwavelengths), dtype=np.float32)
        model = np.zeros(nsurfaces, dtype=np.uint32)
        transmissive = np.zeros(nsurfaces, dtype=np.uint32)
        thickness = np.zeros(nsurfaces, dtype=np.float32)
        nplanes = np.zeros(nsurfaces, dtype=np.float32)
        wire_diameter = np.zeros(nsurfaces, dtype=np.float32)
        wire_pitch = np.zeros(nsurfaces, dtype=np.float32)

        for i in range(len(geometry.unique_surfaces)):
            surface = geometry.unique_surfaces[i]
            if surface is None:
                continue

            detect[i] = self._interp_material_property(wavelengths,
                                                       surface.detect)
            absorb[i] = self._interp_material_property(wavelengths,
                                                       surface.absorb)
            reemit[i] = self._interp_material_property(wavelengths,
                                                       surface.reemit)
            reflect_diffuse[i] = self._interp_material_property(
                wavelengths, surface.reflect_diffuse)
            reflect_specular[i] = self._interp_material_property(
                wavelengths, surface.reflect_specular)
            eta[i] = self._interp_material_property(wavelengths, surface.eta)
            k[i] = self._interp_material_property(wavelengths, surface.k)
            reemission_cdf[i] = self._interp_material_property(
                wavelengths, surface.reemission_cdf)
            model[i] = np.uint32(surface.model)
            transmissive[i] = np.uint32(surface.transmissive)
            thickness[i] = np.float32(surface.thickness)
            nplanes[i] = np.float32(surface.nplanes)
            wire_diameter[i] = np.float32(surface.wire_diameter)
            wire_pitch[i] = np.float32(surface.wire_pitch)

        surface_data["detect"] = ga.to_device(queue, detect.ravel())
        surface_data["absorb"] = ga.to_device(queue, absorb.ravel())
        surface_data["reemit"] = ga.to_device(queue, reemit.ravel())
        surface_data["reflect_diffuse"] = ga.to_device(queue,
                                                       reflect_diffuse.ravel())
        surface_data["reflect_specular"] = ga.to_device(
            queue, reflect_specular.ravel())
        surface_data["eta"] = ga.to_device(queue, eta.ravel())
        surface_data["k"] = ga.to_device(queue, k.ravel())
        surface_data["reemission_cdf"] = ga.to_device(queue,
                                                      reemission_cdf.ravel())
        surface_data["model"] = ga.to_device(queue, model)
        surface_data["transmissive"] = ga.to_device(queue, transmissive)
        surface_data["thickness"] = ga.to_device(queue, thickness)
        surface_data["nplanes"] = ga.to_device(queue, nplanes)
        surface_data["wire_diameter"] = ga.to_device(queue, wire_diameter)
        surface_data["wire_pitch"] = ga.to_device(queue, wire_pitch)
        surface_data["n"] = np.uint32(nwavelengths)
        surface_data["step"] = np.float32(wavelength_step)
        surface_data["wavelength0"] = np.float32(wavelengths[0])
        surface_data["nsurfaces"] = np.uint32(len(geometry.unique_surfaces))

        nbytes = 0
        for data in surface_data:
            nbytes += surface_data[data].nbytes

        return surface_data, nbytes
예제 #2
0
    def _package_material_data_cl(self, context, queue, geometry, wavelengths,
                                  wavelength_step):
        material_data = {}
        material_ptrs = None
        device = context.devices[0]

        # First thing is to define the geometry struct
        # would be great if something like this worked. But its not going to for now.
        # we have to settle for keeping track of simple arrays and passing them in as arguments to cl kernel functions...
        #material_struct = np.dtype( [('refractive_index',  np.float32,len(wavelengths)),
        #                             ('absorption_length', np.float32,len(wavelengths)),
        #                             ('scattering_length', np.float32,len(wavelengths)),
        #                             ('reemission_prob',   np.float32,len(wavelengths)),
        #                             ('reemission_cdf',    np.float32,len(wavelengths)),
        #                             ('n',                 np.uint32),
        #                             ('step',              np.float32),
        #                             ('wavelength0',       np.float32)] )
        #material_struct, material_c_decl = cl.tools.match_dtype_to_c_struct( device, "Material", material_struct )
        #print "defined Material Struct"
        #print material_c_decl
        #material_struct = cl.tools.get_or_register_dtype( "Material", material_struct )
        #print "registered with pyopencl for context=",context," device=",device
        nmaterials = len(geometry.unique_materials)
        nwavelengths = len(wavelengths)
        materials_refractive_index = np.empty((nmaterials, nwavelengths),
                                              dtype=np.float32)
        materials_absorption_length = np.empty((nmaterials, nwavelengths),
                                               dtype=np.float32)
        materials_scattering_length = np.empty((nmaterials, nwavelengths),
                                               dtype=np.float32)
        materials_reemission_prob = np.empty((nmaterials, nwavelengths),
                                             dtype=np.float32)
        materials_reemission_cdf = np.empty((nmaterials, nwavelengths),
                                            dtype=np.float32)

        for i in range(len(geometry.unique_materials)):
            material = geometry.unique_materials[i]

            if material is None:
                raise Exception('one or more triangles is missing a material.')

            materials_refractive_index[i] = self._interp_material_property(
                wavelengths, material.refractive_index)
            materials_absorption_length[i] = self._interp_material_property(
                wavelengths, material.absorption_length)
            materials_scattering_length[i] = self._interp_material_property(
                wavelengths, material.scattering_length)
            materials_reemission_prob[i] = self._interp_material_property(
                wavelengths, material.reemission_prob)
            materials_reemission_cdf[i] = self._interp_material_property(
                wavelengths, material.reemission_cdf)

        material_data["refractive_index"] = ga.to_device(
            queue, materials_refractive_index.ravel())
        material_data["absorption_length"] = ga.to_device(
            queue, materials_absorption_length.ravel())
        material_data["scattering_length"] = ga.to_device(
            queue, materials_scattering_length.ravel())
        material_data["reemission_prob"] = ga.to_device(
            queue, materials_reemission_prob.ravel())
        material_data["reemission_cdf"] = ga.to_device(
            queue, materials_reemission_cdf.ravel())
        material_data["n"] = np.uint32(nwavelengths)
        material_data["step"] = np.float32(wavelength_step)
        material_data["wavelength0"] = np.float32(wavelengths[0])
        material_data["nmaterials"] = np.uint32(len(geometry.unique_materials))

        nbytes = 0
        for data in material_data:
            nbytes += material_data[data].nbytes

        return material_data, nbytes