def pyoptools_repr(self, obj):
        dist = obj.distribution
        nr = obj.nr
        na = obj.na
        wl = obj.wl.getValueAs("µm").Value
        ang = obj.angle.getValueAs("rad").Value

        pla = obj.getGlobalPlacement()
        X, Y, Z = pla.Base
        RZ, RY, RX = pla.Rotation.toEuler()

        if dist == "polar":
            r = rs_lib.point_source_p(
                origin=(X, Y, Z),
                direction=(radians(RX), radians(RY), radians(RZ)),
                span=ang,
                num_rays=(nr, na),
                wavelength=wl,
                label="",
            )
        elif dist == "cartesian":
            r = rs_lib.point_source_c(
                origin=(X, Y, Z),
                direction=(radians(RX), radians(RY), radians(RZ)),
                span=(ang, ang),
                num_rays=(nr, na),
                wavelength=wl,
                label="",
            )
        elif dist == "random":
            print("random ray distribution, not implemented yet")
        else:
            print("Warning ray distribution {} not recognized".format(dist))

        return r
Esempio n. 2
0
    def pyoptools_repr(self,obj):
        X,Y,Z = obj.Placement.Base
        dist=obj.distribution.lower()
        nr=obj.nr
        na=obj.na
        ang = obj.angle
        wl=obj.wavelenght
        RZ,RY,RX = obj.Placement.Rotation.toEuler()
        rm = rot_mat((radians(RX),radians(RY),radians(RZ)))
        dire=((radians(RX),radians(RY),radians(RZ)))

        r=[]
        if obj.enabled:
            if dist=="polar":
                for x in linspace(-obj.xSize/2,obj.xSize/2,obj.Nx):
                    for y in linspace(-obj.ySize/2,obj.ySize/2,obj.Ny):
                        xr,yr,zr =dot(rm,array((x,y,0),dtype="float64"))
                        r=r+rs_lib.point_source_p(origin=(X+xr,Y+yr,Z+zr),direction=dire,span=radians(ang),
                                      num_rays=(nr,na),wavelength=wl/1000., label="")

            elif dist=="cartesian":
                for x in linspace(-obj.xSize/2,obj.xSize/2,obj.Nx):
                    for y in linspace(-obj.ySize/2,obj.ySize/2,obj.Ny):
                        xr,yr,zr =dot(rm,array((x,y,0),dtype="float64"))
                        r=r+rs_lib.point_source_c(origin=(X+xr,Y+yr,Z+zr),direction=dire,span=(radians(ang),radians(ang))\
                                                  ,num_rays=(nr,na),wavelength=wl/1000., label="")
            elif dist=="random":
                print("random ray distribution, not implemented yet")
            else:
                print("Warning ray distribution {} not recognized".format(dist))

        return r
Esempio n. 3
0
def test_point_source_c():
    # point_source_c(origin=(0.,0.,0.),direction=(0.,0.,0),span=(pi/8,pi/8)\
    #                      ,num_rays=(10,10),wavelength=0.58929, label="")
    pos_origin_ray = np.array([1.0, 1.5, 3.1416])
    direction = np.array([5.2, 6.3, 10.3])
    span = (np.pi / 8, np.pi / 8)
    num_rays = (2, 3)
    wavelength = 0.6328
    label = "another_test"

    expected_dir = [
        np.array([0.84217193, -0.45989021, 0.28150922]),
        np.array([0.73225862, -0.61754295, 0.28712021]),
        np.array([0.59697294, -0.75362932, 0.27507482]),
        np.array([0.69812011, -0.34719261, 0.6261674]),
        np.array([0.5882068, -0.50484536, 0.63177839]),
        np.array([0.45292112, -0.64093172, 0.619733]),
    ]
    expected = [
        ray.Ray(
            pos=pos_origin_ray,
            dir=i,
            intensity=1.0,
            wavelength=wavelength,
            n=None,
            label=label,
            orig_surf=None,
            order=0,
        ) for i in expected_dir
    ]

    calculated = ray_source.point_source_c(
        origin=pos_origin_ray,
        direction=direction,
        span=span,
        num_rays=num_rays,
        wavelength=wavelength,
        label=label,
    )

    assert beam_almost_equal(calculated, expected)