Exemple #1
0
class CylindricalSource(object):
    """
    A source for photons emitted in a random direction and position inside a cylinder(radius, length)
    """
    def __init__(self, spectrum=None, wavelength=555, radius=1, length=10):
        super(CylindricalSource, self).__init__()
        self.spectrum = spectrum
        self.wavelength = wavelength
        self.shape = Cylinder(radius=radius, length=length)
        self.radius = radius
        self.length = length
        self.throw = 0
        self.source_id = "CylindricalSource_" + str(id(self))

    def translate(self, translation):
        self.shape.append_transform(tf.translation_matrix(translation))

    def rotate(self, angle, axis):
        self.shape.append_transform(tf.rotation_matrix(angle, axis))

    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1

        # Position of emission
        phi = np.random.uniform(0., 2 * np.pi)
        r = np.random.uniform(0., self.radius)

        x = r * np.cos(phi)
        y = r * np.sin(phi)
        z = np.random.uniform(0., self.length)
        local_center = (x, y, z)

        photon.position = transform_point(local_center, self.shape.transform)

        # Direction of emission (no need to transform if meant to be isotropic)
        phi = np.random.uniform(0., 2 * np.pi)
        theta = np.random.uniform(0., np.pi)

        x = np.cos(phi) * np.sin(theta)
        y = np.sin(phi) * np.sin(theta)
        z = np.cos(theta)
        local_direction = (x, y, z)

        photon.direction = local_direction

        # Set wavelength of photon
        if self.spectrum != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(
                np.random.uniform())
        else:
            photon.wavelength = self.wavelength

        # Further initialisation
        photon.active = True

        return photon
class CylindricalSource(object):
    """
    A source for photons emitted in a random direction and position inside a cylinder(radius, length)
    """
    def __init__(self, spectrum = None, wavelength = 555, radius = 1, length = 10):
        super(CylindricalSource, self).__init__()
        self.spectrum = spectrum
        self.wavelength = wavelength
        self.shape = Cylinder(radius = radius, length = length)
        self.radius = radius
        self.length = length
        self.throw = 0
        self.source_id = "CylindricalSource_" + str(id(self))
                
    def translate(self, translation):
        self.shape.append_transform(tf.translation_matrix(translation))

    def rotate(self, angle, axis):
        self.shape.append_transform(tf.rotation_matrix(angle, axis))

    def photon(self):
        photon = Photon()
        photon.source = self.source_id
        photon.id = self.throw
        self.throw = self.throw + 1 
        
        # Position of emission
        phi = np.random.uniform(0., 2*np.pi)
        r = np.random.uniform(0.,self.radius)        
        
        x = r*np.cos(phi)
        y = r*np.sin(phi) 
        z = np.random.uniform(0.,self.length)
        local_center = (x,y,z)
        
        photon.position = transform_point(local_center, self.shape.transform)
        
        
        # Direction of emission (no need to transform if meant to be isotropic)
        phi = np.random.uniform(0.,2*np.pi)
        theta = np.random.uniform(0.,np.pi)
        
        x = np.cos(phi)*np.sin(theta)
        y = np.sin(phi)*np.sin(theta)
        z = np.cos(theta)
        local_direction = (x,y,z)
        
        photon.direction = local_direction
        
        # Set wavelength of photon
        if self.spectrum != None:
            photon.wavelength = self.spectrum.wavelength_at_probability(np.random.uniform())        
        else:
            photon.wavelength = self.wavelength
            
        # Further initialisation
        photon.active = True
        
        return photon
Exemple #3
0
 def __init__(self, spectrum=None, wavelength=555, radius=1, length=10):
     super(CylindricalSource, self).__init__()
     self.spectrum = spectrum
     self.wavelength = wavelength
     self.shape = Cylinder(radius=radius, length=length)
     self.radius = radius
     self.length = length
     self.throw = 0
     self.source_id = "CylindricalSource_" + str(id(self))
 def __init__(self, spectrum = None, wavelength = 555, radius = 1, length = 10):
     super(CylindricalSource, self).__init__()
     self.spectrum = spectrum
     self.wavelength = wavelength
     self.shape = Cylinder(radius = radius, length = length)
     self.radius = radius
     self.length = length
     self.throw = 0
     self.source_id = "CylindricalSource_" + str(id(self))